@livekit/agents 1.0.6 → 1.0.8
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/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/inference/api_protos.cjs +104 -0
- package/dist/inference/api_protos.cjs.map +1 -0
- package/dist/inference/api_protos.d.cts +222 -0
- package/dist/inference/api_protos.d.ts +222 -0
- package/dist/inference/api_protos.d.ts.map +1 -0
- package/dist/inference/api_protos.js +70 -0
- package/dist/inference/api_protos.js.map +1 -0
- package/dist/inference/index.cjs +56 -0
- package/dist/inference/index.cjs.map +1 -0
- package/dist/inference/index.d.cts +8 -0
- package/dist/inference/index.d.ts +8 -0
- package/dist/inference/index.d.ts.map +1 -0
- package/dist/inference/index.js +23 -0
- package/dist/inference/index.js.map +1 -0
- package/dist/inference/llm.cjs +301 -0
- package/dist/inference/llm.cjs.map +1 -0
- package/dist/inference/llm.d.cts +107 -0
- package/dist/inference/llm.d.ts +107 -0
- package/dist/inference/llm.d.ts.map +1 -0
- package/dist/inference/llm.js +272 -0
- package/dist/inference/llm.js.map +1 -0
- package/dist/inference/stt.cjs +313 -0
- package/dist/inference/stt.cjs.map +1 -0
- package/dist/inference/stt.d.cts +87 -0
- package/dist/inference/stt.d.ts +87 -0
- package/dist/inference/stt.d.ts.map +1 -0
- package/dist/inference/stt.js +292 -0
- package/dist/inference/stt.js.map +1 -0
- package/dist/inference/tts.cjs +324 -0
- package/dist/inference/tts.cjs.map +1 -0
- package/dist/inference/tts.d.cts +77 -0
- package/dist/inference/tts.d.ts +77 -0
- package/dist/inference/tts.d.ts.map +1 -0
- package/dist/inference/tts.js +306 -0
- package/dist/inference/tts.js.map +1 -0
- package/dist/inference/utils.cjs +76 -0
- package/dist/inference/utils.cjs.map +1 -0
- package/dist/inference/utils.d.cts +5 -0
- package/dist/inference/utils.d.ts +5 -0
- package/dist/inference/utils.d.ts.map +1 -0
- package/dist/inference/utils.js +51 -0
- package/dist/inference/utils.js.map +1 -0
- package/dist/llm/remote_chat_context.cjs.map +1 -1
- package/dist/llm/remote_chat_context.d.cts +2 -0
- package/dist/llm/remote_chat_context.d.ts +2 -0
- package/dist/llm/remote_chat_context.d.ts.map +1 -1
- package/dist/llm/remote_chat_context.js.map +1 -1
- package/dist/tts/tts.cjs +1 -1
- package/dist/tts/tts.cjs.map +1 -1
- package/dist/tts/tts.js +1 -1
- package/dist/tts/tts.js.map +1 -1
- package/dist/utils.cjs +11 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +10 -0
- package/dist/utils.js.map +1 -1
- package/dist/voice/agent.cjs +16 -3
- package/dist/voice/agent.cjs.map +1 -1
- package/dist/voice/agent.d.cts +5 -3
- package/dist/voice/agent.d.ts +5 -3
- package/dist/voice/agent.d.ts.map +1 -1
- package/dist/voice/agent.js +20 -3
- package/dist/voice/agent.js.map +1 -1
- package/dist/voice/agent_activity.cjs +4 -2
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +4 -2
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +16 -3
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +4 -3
- package/dist/voice/agent_session.d.ts +4 -3
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +20 -3
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/events.cjs +2 -0
- package/dist/voice/events.cjs.map +1 -1
- package/dist/voice/events.d.cts +4 -1
- package/dist/voice/events.d.ts +4 -1
- package/dist/voice/events.d.ts.map +1 -1
- package/dist/voice/events.js +2 -0
- package/dist/voice/events.js.map +1 -1
- package/dist/voice/generation.cjs.map +1 -1
- package/dist/voice/generation.d.cts +1 -0
- package/dist/voice/generation.d.ts +1 -0
- package/dist/voice/generation.d.ts.map +1 -1
- package/dist/voice/generation.js.map +1 -1
- package/dist/voice/room_io/_input.cjs.map +1 -1
- package/dist/voice/room_io/_input.d.ts.map +1 -1
- package/dist/voice/room_io/_input.js +1 -0
- package/dist/voice/room_io/_input.js.map +1 -1
- package/dist/voice/room_io/_output.cjs +1 -1
- package/dist/voice/room_io/_output.cjs.map +1 -1
- package/dist/voice/room_io/_output.d.cts +1 -0
- package/dist/voice/room_io/_output.d.ts +1 -0
- package/dist/voice/room_io/_output.d.ts.map +1 -1
- package/dist/voice/room_io/_output.js +1 -1
- package/dist/voice/room_io/_output.js.map +1 -1
- package/dist/voice/room_io/room_io.cjs +1 -1
- package/dist/voice/room_io/room_io.cjs.map +1 -1
- package/dist/voice/room_io/room_io.d.cts +20 -0
- package/dist/voice/room_io/room_io.d.ts +20 -0
- package/dist/voice/room_io/room_io.d.ts.map +1 -1
- package/dist/voice/room_io/room_io.js +1 -1
- package/dist/voice/room_io/room_io.js.map +1 -1
- package/dist/voice/transcription/synchronizer.cjs +1 -1
- package/dist/voice/transcription/synchronizer.cjs.map +1 -1
- package/dist/voice/transcription/synchronizer.d.cts +1 -0
- package/dist/voice/transcription/synchronizer.d.ts +1 -0
- package/dist/voice/transcription/synchronizer.d.ts.map +1 -1
- package/dist/voice/transcription/synchronizer.js +1 -1
- package/dist/voice/transcription/synchronizer.js.map +1 -1
- package/dist/worker.cjs +3 -3
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +3 -0
- package/dist/worker.d.ts +3 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +4 -4
- package/dist/worker.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +2 -1
- package/src/inference/api_protos.ts +82 -0
- package/src/inference/index.ts +32 -0
- package/src/inference/llm.ts +464 -0
- package/src/inference/stt.ts +444 -0
- package/src/inference/tts.ts +432 -0
- package/src/inference/utils.ts +66 -0
- package/src/llm/remote_chat_context.ts +2 -2
- package/src/tts/tts.ts +1 -1
- package/src/utils.ts +11 -0
- package/src/voice/agent.ts +31 -7
- package/src/voice/agent_activity.ts +2 -0
- package/src/voice/agent_session.ts +30 -6
- package/src/voice/events.ts +6 -0
- package/src/voice/generation.ts +1 -1
- package/src/voice/room_io/_input.ts +1 -1
- package/src/voice/room_io/_output.ts +1 -1
- package/src/voice/room_io/room_io.ts +21 -2
- package/src/voice/transcription/synchronizer.ts +1 -1
- package/src/worker.ts +5 -10
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const ttsSessionCreateEventSchema = z.object({
|
|
3
|
+
type: z.literal("session.create"),
|
|
4
|
+
sample_rate: z.string(),
|
|
5
|
+
encoding: z.string(),
|
|
6
|
+
model: z.string().optional(),
|
|
7
|
+
voice: z.string().optional(),
|
|
8
|
+
language: z.string().optional(),
|
|
9
|
+
extra: z.record(z.string(), z.unknown()),
|
|
10
|
+
transcript: z.string().optional()
|
|
11
|
+
});
|
|
12
|
+
const ttsInputTranscriptEventSchema = z.object({
|
|
13
|
+
type: z.literal("input_transcript"),
|
|
14
|
+
transcript: z.string()
|
|
15
|
+
});
|
|
16
|
+
const ttsSessionFlushEventSchema = z.object({
|
|
17
|
+
type: z.literal("session.flush")
|
|
18
|
+
});
|
|
19
|
+
const ttsSessionCloseEventSchema = z.object({
|
|
20
|
+
type: z.literal("session.close")
|
|
21
|
+
});
|
|
22
|
+
const ttsSessionCreatedEventSchema = z.object({
|
|
23
|
+
type: z.literal("session.created"),
|
|
24
|
+
session_id: z.string()
|
|
25
|
+
});
|
|
26
|
+
const ttsOutputAudioEventSchema = z.object({
|
|
27
|
+
type: z.literal("output_audio"),
|
|
28
|
+
audio: z.string(),
|
|
29
|
+
session_id: z.string()
|
|
30
|
+
});
|
|
31
|
+
const ttsDoneEventSchema = z.object({
|
|
32
|
+
type: z.literal("done"),
|
|
33
|
+
session_id: z.string()
|
|
34
|
+
});
|
|
35
|
+
const ttsSessionClosedEventSchema = z.object({
|
|
36
|
+
type: z.literal("session.closed"),
|
|
37
|
+
session_id: z.string()
|
|
38
|
+
});
|
|
39
|
+
const ttsErrorEventSchema = z.object({
|
|
40
|
+
type: z.literal("error"),
|
|
41
|
+
message: z.string(),
|
|
42
|
+
session_id: z.string()
|
|
43
|
+
});
|
|
44
|
+
const ttsClientEventSchema = z.discriminatedUnion("type", [
|
|
45
|
+
ttsSessionCreateEventSchema,
|
|
46
|
+
ttsInputTranscriptEventSchema,
|
|
47
|
+
ttsSessionFlushEventSchema,
|
|
48
|
+
ttsSessionCloseEventSchema
|
|
49
|
+
]);
|
|
50
|
+
const ttsServerEventSchema = z.discriminatedUnion("type", [
|
|
51
|
+
ttsSessionCreatedEventSchema,
|
|
52
|
+
ttsOutputAudioEventSchema,
|
|
53
|
+
ttsDoneEventSchema,
|
|
54
|
+
ttsSessionClosedEventSchema,
|
|
55
|
+
ttsErrorEventSchema
|
|
56
|
+
]);
|
|
57
|
+
export {
|
|
58
|
+
ttsClientEventSchema,
|
|
59
|
+
ttsDoneEventSchema,
|
|
60
|
+
ttsErrorEventSchema,
|
|
61
|
+
ttsInputTranscriptEventSchema,
|
|
62
|
+
ttsOutputAudioEventSchema,
|
|
63
|
+
ttsServerEventSchema,
|
|
64
|
+
ttsSessionCloseEventSchema,
|
|
65
|
+
ttsSessionClosedEventSchema,
|
|
66
|
+
ttsSessionCreateEventSchema,
|
|
67
|
+
ttsSessionCreatedEventSchema,
|
|
68
|
+
ttsSessionFlushEventSchema
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=api_protos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inference/api_protos.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { z } from 'zod';\n\nexport const ttsSessionCreateEventSchema = z.object({\n type: z.literal('session.create'),\n sample_rate: z.string(),\n encoding: z.string(),\n model: z.string().optional(),\n voice: z.string().optional(),\n language: z.string().optional(),\n extra: z.record(z.string(), z.unknown()),\n transcript: z.string().optional(),\n});\n\nexport const ttsInputTranscriptEventSchema = z.object({\n type: z.literal('input_transcript'),\n transcript: z.string(),\n});\n\nexport const ttsSessionFlushEventSchema = z.object({\n type: z.literal('session.flush'),\n});\n\nexport const ttsSessionCloseEventSchema = z.object({\n type: z.literal('session.close'),\n});\n\nexport const ttsSessionCreatedEventSchema = z.object({\n type: z.literal('session.created'),\n session_id: z.string(),\n});\n\nexport const ttsOutputAudioEventSchema = z.object({\n type: z.literal('output_audio'),\n audio: z.string(),\n session_id: z.string(),\n});\n\nexport const ttsDoneEventSchema = z.object({\n type: z.literal('done'),\n session_id: z.string(),\n});\n\nexport const ttsSessionClosedEventSchema = z.object({\n type: z.literal('session.closed'),\n session_id: z.string(),\n});\n\nexport const ttsErrorEventSchema = z.object({\n type: z.literal('error'),\n message: z.string(),\n session_id: z.string(),\n});\n\nexport const ttsClientEventSchema = z.discriminatedUnion('type', [\n ttsSessionCreateEventSchema,\n ttsInputTranscriptEventSchema,\n ttsSessionFlushEventSchema,\n ttsSessionCloseEventSchema,\n]);\n\nexport const ttsServerEventSchema = z.discriminatedUnion('type', [\n ttsSessionCreatedEventSchema,\n ttsOutputAudioEventSchema,\n ttsDoneEventSchema,\n ttsSessionClosedEventSchema,\n ttsErrorEventSchema,\n]);\n\nexport type TtsSessionCreateEvent = z.infer<typeof ttsSessionCreateEventSchema>;\nexport type TtsInputTranscriptEvent = z.infer<typeof ttsInputTranscriptEventSchema>;\nexport type TtsSessionFlushEvent = z.infer<typeof ttsSessionFlushEventSchema>;\nexport type TtsSessionCloseEvent = z.infer<typeof ttsSessionCloseEventSchema>;\nexport type TtsSessionCreatedEvent = z.infer<typeof ttsSessionCreatedEventSchema>;\nexport type TtsOutputAudioEvent = z.infer<typeof ttsOutputAudioEventSchema>;\nexport type TtsDoneEvent = z.infer<typeof ttsDoneEventSchema>;\nexport type TtsSessionClosedEvent = z.infer<typeof ttsSessionClosedEventSchema>;\nexport type TtsErrorEvent = z.infer<typeof ttsErrorEventSchema>;\nexport type TtsClientEvent = z.infer<typeof ttsClientEventSchema>;\nexport type TtsServerEvent = z.infer<typeof ttsServerEventSchema>;\n"],"mappings":"AAGA,SAAS,SAAS;AAEX,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,MAAM,EAAE,QAAQ,gBAAgB;AAAA,EAChC,aAAa,EAAE,OAAO;AAAA,EACtB,UAAU,EAAE,OAAO;AAAA,EACnB,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;AAAA,EACvC,YAAY,EAAE,OAAO,EAAE,SAAS;AAClC,CAAC;AAEM,MAAM,gCAAgC,EAAE,OAAO;AAAA,EACpD,MAAM,EAAE,QAAQ,kBAAkB;AAAA,EAClC,YAAY,EAAE,OAAO;AACvB,CAAC;AAEM,MAAM,6BAA6B,EAAE,OAAO;AAAA,EACjD,MAAM,EAAE,QAAQ,eAAe;AACjC,CAAC;AAEM,MAAM,6BAA6B,EAAE,OAAO;AAAA,EACjD,MAAM,EAAE,QAAQ,eAAe;AACjC,CAAC;AAEM,MAAM,+BAA+B,EAAE,OAAO;AAAA,EACnD,MAAM,EAAE,QAAQ,iBAAiB;AAAA,EACjC,YAAY,EAAE,OAAO;AACvB,CAAC;AAEM,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,MAAM,EAAE,QAAQ,cAAc;AAAA,EAC9B,OAAO,EAAE,OAAO;AAAA,EAChB,YAAY,EAAE,OAAO;AACvB,CAAC;AAEM,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,MAAM,EAAE,QAAQ,MAAM;AAAA,EACtB,YAAY,EAAE,OAAO;AACvB,CAAC;AAEM,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,MAAM,EAAE,QAAQ,gBAAgB;AAAA,EAChC,YAAY,EAAE,OAAO;AACvB,CAAC;AAEM,MAAM,sBAAsB,EAAE,OAAO;AAAA,EAC1C,MAAM,EAAE,QAAQ,OAAO;AAAA,EACvB,SAAS,EAAE,OAAO;AAAA,EAClB,YAAY,EAAE,OAAO;AACvB,CAAC;AAEM,MAAM,uBAAuB,EAAE,mBAAmB,QAAQ;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,MAAM,uBAAuB,EAAE,mBAAmB,QAAQ;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 inference_exports = {};
|
|
30
|
+
__export(inference_exports, {
|
|
31
|
+
LLM: () => import_llm.LLM,
|
|
32
|
+
LLMStream: () => import_llm.LLMStream,
|
|
33
|
+
STT: () => import_stt.STT,
|
|
34
|
+
TTS: () => import_tts.TTS,
|
|
35
|
+
llm: () => llm,
|
|
36
|
+
stt: () => stt,
|
|
37
|
+
tts: () => tts
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(inference_exports);
|
|
40
|
+
var llm = __toESM(require("./llm.cjs"), 1);
|
|
41
|
+
var stt = __toESM(require("./stt.cjs"), 1);
|
|
42
|
+
var tts = __toESM(require("./tts.cjs"), 1);
|
|
43
|
+
var import_llm = require("./llm.cjs");
|
|
44
|
+
var import_stt = require("./stt.cjs");
|
|
45
|
+
var import_tts = require("./tts.cjs");
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
LLM,
|
|
49
|
+
LLMStream,
|
|
50
|
+
STT,
|
|
51
|
+
TTS,
|
|
52
|
+
llm,
|
|
53
|
+
stt,
|
|
54
|
+
tts
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inference/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport * as llm from './llm.js';\nimport * as stt from './stt.js';\nimport * as tts from './tts.js';\n\nexport {\n LLM,\n LLMStream,\n type ChatCompletionOptions,\n type GatewayOptions,\n type InferenceLLMOptions,\n type LLMModels,\n} from './llm.js';\n\nexport {\n STT,\n type STTLanguages,\n type STTModels,\n type ModelWithLanguage as STTModelString,\n type STTOptions,\n} from './stt.js';\n\nexport {\n TTS,\n type TTSModels,\n type ModelWithVoice as TTSModelString,\n type TTSOptions,\n} from './tts.js';\n\nexport { llm, stt, tts };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,UAAqB;AACrB,UAAqB;AACrB,UAAqB;AAErB,iBAOO;AAEP,iBAMO;AAEP,iBAKO;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as llm from './llm.js';
|
|
2
|
+
import * as stt from './stt.js';
|
|
3
|
+
import * as tts from './tts.js';
|
|
4
|
+
export { LLM, LLMStream, type ChatCompletionOptions, type GatewayOptions, type InferenceLLMOptions, type LLMModels, } from './llm.js';
|
|
5
|
+
export { STT, type STTLanguages, type STTModels, type ModelWithLanguage as STTModelString, type STTOptions, } from './stt.js';
|
|
6
|
+
export { TTS, type TTSModels, type ModelWithVoice as TTSModelString, type TTSOptions, } from './tts.js';
|
|
7
|
+
export { llm, stt, tts };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as llm from './llm.js';
|
|
2
|
+
import * as stt from './stt.js';
|
|
3
|
+
import * as tts from './tts.js';
|
|
4
|
+
export { LLM, LLMStream, type ChatCompletionOptions, type GatewayOptions, type InferenceLLMOptions, type LLMModels, } from './llm.js';
|
|
5
|
+
export { STT, type STTLanguages, type STTModels, type ModelWithLanguage as STTModelString, type STTOptions, } from './stt.js';
|
|
6
|
+
export { TTS, type TTSModels, type ModelWithVoice as TTSModelString, type TTSOptions, } from './tts.js';
|
|
7
|
+
export { llm, stt, tts };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/inference/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,OAAO,EACL,GAAG,EACH,SAAS,EACT,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,GAAG,EACH,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,iBAAiB,IAAI,cAAc,EACxC,KAAK,UAAU,GAChB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,GAAG,EACH,KAAK,SAAS,EACd,KAAK,cAAc,IAAI,cAAc,EACrC,KAAK,UAAU,GAChB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as llm from "./llm.js";
|
|
2
|
+
import * as stt from "./stt.js";
|
|
3
|
+
import * as tts from "./tts.js";
|
|
4
|
+
import {
|
|
5
|
+
LLM,
|
|
6
|
+
LLMStream
|
|
7
|
+
} from "./llm.js";
|
|
8
|
+
import {
|
|
9
|
+
STT
|
|
10
|
+
} from "./stt.js";
|
|
11
|
+
import {
|
|
12
|
+
TTS
|
|
13
|
+
} from "./tts.js";
|
|
14
|
+
export {
|
|
15
|
+
LLM,
|
|
16
|
+
LLMStream,
|
|
17
|
+
STT,
|
|
18
|
+
TTS,
|
|
19
|
+
llm,
|
|
20
|
+
stt,
|
|
21
|
+
tts
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inference/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport * as llm from './llm.js';\nimport * as stt from './stt.js';\nimport * as tts from './tts.js';\n\nexport {\n LLM,\n LLMStream,\n type ChatCompletionOptions,\n type GatewayOptions,\n type InferenceLLMOptions,\n type LLMModels,\n} from './llm.js';\n\nexport {\n STT,\n type STTLanguages,\n type STTModels,\n type ModelWithLanguage as STTModelString,\n type STTOptions,\n} from './stt.js';\n\nexport {\n TTS,\n type TTSModels,\n type ModelWithVoice as TTSModelString,\n type TTSOptions,\n} from './tts.js';\n\nexport { llm, stt, tts };\n"],"mappings":"AAGA,YAAY,SAAS;AACrB,YAAY,SAAS;AACrB,YAAY,SAAS;AAErB;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AAEP;AAAA,EACE;AAAA,OAKK;AAEP;AAAA,EACE;AAAA,OAIK;","names":[]}
|
|
@@ -0,0 +1,301 @@
|
|
|
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 llm_exports = {};
|
|
30
|
+
__export(llm_exports, {
|
|
31
|
+
LLM: () => LLM,
|
|
32
|
+
LLMStream: () => LLMStream
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(llm_exports);
|
|
35
|
+
var import_openai = __toESM(require("openai"), 1);
|
|
36
|
+
var import__ = require("../index.cjs");
|
|
37
|
+
var llm = __toESM(require("../llm/index.cjs"), 1);
|
|
38
|
+
var import_utils = require("./utils.cjs");
|
|
39
|
+
const DEFAULT_BASE_URL = "https://agent-gateway.livekit.cloud/v1";
|
|
40
|
+
class LLM extends llm.LLM {
|
|
41
|
+
client;
|
|
42
|
+
opts;
|
|
43
|
+
constructor(opts) {
|
|
44
|
+
super();
|
|
45
|
+
const { model, provider, baseURL, apiKey, apiSecret, modelOptions } = opts;
|
|
46
|
+
const lkBaseURL = baseURL || process.env.LIVEKIT_INFERENCE_URL || DEFAULT_BASE_URL;
|
|
47
|
+
const lkApiKey = apiKey || process.env.LIVEKIT_INFERENCE_API_KEY || process.env.LIVEKIT_API_KEY;
|
|
48
|
+
if (!lkApiKey) {
|
|
49
|
+
throw new Error("apiKey is required: pass apiKey or set LIVEKIT_API_KEY");
|
|
50
|
+
}
|
|
51
|
+
const lkApiSecret = apiSecret || process.env.LIVEKIT_INFERENCE_API_SECRET || process.env.LIVEKIT_API_SECRET;
|
|
52
|
+
if (!lkApiSecret) {
|
|
53
|
+
throw new Error("apiSecret is required: pass apiSecret or set LIVEKIT_API_SECRET");
|
|
54
|
+
}
|
|
55
|
+
this.opts = {
|
|
56
|
+
model,
|
|
57
|
+
provider,
|
|
58
|
+
baseURL: lkBaseURL,
|
|
59
|
+
apiKey: lkApiKey,
|
|
60
|
+
apiSecret: lkApiSecret,
|
|
61
|
+
modelOptions: modelOptions || {}
|
|
62
|
+
};
|
|
63
|
+
this.client = new import_openai.default({
|
|
64
|
+
baseURL: this.opts.baseURL,
|
|
65
|
+
apiKey: "",
|
|
66
|
+
// leave a temporary empty string to avoid OpenAI complain about missing key
|
|
67
|
+
timeout: 15e3
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
label() {
|
|
71
|
+
return "inference.LLM";
|
|
72
|
+
}
|
|
73
|
+
get model() {
|
|
74
|
+
return this.opts.model;
|
|
75
|
+
}
|
|
76
|
+
static fromModelString(modelString) {
|
|
77
|
+
return new LLM({ model: modelString });
|
|
78
|
+
}
|
|
79
|
+
chat({
|
|
80
|
+
chatCtx,
|
|
81
|
+
toolCtx,
|
|
82
|
+
connOptions = import__.DEFAULT_API_CONNECT_OPTIONS,
|
|
83
|
+
parallelToolCalls,
|
|
84
|
+
toolChoice,
|
|
85
|
+
// TODO(AJS-270): Add response_format parameter support
|
|
86
|
+
extraKwargs
|
|
87
|
+
}) {
|
|
88
|
+
let modelOptions = { ...extraKwargs || {} };
|
|
89
|
+
parallelToolCalls = parallelToolCalls !== void 0 ? parallelToolCalls : this.opts.modelOptions.parallel_tool_calls;
|
|
90
|
+
if (toolCtx && Object.keys(toolCtx).length > 0 && parallelToolCalls !== void 0) {
|
|
91
|
+
modelOptions.parallel_tool_calls = parallelToolCalls;
|
|
92
|
+
}
|
|
93
|
+
toolChoice = toolChoice !== void 0 ? toolChoice : this.opts.modelOptions.tool_choice;
|
|
94
|
+
if (toolChoice) {
|
|
95
|
+
modelOptions.tool_choice = toolChoice;
|
|
96
|
+
}
|
|
97
|
+
modelOptions = { ...modelOptions, ...this.opts.modelOptions };
|
|
98
|
+
return new LLMStream(this, {
|
|
99
|
+
model: this.opts.model,
|
|
100
|
+
provider: this.opts.provider,
|
|
101
|
+
client: this.client,
|
|
102
|
+
chatCtx,
|
|
103
|
+
toolCtx,
|
|
104
|
+
connOptions,
|
|
105
|
+
modelOptions,
|
|
106
|
+
gatewayOptions: {
|
|
107
|
+
apiKey: this.opts.apiKey,
|
|
108
|
+
apiSecret: this.opts.apiSecret
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
class LLMStream extends llm.LLMStream {
|
|
114
|
+
model;
|
|
115
|
+
provider;
|
|
116
|
+
providerFmt;
|
|
117
|
+
client;
|
|
118
|
+
modelOptions;
|
|
119
|
+
gatewayOptions;
|
|
120
|
+
toolCallId;
|
|
121
|
+
toolIndex;
|
|
122
|
+
fncName;
|
|
123
|
+
fncRawArguments;
|
|
124
|
+
constructor(llm2, {
|
|
125
|
+
model,
|
|
126
|
+
provider,
|
|
127
|
+
client,
|
|
128
|
+
chatCtx,
|
|
129
|
+
toolCtx,
|
|
130
|
+
gatewayOptions,
|
|
131
|
+
connOptions,
|
|
132
|
+
modelOptions,
|
|
133
|
+
providerFmt
|
|
134
|
+
}) {
|
|
135
|
+
super(llm2, { chatCtx, toolCtx, connOptions });
|
|
136
|
+
this.client = client;
|
|
137
|
+
this.gatewayOptions = gatewayOptions;
|
|
138
|
+
this.provider = provider;
|
|
139
|
+
this.providerFmt = providerFmt || "openai";
|
|
140
|
+
this.modelOptions = modelOptions;
|
|
141
|
+
this.model = model;
|
|
142
|
+
}
|
|
143
|
+
async run() {
|
|
144
|
+
var _a;
|
|
145
|
+
let retryable = true;
|
|
146
|
+
this.toolCallId = this.fncName = this.fncRawArguments = this.toolIndex = void 0;
|
|
147
|
+
try {
|
|
148
|
+
const messages = await this.chatCtx.toProviderFormat(
|
|
149
|
+
this.providerFmt
|
|
150
|
+
);
|
|
151
|
+
const tools = this.toolCtx ? Object.entries(this.toolCtx).map(([name, func]) => ({
|
|
152
|
+
type: "function",
|
|
153
|
+
function: {
|
|
154
|
+
name,
|
|
155
|
+
description: func.description,
|
|
156
|
+
parameters: llm.toJsonSchema(
|
|
157
|
+
func.parameters
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
})) : void 0;
|
|
161
|
+
const requestOptions = { ...this.modelOptions };
|
|
162
|
+
if (!tools) {
|
|
163
|
+
delete requestOptions.tool_choice;
|
|
164
|
+
}
|
|
165
|
+
if (this.gatewayOptions) {
|
|
166
|
+
this.client.apiKey = await (0, import_utils.createAccessToken)(
|
|
167
|
+
this.gatewayOptions.apiKey,
|
|
168
|
+
this.gatewayOptions.apiSecret
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
if (this.provider) {
|
|
172
|
+
const extraHeaders = requestOptions.extra_headers ? requestOptions.extra_headers : {};
|
|
173
|
+
extraHeaders["X-LiveKit-Inference-Provider"] = this.provider;
|
|
174
|
+
requestOptions.extra_headers = extraHeaders;
|
|
175
|
+
}
|
|
176
|
+
const stream = await this.client.chat.completions.create(
|
|
177
|
+
{
|
|
178
|
+
model: this.model,
|
|
179
|
+
messages,
|
|
180
|
+
tools,
|
|
181
|
+
stream: true,
|
|
182
|
+
stream_options: { include_usage: true },
|
|
183
|
+
...requestOptions
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
timeout: this.connOptions.timeoutMs
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
for await (const chunk of stream) {
|
|
190
|
+
for (const choice of chunk.choices) {
|
|
191
|
+
if (this.abortController.signal.aborted) {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
const chatChunk = this.parseChoice(chunk.id, choice);
|
|
195
|
+
if (chatChunk) {
|
|
196
|
+
retryable = false;
|
|
197
|
+
this.queue.put(chatChunk);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (chunk.usage) {
|
|
201
|
+
const usage = chunk.usage;
|
|
202
|
+
retryable = false;
|
|
203
|
+
this.queue.put({
|
|
204
|
+
id: chunk.id,
|
|
205
|
+
usage: {
|
|
206
|
+
completionTokens: usage.completion_tokens,
|
|
207
|
+
promptTokens: usage.prompt_tokens,
|
|
208
|
+
promptCachedTokens: ((_a = usage.prompt_tokens_details) == null ? void 0 : _a.cached_tokens) || 0,
|
|
209
|
+
totalTokens: usage.total_tokens
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (error instanceof import_openai.default.APIConnectionTimeoutError) {
|
|
216
|
+
throw new import__.APITimeoutError({ options: { retryable } });
|
|
217
|
+
} else if (error instanceof import_openai.default.APIError) {
|
|
218
|
+
throw new import__.APIStatusError({
|
|
219
|
+
message: error.message,
|
|
220
|
+
options: {
|
|
221
|
+
statusCode: error.status,
|
|
222
|
+
body: error.error,
|
|
223
|
+
requestId: error.request_id,
|
|
224
|
+
retryable
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
} else {
|
|
228
|
+
throw new import__.APIConnectionError({
|
|
229
|
+
message: (0, import__.toError)(error).message,
|
|
230
|
+
options: { retryable }
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
} finally {
|
|
234
|
+
this.queue.close();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
parseChoice(id, choice) {
|
|
238
|
+
const delta = choice.delta;
|
|
239
|
+
if (delta === void 0) return void 0;
|
|
240
|
+
if (delta.tool_calls) {
|
|
241
|
+
for (const tool of delta.tool_calls) {
|
|
242
|
+
if (!tool.function) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
let callChunk;
|
|
246
|
+
if (this.toolCallId && tool.id && tool.index !== this.toolIndex) {
|
|
247
|
+
callChunk = this.createRunningToolCallChunk(id, delta);
|
|
248
|
+
this.toolCallId = this.fncName = this.fncRawArguments = void 0;
|
|
249
|
+
}
|
|
250
|
+
if (tool.function.name) {
|
|
251
|
+
this.toolIndex = tool.index;
|
|
252
|
+
this.toolCallId = tool.id;
|
|
253
|
+
this.fncName = tool.function.name;
|
|
254
|
+
this.fncRawArguments = tool.function.arguments || "";
|
|
255
|
+
} else if (tool.function.arguments) {
|
|
256
|
+
this.fncRawArguments = (this.fncRawArguments || "") + tool.function.arguments;
|
|
257
|
+
}
|
|
258
|
+
if (callChunk) {
|
|
259
|
+
return callChunk;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (choice.finish_reason && ["tool_calls", "stop"].includes(choice.finish_reason) && this.toolCallId !== void 0) {
|
|
264
|
+
const callChunk = this.createRunningToolCallChunk(id, delta);
|
|
265
|
+
this.toolCallId = this.fncName = this.fncRawArguments = void 0;
|
|
266
|
+
return callChunk;
|
|
267
|
+
}
|
|
268
|
+
if (!delta.content) {
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
id,
|
|
273
|
+
delta: {
|
|
274
|
+
role: "assistant",
|
|
275
|
+
content: delta.content
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
createRunningToolCallChunk(id, delta) {
|
|
280
|
+
return {
|
|
281
|
+
id,
|
|
282
|
+
delta: {
|
|
283
|
+
role: "assistant",
|
|
284
|
+
content: delta.content || void 0,
|
|
285
|
+
toolCalls: [
|
|
286
|
+
llm.FunctionCall.create({
|
|
287
|
+
callId: this.toolCallId || "",
|
|
288
|
+
name: this.fncName || "",
|
|
289
|
+
args: this.fncRawArguments || ""
|
|
290
|
+
})
|
|
291
|
+
]
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
297
|
+
0 && (module.exports = {
|
|
298
|
+
LLM,
|
|
299
|
+
LLMStream
|
|
300
|
+
});
|
|
301
|
+
//# sourceMappingURL=llm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/inference/llm.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport OpenAI from 'openai';\nimport {\n APIConnectionError,\n APIStatusError,\n APITimeoutError,\n DEFAULT_API_CONNECT_OPTIONS,\n toError,\n} from '../index.js';\nimport * as llm from '../llm/index.js';\nimport type { APIConnectOptions } from '../types.js';\nimport { type AnyString, createAccessToken } from './utils.js';\n\nconst DEFAULT_BASE_URL = 'https://agent-gateway.livekit.cloud/v1';\n\nexport type OpenAIModels =\n | 'openai/gpt-5'\n | 'openai/gpt-5-mini'\n | 'openai/gpt-5-nano'\n | 'openai/gpt-4.1'\n | 'openai/gpt-4.1-mini'\n | 'openai/gpt-4.1-nano'\n | 'openai/gpt-4o'\n | 'openai/gpt-4o-mini'\n | 'openai/gpt-oss-120b';\n\nexport type GoogleModels = 'google/gemini-2.0-flash-lite';\n\nexport type QwenModels = 'qwen/qwen3-235b-a22b-instruct';\n\nexport type KimiModels = 'moonshotai/kimi-k2-instruct';\n\nexport type DeepSeekModels = 'deepseek-ai/deepseek-v3';\n\ntype ChatCompletionPredictionContentParam = OpenAI.Chat.Completions.ChatCompletionPredictionContent;\ntype WebSearchOptions = OpenAI.Chat.Completions.ChatCompletionCreateParams.WebSearchOptions;\ntype ToolChoice = OpenAI.Chat.Completions.ChatCompletionCreateParams['tool_choice'];\ntype Verbosity = 'low' | 'medium' | 'high';\n\nexport interface ChatCompletionOptions extends Record<string, unknown> {\n frequency_penalty?: number;\n logit_bias?: Record<string, number>;\n logprobs?: boolean;\n max_completion_tokens?: number;\n max_tokens?: number;\n metadata?: Record<string, string>;\n modalities?: Array<'text' | 'audio'>;\n n?: number;\n parallel_tool_calls?: boolean;\n prediction?: ChatCompletionPredictionContentParam | null;\n presence_penalty?: number;\n prompt_cache_key?: string;\n reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high';\n safety_identifier?: string;\n seed?: number;\n service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority';\n stop?: string | string[];\n store?: boolean;\n temperature?: number;\n top_logprobs?: number;\n top_p?: number;\n user?: string;\n verbosity?: Verbosity;\n web_search_options?: WebSearchOptions;\n\n // livekit-typed arguments\n tool_choice?: ToolChoice;\n // TODO(brian): support response format\n // response_format?: OpenAI.Chat.Completions.ChatCompletionCreateParams['response_format']\n}\n\nexport type LLMModels =\n | OpenAIModels\n | GoogleModels\n | QwenModels\n | KimiModels\n | DeepSeekModels\n | AnyString;\n\nexport interface InferenceLLMOptions {\n model: LLMModels;\n provider?: string;\n baseURL: string;\n apiKey: string;\n apiSecret: string;\n modelOptions: ChatCompletionOptions;\n}\n\nexport interface GatewayOptions {\n apiKey: string;\n apiSecret: string;\n}\n\n/**\n * Livekit Cloud Inference LLM\n */\nexport class LLM extends llm.LLM {\n private client: OpenAI;\n private opts: InferenceLLMOptions;\n\n constructor(opts: {\n model: LLMModels;\n provider?: string;\n baseURL?: string;\n apiKey?: string;\n apiSecret?: string;\n modelOptions?: InferenceLLMOptions['modelOptions'];\n }) {\n super();\n\n const { model, provider, baseURL, apiKey, apiSecret, modelOptions } = opts;\n\n const lkBaseURL = baseURL || process.env.LIVEKIT_INFERENCE_URL || DEFAULT_BASE_URL;\n const lkApiKey = apiKey || process.env.LIVEKIT_INFERENCE_API_KEY || process.env.LIVEKIT_API_KEY;\n if (!lkApiKey) {\n throw new Error('apiKey is required: pass apiKey or set LIVEKIT_API_KEY');\n }\n\n const lkApiSecret =\n apiSecret || process.env.LIVEKIT_INFERENCE_API_SECRET || process.env.LIVEKIT_API_SECRET;\n if (!lkApiSecret) {\n throw new Error('apiSecret is required: pass apiSecret or set LIVEKIT_API_SECRET');\n }\n\n this.opts = {\n model,\n provider,\n baseURL: lkBaseURL,\n apiKey: lkApiKey,\n apiSecret: lkApiSecret,\n modelOptions: modelOptions || {},\n };\n\n this.client = new OpenAI({\n baseURL: this.opts.baseURL,\n apiKey: '', // leave a temporary empty string to avoid OpenAI complain about missing key\n timeout: 15000,\n });\n }\n\n label(): string {\n return 'inference.LLM';\n }\n\n get model(): string {\n return this.opts.model;\n }\n\n static fromModelString(modelString: string): LLM {\n return new LLM({ model: modelString });\n }\n\n chat({\n chatCtx,\n toolCtx,\n connOptions = DEFAULT_API_CONNECT_OPTIONS,\n parallelToolCalls,\n toolChoice,\n // TODO(AJS-270): Add response_format parameter support\n extraKwargs,\n }: {\n chatCtx: llm.ChatContext;\n toolCtx?: llm.ToolContext;\n connOptions?: APIConnectOptions;\n parallelToolCalls?: boolean;\n toolChoice?: llm.ToolChoice;\n // TODO(AJS-270): Add responseFormat parameter\n extraKwargs?: Record<string, unknown>;\n }): LLMStream {\n let modelOptions: Record<string, unknown> = { ...(extraKwargs || {}) };\n\n parallelToolCalls =\n parallelToolCalls !== undefined\n ? parallelToolCalls\n : this.opts.modelOptions.parallel_tool_calls;\n\n if (toolCtx && Object.keys(toolCtx).length > 0 && parallelToolCalls !== undefined) {\n modelOptions.parallel_tool_calls = parallelToolCalls;\n }\n\n toolChoice = toolChoice !== undefined ? toolChoice : this.opts.modelOptions.tool_choice;\n if (toolChoice) {\n modelOptions.tool_choice = toolChoice;\n }\n\n // TODO(AJS-270): Add response_format support here\n\n modelOptions = { ...modelOptions, ...this.opts.modelOptions };\n\n return new LLMStream(this, {\n model: this.opts.model,\n provider: this.opts.provider,\n client: this.client,\n chatCtx,\n toolCtx,\n connOptions,\n modelOptions,\n gatewayOptions: {\n apiKey: this.opts.apiKey,\n apiSecret: this.opts.apiSecret,\n },\n });\n }\n}\n\nexport class LLMStream extends llm.LLMStream {\n private model: LLMModels;\n private provider?: string;\n private providerFmt: llm.ProviderFormat;\n private client: OpenAI;\n private modelOptions: Record<string, unknown>;\n\n private gatewayOptions?: GatewayOptions;\n private toolCallId?: string;\n private toolIndex?: number;\n private fncName?: string;\n private fncRawArguments?: string;\n\n constructor(\n llm: LLM,\n {\n model,\n provider,\n client,\n chatCtx,\n toolCtx,\n gatewayOptions,\n connOptions,\n modelOptions,\n providerFmt,\n }: {\n model: LLMModels;\n provider?: string;\n client: OpenAI;\n chatCtx: llm.ChatContext;\n toolCtx?: llm.ToolContext;\n gatewayOptions?: GatewayOptions;\n connOptions: APIConnectOptions;\n modelOptions: Record<string, any>;\n providerFmt?: llm.ProviderFormat;\n },\n ) {\n super(llm, { chatCtx, toolCtx, connOptions });\n this.client = client;\n this.gatewayOptions = gatewayOptions;\n this.provider = provider;\n this.providerFmt = providerFmt || 'openai';\n this.modelOptions = modelOptions;\n this.model = model;\n }\n\n protected async run(): Promise<void> {\n // current function call that we're waiting for full completion (args are streamed)\n // (defined inside the run method to make sure the state is reset for each run/attempt)\n let retryable = true;\n this.toolCallId = this.fncName = this.fncRawArguments = this.toolIndex = undefined;\n\n try {\n const messages = (await this.chatCtx.toProviderFormat(\n this.providerFmt,\n )) as OpenAI.ChatCompletionMessageParam[];\n\n const tools = this.toolCtx\n ? Object.entries(this.toolCtx).map(([name, func]) => ({\n type: 'function' as const,\n function: {\n name,\n description: func.description,\n parameters: llm.toJsonSchema(\n func.parameters,\n ) as unknown as OpenAI.Chat.Completions.ChatCompletionTool['function']['parameters'],\n },\n }))\n : undefined;\n\n const requestOptions: Record<string, unknown> = { ...this.modelOptions };\n if (!tools) {\n delete requestOptions.tool_choice;\n }\n\n // Dynamically set the access token for the LiveKit Agent Gateway API\n if (this.gatewayOptions) {\n this.client.apiKey = await createAccessToken(\n this.gatewayOptions.apiKey,\n this.gatewayOptions.apiSecret,\n );\n }\n\n if (this.provider) {\n const extraHeaders = requestOptions.extra_headers\n ? (requestOptions.extra_headers as Record<string, string>)\n : {};\n extraHeaders['X-LiveKit-Inference-Provider'] = this.provider;\n requestOptions.extra_headers = extraHeaders;\n }\n\n const stream = await this.client.chat.completions.create(\n {\n model: this.model,\n messages,\n tools,\n stream: true,\n stream_options: { include_usage: true },\n ...requestOptions,\n },\n {\n timeout: this.connOptions.timeoutMs,\n },\n );\n\n for await (const chunk of stream) {\n for (const choice of chunk.choices) {\n if (this.abortController.signal.aborted) {\n break;\n }\n const chatChunk = this.parseChoice(chunk.id, choice);\n if (chatChunk) {\n retryable = false;\n this.queue.put(chatChunk);\n }\n }\n\n if (chunk.usage) {\n const usage = chunk.usage;\n retryable = false;\n this.queue.put({\n id: chunk.id,\n usage: {\n completionTokens: usage.completion_tokens,\n promptTokens: usage.prompt_tokens,\n promptCachedTokens: usage.prompt_tokens_details?.cached_tokens || 0,\n totalTokens: usage.total_tokens,\n },\n });\n }\n }\n } catch (error) {\n if (error instanceof OpenAI.APIConnectionTimeoutError) {\n throw new APITimeoutError({ options: { retryable } });\n } else if (error instanceof OpenAI.APIError) {\n throw new APIStatusError({\n message: error.message,\n options: {\n statusCode: error.status,\n body: error.error,\n requestId: error.request_id,\n retryable,\n },\n });\n } else {\n throw new APIConnectionError({\n message: toError(error).message,\n options: { retryable },\n });\n }\n } finally {\n this.queue.close();\n }\n }\n\n private parseChoice(\n id: string,\n choice: OpenAI.ChatCompletionChunk.Choice,\n ): llm.ChatChunk | undefined {\n const delta = choice.delta;\n\n // https://github.com/livekit/agents/issues/688\n // the delta can be None when using Azure OpenAI (content filtering)\n if (delta === undefined) return undefined;\n\n if (delta.tool_calls) {\n // check if we have functions to calls\n for (const tool of delta.tool_calls) {\n if (!tool.function) {\n continue; // oai may add other tools in the future\n }\n\n /**\n * The way OpenAI streams tool calls is a bit tricky.\n *\n * For any new tool call, it first emits a delta tool call with id, and function name,\n * the rest of the delta chunks will only stream the remaining arguments string,\n * until a new tool call is started or the tool call is finished.\n * See below for an example.\n *\n * Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role='assistant', tool_calls=None), finish_reason=None, index=0, logprobs=None)\n * [ChoiceDeltaToolCall(index=0, id='call_LaVeHWUHpef9K1sd5UO8TtLg', function=ChoiceDeltaToolCallFunction(arguments='', name='get_weather'), type='function')]\n * [ChoiceDeltaToolCall(index=0, id=None, function=ChoiceDeltaToolCallFunction(arguments='{\"location\": \"P', name=None), type=None)]\n * [ChoiceDeltaToolCall(index=0, id=None, function=ChoiceDeltaToolCallFunction(arguments='aris}', name=None), type=None)]\n * [ChoiceDeltaToolCall(index=1, id='call_ThU4OmMdQXnnVmpXGOCknXIB', function=ChoiceDeltaToolCallFunction(arguments='', name='get_weather'), type='function')]\n * [ChoiceDeltaToolCall(index=1, id=None, function=ChoiceDeltaToolCallFunction(arguments='{\"location\": \"T', name=None), type=None)]\n * [ChoiceDeltaToolCall(index=1, id=None, function=ChoiceDeltaToolCallFunction(arguments='okyo', name=None), type=None)]\n * Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None), finish_reason='tool_calls', index=0, logprobs=None)\n */\n let callChunk: llm.ChatChunk | undefined;\n // If we have a previous tool call and this is a new one, emit the previous\n if (this.toolCallId && tool.id && tool.index !== this.toolIndex) {\n callChunk = this.createRunningToolCallChunk(id, delta);\n this.toolCallId = this.fncName = this.fncRawArguments = undefined;\n }\n\n // Start or continue building the current tool call\n if (tool.function.name) {\n this.toolIndex = tool.index;\n this.toolCallId = tool.id;\n this.fncName = tool.function.name;\n this.fncRawArguments = tool.function.arguments || '';\n } else if (tool.function.arguments) {\n this.fncRawArguments = (this.fncRawArguments || '') + tool.function.arguments;\n }\n\n if (callChunk) {\n return callChunk;\n }\n }\n }\n\n // If we're done with tool calls, emit the final one\n if (\n choice.finish_reason &&\n ['tool_calls', 'stop'].includes(choice.finish_reason) &&\n this.toolCallId !== undefined\n ) {\n const callChunk = this.createRunningToolCallChunk(id, delta);\n this.toolCallId = this.fncName = this.fncRawArguments = undefined;\n return callChunk;\n }\n\n // Regular content message\n if (!delta.content) {\n return undefined;\n }\n\n return {\n id,\n delta: {\n role: 'assistant',\n content: delta.content,\n },\n };\n }\n\n private createRunningToolCallChunk(\n id: string,\n delta: OpenAI.Chat.Completions.ChatCompletionChunk.Choice.Delta,\n ): llm.ChatChunk {\n return {\n id,\n delta: {\n role: 'assistant',\n content: delta.content || undefined,\n toolCalls: [\n llm.FunctionCall.create({\n callId: this.toolCallId || '',\n name: this.fncName || '',\n args: this.fncRawArguments || '',\n }),\n ],\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAmB;AACnB,eAMO;AACP,UAAqB;AAErB,mBAAkD;AAElD,MAAM,mBAAmB;AAmFlB,MAAM,YAAY,IAAI,IAAI;AAAA,EACvB;AAAA,EACA;AAAA,EAER,YAAY,MAOT;AACD,UAAM;AAEN,UAAM,EAAE,OAAO,UAAU,SAAS,QAAQ,WAAW,aAAa,IAAI;AAEtE,UAAM,YAAY,WAAW,QAAQ,IAAI,yBAAyB;AAClE,UAAM,WAAW,UAAU,QAAQ,IAAI,6BAA6B,QAAQ,IAAI;AAChF,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AAEA,UAAM,cACJ,aAAa,QAAQ,IAAI,gCAAgC,QAAQ,IAAI;AACvE,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,iEAAiE;AAAA,IACnF;AAEA,SAAK,OAAO;AAAA,MACV;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,cAAc,gBAAgB,CAAC;AAAA,IACjC;AAEA,SAAK,SAAS,IAAI,cAAAA,QAAO;AAAA,MACvB,SAAS,KAAK,KAAK;AAAA,MACnB,QAAQ;AAAA;AAAA,MACR,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAAA,EAEA,QAAgB;AACd,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,KAA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|
2
|
+
import * as llm from '../llm/index.js';
|
|
3
|
+
import type { APIConnectOptions } from '../types.js';
|
|
4
|
+
import { type AnyString } from './utils.js';
|
|
5
|
+
export type OpenAIModels = 'openai/gpt-5' | 'openai/gpt-5-mini' | 'openai/gpt-5-nano' | 'openai/gpt-4.1' | 'openai/gpt-4.1-mini' | 'openai/gpt-4.1-nano' | 'openai/gpt-4o' | 'openai/gpt-4o-mini' | 'openai/gpt-oss-120b';
|
|
6
|
+
export type GoogleModels = 'google/gemini-2.0-flash-lite';
|
|
7
|
+
export type QwenModels = 'qwen/qwen3-235b-a22b-instruct';
|
|
8
|
+
export type KimiModels = 'moonshotai/kimi-k2-instruct';
|
|
9
|
+
export type DeepSeekModels = 'deepseek-ai/deepseek-v3';
|
|
10
|
+
type ChatCompletionPredictionContentParam = OpenAI.Chat.Completions.ChatCompletionPredictionContent;
|
|
11
|
+
type WebSearchOptions = OpenAI.Chat.Completions.ChatCompletionCreateParams.WebSearchOptions;
|
|
12
|
+
type ToolChoice = OpenAI.Chat.Completions.ChatCompletionCreateParams['tool_choice'];
|
|
13
|
+
type Verbosity = 'low' | 'medium' | 'high';
|
|
14
|
+
export interface ChatCompletionOptions extends Record<string, unknown> {
|
|
15
|
+
frequency_penalty?: number;
|
|
16
|
+
logit_bias?: Record<string, number>;
|
|
17
|
+
logprobs?: boolean;
|
|
18
|
+
max_completion_tokens?: number;
|
|
19
|
+
max_tokens?: number;
|
|
20
|
+
metadata?: Record<string, string>;
|
|
21
|
+
modalities?: Array<'text' | 'audio'>;
|
|
22
|
+
n?: number;
|
|
23
|
+
parallel_tool_calls?: boolean;
|
|
24
|
+
prediction?: ChatCompletionPredictionContentParam | null;
|
|
25
|
+
presence_penalty?: number;
|
|
26
|
+
prompt_cache_key?: string;
|
|
27
|
+
reasoning_effort?: 'minimal' | 'low' | 'medium' | 'high';
|
|
28
|
+
safety_identifier?: string;
|
|
29
|
+
seed?: number;
|
|
30
|
+
service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority';
|
|
31
|
+
stop?: string | string[];
|
|
32
|
+
store?: boolean;
|
|
33
|
+
temperature?: number;
|
|
34
|
+
top_logprobs?: number;
|
|
35
|
+
top_p?: number;
|
|
36
|
+
user?: string;
|
|
37
|
+
verbosity?: Verbosity;
|
|
38
|
+
web_search_options?: WebSearchOptions;
|
|
39
|
+
tool_choice?: ToolChoice;
|
|
40
|
+
}
|
|
41
|
+
export type LLMModels = OpenAIModels | GoogleModels | QwenModels | KimiModels | DeepSeekModels | AnyString;
|
|
42
|
+
export interface InferenceLLMOptions {
|
|
43
|
+
model: LLMModels;
|
|
44
|
+
provider?: string;
|
|
45
|
+
baseURL: string;
|
|
46
|
+
apiKey: string;
|
|
47
|
+
apiSecret: string;
|
|
48
|
+
modelOptions: ChatCompletionOptions;
|
|
49
|
+
}
|
|
50
|
+
export interface GatewayOptions {
|
|
51
|
+
apiKey: string;
|
|
52
|
+
apiSecret: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Livekit Cloud Inference LLM
|
|
56
|
+
*/
|
|
57
|
+
export declare class LLM extends llm.LLM {
|
|
58
|
+
private client;
|
|
59
|
+
private opts;
|
|
60
|
+
constructor(opts: {
|
|
61
|
+
model: LLMModels;
|
|
62
|
+
provider?: string;
|
|
63
|
+
baseURL?: string;
|
|
64
|
+
apiKey?: string;
|
|
65
|
+
apiSecret?: string;
|
|
66
|
+
modelOptions?: InferenceLLMOptions['modelOptions'];
|
|
67
|
+
});
|
|
68
|
+
label(): string;
|
|
69
|
+
get model(): string;
|
|
70
|
+
static fromModelString(modelString: string): LLM;
|
|
71
|
+
chat({ chatCtx, toolCtx, connOptions, parallelToolCalls, toolChoice, extraKwargs, }: {
|
|
72
|
+
chatCtx: llm.ChatContext;
|
|
73
|
+
toolCtx?: llm.ToolContext;
|
|
74
|
+
connOptions?: APIConnectOptions;
|
|
75
|
+
parallelToolCalls?: boolean;
|
|
76
|
+
toolChoice?: llm.ToolChoice;
|
|
77
|
+
extraKwargs?: Record<string, unknown>;
|
|
78
|
+
}): LLMStream;
|
|
79
|
+
}
|
|
80
|
+
export declare class LLMStream extends llm.LLMStream {
|
|
81
|
+
private model;
|
|
82
|
+
private provider?;
|
|
83
|
+
private providerFmt;
|
|
84
|
+
private client;
|
|
85
|
+
private modelOptions;
|
|
86
|
+
private gatewayOptions?;
|
|
87
|
+
private toolCallId?;
|
|
88
|
+
private toolIndex?;
|
|
89
|
+
private fncName?;
|
|
90
|
+
private fncRawArguments?;
|
|
91
|
+
constructor(llm: LLM, { model, provider, client, chatCtx, toolCtx, gatewayOptions, connOptions, modelOptions, providerFmt, }: {
|
|
92
|
+
model: LLMModels;
|
|
93
|
+
provider?: string;
|
|
94
|
+
client: OpenAI;
|
|
95
|
+
chatCtx: llm.ChatContext;
|
|
96
|
+
toolCtx?: llm.ToolContext;
|
|
97
|
+
gatewayOptions?: GatewayOptions;
|
|
98
|
+
connOptions: APIConnectOptions;
|
|
99
|
+
modelOptions: Record<string, any>;
|
|
100
|
+
providerFmt?: llm.ProviderFormat;
|
|
101
|
+
});
|
|
102
|
+
protected run(): Promise<void>;
|
|
103
|
+
private parseChoice;
|
|
104
|
+
private createRunningToolCallChunk;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=llm.d.ts.map
|