booths 0.1.0 → 0.1.2

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
@@ -904,10 +904,9 @@ export declare class ToolRegistry {
904
904
  registerTools(tools: ToolModule[]): void;
905
905
  /**
906
906
  * Registers a single tool in the registry.
907
- * Throws an error if a tool with the same ID already exists.
907
+ * If a tool with the same ID already exists, it will not be re-registered.
908
908
  *
909
909
  * @param tool - The OpenAI Tool instance to register
910
- * @throws Error if a tool with the same ID is already registered
911
910
  */
912
911
  registerTool(tool: ToolModule): void;
913
912
  /**
package/dist/index.js CHANGED
@@ -167,8 +167,8 @@ class R {
167
167
  */
168
168
  async runAfterToolCall(t, o, e, r) {
169
169
  let n = e;
170
- for (const l of this.plugins)
171
- l.onAfterToolCall && (n = await l.onAfterToolCall(t, o, n, r));
170
+ for (const a of this.plugins)
171
+ a.onAfterToolCall && (n = await a.onAfterToolCall(t, o, n, r));
172
172
  return n;
173
173
  }
174
174
  /**
@@ -184,8 +184,8 @@ class R {
184
184
  */
185
185
  async runToolCallError(t, o, e, r) {
186
186
  let n = `Error: ${e.message}`;
187
- for (const l of this.plugins)
188
- l.onToolCallError && (n = await l.onToolCallError(t, o, e, r));
187
+ for (const a of this.plugins)
188
+ a.onToolCallError && (n = await a.onToolCallError(t, o, e, r));
189
189
  return n;
190
190
  }
191
191
  }
@@ -484,14 +484,20 @@ ${(r.examples || []).map((n) => ` - "${n}"`).join(`
484
484
  return {
485
485
  type: "function",
486
486
  name: d,
487
- description: "Routes the conversation to a specialized booth based on the user's needs. Each booth has a specific role and set of capabilities.",
487
+ description: `
488
+ Routes the conversation to a specialized booth based on the user's needs. Each booth has a
489
+ specific role and set of capabilities.
490
+ `,
488
491
  parameters: {
489
492
  type: "object",
490
493
  properties: {
491
494
  targetBooth: {
492
495
  type: "string",
493
- description: `The ID of the booth to route the conversation to. Must be one of the following available booths:
494
- ${o}`,
496
+ description: `
497
+ The ID of the booth to route the conversation to. Must be one of the following available
498
+ booths:
499
+ ${o}
500
+ `,
495
501
  enum: e
496
502
  }
497
503
  },
@@ -587,15 +593,15 @@ class I {
587
593
  async onResponseReceived(t, o, e) {
588
594
  let n = [...o.input, ...(e == null ? void 0 : e.output) ?? []];
589
595
  if (this.responseContainsBoothChange(e)) {
590
- const a = `Please summarize the following conversation history:
596
+ const l = `Please summarize the following conversation history:
591
597
 
592
- ${JSON.stringify(c)}`, g = (await S(t.llmAdapter, C).callProcessor.send(a)).output_text, f = n.filter((h) => "role" in h && h.role === "user").pop(), y = {
598
+ ${JSON.stringify(c)}`, g = (await S(t.llmAdapter, C).callProcessor.send(l)).output_text, y = n.filter((h) => "role" in h && h.role === "user").pop(), f = {
593
599
  role: "developer",
594
600
  content: `A conversation summary up to this point: ${g}`
595
601
  }, m = n.filter(
596
602
  (h) => "type" in h && h.type === "function_call" || h.type === "function_call_output"
597
603
  );
598
- c = f ? [...m, y, f] : [...m, y], n = c;
604
+ c = y ? [...m, f, y] : [...m, f], n = c;
599
605
  } else
600
606
  c = n;
601
607
  return {
@@ -661,12 +667,12 @@ class v {
661
667
  const e = t.boothRegistry;
662
668
  let n = e.baseBoothConfig.description;
663
669
  if (e.isMultiBoothMode) {
664
- const l = e.orchestratorBoothConfig, a = e.currentContextBoothConfig;
670
+ const a = e.orchestratorBoothConfig, l = e.currentContextBoothConfig;
665
671
  n += `
666
672
 
667
- ${l.description}`, a.id !== l.id && (n += `
673
+ ${a.description}`, l.id !== a.id && (n += `
668
674
 
669
- ${a.description}`);
675
+ ${l.description}`);
670
676
  }
671
677
  return { ...o, instructions: n };
672
678
  }
@@ -693,14 +699,15 @@ class A {
693
699
  }
694
700
  /**
695
701
  * Registers a single tool in the registry.
696
- * Throws an error if a tool with the same ID already exists.
702
+ * If a tool with the same ID already exists, it will not be re-registered.
697
703
  *
698
704
  * @param tool - The OpenAI Tool instance to register
699
- * @throws Error if a tool with the same ID is already registered
700
705
  */
701
706
  registerTool(t) {
702
- if (this.tools.has(t.name))
703
- throw new Error(`Tool with ID ${t.name} is already registered.`);
707
+ if (this.tools.has(t.name)) {
708
+ console.warn(`Tool with ID '${t.name}' is already registered. Duplicate registration ignored.`);
709
+ return;
710
+ }
704
711
  this.tools.set(t.name, t);
705
712
  }
706
713
  /**
@@ -751,22 +758,16 @@ class P {
751
758
  * @returns The updated response parameters with the aggregated list of tools.
752
759
  */
753
760
  async onBeforeMessageSend(t, o) {
754
- const e = t.boothRegistry.baseBoothConfig, r = t.boothRegistry.currentContextBoothConfig, n = [...e.tools || [], ...(r == null ? void 0 : r.tools) || []], l = /* @__PURE__ */ new Set();
755
- for (const u of n) {
756
- if (l.has(u))
757
- throw new Error(`Duplicate tool key detected: ${u}`);
758
- l.add(u);
759
- }
760
- const a = n.map(
761
+ const e = t.boothRegistry.baseBoothConfig, r = t.boothRegistry.currentContextBoothConfig, n = [...e.tools || [], ...(r == null ? void 0 : r.tools) || []], l = [...new Set(n)].map(
761
762
  (u) => t.toolRegistry.getTool(u)
762
763
  );
763
- if (e.mcp && a.push(...e.mcp), r != null && r.mcp && a.push(...r.mcp), t.boothRegistry.isMultiBoothMode) {
764
+ if (e.mcp && l.push(...e.mcp), r != null && r.mcp && l.push(...r.mcp), t.boothRegistry.isMultiBoothMode) {
764
765
  const u = w(t.boothRegistry);
765
- a.push(u);
766
+ l.push(u);
766
767
  }
767
768
  return {
768
769
  ...o,
769
- tools: a
770
+ tools: l
770
771
  };
771
772
  }
772
773
  /**
@@ -805,16 +806,16 @@ class x {
805
806
  call_id: r.call_id,
806
807
  output: `Error: Tool '${r.name}' not found.`
807
808
  };
808
- const l = await n.execute(JSON.parse(r.arguments)), a = await t.pluginRegistry.runAfterToolCall(
809
+ const a = await n.execute(JSON.parse(r.arguments)), l = await t.pluginRegistry.runAfterToolCall(
809
810
  t,
810
811
  r,
811
- l,
812
+ a,
812
813
  e
813
814
  );
814
815
  return {
815
816
  type: "function_call_output",
816
817
  call_id: r.call_id,
817
- output: JSON.stringify(a)
818
+ output: JSON.stringify(l)
818
819
  };
819
820
  } catch (r) {
820
821
  console.error(`Error executing tool ${o.name}:`, r);
@@ -842,23 +843,23 @@ class x {
842
843
  */
843
844
  async onResponseReceived(t, o, e) {
844
845
  const r = (e == null ? void 0 : e.output) ?? [], n = (r == null ? void 0 : r.filter(
845
- (a) => a.type === "function_call"
846
+ (l) => l.type === "function_call"
846
847
  )) ?? [];
847
848
  if (!n.length)
848
849
  return o;
849
- const l = [];
850
- for (let a = 0; a < n.length; a++) {
851
- const u = n[a], p = {
850
+ const a = [];
851
+ for (let l = 0; l < n.length; l++) {
852
+ const u = n[l], p = {
852
853
  responseParams: o,
853
854
  response: e,
854
- toolCallIndex: a,
855
+ toolCallIndex: l,
855
856
  totalToolCalls: n.length
856
857
  }, g = await this.executeToolCall(t, u, p);
857
- l.push(g);
858
+ a.push(g);
858
859
  }
859
860
  return {
860
861
  ...o,
861
- input: [...o.input, ...l]
862
+ input: [...o.input, ...a]
862
863
  };
863
864
  }
864
865
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "booths",
3
3
  "private": false,
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",