booths 1.0.0 → 1.1.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.d.ts CHANGED
@@ -305,6 +305,23 @@ export declare class BoothRegistry {
305
305
  * @private
306
306
  */
307
307
  private currentContextId;
308
+ /**
309
+ * Tracks whether the orchestrator booth is currently registered.
310
+ * @private
311
+ */
312
+ private hasOrchestrator;
313
+ /**
314
+ * Optional callback function that gets called when multi-booth mode is enabled.
315
+ * Used to coordinate external actions like tool registration.
316
+ * @private
317
+ */
318
+ private onMultiBoothModeEnabled?;
319
+ /**
320
+ * Optional callback function that gets called when multi-booth mode is disabled.
321
+ * Used to coordinate external actions like tool unregistration.
322
+ * @private
323
+ */
324
+ private onMultiBoothModeDisabled?;
308
325
  /**
309
326
  * Creates a new booth registry with a specified base booth configuration.
310
327
  *
@@ -375,9 +392,23 @@ export declare class BoothRegistry {
375
392
  getAllBooths(): Record<string, BoothConfig>;
376
393
  toArray(): BoothConfig[];
377
394
  /**
378
- * Checks if the registry is operating in a multi-booth configuration.
379
- * @returns {boolean} `true` if there is more than one booth registered, otherwise `false`.
395
+ * Enables multi-booth mode by registering the orchestrator and setting it as current context.
396
+ * @private
380
397
  */
398
+ private enableMultiBoothMode;
399
+ /**
400
+ * Disables multi-booth mode by unregistering the orchestrator and resetting context to base booth.
401
+ * @private
402
+ */
403
+ private disableMultiBoothMode;
404
+ /**
405
+ * Sets callback functions for when multi-booth mode is enabled/disabled.
406
+ * Used to coordinate external actions like tool registration/unregistration.
407
+ *
408
+ * @param onEnabled - Callback for when multi-booth mode is enabled
409
+ * @param onDisabled - Callback for when multi-booth mode is disabled
410
+ */
411
+ setMultiBoothModeCallbacks(onEnabled?: () => void, onDisabled?: () => void): void;
381
412
  get isMultiBoothMode(): boolean;
382
413
  /**
383
414
  * Removes a booth configuration from the registry by its ID.
@@ -388,6 +419,12 @@ export declare class BoothRegistry {
388
419
  unregisterBooth(boothId: string): void;
389
420
  }
390
421
 
422
+ export declare type BoothResponseInput = BoothResponseInputItem[];
423
+
424
+ export declare type BoothResponseInputItem = (ResponseInputItem & {
425
+ bmId: string;
426
+ }) | string;
427
+
391
428
  /**
392
429
  * The ContextProviderPlugin provides contextual information to booths during interaction loops.
393
430
  *
@@ -480,12 +517,19 @@ export declare class ConversationHistoryPlugin implements BoothPlugin {
480
517
  */
481
518
  private responseContainsBoothChange;
482
519
  /**
483
- * Constructs a new instance with the provided session history.
520
+ * Constructs a new instance with an optional session history.
484
521
  *
485
- * @param {ResponseInput} [sessionHistory=[]] - An optional array representing the session history. Defaults to an empty array if not provided.
486
- * @return {void}
522
+ * @param {ResponseInput[]} [sessionHistory=[]] - An array representing the session history. Defaults to an empty array if not provided.
487
523
  */
488
524
  constructor(sessionHistory?: ResponseInput);
525
+ /**
526
+ * Retrieves the session history.
527
+ *
528
+ * @return {Array} The history of the current session.
529
+ */
530
+ get history(): (ResponseInputItem & {
531
+ bmId?: string;
532
+ })[];
489
533
  /**
490
534
  * Returns the plugin's unique identifier.
491
535
  */
@@ -517,7 +561,7 @@ export declare class ConversationHistoryPlugin implements BoothPlugin {
517
561
  * @returns Unmodified response parameters
518
562
  */
519
563
  onResponseReceived(utilities: RepositoryUtilities, responseParams: ResponseCreateParamsNonStreaming, response: Response_2): Promise<{
520
- input: ( ResponseFunctionToolCall | EasyInputMessage | ResponseOutputMessage | ResponseFileSearchToolCall | ResponseComputerToolCall | ResponseInputItem.ComputerCallOutput | ResponseFunctionWebSearch | ResponseInputItem.FunctionCallOutput | ResponseReasoningItem | ResponseInputItem.ImageGenerationCall | ResponseCodeInterpreterToolCall | ResponseInputItem.LocalShellCall | ResponseInputItem.LocalShellCallOutput | ResponseInputItem.McpListTools | ResponseInputItem.McpApprovalRequest | ResponseInputItem.McpApprovalResponse | ResponseInputItem.McpCall | ResponseInputItem.ItemReference)[];
564
+ input: ( EasyInputMessage | ResponseOutputMessage | ResponseFileSearchToolCall | ResponseComputerToolCall | ResponseInputItem.ComputerCallOutput | ResponseFunctionWebSearch | ResponseFunctionToolCall | ResponseInputItem.FunctionCallOutput | ResponseReasoningItem | ResponseInputItem.ImageGenerationCall | ResponseCodeInterpreterToolCall | ResponseInputItem.LocalShellCall | ResponseInputItem.LocalShellCallOutput | ResponseInputItem.McpListTools | ResponseInputItem.McpApprovalRequest | ResponseInputItem.McpApprovalResponse | ResponseInputItem.McpCall | ResponseInputItem.ItemReference)[];
521
565
  stream?: false | null;
522
566
  background?: boolean | null;
523
567
  include?: Array< ResponseIncludable> | null;
package/dist/index.js CHANGED
@@ -1,14 +1,9 @@
1
- var T = Object.defineProperty;
2
- var B = (i, t, o) => t in i ? T(i, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : i[t] = o;
3
- var n = (i, t, o) => B(i, typeof t != "symbol" ? t + "" : t, o);
4
- class d {
5
- constructor() {
6
- /**
7
- * Collection of registered plugins.
8
- * @private
9
- */
10
- n(this, "plugins", []);
11
- }
1
+ class p {
2
+ /**
3
+ * Collection of registered plugins.
4
+ * @private
5
+ */
6
+ plugins = [];
12
7
  /**
13
8
  * Registers a single plugin in the registry.
14
9
  * Throws an error if a plugin with the same ID already exists.
@@ -167,8 +162,8 @@ class d {
167
162
  */
168
163
  async runAfterToolCall(t, o, e, r) {
169
164
  let s = e;
170
- for (const a of this.plugins)
171
- a.onAfterToolCall && (s = await a.onAfterToolCall(t, o, s, r));
165
+ for (const l of this.plugins)
166
+ l.onAfterToolCall && (s = await l.onAfterToolCall(t, o, s, r));
172
167
  return s;
173
168
  }
174
169
  /**
@@ -184,12 +179,47 @@ class d {
184
179
  */
185
180
  async runToolCallError(t, o, e, r) {
186
181
  let s = `Error: ${e.message}`;
187
- for (const a of this.plugins)
188
- a.onToolCallError && (s = await a.onToolCallError(t, o, e, r));
182
+ for (const l of this.plugins)
183
+ l.onToolCallError && (s = await l.onToolCallError(t, o, e, r));
189
184
  return s;
190
185
  }
191
186
  }
192
- class v {
187
+ const u = {
188
+ id: "orchestrator",
189
+ role: `
190
+ This booth serves as the orchestration layer that analyzes user intent and routes
191
+ conversations to the most appropriate specialized booth configuration.
192
+ `,
193
+ description: `
194
+ You are the orchestration layer responsible for determining which booth configuration
195
+ should be active based on user needs. Focus exclusively on routing - do not answer
196
+ questions or provide information directly to users.
197
+
198
+ [ROUTING STRATEGY]
199
+ - Analyze user request and route to the most appropriate specialized booth immediately
200
+ - This booth is only active for initial routing or when explicitly routed back to
201
+ - Once routed, the target booth handles the conversation until completion or re-routing
202
+
203
+ [ROUTING TARGETS]
204
+ - Ambiguous requests → Ask for clarification, then route appropriately
205
+
206
+ [CORE PRINCIPLES]
207
+ - Maintain illusion of single, continuous assistant
208
+ - Never reference booths, tools, or system mechanics to users
209
+ - Silent routing is preferred when intent is clear
210
+ - Only speak to users when clarification is absolutely necessary
211
+
212
+ [ROUTING BEHAVIOR]
213
+ - Clear intent: Route silently using route_to_booth() - do NOT respond to user
214
+ - Ambiguous intent: Ask user for clarification, then route once clarified
215
+ - Never respond to user AND route - it's either respond OR route, not both
216
+
217
+ [BEHAVIOR EXAMPLES]
218
+ - User: "How do I test my number?" → route_to_booth({ targetBooth: 'page-router-booth' })
219
+ - User: "I need help" → "What specifically would you like help with?" → then route based on response
220
+ `
221
+ };
222
+ class R {
193
223
  /**
194
224
  * Creates a new booth registry with a specified base booth configuration.
195
225
  *
@@ -197,18 +227,35 @@ class v {
197
227
  * @param currentContextId - The initial current context booth ID (default is 'orchestrator')
198
228
  */
199
229
  constructor(t, o) {
200
- /**
201
- * Collection of registered booth configurations, indexed by their IDs.
202
- * @private
203
- */
204
- n(this, "booths", {});
205
- /**
206
- * The current context booth ID, defaulting to the orchestrator context.
207
- * @private
208
- */
209
- n(this, "currentContextId");
210
230
  this.baseBooth = t, this.registerBooth(t), this.currentContextId = o || t.id;
211
231
  }
232
+ /**
233
+ * Collection of registered booth configurations, indexed by their IDs.
234
+ * @private
235
+ */
236
+ booths = {};
237
+ /**
238
+ * The current context booth ID, defaulting to the orchestrator context.
239
+ * @private
240
+ */
241
+ currentContextId;
242
+ /**
243
+ * Tracks whether the orchestrator booth is currently registered.
244
+ * @private
245
+ */
246
+ hasOrchestrator = !1;
247
+ /**
248
+ * Optional callback function that gets called when multi-booth mode is enabled.
249
+ * Used to coordinate external actions like tool registration.
250
+ * @private
251
+ */
252
+ onMultiBoothModeEnabled;
253
+ /**
254
+ * Optional callback function that gets called when multi-booth mode is disabled.
255
+ * Used to coordinate external actions like tool unregistration.
256
+ * @private
257
+ */
258
+ onMultiBoothModeDisabled;
212
259
  /**
213
260
  * Gets the current context booth ID.
214
261
  *
@@ -247,7 +294,11 @@ class v {
247
294
  * @param boothConfig - The booth configuration to register
248
295
  */
249
296
  registerBooth(t) {
250
- this.booths[t.id] || (this.booths[t.id] = t);
297
+ if (this.booths[t.id])
298
+ return;
299
+ this.booths[t.id] = t, Object.keys(this.booths).filter(
300
+ (e) => e !== u.id
301
+ ).length > 1 && !this.hasOrchestrator && this.enableMultiBoothMode();
251
302
  }
252
303
  /**
253
304
  * Returns the base booth configuration that was provided during initialization.
@@ -301,11 +352,33 @@ class v {
301
352
  return Object.values(this.booths);
302
353
  }
303
354
  /**
304
- * Checks if the registry is operating in a multi-booth configuration.
305
- * @returns {boolean} `true` if there is more than one booth registered, otherwise `false`.
355
+ * Enables multi-booth mode by registering the orchestrator and setting it as current context.
356
+ * @private
306
357
  */
358
+ enableMultiBoothMode() {
359
+ this.hasOrchestrator || (this.booths[u.id] = u, this.hasOrchestrator = !0, this.currentContextId = u.id, this.onMultiBoothModeEnabled?.());
360
+ }
361
+ /**
362
+ * Disables multi-booth mode by unregistering the orchestrator and resetting context to base booth.
363
+ * @private
364
+ */
365
+ disableMultiBoothMode() {
366
+ this.hasOrchestrator && (delete this.booths[u.id], this.hasOrchestrator = !1, this.currentContextId = this.baseBooth.id, this.onMultiBoothModeDisabled?.());
367
+ }
368
+ /**
369
+ * Sets callback functions for when multi-booth mode is enabled/disabled.
370
+ * Used to coordinate external actions like tool registration/unregistration.
371
+ *
372
+ * @param onEnabled - Callback for when multi-booth mode is enabled
373
+ * @param onDisabled - Callback for when multi-booth mode is disabled
374
+ */
375
+ setMultiBoothModeCallbacks(t, o) {
376
+ this.onMultiBoothModeEnabled = t, this.onMultiBoothModeDisabled = o;
377
+ }
307
378
  get isMultiBoothMode() {
308
- return Object.keys(this.booths).length > 1;
379
+ return Object.keys(this.booths).filter(
380
+ (o) => o !== u.id
381
+ ).length > 1;
309
382
  }
310
383
  /**
311
384
  * Removes a booth configuration from the registry by its ID.
@@ -316,10 +389,16 @@ class v {
316
389
  unregisterBooth(t) {
317
390
  if (!this.booths[t])
318
391
  throw new Error(`Booth with ID ${t} does not exist.`);
319
- delete this.booths[t];
392
+ if (t === u.id)
393
+ throw new Error(
394
+ "Cannot unregister orchestrator booth directly. It will be automatically managed based on booth count."
395
+ );
396
+ delete this.booths[t], Object.keys(this.booths).filter(
397
+ (e) => e !== u.id
398
+ ).length <= 1 && this.hasOrchestrator && this.disableMultiBoothMode();
320
399
  }
321
400
  }
322
- class E {
401
+ class B {
323
402
  /**
324
403
  * Creates an instance of InteractionProcessor.
325
404
  * @param boothRegistry - The registry for booth configurations.
@@ -328,9 +407,9 @@ class E {
328
407
  * @param llmAdapter - The adapter for interacting with the LLM.
329
408
  */
330
409
  constructor(t, o, e, r) {
331
- n(this, "loopLimit", 10);
332
410
  this.boothRegistry = t, this.boothPlugins = o, this.toolRegistry = e, this.llmAdapter = r;
333
411
  }
412
+ loopLimit = 10;
334
413
  /**
335
414
  * Creates a synthetic error response with proper structure and error details.
336
415
  * @param error - The error that occurred
@@ -473,13 +552,13 @@ class E {
473
552
  ), r;
474
553
  }
475
554
  }
476
- const C = {
555
+ const T = {
477
556
  id: "summarizer",
478
557
  role: 'You are a highly skilled summarization AI. Your task is to read a conversation history and provide a concise, neutral, and objective summary. The summary should capture the key points, decisions made, and any unresolved questions. It must be written from a third-person perspective and should be clear enough for another AI assistant to understand the full context and continue the conversation seamlessly without needing the original transcript. Do not add any conversational fluff or introductory phrases like "Here is the summary:".',
479
558
  description: "A specialized booth for summarizing conversation histories."
480
- }, p = "route_to_booth";
481
- function w(i) {
482
- const t = i.getAllBooths(), o = Object.values(t).map(
559
+ }, f = "route_to_booth";
560
+ function y(n) {
561
+ const t = n.getAllBooths(), o = Object.values(t).map(
483
562
  (r) => `- ${r.id}: ${r.role}
484
563
  Examples:
485
564
  ${(r.examples || []).map((s) => ` - "${s}"`).join(`
@@ -488,7 +567,7 @@ ${(r.examples || []).map((s) => ` - "${s}"`).join(`
488
567
  `), e = Object.keys(t);
489
568
  return {
490
569
  type: "function",
491
- name: p,
570
+ name: f,
492
571
  description: `
493
572
  Routes the conversation to a specialized booth based on the user's needs. Each booth has a
494
573
  specific role and set of capabilities.
@@ -518,7 +597,7 @@ ${o}
518
597
  */
519
598
  execute: async function({ targetBooth: r }) {
520
599
  try {
521
- return i.setCurrentContextId(r), {
600
+ return n.setCurrentContextId(r), {
522
601
  content: `Routed to booth ${r}`
523
602
  };
524
603
  } catch (s) {
@@ -529,36 +608,27 @@ ${o}
529
608
  }
530
609
  };
531
610
  }
532
- class I {
611
+ class v {
533
612
  /**
534
- * Constructs a new instance with the provided session history.
535
- *
536
- * @param {ResponseInput} [sessionHistory=[]] - An optional array representing the session history. Defaults to an empty array if not provided.
537
- * @return {void}
613
+ * The sessionHistory variable stores the conversation history between the user and the booth system.
614
+ * It is initialized as an empty array and will be populated with messages exchanged during the interaction.
538
615
  */
539
- constructor(t = []) {
540
- /**
541
- * The sessionHistory variable stores the conversation history between the user and the booth system.
542
- * It is initialized as an empty array and will be populated with messages exchanged during the interaction.
543
- */
544
- n(this, "sessionHistory", []);
545
- /**
546
- * Unique identifier for this plugin instance.
547
- * @private
548
- */
549
- n(this, "plugin_id", "conversation-history");
550
- /**
551
- * Display name for this plugin.
552
- * @private
553
- */
554
- n(this, "plugin_name", "Conversation History Plugin");
555
- /**
556
- * Brief description of the plugin's purpose and functionality.
557
- * @private
558
- */
559
- n(this, "plugin_description", "A plugin to manage conversation history in booths.");
560
- this.sessionHistory = t;
561
- }
616
+ sessionHistory = [];
617
+ /**
618
+ * Unique identifier for this plugin instance.
619
+ * @private
620
+ */
621
+ plugin_id = "conversation-history";
622
+ /**
623
+ * Display name for this plugin.
624
+ * @private
625
+ */
626
+ plugin_name = "Conversation History Plugin";
627
+ /**
628
+ * Brief description of the plugin's purpose and functionality.
629
+ * @private
630
+ */
631
+ plugin_description = "A plugin to manage conversation history in booths.";
562
632
  /**
563
633
  * Checks if the given response contains a booth change.
564
634
  *
@@ -569,10 +639,26 @@ class I {
569
639
  * @return A boolean indicating whether a booth change is present in the response.
570
640
  */
571
641
  responseContainsBoothChange(t) {
572
- return t.output ? t.output.some((o) => o.type === "function_call" ? o.name === p : o.type === "message" && "tool_calls" in o && Array.isArray(o.tool_calls) ? o.tool_calls.some(
573
- (e) => e.type === "function" && e.function.name === p
642
+ return t.output ? t.output.some((o) => o.type === "function_call" ? o.name === f : o.type === "message" && "tool_calls" in o && Array.isArray(o.tool_calls) ? o.tool_calls.some(
643
+ (e) => e.type === "function" && e.function.name === f
574
644
  ) : !1) : !1;
575
645
  }
646
+ /**
647
+ * Constructs a new instance with an optional session history.
648
+ *
649
+ * @param {ResponseInput[]} [sessionHistory=[]] - An array representing the session history. Defaults to an empty array if not provided.
650
+ */
651
+ constructor(t = []) {
652
+ this.sessionHistory = t;
653
+ }
654
+ /**
655
+ * Retrieves the session history.
656
+ *
657
+ * @return {Array} The history of the current session.
658
+ */
659
+ get history() {
660
+ return this.sessionHistory;
661
+ }
576
662
  /**
577
663
  * Returns the plugin's unique identifier.
578
664
  */
@@ -616,17 +702,15 @@ class I {
616
702
  * @returns Unmodified response parameters
617
703
  */
618
704
  async onResponseReceived(t, o, e) {
619
- let s = [...o.input, ...(e == null ? void 0 : e.output) ?? []];
705
+ let s = [...o.input, ...e?.output ?? []];
620
706
  if (this.responseContainsBoothChange(e)) {
621
- const l = `Please summarize the following conversation history:
707
+ const i = `Please summarize the following conversation history:
622
708
 
623
- ${JSON.stringify(this.sessionHistory)}`, c = (await L(t.llmAdapter, C).callProcessor.send(l)).output_text, f = s.filter((h) => "role" in h && h.role === "user").pop(), m = {
709
+ ${JSON.stringify(this.sessionHistory)}`, d = (await A(t.llmAdapter, T).callProcessor.send(i)).output_text, g = s.filter((h) => "role" in h && h.role === "user").pop(), b = {
624
710
  role: "developer",
625
- content: `A conversation summary up to this point: ${c}`
626
- }, b = s.filter(
627
- (h) => "type" in h && h.type === "function_call" || h.type === "function_call_output"
628
- );
629
- this.sessionHistory = f ? [...b, m, f] : [...b, m], s = this.sessionHistory;
711
+ content: `A conversation summary up to this point: ${d}`
712
+ }, _ = s.filter((h) => !("role" in h && h.role === "user" || "type" in h && h.type === "message"));
713
+ this.sessionHistory = g ? [..._, b, g] : [..._, b], s = this.sessionHistory;
630
714
  } else
631
715
  this.sessionHistory = s;
632
716
  return {
@@ -644,24 +728,22 @@ ${JSON.stringify(this.sessionHistory)}`, c = (await L(t.llmAdapter, C).callProce
644
728
  return !1;
645
729
  }
646
730
  }
647
- class A {
648
- constructor() {
649
- /**
650
- * Unique identifier for this plugin instance.
651
- * @private
652
- */
653
- n(this, "plugin_id", "context-provider");
654
- /**
655
- * Display the name for this plugin.
656
- * @private
657
- */
658
- n(this, "plugin_name", "Context Provider Plugin");
659
- /**
660
- * Brief description of the plugin's purpose and functionality.
661
- * @private
662
- */
663
- n(this, "plugin_description", "A plugin to provide context to booths.");
664
- }
731
+ class E {
732
+ /**
733
+ * Unique identifier for this plugin instance.
734
+ * @private
735
+ */
736
+ plugin_id = "context-provider";
737
+ /**
738
+ * Display the name for this plugin.
739
+ * @private
740
+ */
741
+ plugin_name = "Context Provider Plugin";
742
+ /**
743
+ * Brief description of the plugin's purpose and functionality.
744
+ * @private
745
+ */
746
+ plugin_description = "A plugin to provide context to booths.";
665
747
  /**
666
748
  * Returns the plugin's unique identifier.
667
749
  */
@@ -692,12 +774,12 @@ class A {
692
774
  const e = t.boothRegistry;
693
775
  let s = e.baseBoothConfig.description;
694
776
  if (e.isMultiBoothMode) {
695
- const a = e.orchestratorBoothConfig, l = e.currentContextBoothConfig;
777
+ const l = e.orchestratorBoothConfig, i = e.currentContextBoothConfig;
696
778
  s += `
697
779
 
698
- ${a.description}`, l.id !== a.id && (s += `
780
+ ${l.description}`, i.id !== l.id && (s += `
699
781
 
700
- ${l.description}`);
782
+ ${i.description}`);
701
783
  }
702
784
  return { ...o, instructions: s };
703
785
  }
@@ -711,12 +793,12 @@ class A {
711
793
  return !1;
712
794
  }
713
795
  }
714
- class _ {
796
+ class w {
797
+ tools;
715
798
  /**
716
799
  * Initializes an empty Map to store tools.
717
800
  */
718
801
  constructor() {
719
- n(this, "tools");
720
802
  this.tools = /* @__PURE__ */ new Map();
721
803
  }
722
804
  registerTools(t) {
@@ -791,12 +873,41 @@ class _ {
791
873
  this.tools.delete(t);
792
874
  }
793
875
  }
794
- class x {
795
- constructor() {
796
- n(this, "description", "A plugin to aggregate and provide tools from base and context booths.");
797
- n(this, "id", "tool-provider");
798
- n(this, "name", "Tool Provider Plugin");
876
+ function C(n) {
877
+ switch (n.type) {
878
+ case "function":
879
+ return `function:${n.name}`;
880
+ case "mcp":
881
+ return `mcp:${n.server_label}`;
882
+ case "file_search":
883
+ return `file_search:${n.vector_store_ids.join(",")}`;
884
+ case "web_search_preview":
885
+ case "web_search_preview_2025_03_11":
886
+ return `web_search:${n.type}`;
887
+ case "computer_use_preview":
888
+ return `computer:${n.environment}:${n.display_width}x${n.display_height}`;
889
+ case "code_interpreter":
890
+ return `code_interpreter:${typeof n.container == "string" ? n.container : "auto"}`;
891
+ case "image_generation":
892
+ return `image_generation:${n.model || "gpt-image-1"}`;
893
+ case "local_shell":
894
+ return "local_shell";
895
+ default:
896
+ return `${n.type}:${JSON.stringify(n)}`;
897
+ }
898
+ }
899
+ function I(n) {
900
+ const t = /* @__PURE__ */ new Set(), o = [];
901
+ for (const e of n) {
902
+ const r = C(e);
903
+ t.has(r) || (t.add(r), o.push(e));
799
904
  }
905
+ return o;
906
+ }
907
+ class x {
908
+ description = "A plugin to aggregate and provide tools from base and context booths.";
909
+ id = "tool-provider";
910
+ name = "Tool Provider Plugin";
800
911
  /**
801
912
  * Before a message is sent, this hook gathers the tool keys from both the base and context booths,
802
913
  * retrieves the corresponding tool definitions from the `toolRegistry`, and adds them to the
@@ -806,16 +917,18 @@ class x {
806
917
  * @returns The updated response parameters with the aggregated list of tools.
807
918
  */
808
919
  async onBeforeMessageSend(t, o) {
809
- const e = t.boothRegistry.baseBoothConfig, r = t.boothRegistry.currentContextBoothConfig, l = [...e.tools || [], ...(r == null ? void 0 : r.tools) || []].filter((u, g, c) => c.indexOf(u) === g).map(
810
- (u) => t.toolRegistry.getTool(u)
920
+ const e = t.boothRegistry.baseBoothConfig, r = t.boothRegistry.currentContextBoothConfig, i = [...e.tools || [], ...r?.tools || []].filter((a, d, g) => g.indexOf(a) === d).map(
921
+ (a) => t.toolRegistry.getTool(a)
811
922
  );
812
- if (e.mcp && l.push(...e.mcp), r != null && r.mcp && l.push(...r.mcp), t.boothRegistry.isMultiBoothMode) {
813
- const u = w(t.boothRegistry);
814
- l.push(u);
923
+ if (e.mcp && i.push(...e.mcp), r?.mcp && i.push(...r.mcp), t.boothRegistry.isMultiBoothMode) {
924
+ const a = y(t.boothRegistry);
925
+ i.push(a);
815
926
  }
816
- return l.push(...t.toolRegistry.getGlobalTools()), {
927
+ i.push(...t.toolRegistry.getGlobalTools());
928
+ const c = I(i);
929
+ return {
817
930
  ...o,
818
- tools: l
931
+ tools: c
819
932
  };
820
933
  }
821
934
  /**
@@ -827,12 +940,10 @@ class x {
827
940
  return !1;
828
941
  }
829
942
  }
830
- class y {
831
- constructor() {
832
- n(this, "id", "tool-executor");
833
- n(this, "name", "Tool Executor");
834
- n(this, "description", "Checks for tool calls in the response, executes them, and adds the results to the message history.");
835
- }
943
+ class m {
944
+ id = "tool-executor";
945
+ name = "Tool Executor";
946
+ description = "Checks for tool calls in the response, executes them, and adds the results to the message history.";
836
947
  /**
837
948
  * Executes a single tool call with proper hook integration.
838
949
  * @param utilities - Repository utilities for accessing registries.
@@ -860,16 +971,16 @@ class y {
860
971
  call_id: r.call_id,
861
972
  output: `Error: Tool '${r.name}' does not have an 'execute' method.`
862
973
  };
863
- const a = await s.execute(JSON.parse(r.arguments)), l = await t.pluginRegistry.runAfterToolCall(
974
+ const l = await s.execute(JSON.parse(r.arguments)), i = await t.pluginRegistry.runAfterToolCall(
864
975
  t,
865
976
  r,
866
- a,
977
+ l,
867
978
  e
868
979
  );
869
980
  return {
870
981
  type: "function_call_output",
871
982
  call_id: r.call_id,
872
- output: JSON.stringify(l)
983
+ output: JSON.stringify(i)
873
984
  };
874
985
  } catch (r) {
875
986
  console.error(`Error executing tool ${o.name}:`, r);
@@ -901,25 +1012,25 @@ class y {
901
1012
  * @returns The updated response parameters, potentially with tool call outputs added to the input.
902
1013
  */
903
1014
  async onResponseReceived(t, o, e) {
904
- const r = (e == null ? void 0 : e.output) ?? [], s = y.extractFunctionCalls(r);
1015
+ const r = e?.output ?? [], s = m.extractFunctionCalls(r);
905
1016
  if (!s.length)
906
1017
  return o;
907
- const a = [];
908
- for (let l = 0; l < s.length; l++) {
909
- const u = s[l];
910
- if (t.toolRegistry.isLocalTool(u.name))
1018
+ const l = [];
1019
+ for (let i = 0; i < s.length; i++) {
1020
+ const c = s[i];
1021
+ if (t.toolRegistry.isLocalTool(c.name))
911
1022
  continue;
912
- const g = {
1023
+ const a = {
913
1024
  responseParams: o,
914
1025
  response: e,
915
- toolCallIndex: l,
1026
+ toolCallIndex: i,
916
1027
  totalToolCalls: s.length
917
- }, c = await this.executeToolCall(t, u, g);
918
- a.push(c);
1028
+ }, d = await this.executeToolCall(t, c, a);
1029
+ l.push(d);
919
1030
  }
920
1031
  return {
921
1032
  ...o,
922
- input: [...o.input, ...a]
1033
+ input: [...o.input, ...l]
923
1034
  };
924
1035
  }
925
1036
  /**
@@ -931,12 +1042,10 @@ class y {
931
1042
  return !1;
932
1043
  }
933
1044
  }
934
- class P {
935
- constructor() {
936
- n(this, "description", "A plugin to ensure the interaction loop can be finished.");
937
- n(this, "id", "finish-turn-plugin");
938
- n(this, "name", "Finish Turn Plugin");
939
- }
1045
+ class M {
1046
+ description = "A plugin to ensure the interaction loop can be finished.";
1047
+ id = "finish-turn-plugin";
1048
+ name = "Finish Turn Plugin";
940
1049
  /**
941
1050
  * Before sending a message, this hook adds an instruction to the LLM to include a
942
1051
  * specific marker (`__awaiting_user_response__`) when it expects a user response.
@@ -990,51 +1099,60 @@ class P {
990
1099
  return o;
991
1100
  }
992
1101
  }
993
- const R = {
994
- id: "orchestrator",
995
- role: `
996
- This booth serves as the orchestration layer that analyzes user intent and routes
997
- conversations to the most appropriate specialized booth configuration.
998
- `,
999
- description: `
1000
- You are the orchestration layer responsible for determining which booth configuration
1001
- should be active based on user needs. Focus exclusively on routing - do not answer
1002
- questions or provide information directly to users.
1003
-
1004
- [ROUTING STRATEGY]
1005
- - Analyze user request and route to the most appropriate specialized booth immediately
1006
- - This booth is only active for initial routing or when explicitly routed back to
1007
- - Once routed, the target booth handles the conversation until completion or re-routing
1008
-
1009
- [ROUTING TARGETS]
1010
- - Ambiguous requests → Ask for clarification, then route appropriately
1011
-
1012
- [CORE PRINCIPLES]
1013
- - Maintain illusion of single, continuous assistant
1014
- - Never reference booths, tools, or system mechanics to users
1015
- - Silent routing is preferred when intent is clear
1016
- - Only speak to users when clarification is absolutely necessary
1017
-
1018
- [ROUTING BEHAVIOR]
1019
- - Clear intent: Route silently using route_to_booth() - do NOT respond to user
1020
- - Ambiguous intent: Ask user for clarification, then route once clarified
1021
- - Never respond to user AND route - it's either respond OR route, not both
1022
-
1023
- [BEHAVIOR EXAMPLES]
1024
- - User: "How do I test my number?" → route_to_booth({ targetBooth: 'page-router-booth' })
1025
- - User: "I need help" → "What specifically would you like help with?" → then route based on response
1026
- `
1027
- };
1028
- function L(i, t) {
1029
- const o = new v(t), e = new _(), r = new d();
1030
- return new S({
1031
- llmAdapter: i,
1102
+ function A(n, t) {
1103
+ const o = new R(t), e = new w(), r = new p();
1104
+ return new P({
1105
+ llmAdapter: n,
1032
1106
  booths: o,
1033
1107
  tools: e,
1034
1108
  boothPlugins: r
1035
1109
  });
1036
1110
  }
1037
- class S {
1111
+ class P {
1112
+ /**
1113
+ * Represents a registry that maintains a collection of plugins for a booth system.
1114
+ * The boothPluginRegistry is used to manage and access plugins that enhance
1115
+ * or extend the booth's behavior or features.
1116
+ *
1117
+ * This variable is intended to provide a central location for plugin registration,
1118
+ * retrieval, and management.
1119
+ *
1120
+ * @type {BoothPluginRegistry}
1121
+ */
1122
+ boothPluginRegistry;
1123
+ /**
1124
+ * Registry for managing booth configurations across the system.
1125
+ * This registry maintains a collection of booth definitions that can be
1126
+ * accessed by their unique identifiers.
1127
+ *
1128
+ * @type {BoothRegistry}
1129
+ */
1130
+ boothRegistry;
1131
+ /**
1132
+ * Primary processor for handling interactions between users and the booth system.
1133
+ * Responsible for sending messages to the LLM, processing responses, and managing
1134
+ * the interaction loop through plugins.
1135
+ *
1136
+ * @type {InteractionProcessor}
1137
+ */
1138
+ callProcessor;
1139
+ /**
1140
+ * Registry dedicated to system-level plugins that are always available.
1141
+ * This includes core functionality plugins like conversation history and context providers,
1142
+ * as well as any user-defined plugins from the boothPluginRegistry.
1143
+ *
1144
+ * @type {BoothPluginRegistry}
1145
+ */
1146
+ systemPluginsRegistry;
1147
+ /**
1148
+ * A variable that represents a registry for managing and maintaining a collection of tools.
1149
+ * `toolRegistry` is an instance of the `ToolRegistry` class, which provides functionalities
1150
+ * for adding, removing, and retrieving tools.
1151
+ *
1152
+ * The `ToolRegistry` class typically serves as a centralized storage or management
1153
+ * solution for tools that are used in a specific context or application.
1154
+ */
1155
+ toolRegistry;
1038
1156
  /**
1039
1157
  * Initializes a new instance of the CoreBooth class.
1040
1158
  * Sets up the plugin registries, system plugins, and interaction processor.
@@ -1045,62 +1163,24 @@ class S {
1045
1163
  * @param {ToolRegistry} options.tools - Registry containing tool configurations
1046
1164
  */
1047
1165
  constructor(t) {
1048
- /**
1049
- * Represents a registry that maintains a collection of plugins for a booth system.
1050
- * The boothPluginRegistry is used to manage and access plugins that enhance
1051
- * or extend the booth's behavior or features.
1052
- *
1053
- * This variable is intended to provide a central location for plugin registration,
1054
- * retrieval, and management.
1055
- *
1056
- * @type {BoothPluginRegistry}
1057
- */
1058
- n(this, "boothPluginRegistry");
1059
- /**
1060
- * Registry for managing booth configurations across the system.
1061
- * This registry maintains a collection of booth definitions that can be
1062
- * accessed by their unique identifiers.
1063
- *
1064
- * @type {BoothRegistry}
1065
- */
1066
- n(this, "boothRegistry");
1067
- /**
1068
- * Primary processor for handling interactions between users and the booth system.
1069
- * Responsible for sending messages to the LLM, processing responses, and managing
1070
- * the interaction loop through plugins.
1071
- *
1072
- * @type {InteractionProcessor}
1073
- */
1074
- n(this, "callProcessor");
1075
- /**
1076
- * Registry dedicated to system-level plugins that are always available.
1077
- * This includes core functionality plugins like conversation history and context providers,
1078
- * as well as any user-defined plugins from the boothPluginRegistry.
1079
- *
1080
- * @type {BoothPluginRegistry}
1081
- */
1082
- n(this, "systemPluginsRegistry");
1083
- /**
1084
- * A variable that represents a registry for managing and maintaining a collection of tools.
1085
- * `toolRegistry` is an instance of the `ToolRegistry` class, which provides functionalities
1086
- * for adding, removing, and retrieving tools.
1087
- *
1088
- * The `ToolRegistry` class typically serves as a centralized storage or management
1089
- * solution for tools that are used in a specific context or application.
1090
- */
1091
- n(this, "toolRegistry");
1092
- if (this.boothPluginRegistry = (t == null ? void 0 : t.boothPlugins) ?? new d(), this.boothRegistry = t.booths, this.toolRegistry = (t == null ? void 0 : t.tools) ?? new _(), this.boothRegistry.isMultiBoothMode) {
1093
- this.boothRegistry.registerBooth(R), this.boothRegistry.setCurrentContextId(R.id);
1094
- const o = w(this.boothRegistry);
1166
+ if (this.boothPluginRegistry = t?.boothPlugins ?? new p(), this.boothRegistry = t.booths, this.toolRegistry = t?.tools ?? new w(), this.boothRegistry.setMultiBoothModeCallbacks(
1167
+ () => {
1168
+ const o = y(this.boothRegistry);
1169
+ this.toolRegistry.registerTools([o]);
1170
+ },
1171
+ () => {
1172
+ }
1173
+ ), this.boothRegistry.isMultiBoothMode) {
1174
+ const o = y(this.boothRegistry);
1095
1175
  this.toolRegistry.registerTools([o]);
1096
1176
  }
1097
- this.systemPluginsRegistry = new d(), this.systemPluginsRegistry.registerPlugins([
1098
- new I(t.sessionHistory),
1099
- new A(),
1177
+ this.systemPluginsRegistry = new p(), this.systemPluginsRegistry.registerPlugins([
1178
+ new v(t.sessionHistory),
1179
+ new E(),
1100
1180
  new x(),
1101
- new y(),
1102
- new P()
1103
- ]), this.systemPluginsRegistry.registerPlugins(this.boothPluginRegistry.getPlugins()), this.callProcessor = new E(
1181
+ new m(),
1182
+ new M()
1183
+ ]), this.systemPluginsRegistry.registerPlugins(this.boothPluginRegistry.getPlugins()), this.callProcessor = new B(
1104
1184
  this.boothRegistry,
1105
1185
  this.systemPluginsRegistry,
1106
1186
  this.toolRegistry,
@@ -1109,16 +1189,16 @@ class S {
1109
1189
  }
1110
1190
  }
1111
1191
  export {
1112
- d as BoothPluginRegistry,
1113
- v as BoothRegistry,
1114
- A as ContextProviderPlugin,
1115
- I as ConversationHistoryPlugin,
1116
- S as CoreBooth,
1117
- P as FinishTurnPlugin,
1118
- E as InteractionProcessor,
1119
- y as ToolExecutorPlugin,
1192
+ p as BoothPluginRegistry,
1193
+ R as BoothRegistry,
1194
+ E as ContextProviderPlugin,
1195
+ v as ConversationHistoryPlugin,
1196
+ P as CoreBooth,
1197
+ M as FinishTurnPlugin,
1198
+ B as InteractionProcessor,
1199
+ m as ToolExecutorPlugin,
1120
1200
  x as ToolProviderPlugin,
1121
- _ as ToolRegistry,
1122
- L as createCoreBooth,
1123
- w as createRouteToBoothTool
1201
+ w as ToolRegistry,
1202
+ A as createCoreBooth,
1203
+ y as createRouteToBoothTool
1124
1204
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "booths",
3
3
  "private": false,
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -16,6 +16,7 @@
16
16
  }
17
17
  },
18
18
  "scripts": {
19
+ "build-pack": "npm install --package-lock-only && npm run build && npm pack",
19
20
  "build": "tsc && vite build",
20
21
  "format": "prettier --write \"src/**/*.{js,ts,json,css,scss,md}\"",
21
22
  "typecheck": "tsc --noEmit"