@livekit/agents 1.0.47 → 1.0.49
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/beta/index.cjs +29 -0
- package/dist/beta/index.cjs.map +1 -0
- package/dist/beta/index.d.cts +2 -0
- package/dist/beta/index.d.ts +2 -0
- package/dist/beta/index.d.ts.map +1 -0
- package/dist/beta/index.js +7 -0
- package/dist/beta/index.js.map +1 -0
- package/dist/beta/workflows/index.cjs +29 -0
- package/dist/beta/workflows/index.cjs.map +1 -0
- package/dist/beta/workflows/index.d.cts +2 -0
- package/dist/beta/workflows/index.d.ts +2 -0
- package/dist/beta/workflows/index.d.ts.map +1 -0
- package/dist/beta/workflows/index.js +7 -0
- package/dist/beta/workflows/index.js.map +1 -0
- package/dist/beta/workflows/task_group.cjs +162 -0
- package/dist/beta/workflows/task_group.cjs.map +1 -0
- package/dist/beta/workflows/task_group.d.cts +32 -0
- package/dist/beta/workflows/task_group.d.ts +32 -0
- package/dist/beta/workflows/task_group.d.ts.map +1 -0
- package/dist/beta/workflows/task_group.js +138 -0
- package/dist/beta/workflows/task_group.js.map +1 -0
- package/dist/cpu.cjs +189 -0
- package/dist/cpu.cjs.map +1 -0
- package/dist/cpu.d.cts +24 -0
- package/dist/cpu.d.ts +24 -0
- package/dist/cpu.d.ts.map +1 -0
- package/dist/cpu.js +152 -0
- package/dist/cpu.js.map +1 -0
- package/dist/cpu.test.cjs +227 -0
- package/dist/cpu.test.cjs.map +1 -0
- package/dist/cpu.test.js +204 -0
- package/dist/cpu.test.js.map +1 -0
- 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.d.cts +59 -59
- package/dist/inference/api_protos.d.ts +59 -59
- package/dist/inference/llm.cjs.map +1 -1
- package/dist/inference/llm.d.cts +1 -1
- package/dist/inference/llm.d.ts +1 -1
- package/dist/inference/llm.d.ts.map +1 -1
- package/dist/inference/llm.js.map +1 -1
- package/dist/inference/tts.cjs.map +1 -1
- package/dist/inference/tts.d.cts +6 -0
- package/dist/inference/tts.d.ts +6 -0
- package/dist/inference/tts.d.ts.map +1 -1
- package/dist/inference/tts.js.map +1 -1
- package/dist/llm/chat_context.cjs +89 -1
- package/dist/llm/chat_context.cjs.map +1 -1
- package/dist/llm/chat_context.d.cts +10 -1
- package/dist/llm/chat_context.d.ts +10 -1
- package/dist/llm/chat_context.d.ts.map +1 -1
- package/dist/llm/chat_context.js +89 -1
- package/dist/llm/chat_context.js.map +1 -1
- package/dist/llm/chat_context.test.cjs +43 -0
- package/dist/llm/chat_context.test.cjs.map +1 -1
- package/dist/llm/chat_context.test.js +43 -0
- package/dist/llm/chat_context.test.js.map +1 -1
- package/dist/llm/index.cjs +2 -0
- package/dist/llm/index.cjs.map +1 -1
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +3 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/provider_format/index.d.cts +1 -1
- package/dist/llm/provider_format/index.d.ts +1 -1
- package/dist/llm/tool_context.cjs +7 -0
- package/dist/llm/tool_context.cjs.map +1 -1
- package/dist/llm/tool_context.d.cts +10 -2
- package/dist/llm/tool_context.d.ts +10 -2
- package/dist/llm/tool_context.d.ts.map +1 -1
- package/dist/llm/tool_context.js +6 -0
- package/dist/llm/tool_context.js.map +1 -1
- package/dist/utils.cjs +1 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/dist/voice/agent.cjs +9 -0
- package/dist/voice/agent.cjs.map +1 -1
- package/dist/voice/agent.d.cts +1 -0
- package/dist/voice/agent.d.ts +1 -0
- package/dist/voice/agent.d.ts.map +1 -1
- package/dist/voice/agent.js +9 -0
- package/dist/voice/agent.js.map +1 -1
- package/dist/voice/agent_activity.cjs +67 -16
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.cts +7 -0
- package/dist/voice/agent_activity.d.ts +7 -0
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +68 -17
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +27 -1
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +6 -0
- package/dist/voice/agent_session.d.ts +6 -0
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +27 -1
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/room_io/room_io.cjs +11 -2
- package/dist/voice/room_io/room_io.cjs.map +1 -1
- package/dist/voice/room_io/room_io.d.ts.map +1 -1
- package/dist/voice/room_io/room_io.js +12 -3
- package/dist/voice/room_io/room_io.js.map +1 -1
- package/dist/voice/testing/fake_llm.cjs +127 -0
- package/dist/voice/testing/fake_llm.cjs.map +1 -0
- package/dist/voice/testing/fake_llm.d.cts +30 -0
- package/dist/voice/testing/fake_llm.d.ts +30 -0
- package/dist/voice/testing/fake_llm.d.ts.map +1 -0
- package/dist/voice/testing/fake_llm.js +103 -0
- package/dist/voice/testing/fake_llm.js.map +1 -0
- package/dist/voice/testing/index.cjs +3 -0
- package/dist/voice/testing/index.cjs.map +1 -1
- package/dist/voice/testing/index.d.cts +1 -0
- package/dist/voice/testing/index.d.ts +1 -0
- package/dist/voice/testing/index.d.ts.map +1 -1
- package/dist/voice/testing/index.js +2 -0
- package/dist/voice/testing/index.js.map +1 -1
- package/dist/worker.cjs +6 -29
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +6 -19
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/beta/index.ts +9 -0
- package/src/beta/workflows/index.ts +9 -0
- package/src/beta/workflows/task_group.ts +194 -0
- package/src/cpu.test.ts +239 -0
- package/src/cpu.ts +173 -0
- package/src/index.ts +2 -1
- package/src/inference/llm.ts +2 -0
- package/src/inference/tts.ts +8 -1
- package/src/llm/chat_context.test.ts +48 -0
- package/src/llm/chat_context.ts +123 -0
- package/src/llm/index.ts +1 -0
- package/src/llm/tool_context.ts +14 -0
- package/src/utils.ts +5 -0
- package/src/voice/agent.ts +11 -0
- package/src/voice/agent_activity.ts +102 -16
- package/src/voice/agent_session.ts +33 -2
- package/src/voice/room_io/room_io.ts +14 -3
- package/src/voice/testing/fake_llm.ts +138 -0
- package/src/voice/testing/index.ts +2 -0
- package/src/worker.ts +34 -50
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var fake_llm_exports = {};
|
|
20
|
+
__export(fake_llm_exports, {
|
|
21
|
+
FakeLLM: () => FakeLLM
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(fake_llm_exports);
|
|
24
|
+
var import_chat_context = require("../../llm/chat_context.cjs");
|
|
25
|
+
var import_llm = require("../../llm/llm.cjs");
|
|
26
|
+
var import_types = require("../../types.cjs");
|
|
27
|
+
var import_utils = require("../../utils.cjs");
|
|
28
|
+
class FakeLLM extends import_llm.LLM {
|
|
29
|
+
responseMap = /* @__PURE__ */ new Map();
|
|
30
|
+
constructor(responses = []) {
|
|
31
|
+
super();
|
|
32
|
+
for (const response of responses) {
|
|
33
|
+
this.responseMap.set(response.input, {
|
|
34
|
+
type: "llm",
|
|
35
|
+
ttft: 0,
|
|
36
|
+
duration: 0,
|
|
37
|
+
...response
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
label() {
|
|
42
|
+
return "fake-llm";
|
|
43
|
+
}
|
|
44
|
+
chat({
|
|
45
|
+
chatCtx,
|
|
46
|
+
toolCtx,
|
|
47
|
+
connOptions = import_types.DEFAULT_API_CONNECT_OPTIONS
|
|
48
|
+
}) {
|
|
49
|
+
return new FakeLLMStream(this, {
|
|
50
|
+
chatCtx,
|
|
51
|
+
toolCtx,
|
|
52
|
+
connOptions
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
lookup(input) {
|
|
56
|
+
return this.responseMap.get(input);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
class FakeLLMStream extends import_llm.LLMStream {
|
|
60
|
+
fake;
|
|
61
|
+
constructor(fake, params) {
|
|
62
|
+
super(fake, params);
|
|
63
|
+
this.fake = fake;
|
|
64
|
+
}
|
|
65
|
+
async run() {
|
|
66
|
+
const input = this.getInputText();
|
|
67
|
+
const decision = this.fake.lookup(input);
|
|
68
|
+
if (!decision) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const startedAt = Date.now();
|
|
72
|
+
if ((decision.ttft ?? 0) > 0) {
|
|
73
|
+
await (0, import_utils.delay)(decision.ttft);
|
|
74
|
+
}
|
|
75
|
+
const content = decision.content ?? "";
|
|
76
|
+
const chunkSize = 3;
|
|
77
|
+
for (let i = 0; i < content.length; i += chunkSize) {
|
|
78
|
+
this.queue.put({
|
|
79
|
+
id: "fake",
|
|
80
|
+
delta: { role: "assistant", content: content.slice(i, i + chunkSize) }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (decision.toolCalls && decision.toolCalls.length > 0) {
|
|
84
|
+
const calls = decision.toolCalls.map(
|
|
85
|
+
(tc, index) => import_chat_context.FunctionCall.create({
|
|
86
|
+
callId: `fake_call_${index}`,
|
|
87
|
+
name: tc.name,
|
|
88
|
+
args: JSON.stringify(tc.args)
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
this.queue.put({
|
|
92
|
+
id: "fake",
|
|
93
|
+
delta: { role: "assistant", toolCalls: calls }
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const elapsed = Date.now() - startedAt;
|
|
97
|
+
const waitMs = Math.max(0, (decision.duration ?? 0) - elapsed);
|
|
98
|
+
if (waitMs > 0) {
|
|
99
|
+
await (0, import_utils.delay)(waitMs);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
getInputText() {
|
|
103
|
+
const items = this.chatCtx.items;
|
|
104
|
+
if (items.length === 0) {
|
|
105
|
+
throw new Error("No input text found");
|
|
106
|
+
}
|
|
107
|
+
for (const item of items) {
|
|
108
|
+
if (item.type === "message" && item.role === "system") {
|
|
109
|
+
const text = item.textContent ?? "";
|
|
110
|
+
const lines = text.split("\n");
|
|
111
|
+
const tail = lines[lines.length - 1] ?? "";
|
|
112
|
+
if (lines.length > 1 && tail.startsWith("instructions:")) {
|
|
113
|
+
return tail;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const last = items[items.length - 1];
|
|
118
|
+
if (last.type === "message" && last.role === "user") return last.textContent ?? "";
|
|
119
|
+
if (last.type === "function_call_output") return last.output;
|
|
120
|
+
throw new Error("No input text found");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
124
|
+
0 && (module.exports = {
|
|
125
|
+
FakeLLM
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=fake_llm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/voice/testing/fake_llm.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChatContext } from '../../llm/chat_context.js';\nimport { FunctionCall } from '../../llm/chat_context.js';\nimport { LLMStream as BaseLLMStream, LLM, type LLMStream } from '../../llm/llm.js';\nimport type { ToolChoice, ToolContext } from '../../llm/tool_context.js';\nimport { type APIConnectOptions, DEFAULT_API_CONNECT_OPTIONS } from '../../types.js';\nimport { delay } from '../../utils.js';\n\nexport interface FakeLLMResponse {\n input: string;\n type?: 'llm';\n content?: string;\n ttft?: number;\n duration?: number;\n toolCalls?: Array<{ name: string; args: Record<string, unknown> }>;\n}\n\nexport class FakeLLM extends LLM {\n private readonly responseMap = new Map<string, FakeLLMResponse>();\n\n constructor(responses: FakeLLMResponse[] = []) {\n super();\n for (const response of responses) {\n this.responseMap.set(response.input, {\n type: 'llm',\n ttft: 0,\n duration: 0,\n ...response,\n });\n }\n }\n\n label(): string {\n return 'fake-llm';\n }\n\n chat({\n chatCtx,\n toolCtx,\n connOptions = DEFAULT_API_CONNECT_OPTIONS,\n }: {\n chatCtx: ChatContext;\n toolCtx?: ToolContext;\n connOptions?: APIConnectOptions;\n parallelToolCalls?: boolean;\n toolChoice?: ToolChoice;\n extraKwargs?: Record<string, unknown>;\n }): LLMStream {\n return new FakeLLMStream(this, {\n chatCtx,\n toolCtx,\n connOptions,\n });\n }\n\n lookup(input: string): FakeLLMResponse | undefined {\n return this.responseMap.get(input);\n }\n}\n\nclass FakeLLMStream extends BaseLLMStream {\n private readonly fake: FakeLLM;\n\n constructor(\n fake: FakeLLM,\n params: { chatCtx: ChatContext; toolCtx?: ToolContext; connOptions: APIConnectOptions },\n ) {\n super(fake, params);\n this.fake = fake;\n }\n\n protected async run(): Promise<void> {\n const input = this.getInputText();\n const decision = this.fake.lookup(input);\n if (!decision) {\n return;\n }\n\n const startedAt = Date.now();\n if ((decision.ttft ?? 0) > 0) {\n await delay(decision.ttft!);\n }\n\n const content = decision.content ?? '';\n const chunkSize = 3;\n for (let i = 0; i < content.length; i += chunkSize) {\n this.queue.put({\n id: 'fake',\n delta: { role: 'assistant', content: content.slice(i, i + chunkSize) },\n });\n }\n\n if (decision.toolCalls && decision.toolCalls.length > 0) {\n const calls = decision.toolCalls.map((tc, index) =>\n FunctionCall.create({\n callId: `fake_call_${index}`,\n name: tc.name,\n args: JSON.stringify(tc.args),\n }),\n );\n this.queue.put({\n id: 'fake',\n delta: { role: 'assistant', toolCalls: calls },\n });\n }\n\n const elapsed = Date.now() - startedAt;\n const waitMs = Math.max(0, (decision.duration ?? 0) - elapsed);\n if (waitMs > 0) {\n await delay(waitMs);\n }\n }\n\n private getInputText(): string {\n const items = this.chatCtx.items;\n if (items.length === 0) {\n throw new Error('No input text found');\n }\n\n for (const item of items) {\n if (item.type === 'message' && item.role === 'system') {\n const text = item.textContent ?? '';\n const lines = text.split('\\n');\n const tail = lines[lines.length - 1] ?? '';\n if (lines.length > 1 && tail.startsWith('instructions:')) {\n return tail;\n }\n }\n }\n\n const last = items[items.length - 1]!;\n if (last.type === 'message' && last.role === 'user') return last.textContent ?? '';\n if (last.type === 'function_call_output') return last.output;\n throw new Error('No input text found');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAA6B;AAC7B,iBAAgE;AAEhE,mBAAoE;AACpE,mBAAsB;AAWf,MAAM,gBAAgB,eAAI;AAAA,EACd,cAAc,oBAAI,IAA6B;AAAA,EAEhE,YAAY,YAA+B,CAAC,GAAG;AAC7C,UAAM;AACN,eAAW,YAAY,WAAW;AACh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,GAAG;AAAA,UACT,MAAM,KAAK,UAAU,GAAG,IAAI;AAAA,QAC9B,CAAC;AAAA,MACH;AACA,WAAK,MAAM,IAAI;AAAA,QACb,IAAI;AAAA,QACJ,OAAO,EAAE,MAAM,aAAa,WAAW,MAAM;AAAA,MAC/C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,KAAK,IAAI,IAAI;AAC7B,UAAM,SAAS,KAAK,IAAI,IAAI,SAAS,YAAY,KAAK,OAAO;AAC7D,QAAI,SAAS,GAAG;AACd,gBAAM,oBAAM,MAAM;AAAA,IACpB;AAAA,EACF;AAAA,EAEQ,eAAuB;AAC7B,UAAM,QAAQ,KAAK,QAAQ;AAC3B,QAAI,MAAM,WAAW,GAAG;AACtB,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AAEA,eAAW,QAAQ,OAAO;AACxB,UAAI,KAAK,SAAS,aAAa,KAAK,SAAS,UAAU;AACrD,cAAM,OAAO,KAAK,eAAe;AACjC,cAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,cAAM,OAAO,MAAM,MAAM,SAAS,CAAC,KAAK;AACxC,YAAI,MAAM,SAAS,KAAK,KAAK,WAAW,eAAe,GAAG;AACxD,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAEA,UAAM,OAAO,MAAM,MAAM,SAAS,CAAC;AACnC,QAAI,KAAK,SAAS,aAAa,KAAK,SAAS,OAAQ,QAAO,KAAK,eAAe;AAChF,QAAI,KAAK,SAAS,uBAAwB,QAAO,KAAK;AACtD,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AACF;","names":["BaseLLMStream"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChatContext } from '../../llm/chat_context.js';
|
|
2
|
+
import { LLM, type LLMStream } from '../../llm/llm.js';
|
|
3
|
+
import type { ToolChoice, ToolContext } from '../../llm/tool_context.js';
|
|
4
|
+
import { type APIConnectOptions } from '../../types.js';
|
|
5
|
+
export interface FakeLLMResponse {
|
|
6
|
+
input: string;
|
|
7
|
+
type?: 'llm';
|
|
8
|
+
content?: string;
|
|
9
|
+
ttft?: number;
|
|
10
|
+
duration?: number;
|
|
11
|
+
toolCalls?: Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
args: Record<string, unknown>;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare class FakeLLM extends LLM {
|
|
17
|
+
private readonly responseMap;
|
|
18
|
+
constructor(responses?: FakeLLMResponse[]);
|
|
19
|
+
label(): string;
|
|
20
|
+
chat({ chatCtx, toolCtx, connOptions, }: {
|
|
21
|
+
chatCtx: ChatContext;
|
|
22
|
+
toolCtx?: ToolContext;
|
|
23
|
+
connOptions?: APIConnectOptions;
|
|
24
|
+
parallelToolCalls?: boolean;
|
|
25
|
+
toolChoice?: ToolChoice;
|
|
26
|
+
extraKwargs?: Record<string, unknown>;
|
|
27
|
+
}): LLMStream;
|
|
28
|
+
lookup(input: string): FakeLLMResponse | undefined;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=fake_llm.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChatContext } from '../../llm/chat_context.js';
|
|
2
|
+
import { LLM, type LLMStream } from '../../llm/llm.js';
|
|
3
|
+
import type { ToolChoice, ToolContext } from '../../llm/tool_context.js';
|
|
4
|
+
import { type APIConnectOptions } from '../../types.js';
|
|
5
|
+
export interface FakeLLMResponse {
|
|
6
|
+
input: string;
|
|
7
|
+
type?: 'llm';
|
|
8
|
+
content?: string;
|
|
9
|
+
ttft?: number;
|
|
10
|
+
duration?: number;
|
|
11
|
+
toolCalls?: Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
args: Record<string, unknown>;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare class FakeLLM extends LLM {
|
|
17
|
+
private readonly responseMap;
|
|
18
|
+
constructor(responses?: FakeLLMResponse[]);
|
|
19
|
+
label(): string;
|
|
20
|
+
chat({ chatCtx, toolCtx, connOptions, }: {
|
|
21
|
+
chatCtx: ChatContext;
|
|
22
|
+
toolCtx?: ToolContext;
|
|
23
|
+
connOptions?: APIConnectOptions;
|
|
24
|
+
parallelToolCalls?: boolean;
|
|
25
|
+
toolChoice?: ToolChoice;
|
|
26
|
+
extraKwargs?: Record<string, unknown>;
|
|
27
|
+
}): LLMStream;
|
|
28
|
+
lookup(input: string): FakeLLMResponse | undefined;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=fake_llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake_llm.d.ts","sourceRoot":"","sources":["../../../src/voice/testing/fake_llm.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAA8B,GAAG,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,KAAK,iBAAiB,EAA+B,MAAM,gBAAgB,CAAC;AAGrF,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CACpE;AAED,qBAAa,OAAQ,SAAQ,GAAG;IAC9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;gBAEtD,SAAS,GAAE,eAAe,EAAO;IAY7C,KAAK,IAAI,MAAM;IAIf,IAAI,CAAC,EACH,OAAO,EACP,OAAO,EACP,WAAyC,GAC1C,EAAE;QACD,OAAO,EAAE,WAAW,CAAC;QACrB,OAAO,CAAC,EAAE,WAAW,CAAC;QACtB,WAAW,CAAC,EAAE,iBAAiB,CAAC;QAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,UAAU,CAAC,EAAE,UAAU,CAAC;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACvC,GAAG,SAAS;IAQb,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;CAGnD"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { FunctionCall } from "../../llm/chat_context.js";
|
|
2
|
+
import { LLMStream as BaseLLMStream, LLM } from "../../llm/llm.js";
|
|
3
|
+
import { DEFAULT_API_CONNECT_OPTIONS } from "../../types.js";
|
|
4
|
+
import { delay } from "../../utils.js";
|
|
5
|
+
class FakeLLM extends LLM {
|
|
6
|
+
responseMap = /* @__PURE__ */ new Map();
|
|
7
|
+
constructor(responses = []) {
|
|
8
|
+
super();
|
|
9
|
+
for (const response of responses) {
|
|
10
|
+
this.responseMap.set(response.input, {
|
|
11
|
+
type: "llm",
|
|
12
|
+
ttft: 0,
|
|
13
|
+
duration: 0,
|
|
14
|
+
...response
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
label() {
|
|
19
|
+
return "fake-llm";
|
|
20
|
+
}
|
|
21
|
+
chat({
|
|
22
|
+
chatCtx,
|
|
23
|
+
toolCtx,
|
|
24
|
+
connOptions = DEFAULT_API_CONNECT_OPTIONS
|
|
25
|
+
}) {
|
|
26
|
+
return new FakeLLMStream(this, {
|
|
27
|
+
chatCtx,
|
|
28
|
+
toolCtx,
|
|
29
|
+
connOptions
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
lookup(input) {
|
|
33
|
+
return this.responseMap.get(input);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class FakeLLMStream extends BaseLLMStream {
|
|
37
|
+
fake;
|
|
38
|
+
constructor(fake, params) {
|
|
39
|
+
super(fake, params);
|
|
40
|
+
this.fake = fake;
|
|
41
|
+
}
|
|
42
|
+
async run() {
|
|
43
|
+
const input = this.getInputText();
|
|
44
|
+
const decision = this.fake.lookup(input);
|
|
45
|
+
if (!decision) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const startedAt = Date.now();
|
|
49
|
+
if ((decision.ttft ?? 0) > 0) {
|
|
50
|
+
await delay(decision.ttft);
|
|
51
|
+
}
|
|
52
|
+
const content = decision.content ?? "";
|
|
53
|
+
const chunkSize = 3;
|
|
54
|
+
for (let i = 0; i < content.length; i += chunkSize) {
|
|
55
|
+
this.queue.put({
|
|
56
|
+
id: "fake",
|
|
57
|
+
delta: { role: "assistant", content: content.slice(i, i + chunkSize) }
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (decision.toolCalls && decision.toolCalls.length > 0) {
|
|
61
|
+
const calls = decision.toolCalls.map(
|
|
62
|
+
(tc, index) => FunctionCall.create({
|
|
63
|
+
callId: `fake_call_${index}`,
|
|
64
|
+
name: tc.name,
|
|
65
|
+
args: JSON.stringify(tc.args)
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
this.queue.put({
|
|
69
|
+
id: "fake",
|
|
70
|
+
delta: { role: "assistant", toolCalls: calls }
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const elapsed = Date.now() - startedAt;
|
|
74
|
+
const waitMs = Math.max(0, (decision.duration ?? 0) - elapsed);
|
|
75
|
+
if (waitMs > 0) {
|
|
76
|
+
await delay(waitMs);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getInputText() {
|
|
80
|
+
const items = this.chatCtx.items;
|
|
81
|
+
if (items.length === 0) {
|
|
82
|
+
throw new Error("No input text found");
|
|
83
|
+
}
|
|
84
|
+
for (const item of items) {
|
|
85
|
+
if (item.type === "message" && item.role === "system") {
|
|
86
|
+
const text = item.textContent ?? "";
|
|
87
|
+
const lines = text.split("\n");
|
|
88
|
+
const tail = lines[lines.length - 1] ?? "";
|
|
89
|
+
if (lines.length > 1 && tail.startsWith("instructions:")) {
|
|
90
|
+
return tail;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const last = items[items.length - 1];
|
|
95
|
+
if (last.type === "message" && last.role === "user") return last.textContent ?? "";
|
|
96
|
+
if (last.type === "function_call_output") return last.output;
|
|
97
|
+
throw new Error("No input text found");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
FakeLLM
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=fake_llm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/voice/testing/fake_llm.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2026 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChatContext } from '../../llm/chat_context.js';\nimport { FunctionCall } from '../../llm/chat_context.js';\nimport { LLMStream as BaseLLMStream, LLM, type LLMStream } from '../../llm/llm.js';\nimport type { ToolChoice, ToolContext } from '../../llm/tool_context.js';\nimport { type APIConnectOptions, DEFAULT_API_CONNECT_OPTIONS } from '../../types.js';\nimport { delay } from '../../utils.js';\n\nexport interface FakeLLMResponse {\n input: string;\n type?: 'llm';\n content?: string;\n ttft?: number;\n duration?: number;\n toolCalls?: Array<{ name: string; args: Record<string, unknown> }>;\n}\n\nexport class FakeLLM extends LLM {\n private readonly responseMap = new Map<string, FakeLLMResponse>();\n\n constructor(responses: FakeLLMResponse[] = []) {\n super();\n for (const response of responses) {\n this.responseMap.set(response.input, {\n type: 'llm',\n ttft: 0,\n duration: 0,\n ...response,\n });\n }\n }\n\n label(): string {\n return 'fake-llm';\n }\n\n chat({\n chatCtx,\n toolCtx,\n connOptions = DEFAULT_API_CONNECT_OPTIONS,\n }: {\n chatCtx: ChatContext;\n toolCtx?: ToolContext;\n connOptions?: APIConnectOptions;\n parallelToolCalls?: boolean;\n toolChoice?: ToolChoice;\n extraKwargs?: Record<string, unknown>;\n }): LLMStream {\n return new FakeLLMStream(this, {\n chatCtx,\n toolCtx,\n connOptions,\n });\n }\n\n lookup(input: string): FakeLLMResponse | undefined {\n return this.responseMap.get(input);\n }\n}\n\nclass FakeLLMStream extends BaseLLMStream {\n private readonly fake: FakeLLM;\n\n constructor(\n fake: FakeLLM,\n params: { chatCtx: ChatContext; toolCtx?: ToolContext; connOptions: APIConnectOptions },\n ) {\n super(fake, params);\n this.fake = fake;\n }\n\n protected async run(): Promise<void> {\n const input = this.getInputText();\n const decision = this.fake.lookup(input);\n if (!decision) {\n return;\n }\n\n const startedAt = Date.now();\n if ((decision.ttft ?? 0) > 0) {\n await delay(decision.ttft!);\n }\n\n const content = decision.content ?? '';\n const chunkSize = 3;\n for (let i = 0; i < content.length; i += chunkSize) {\n this.queue.put({\n id: 'fake',\n delta: { role: 'assistant', content: content.slice(i, i + chunkSize) },\n });\n }\n\n if (decision.toolCalls && decision.toolCalls.length > 0) {\n const calls = decision.toolCalls.map((tc, index) =>\n FunctionCall.create({\n callId: `fake_call_${index}`,\n name: tc.name,\n args: JSON.stringify(tc.args),\n }),\n );\n this.queue.put({\n id: 'fake',\n delta: { role: 'assistant', toolCalls: calls },\n });\n }\n\n const elapsed = Date.now() - startedAt;\n const waitMs = Math.max(0, (decision.duration ?? 0) - elapsed);\n if (waitMs > 0) {\n await delay(waitMs);\n }\n }\n\n private getInputText(): string {\n const items = this.chatCtx.items;\n if (items.length === 0) {\n throw new Error('No input text found');\n }\n\n for (const item of items) {\n if (item.type === 'message' && item.role === 'system') {\n const text = item.textContent ?? '';\n const lines = text.split('\\n');\n const tail = lines[lines.length - 1] ?? '';\n if (lines.length > 1 && tail.startsWith('instructions:')) {\n return tail;\n }\n }\n }\n\n const last = items[items.length - 1]!;\n if (last.type === 'message' && last.role === 'user') return last.textContent ?? '';\n if (last.type === 'function_call_output') return last.output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EACvC;AACF;","names":[]}
|
|
@@ -22,6 +22,7 @@ __export(testing_exports, {
|
|
|
22
22
|
AssertionError: () => import_run_result.AssertionError,
|
|
23
23
|
EventAssert: () => import_run_result.EventAssert,
|
|
24
24
|
EventRangeAssert: () => import_run_result.EventRangeAssert,
|
|
25
|
+
FakeLLM: () => import_fake_llm.FakeLLM,
|
|
25
26
|
FunctionCallAssert: () => import_run_result.FunctionCallAssert,
|
|
26
27
|
FunctionCallOutputAssert: () => import_run_result.FunctionCallOutputAssert,
|
|
27
28
|
MessageAssert: () => import_run_result.MessageAssert,
|
|
@@ -35,12 +36,14 @@ __export(testing_exports, {
|
|
|
35
36
|
module.exports = __toCommonJS(testing_exports);
|
|
36
37
|
var import_run_result = require("./run_result.cjs");
|
|
37
38
|
var import_types = require("./types.cjs");
|
|
39
|
+
var import_fake_llm = require("./fake_llm.cjs");
|
|
38
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
41
|
0 && (module.exports = {
|
|
40
42
|
AgentHandoffAssert,
|
|
41
43
|
AssertionError,
|
|
42
44
|
EventAssert,
|
|
43
45
|
EventRangeAssert,
|
|
46
|
+
FakeLLM,
|
|
44
47
|
FunctionCallAssert,
|
|
45
48
|
FunctionCallOutputAssert,
|
|
46
49
|
MessageAssert,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/voice/testing/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Testing utilities for agent evaluation.\n *\n * @example\n * ```typescript\n * import { AgentSession, Agent, voice } from '@livekit/agents';\n *\n * const session = new AgentSession({ llm });\n * await session.start(agent);\n *\n * const result = await session.run({ userInput: 'Hello' });\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * result.expect.noMoreEvents();\n * ```\n *\n * @packageDocumentation\n */\n\nexport {\n AgentHandoffAssert,\n AssertionError,\n EventAssert,\n EventRangeAssert,\n FunctionCallAssert,\n FunctionCallOutputAssert,\n MessageAssert,\n RunAssert,\n RunResult,\n} from './run_result.js';\n\nexport {\n isAgentHandoffEvent,\n isChatMessageEvent,\n isFunctionCallEvent,\n isFunctionCallOutputEvent,\n type AgentHandoffAssertOptions,\n type AgentHandoffEvent,\n type ChatMessageEvent,\n type EventType,\n type FunctionCallAssertOptions,\n type FunctionCallEvent,\n type FunctionCallOutputAssertOptions,\n type FunctionCallOutputEvent,\n type MessageAssertOptions,\n type RunEvent,\n} from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,wBAUO;AAEP,mBAeO;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/voice/testing/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Testing utilities for agent evaluation.\n *\n * @example\n * ```typescript\n * import { AgentSession, Agent, voice } from '@livekit/agents';\n *\n * const session = new AgentSession({ llm });\n * await session.start(agent);\n *\n * const result = await session.run({ userInput: 'Hello' });\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * result.expect.noMoreEvents();\n * ```\n *\n * @packageDocumentation\n */\n\nexport {\n AgentHandoffAssert,\n AssertionError,\n EventAssert,\n EventRangeAssert,\n FunctionCallAssert,\n FunctionCallOutputAssert,\n MessageAssert,\n RunAssert,\n RunResult,\n} from './run_result.js';\n\nexport {\n isAgentHandoffEvent,\n isChatMessageEvent,\n isFunctionCallEvent,\n isFunctionCallOutputEvent,\n type AgentHandoffAssertOptions,\n type AgentHandoffEvent,\n type ChatMessageEvent,\n type EventType,\n type FunctionCallAssertOptions,\n type FunctionCallEvent,\n type FunctionCallOutputAssertOptions,\n type FunctionCallOutputEvent,\n type MessageAssertOptions,\n type RunEvent,\n} from './types.js';\n\nexport { FakeLLM, type FakeLLMResponse } from './fake_llm.js';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,wBAUO;AAEP,mBAeO;AAEP,sBAA8C;","names":[]}
|
|
@@ -17,4 +17,5 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export { AgentHandoffAssert, AssertionError, EventAssert, EventRangeAssert, FunctionCallAssert, FunctionCallOutputAssert, MessageAssert, RunAssert, RunResult, } from './run_result.js';
|
|
19
19
|
export { isAgentHandoffEvent, isChatMessageEvent, isFunctionCallEvent, isFunctionCallOutputEvent, type AgentHandoffAssertOptions, type AgentHandoffEvent, type ChatMessageEvent, type EventType, type FunctionCallAssertOptions, type FunctionCallEvent, type FunctionCallOutputAssertOptions, type FunctionCallOutputEvent, type MessageAssertOptions, type RunEvent, } from './types.js';
|
|
20
|
+
export { FakeLLM, type FakeLLMResponse } from './fake_llm.js';
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -17,4 +17,5 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export { AgentHandoffAssert, AssertionError, EventAssert, EventRangeAssert, FunctionCallAssert, FunctionCallOutputAssert, MessageAssert, RunAssert, RunResult, } from './run_result.js';
|
|
19
19
|
export { isAgentHandoffEvent, isChatMessageEvent, isFunctionCallEvent, isFunctionCallOutputEvent, type AgentHandoffAssertOptions, type AgentHandoffEvent, type ChatMessageEvent, type EventType, type FunctionCallAssertOptions, type FunctionCallEvent, type FunctionCallOutputAssertOptions, type FunctionCallOutputEvent, type MessageAssertOptions, type RunEvent, } from './types.js';
|
|
20
|
+
export { FakeLLM, type FakeLLMResponse } from './fake_llm.js';
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/voice/testing/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,SAAS,EACT,SAAS,GACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,+BAA+B,EACpC,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,QAAQ,GACd,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/voice/testing/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,SAAS,EACT,SAAS,GACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,+BAA+B,EACpC,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,QAAQ,GACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -15,11 +15,13 @@ import {
|
|
|
15
15
|
isFunctionCallEvent,
|
|
16
16
|
isFunctionCallOutputEvent
|
|
17
17
|
} from "./types.js";
|
|
18
|
+
import { FakeLLM } from "./fake_llm.js";
|
|
18
19
|
export {
|
|
19
20
|
AgentHandoffAssert,
|
|
20
21
|
AssertionError,
|
|
21
22
|
EventAssert,
|
|
22
23
|
EventRangeAssert,
|
|
24
|
+
FakeLLM,
|
|
23
25
|
FunctionCallAssert,
|
|
24
26
|
FunctionCallOutputAssert,
|
|
25
27
|
MessageAssert,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/voice/testing/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Testing utilities for agent evaluation.\n *\n * @example\n * ```typescript\n * import { AgentSession, Agent, voice } from '@livekit/agents';\n *\n * const session = new AgentSession({ llm });\n * await session.start(agent);\n *\n * const result = await session.run({ userInput: 'Hello' });\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * result.expect.noMoreEvents();\n * ```\n *\n * @packageDocumentation\n */\n\nexport {\n AgentHandoffAssert,\n AssertionError,\n EventAssert,\n EventRangeAssert,\n FunctionCallAssert,\n FunctionCallOutputAssert,\n MessageAssert,\n RunAssert,\n RunResult,\n} from './run_result.js';\n\nexport {\n isAgentHandoffEvent,\n isChatMessageEvent,\n isFunctionCallEvent,\n isFunctionCallOutputEvent,\n type AgentHandoffAssertOptions,\n type AgentHandoffEvent,\n type ChatMessageEvent,\n type EventType,\n type FunctionCallAssertOptions,\n type FunctionCallEvent,\n type FunctionCallOutputAssertOptions,\n type FunctionCallOutputEvent,\n type MessageAssertOptions,\n type RunEvent,\n} from './types.js';\n"],"mappings":"AAsBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAWK;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/voice/testing/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Testing utilities for agent evaluation.\n *\n * @example\n * ```typescript\n * import { AgentSession, Agent, voice } from '@livekit/agents';\n *\n * const session = new AgentSession({ llm });\n * await session.start(agent);\n *\n * const result = await session.run({ userInput: 'Hello' });\n * result.expect.nextEvent().isMessage({ role: 'assistant' });\n * result.expect.noMoreEvents();\n * ```\n *\n * @packageDocumentation\n */\n\nexport {\n AgentHandoffAssert,\n AssertionError,\n EventAssert,\n EventRangeAssert,\n FunctionCallAssert,\n FunctionCallOutputAssert,\n MessageAssert,\n RunAssert,\n RunResult,\n} from './run_result.js';\n\nexport {\n isAgentHandoffEvent,\n isChatMessageEvent,\n isFunctionCallEvent,\n isFunctionCallOutputEvent,\n type AgentHandoffAssertOptions,\n type AgentHandoffEvent,\n type ChatMessageEvent,\n type EventType,\n type FunctionCallAssertOptions,\n type FunctionCallEvent,\n type FunctionCallOutputAssertOptions,\n type FunctionCallOutputEvent,\n type MessageAssertOptions,\n type RunEvent,\n} from './types.js';\n\nexport { FakeLLM, type FakeLLMResponse } from './fake_llm.js';\n"],"mappings":"AAsBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAWK;AAEP,SAAS,eAAqC;","names":[]}
|
package/dist/worker.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
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
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var worker_exports = {};
|
|
30
20
|
__export(worker_exports, {
|
|
@@ -41,8 +31,8 @@ module.exports = __toCommonJS(worker_exports);
|
|
|
41
31
|
var import_protocol = require("@livekit/protocol");
|
|
42
32
|
var import_livekit_server_sdk = require("livekit-server-sdk");
|
|
43
33
|
var import_node_events = require("node:events");
|
|
44
|
-
var import_node_os = __toESM(require("node:os"), 1);
|
|
45
34
|
var import_ws = require("ws");
|
|
35
|
+
var import_cpu = require("./cpu.cjs");
|
|
46
36
|
var import_http_server = require("./http_server.cjs");
|
|
47
37
|
var import_inference_runner = require("./inference_runner.cjs");
|
|
48
38
|
var import_inference_proc_executor = require("./ipc/inference_proc_executor.cjs");
|
|
@@ -94,24 +84,9 @@ const defaultInitializeProcessFunc = (_) => _;
|
|
|
94
84
|
const defaultRequestFunc = async (ctx) => {
|
|
95
85
|
await ctx.accept();
|
|
96
86
|
};
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
setTimeout(() => {
|
|
101
|
-
const cpus2 = import_node_os.default.cpus();
|
|
102
|
-
let idle = 0;
|
|
103
|
-
let total = 0;
|
|
104
|
-
for (let i = 0; i < cpus1.length; i++) {
|
|
105
|
-
const cpu1 = cpus1[i].times;
|
|
106
|
-
const cpu2 = cpus2[i].times;
|
|
107
|
-
idle += cpu2.idle - cpu1.idle;
|
|
108
|
-
const total1 = Object.values(cpu1).reduce((acc, i2) => acc + i2, 0);
|
|
109
|
-
const total2 = Object.values(cpu2).reduce((acc, i2) => acc + i2, 0);
|
|
110
|
-
total += total2 - total1;
|
|
111
|
-
}
|
|
112
|
-
resolve(+(1 - idle / total).toFixed(2));
|
|
113
|
-
}, UPDATE_LOAD_INTERVAL);
|
|
114
|
-
});
|
|
87
|
+
const cpuMonitor = (0, import_cpu.getCpuMonitor)();
|
|
88
|
+
const defaultCpuLoad = async (_worker) => {
|
|
89
|
+
return cpuMonitor.cpuPercent(UPDATE_LOAD_INTERVAL);
|
|
115
90
|
};
|
|
116
91
|
class WorkerPermissions {
|
|
117
92
|
canPublish;
|
|
@@ -564,6 +539,8 @@ class AgentServer {
|
|
|
564
539
|
}
|
|
565
540
|
})
|
|
566
541
|
);
|
|
542
|
+
}).catch((e) => {
|
|
543
|
+
this.#logger.warn({ error: e }, "failed to measure CPU load");
|
|
567
544
|
});
|
|
568
545
|
}, UPDATE_LOAD_INTERVAL);
|
|
569
546
|
await close;
|