@mastra/livekit 0.0.0 → 0.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/LICENSE.md +30 -0
  3. package/README.md +270 -7
  4. package/dist/bridge.d.ts +153 -0
  5. package/dist/bridge.d.ts.map +1 -0
  6. package/dist/chunk-2E3MTAOA.js +133 -0
  7. package/dist/chunk-2E3MTAOA.js.map +1 -0
  8. package/dist/chunk-MWTEZOBS.cjs +139 -0
  9. package/dist/chunk-MWTEZOBS.cjs.map +1 -0
  10. package/dist/constants.d.ts +3 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/dispatch.d.ts +20 -0
  13. package/dist/dispatch.d.ts.map +1 -0
  14. package/dist/index.cjs +105 -0
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/index.d.ts +10 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +91 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/messages.d.ts +24 -0
  21. package/dist/messages.d.ts.map +1 -0
  22. package/dist/metadata.d.ts +17 -0
  23. package/dist/metadata.d.ts.map +1 -0
  24. package/dist/observability.d.ts +46 -0
  25. package/dist/observability.d.ts.map +1 -0
  26. package/dist/routes.d.ts +52 -0
  27. package/dist/routes.d.ts.map +1 -0
  28. package/dist/run.d.ts +32 -0
  29. package/dist/run.d.ts.map +1 -0
  30. package/dist/voice-thread.d.ts +23 -0
  31. package/dist/voice-thread.d.ts.map +1 -0
  32. package/dist/worker-entry.cjs +656 -0
  33. package/dist/worker-entry.cjs.map +1 -0
  34. package/dist/worker-entry.d.ts +8 -0
  35. package/dist/worker-entry.d.ts.map +1 -0
  36. package/dist/worker-entry.js +652 -0
  37. package/dist/worker-entry.js.map +1 -0
  38. package/dist/worker-setup.d.ts +5 -0
  39. package/dist/worker-setup.d.ts.map +1 -0
  40. package/dist/worker.d.ts +187 -0
  41. package/dist/worker.d.ts.map +1 -0
  42. package/dist/workflow-generator.d.ts +92 -0
  43. package/dist/workflow-generator.d.ts.map +1 -0
  44. package/package.json +24 -14
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/routes.ts","../src/dispatch.ts"],"names":[],"mappings":";;;;;;AAgDA,SAAS,WAAA,CAAY,MAA+B,GAAA,EAAiC;AACnF,EAAA,MAAM,KAAA,GAAQ,KAAK,GAAG,CAAA;AACtB,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,MAAA,GAAS,IAAI,KAAA,GAAQ,MAAA;AACjE;AAaO,SAAS,sBAAA,CAAuB,OAAA,GAAyC,EAAC,EAAa;AAC5F,EAAA,MAAM,OAAA,GAAU,OAAO,CAAA,KAAyB;AAC9C,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAa,OAAA,CAAQ,GAAA,CAAI,WAAA;AACnD,IAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,MAAA,IAAU,OAAA,CAAQ,GAAA,CAAI,eAAA;AAC7C,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,IAAa,OAAA,CAAQ,GAAA,CAAI,kBAAA;AACnD,IAAA,IAAI,CAAC,SAAA,IAAa,CAAC,MAAA,IAAU,CAAC,SAAA,EAAW;AACvC,MAAA,OAAO,CAAA,CAAE,IAAA;AAAA,QACP;AAAA,UACE,KAAA,EACE;AAAA,SAEJ;AAAA,QACA;AAAA,OACF;AAAA,IACF;AAEA,IAAA,MAAM,IAAA,GAAgC,MAAM,CAAA,CAAE,GAAA,CAC3C,MAAK,CACL,IAAA;AAAA,MAAK,CAAC,MAAA,KACL,MAAA,IAAU,OAAO,MAAA,KAAW,QAAA,IAAY,CAAC,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAK,MAAA,GAAqC;AAAC,KAC1G,CACC,KAAA,CAAM,OAAO,EAAC,CAAE,CAAA;AACnB,IAAA,MAAM,IAAA,GAA8B,E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SAAS,CAAA,EAAG,QAAQ,SAAS,CAAA;AAC9E,EAAA,OAAO,OAAO,cAAA,CAAe,OAAA,CAAQ,QAAA,EAAU,OAAA,CAAQ,aAAa,0BAAA,EAA4B;AAAA,IAC9F,QAAA,EAAU,wBAAA,CAAyB,OAAA,CAAQ,QAAA,IAAY,EAAE;AAAA,GAC1D,CAAA;AACH","file":"index.js","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { RoomAgentDispatch, RoomConfiguration } from '@livekit/protocol';\nimport type { ContextWithMastra, ApiRoute } from '@mastra/core/server';\nimport { AccessToken } from 'livekit-server-sdk';\nimport { DEFAULT_LIVEKIT_AGENT_NAME } from './constants';\nimport { serializeSessionMetadata } from './metadata';\nimport type { LiveKitSessionMetadata } from './metadata';\n\n/** Response body of the connection-details route. Matches LiveKit's frontend starter contract. */\nexport interface LiveKitConnectionDetails {\n serverUrl: string;\n roomName: string;\n participantName: string;\n participantToken: string;\n}\n\nexport interface ConnectionRequestArgs {\n body: Record<string, unknown>;\n context: ContextWithMastra;\n}\n\nexport interface LiveKitConnectionRouteOptions {\n /**\n * Route path. Defaults to `/voice/livekit/connection-details`. Mastra reserves the\n * `/api` prefix for built-in routes, so custom paths must not start with `/api`.\n */\n path?: string;\n /** LiveKit server URL (`wss://...`). Defaults to `LIVEKIT_URL`. */\n serverUrl?: string;\n /** Defaults to `LIVEKIT_API_KEY`. */\n apiKey?: string;\n /** Defaults to `LIVEKIT_API_SECRET`. */\n apiSecret?: string;\n /** LiveKit agent name for explicit dispatch. Must match the worker's `agentName`. */\n agentName?: string;\n /** Token time-to-live. Defaults to `'15m'`. */\n ttl?: string | number;\n /** Defaults to `true` (Mastra custom routes require auth unless opted out). */\n requiresAuth?: boolean;\n roomName?: string | ((args: ConnectionRequestArgs) => string);\n participantIdentity?: string | ((args: ConnectionRequestArgs) => string);\n /**\n * Session metadata delivered to the worker via agent dispatch. Defaults to passing\n * through `agentId`, `threadId`, and `resourceId` from the request body.\n */\n metadata?: (args: ConnectionRequestArgs) => LiveKitSessionMetadata | Promise<LiveKitSessionMetadata>;\n}\n\nfunction stringField(body: Record<string, unknown>, key: string): string | undefined {\n const value = body[key];\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n}\n\n/**\n * An ApiRoute for `server.apiRoutes` that mints a LiveKit access token with the Mastra\n * voice agent dispatched into the room. Frontends call it to join a voice session:\n *\n * ```ts\n * export const mastra = new Mastra({\n * agents: { support },\n * server: { apiRoutes: [liveKitConnectionRoute({ agentName: 'mastra-voice' })] },\n * });\n * ```\n */\nexport function liveKitConnectionRoute(options: LiveKitConnectionRouteOptions = {}): ApiRoute {\n const handler = async (c: ContextWithMastra) => {\n const serverUrl = options.serverUrl ?? process.env.LIVEKIT_URL;\n const apiKey = options.apiKey ?? process.env.LIVEKIT_API_KEY;\n const apiSecret = options.apiSecret ?? process.env.LIVEKIT_API_SECRET;\n if (!serverUrl || !apiKey || !apiSecret) {\n return c.json(\n {\n error:\n 'LiveKit is not configured. Set LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET ' +\n '(or pass serverUrl/apiKey/apiSecret to liveKitConnectionRoute).',\n },\n 500,\n );\n }\n\n const body: Record<string, unknown> = await c.req\n .json()\n .then((parsed: unknown) =>\n parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? (parsed as Record<string, unknown>) : {},\n )\n .catch(() => ({}));\n const args: ConnectionRequestArgs = { body, context: c };\n\n const metadata: LiveKitSessionMetadata = options.metadata\n ? await options.metadata(args)\n : {\n agentId: stringField(body, 'agentId'),\n threadId: stringField(body, 'threadId'),\n resourceId: stringField(body, 'resourceId'),\n };\n\n const roomName =\n typeof options.roomName === 'function'\n ? options.roomName(args)\n : (options.roomName ?? `mastra-voice-${randomUUID().slice(0, 8)}`);\n const identity =\n typeof options.participantIdentity === 'function'\n ? options.participantIdentity(args)\n : (options.participantIdentity ?? metadata.resourceId ?? `user-${randomUUID().slice(0, 8)}`);\n // One memory thread per room unless the caller pins a thread explicitly.\n metadata.threadId ??= roomName;\n\n const token = new AccessToken(apiKey, apiSecret, { identity, ttl: options.ttl ?? '15m' });\n token.addGrant({\n room: roomName,\n roomJoin: true,\n canPublish: true,\n canSubscribe: true,\n canPublishData: true,\n canUpdateOwnMetadata: true,\n });\n token.roomConfig = new RoomConfiguration({\n agents: [\n new RoomAgentDispatch({\n agentName: options.agentName ?? DEFAULT_LIVEKIT_AGENT_NAME,\n metadata: serializeSessionMetadata(metadata),\n }),\n ],\n });\n\n const details: LiveKitConnectionDetails = {\n serverUrl,\n roomName,\n participantName: identity,\n participantToken: await token.toJwt(),\n };\n return c.json(details);\n };\n\n return {\n path: options.path ?? '/voice/livekit/connection-details',\n method: 'POST',\n requiresAuth: options.requiresAuth,\n handler,\n } as ApiRoute;\n}\n","import { AgentDispatchClient } from 'livekit-server-sdk';\nimport { DEFAULT_LIVEKIT_AGENT_NAME } from './constants';\nimport { serializeSessionMetadata } from './metadata';\nimport type { LiveKitSessionMetadata } from './metadata';\n\nexport interface DispatchVoiceSessionOptions {\n /** Room to dispatch the agent into (created on demand). */\n roomName: string;\n /** Must match the worker's `agentName`. Defaults to `'mastra-voice'`. */\n agentName?: string;\n metadata?: LiveKitSessionMetadata;\n /** Defaults to `LIVEKIT_URL`. */\n serverUrl?: string;\n /** Defaults to `LIVEKIT_API_KEY`. */\n apiKey?: string;\n /** Defaults to `LIVEKIT_API_SECRET`. */\n apiSecret?: string;\n}\n\nfunction toHttpUrl(url: string): string {\n return url.replace(/^ws/, 'http');\n}\n\n/**\n * Programmatically dispatches a Mastra voice agent into a LiveKit room — for\n * server-initiated sessions such as outbound calls or joining an existing room.\n */\nexport async function dispatchVoiceSession(options: DispatchVoiceSessionOptions) {\n const serverUrl = options.serverUrl ?? process.env.LIVEKIT_URL;\n const apiKey = options.apiKey ?? process.env.LIVEKIT_API_KEY;\n const apiSecret = options.apiSecret ?? process.env.LIVEKIT_API_SECRET;\n if (!serverUrl) {\n throw new Error('@mastra/livekit: set LIVEKIT_URL or pass serverUrl to dispatchVoiceSession.');\n }\n if (!apiKey || !apiSecret) {\n throw new Error(\n '@mastra/livekit: set LIVEKIT_API_KEY and LIVEKIT_API_SECRET or pass apiKey/apiSecret to dispatchVoiceSession.',\n );\n }\n const client = new AgentDispatchClient(toHttpUrl(serverUrl), apiKey, apiSecret);\n return client.createDispatch(options.roomName, options.agentName ?? DEFAULT_LIVEKIT_AGENT_NAME, {\n metadata: serializeSessionMetadata(options.metadata ?? {}),\n });\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import type { llm } from '@livekit/agents';
2
+ export type VoiceTurnMessage = {
3
+ role: 'system';
4
+ content: string;
5
+ } | {
6
+ role: 'user';
7
+ content: string;
8
+ } | {
9
+ role: 'assistant';
10
+ content: string;
11
+ };
12
+ /**
13
+ * Extracts only the messages added since the agent last spoke. Used when Mastra Memory is
14
+ * the source of truth for conversation history: prior turns are already persisted in the
15
+ * thread, so re-sending them would duplicate history.
16
+ */
17
+ export declare function extractNewTurnMessages(chatCtx: llm.ChatContext): VoiceTurnMessage[];
18
+ /**
19
+ * Converts the full LiveKit chat context to Mastra messages. Used when the bridge runs
20
+ * without Mastra Memory and LiveKit's in-session context is the only history. The agent's
21
+ * LiveKit-level instructions are excluded — the Mastra agent applies its own instructions.
22
+ */
23
+ export declare function chatContextToMessages(chatCtx: llm.ChatContext): VoiceTurnMessage[];
24
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AA0B3C;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,GAAG,gBAAgB,EAAE,CAgBnF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,GAAG,gBAAgB,EAAE,CAQlF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Session metadata passed from the Mastra server to the LiveKit agent worker through
3
+ * LiveKit's job dispatch metadata (a plain string, so this is JSON-serialized).
4
+ */
5
+ export interface LiveKitSessionMetadata {
6
+ /** Mastra agent to run, by registered key or agent id. */
7
+ agentId?: string;
8
+ /** Memory thread id. Defaults to the LiveKit room name when omitted. */
9
+ threadId?: string;
10
+ /** Memory resource id (typically the end user id). */
11
+ resourceId?: string;
12
+ /** Plain-object entries restored into a RequestContext for agent execution. */
13
+ requestContext?: Record<string, unknown>;
14
+ }
15
+ export declare function parseSessionMetadata(raw: string | undefined | null): LiveKitSessionMetadata;
16
+ export declare function serializeSessionMetadata(metadata: LiveKitSessionMetadata): string;
17
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,sBAAsB,CAW3F;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,sBAAsB,GAAG,MAAM,CAEjF"}
@@ -0,0 +1,46 @@
1
+ import { voice } from '@livekit/agents';
2
+ import type { Mastra } from '@mastra/core/mastra';
3
+ import { SpanType } from '@mastra/core/observability';
4
+ import type { Span, TracingContext } from '@mastra/core/observability';
5
+ import type { RequestContext } from '@mastra/core/request-context';
6
+ import type { LiveKitSessionMetadata } from './metadata.js';
7
+ export interface VoiceCallObservabilityOptions {
8
+ /** The Mastra instance whose observability config receives the spans. */
9
+ mastra: Mastra;
10
+ /** Resolved Mastra agent id/key answering the call (for span attribution). */
11
+ agentId: string;
12
+ /** LiveKit room name for this session. */
13
+ roomName: string;
14
+ /** Dispatch metadata for the session. */
15
+ metadata: LiveKitSessionMetadata;
16
+ /** Request context forwarded to span sampling. */
17
+ requestContext?: RequestContext;
18
+ }
19
+ export interface VoiceCallObservability {
20
+ /** The root `voice call` span. Each turn's agent run and every pipeline metric nests under it. */
21
+ readonly span: Span<SpanType.GENERIC>;
22
+ /** Thread into the bridge's `streamOptions` so each turn's agent run nests under the call. */
23
+ readonly tracingContext: TracingContext;
24
+ /** Subscribe to the session's `metrics_collected` events. Call once, before `session.start()`. */
25
+ attach(session: voice.AgentSession): void;
26
+ /** Close the call span with the usage roll-up. Idempotent; safe to call from a shutdown hook. */
27
+ finalize(options?: {
28
+ error?: unknown;
29
+ }): void;
30
+ }
31
+ /**
32
+ * Opens a `voice call` trace for one LiveKit session and bridges LiveKit's voice-pipeline
33
+ * metrics into Mastra observability.
34
+ *
35
+ * The returned root span groups everything about the call: each conversation turn's Mastra
36
+ * agent run (nested via {@link VoiceCallObservability.tracingContext}) plus an event span for
37
+ * every STT, TTS, end-of-utterance, VAD, and LLM-latency metric LiveKit emits. Metrics are
38
+ * point-in-time, so they're recorded as event spans (no duration) with the value in the name.
39
+ * The root closes on the session `close` event with a per-model usage roll-up (token, character,
40
+ * and audio totals for the whole call) from a `ModelUsageCollector`.
41
+ *
42
+ * Returns `undefined` when the Mastra instance has no observability configured, so callers
43
+ * can treat instrumentation as a no-op without branching on config.
44
+ */
45
+ export declare function startVoiceCallObservability(options: VoiceCallObservabilityOptions): VoiceCallObservability | undefined;
46
+ //# sourceMappingURL=observability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observability.d.ts","sourceRoot":"","sources":["../src/observability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAmB,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,WAAW,6BAA6B;IAC5C,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,QAAQ,EAAE,sBAAsB,CAAC;IACjC,kDAAkD;IAClD,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,sBAAsB;IACrC,kGAAkG;IAClG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACtC,8FAA8F;IAC9F,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,kGAAkG;IAClG,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;IAC1C,iGAAiG;IACjG,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC/C;AAgGD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,6BAA6B,GACrC,sBAAsB,GAAG,SAAS,CAsDpC"}
@@ -0,0 +1,52 @@
1
+ import type { ContextWithMastra, ApiRoute } from '@mastra/core/server';
2
+ import type { LiveKitSessionMetadata } from './metadata.js';
3
+ /** Response body of the connection-details route. Matches LiveKit's frontend starter contract. */
4
+ export interface LiveKitConnectionDetails {
5
+ serverUrl: string;
6
+ roomName: string;
7
+ participantName: string;
8
+ participantToken: string;
9
+ }
10
+ export interface ConnectionRequestArgs {
11
+ body: Record<string, unknown>;
12
+ context: ContextWithMastra;
13
+ }
14
+ export interface LiveKitConnectionRouteOptions {
15
+ /**
16
+ * Route path. Defaults to `/voice/livekit/connection-details`. Mastra reserves the
17
+ * `/api` prefix for built-in routes, so custom paths must not start with `/api`.
18
+ */
19
+ path?: string;
20
+ /** LiveKit server URL (`wss://...`). Defaults to `LIVEKIT_URL`. */
21
+ serverUrl?: string;
22
+ /** Defaults to `LIVEKIT_API_KEY`. */
23
+ apiKey?: string;
24
+ /** Defaults to `LIVEKIT_API_SECRET`. */
25
+ apiSecret?: string;
26
+ /** LiveKit agent name for explicit dispatch. Must match the worker's `agentName`. */
27
+ agentName?: string;
28
+ /** Token time-to-live. Defaults to `'15m'`. */
29
+ ttl?: string | number;
30
+ /** Defaults to `true` (Mastra custom routes require auth unless opted out). */
31
+ requiresAuth?: boolean;
32
+ roomName?: string | ((args: ConnectionRequestArgs) => string);
33
+ participantIdentity?: string | ((args: ConnectionRequestArgs) => string);
34
+ /**
35
+ * Session metadata delivered to the worker via agent dispatch. Defaults to passing
36
+ * through `agentId`, `threadId`, and `resourceId` from the request body.
37
+ */
38
+ metadata?: (args: ConnectionRequestArgs) => LiveKitSessionMetadata | Promise<LiveKitSessionMetadata>;
39
+ }
40
+ /**
41
+ * An ApiRoute for `server.apiRoutes` that mints a LiveKit access token with the Mastra
42
+ * voice agent dispatched into the room. Frontends call it to join a voice session:
43
+ *
44
+ * ```ts
45
+ * export const mastra = new Mastra({
46
+ * agents: { support },
47
+ * server: { apiRoutes: [liveKitConnectionRoute({ agentName: 'mastra-voice' })] },
48
+ * });
49
+ * ```
50
+ */
51
+ export declare function liveKitConnectionRoute(options?: LiveKitConnectionRouteOptions): ApiRoute;
52
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,kGAAkG;AAClG,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AAED,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,+EAA+E;IAC/E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,qBAAqB,KAAK,MAAM,CAAC,CAAC;IAC9D,mBAAmB,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,qBAAqB,KAAK,MAAM,CAAC,CAAC;IACzE;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;CACtG;AAOD;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,6BAAkC,GAAG,QAAQ,CA4E5F"}
package/dist/run.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { ServerOptions } from '@livekit/agents';
2
+ export interface RunLiveKitWorkerOptions {
3
+ /** The worker entry module whose default export is the agent definition. Pass `import.meta.url`. */
4
+ entry: string | URL;
5
+ /** LiveKit agent name for explicit dispatch. Defaults to `'mastra-voice'`. */
6
+ agentName?: string;
7
+ /** Extra LiveKit ServerOptions merged over what this helper builds. */
8
+ serverOptions?: Partial<ConstructorParameters<typeof ServerOptions>[0]>;
9
+ }
10
+ export declare function resolveWorkerEntryPath(entry: string | URL): string;
11
+ /**
12
+ * Starts the LiveKit agent worker CLI (`dev` / `start` / `connect` subcommands) for a
13
+ * worker entry file. Call it from the same file that default-exports
14
+ * {@link createLiveKitWorker}, guarded so it only runs when executed directly:
15
+ *
16
+ * ```ts
17
+ * import { fileURLToPath } from 'node:url';
18
+ * import { createLiveKitWorker, runLiveKitWorker } from '@mastra/livekit/worker';
19
+ * import { mastra } from './index.js';
20
+ *
21
+ * export default createLiveKitWorker({ mastra, agent: 'support' });
22
+ *
23
+ * if (process.argv[1] === fileURLToPath(import.meta.url)) {
24
+ * runLiveKitWorker({ entry: import.meta.url, agentName: 'mastra-voice' });
25
+ * }
26
+ * ```
27
+ *
28
+ * Using this helper (instead of `cli.runApp` from `@livekit/agents`) guarantees the worker
29
+ * runtime and the bridge share one copy of the LiveKit SDK.
30
+ */
31
+ export declare function runLiveKitWorker(options: RunLiveKitWorkerOptions): void;
32
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIrD,MAAM,WAAW,uBAAuB;IACtC,oGAAoG;IACpG,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;IACpB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,aAAa,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACzE;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAGlE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAYvE"}
@@ -0,0 +1,23 @@
1
+ import type { MastraMemory } from '@mastra/core/memory';
2
+ export interface VoiceThreadArgs {
3
+ memory: MastraMemory;
4
+ threadId: string;
5
+ resourceId: string;
6
+ }
7
+ /**
8
+ * Creates the call's memory thread up front when it doesn't exist yet, titled and tagged
9
+ * so it reads as a voice call in Studio's thread list instead of an untitled thread that
10
+ * only appears after the first exchange.
11
+ */
12
+ export declare function ensureVoiceCallThread({ memory, threadId, resourceId, roomName, }: VoiceThreadArgs & {
13
+ roomName: string;
14
+ }): Promise<void>;
15
+ /**
16
+ * Persists the spoken greeting as an assistant message. The greeting is spoken via TTS
17
+ * without going through the Mastra agent, so without this the saved thread would start
18
+ * at the caller's first words instead of being a faithful call transcript.
19
+ */
20
+ export declare function persistSpokenGreeting({ memory, threadId, resourceId, greeting, }: VoiceThreadArgs & {
21
+ greeting: string;
22
+ }): Promise<void>;
23
+ //# sourceMappingURL=voice-thread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice-thread.d.ts","sourceRoot":"","sources":["../src/voice-thread.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,MAAM,EACN,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,eAAe,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CASxD;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,MAAM,EACN,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,eAAe,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBxD"}