@livekit/agents 1.0.22 → 1.0.24
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/inference/api_protos.cjs +2 -2
- package/dist/inference/api_protos.cjs.map +1 -1
- package/dist/inference/api_protos.d.cts +16 -16
- package/dist/inference/api_protos.d.ts +16 -16
- package/dist/inference/api_protos.js +2 -2
- package/dist/inference/api_protos.js.map +1 -1
- package/dist/ipc/job_proc_lazy_main.cjs +35 -1
- package/dist/ipc/job_proc_lazy_main.cjs.map +1 -1
- package/dist/ipc/job_proc_lazy_main.js +13 -1
- package/dist/ipc/job_proc_lazy_main.js.map +1 -1
- package/dist/job.cjs +52 -6
- package/dist/job.cjs.map +1 -1
- package/dist/job.d.cts +2 -0
- package/dist/job.d.ts +2 -0
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +52 -6
- package/dist/job.js.map +1 -1
- package/dist/llm/llm.cjs +38 -3
- 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 +38 -3
- package/dist/llm/llm.js.map +1 -1
- package/dist/log.cjs +34 -10
- package/dist/log.cjs.map +1 -1
- package/dist/log.d.cts +7 -0
- package/dist/log.d.ts +7 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +34 -11
- package/dist/log.js.map +1 -1
- package/dist/telemetry/index.cjs +23 -2
- package/dist/telemetry/index.cjs.map +1 -1
- package/dist/telemetry/index.d.cts +4 -1
- package/dist/telemetry/index.d.ts +4 -1
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +27 -2
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/logging.cjs +65 -0
- package/dist/telemetry/logging.cjs.map +1 -0
- package/dist/telemetry/logging.d.cts +21 -0
- package/dist/telemetry/logging.d.ts +21 -0
- package/dist/telemetry/logging.d.ts.map +1 -0
- package/dist/telemetry/logging.js +40 -0
- package/dist/telemetry/logging.js.map +1 -0
- package/dist/telemetry/otel_http_exporter.cjs +144 -0
- package/dist/telemetry/otel_http_exporter.cjs.map +1 -0
- package/dist/telemetry/otel_http_exporter.d.cts +62 -0
- package/dist/telemetry/otel_http_exporter.d.ts +62 -0
- package/dist/telemetry/otel_http_exporter.d.ts.map +1 -0
- package/dist/telemetry/otel_http_exporter.js +120 -0
- package/dist/telemetry/otel_http_exporter.js.map +1 -0
- package/dist/telemetry/pino_otel_transport.cjs +217 -0
- package/dist/telemetry/pino_otel_transport.cjs.map +1 -0
- package/dist/telemetry/pino_otel_transport.d.cts +58 -0
- package/dist/telemetry/pino_otel_transport.d.ts +58 -0
- package/dist/telemetry/pino_otel_transport.d.ts.map +1 -0
- package/dist/telemetry/pino_otel_transport.js +189 -0
- package/dist/telemetry/pino_otel_transport.js.map +1 -0
- package/dist/telemetry/traces.cjs +225 -16
- package/dist/telemetry/traces.cjs.map +1 -1
- package/dist/telemetry/traces.d.cts +17 -0
- package/dist/telemetry/traces.d.ts +17 -0
- package/dist/telemetry/traces.d.ts.map +1 -1
- package/dist/telemetry/traces.js +211 -14
- package/dist/telemetry/traces.js.map +1 -1
- package/dist/tts/tts.cjs +62 -5
- package/dist/tts/tts.cjs.map +1 -1
- package/dist/tts/tts.d.cts +2 -0
- package/dist/tts/tts.d.ts +2 -0
- package/dist/tts/tts.d.ts.map +1 -1
- package/dist/tts/tts.js +62 -5
- package/dist/tts/tts.js.map +1 -1
- package/dist/utils.cjs +6 -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 +5 -0
- package/dist/utils.js.map +1 -1
- package/dist/voice/agent_activity.cjs +93 -7
- package/dist/voice/agent_activity.cjs.map +1 -1
- package/dist/voice/agent_activity.d.cts +3 -0
- package/dist/voice/agent_activity.d.ts +3 -0
- package/dist/voice/agent_activity.d.ts.map +1 -1
- package/dist/voice/agent_activity.js +93 -7
- package/dist/voice/agent_activity.js.map +1 -1
- package/dist/voice/agent_session.cjs +122 -27
- package/dist/voice/agent_session.cjs.map +1 -1
- package/dist/voice/agent_session.d.cts +15 -0
- package/dist/voice/agent_session.d.ts +15 -0
- package/dist/voice/agent_session.d.ts.map +1 -1
- package/dist/voice/agent_session.js +122 -27
- package/dist/voice/agent_session.js.map +1 -1
- package/dist/voice/audio_recognition.cjs +69 -22
- package/dist/voice/audio_recognition.cjs.map +1 -1
- package/dist/voice/audio_recognition.d.cts +5 -0
- package/dist/voice/audio_recognition.d.ts +5 -0
- package/dist/voice/audio_recognition.d.ts.map +1 -1
- package/dist/voice/audio_recognition.js +69 -22
- package/dist/voice/audio_recognition.js.map +1 -1
- package/dist/voice/generation.cjs +43 -3
- package/dist/voice/generation.cjs.map +1 -1
- package/dist/voice/generation.d.ts.map +1 -1
- package/dist/voice/generation.js +43 -3
- package/dist/voice/generation.js.map +1 -1
- package/dist/voice/report.cjs +3 -2
- package/dist/voice/report.cjs.map +1 -1
- package/dist/voice/report.d.cts +7 -1
- package/dist/voice/report.d.ts +7 -1
- package/dist/voice/report.d.ts.map +1 -1
- package/dist/voice/report.js +3 -2
- package/dist/voice/report.js.map +1 -1
- package/package.json +8 -2
- package/src/inference/api_protos.ts +2 -2
- package/src/ipc/job_proc_lazy_main.ts +12 -1
- package/src/job.ts +59 -10
- package/src/llm/llm.ts +48 -5
- package/src/log.ts +52 -15
- package/src/telemetry/index.ts +22 -4
- package/src/telemetry/logging.ts +55 -0
- package/src/telemetry/otel_http_exporter.ts +191 -0
- package/src/telemetry/pino_otel_transport.ts +265 -0
- package/src/telemetry/traces.ts +320 -20
- package/src/tts/tts.ts +71 -9
- package/src/utils.ts +5 -0
- package/src/voice/agent_activity.ts +140 -22
- package/src/voice/agent_session.ts +174 -34
- package/src/voice/audio_recognition.ts +85 -26
- package/src/voice/generation.ts +59 -7
- package/src/voice/report.ts +10 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Mutex } from "@livekit/mutex";
|
|
2
|
+
import { ROOT_CONTEXT, trace } from "@opentelemetry/api";
|
|
2
3
|
import { Heap } from "heap-js";
|
|
3
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
5
|
import { ReadableStream } from "node:stream/web";
|
|
@@ -11,6 +12,7 @@ import { isSameToolChoice, isSameToolContext } from "../llm/tool_context.js";
|
|
|
11
12
|
import { log } from "../log.js";
|
|
12
13
|
import { DeferredReadableStream } from "../stream/deferred_stream.js";
|
|
13
14
|
import { STT } from "../stt/stt.js";
|
|
15
|
+
import { traceTypes, tracer } from "../telemetry/index.js";
|
|
14
16
|
import { splitWords } from "../tokenize/basic/word.js";
|
|
15
17
|
import { TTS } from "../tts/tts.js";
|
|
16
18
|
import { Future, Task, cancelAndWait, waitFor } from "../utils.js";
|
|
@@ -124,6 +126,11 @@ class AgentActivity {
|
|
|
124
126
|
async start() {
|
|
125
127
|
const unlock = await this.lock.lock();
|
|
126
128
|
try {
|
|
129
|
+
const startSpan = tracer.startSpan({
|
|
130
|
+
name: "start_agent_activity",
|
|
131
|
+
attributes: { [traceTypes.ATTR_AGENT_LABEL]: this.agent.id },
|
|
132
|
+
context: ROOT_CONTEXT
|
|
133
|
+
});
|
|
127
134
|
this.agent._agentActivity = this;
|
|
128
135
|
if (this.llm instanceof RealtimeModel) {
|
|
129
136
|
this.realtimeSession = this.llm.session();
|
|
@@ -191,15 +198,22 @@ class AgentActivity {
|
|
|
191
198
|
turnDetector: typeof this.turnDetection === "string" ? void 0 : this.turnDetection,
|
|
192
199
|
turnDetectionMode: this.turnDetectionMode,
|
|
193
200
|
minEndpointingDelay: this.agentSession.options.minEndpointingDelay,
|
|
194
|
-
maxEndpointingDelay: this.agentSession.options.maxEndpointingDelay
|
|
201
|
+
maxEndpointingDelay: this.agentSession.options.maxEndpointingDelay,
|
|
202
|
+
rootSpanContext: this.agentSession.rootSpanContext
|
|
195
203
|
});
|
|
196
204
|
this.audioRecognition.start();
|
|
197
205
|
this.started = true;
|
|
198
206
|
this._mainTask = Task.from(({ signal }) => this.mainTask(signal));
|
|
207
|
+
const onEnterTask = tracer.startActiveSpan(async () => this.agent.onEnter(), {
|
|
208
|
+
name: "on_enter",
|
|
209
|
+
context: trace.setSpan(ROOT_CONTEXT, startSpan),
|
|
210
|
+
attributes: { [traceTypes.ATTR_AGENT_LABEL]: this.agent.id }
|
|
211
|
+
});
|
|
199
212
|
this.createSpeechTask({
|
|
200
|
-
task: Task.from(() =>
|
|
213
|
+
task: Task.from(() => onEnterTask),
|
|
201
214
|
name: "AgentActivity_onEnter"
|
|
202
215
|
});
|
|
216
|
+
startSpan.end();
|
|
203
217
|
} finally {
|
|
204
218
|
unlock();
|
|
205
219
|
}
|
|
@@ -900,9 +914,25 @@ ${instructions}` : instructions,
|
|
|
900
914
|
this.agentSession._updateAgentState("listening");
|
|
901
915
|
}
|
|
902
916
|
}
|
|
903
|
-
|
|
904
|
-
|
|
917
|
+
_pipelineReplyTaskImpl = async ({
|
|
918
|
+
speechHandle,
|
|
919
|
+
chatCtx,
|
|
920
|
+
toolCtx,
|
|
921
|
+
modelSettings,
|
|
922
|
+
replyAbortController,
|
|
923
|
+
instructions,
|
|
924
|
+
newMessage,
|
|
925
|
+
toolsMessages,
|
|
926
|
+
span
|
|
927
|
+
}) => {
|
|
905
928
|
var _a, _b, _c;
|
|
929
|
+
span.setAttribute(traceTypes.ATTR_SPEECH_ID, speechHandle.id);
|
|
930
|
+
if (instructions) {
|
|
931
|
+
span.setAttribute(traceTypes.ATTR_INSTRUCTIONS, instructions);
|
|
932
|
+
}
|
|
933
|
+
if (newMessage) {
|
|
934
|
+
span.setAttribute(traceTypes.ATTR_USER_INPUT, newMessage.textContent || "");
|
|
935
|
+
}
|
|
906
936
|
speechHandleStorage.enterWith(speechHandle);
|
|
907
937
|
const audioOutput = this.agentSession.output.audioEnabled ? this.agentSession.output.audio : null;
|
|
908
938
|
const transcriptionOutput = this.agentSession.output.transcriptionEnabled ? this.agentSession.output.transcription : null;
|
|
@@ -1011,6 +1041,7 @@ ${instructions}` : instructions,
|
|
|
1011
1041
|
msg.createdAt = replyStartedAt;
|
|
1012
1042
|
}
|
|
1013
1043
|
this.agent._chatCtx.insert(toolsMessages);
|
|
1044
|
+
this.agentSession._toolItemsAdded(toolsMessages);
|
|
1014
1045
|
}
|
|
1015
1046
|
if (speechHandle.interrupted) {
|
|
1016
1047
|
this.logger.debug(
|
|
@@ -1175,10 +1206,50 @@ ${instructions}` : instructions,
|
|
|
1175
1206
|
msg.createdAt = replyStartedAt;
|
|
1176
1207
|
}
|
|
1177
1208
|
this.agent._chatCtx.insert(toolMessages);
|
|
1209
|
+
this.agentSession._toolItemsAdded(toolMessages);
|
|
1178
1210
|
}
|
|
1179
|
-
}
|
|
1211
|
+
};
|
|
1212
|
+
pipelineReplyTask = async (speechHandle, chatCtx, toolCtx, modelSettings, replyAbortController, instructions, newMessage, toolsMessages) => tracer.startActiveSpan(
|
|
1213
|
+
async (span) => this._pipelineReplyTaskImpl({
|
|
1214
|
+
speechHandle,
|
|
1215
|
+
chatCtx,
|
|
1216
|
+
toolCtx,
|
|
1217
|
+
modelSettings,
|
|
1218
|
+
replyAbortController,
|
|
1219
|
+
instructions,
|
|
1220
|
+
newMessage,
|
|
1221
|
+
toolsMessages,
|
|
1222
|
+
span
|
|
1223
|
+
}),
|
|
1224
|
+
{
|
|
1225
|
+
name: "agent_turn",
|
|
1226
|
+
context: this.agentSession.rootSpanContext
|
|
1227
|
+
}
|
|
1228
|
+
);
|
|
1180
1229
|
async realtimeGenerationTask(speechHandle, ev, modelSettings, replyAbortController) {
|
|
1230
|
+
return tracer.startActiveSpan(
|
|
1231
|
+
async (span) => this._realtimeGenerationTaskImpl({
|
|
1232
|
+
speechHandle,
|
|
1233
|
+
ev,
|
|
1234
|
+
modelSettings,
|
|
1235
|
+
replyAbortController,
|
|
1236
|
+
span
|
|
1237
|
+
}),
|
|
1238
|
+
{
|
|
1239
|
+
name: "agent_turn",
|
|
1240
|
+
context: this.agentSession.rootSpanContext
|
|
1241
|
+
}
|
|
1242
|
+
);
|
|
1243
|
+
}
|
|
1244
|
+
async _realtimeGenerationTaskImpl({
|
|
1245
|
+
speechHandle,
|
|
1246
|
+
ev,
|
|
1247
|
+
modelSettings,
|
|
1248
|
+
replyAbortController,
|
|
1249
|
+
span
|
|
1250
|
+
}) {
|
|
1181
1251
|
var _a, _b, _c;
|
|
1252
|
+
span.setAttribute(traceTypes.ATTR_SPEECH_ID, speechHandle.id);
|
|
1182
1253
|
speechHandleStorage.enterWith(speechHandle);
|
|
1183
1254
|
if (!this.realtimeSession) {
|
|
1184
1255
|
throw new Error("realtime session is not initialized");
|
|
@@ -1320,6 +1391,8 @@ ${instructions}` : instructions,
|
|
|
1320
1391
|
);
|
|
1321
1392
|
const onToolExecutionStarted = (f) => {
|
|
1322
1393
|
speechHandle._itemAdded([f]);
|
|
1394
|
+
this.agent._chatCtx.items.push(f);
|
|
1395
|
+
this.agentSession._toolItemsAdded([f]);
|
|
1323
1396
|
};
|
|
1324
1397
|
const onToolExecutionCompleted = (out) => {
|
|
1325
1398
|
if (out.toolCallOutput) {
|
|
@@ -1469,6 +1542,9 @@ ${instructions}` : instructions,
|
|
|
1469
1542
|
}
|
|
1470
1543
|
const chatCtx = this.realtimeSession.chatCtx.copy();
|
|
1471
1544
|
chatCtx.items.push(...functionToolsExecutedEvent.functionCallOutputs);
|
|
1545
|
+
this.agentSession._toolItemsAdded(
|
|
1546
|
+
functionToolsExecutedEvent.functionCallOutputs
|
|
1547
|
+
);
|
|
1472
1548
|
try {
|
|
1473
1549
|
await this.realtimeSession.updateChatCtx(chatCtx);
|
|
1474
1550
|
} catch (error) {
|
|
@@ -1557,15 +1633,25 @@ ${instructions}` : instructions,
|
|
|
1557
1633
|
speechHandle._markScheduled();
|
|
1558
1634
|
this.wakeupMainTask();
|
|
1559
1635
|
}
|
|
1560
|
-
// TODO(brian): PR3 - Wrap entire drain() method with tracer.startActiveSpan('drain_agent_activity', { attributes: { 'lk.agent_label': this.agent.label } })
|
|
1561
1636
|
async drain() {
|
|
1637
|
+
return tracer.startActiveSpan(async (span) => this._drainImpl(span), {
|
|
1638
|
+
name: "drain_agent_activity",
|
|
1639
|
+
context: ROOT_CONTEXT
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
async _drainImpl(span) {
|
|
1562
1643
|
var _a;
|
|
1644
|
+
span.setAttribute(traceTypes.ATTR_AGENT_LABEL, this.agent.id);
|
|
1563
1645
|
const unlock = await this.lock.lock();
|
|
1564
1646
|
try {
|
|
1565
1647
|
if (this._draining) return;
|
|
1566
1648
|
this.cancelPreemptiveGeneration();
|
|
1649
|
+
const onExitTask = tracer.startActiveSpan(async () => this.agent.onExit(), {
|
|
1650
|
+
name: "on_exit",
|
|
1651
|
+
attributes: { [traceTypes.ATTR_AGENT_LABEL]: this.agent.id }
|
|
1652
|
+
});
|
|
1567
1653
|
this.createSpeechTask({
|
|
1568
|
-
task: Task.from(() =>
|
|
1654
|
+
task: Task.from(() => onExitTask),
|
|
1569
1655
|
name: "AgentActivity_onExit"
|
|
1570
1656
|
});
|
|
1571
1657
|
this.wakeupMainTask();
|