@livekit/agents 1.0.34 → 1.0.36-dev.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.
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inference/api_protos.d.cts +4 -4
- package/dist/inference/api_protos.d.ts +4 -4
- package/dist/inference/interruption/AdaptiveInterruptionDetector.cjs +152 -0
- package/dist/inference/interruption/AdaptiveInterruptionDetector.cjs.map +1 -0
- package/dist/inference/interruption/AdaptiveInterruptionDetector.d.cts +50 -0
- package/dist/inference/interruption/AdaptiveInterruptionDetector.d.ts +50 -0
- package/dist/inference/interruption/AdaptiveInterruptionDetector.d.ts.map +1 -0
- package/dist/inference/interruption/AdaptiveInterruptionDetector.js +125 -0
- package/dist/inference/interruption/AdaptiveInterruptionDetector.js.map +1 -0
- package/dist/inference/interruption/InterruptionStream.cjs +310 -0
- package/dist/inference/interruption/InterruptionStream.cjs.map +1 -0
- package/dist/inference/interruption/InterruptionStream.d.cts +57 -0
- package/dist/inference/interruption/InterruptionStream.d.ts +57 -0
- package/dist/inference/interruption/InterruptionStream.d.ts.map +1 -0
- package/dist/inference/interruption/InterruptionStream.js +288 -0
- package/dist/inference/interruption/InterruptionStream.js.map +1 -0
- package/dist/inference/interruption/defaults.cjs +76 -0
- package/dist/inference/interruption/defaults.cjs.map +1 -0
- package/dist/inference/interruption/defaults.d.cts +14 -0
- package/dist/inference/interruption/defaults.d.ts +14 -0
- package/dist/inference/interruption/defaults.d.ts.map +1 -0
- package/dist/inference/interruption/defaults.js +42 -0
- package/dist/inference/interruption/defaults.js.map +1 -0
- package/dist/inference/interruption/errors.cjs +2 -0
- package/dist/inference/interruption/errors.cjs.map +1 -0
- package/dist/inference/interruption/errors.d.cts +2 -0
- package/dist/inference/interruption/errors.d.ts +2 -0
- package/dist/inference/interruption/errors.d.ts.map +1 -0
- package/dist/inference/interruption/errors.js +1 -0
- package/dist/inference/interruption/errors.js.map +1 -0
- package/dist/inference/interruption/http_transport.cjs +57 -0
- package/dist/inference/interruption/http_transport.cjs.map +1 -0
- package/dist/inference/interruption/http_transport.d.cts +23 -0
- package/dist/inference/interruption/http_transport.d.ts +23 -0
- package/dist/inference/interruption/http_transport.d.ts.map +1 -0
- package/dist/inference/interruption/http_transport.js +33 -0
- package/dist/inference/interruption/http_transport.js.map +1 -0
- package/dist/inference/interruption/index.cjs +34 -0
- package/dist/inference/interruption/index.cjs.map +1 -0
- package/dist/inference/interruption/index.d.cts +5 -0
- package/dist/inference/interruption/index.d.ts +5 -0
- package/dist/inference/interruption/index.d.ts.map +1 -0
- package/dist/inference/interruption/index.js +7 -0
- package/dist/inference/interruption/index.js.map +1 -0
- package/dist/inference/interruption/interruption.cjs +85 -0
- package/dist/inference/interruption/interruption.cjs.map +1 -0
- package/dist/inference/interruption/interruption.d.cts +48 -0
- package/dist/inference/interruption/interruption.d.ts +48 -0
- package/dist/inference/interruption/interruption.d.ts.map +1 -0
- package/dist/inference/interruption/interruption.js +59 -0
- package/dist/inference/interruption/interruption.js.map +1 -0
- package/dist/inference/llm.cjs +30 -3
- package/dist/inference/llm.cjs.map +1 -1
- package/dist/inference/llm.d.cts +3 -1
- package/dist/inference/llm.d.ts +3 -1
- package/dist/inference/llm.d.ts.map +1 -1
- package/dist/inference/llm.js +30 -3
- package/dist/inference/llm.js.map +1 -1
- package/dist/inference/utils.cjs +15 -2
- package/dist/inference/utils.cjs.map +1 -1
- package/dist/inference/utils.d.cts +1 -0
- package/dist/inference/utils.d.ts +1 -0
- package/dist/inference/utils.d.ts.map +1 -1
- package/dist/inference/utils.js +13 -1
- package/dist/inference/utils.js.map +1 -1
- package/dist/inference/utils.test.cjs +20 -0
- package/dist/inference/utils.test.cjs.map +1 -0
- package/dist/inference/utils.test.js +19 -0
- package/dist/inference/utils.test.js.map +1 -0
- package/dist/ipc/inference_proc_executor.cjs.map +1 -1
- package/dist/ipc/job_proc_executor.cjs.map +1 -1
- package/dist/ipc/job_proc_lazy_main.cjs +1 -1
- package/dist/ipc/job_proc_lazy_main.cjs.map +1 -1
- package/dist/ipc/job_proc_lazy_main.js +1 -1
- package/dist/ipc/job_proc_lazy_main.js.map +1 -1
- package/dist/llm/chat_context.cjs +20 -2
- package/dist/llm/chat_context.cjs.map +1 -1
- package/dist/llm/chat_context.d.cts +9 -0
- package/dist/llm/chat_context.d.ts +9 -0
- package/dist/llm/chat_context.d.ts.map +1 -1
- package/dist/llm/chat_context.js +20 -2
- package/dist/llm/chat_context.js.map +1 -1
- package/dist/llm/llm.cjs.map +1 -1
- package/dist/llm/llm.d.cts +1 -0
- package/dist/llm/llm.d.ts +1 -0
- package/dist/llm/llm.d.ts.map +1 -1
- package/dist/llm/llm.js.map +1 -1
- package/dist/llm/provider_format/openai.cjs +43 -20
- package/dist/llm/provider_format/openai.cjs.map +1 -1
- package/dist/llm/provider_format/openai.d.ts.map +1 -1
- package/dist/llm/provider_format/openai.js +43 -20
- package/dist/llm/provider_format/openai.js.map +1 -1
- package/dist/llm/provider_format/openai.test.cjs +35 -0
- package/dist/llm/provider_format/openai.test.cjs.map +1 -1
- package/dist/llm/provider_format/openai.test.js +35 -0
- package/dist/llm/provider_format/openai.test.js.map +1 -1
- package/dist/llm/provider_format/utils.cjs +1 -1
- package/dist/llm/provider_format/utils.cjs.map +1 -1
- package/dist/llm/provider_format/utils.d.ts.map +1 -1
- package/dist/llm/provider_format/utils.js +1 -1
- package/dist/llm/provider_format/utils.js.map +1 -1
- package/dist/stream/stream_channel.cjs +3 -0
- package/dist/stream/stream_channel.cjs.map +1 -1
- package/dist/stream/stream_channel.d.cts +3 -2
- package/dist/stream/stream_channel.d.ts +3 -2
- package/dist/stream/stream_channel.d.ts.map +1 -1
- package/dist/stream/stream_channel.js +3 -0
- package/dist/stream/stream_channel.js.map +1 -1
- package/dist/telemetry/trace_types.cjs +15 -0
- package/dist/telemetry/trace_types.cjs.map +1 -1
- package/dist/telemetry/trace_types.d.cts +5 -0
- package/dist/telemetry/trace_types.d.ts +5 -0
- package/dist/telemetry/trace_types.d.ts.map +1 -1
- package/dist/telemetry/trace_types.js +10 -0
- package/dist/telemetry/trace_types.js.map +1 -1
- package/dist/utils/ws_transport.cjs +51 -0
- package/dist/utils/ws_transport.cjs.map +1 -0
- package/dist/utils/ws_transport.d.cts +9 -0
- package/dist/utils/ws_transport.d.ts +9 -0
- package/dist/utils/ws_transport.d.ts.map +1 -0
- package/dist/utils/ws_transport.js +17 -0
- package/dist/utils/ws_transport.js.map +1 -0
- package/dist/utils/ws_transport.test.cjs +212 -0
- package/dist/utils/ws_transport.test.cjs.map +1 -0
- package/dist/utils/ws_transport.test.js +211 -0
- package/dist/utils/ws_transport.test.js.map +1 -0
- package/dist/voice/agent_activity.cjs +49 -0
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.cts +14 -0
- package/dist/voice/agent_activity.d.ts +14 -0
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +49 -0
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +12 -1
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +3 -0
- package/dist/voice/agent_session.d.ts +3 -0
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +12 -1
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/audio_recognition.cjs +124 -2
- package/dist/voice/audio_recognition.cjs.map +1 -1
- package/dist/voice/audio_recognition.d.cts +32 -1
- package/dist/voice/audio_recognition.d.ts +32 -1
- package/dist/voice/audio_recognition.d.ts.map +1 -1
- package/dist/voice/audio_recognition.js +127 -2
- package/dist/voice/audio_recognition.js.map +1 -1
- package/dist/voice/background_audio.cjs.map +1 -1
- package/dist/voice/generation.cjs +2 -1
- package/dist/voice/generation.cjs.map +1 -1
- package/dist/voice/generation.d.ts.map +1 -1
- package/dist/voice/generation.js +2 -1
- package/dist/voice/generation.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +2 -0
- package/src/inference/interruption/AdaptiveInterruptionDetector.ts +166 -0
- package/src/inference/interruption/InterruptionStream.ts +397 -0
- package/src/inference/interruption/defaults.ts +33 -0
- package/src/inference/interruption/errors.ts +0 -0
- package/src/inference/interruption/http_transport.ts +61 -0
- package/src/inference/interruption/index.ts +4 -0
- package/src/inference/interruption/interruption.ts +88 -0
- package/src/inference/llm.ts +42 -3
- package/src/inference/utils.test.ts +31 -0
- package/src/inference/utils.ts +15 -0
- package/src/ipc/job_proc_lazy_main.ts +1 -1
- package/src/llm/chat_context.ts +32 -2
- package/src/llm/llm.ts +1 -0
- package/src/llm/provider_format/openai.test.ts +40 -0
- package/src/llm/provider_format/openai.ts +46 -19
- package/src/llm/provider_format/utils.ts +5 -1
- package/src/stream/stream_channel.ts +6 -2
- package/src/telemetry/trace_types.ts +7 -0
- package/src/utils/ws_transport.test.ts +282 -0
- package/src/utils/ws_transport.ts +22 -0
- package/src/voice/agent_activity.ts +61 -0
- package/src/voice/agent_session.ts +22 -2
- package/src/voice/audio_recognition.ts +161 -1
- package/src/voice/generation.ts +1 -0
package/dist/cli.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.43.7_@types+node@22.15.30__postcss@8.4.38_tsx@4.20.4_typescript@5.4.5/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Command, Option } from 'commander';\nimport type { EventEmitter } from 'node:events';\nimport { initializeLogger, log } from './log.js';\nimport { Plugin } from './plugin.js';\nimport { version } from './version.js';\nimport { AgentServer, ServerOptions } from './worker.js';\n\ntype CliArgs = {\n opts: ServerOptions;\n production: boolean;\n watch: boolean;\n event?: EventEmitter;\n room?: string;\n participantIdentity?: string;\n};\n\nconst runServer = async (args: CliArgs) => {\n initializeLogger({ pretty: !args.production, level: args.opts.logLevel });\n const logger = log();\n\n // though `production` is defined in ServerOptions, it will always be overridden by CLI.\n const { production: _, ...opts } = args.opts; // eslint-disable-line @typescript-eslint/no-unused-vars\n const server = new AgentServer(new ServerOptions({ production: args.production, ...opts }));\n\n if (args.room) {\n server.event.once('worker_registered', () => {\n logger.info(`connecting to room ${args.room}`);\n server.simulateJob(args.room!, args.participantIdentity);\n });\n }\n\n process.once('SIGINT', async () => {\n logger.debug('SIGINT received in CLI');\n // allow C-c C-c for force interrupt\n process.once('SIGINT', () => {\n console.log('Force exit (Ctrl+C pressed twice)');\n process.exit(130); // SIGINT exit code\n });\n if (args.production) {\n await server.drain();\n }\n await server.close();\n logger.debug('worker closed due to SIGINT.');\n process.exit(130); // SIGINT exit code\n });\n\n process.once('SIGTERM', async () => {\n logger.debug('SIGTERM received in CLI.');\n if (args.production) {\n await server.drain();\n }\n await server.close();\n logger.debug('worker closed due to SIGTERM.');\n process.exit(143); // SIGTERM exit code\n });\n\n try {\n await server.run();\n } catch {\n logger.fatal('closing worker due to error.');\n process.exit(1);\n }\n};\n\n/**\n * Exposes a CLI for creating a new worker, in development or production mode.\n *\n * @param opts - Options to launch the worker with\n * @example\n * ```\n * if (process.argv[1] === fileURLToPath(import.meta.url)) {\n * cli.runApp(new ServerOptions({ agent: import.meta.filename }));\n * }\n * ```\n */\nexport const runApp = (opts: ServerOptions) => {\n const program = new Command()\n .name('agents')\n .description('LiveKit Agents CLI')\n .version(version)\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('info')\n .env('LOG_LEVEL'),\n )\n .addOption(\n new Option('--url <string>', 'LiveKit server or Cloud project websocket URL').env(\n 'LIVEKIT_URL',\n ),\n )\n .addOption(\n new Option('--api-key <string>', \"LiveKit server or Cloud project's API key\").env(\n 'LIVEKIT_API_KEY',\n ),\n )\n .addOption(\n new Option('--api-secret <string>', \"LiveKit server or Cloud project's API secret\").env(\n 'LIVEKIT_API_SECRET',\n ),\n )\n .addOption(\n new Option('--worker-token <string>', 'Internal use only')\n .env('LIVEKIT_WORKER_TOKEN')\n .hideHelp(),\n )\n .action(() => {\n if (\n // do not run CLI if origin file is agents/ipc/job_main.js\n process.argv[1] !== new URL('ipc/job_main.js', import.meta.url).pathname &&\n process.argv.length < 3\n ) {\n program.help();\n }\n });\n\n program\n .command('start')\n .description('Start the worker in production mode')\n .action(() => {\n const options = program.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n opts.workerToken = options.workerToken || opts.workerToken;\n runServer({\n opts,\n production: true,\n watch: false,\n });\n });\n\n program\n .command('dev')\n .description('Start the worker in development mode')\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('debug')\n .env('LOG_LEVEL'),\n )\n .action(() => {\n const options = program.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n opts.workerToken = options.workerToken || opts.workerToken;\n runServer({\n opts,\n production: false,\n watch: false,\n });\n });\n\n program\n .command('connect')\n .description('Connect to a specific room')\n .requiredOption('--room <string>', 'Room name to connect to')\n .option('--participant-identity <string>', 'Identity of user to listen to')\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('debug')\n .env('LOG_LEVEL'),\n )\n .action((...[, command]) => {\n const options = command.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n opts.workerToken = options.workerToken || opts.workerToken;\n runServer({\n opts,\n production: false,\n watch: false,\n room: options.room,\n participantIdentity: options.participantIdentity,\n });\n });\n\n program\n .command('download-files')\n .description('Download plugin dependency files')\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('debug')\n .env('LOG_LEVEL'),\n )\n .action(() => {\n const options = program.optsWithGlobals();\n initializeLogger({ pretty: true, level: options.logLevel });\n const logger = log();\n\n const downloadFiles = async () => {\n for (const plugin of Plugin.registeredPlugins) {\n logger.info(`Downloading files for ${plugin.title}`);\n try {\n await plugin.downloadFiles();\n logger.info(`Finished downloading files for ${plugin.title}`);\n } catch (error) {\n logger.error(`Failed to download files for ${plugin.title}: ${error}`);\n }\n }\n };\n\n downloadFiles()\n .catch((error) => {\n logger.fatal(`Error during file downloads: ${error}`);\n process.exit(1);\n })\n .finally(() => {\n process.exit(0);\n });\n });\n\n program.parse();\n};\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,OAClD,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEpC,IAAM,gBAAgC,iCAAiB;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AC,SAAS,SAAS,QAAQ,QAAQ,SAAS,OAAO,CAAC,EAC5D,QAAQ,OAAO,EACf,IAAI,WAAW;AAAA,EACpB,EACC,OAAO,MAAM;AACZ,UAAM,UAAU,QAAQ,gBAAgB;AACxC,qCAAiB,EAAE,QAAQ,MAAM,OAAO,QAAQ,SAAS,CAAC;AAC1D,UAAM,aAAS,gBAAI;AAEnB,UAAM,gBAAgB,YAAY;AAChC,iBAAW,UAAU,qBAAO,mBAAmB;AAC7C,eAAO,KAAK,yBAAyB,OAAO,KAAK,EAAE;AACnD,YAAI;AACF,gBAAM,OAAO,cAAc;AAC3B,iBAAO,KAAK,kCAAkC,OAAO,KAAK,EAAE;AAAA,QAC9D,SAAS,OAAO;AACd,iBAAO,MAAM,gCAAgC,OAAO,KAAK,KAAK,KAAK,EAAE;AAAA,QACvE;AAAA,MACF;AAAA,IACF;AAEA,kBAAc,EACX,MAAM,CAAC,UAAU;AAChB,aAAO,MAAM,gCAAgC,KAAK,EAAE;AACpD,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC,EACA,QAAQ,MAAM;AACb,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC;AAAA,EACL,CAAC;AAEH,UAAQ,MAAM;AAChB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.43.7_@types+node@22.15.30__postcss@8.5.6_tsx@4.20.4_typescript@5.4.5/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Command, Option } from 'commander';\nimport type { EventEmitter } from 'node:events';\nimport { initializeLogger, log } from './log.js';\nimport { Plugin } from './plugin.js';\nimport { version } from './version.js';\nimport { AgentServer, ServerOptions } from './worker.js';\n\ntype CliArgs = {\n opts: ServerOptions;\n production: boolean;\n watch: boolean;\n event?: EventEmitter;\n room?: string;\n participantIdentity?: string;\n};\n\nconst runServer = async (args: CliArgs) => {\n initializeLogger({ pretty: !args.production, level: args.opts.logLevel });\n const logger = log();\n\n // though `production` is defined in ServerOptions, it will always be overridden by CLI.\n const { production: _, ...opts } = args.opts; // eslint-disable-line @typescript-eslint/no-unused-vars\n const server = new AgentServer(new ServerOptions({ production: args.production, ...opts }));\n\n if (args.room) {\n server.event.once('worker_registered', () => {\n logger.info(`connecting to room ${args.room}`);\n server.simulateJob(args.room!, args.participantIdentity);\n });\n }\n\n process.once('SIGINT', async () => {\n logger.debug('SIGINT received in CLI');\n // allow C-c C-c for force interrupt\n process.once('SIGINT', () => {\n console.log('Force exit (Ctrl+C pressed twice)');\n process.exit(130); // SIGINT exit code\n });\n if (args.production) {\n await server.drain();\n }\n await server.close();\n logger.debug('worker closed due to SIGINT.');\n process.exit(130); // SIGINT exit code\n });\n\n process.once('SIGTERM', async () => {\n logger.debug('SIGTERM received in CLI.');\n if (args.production) {\n await server.drain();\n }\n await server.close();\n logger.debug('worker closed due to SIGTERM.');\n process.exit(143); // SIGTERM exit code\n });\n\n try {\n await server.run();\n } catch {\n logger.fatal('closing worker due to error.');\n process.exit(1);\n }\n};\n\n/**\n * Exposes a CLI for creating a new worker, in development or production mode.\n *\n * @param opts - Options to launch the worker with\n * @example\n * ```\n * if (process.argv[1] === fileURLToPath(import.meta.url)) {\n * cli.runApp(new ServerOptions({ agent: import.meta.filename }));\n * }\n * ```\n */\nexport const runApp = (opts: ServerOptions) => {\n const program = new Command()\n .name('agents')\n .description('LiveKit Agents CLI')\n .version(version)\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('info')\n .env('LOG_LEVEL'),\n )\n .addOption(\n new Option('--url <string>', 'LiveKit server or Cloud project websocket URL').env(\n 'LIVEKIT_URL',\n ),\n )\n .addOption(\n new Option('--api-key <string>', \"LiveKit server or Cloud project's API key\").env(\n 'LIVEKIT_API_KEY',\n ),\n )\n .addOption(\n new Option('--api-secret <string>', \"LiveKit server or Cloud project's API secret\").env(\n 'LIVEKIT_API_SECRET',\n ),\n )\n .addOption(\n new Option('--worker-token <string>', 'Internal use only')\n .env('LIVEKIT_WORKER_TOKEN')\n .hideHelp(),\n )\n .action(() => {\n if (\n // do not run CLI if origin file is agents/ipc/job_main.js\n process.argv[1] !== new URL('ipc/job_main.js', import.meta.url).pathname &&\n process.argv.length < 3\n ) {\n program.help();\n }\n });\n\n program\n .command('start')\n .description('Start the worker in production mode')\n .action(() => {\n const options = program.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n opts.workerToken = options.workerToken || opts.workerToken;\n runServer({\n opts,\n production: true,\n watch: false,\n });\n });\n\n program\n .command('dev')\n .description('Start the worker in development mode')\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('debug')\n .env('LOG_LEVEL'),\n )\n .action(() => {\n const options = program.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n opts.workerToken = options.workerToken || opts.workerToken;\n runServer({\n opts,\n production: false,\n watch: false,\n });\n });\n\n program\n .command('connect')\n .description('Connect to a specific room')\n .requiredOption('--room <string>', 'Room name to connect to')\n .option('--participant-identity <string>', 'Identity of user to listen to')\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('debug')\n .env('LOG_LEVEL'),\n )\n .action((...[, command]) => {\n const options = command.optsWithGlobals();\n opts.wsURL = options.url || opts.wsURL;\n opts.apiKey = options.apiKey || opts.apiKey;\n opts.apiSecret = options.apiSecret || opts.apiSecret;\n opts.logLevel = options.logLevel || opts.logLevel;\n opts.workerToken = options.workerToken || opts.workerToken;\n runServer({\n opts,\n production: false,\n watch: false,\n room: options.room,\n participantIdentity: options.participantIdentity,\n });\n });\n\n program\n .command('download-files')\n .description('Download plugin dependency files')\n .addOption(\n new Option('--log-level <level>', 'Set the logging level')\n .choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])\n .default('debug')\n .env('LOG_LEVEL'),\n )\n .action(() => {\n const options = program.optsWithGlobals();\n initializeLogger({ pretty: true, level: options.logLevel });\n const logger = log();\n\n const downloadFiles = async () => {\n for (const plugin of Plugin.registeredPlugins) {\n logger.info(`Downloading files for ${plugin.title}`);\n try {\n await plugin.downloadFiles();\n logger.info(`Finished downloading files for ${plugin.title}`);\n } catch (error) {\n logger.error(`Failed to download files for ${plugin.title}: ${error}`);\n }\n }\n };\n\n downloadFiles()\n .catch((error) => {\n logger.fatal(`Error during file downloads: ${error}`);\n process.exit(1);\n })\n .finally(() => {\n process.exit(0);\n });\n });\n\n program.parse();\n};\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,OAClD,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEpC,IAAM,gBAAgC,iCAAiB;ADR9D,uBAAgC;AAEhC,iBAAsC;AACtC,oBAAuB;AACvB,qBAAwB;AACxB,oBAA2C;AAW3C,MAAM,YAAY,OAAO,SAAk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AO,MAAM;AACZ,UAAM,UAAU,QAAQ,gBAAgB;AACxC,qCAAiB,EAAE,QAAQ,MAAM,OAAO,QAAQ,SAAS,CAAC;AAC1D,UAAM,aAAS,gBAAI;AAEnB,UAAM,gBAAgB,YAAY;AAChC,iBAAW,UAAU,qBAAO,mBAAmB;AAC7C,eAAO,KAAK,yBAAyB,OAAO,KAAK,EAAE;AACnD,YAAI;AACF,gBAAM,OAAO,cAAc;AAC3B,iBAAO,KAAK,kCAAkC,OAAO,KAAK,EAAE;AAAA,QAC9D,SAAS,OAAO;AACd,iBAAO,MAAM,gCAAgC,OAAO,KAAK,KAAK,KAAK,EAAE;AAAA,QACvE;AAAA,MACF;AAAA,IACF;AAEA,kBAAc,EACX,MAAM,CAAC,UAAU;AAChB,aAAO,MAAM,gCAAgC,KAAK,EAAE;AACpD,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC,EACA,QAAQ,MAAM;AACb,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC;AAAA,EACL,CAAC;AAEH,UAAQ,MAAM;AAChB;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -67,6 +67,7 @@ __reExport(index_exports, require("./utils.cjs"), module.exports);
|
|
|
67
67
|
__reExport(index_exports, require("./vad.cjs"), module.exports);
|
|
68
68
|
__reExport(index_exports, require("./version.cjs"), module.exports);
|
|
69
69
|
__reExport(index_exports, require("./worker.cjs"), module.exports);
|
|
70
|
+
__reExport(index_exports, require("./inference/interruption/index.cjs"), module.exports);
|
|
70
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
72
|
0 && (module.exports = {
|
|
72
73
|
cli,
|
|
@@ -93,6 +94,7 @@ __reExport(index_exports, require("./worker.cjs"), module.exports);
|
|
|
93
94
|
...require("./utils.cjs"),
|
|
94
95
|
...require("./vad.cjs"),
|
|
95
96
|
...require("./version.cjs"),
|
|
96
|
-
...require("./worker.cjs")
|
|
97
|
+
...require("./worker.cjs"),
|
|
98
|
+
...require("./inference/interruption/index.cjs")
|
|
97
99
|
});
|
|
98
100
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LiveKit Agents is a framework for building realtime programmable participants that run on\n * servers.\n *\n * @see {@link https://docs.livekit.io/agents/overview | LiveKit Agents documentation}\n * @packageDocumentation\n */\nimport * as cli from './cli.js';\nimport * as inference from './inference/index.js';\nimport * as ipc from './ipc/index.js';\nimport * as llm from './llm/index.js';\nimport * as metrics from './metrics/index.js';\nimport * as stream from './stream/index.js';\nimport * as stt from './stt/index.js';\nimport * as telemetry from './telemetry/index.js';\nimport * as tokenize from './tokenize/index.js';\nimport * as tts from './tts/index.js';\nimport * as voice from './voice/index.js';\n\nexport * from './_exceptions.js';\nexport * from './audio.js';\nexport * from './connection_pool.js';\nexport * from './generator.js';\nexport * from './inference_runner.js';\nexport * from './job.js';\nexport * from './log.js';\nexport * from './plugin.js';\nexport * from './transcription.js';\nexport * from './types.js';\nexport * from './utils.js';\nexport * from './vad.js';\nexport * from './version.js';\nexport * from './worker.js';\n\nexport { cli, inference, ipc, llm, metrics, stream, stt, telemetry, tokenize, tts, voice };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,UAAqB;AACrB,gBAA2B;AAC3B,UAAqB;AACrB,UAAqB;AACrB,cAAyB;AACzB,aAAwB;AACxB,UAAqB;AACrB,gBAA2B;AAC3B,eAA0B;AAC1B,UAAqB;AACrB,YAAuB;AAEvB,0BAAc,6BAvBd;AAwBA,0BAAc,uBAxBd;AAyBA,0BAAc,iCAzBd;AA0BA,0BAAc,2BA1Bd;AA2BA,0BAAc,kCA3Bd;AA4BA,0BAAc,qBA5Bd;AA6BA,0BAAc,qBA7Bd;AA8BA,0BAAc,wBA9Bd;AA+BA,0BAAc,+BA/Bd;AAgCA,0BAAc,uBAhCd;AAiCA,0BAAc,uBAjCd;AAkCA,0BAAc,qBAlCd;AAmCA,0BAAc,yBAnCd;AAoCA,0BAAc,wBApCd;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LiveKit Agents is a framework for building realtime programmable participants that run on\n * servers.\n *\n * @see {@link https://docs.livekit.io/agents/overview | LiveKit Agents documentation}\n * @packageDocumentation\n */\nimport * as cli from './cli.js';\nimport * as inference from './inference/index.js';\nimport * as ipc from './ipc/index.js';\nimport * as llm from './llm/index.js';\nimport * as metrics from './metrics/index.js';\nimport * as stream from './stream/index.js';\nimport * as stt from './stt/index.js';\nimport * as telemetry from './telemetry/index.js';\nimport * as tokenize from './tokenize/index.js';\nimport * as tts from './tts/index.js';\nimport * as voice from './voice/index.js';\n\nexport * from './_exceptions.js';\nexport * from './audio.js';\nexport * from './connection_pool.js';\nexport * from './generator.js';\nexport * from './inference_runner.js';\nexport * from './job.js';\nexport * from './log.js';\nexport * from './plugin.js';\nexport * from './transcription.js';\nexport * from './types.js';\nexport * from './utils.js';\nexport * from './vad.js';\nexport * from './version.js';\nexport * from './worker.js';\n\nexport * from './inference/interruption/index.js';\n\nexport { cli, inference, ipc, llm, metrics, stream, stt, telemetry, tokenize, tts, voice };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,UAAqB;AACrB,gBAA2B;AAC3B,UAAqB;AACrB,UAAqB;AACrB,cAAyB;AACzB,aAAwB;AACxB,UAAqB;AACrB,gBAA2B;AAC3B,eAA0B;AAC1B,UAAqB;AACrB,YAAuB;AAEvB,0BAAc,6BAvBd;AAwBA,0BAAc,uBAxBd;AAyBA,0BAAc,iCAzBd;AA0BA,0BAAc,2BA1Bd;AA2BA,0BAAc,kCA3Bd;AA4BA,0BAAc,qBA5Bd;AA6BA,0BAAc,qBA7Bd;AA8BA,0BAAc,wBA9Bd;AA+BA,0BAAc,+BA/Bd;AAgCA,0BAAc,uBAhCd;AAiCA,0BAAc,uBAjCd;AAkCA,0BAAc,qBAlCd;AAmCA,0BAAc,yBAnCd;AAoCA,0BAAc,wBApCd;AAsCA,0BAAc,8CAtCd;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -30,5 +30,6 @@ export * from './utils.js';
|
|
|
30
30
|
export * from './vad.js';
|
|
31
31
|
export * from './version.js';
|
|
32
32
|
export * from './worker.js';
|
|
33
|
+
export * from './inference/interruption/index.js';
|
|
33
34
|
export { cli, inference, ipc, llm, metrics, stream, stt, telemetry, tokenize, tts, voice };
|
|
34
35
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -30,5 +30,6 @@ export * from './utils.js';
|
|
|
30
30
|
export * from './vad.js';
|
|
31
31
|
export * from './version.js';
|
|
32
32
|
export * from './worker.js';
|
|
33
|
+
export * from './inference/interruption/index.js';
|
|
33
34
|
export { cli, inference, ipc, llm, metrics, stream, stt, telemetry, tokenize, tts, voice };
|
|
34
35
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,K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,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAE1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAE5B,cAAc,mCAAmC,CAAC;AAElD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LiveKit Agents is a framework for building realtime programmable participants that run on\n * servers.\n *\n * @see {@link https://docs.livekit.io/agents/overview | LiveKit Agents documentation}\n * @packageDocumentation\n */\nimport * as cli from './cli.js';\nimport * as inference from './inference/index.js';\nimport * as ipc from './ipc/index.js';\nimport * as llm from './llm/index.js';\nimport * as metrics from './metrics/index.js';\nimport * as stream from './stream/index.js';\nimport * as stt from './stt/index.js';\nimport * as telemetry from './telemetry/index.js';\nimport * as tokenize from './tokenize/index.js';\nimport * as tts from './tts/index.js';\nimport * as voice from './voice/index.js';\n\nexport * from './_exceptions.js';\nexport * from './audio.js';\nexport * from './connection_pool.js';\nexport * from './generator.js';\nexport * from './inference_runner.js';\nexport * from './job.js';\nexport * from './log.js';\nexport * from './plugin.js';\nexport * from './transcription.js';\nexport * from './types.js';\nexport * from './utils.js';\nexport * from './vad.js';\nexport * from './version.js';\nexport * from './worker.js';\n\nexport { cli, inference, ipc, llm, metrics, stream, stt, telemetry, tokenize, tts, voice };\n"],"mappings":"AAWA,YAAY,SAAS;AACrB,YAAY,eAAe;AAC3B,YAAY,SAAS;AACrB,YAAY,SAAS;AACrB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,SAAS;AACrB,YAAY,eAAe;AAC3B,YAAY,cAAc;AAC1B,YAAY,SAAS;AACrB,YAAY,WAAW;AAEvB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * LiveKit Agents is a framework for building realtime programmable participants that run on\n * servers.\n *\n * @see {@link https://docs.livekit.io/agents/overview | LiveKit Agents documentation}\n * @packageDocumentation\n */\nimport * as cli from './cli.js';\nimport * as inference from './inference/index.js';\nimport * as ipc from './ipc/index.js';\nimport * as llm from './llm/index.js';\nimport * as metrics from './metrics/index.js';\nimport * as stream from './stream/index.js';\nimport * as stt from './stt/index.js';\nimport * as telemetry from './telemetry/index.js';\nimport * as tokenize from './tokenize/index.js';\nimport * as tts from './tts/index.js';\nimport * as voice from './voice/index.js';\n\nexport * from './_exceptions.js';\nexport * from './audio.js';\nexport * from './connection_pool.js';\nexport * from './generator.js';\nexport * from './inference_runner.js';\nexport * from './job.js';\nexport * from './log.js';\nexport * from './plugin.js';\nexport * from './transcription.js';\nexport * from './types.js';\nexport * from './utils.js';\nexport * from './vad.js';\nexport * from './version.js';\nexport * from './worker.js';\n\nexport * from './inference/interruption/index.js';\n\nexport { cli, inference, ipc, llm, metrics, stream, stt, telemetry, tokenize, tts, voice };\n"],"mappings":"AAWA,YAAY,SAAS;AACrB,YAAY,eAAe;AAC3B,YAAY,SAAS;AACrB,YAAY,SAAS;AACrB,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,SAAS;AACrB,YAAY,eAAe;AAC3B,YAAY,cAAc;AAC1B,YAAY,SAAS;AACrB,YAAY,WAAW;AAEvB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;","names":[]}
|
|
@@ -10,18 +10,18 @@ export declare const ttsSessionCreateEventSchema: z.ZodObject<{
|
|
|
10
10
|
transcript: z.ZodOptional<z.ZodString>;
|
|
11
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
12
|
type: "session.create";
|
|
13
|
+
extra: Record<string, unknown>;
|
|
13
14
|
sample_rate: string;
|
|
14
15
|
encoding: string;
|
|
15
|
-
extra: Record<string, unknown>;
|
|
16
16
|
language?: string | undefined;
|
|
17
17
|
model?: string | undefined;
|
|
18
18
|
transcript?: string | undefined;
|
|
19
19
|
voice?: string | undefined;
|
|
20
20
|
}, {
|
|
21
21
|
type: "session.create";
|
|
22
|
+
extra: Record<string, unknown>;
|
|
22
23
|
sample_rate: string;
|
|
23
24
|
encoding: string;
|
|
24
|
-
extra: Record<string, unknown>;
|
|
25
25
|
language?: string | undefined;
|
|
26
26
|
model?: string | undefined;
|
|
27
27
|
transcript?: string | undefined;
|
|
@@ -118,18 +118,18 @@ export declare const ttsClientEventSchema: z.ZodDiscriminatedUnion<"type", [z.Zo
|
|
|
118
118
|
transcript: z.ZodOptional<z.ZodString>;
|
|
119
119
|
}, "strip", z.ZodTypeAny, {
|
|
120
120
|
type: "session.create";
|
|
121
|
+
extra: Record<string, unknown>;
|
|
121
122
|
sample_rate: string;
|
|
122
123
|
encoding: string;
|
|
123
|
-
extra: Record<string, unknown>;
|
|
124
124
|
language?: string | undefined;
|
|
125
125
|
model?: string | undefined;
|
|
126
126
|
transcript?: string | undefined;
|
|
127
127
|
voice?: string | undefined;
|
|
128
128
|
}, {
|
|
129
129
|
type: "session.create";
|
|
130
|
+
extra: Record<string, unknown>;
|
|
130
131
|
sample_rate: string;
|
|
131
132
|
encoding: string;
|
|
132
|
-
extra: Record<string, unknown>;
|
|
133
133
|
language?: string | undefined;
|
|
134
134
|
model?: string | undefined;
|
|
135
135
|
transcript?: string | undefined;
|
|
@@ -10,18 +10,18 @@ export declare const ttsSessionCreateEventSchema: z.ZodObject<{
|
|
|
10
10
|
transcript: z.ZodOptional<z.ZodString>;
|
|
11
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
12
|
type: "session.create";
|
|
13
|
+
extra: Record<string, unknown>;
|
|
13
14
|
sample_rate: string;
|
|
14
15
|
encoding: string;
|
|
15
|
-
extra: Record<string, unknown>;
|
|
16
16
|
language?: string | undefined;
|
|
17
17
|
model?: string | undefined;
|
|
18
18
|
transcript?: string | undefined;
|
|
19
19
|
voice?: string | undefined;
|
|
20
20
|
}, {
|
|
21
21
|
type: "session.create";
|
|
22
|
+
extra: Record<string, unknown>;
|
|
22
23
|
sample_rate: string;
|
|
23
24
|
encoding: string;
|
|
24
|
-
extra: Record<string, unknown>;
|
|
25
25
|
language?: string | undefined;
|
|
26
26
|
model?: string | undefined;
|
|
27
27
|
transcript?: string | undefined;
|
|
@@ -118,18 +118,18 @@ export declare const ttsClientEventSchema: z.ZodDiscriminatedUnion<"type", [z.Zo
|
|
|
118
118
|
transcript: z.ZodOptional<z.ZodString>;
|
|
119
119
|
}, "strip", z.ZodTypeAny, {
|
|
120
120
|
type: "session.create";
|
|
121
|
+
extra: Record<string, unknown>;
|
|
121
122
|
sample_rate: string;
|
|
122
123
|
encoding: string;
|
|
123
|
-
extra: Record<string, unknown>;
|
|
124
124
|
language?: string | undefined;
|
|
125
125
|
model?: string | undefined;
|
|
126
126
|
transcript?: string | undefined;
|
|
127
127
|
voice?: string | undefined;
|
|
128
128
|
}, {
|
|
129
129
|
type: "session.create";
|
|
130
|
+
extra: Record<string, unknown>;
|
|
130
131
|
sample_rate: string;
|
|
131
132
|
encoding: string;
|
|
132
|
-
extra: Record<string, unknown>;
|
|
133
133
|
language?: string | undefined;
|
|
134
134
|
model?: string | undefined;
|
|
135
135
|
transcript?: string | undefined;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var AdaptiveInterruptionDetector_exports = {};
|
|
30
|
+
__export(AdaptiveInterruptionDetector_exports, {
|
|
31
|
+
AdaptiveInterruptionDetector: () => AdaptiveInterruptionDetector
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(AdaptiveInterruptionDetector_exports);
|
|
34
|
+
var import_events = __toESM(require("events"), 1);
|
|
35
|
+
var import_web = require("stream/web");
|
|
36
|
+
var import_InterruptionStream = require("./InterruptionStream.cjs");
|
|
37
|
+
var import_defaults = require("./defaults.cjs");
|
|
38
|
+
var import_interruption = require("./interruption.cjs");
|
|
39
|
+
class AdaptiveInterruptionDetector extends import_events.default {
|
|
40
|
+
options;
|
|
41
|
+
label;
|
|
42
|
+
streams;
|
|
43
|
+
// TODO: Union of InterruptionHttpStream | InterruptionWebSocketStream
|
|
44
|
+
constructor(options = {}) {
|
|
45
|
+
super();
|
|
46
|
+
const {
|
|
47
|
+
maxAudioDuration,
|
|
48
|
+
baseUrl,
|
|
49
|
+
apiKey,
|
|
50
|
+
apiSecret,
|
|
51
|
+
useProxy: useProxyArg,
|
|
52
|
+
audioPrefixDuration,
|
|
53
|
+
threshold,
|
|
54
|
+
detectionInterval,
|
|
55
|
+
inferenceTimeout,
|
|
56
|
+
minInterruptionDuration
|
|
57
|
+
} = { ...import_defaults.interruptionOptionDefaults, ...options };
|
|
58
|
+
if (maxAudioDuration > 3) {
|
|
59
|
+
throw new Error("maxAudioDuration must be less than or equal to 3.0 seconds");
|
|
60
|
+
}
|
|
61
|
+
const lkBaseUrl = baseUrl ?? process.env.LIVEKIT_REMOTE_EOT_URL ?? import_defaults.DEFAULT_BASE_URL;
|
|
62
|
+
let lkApiKey = apiKey ?? "";
|
|
63
|
+
let lkApiSecret = apiSecret ?? "";
|
|
64
|
+
let useProxy;
|
|
65
|
+
if (lkBaseUrl === import_defaults.DEFAULT_BASE_URL) {
|
|
66
|
+
lkApiKey = apiKey ?? process.env.LIVEKIT_INFERENCE_API_KEY ?? process.env.LIVEKIT_API_KEY ?? "";
|
|
67
|
+
if (!lkApiKey) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
"apiKey is required, either as argument or set LIVEKIT_API_KEY environmental variable"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
lkApiSecret = apiSecret ?? process.env.LIVEKIT_INFERENCE_API_SECRET ?? process.env.LIVEKIT_API_SECRET ?? "";
|
|
73
|
+
if (!lkApiSecret) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
"apiSecret is required, either as argument or set LIVEKIT_API_SECRET environmental variable"
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
useProxy = true;
|
|
79
|
+
} else {
|
|
80
|
+
useProxy = useProxyArg ?? false;
|
|
81
|
+
}
|
|
82
|
+
this.options = {
|
|
83
|
+
sampleRate: import_defaults.SAMPLE_RATE,
|
|
84
|
+
threshold,
|
|
85
|
+
minFrames: Math.ceil(minInterruptionDuration * import_defaults.FRAMES_PER_SECOND),
|
|
86
|
+
maxAudioDuration,
|
|
87
|
+
audioPrefixDuration,
|
|
88
|
+
detectionInterval,
|
|
89
|
+
inferenceTimeout,
|
|
90
|
+
baseUrl: lkBaseUrl,
|
|
91
|
+
apiKey: lkApiKey,
|
|
92
|
+
apiSecret: lkApiSecret,
|
|
93
|
+
useProxy,
|
|
94
|
+
minInterruptionDuration
|
|
95
|
+
};
|
|
96
|
+
this.label = `${this.constructor.name}`;
|
|
97
|
+
this.streams = /* @__PURE__ */ new WeakSet();
|
|
98
|
+
console.info("adaptive interruption detector initialized", {
|
|
99
|
+
baseUrl: this.options.baseUrl,
|
|
100
|
+
detectionInterval: this.options.detectionInterval,
|
|
101
|
+
audioPrefixDuration: this.options.audioPrefixDuration,
|
|
102
|
+
maxAudioDuration: this.options.maxAudioDuration,
|
|
103
|
+
minFrames: this.options.minFrames,
|
|
104
|
+
threshold: this.options.threshold,
|
|
105
|
+
inferenceTimeout: this.options.inferenceTimeout,
|
|
106
|
+
useProxy: this.options.useProxy
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new InterruptionStreamBase for internal use.
|
|
111
|
+
* The stream can receive audio frames and sentinels via pushFrame().
|
|
112
|
+
* Use this when you need direct access to the stream for pushing frames.
|
|
113
|
+
*/
|
|
114
|
+
createStream() {
|
|
115
|
+
const stream = new import_InterruptionStream.InterruptionStreamBase(this, {});
|
|
116
|
+
this.streams.add(stream);
|
|
117
|
+
return stream;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Creates a new interruption stream and returns a ReadableStream of InterruptionEvents.
|
|
121
|
+
* This is a convenience method for consuming interruption events without needing
|
|
122
|
+
* to manage the underlying stream directly.
|
|
123
|
+
*/
|
|
124
|
+
stream() {
|
|
125
|
+
const httpStream = this.createStream();
|
|
126
|
+
const transformer = new import_web.TransformStream({
|
|
127
|
+
transform: (chunk, controller) => {
|
|
128
|
+
if (chunk.type === import_interruption.InterruptionEventType.INTERRUPTION) {
|
|
129
|
+
this.emit("interruptionDetected");
|
|
130
|
+
} else if (chunk.type === import_interruption.InterruptionEventType.OVERLAP_SPEECH_ENDED) {
|
|
131
|
+
this.emit("overlapSpeechDetected");
|
|
132
|
+
}
|
|
133
|
+
controller.enqueue(chunk);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const stream = httpStream.stream.pipeThrough(transformer);
|
|
137
|
+
return stream;
|
|
138
|
+
}
|
|
139
|
+
updateOptions(options) {
|
|
140
|
+
if (options.threshold !== void 0) {
|
|
141
|
+
this.options.threshold = options.threshold;
|
|
142
|
+
}
|
|
143
|
+
if (options.minInterruptionDuration !== void 0) {
|
|
144
|
+
this.options.minFrames = Math.ceil(options.minInterruptionDuration * import_defaults.FRAMES_PER_SECOND);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
149
|
+
0 && (module.exports = {
|
|
150
|
+
AdaptiveInterruptionDetector
|
|
151
|
+
});
|
|
152
|
+
//# sourceMappingURL=AdaptiveInterruptionDetector.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/inference/interruption/AdaptiveInterruptionDetector.ts"],"sourcesContent":["import type { TypedEventEmitter } from '@livekit/typed-emitter';\nimport EventEmitter from 'events';\nimport { type ReadableStream, TransformStream } from 'stream/web';\nimport { InterruptionStreamBase } from './InterruptionStream.js';\nimport {\n DEFAULT_BASE_URL,\n FRAMES_PER_SECOND,\n SAMPLE_RATE,\n interruptionOptionDefaults,\n} from './defaults.js';\nimport {\n type InterruptionDetectionError,\n type InterruptionEvent,\n InterruptionEventType,\n} from './interruption.js';\n\ntype InterruptionCallbacks = {\n interruptionDetected: () => void;\n overlapSpeechDetected: () => void;\n error: (error: InterruptionDetectionError) => void;\n};\n\nexport interface InterruptionOptions {\n sampleRate: number;\n threshold: number;\n minFrames: number;\n maxAudioDuration: number;\n audioPrefixDuration: number;\n detectionInterval: number;\n inferenceTimeout: number;\n minInterruptionDuration: number;\n baseUrl: string;\n apiKey: string;\n apiSecret: string;\n useProxy: boolean;\n}\n\nexport type AdaptiveInterruptionDetectorOptions = Partial<InterruptionOptions>;\n\nexport class AdaptiveInterruptionDetector extends (EventEmitter as new () => TypedEventEmitter<InterruptionCallbacks>) {\n options: InterruptionOptions;\n private label: string;\n private streams: WeakSet<object>; // TODO: Union of InterruptionHttpStream | InterruptionWebSocketStream\n\n constructor(options: AdaptiveInterruptionDetectorOptions = {}) {\n super();\n\n const {\n maxAudioDuration,\n baseUrl,\n apiKey,\n apiSecret,\n useProxy: useProxyArg,\n audioPrefixDuration,\n threshold,\n detectionInterval,\n inferenceTimeout,\n minInterruptionDuration,\n } = { ...interruptionOptionDefaults, ...options };\n\n if (maxAudioDuration > 3.0) {\n throw new Error('maxAudioDuration must be less than or equal to 3.0 seconds');\n }\n\n const lkBaseUrl = baseUrl ?? process.env.LIVEKIT_REMOTE_EOT_URL ?? DEFAULT_BASE_URL;\n let lkApiKey = apiKey ?? '';\n let lkApiSecret = apiSecret ?? '';\n let useProxy: boolean;\n\n // use LiveKit credentials if using the default base URL (inference)\n if (lkBaseUrl === DEFAULT_BASE_URL) {\n lkApiKey =\n apiKey ?? process.env.LIVEKIT_INFERENCE_API_KEY ?? process.env.LIVEKIT_API_KEY ?? '';\n if (!lkApiKey) {\n throw new Error(\n 'apiKey is required, either as argument or set LIVEKIT_API_KEY environmental variable',\n );\n }\n\n lkApiSecret =\n apiSecret ??\n process.env.LIVEKIT_INFERENCE_API_SECRET ??\n process.env.LIVEKIT_API_SECRET ??\n '';\n if (!lkApiSecret) {\n throw new Error(\n 'apiSecret is required, either as argument or set LIVEKIT_API_SECRET environmental variable',\n );\n }\n\n useProxy = true;\n } else {\n useProxy = useProxyArg ?? false;\n }\n\n this.options = {\n sampleRate: SAMPLE_RATE,\n threshold,\n minFrames: Math.ceil(minInterruptionDuration * FRAMES_PER_SECOND),\n maxAudioDuration,\n audioPrefixDuration,\n detectionInterval,\n inferenceTimeout,\n baseUrl: lkBaseUrl,\n apiKey: lkApiKey,\n apiSecret: lkApiSecret,\n useProxy,\n minInterruptionDuration,\n };\n\n this.label = `${this.constructor.name}`;\n this.streams = new WeakSet();\n\n console.info('adaptive interruption detector initialized', {\n baseUrl: this.options.baseUrl,\n detectionInterval: this.options.detectionInterval,\n audioPrefixDuration: this.options.audioPrefixDuration,\n maxAudioDuration: this.options.maxAudioDuration,\n minFrames: this.options.minFrames,\n threshold: this.options.threshold,\n inferenceTimeout: this.options.inferenceTimeout,\n useProxy: this.options.useProxy,\n });\n }\n\n /**\n * Creates a new InterruptionStreamBase for internal use.\n * The stream can receive audio frames and sentinels via pushFrame().\n * Use this when you need direct access to the stream for pushing frames.\n */\n createStream(): InterruptionStreamBase {\n const stream = new InterruptionStreamBase(this, {});\n this.streams.add(stream);\n return stream;\n }\n\n /**\n * Creates a new interruption stream and returns a ReadableStream of InterruptionEvents.\n * This is a convenience method for consuming interruption events without needing\n * to manage the underlying stream directly.\n */\n stream(): ReadableStream<InterruptionEvent> {\n const httpStream = this.createStream();\n const transformer = new TransformStream<InterruptionEvent, InterruptionEvent>({\n transform: (chunk, controller) => {\n if (chunk.type === InterruptionEventType.INTERRUPTION) {\n this.emit('interruptionDetected'); // TODO payload\n } else if (chunk.type === InterruptionEventType.OVERLAP_SPEECH_ENDED) {\n this.emit('overlapSpeechDetected'); // TODO payload\n }\n controller.enqueue(chunk);\n },\n });\n const stream = httpStream.stream.pipeThrough(transformer);\n return stream;\n }\n\n updateOptions(options: { threshold?: number; minInterruptionDuration?: number }): void {\n if (options.threshold !== undefined) {\n this.options.threshold = options.threshold;\n }\n if (options.minInterruptionDuration !== undefined) {\n this.options.minFrames = Math.ceil(options.minInterruptionDuration * FRAMES_PER_SECOND);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAyB;AACzB,iBAAqD;AACrD,gCAAuC;AACvC,sBAKO;AACP,0BAIO;AAyBA,MAAM,qCAAsC,cAAAA,QAAoE;AAAA,EACrH;AAAA,EACQ;AAAA,EACA;AAAA;AAAA,EAER,YAAY,UAA+C,CAAC,GAAG;AAC7D,UAAM;AAEN,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI,EAAE,GAAG,4CAA4B,GAAG,QAAQ;AAEhD,QAAI,mBAAmB,GAAK;AAC1B,YAAM,I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AAI,MAAM;AACvB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAA4C;AAC1C,UAAM,aAAa,KAAK,aAAa;AACrC,UAAM,cAAc,IAAI,2BAAsD;AAAA,MAC5E,WAAW,CAAC,OAAO,eAAe;AAChC,YAAI,MAAM,SAAS,0CAAsB,cAAc;AACrD,eAAK,KAAK,sBAAsB;AAAA,QAClC,WAAW,MAAM,SAAS,0CAAsB,sBAAsB;AACpE,eAAK,KAAK,uBAAuB;AAAA,QACnC;AACA,mBAAW,QAAQ,KAAK;AAAA,MAC1B;AAAA,IACF,CAAC;AACD,UAAM,SAAS,WAAW,OAAO,YAAY,WAAW;AACxD,WAAO;AAAA,EACT;AAAA,EAEA,cAAc,SAAyE;AACrF,QAAI,QAAQ,cAAc,QAAW;AACnC,WAAK,QAAQ,YAAY,QAAQ;AAAA,IACnC;AACA,QAAI,QAAQ,4BAA4B,QAAW;AACjD,WAAK,QAAQ,YAAY,KAAK,KAAK,QAAQ,0BAA0B,iCAAiB;AAAA,IACxF;AAAA,EACF;AACF;","names":["EventEmitter"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { TypedEventEmitter } from '@livekit/typed-emitter';
|
|
3
|
+
import { type ReadableStream } from 'stream/web';
|
|
4
|
+
import { InterruptionStreamBase } from './InterruptionStream.js';
|
|
5
|
+
import { type InterruptionDetectionError, type InterruptionEvent } from './interruption.js';
|
|
6
|
+
type InterruptionCallbacks = {
|
|
7
|
+
interruptionDetected: () => void;
|
|
8
|
+
overlapSpeechDetected: () => void;
|
|
9
|
+
error: (error: InterruptionDetectionError) => void;
|
|
10
|
+
};
|
|
11
|
+
export interface InterruptionOptions {
|
|
12
|
+
sampleRate: number;
|
|
13
|
+
threshold: number;
|
|
14
|
+
minFrames: number;
|
|
15
|
+
maxAudioDuration: number;
|
|
16
|
+
audioPrefixDuration: number;
|
|
17
|
+
detectionInterval: number;
|
|
18
|
+
inferenceTimeout: number;
|
|
19
|
+
minInterruptionDuration: number;
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
apiKey: string;
|
|
22
|
+
apiSecret: string;
|
|
23
|
+
useProxy: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type AdaptiveInterruptionDetectorOptions = Partial<InterruptionOptions>;
|
|
26
|
+
declare const AdaptiveInterruptionDetector_base: new () => TypedEventEmitter<InterruptionCallbacks>;
|
|
27
|
+
export declare class AdaptiveInterruptionDetector extends AdaptiveInterruptionDetector_base {
|
|
28
|
+
options: InterruptionOptions;
|
|
29
|
+
private label;
|
|
30
|
+
private streams;
|
|
31
|
+
constructor(options?: AdaptiveInterruptionDetectorOptions);
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new InterruptionStreamBase for internal use.
|
|
34
|
+
* The stream can receive audio frames and sentinels via pushFrame().
|
|
35
|
+
* Use this when you need direct access to the stream for pushing frames.
|
|
36
|
+
*/
|
|
37
|
+
createStream(): InterruptionStreamBase;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new interruption stream and returns a ReadableStream of InterruptionEvents.
|
|
40
|
+
* This is a convenience method for consuming interruption events without needing
|
|
41
|
+
* to manage the underlying stream directly.
|
|
42
|
+
*/
|
|
43
|
+
stream(): ReadableStream<InterruptionEvent>;
|
|
44
|
+
updateOptions(options: {
|
|
45
|
+
threshold?: number;
|
|
46
|
+
minInterruptionDuration?: number;
|
|
47
|
+
}): void;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=AdaptiveInterruptionDetector.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { TypedEventEmitter } from '@livekit/typed-emitter';
|
|
3
|
+
import { type ReadableStream } from 'stream/web';
|
|
4
|
+
import { InterruptionStreamBase } from './InterruptionStream.js';
|
|
5
|
+
import { type InterruptionDetectionError, type InterruptionEvent } from './interruption.js';
|
|
6
|
+
type InterruptionCallbacks = {
|
|
7
|
+
interruptionDetected: () => void;
|
|
8
|
+
overlapSpeechDetected: () => void;
|
|
9
|
+
error: (error: InterruptionDetectionError) => void;
|
|
10
|
+
};
|
|
11
|
+
export interface InterruptionOptions {
|
|
12
|
+
sampleRate: number;
|
|
13
|
+
threshold: number;
|
|
14
|
+
minFrames: number;
|
|
15
|
+
maxAudioDuration: number;
|
|
16
|
+
audioPrefixDuration: number;
|
|
17
|
+
detectionInterval: number;
|
|
18
|
+
inferenceTimeout: number;
|
|
19
|
+
minInterruptionDuration: number;
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
apiKey: string;
|
|
22
|
+
apiSecret: string;
|
|
23
|
+
useProxy: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type AdaptiveInterruptionDetectorOptions = Partial<InterruptionOptions>;
|
|
26
|
+
declare const AdaptiveInterruptionDetector_base: new () => TypedEventEmitter<InterruptionCallbacks>;
|
|
27
|
+
export declare class AdaptiveInterruptionDetector extends AdaptiveInterruptionDetector_base {
|
|
28
|
+
options: InterruptionOptions;
|
|
29
|
+
private label;
|
|
30
|
+
private streams;
|
|
31
|
+
constructor(options?: AdaptiveInterruptionDetectorOptions);
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new InterruptionStreamBase for internal use.
|
|
34
|
+
* The stream can receive audio frames and sentinels via pushFrame().
|
|
35
|
+
* Use this when you need direct access to the stream for pushing frames.
|
|
36
|
+
*/
|
|
37
|
+
createStream(): InterruptionStreamBase;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new interruption stream and returns a ReadableStream of InterruptionEvents.
|
|
40
|
+
* This is a convenience method for consuming interruption events without needing
|
|
41
|
+
* to manage the underlying stream directly.
|
|
42
|
+
*/
|
|
43
|
+
stream(): ReadableStream<InterruptionEvent>;
|
|
44
|
+
updateOptions(options: {
|
|
45
|
+
threshold?: number;
|
|
46
|
+
minInterruptionDuration?: number;
|
|
47
|
+
}): void;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=AdaptiveInterruptionDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdaptiveInterruptionDetector.d.ts","sourceRoot":"","sources":["../../../src/inference/interruption/AdaptiveInterruptionDetector.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAOjE,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EAEvB,MAAM,mBAAmB,CAAC;AAE3B,KAAK,qBAAqB,GAAG;IAC3B,oBAAoB,EAAE,MAAM,IAAI,CAAC;IACjC,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,KAAK,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,CAAC;CACpD,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,uBAAuB,EAAE,MAAM,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,mCAAmC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;2DAEF,kBAAkB,qBAAqB,CAAC;AAArH,qBAAa,4BAA6B,SAAQ,iCAAoE;IACpH,OAAO,EAAE,mBAAmB,CAAC;IAC7B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,OAAO,CAAkB;gBAErB,OAAO,GAAE,mCAAwC;IAiF7D;;;;OAIG;IACH,YAAY,IAAI,sBAAsB;IAMtC;;;;OAIG;IACH,MAAM,IAAI,cAAc,CAAC,iBAAiB,CAAC;IAgB3C,aAAa,CAAC,OAAO,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,uBAAuB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAQvF"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import EventEmitter from "events";
|
|
2
|
+
import { TransformStream } from "stream/web";
|
|
3
|
+
import { InterruptionStreamBase } from "./InterruptionStream.js";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_BASE_URL,
|
|
6
|
+
FRAMES_PER_SECOND,
|
|
7
|
+
SAMPLE_RATE,
|
|
8
|
+
interruptionOptionDefaults
|
|
9
|
+
} from "./defaults.js";
|
|
10
|
+
import {
|
|
11
|
+
InterruptionEventType
|
|
12
|
+
} from "./interruption.js";
|
|
13
|
+
class AdaptiveInterruptionDetector extends EventEmitter {
|
|
14
|
+
options;
|
|
15
|
+
label;
|
|
16
|
+
streams;
|
|
17
|
+
// TODO: Union of InterruptionHttpStream | InterruptionWebSocketStream
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
super();
|
|
20
|
+
const {
|
|
21
|
+
maxAudioDuration,
|
|
22
|
+
baseUrl,
|
|
23
|
+
apiKey,
|
|
24
|
+
apiSecret,
|
|
25
|
+
useProxy: useProxyArg,
|
|
26
|
+
audioPrefixDuration,
|
|
27
|
+
threshold,
|
|
28
|
+
detectionInterval,
|
|
29
|
+
inferenceTimeout,
|
|
30
|
+
minInterruptionDuration
|
|
31
|
+
} = { ...interruptionOptionDefaults, ...options };
|
|
32
|
+
if (maxAudioDuration > 3) {
|
|
33
|
+
throw new Error("maxAudioDuration must be less than or equal to 3.0 seconds");
|
|
34
|
+
}
|
|
35
|
+
const lkBaseUrl = baseUrl ?? process.env.LIVEKIT_REMOTE_EOT_URL ?? DEFAULT_BASE_URL;
|
|
36
|
+
let lkApiKey = apiKey ?? "";
|
|
37
|
+
let lkApiSecret = apiSecret ?? "";
|
|
38
|
+
let useProxy;
|
|
39
|
+
if (lkBaseUrl === DEFAULT_BASE_URL) {
|
|
40
|
+
lkApiKey = apiKey ?? process.env.LIVEKIT_INFERENCE_API_KEY ?? process.env.LIVEKIT_API_KEY ?? "";
|
|
41
|
+
if (!lkApiKey) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
"apiKey is required, either as argument or set LIVEKIT_API_KEY environmental variable"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
lkApiSecret = apiSecret ?? process.env.LIVEKIT_INFERENCE_API_SECRET ?? process.env.LIVEKIT_API_SECRET ?? "";
|
|
47
|
+
if (!lkApiSecret) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
"apiSecret is required, either as argument or set LIVEKIT_API_SECRET environmental variable"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
useProxy = true;
|
|
53
|
+
} else {
|
|
54
|
+
useProxy = useProxyArg ?? false;
|
|
55
|
+
}
|
|
56
|
+
this.options = {
|
|
57
|
+
sampleRate: SAMPLE_RATE,
|
|
58
|
+
threshold,
|
|
59
|
+
minFrames: Math.ceil(minInterruptionDuration * FRAMES_PER_SECOND),
|
|
60
|
+
maxAudioDuration,
|
|
61
|
+
audioPrefixDuration,
|
|
62
|
+
detectionInterval,
|
|
63
|
+
inferenceTimeout,
|
|
64
|
+
baseUrl: lkBaseUrl,
|
|
65
|
+
apiKey: lkApiKey,
|
|
66
|
+
apiSecret: lkApiSecret,
|
|
67
|
+
useProxy,
|
|
68
|
+
minInterruptionDuration
|
|
69
|
+
};
|
|
70
|
+
this.label = `${this.constructor.name}`;
|
|
71
|
+
this.streams = /* @__PURE__ */ new WeakSet();
|
|
72
|
+
console.info("adaptive interruption detector initialized", {
|
|
73
|
+
baseUrl: this.options.baseUrl,
|
|
74
|
+
detectionInterval: this.options.detectionInterval,
|
|
75
|
+
audioPrefixDuration: this.options.audioPrefixDuration,
|
|
76
|
+
maxAudioDuration: this.options.maxAudioDuration,
|
|
77
|
+
minFrames: this.options.minFrames,
|
|
78
|
+
threshold: this.options.threshold,
|
|
79
|
+
inferenceTimeout: this.options.inferenceTimeout,
|
|
80
|
+
useProxy: this.options.useProxy
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new InterruptionStreamBase for internal use.
|
|
85
|
+
* The stream can receive audio frames and sentinels via pushFrame().
|
|
86
|
+
* Use this when you need direct access to the stream for pushing frames.
|
|
87
|
+
*/
|
|
88
|
+
createStream() {
|
|
89
|
+
const stream = new InterruptionStreamBase(this, {});
|
|
90
|
+
this.streams.add(stream);
|
|
91
|
+
return stream;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new interruption stream and returns a ReadableStream of InterruptionEvents.
|
|
95
|
+
* This is a convenience method for consuming interruption events without needing
|
|
96
|
+
* to manage the underlying stream directly.
|
|
97
|
+
*/
|
|
98
|
+
stream() {
|
|
99
|
+
const httpStream = this.createStream();
|
|
100
|
+
const transformer = new TransformStream({
|
|
101
|
+
transform: (chunk, controller) => {
|
|
102
|
+
if (chunk.type === InterruptionEventType.INTERRUPTION) {
|
|
103
|
+
this.emit("interruptionDetected");
|
|
104
|
+
} else if (chunk.type === InterruptionEventType.OVERLAP_SPEECH_ENDED) {
|
|
105
|
+
this.emit("overlapSpeechDetected");
|
|
106
|
+
}
|
|
107
|
+
controller.enqueue(chunk);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const stream = httpStream.stream.pipeThrough(transformer);
|
|
111
|
+
return stream;
|
|
112
|
+
}
|
|
113
|
+
updateOptions(options) {
|
|
114
|
+
if (options.threshold !== void 0) {
|
|
115
|
+
this.options.threshold = options.threshold;
|
|
116
|
+
}
|
|
117
|
+
if (options.minInterruptionDuration !== void 0) {
|
|
118
|
+
this.options.minFrames = Math.ceil(options.minInterruptionDuration * FRAMES_PER_SECOND);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
AdaptiveInterruptionDetector
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=AdaptiveInterruptionDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/inference/interruption/AdaptiveInterruptionDetector.ts"],"sourcesContent":["import type { TypedEventEmitter } from '@livekit/typed-emitter';\nimport EventEmitter from 'events';\nimport { type ReadableStream, TransformStream } from 'stream/web';\nimport { InterruptionStreamBase } from './InterruptionStream.js';\nimport {\n DEFAULT_BASE_URL,\n FRAMES_PER_SECOND,\n SAMPLE_RATE,\n interruptionOptionDefaults,\n} from './defaults.js';\nimport {\n type InterruptionDetectionError,\n type InterruptionEvent,\n InterruptionEventType,\n} from './interruption.js';\n\ntype InterruptionCallbacks = {\n interruptionDetected: () => void;\n overlapSpeechDetected: () => void;\n error: (error: InterruptionDetectionError) => void;\n};\n\nexport interface InterruptionOptions {\n sampleRate: number;\n threshold: number;\n minFrames: number;\n maxAudioDuration: number;\n audioPrefixDuration: number;\n detectionInterval: number;\n inferenceTimeout: number;\n minInterruptionDuration: number;\n baseUrl: string;\n apiKey: string;\n apiSecret: string;\n useProxy: boolean;\n}\n\nexport type AdaptiveInterruptionDetectorOptions = Partial<InterruptionOptions>;\n\nexport class AdaptiveInterruptionDetector extends (EventEmitter as new () => TypedEventEmitter<InterruptionCallbacks>) {\n options: InterruptionOptions;\n private label: string;\n private streams: WeakSet<object>; // TODO: Union of InterruptionHttpStream | InterruptionWebSocketStream\n\n constructor(options: AdaptiveInterruptionDetectorOptions = {}) {\n super();\n\n const {\n maxAudioDuration,\n baseUrl,\n apiKey,\n apiSecret,\n useProxy: useProxyArg,\n audioPrefixDuration,\n threshold,\n detectionInterval,\n inferenceTimeout,\n minInterruptionDuration,\n } = { ...interruptionOptionDefaults, ...options };\n\n if (maxAudioDuration > 3.0) {\n throw new Error('maxAudioDuration must be less than or equal to 3.0 seconds');\n }\n\n const lkBaseUrl = baseUrl ?? process.env.LIVEKIT_REMOTE_EOT_URL ?? DEFAULT_BASE_URL;\n let lkApiKey = apiKey ?? '';\n let lkApiSecret = apiSecret ?? '';\n let useProxy: boolean;\n\n // use LiveKit credentials if using the default base URL (inference)\n if (lkBaseUrl === DEFAULT_BASE_URL) {\n lkApiKey =\n apiKey ?? process.env.LIVEKIT_INFERENCE_API_KEY ?? process.env.LIVEKIT_API_KEY ?? '';\n if (!lkApiKey) {\n throw new Error(\n 'apiKey is required, either as argument or set LIVEKIT_API_KEY environmental variable',\n );\n }\n\n lkApiSecret =\n apiSecret ??\n process.env.LIVEKIT_INFERENCE_API_SECRET ??\n process.env.LIVEKIT_API_SECRET ??\n '';\n if (!lkApiSecret) {\n throw new Error(\n 'apiSecret is required, either as argument or set LIVEKIT_API_SECRET environmental variable',\n );\n }\n\n useProxy = true;\n } else {\n useProxy = useProxyArg ?? false;\n }\n\n this.options = {\n sampleRate: SAMPLE_RATE,\n threshold,\n minFrames: Math.ceil(minInterruptionDuration * FRAMES_PER_SECOND),\n maxAudioDuration,\n audioPrefixDuration,\n detectionInterval,\n inferenceTimeout,\n baseUrl: lkBaseUrl,\n apiKey: lkApiKey,\n apiSecret: lkApiSecret,\n useProxy,\n minInterruptionDuration,\n };\n\n this.label = `${this.constructor.name}`;\n this.streams = new WeakSet();\n\n console.info('adaptive interruption detector initialized', {\n baseUrl: this.options.baseUrl,\n detectionInterval: this.options.detectionInterval,\n audioPrefixDuration: this.options.audioPrefixDuration,\n maxAudioDuration: this.options.maxAudioDuration,\n minFrames: this.options.minFrames,\n threshold: this.options.threshold,\n inferenceTimeout: this.options.inferenceTimeout,\n useProxy: this.options.useProxy,\n });\n }\n\n /**\n * Creates a new InterruptionStreamBase for internal use.\n * The stream can receive audio frames and sentinels via pushFrame().\n * Use this when you need direct access to the stream for pushing frames.\n */\n createStream(): InterruptionStreamBase {\n const stream = new InterruptionStreamBase(this, {});\n this.streams.add(stream);\n return stream;\n }\n\n /**\n * Creates a new interruption stream and returns a ReadableStream of InterruptionEvents.\n * This is a convenience method for consuming interruption events without needing\n * to manage the underlying stream directly.\n */\n stream(): ReadableStream<InterruptionEvent> {\n const httpStream = this.createStream();\n const transformer = new TransformStream<InterruptionEvent, InterruptionEvent>({\n transform: (chunk, controller) => {\n if (chunk.type === InterruptionEventType.INTERRUPTION) {\n this.emit('interruptionDetected'); // TODO payload\n } else if (chunk.type === InterruptionEventType.OVERLAP_SPEECH_ENDED) {\n this.emit('overlapSpeechDetected'); // TODO payload\n }\n controller.enqueue(chunk);\n },\n });\n const stream = httpStream.stream.pipeThrough(transformer);\n return stream;\n }\n\n updateOptions(options: { threshold?: number; minInterruptionDuration?: number }): void {\n if (options.threshold !== undefined) {\n this.options.threshold = options.threshold;\n }\n if (options.minInterruptionDuration !== undefined) {\n this.options.minFrames = Math.ceil(options.minInterruptionDuration * FRAMES_PER_SECOND);\n }\n }\n}\n"],"mappings":"AACA,OAAO,kBAAkB;AACzB,SAA8B,uBAAuB;AACrD,SAAS,8BAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAGE;AAAA,OACK;AAyBA,MAAM,qCAAsC,aAAoE;AAAA,EACrH;AAAA,EACQ;AAAA,EACA;AAAA;AAAA,EAER,YAAY,UAA+C,CAAC,GAAG;AAC7D,UAAM;AAEN,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI,EAAE,GAAG,4BAA4B,GAAG,QAAQ;AAEhD,QAAI,mBAAmB,GAAK;AAC1B,YAAM,IAAI,MAAM,4DAA4D;AAAA,IAC9E;AAEA,UAAM,YAAY,WAAW,QAAQ,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