@livekit/agents-plugin-openai 1.5.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -52,7 +52,7 @@ class OpenAIPlugin extends import_agents.Plugin {
52
52
  constructor() {
53
53
  super({
54
54
  title: "openai",
55
- version: "1.5.3",
55
+ version: "1.6.0",
56
56
  package: "@livekit/agents-plugin-openai"
57
57
  });
58
58
  }
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ class OpenAIPlugin extends Plugin {
11
11
  constructor() {
12
12
  super({
13
13
  title: "openai",
14
- version: "1.5.3",
14
+ version: "1.6.0",
15
15
  package: "@livekit/agents-plugin-openai"
16
16
  });
17
17
  }
@@ -473,7 +473,7 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
473
473
  const timeoutController = new AbortController();
474
474
  const timeoutPromise = (0, import_agents.delay)(5e3, { signal: timeoutController.signal }).then(() => {
475
475
  cleanupTimedOutFutures();
476
- throw new Error("Chat ctx update events timed out");
476
+ throw new import_agents.llm.RealtimeError("update_chat_ctx timed out.");
477
477
  });
478
478
  try {
479
479
  await Promise.race([Promise.all(futures), timeoutPromise]);
@@ -512,7 +512,7 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
512
512
  event_id: (0, import_agents.shortuuid)("chat_ctx_delete_")
513
513
  });
514
514
  }
515
- for (const [previousId, id] of diffOps.toCreate) {
515
+ const createItem = async (previousId, id) => {
516
516
  const chatItem = newChatCtx.getById(id);
517
517
  if (!chatItem) {
518
518
  throw new Error(`Chat item ${id} not found`);
@@ -523,6 +523,24 @@ class RealtimeSession extends import_agents.llm.RealtimeSession {
523
523
  previous_item_id: previousId ?? void 0,
524
524
  event_id: (0, import_agents.shortuuid)("chat_ctx_create_")
525
525
  });
526
+ };
527
+ const isContentEmpty = (id) => {
528
+ const remoteItem = remoteCtx.getById(id);
529
+ return (remoteItem == null ? void 0 : remoteItem.type) === "message" && remoteItem.content.length === 0;
530
+ };
531
+ for (const [previousId, id] of diffOps.toCreate) {
532
+ await createItem(previousId, id);
533
+ }
534
+ for (const [previousId, id] of diffOps.toUpdate) {
535
+ if (isContentEmpty(id)) {
536
+ continue;
537
+ }
538
+ events.push({
539
+ type: "conversation.item.delete",
540
+ item_id: id,
541
+ event_id: (0, import_agents.shortuuid)("chat_ctx_delete_")
542
+ });
543
+ await createItem(previousId, id);
526
544
  }
527
545
  return events;
528
546
  }