"""WebSocket Demo - Server with Postman Collection Tools"""
import os
import json
from pathlib import Path
from kuralit.server.agent_session import AgentSession
from kuralit.server.config import ServerConfig
from kuralit.server.websocket_server import create_app
def validate_api_key(api_key: str) -> bool:
"""Validate API key."""
expected_key = os.getenv("KURALIT_API_KEY", "demo-api-key")
return api_key == expected_key
if __name__ == "__main__":
import uvicorn
# Load Postman collection if provided
tools = []
postman_collection_path = "postman.json"
if postman_collection_path:
try:
from kuralit.tools.api import RESTAPIToolkit
collection_path = Path(postman_collection_path)
if not collection_path.is_absolute():
resolved_path = Path.cwd() / collection_path
if resolved_path.exists():
collection_path = resolved_path.resolve()
if collection_path and collection_path.exists():
api_toolkit = RESTAPIToolkit.from_postman_collection(
collection_path=str(collection_path),
base_url="http://localhost:35814"
)
tools.append(api_toolkit)
except Exception as e:
print(f"⚠️ Failed to load Postman collection: {e}")
# Create AgentSession with API tools
agent_session = AgentSession(
stt="deepgram/nova-2:en-US",
llm="gemini/gemini-2.0-flash-001",
vad="silero/v3",
turn_detection="multilingual/v1",
instructions="You are a helpful assistant with access to realtime communication. "
"Provide clear, concise, and helpful responses.",
name="Kuralit Demo Agent",
tools=tools if tools else None,
)
app = create_app(
api_key_validator=validate_api_key,
agent_session=agent_session,
)
config = agent_session._config.server if agent_session._config else ServerConfig()
print("🚀 Starting WebSocket server...")
uvicorn.run(
app,
host=config.host,
port=config.port,
log_level=config.log_level.lower(),
)