booths 1.3.0 → 1.3.1

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.d.ts CHANGED
@@ -830,6 +830,28 @@ export declare class InteractionProcessor<T> {
830
830
  * @private
831
831
  */
832
832
  private callLLMStreaming;
833
+ /**
834
+ * Type guard to check if an output item has a function property (tool call).
835
+ * @param output - The output item to check
836
+ * @returns True if the output item is a tool call with a function
837
+ * @private
838
+ */
839
+ private isToolCall;
840
+ /**
841
+ * Helper function to safely update tool call arguments.
842
+ * @param accumulated - The accumulated response
843
+ * @param callId - The tool call ID to update
844
+ * @param delta - The argument delta to append
845
+ * @private
846
+ */
847
+ private updateToolCallArguments;
848
+ /**
849
+ * Helper function to safely update a tool call with final data.
850
+ * @param accumulated - The accumulated response
851
+ * @param toolCallData - The final tool call data
852
+ * @private
853
+ */
854
+ private updateToolCallFunction;
833
855
  /**
834
856
  * Merges a stream event into the accumulated response.
835
857
  * @param accumulated - The current accumulated response.
package/dist/index.js CHANGED
@@ -605,6 +605,38 @@ class T {
605
605
  }
606
606
  return this.finalizeAccumulatedResponse(r, t);
607
607
  }
608
+ /**
609
+ * Type guard to check if an output item has a function property (tool call).
610
+ * @param output - The output item to check
611
+ * @returns True if the output item is a tool call with a function
612
+ * @private
613
+ */
614
+ isToolCall(t) {
615
+ return t && "function" in t && t.function && typeof t.function.arguments == "string";
616
+ }
617
+ /**
618
+ * Helper function to safely update tool call arguments.
619
+ * @param accumulated - The accumulated response
620
+ * @param callId - The tool call ID to update
621
+ * @param delta - The argument delta to append
622
+ * @private
623
+ */
624
+ updateToolCallArguments(t, o, e) {
625
+ if (!t.output) return;
626
+ const r = t.output.find((s) => s.id === o);
627
+ this.isToolCall(r) && (r.function.arguments = (r.function.arguments || "") + e);
628
+ }
629
+ /**
630
+ * Helper function to safely update a tool call with final data.
631
+ * @param accumulated - The accumulated response
632
+ * @param toolCallData - The final tool call data
633
+ * @private
634
+ */
635
+ updateToolCallFunction(t, o) {
636
+ if (!t.output || !o?.id || !o?.function) return;
637
+ const e = t.output.find((r) => r.id === o.id);
638
+ this.isToolCall(e) && (e.function = o.function);
639
+ }
608
640
  /**
609
641
  * Merges a stream event into the accumulated response.
610
642
  * @param accumulated - The current accumulated response.
@@ -617,11 +649,14 @@ class T {
617
649
  return t;
618
650
  switch (o.type) {
619
651
  case "text_delta":
620
- o.delta && (t.output_text = (t.output_text || "") + o.delta);
652
+ o.delta && !o.metadata?.call_id ? t.output_text = (t.output_text || "") + o.delta : o.delta && o.metadata?.call_id && typeof o.metadata.call_id == "string" && (t.output = t.output || [], this.updateToolCallArguments(t, o.metadata.call_id, o.delta));
621
653
  break;
622
654
  case "tool_call_start":
623
655
  o.toolCall && (t.output = t.output || [], t.output.push(o.toolCall));
624
656
  break;
657
+ case "tool_call_end":
658
+ o.toolCall && (t.output = t.output || [], this.updateToolCallFunction(t, o.toolCall));
659
+ break;
625
660
  }
626
661
  return t;
627
662
  }
@@ -889,7 +924,7 @@ class x {
889
924
  if (this.responseContainsBoothChange(e)) {
890
925
  const l = `Please summarize the following conversation history:
891
926
 
892
- ${JSON.stringify(this.sessionHistory)}`, g = (await M(t.llmAdapter, I).callProcessor.send(l)).output_text, d = s.filter((c) => "role" in c && c.role === "user").pop(), b = {
927
+ ${JSON.stringify(this.sessionHistory)}`, g = (await L(t.llmAdapter, I).callProcessor.send(l)).output_text, d = s.filter((c) => "role" in c && c.role === "user").pop(), b = {
893
928
  role: "developer",
894
929
  content: `A conversation summary up to this point: ${g}`
895
930
  }, _ = s.filter((c) => !("role" in c && c.role === "user" || "type" in c && c.type === "message"));
@@ -911,7 +946,7 @@ ${JSON.stringify(this.sessionHistory)}`, g = (await M(t.llmAdapter, I).callProce
911
946
  return !1;
912
947
  }
913
948
  }
914
- class S {
949
+ class C {
915
950
  /**
916
951
  * Unique identifier for this plugin instance.
917
952
  * @private
@@ -1072,7 +1107,7 @@ class w {
1072
1107
  this.tools.delete(t);
1073
1108
  }
1074
1109
  }
1075
- function v(n) {
1110
+ function S(n) {
1076
1111
  switch (n.type) {
1077
1112
  case "function":
1078
1113
  return `function:${n.name}`;
@@ -1095,15 +1130,15 @@ function v(n) {
1095
1130
  return `${n.type}:${JSON.stringify(n)}`;
1096
1131
  }
1097
1132
  }
1098
- function C(n) {
1133
+ function v(n) {
1099
1134
  const t = /* @__PURE__ */ new Set(), o = [];
1100
1135
  for (const e of n) {
1101
- const r = v(e);
1136
+ const r = S(e);
1102
1137
  t.has(r) || (t.add(r), o.push(e));
1103
1138
  }
1104
1139
  return o;
1105
1140
  }
1106
- class E {
1141
+ class A {
1107
1142
  description = "A plugin to aggregate and provide tools from base and context booths.";
1108
1143
  id = "tool-provider";
1109
1144
  name = "Tool Provider Plugin";
@@ -1124,7 +1159,7 @@ class E {
1124
1159
  l.push(a);
1125
1160
  }
1126
1161
  l.push(...t.toolRegistry.getGlobalTools());
1127
- const h = C(l);
1162
+ const h = v(l);
1128
1163
  return {
1129
1164
  ...o,
1130
1165
  tools: h
@@ -1241,7 +1276,7 @@ class m {
1241
1276
  return !1;
1242
1277
  }
1243
1278
  }
1244
- class A {
1279
+ class M {
1245
1280
  description = "A plugin to ensure the interaction loop can be finished.";
1246
1281
  id = "finish-turn-plugin";
1247
1282
  name = "Finish Turn Plugin";
@@ -1381,16 +1416,16 @@ class k {
1381
1416
  return !1;
1382
1417
  }
1383
1418
  }
1384
- function M(n, t) {
1419
+ function L(n, t) {
1385
1420
  const o = new B(t), e = new w(), r = new p();
1386
- return new L({
1421
+ return new P({
1387
1422
  llmAdapter: n,
1388
1423
  booths: o,
1389
1424
  tools: e,
1390
1425
  boothPlugins: r
1391
1426
  });
1392
1427
  }
1393
- class L {
1428
+ class P {
1394
1429
  /**
1395
1430
  * Represents a registry that maintains a collection of plugins for a booth system.
1396
1431
  * The boothPluginRegistry is used to manage and access plugins that enhance
@@ -1458,10 +1493,10 @@ class L {
1458
1493
  }
1459
1494
  this.systemPluginsRegistry = new p(), this.systemPluginsRegistry.registerPlugins([
1460
1495
  new x(t.sessionHistory),
1461
- new S(),
1462
- new E(),
1496
+ new C(),
1497
+ new A(),
1463
1498
  new m(),
1464
- new A()
1499
+ new M()
1465
1500
  ]), this.systemPluginsRegistry.registerPlugins(this.boothPluginRegistry.getPlugins()), this.callProcessor = new T(
1466
1501
  this.boothRegistry,
1467
1502
  this.systemPluginsRegistry,
@@ -1473,16 +1508,16 @@ class L {
1473
1508
  export {
1474
1509
  p as BoothPluginRegistry,
1475
1510
  B as BoothRegistry,
1476
- S as ContextProviderPlugin,
1511
+ C as ContextProviderPlugin,
1477
1512
  x as ConversationHistoryPlugin,
1478
- L as CoreBooth,
1479
- A as FinishTurnPlugin,
1513
+ P as CoreBooth,
1514
+ M as FinishTurnPlugin,
1480
1515
  T as InteractionProcessor,
1481
1516
  $ as StreamingLoggerPlugin,
1482
1517
  k as StreamingUIPlugin,
1483
1518
  m as ToolExecutorPlugin,
1484
- E as ToolProviderPlugin,
1519
+ A as ToolProviderPlugin,
1485
1520
  w as ToolRegistry,
1486
- M as createCoreBooth,
1521
+ L as createCoreBooth,
1487
1522
  y as createRouteToBoothTool
1488
1523
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "booths",
3
3
  "private": false,
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",