Enhance WebSocket session management by requiring assistant_id as a query parameter for connection. Update API reference documentation to reflect changes in message flow and metadata validation rules, including the introduction of whitelists for allowed metadata fields and restrictions on sensitive keys. Refactor client examples to align with the new session initiation process.
This commit is contained in:
@@ -12,6 +12,7 @@ import math
|
||||
import argparse
|
||||
import os
|
||||
from datetime import datetime
|
||||
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
|
||||
|
||||
# Configuration
|
||||
SERVER_URL = "ws://localhost:8000/ws"
|
||||
@@ -130,14 +131,17 @@ async def run_client(url, file_path=None, use_sine=False, track_debug: bool = Fa
|
||||
"""Run the WebSocket test client."""
|
||||
session = aiohttp.ClientSession()
|
||||
try:
|
||||
print(f"🔌 Connecting to {url}...")
|
||||
async with session.ws_connect(url) as ws:
|
||||
parts = urlsplit(url)
|
||||
query = dict(parse_qsl(parts.query, keep_blank_values=True))
|
||||
query["assistant_id"] = str(query.get("assistant_id") or "assistant_demo")
|
||||
session_url = urlunsplit((parts.scheme, parts.netloc, parts.path, urlencode(query), parts.fragment))
|
||||
print(f"🔌 Connecting to {session_url}...")
|
||||
async with session.ws_connect(session_url) as ws:
|
||||
print("✅ Connected!")
|
||||
session_ready = asyncio.Event()
|
||||
recv_task = asyncio.create_task(receive_loop(ws, session_ready, track_debug=track_debug))
|
||||
|
||||
# Send v1 hello + session.start handshake
|
||||
await ws.send_json({"type": "hello", "version": "v1"})
|
||||
# Send v1 session.start initialization
|
||||
await ws.send_json({
|
||||
"type": "session.start",
|
||||
"audio": {
|
||||
@@ -146,12 +150,11 @@ async def run_client(url, file_path=None, use_sine=False, track_debug: bool = Fa
|
||||
"channels": 1
|
||||
},
|
||||
"metadata": {
|
||||
"appId": "assistant_demo",
|
||||
"channel": "test_websocket",
|
||||
"configVersionId": "local-dev",
|
||||
"source": "test_websocket",
|
||||
},
|
||||
})
|
||||
print("📤 Sent v1 hello/session.start")
|
||||
print("📤 Sent v1 session.start")
|
||||
await asyncio.wait_for(session_ready.wait(), timeout=8)
|
||||
|
||||
# Select sender based on args
|
||||
|
||||
Reference in New Issue
Block a user