fix: use livekit-api package for voice-service token endpoint

The livekit package is the client SDK and doesn't include the server-side
API module. Switch to livekit-api which provides AccessToken, VideoGrants,
RoomAgentDispatch, and RoomConfiguration needed for token generation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-28 09:49:11 -08:00
parent 112c445143
commit acfdae7773
2 changed files with 6 additions and 6 deletions

View File

@ -19,4 +19,4 @@ ordered-set
pypinyin pypinyin
cn2an cn2an
jieba jieba
livekit>=1.0.0 livekit-api>=1.0.0

View File

@ -12,7 +12,7 @@ import uuid
from fastapi import APIRouter, Request from fastapi import APIRouter, Request
from livekit.api import AccessToken, VideoGrants, RoomAgentDispatch, RoomConfiguration from livekit import api as livekit_api
from ..config.settings import settings from ..config.settings import settings
@ -32,11 +32,11 @@ async def create_livekit_token(request: Request):
participant_identity = f"user-{uuid.uuid4().hex[:8]}" participant_identity = f"user-{uuid.uuid4().hex[:8]}"
token = ( token = (
AccessToken(settings.livekit_api_key, settings.livekit_api_secret) livekit_api.AccessToken(settings.livekit_api_key, settings.livekit_api_secret)
.with_identity(participant_identity) .with_identity(participant_identity)
.with_name("User") .with_name("User")
.with_grants( .with_grants(
VideoGrants( livekit_api.VideoGrants(
room_join=True, room_join=True,
room=room_name, room=room_name,
can_publish=True, can_publish=True,
@ -45,9 +45,9 @@ async def create_livekit_token(request: Request):
) )
) )
.with_room_config( .with_room_config(
RoomConfiguration( livekit_api.RoomConfiguration(
agents=[ agents=[
RoomAgentDispatch( livekit_api.RoomAgentDispatch(
agent_name="voice-agent", agent_name="voice-agent",
metadata=json.dumps({"auth_header": auth_header}), metadata=json.dumps({"auth_header": auth_header}),
) )