@livekit/agents 1.0.35 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/voice/agent_activity.cjs +19 -19
  2. package/dist/voice/agent_activity.cjs.map +1 -1
  3. package/dist/voice/agent_activity.d.ts.map +1 -1
  4. package/dist/voice/agent_activity.js +19 -19
  5. package/dist/voice/agent_activity.js.map +1 -1
  6. package/dist/voice/agent_session.cjs +64 -25
  7. package/dist/voice/agent_session.cjs.map +1 -1
  8. package/dist/voice/agent_session.d.cts +25 -1
  9. package/dist/voice/agent_session.d.ts +25 -1
  10. package/dist/voice/agent_session.d.ts.map +1 -1
  11. package/dist/voice/agent_session.js +64 -25
  12. package/dist/voice/agent_session.js.map +1 -1
  13. package/dist/voice/index.cjs +14 -1
  14. package/dist/voice/index.cjs.map +1 -1
  15. package/dist/voice/index.d.cts +1 -0
  16. package/dist/voice/index.d.ts +1 -0
  17. package/dist/voice/index.d.ts.map +1 -1
  18. package/dist/voice/index.js +3 -1
  19. package/dist/voice/index.js.map +1 -1
  20. package/dist/voice/room_io/room_io.cjs +1 -0
  21. package/dist/voice/room_io/room_io.cjs.map +1 -1
  22. package/dist/voice/room_io/room_io.d.ts.map +1 -1
  23. package/dist/voice/room_io/room_io.js +1 -0
  24. package/dist/voice/room_io/room_io.js.map +1 -1
  25. package/dist/voice/speech_handle.cjs +12 -3
  26. package/dist/voice/speech_handle.cjs.map +1 -1
  27. package/dist/voice/speech_handle.d.cts +12 -2
  28. package/dist/voice/speech_handle.d.ts +12 -2
  29. package/dist/voice/speech_handle.d.ts.map +1 -1
  30. package/dist/voice/speech_handle.js +10 -2
  31. package/dist/voice/speech_handle.js.map +1 -1
  32. package/dist/voice/testing/index.cjs +52 -0
  33. package/dist/voice/testing/index.cjs.map +1 -0
  34. package/dist/voice/testing/index.d.cts +20 -0
  35. package/dist/voice/testing/index.d.ts +20 -0
  36. package/dist/voice/testing/index.d.ts.map +1 -0
  37. package/dist/voice/testing/index.js +31 -0
  38. package/dist/voice/testing/index.js.map +1 -0
  39. package/dist/voice/testing/run_result.cjs +477 -0
  40. package/dist/voice/testing/run_result.cjs.map +1 -0
  41. package/dist/voice/testing/run_result.d.cts +226 -0
  42. package/dist/voice/testing/run_result.d.ts +226 -0
  43. package/dist/voice/testing/run_result.d.ts.map +1 -0
  44. package/dist/voice/testing/run_result.js +451 -0
  45. package/dist/voice/testing/run_result.js.map +1 -0
  46. package/dist/voice/testing/types.cjs +46 -0
  47. package/dist/voice/testing/types.cjs.map +1 -0
  48. package/dist/voice/testing/types.d.cts +83 -0
  49. package/dist/voice/testing/types.d.ts +83 -0
  50. package/dist/voice/testing/types.d.ts.map +1 -0
  51. package/dist/voice/testing/types.js +19 -0
  52. package/dist/voice/testing/types.js.map +1 -0
  53. package/package.json +3 -3
  54. package/src/voice/agent_activity.ts +24 -22
  55. package/src/voice/agent_session.ts +73 -28
  56. package/src/voice/index.ts +1 -0
  57. package/src/voice/room_io/room_io.ts +1 -0
  58. package/src/voice/speech_handle.ts +24 -4
  59. package/src/voice/testing/index.ts +49 -0
  60. package/src/voice/testing/run_result.ts +576 -0
  61. package/src/voice/testing/types.ts +118 -0
@@ -974,10 +974,12 @@ ${instructions}` : instructions,
974
974
  replyAbortController
975
975
  );
976
976
  tasks.push(llmTask);
977
- const [ttsTextInput, llmOutput] = llmGenData.textStream.tee();
978
977
  let ttsTask = null;
979
978
  let ttsStream = null;
979
+ let llmOutput;
980
980
  if (audioOutput) {
981
+ const [ttsTextInput, textOutput] = llmGenData.textStream.tee();
982
+ llmOutput = textOutput;
981
983
  [ttsTask, ttsStream] = (0, import_generation.performTTSInference)(
982
984
  (...args) => this.agent.ttsNode(...args),
983
985
  ttsTextInput,
@@ -985,6 +987,8 @@ ${instructions}` : instructions,
985
987
  replyAbortController
986
988
  );
987
989
  tasks.push(ttsTask);
990
+ } else {
991
+ llmOutput = llmGenData.textStream;
988
992
  }
989
993
  await speechHandle.waitIfNotInterrupted([speechHandle._waitForScheduled()]);
990
994
  if (newMessage && speechHandle.scheduled) {
@@ -1031,9 +1035,15 @@ ${instructions}` : instructions,
1031
1035
  } else {
1032
1036
  textOut == null ? void 0 : textOut.firstTextFut.await.finally(onFirstFrame);
1033
1037
  }
1034
- const onToolExecutionStarted = (_) => {
1038
+ const onToolExecutionStarted = (f) => {
1039
+ speechHandle._itemAdded([f]);
1040
+ this.agent._chatCtx.items.push(f);
1041
+ this.agentSession._toolItemsAdded([f]);
1035
1042
  };
1036
- const onToolExecutionCompleted = (_) => {
1043
+ const onToolExecutionCompleted = (out) => {
1044
+ if (out.toolCallOutput) {
1045
+ speechHandle._itemAdded([out.toolCallOutput]);
1046
+ }
1037
1047
  };
1038
1048
  const [executeToolsTask, toolOutput] = (0, import_generation.performToolExecutions)({
1039
1049
  session: this.agentSession,
@@ -1093,6 +1103,7 @@ ${instructions}` : instructions,
1093
1103
  });
1094
1104
  chatCtx.insert(message);
1095
1105
  this.agent._chatCtx.insert(message);
1106
+ speechHandle._itemAdded([message]);
1096
1107
  this.agentSession._conversationItemAdded(message);
1097
1108
  }
1098
1109
  if (this.agentSession.agentState === "speaking") {
@@ -1116,6 +1127,7 @@ ${instructions}` : instructions,
1116
1127
  });
1117
1128
  chatCtx.insert(message);
1118
1129
  this.agent._chatCtx.insert(message);
1130
+ speechHandle._itemAdded([message]);
1119
1131
  this.agentSession._conversationItemAdded(message);
1120
1132
  this.logger.info(
1121
1133
  { speech_id: speechHandle.id, message: textOut.text },
@@ -1184,24 +1196,12 @@ ${instructions}` : instructions,
1184
1196
  ];
1185
1197
  if (shouldGenerateToolReply) {
1186
1198
  chatCtx.insert(toolMessages);
1187
- const handle = import_speech_handle.SpeechHandle.create({
1188
- allowInterruptions: speechHandle.allowInterruptions,
1189
- stepIndex: speechHandle._stepIndex + 1,
1190
- parent: speechHandle
1191
- });
1192
- this.agentSession.emit(
1193
- import_events.AgentSessionEventTypes.SpeechCreated,
1194
- (0, import_events.createSpeechCreatedEvent)({
1195
- userInitiated: false,
1196
- source: "tool_response",
1197
- speechHandle: handle
1198
- })
1199
- );
1199
+ speechHandle._numSteps += 1;
1200
1200
  const respondToolChoice = draining || modelSettings.toolChoice === "none" ? "none" : "auto";
1201
1201
  const toolResponseTask = this.createSpeechTask({
1202
1202
  task: import_utils.Task.from(
1203
1203
  () => this.pipelineReplyTask(
1204
- handle,
1204
+ speechHandle,
1205
1205
  chatCtx,
1206
1206
  toolCtx,
1207
1207
  { toolChoice: respondToolChoice },
@@ -1211,11 +1211,11 @@ ${instructions}` : instructions,
1211
1211
  toolMessages
1212
1212
  )
1213
1213
  ),
1214
- ownedSpeechHandle: handle,
1214
+ ownedSpeechHandle: speechHandle,
1215
1215
  name: "AgentActivity.pipelineReply"
1216
1216
  });
1217
1217
  toolResponseTask.finally(() => this.onPipelineReplyDone());
1218
- this.scheduleSpeech(handle, import_speech_handle.SpeechHandle.SPEECH_PRIORITY_NORMAL, true);
1218
+ this.scheduleSpeech(speechHandle, import_speech_handle.SpeechHandle.SPEECH_PRIORITY_NORMAL, true);
1219
1219
  } else if (functionToolsExecutedEvent.functionCallOutputs.length > 0) {
1220
1220
  for (const msg of toolMessages) {
1221
1221
  msg.createdAt = replyStartedAt;