agent-swarm-kit 1.1.4 → 1.1.6

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/build/index.cjs CHANGED
@@ -4840,7 +4840,7 @@ class AgentConnectionService {
4840
4840
  }
4841
4841
 
4842
4842
  /** @private Constant defining the method name for logging purposes */
4843
- const METHOD_NAME$19 = "function.common.getPayload";
4843
+ const METHOD_NAME$1b = "function.common.getPayload";
4844
4844
  /**
4845
4845
  * Retrieves the payload from the current PayloadContextService context.
4846
4846
  * Returns null if no context is available. Logs the operation if logging is enabled.
@@ -4851,7 +4851,7 @@ const METHOD_NAME$19 = "function.common.getPayload";
4851
4851
  * console.log(payload); // { id: number } or null
4852
4852
  */
4853
4853
  const getPayload = () => {
4854
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$19);
4854
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1b);
4855
4855
  if (PayloadContextService.hasContext()) {
4856
4856
  const { payload } = swarm$1.payloadContextService.context;
4857
4857
  return payload;
@@ -14523,7 +14523,7 @@ const swarm = {
14523
14523
  init();
14524
14524
  var swarm$1 = swarm;
14525
14525
 
14526
- const METHOD_NAME$18 = "cli.dumpDocs";
14526
+ const METHOD_NAME$1a = "cli.dumpDocs";
14527
14527
  /**
14528
14528
  * Dumps the documentation for the agents and swarms.
14529
14529
  *
@@ -14533,7 +14533,7 @@ const METHOD_NAME$18 = "cli.dumpDocs";
14533
14533
  */
14534
14534
  const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantUML) => {
14535
14535
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14536
- swarm$1.loggerService.log(METHOD_NAME$18, {
14536
+ swarm$1.loggerService.log(METHOD_NAME$1a, {
14537
14537
  dirName,
14538
14538
  });
14539
14539
  if (PlantUML) {
@@ -14543,10 +14543,10 @@ const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantU
14543
14543
  }
14544
14544
  swarm$1.agentValidationService
14545
14545
  .getAgentList()
14546
- .forEach((agentName) => swarm$1.agentValidationService.validate(agentName, METHOD_NAME$18));
14546
+ .forEach((agentName) => swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1a));
14547
14547
  swarm$1.swarmValidationService
14548
14548
  .getSwarmList()
14549
- .forEach((swarmName) => swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$18));
14549
+ .forEach((swarmName) => swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1a));
14550
14550
  swarm$1.agentValidationService.getAgentList().forEach((agentName) => {
14551
14551
  const { dependsOn } = swarm$1.agentSchemaService.get(agentName);
14552
14552
  if (!dependsOn) {
@@ -14556,7 +14556,7 @@ const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantU
14556
14556
  return swarm$1.docService.dumpDocs(prefix, dirName);
14557
14557
  });
14558
14558
 
14559
- const METHOD_NAME$17 = "cli.dumpAgent";
14559
+ const METHOD_NAME$19 = "cli.dumpAgent";
14560
14560
  /**
14561
14561
  * Dumps the agent information into PlantUML format.
14562
14562
  *
@@ -14565,14 +14565,14 @@ const METHOD_NAME$17 = "cli.dumpAgent";
14565
14565
  */
14566
14566
  const dumpAgent = beginContext((agentName, { withSubtree = false } = {}) => {
14567
14567
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14568
- swarm$1.loggerService.log(METHOD_NAME$17, {
14568
+ swarm$1.loggerService.log(METHOD_NAME$19, {
14569
14569
  agentName,
14570
14570
  });
14571
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$17);
14571
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$19);
14572
14572
  return swarm$1.agentMetaService.toUML(agentName, withSubtree);
14573
14573
  });
14574
14574
 
14575
- const METHOD_NAME$16 = "cli.dumpSwarm";
14575
+ const METHOD_NAME$18 = "cli.dumpSwarm";
14576
14576
  /**
14577
14577
  * Dumps the swarm information into PlantUML format.
14578
14578
  *
@@ -14581,14 +14581,14 @@ const METHOD_NAME$16 = "cli.dumpSwarm";
14581
14581
  */
14582
14582
  const dumpSwarm = beginContext((swarmName) => {
14583
14583
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14584
- swarm$1.loggerService.log(METHOD_NAME$16, {
14584
+ swarm$1.loggerService.log(METHOD_NAME$18, {
14585
14585
  swarmName,
14586
14586
  });
14587
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$16);
14587
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$18);
14588
14588
  return swarm$1.swarmMetaService.toUML(swarmName);
14589
14589
  });
14590
14590
 
14591
- const METHOD_NAME$15 = "cli.dumpPerfomance";
14591
+ const METHOD_NAME$17 = "cli.dumpPerfomance";
14592
14592
  const METHOD_NAME_INTERNAL$1 = "cli.dumpPerfomance.internal";
14593
14593
  const METHOD_NAME_INTERVAL = "cli.dumpPerfomance.interval";
14594
14594
  /**
@@ -14607,7 +14607,7 @@ const dumpPerfomanceInternal = beginContext(async (dirName = "./logs/meta") => {
14607
14607
  * @returns {Promise<void>} A promise that resolves when the performance data has been dumped.
14608
14608
  */
14609
14609
  const dumpPerfomance = async (dirName = "./logs/meta") => {
14610
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$15);
14610
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$17);
14611
14611
  await dumpPerfomanceInternal(dirName);
14612
14612
  };
14613
14613
  /**
@@ -14622,95 +14622,699 @@ dumpPerfomance.runInterval = beginContext((dirName = "./logs/meta", interval = 3
14622
14622
  swarm$1.loggerService.log(METHOD_NAME_INTERVAL);
14623
14623
  return functoolsKit.Source.fromInterval(interval).connect(() => dumpPerfomance(dirName));
14624
14624
  });
14625
-
14625
+
14626
+ /**
14627
+ * Validates the client ID for execution event listening, allowing wildcard "*" or checking for an active session.
14628
+ *
14629
+ * @param {string} clientId - The client ID to validate.
14630
+ * @throws {Error} If the client ID is not "*" and no active session exists for it.
14631
+ */
14632
+ const validateClientId$h = (clientId) => {
14633
+ if (clientId === "*") {
14634
+ return;
14635
+ }
14636
+ if (!swarm$1.sessionValidationService.hasSession(clientId)) {
14637
+ throw new Error(`agent-swarm listenExecutionEvent session not found for clientId=${clientId}`);
14638
+ }
14639
+ };
14640
+ /**
14641
+ * Subscribes to execution-specific events on the swarm bus service for a specific client and executes a callback for each event.
14642
+ *
14643
+ * This function sets up a listener for events on the "execution-bus" topic associated with a given client ID, invoking the provided callback with
14644
+ * the event data whenever an execution event is received. It is wrapped in `beginContext` for a clean execution environment and logs the operation
14645
+ * via `loggerService`. The callback is queued using `functools-kit` to ensure sequential processing of events. The function supports a wildcard
14646
+ * client ID ("*") for listening to all clients or validates a specific client session. It returns an unsubscribe function to stop listening.
14647
+ *
14648
+ * @param {string} clientId - The ID of the client to subscribe to execution events for, or "*" to listen to all clients.
14649
+ * @param {(event: IBusEvent) => void} fn - The callback function to execute when an execution event is received, passed the event object.
14650
+ * @returns {() => void} A function to unsubscribe from the execution event listener.
14651
+ * @throws {Error} If the `clientId` is not "*" and no active session exists for it.
14652
+ * @example
14653
+ * const unsubscribe = listenExecutionEvent("client-123", (event) => console.log(event));
14654
+ * // Logs each execution event for "client-123"
14655
+ * unsubscribe(); // Stops listening
14656
+ */
14657
+ const listenExecutionEvent = beginContext((clientId, fn) => {
14658
+ // Log the operation details
14659
+ swarm$1.loggerService.log("middleware listenExecutionEvent", {
14660
+ clientId,
14661
+ });
14662
+ // Validate the client ID
14663
+ validateClientId$h(clientId);
14664
+ // Subscribe to execution events with a queued callback
14665
+ return swarm$1.busService.subscribe(clientId, "execution-bus", functoolsKit.queued(async (e) => await fn(e)));
14666
+ });
14667
+
14668
+ const METHOD_NAME$16 = "cli.dumpClientPerformance";
14669
+ const METHOD_NAME_INTERNAL = "cli.dumpClientPerformance.internal";
14670
+ const METHOD_NAME_EXECUTE = "cli.dumpClientPerformance.execute";
14671
+ /**
14672
+ * The internal HOF for handling the performance dump
14673
+ *
14674
+ * @param {string} clientId - The client ID for which the performance data is being dumped.
14675
+ * @param {string} [dirName="./logs/client"] - The directory name where the performance data will be dumped.
14676
+ * @returns {Promise<void>} A promise that resolves when the performance data has been dumped.
14677
+ */
14678
+ const dumpClientPerformanceInternal = beginContext(async (clientId, dirName = "./logs/client") => {
14679
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14680
+ swarm$1.loggerService.log(METHOD_NAME_INTERNAL);
14681
+ return await swarm$1.docService.dumpClientPerfomance(clientId, dirName);
14682
+ });
14683
+ /**
14684
+ * Dumps the performance data using the swarm's document service.
14685
+ * Logs the method name if logging is enabled in the global configuration.
14686
+ *
14687
+ * @param {string} clientId - The client ID for which the performance data is being dumped.
14688
+ * @param {string} [dirName="./logs/client"] - The directory name where the performance data will be dumped.
14689
+ * @returns {Promise<void>} A promise that resolves when the performance data has been dumped.
14690
+ */
14691
+ const dumpClientPerformance = async (clientId, dirName = "./logs/client") => {
14692
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$16);
14693
+ await dumpClientPerformanceInternal(clientId, dirName);
14694
+ };
14695
+ /**
14696
+ * Sets up a listener to dump performance data after execution.
14697
+ * Logs the method name if logging is enabled in the global configuration.
14698
+ *
14699
+ * @param {string} [dirName="./logs/client"] - The directory name where the performance data will be dumped.
14700
+ * @returns {Promise<void>} A promise that resolves when the listener has been set up.
14701
+ */
14702
+ dumpClientPerformance.runAfterExecute = beginContext(async (dirName = "./logs/client") => {
14703
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14704
+ swarm$1.loggerService.log(METHOD_NAME_EXECUTE);
14705
+ return listenExecutionEvent("*", async ({ type, clientId }) => {
14706
+ if (type === "commit-execution-end") {
14707
+ await dumpClientPerformanceInternal(clientId, dirName);
14708
+ }
14709
+ });
14710
+ });
14711
+
14712
+ /** @private Constant defining the method name for logging and validation context */
14713
+ const METHOD_NAME$15 = "function.commit.commitFlushForce";
14714
+ /**
14715
+ * Forcefully commits a flush of agent history for a specific client in the swarm system, without checking the active agent.
14716
+ * Validates the session and swarm, then proceeds with flushing the history regardless of the current agent state.
14717
+ * Runs within a beginContext wrapper for execution context management, logging operations via LoggerService.
14718
+ * Integrates with SessionValidationService (session and swarm retrieval), SwarmValidationService (swarm validation),
14719
+ * SessionPublicService (history flush), and LoggerService (logging).
14720
+ * Unlike commitFlush, this function skips agent validation and active agent checks, providing a more aggressive flush mechanism,
14721
+ * analogous to commitAssistantMessageForce vs. commitAssistantMessage.
14722
+ *
14723
+ * @param {string} clientId - The ID of the client associated with the session, validated against active sessions.
14724
+ * @param {string} agentName - The name of the agent (unused in this implementation, included for interface consistency with commitFlush).
14725
+ * @returns {Promise<void>} A promise that resolves when the history flush is committed.
14726
+ * @throws {Error} If session or swarm validation fails, propagated from respective validation services.
14727
+ */
14728
+ const commitFlushForce = beginContext(async (clientId) => {
14729
+ // Log the flush attempt if enabled
14730
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14731
+ swarm$1.loggerService.log(METHOD_NAME$15, {
14732
+ clientId,
14733
+ METHOD_NAME: METHOD_NAME$15,
14734
+ });
14735
+ // Validate the session exists and retrieve the associated swarm
14736
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$15);
14737
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
14738
+ // Validate the swarm configuration
14739
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$15);
14740
+ // Commit the flush of agent history via SessionPublicService without agent checks
14741
+ await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$15, clientId, swarmName);
14742
+ });
14743
+
14744
+ const METHOD_NAME$14 = "function.commit.commitToolOutputForce";
14745
+ /**
14746
+ * Commits the output of a tool execution to the active agent in a swarm session without checking the active agent.
14747
+ *
14748
+ * This function forcefully commits the tool output to the session, bypassing the check for whether the agent is still active in the swarm session.
14749
+ * It performs validation on the session and swarm, logs the operation if enabled, and delegates the commit operation to the session public service.
14750
+ * The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts, providing a clean execution environment.
14751
+ *
14752
+ * @param {string} toolId - The unique identifier of the tool whose output is being committed.
14753
+ * @param {string} content - The content or result of the tool execution to be committed.
14754
+ * @param {string} clientId - The unique identifier of the client session associated with the operation.
14755
+ * @returns {Promise<void>} A promise that resolves when the tool output is successfully committed.
14756
+ * @throws {Error} If validation fails (e.g., invalid session or swarm) or if the session public service encounters an error during the commit operation.
14757
+ * @example
14758
+ * await commitToolOutputForce("tool-123", "Tool execution result", "client-456");
14759
+ */
14760
+ const commitToolOutputForce = beginContext(async (toolId, content, clientId) => {
14761
+ // Log the operation details if logging is enabled in GLOBAL_CONFIG
14762
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14763
+ swarm$1.loggerService.log(METHOD_NAME$14, {
14764
+ toolId,
14765
+ content,
14766
+ clientId,
14767
+ });
14768
+ // Validate the session and swarm to ensure they exist and are accessible
14769
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$14);
14770
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
14771
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$14);
14772
+ // Commit the tool output to the session via the session public service without checking the active agent
14773
+ await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$14, clientId, swarmName);
14774
+ });
14775
+
14776
+ /**
14777
+ * @private Constant defining the method name for logging and validation purposes.
14778
+ * Used as an identifier in log messages and validation checks to track calls to `hasNavigation`.
14779
+ */
14780
+ const METHOD_NAME$13 = "function.common.hasNavigation";
14781
+ /**
14782
+ * Checks if a specific agent is part of the navigation route for a given client.
14783
+ * Validates the agent and client session, retrieves the associated swarm, and queries the navigation route.
14784
+ * Logs the operation if enabled by global configuration.
14785
+ * @param {string} clientId - The unique identifier of the client whose navigation route is being checked.
14786
+ * @param {AgentName} agentName - The name of the agent to check within the navigation route.
14787
+ * @returns {Promise<boolean>} A promise resolving to true if the agent is in the navigation route, false otherwise.
14788
+ */
14789
+ const hasNavigation = async (clientId, agentName) => {
14790
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14791
+ swarm$1.loggerService.log(METHOD_NAME$13, { clientId });
14792
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$13);
14793
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$13);
14794
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
14795
+ return swarm$1.navigationValidationService
14796
+ .getNavigationRoute(clientId, swarmName)
14797
+ .has(agentName);
14798
+ };
14799
+
14800
+ const METHOD_NAME$12 = "function.history.getRawHistory";
14801
+ /**
14802
+ * Retrieves the raw, unmodified history for a given client session.
14803
+ *
14804
+ * This function fetches the complete history associated with a client’s active agent in a swarm session, without any filtering or modifications.
14805
+ * It is wrapped in `beginContext` for a clean execution environment and logs the operation if enabled via `GLOBAL_CONFIG`. The function validates
14806
+ * the session and swarm, retrieves the current agent, and uses `historyPublicService.toArrayForRaw` to obtain the raw history as an array.
14807
+ * The result is a fresh copy of the history array.
14808
+ *
14809
+ * @param {string} clientId - The unique identifier of the client session whose raw history is to be retrieved.
14810
+ * @param {string} [methodName="function.history.getRawHistory"] - The name of the calling method, used for validation and logging (defaults to `METHOD_NAME`).
14811
+ * @returns {Promise<object[]>} A promise that resolves to an array containing the raw history entries.
14812
+ * @throws {Error} If session or swarm validation fails, or if history retrieval encounters an issue.
14813
+ * @example
14814
+ * const rawHistory = await getRawHistory("client-123");
14815
+ * console.log(rawHistory); // Outputs the full raw history array
14816
+ */
14817
+ const getRawHistory = beginContext(async (clientId, methodName = METHOD_NAME$12) => {
14818
+ // Log the operation details if logging is enabled in GLOBAL_CONFIG
14819
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14820
+ swarm$1.loggerService.log(METHOD_NAME$12, {
14821
+ clientId,
14822
+ });
14823
+ // Validate the session and swarm
14824
+ swarm$1.sessionValidationService.validate(clientId, methodName);
14825
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
14826
+ swarm$1.swarmValidationService.validate(swarmName, methodName);
14827
+ // Get the current agent and fetch raw history
14828
+ const agentName = await swarm$1.swarmPublicService.getAgentName(methodName, clientId, swarmName);
14829
+ const history = await swarm$1.historyPublicService.toArrayForRaw(methodName, clientId, agentName);
14830
+ return [...history];
14831
+ });
14832
+
14833
+ const METHOD_NAME$11 = "function.history.getLastUserMessage";
14834
+ /**
14835
+ * Retrieves the content of the most recent user message from a client's session history.
14836
+ *
14837
+ * This function fetches the raw history for a specified client using `getRawHistory` and finds the last entry where the role is "user" and the mode
14838
+ * is "user". It is wrapped in `beginContext` for a clean execution environment and logs the operation if enabled via `GLOBAL_CONFIG`. The result is
14839
+ * the content of the last user message as a string, or `null` if no matching user message exists in the history.
14840
+ *
14841
+ * @param {string} clientId - The unique identifier of the client session whose last user message is to be retrieved.
14842
+ * @returns {Promise<string | null>} A promise that resolves to the content of the last user message, or `null` if none is found.
14843
+ * @throws {Error} If `getRawHistory` fails due to session validation or history retrieval issues.
14844
+ * @example
14845
+ * const lastMessage = await getLastUserMessage("client-123");
14846
+ * console.log(lastMessage); // Outputs the last user message or null
14847
+ */
14848
+ const getLastUserMessage = beginContext(async (clientId) => {
14849
+ // Log the operation details if logging is enabled in GLOBAL_CONFIG
14850
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14851
+ swarm$1.loggerService.log(METHOD_NAME$11, {
14852
+ clientId,
14853
+ });
14854
+ // Fetch raw history and find the last user message
14855
+ const history = await getRawHistory(clientId, METHOD_NAME$11);
14856
+ const last = history.findLast(({ role, mode }) => role === "user" && mode === "user");
14857
+ return last ? last.content : null;
14858
+ });
14859
+
14860
+ const METHOD_NAME$10 = "function.navigate.changeToDefaultAgent";
14861
+ /**
14862
+ * Time-to-live for the change agent function in milliseconds.
14863
+ * Defines how long the cached change agent function remains valid before expiring.
14864
+ * @constant {number}
14865
+ */
14866
+ const CHANGE_AGENT_TTL$2 = 15 * 60 * 1000;
14867
+ /**
14868
+ * Garbage collection interval for the change agent function in milliseconds.
14869
+ * Specifies the frequency at which expired TTL entries are cleaned up.
14870
+ * @constant {number}
14871
+ */
14872
+ const CHANGE_AGENT_GC$2 = 60 * 1000;
14873
+ /**
14874
+ * Creates a change agent function with time-to-live (TTL) and queuing capabilities for switching to the default agent.
14875
+ *
14876
+ * This factory function generates a queued, TTL-limited function to handle agent changes to the default agent for a specific client session,
14877
+ * ensuring operations are executed sequentially and cached results are reused within the TTL period.
14878
+ *
14879
+ * @function
14880
+ * @param {string} clientId - The unique identifier of the client session.
14881
+ * @returns {TChangeToDefaultAgentRun} A function that performs the default agent change operation with queuing and TTL.
14882
+ */
14883
+ const createChangeToDefaultAgent = functoolsKit.ttl((clientId) => functoolsKit.queued(async (methodName, agentName, swarmName) => {
14884
+ if (!swarm$1.navigationValidationService.shouldNavigate(agentName, clientId, swarmName)) {
14885
+ return false;
14886
+ }
14887
+ // Notify all agents in the swarm of the change
14888
+ await Promise.all(swarm$1.swarmValidationService
14889
+ .getAgentList(swarmName)
14890
+ .map(async (agentName) => {
14891
+ await swarm$1.agentPublicService.commitAgentChange(methodName, clientId, agentName);
14892
+ }));
14893
+ {
14894
+ // Dispose of the current agent's resources and set up the new default agent
14895
+ const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$10, clientId, swarmName);
14896
+ await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
14897
+ await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
14898
+ await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
14899
+ }
14900
+ // Set the default agent as the active agent
14901
+ await swarm$1.swarmPublicService.setAgentName(agentName, methodName, clientId, swarmName);
14902
+ return true;
14903
+ }), {
14904
+ key: ([clientId]) => `${clientId}`,
14905
+ timeout: CHANGE_AGENT_TTL$2,
14906
+ });
14907
+ /**
14908
+ * Creates a garbage collector for the change agent function.
14909
+ *
14910
+ * This function sets up a singleton interval-based garbage collector to periodically clean up expired TTL entries from `createChangeToDefaultAgent`.
14911
+ *
14912
+ * @function
14913
+ * @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
14914
+ */
14915
+ const createGc$3 = functoolsKit.singleshot(async () => {
14916
+ setInterval(createChangeToDefaultAgent.gc, CHANGE_AGENT_GC$2);
14917
+ });
14918
+ /**
14919
+ * Navigates back to the default agent for a given client session in a swarm.
14920
+ *
14921
+ * This function switches the active agent to the default agent defined in the swarm schema for the specified client session.
14922
+ * It validates the session and default agent, logs the operation if enabled, and executes the change using a TTL-limited, queued runner.
14923
+ * The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts.
14924
+ *
14925
+ * @param {string} clientId - The unique identifier of the client session.
14926
+ * @returns {Promise<boolean>} A promise that resolves when the default agent change is complete. If navigation stack contains recursion being canceled
14927
+ * @throws {Error} If session or agent validation fails, or if the agent change process encounters an error.
14928
+ * @example
14929
+ * await changeToDefaultAgent("client-123");
14930
+ */
14931
+ const changeToDefaultAgent = beginContext(async (clientId) => {
14932
+ // Log the operation details if logging is enabled in GLOBAL_CONFIG
14933
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14934
+ swarm$1.loggerService.log(METHOD_NAME$10, {
14935
+ clientId,
14936
+ });
14937
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
14938
+ const { defaultAgent: agentName } = swarm$1.swarmSchemaService.get(swarmName);
14939
+ {
14940
+ // Validate session and default agent
14941
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$10);
14942
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$10);
14943
+ }
14944
+ // Execute the agent change with TTL and queuing
14945
+ const run = await createChangeToDefaultAgent(clientId);
14946
+ createGc$3();
14947
+ return await run(METHOD_NAME$10, agentName, swarmName);
14948
+ });
14949
+
14950
+ const METHOD_NAME$$ = "function.target.emitForce";
14951
+ /**
14952
+ * Emits a string as model output without executing an incoming message or checking the active agent.
14953
+ *
14954
+ * This function directly emits a provided string as output from the swarm session, bypassing message execution and agent activity checks.
14955
+ * It is designed exclusively for sessions established via `makeConnection`, ensuring compatibility with its connection model.
14956
+ * The execution is wrapped in `beginContext` for a clean environment, validates the session and swarm, and throws an error if the session mode
14957
+ * is not "makeConnection". The operation is logged if enabled, and resolves when the content is successfully emitted.
14958
+ *
14959
+ * @param {string} content - The content to be emitted as the model output.
14960
+ * @param {string} clientId - The unique identifier of the client session emitting the content.
14961
+ * @returns {Promise<void>} A promise that resolves when the content is emitted.
14962
+ * @throws {Error} If the session mode is not "makeConnection", or if session or swarm validation fails.
14963
+ * @example
14964
+ * await emitForce("Direct output", "client-123"); // Emits "Direct output" in a makeConnection session
14965
+ */
14966
+ const emitForce = beginContext(async (content, clientId) => {
14967
+ // Log the operation details if logging is enabled in GLOBAL_CONFIG
14968
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14969
+ swarm$1.loggerService.log(METHOD_NAME$$, {
14970
+ content,
14971
+ clientId,
14972
+ });
14973
+ // Validate the session and swarm
14974
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$$);
14975
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
14976
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$$);
14977
+ // Emit the content directly via the session public service
14978
+ return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$$, clientId, swarmName);
14979
+ });
14980
+
14981
+ const METHOD_NAME$_ = "function.target.executeForce";
14982
+ /**
14983
+ * Sends a message to the active agent in a swarm session as if it originated from the client side, forcing execution regardless of agent activity.
14984
+ *
14985
+ * This function executes a command or message on behalf of the active agent within a swarm session, designed for scenarios like reviewing tool output
14986
+ * or initiating a model-to-client conversation. Unlike `execute`, it does not check if the agent is currently active, ensuring execution even if the
14987
+ * agent has changed or is inactive. It validates the session and swarm, executes the content with performance tracking and event bus notifications,
14988
+ * and is wrapped in `beginContext` for a clean environment and `ExecutionContextService` for metadata tracking.
14989
+ *
14990
+ * @param {string} content - The content or command to be executed by the active agent.
14991
+ * @param {string} clientId - The unique identifier of the client session requesting the execution.
14992
+ * @returns {Promise<string>} A promise that resolves to the result of the execution.
14993
+ * @throws {Error} If session or swarm validation fails, or if the execution process encounters an error.
14994
+ * @example
14995
+ * const result = await executeForce("Force this execution", "client-123");
14996
+ * console.log(result); // Outputs the agent's response regardless of its active state
14997
+ */
14998
+ const executeForce = beginContext(async (content, clientId) => {
14999
+ const executionId = functoolsKit.randomString();
15000
+ // Log the operation details if logging is enabled in GLOBAL_CONFIG
15001
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15002
+ swarm$1.loggerService.log(METHOD_NAME$_, {
15003
+ content,
15004
+ clientId,
15005
+ executionId,
15006
+ });
15007
+ // Validate the session and swarm
15008
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$_);
15009
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15010
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$_);
15011
+ // Execute the command within an execution context with performance tracking
15012
+ return ExecutionContextService.runInContext(async () => {
15013
+ let isFinished = false;
15014
+ swarm$1.perfService.startExecution(executionId, clientId, content.length);
15015
+ try {
15016
+ swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
15017
+ const result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$_, clientId, swarmName);
15018
+ isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
15019
+ swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
15020
+ return result;
15021
+ }
15022
+ finally {
15023
+ if (!isFinished) {
15024
+ swarm$1.perfService.endExecution(executionId, clientId, 0);
15025
+ }
15026
+ }
15027
+ }, {
15028
+ clientId,
15029
+ executionId,
15030
+ processId: GLOBAL_CONFIG.CC_PROCESS_UUID,
15031
+ });
15032
+ });
15033
+
15034
+ const METHOD_NAME$Z = "function.template.navigateToTriageAgent";
15035
+ const DEFAULT_ACCEPT_FN = (_, defaultAgent) => `Successfully navigated to ${defaultAgent}`;
15036
+ const DEFAULT_REJECT_FN = (_, defaultAgent) => `Already on ${defaultAgent}`;
15037
+ /**
15038
+ * Creates a function to navigate to a triage agent for a specific client, handling navigation, message execution, and tool output.
15039
+ * The factory generates a handler that checks navigation state, commits tool outputs with accept/reject messages, and triggers execution or emission based on provided parameters.
15040
+ * It operates outside any existing method or execution contexts to ensure isolation, leveraging `beginContext` for a clean execution scope.
15041
+ * Logs the navigation operation if logging is enabled in the global configuration.
15042
+ *
15043
+ * @param {IFactoryParams} params - Configuration parameters for the navigation handler.
15044
+ * @param {string | ((clientId: string, defaultAgent: AgentName) => string | Promise<string>)} [params.flushMessage] - Optional message or function to emit after flushing the session.
15045
+ * @param {string | ((clientId: string, defaultAgent: AgentName) => string | Promise<string>)} [params.executeMessage] - Optional message or function to execute if no navigation is needed.
15046
+ * @param {string | ((clientId: string, defaultAgent: AgentName) => string | Promise<string>)} [params.toolOutputAccept] - Optional message or function for tool output when navigation occurs, defaults to `DEFAULT_ACCEPT_FN`.
15047
+ * @param {string | ((clientId: string, defaultAgent: AgentName) => string | Promise<string>)} [params.toolOutputReject] - Optional message or function for tool output when already on the default agent, defaults to `DEFAULT_REJECT_FN`.
15048
+ * @returns {Promise<(toolId: string, clientId: string) => Promise<void>>} A promise resolving to a function that handles navigation to the triage agent.
15049
+ * @throws {Error} If neither `flushMessage` nor `executeMessage` is provided, or if any internal operation (e.g., navigation, commit, or execution) fails.
15050
+ *
15051
+ * @example
15052
+ * // Create a navigation handler with a static flush message
15053
+ * const navigate = await createNavigateToTriageAgent({
15054
+ * flushMessage: "Session reset for triage.",
15055
+ * toolOutputAccept: "Navigation completed.",
15056
+ * });
15057
+ * await navigate("tool-123", "client-456");
15058
+ * // Navigates to default agent, commits custom tool output, and emits the flush message if applicable.
15059
+ *
15060
+ * @example
15061
+ * // Create a navigation handler with dynamic messages
15062
+ * const navigate = await createNavigateToTriageAgent({
15063
+ * executeMessage: (clientId, agent) => `Processing ${clientId} on ${agent}`,
15064
+ * toolOutputReject: (clientId, agent) => `No navigation needed for ${clientId}`,
15065
+ * });
15066
+ * await navigate("tool-789", "client-012");
15067
+ * // Commits dynamic reject message and executes the message if already on the default agent.
15068
+ */
15069
+ const createNavigateToTriageAgent = async ({ flushMessage, executeMessage, toolOutputAccept = DEFAULT_ACCEPT_FN, toolOutputReject = DEFAULT_REJECT_FN, }) => {
15070
+ if (!flushMessage && !executeMessage) {
15071
+ throw new Error("agent-swarm createNavigateToTriageAgent flushMessage or executeMessage required");
15072
+ }
15073
+ /**
15074
+ * Navigates to the default triage agent for a given client and tool, handling message commits and execution.
15075
+ *
15076
+ * @param {string} toolId - The identifier of the tool triggering the navigation.
15077
+ * @param {string} clientId - The unique identifier of the client session.
15078
+ * @returns {Promise<void>} A promise that resolves when the navigation and associated actions are complete.
15079
+ * @throws {Error} If navigation, commit, or execution operations fail (e.g., invalid clientId or swarm configuration).
15080
+ */
15081
+ return beginContext(async (toolId, clientId) => {
15082
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15083
+ swarm$1.loggerService.log(METHOD_NAME$Z, {
15084
+ clientId,
15085
+ toolId,
15086
+ });
15087
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15088
+ const { defaultAgent } = swarm$1.swarmSchemaService.get(swarmName);
15089
+ if (await functoolsKit.not(hasNavigation(clientId, defaultAgent))) {
15090
+ const lastMessage = await getLastUserMessage(clientId);
15091
+ await changeToDefaultAgent(clientId);
15092
+ await commitToolOutputForce(toolId, typeof toolOutputAccept === "string"
15093
+ ? toolOutputAccept
15094
+ : await toolOutputAccept(clientId, defaultAgent), clientId);
15095
+ await executeForce(lastMessage, clientId);
15096
+ }
15097
+ if (flushMessage) {
15098
+ await commitFlushForce(clientId);
15099
+ await emitForce(typeof flushMessage === "string"
15100
+ ? flushMessage
15101
+ : await flushMessage(clientId, defaultAgent), clientId);
15102
+ return;
15103
+ }
15104
+ await commitToolOutputForce(toolId, typeof toolOutputReject === "string"
15105
+ ? toolOutputReject
15106
+ : await toolOutputReject(clientId, defaultAgent), clientId);
15107
+ await executeForce(typeof executeMessage === "string"
15108
+ ? executeMessage
15109
+ : await executeMessage(clientId, defaultAgent), clientId);
15110
+ });
15111
+ };
15112
+
15113
+ const METHOD_NAME$Y = "function.navigate.changeToAgent";
15114
+ /**
15115
+ * Time-to-live for the change agent function in milliseconds.
15116
+ * Defines how long the cached change agent function remains valid before expiring.
15117
+ * @constant {number}
15118
+ */
15119
+ const CHANGE_AGENT_TTL$1 = 15 * 60 * 1000;
15120
+ /**
15121
+ * Garbage collection interval for the change agent function in milliseconds.
15122
+ * Specifies the frequency at which expired TTL entries are cleaned up.
15123
+ * @constant {number}
15124
+ */
15125
+ const CHANGE_AGENT_GC$1 = 60 * 1000;
15126
+ /**
15127
+ * Creates a change agent function with time-to-live (TTL) and queuing capabilities.
15128
+ *
15129
+ * This factory function generates a queued, TTL-limited function to handle agent changes for a specific client session,
15130
+ * ensuring operations are executed sequentially and cached results are reused within the TTL period.
15131
+ *
15132
+ * @function
15133
+ * @param {string} clientId - The unique identifier of the client session.
15134
+ * @returns {TChangeToAgentRun} A function that performs the agent change operation with queuing and TTL.
15135
+ */
15136
+ const createChangeToAgent = functoolsKit.ttl((clientId) => functoolsKit.queued(async (methodName, agentName, swarmName) => {
15137
+ if (!swarm$1.navigationValidationService.shouldNavigate(agentName, clientId, swarmName)) {
15138
+ console.warn(`function "changeToAgent" skipped due to the circular route found clientId=${clientId} swarmName=${swarmName} agentNameTo=${agentName}`);
15139
+ return false;
15140
+ }
15141
+ // Notify all agents in the swarm of the change
15142
+ await Promise.all(swarm$1.swarmValidationService
15143
+ .getAgentList(swarmName)
15144
+ .map(async (agentName) => {
15145
+ await swarm$1.agentPublicService.commitAgentChange(methodName, clientId, agentName);
15146
+ }));
15147
+ {
15148
+ // Dispose of the current agent's resources and set up the new agent
15149
+ const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$Y, clientId, swarmName);
15150
+ await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
15151
+ await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
15152
+ await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
15153
+ }
15154
+ // Set the new agent as the active agent
15155
+ await swarm$1.swarmPublicService.setAgentName(agentName, methodName, clientId, swarmName);
15156
+ return true;
15157
+ }), {
15158
+ key: ([clientId]) => `${clientId}`,
15159
+ timeout: CHANGE_AGENT_TTL$1,
15160
+ });
14626
15161
  /**
14627
- * Validates the client ID for execution event listening, allowing wildcard "*" or checking for an active session.
15162
+ * Creates a garbage collector for the change agent function.
14628
15163
  *
14629
- * @param {string} clientId - The client ID to validate.
14630
- * @throws {Error} If the client ID is not "*" and no active session exists for it.
15164
+ * This function sets up a singleton interval-based garbage collector to periodically clean up expired TTL entries from `createChangeToAgent`.
15165
+ *
15166
+ * @function
15167
+ * @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
14631
15168
  */
14632
- const validateClientId$h = (clientId) => {
14633
- if (clientId === "*") {
14634
- return;
14635
- }
14636
- if (!swarm$1.sessionValidationService.hasSession(clientId)) {
14637
- throw new Error(`agent-swarm listenExecutionEvent session not found for clientId=${clientId}`);
14638
- }
14639
- };
15169
+ const createGc$2 = functoolsKit.singleshot(async () => {
15170
+ setInterval(createChangeToAgent.gc, CHANGE_AGENT_GC$1);
15171
+ });
14640
15172
  /**
14641
- * Subscribes to execution-specific events on the swarm bus service for a specific client and executes a callback for each event.
15173
+ * Changes the active agent for a given client session in a swarm.
14642
15174
  *
14643
- * This function sets up a listener for events on the "execution-bus" topic associated with a given client ID, invoking the provided callback with
14644
- * the event data whenever an execution event is received. It is wrapped in `beginContext` for a clean execution environment and logs the operation
14645
- * via `loggerService`. The callback is queued using `functools-kit` to ensure sequential processing of events. The function supports a wildcard
14646
- * client ID ("*") for listening to all clients or validates a specific client session. It returns an unsubscribe function to stop listening.
15175
+ * This function facilitates switching the active agent in a swarm session, validating the session and agent dependencies,
15176
+ * logging the operation if enabled, and executing the change using a TTL-limited, queued runner.
15177
+ * The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts.
14647
15178
  *
14648
- * @param {string} clientId - The ID of the client to subscribe to execution events for, or "*" to listen to all clients.
14649
- * @param {(event: IBusEvent) => void} fn - The callback function to execute when an execution event is received, passed the event object.
14650
- * @returns {() => void} A function to unsubscribe from the execution event listener.
14651
- * @throws {Error} If the `clientId` is not "*" and no active session exists for it.
15179
+ * @param {AgentName} agentName - The name of the agent to switch to.
15180
+ * @param {string} clientId - The unique identifier of the client session.
15181
+ * @returns {Promise<boolean>} A promise that resolves when the agent change is complete. If it resolved false, the navigation is canceled due to recursion
15182
+ * @throws {Error} If session or agent validation fails, or if the agent change process encounters an error.
14652
15183
  * @example
14653
- * const unsubscribe = listenExecutionEvent("client-123", (event) => console.log(event));
14654
- * // Logs each execution event for "client-123"
14655
- * unsubscribe(); // Stops listening
15184
+ * await changeToAgent("AgentX", "client-123");
14656
15185
  */
14657
- const listenExecutionEvent = beginContext((clientId, fn) => {
14658
- // Log the operation details
14659
- swarm$1.loggerService.log("middleware listenExecutionEvent", {
14660
- clientId,
14661
- });
14662
- // Validate the client ID
14663
- validateClientId$h(clientId);
14664
- // Subscribe to execution events with a queued callback
14665
- return swarm$1.busService.subscribe(clientId, "execution-bus", functoolsKit.queued(async (e) => await fn(e)));
15186
+ const changeToAgent = beginContext(async (agentName, clientId) => {
15187
+ // Log the operation details if logging is enabled in GLOBAL_CONFIG
15188
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15189
+ swarm$1.loggerService.log(METHOD_NAME$Y, {
15190
+ agentName,
15191
+ clientId,
15192
+ });
15193
+ const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15194
+ {
15195
+ // Validate session, agent, and dependencies
15196
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$Y);
15197
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$Y);
15198
+ const activeAgent = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$Y, clientId, swarmName);
15199
+ if (!swarm$1.agentValidationService.hasDependency(activeAgent, agentName)) {
15200
+ console.error(`agent-swarm missing dependency detected for activeAgent=${activeAgent} dependencyAgent=${agentName}`);
15201
+ }
15202
+ }
15203
+ if (!swarm$1.swarmValidationService.getAgentSet(swarmName).has(agentName)) {
15204
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15205
+ swarm$1.loggerService.log('function "changeToAgent" skipped due to the agent is not in the swarm', {
15206
+ agentName,
15207
+ clientId,
15208
+ swarmName,
15209
+ });
15210
+ console.warn(`function "changeToAgent" skipped due to the agent is not in the swarm clientId=${clientId} agentName=${agentName} swarmName=${swarmName}`);
15211
+ return false;
15212
+ }
15213
+ // Execute the agent change with TTL and queuing
15214
+ const run = await createChangeToAgent(clientId);
15215
+ createGc$2();
15216
+ return await run(METHOD_NAME$Y, agentName, swarmName);
14666
15217
  });
14667
15218
 
14668
- const METHOD_NAME$14 = "cli.dumpClientPerformance";
14669
- const METHOD_NAME_INTERNAL = "cli.dumpClientPerformance.internal";
14670
- const METHOD_NAME_EXECUTE = "cli.dumpClientPerformance.execute";
15219
+ const METHOD_NAME$X = "function.template.navigateToAgent";
14671
15220
  /**
14672
- * The internal HOF for handling the performance dump
15221
+ * Default tool output message indicating successful navigation to the specified agent.
14673
15222
  *
14674
- * @param {string} clientId - The client ID for which the performance data is being dumped.
14675
- * @param {string} [dirName="./logs/client"] - The directory name where the performance data will be dumped.
14676
- * @returns {Promise<void>} A promise that resolves when the performance data has been dumped.
15223
+ * @param {SessionId} _ - The client session ID (unused).
15224
+ * @param {AgentName} agentName - The name of the agent navigated to.
15225
+ * @returns {string} A message confirming navigation to the agent.
14677
15226
  */
14678
- const dumpClientPerformanceInternal = beginContext(async (clientId, dirName = "./logs/client") => {
14679
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14680
- swarm$1.loggerService.log(METHOD_NAME_INTERNAL);
14681
- return await swarm$1.docService.dumpClientPerfomance(clientId, dirName);
14682
- });
15227
+ const DEFAULT_TOOL_OUTPUT = (_, agentName) => `Successfully navigated to ${agentName}`;
14683
15228
  /**
14684
- * Dumps the performance data using the swarm's document service.
14685
- * Logs the method name if logging is enabled in the global configuration.
15229
+ * Default flush message prompting the user to repeat their input.
14686
15230
  *
14687
- * @param {string} clientId - The client ID for which the performance data is being dumped.
14688
- * @param {string} [dirName="./logs/client"] - The directory name where the performance data will be dumped.
14689
- * @returns {Promise<void>} A promise that resolves when the performance data has been dumped.
15231
+ * @param {SessionId} _ - The client session ID (unused).
15232
+ * @param {AgentName} _ - The agent name (unused).
15233
+ * @returns {string} A generic retry message.
14690
15234
  */
14691
- const dumpClientPerformance = async (clientId, dirName = "./logs/client") => {
14692
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$14);
14693
- await dumpClientPerformanceInternal(clientId, dirName);
14694
- };
15235
+ const DEFAULT_FLUSH_MESSAGE = ({}, {}) => `Sorry, I missed that. Could you repeat please`;
14695
15236
  /**
14696
- * Sets up a listener to dump performance data after execution.
14697
- * Logs the method name if logging is enabled in the global configuration.
15237
+ * Creates a function to navigate to a specified agent for a given client, handling navigation, message execution, emission, and tool output.
15238
+ * The factory generates a handler that checks navigation state, retrieves the last user message, commits tool outputs, and triggers execution or emission based on provided parameters.
15239
+ * It validates the presence of either `emitMessage` or `executeMessage` to ensure proper navigation behavior.
15240
+ * Logs the navigation operation if logging is enabled in the global configuration.
14698
15241
  *
14699
- * @param {string} [dirName="./logs/client"] - The directory name where the performance data will be dumped.
14700
- * @returns {Promise<void>} A promise that resolves when the listener has been set up.
15242
+ * @param {IFactoryParams} params - Configuration parameters for the navigation handler.
15243
+ * @param {string | ((clientId: string, defaultAgent: AgentName) => string | Promise<string>)} [params.flushMessage] - Optional message or function to emit after flushing the session, defaults to `DEFAULT_FLUSH_MESSAGE`.
15244
+ * @param {string | ((clientId: string, agentName: AgentName) => string | Promise<string>)} [params.toolOutput] - Optional message or function for tool output when navigation occurs, defaults to `DEFAULT_TOOL_OUTPUT`.
15245
+ * @param {string | ((clientId: string, lastMessage: string, agentName: AgentName) => string | Promise<string>)} [params.emitMessage] - Optional message or function to emit when navigation occurs without execution.
15246
+ * @param {string | ((clientId: string, lastMessage: string, agentName: AgentName) => string | Promise<string>)} [params.executeMessage] - Optional message or function to execute when navigation occurs with execution.
15247
+ * @returns {Promise<(toolId: string, clientId: string, agentName: AgentName) => Promise<void>>} A promise resolving to a function that handles navigation to the specified agent.
15248
+ * @throws {Error} If neither `emitMessage` nor `executeMessage` is provided, or if any internal operation (e.g., navigation, commit, or execution) fails.
15249
+ *
15250
+ * @example
15251
+ * // Create a navigation handler with static messages
15252
+ * const navigate = await createNavigateToAgent({
15253
+ * flushMessage: "Session reset.",
15254
+ * toolOutput: "Navigation completed.",
15255
+ * emitMessage: "Navigation event triggered.",
15256
+ * });
15257
+ * await navigate("tool-123", "client-456", "WeatherAgent");
15258
+ * // Navigates to WeatherAgent, commits tool output, and emits the message.
15259
+ *
15260
+ * @example
15261
+ * // Create a navigation handler with dynamic messages
15262
+ * const navigate = await createNavigateToAgent({
15263
+ * executeMessage: (clientId, lastMessage, agent) => `Processing ${lastMessage} for ${clientId} on ${agent}`,
15264
+ * toolOutput: (clientId, agent) => `Navigated ${clientId} to ${agent}`,
15265
+ * });
15266
+ * await navigate("tool-789", "client-012", "SupportAgent");
15267
+ * // Navigates to SupportAgent, commits dynamic tool output, and executes the message with the last user message.
14701
15268
  */
14702
- dumpClientPerformance.runAfterExecute = beginContext(async (dirName = "./logs/client") => {
14703
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14704
- swarm$1.loggerService.log(METHOD_NAME_EXECUTE);
14705
- return listenExecutionEvent("*", async ({ type, clientId }) => {
14706
- if (type === "commit-execution-end") {
14707
- await dumpClientPerformanceInternal(clientId, dirName);
15269
+ const createNavigateToAgent = async ({ executeMessage, emitMessage, flushMessage = DEFAULT_FLUSH_MESSAGE, toolOutput = DEFAULT_TOOL_OUTPUT, }) => {
15270
+ if (!emitMessage && !executeMessage) {
15271
+ throw new Error("agent-swarm createNavigateToAgent emitMessage or executeMessage required");
15272
+ }
15273
+ /**
15274
+ * Navigates to a specified agent for a given client and tool, handling message commits, execution, or emission using the last user message.
15275
+ *
15276
+ * @param {string} toolId - The identifier of the tool triggering the navigation.
15277
+ * @param {string} clientId - The unique identifier of the client session.
15278
+ * @param {AgentName} agentName - The name of the agent to navigate to.
15279
+ * @returns {Promise<void>} A promise that resolves when the navigation and associated actions are complete.
15280
+ * @throws {Error} If navigation, commit, execution, or emission operations fail (e.g., invalid clientId or agentName).
15281
+ */
15282
+ return beginContext(async (toolId, clientId, agentName) => {
15283
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15284
+ swarm$1.loggerService.log(METHOD_NAME$X, {
15285
+ clientId,
15286
+ toolId,
15287
+ });
15288
+ const lastMessage = await getLastUserMessage(clientId);
15289
+ if (await functoolsKit.and(functoolsKit.not(hasNavigation(clientId, agentName)), Promise.resolve(!!executeMessage))) {
15290
+ await commitToolOutputForce(toolId, typeof toolOutput === "string"
15291
+ ? toolOutput
15292
+ : await toolOutput(clientId, agentName), clientId);
15293
+ await changeToAgent(agentName, clientId);
15294
+ await executeForce(typeof executeMessage === "string"
15295
+ ? executeMessage
15296
+ : await executeMessage(clientId, lastMessage, agentName), clientId);
15297
+ return;
15298
+ }
15299
+ if (await functoolsKit.and(functoolsKit.not(hasNavigation(clientId, agentName)), Promise.resolve(!!emitMessage))) {
15300
+ await commitToolOutputForce(toolId, typeof toolOutput === "string"
15301
+ ? toolOutput
15302
+ : await toolOutput(clientId, agentName), clientId);
15303
+ await changeToAgent(agentName, clientId);
15304
+ await emitForce(typeof emitMessage === "string"
15305
+ ? emitMessage
15306
+ : await emitMessage(clientId, lastMessage, agentName), clientId);
15307
+ return;
14708
15308
  }
15309
+ await commitFlushForce(clientId);
15310
+ await emitForce(typeof flushMessage === "string"
15311
+ ? flushMessage
15312
+ : await flushMessage(clientId, agentName), clientId);
14709
15313
  });
14710
- });
15314
+ };
14711
15315
 
14712
15316
  /** @constant {string} METHOD_NAME - The name of the method used for logging */
14713
- const METHOD_NAME$13 = "function.setup.addWiki";
15317
+ const METHOD_NAME$W = "function.setup.addWiki";
14714
15318
  /**
14715
15319
  * Adds a wiki schema to the system
14716
15320
  * @function addWiki
@@ -14719,7 +15323,7 @@ const METHOD_NAME$13 = "function.setup.addWiki";
14719
15323
  */
14720
15324
  const addWiki = beginContext((wikiSchema) => {
14721
15325
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14722
- swarm$1.loggerService.log(METHOD_NAME$13, {
15326
+ swarm$1.loggerService.log(METHOD_NAME$W, {
14723
15327
  wikiSchema,
14724
15328
  });
14725
15329
  swarm$1.wikiValidationService.addWiki(wikiSchema.wikiName, wikiSchema);
@@ -14727,7 +15331,7 @@ const addWiki = beginContext((wikiSchema) => {
14727
15331
  return wikiSchema.wikiName;
14728
15332
  });
14729
15333
 
14730
- const METHOD_NAME$12 = "function.setup.addAgent";
15334
+ const METHOD_NAME$V = "function.setup.addAgent";
14731
15335
  /**
14732
15336
  * Adds a new agent to the agent registry for use within the swarm system.
14733
15337
  *
@@ -14747,7 +15351,7 @@ const METHOD_NAME$12 = "function.setup.addAgent";
14747
15351
  const addAgent = beginContext((agentSchema) => {
14748
15352
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
14749
15353
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14750
- swarm$1.loggerService.log(METHOD_NAME$12, {
15354
+ swarm$1.loggerService.log(METHOD_NAME$V, {
14751
15355
  agentSchema,
14752
15356
  });
14753
15357
  // Register the agent in the validation and schema services
@@ -14757,7 +15361,7 @@ const addAgent = beginContext((agentSchema) => {
14757
15361
  return agentSchema.agentName;
14758
15362
  });
14759
15363
 
14760
- const METHOD_NAME$11 = "function.setup.addCompletion";
15364
+ const METHOD_NAME$U = "function.setup.addCompletion";
14761
15365
  /**
14762
15366
  * Adds a completion engine to the registry for use by agents in the swarm system.
14763
15367
  *
@@ -14777,7 +15381,7 @@ const METHOD_NAME$11 = "function.setup.addCompletion";
14777
15381
  const addCompletion = beginContext((completionSchema) => {
14778
15382
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
14779
15383
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14780
- swarm$1.loggerService.log(METHOD_NAME$11, {
15384
+ swarm$1.loggerService.log(METHOD_NAME$U, {
14781
15385
  completionSchema,
14782
15386
  });
14783
15387
  // Register the completion in the validation and schema services
@@ -14787,7 +15391,7 @@ const addCompletion = beginContext((completionSchema) => {
14787
15391
  return completionSchema.completionName;
14788
15392
  });
14789
15393
 
14790
- const METHOD_NAME$10 = "function.setup.addSwarm";
15394
+ const METHOD_NAME$T = "function.setup.addSwarm";
14791
15395
  /**
14792
15396
  * Adds a new swarm to the system for managing client sessions.
14793
15397
  *
@@ -14807,7 +15411,7 @@ const METHOD_NAME$10 = "function.setup.addSwarm";
14807
15411
  const addSwarm = beginContext((swarmSchema) => {
14808
15412
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
14809
15413
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14810
- swarm$1.loggerService.log(METHOD_NAME$10, {
15414
+ swarm$1.loggerService.log(METHOD_NAME$T, {
14811
15415
  swarmSchema,
14812
15416
  });
14813
15417
  // Register the swarm in the validation and schema services
@@ -14817,7 +15421,7 @@ const addSwarm = beginContext((swarmSchema) => {
14817
15421
  return swarmSchema.swarmName;
14818
15422
  });
14819
15423
 
14820
- const METHOD_NAME$$ = "function.setup.addTool";
15424
+ const METHOD_NAME$S = "function.setup.addTool";
14821
15425
  /**
14822
15426
  * Adds a new tool to the tool registry for use by agents in the swarm system.
14823
15427
  *
@@ -14839,7 +15443,7 @@ const METHOD_NAME$$ = "function.setup.addTool";
14839
15443
  const addTool = beginContext((toolSchema) => {
14840
15444
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
14841
15445
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14842
- swarm$1.loggerService.log(METHOD_NAME$$, {
15446
+ swarm$1.loggerService.log(METHOD_NAME$S, {
14843
15447
  toolSchema,
14844
15448
  });
14845
15449
  // Register the tool in the validation and schema services
@@ -14849,7 +15453,7 @@ const addTool = beginContext((toolSchema) => {
14849
15453
  return toolSchema.toolName;
14850
15454
  });
14851
15455
 
14852
- const METHOD_NAME$_ = "function.setup.addState";
15456
+ const METHOD_NAME$R = "function.setup.addState";
14853
15457
  /**
14854
15458
  * Adds a new state to the state registry for use within the swarm system.
14855
15459
  *
@@ -14871,7 +15475,7 @@ const METHOD_NAME$_ = "function.setup.addState";
14871
15475
  const addState = beginContext((stateSchema) => {
14872
15476
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
14873
15477
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14874
- swarm$1.loggerService.log(METHOD_NAME$_, {
15478
+ swarm$1.loggerService.log(METHOD_NAME$R, {
14875
15479
  stateSchema,
14876
15480
  });
14877
15481
  // Register the state in the schema service
@@ -14886,7 +15490,7 @@ const addState = beginContext((stateSchema) => {
14886
15490
  return stateSchema.stateName;
14887
15491
  });
14888
15492
 
14889
- const METHOD_NAME$Z = "function.setup.addEmbedding";
15493
+ const METHOD_NAME$Q = "function.setup.addEmbedding";
14890
15494
  /**
14891
15495
  * Adds a new embedding engine to the embedding registry for use within the swarm system.
14892
15496
  *
@@ -14906,7 +15510,7 @@ const METHOD_NAME$Z = "function.setup.addEmbedding";
14906
15510
  const addEmbedding = beginContext((embeddingSchema) => {
14907
15511
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
14908
15512
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14909
- swarm$1.loggerService.log(METHOD_NAME$Z, {
15513
+ swarm$1.loggerService.log(METHOD_NAME$Q, {
14910
15514
  embeddingSchema,
14911
15515
  });
14912
15516
  // Register the embedding in the validation and schema services
@@ -14916,7 +15520,7 @@ const addEmbedding = beginContext((embeddingSchema) => {
14916
15520
  return embeddingSchema.embeddingName;
14917
15521
  });
14918
15522
 
14919
- const METHOD_NAME$Y = "function.setup.addStorage";
15523
+ const METHOD_NAME$P = "function.setup.addStorage";
14920
15524
  /**
14921
15525
  * Adds a new storage engine to the storage registry for use within the swarm system.
14922
15526
  *
@@ -14938,7 +15542,7 @@ const METHOD_NAME$Y = "function.setup.addStorage";
14938
15542
  const addStorage = beginContext((storageSchema) => {
14939
15543
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
14940
15544
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14941
- swarm$1.loggerService.log(METHOD_NAME$Y, {
15545
+ swarm$1.loggerService.log(METHOD_NAME$P, {
14942
15546
  storageSchema,
14943
15547
  });
14944
15548
  // Register the storage in the validation and schema services
@@ -14955,7 +15559,7 @@ const addStorage = beginContext((storageSchema) => {
14955
15559
  });
14956
15560
 
14957
15561
  /** @private Constant defining the method name for logging and validation context */
14958
- const METHOD_NAME$X = "function.setup.addPolicy";
15562
+ const METHOD_NAME$O = "function.setup.addPolicy";
14959
15563
  /**
14960
15564
  * Adds a new policy for agents in the swarm system by registering it with validation and schema services.
14961
15565
  * Registers the policy with PolicyValidationService for runtime validation and PolicySchemaService for schema management.
@@ -14971,7 +15575,7 @@ const METHOD_NAME$X = "function.setup.addPolicy";
14971
15575
  const addPolicy = beginContext((policySchema) => {
14972
15576
  // Log the policy addition attempt if enabled
14973
15577
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
14974
- swarm$1.loggerService.log(METHOD_NAME$X, {
15578
+ swarm$1.loggerService.log(METHOD_NAME$O, {
14975
15579
  policySchema,
14976
15580
  });
14977
15581
  // Register the policy with PolicyValidationService for runtime validation
@@ -14982,7 +15586,7 @@ const addPolicy = beginContext((policySchema) => {
14982
15586
  return policySchema.policyName;
14983
15587
  });
14984
15588
 
14985
- const METHOD_NAME$W = "function.test.overrideAgent";
15589
+ const METHOD_NAME$N = "function.test.overrideAgent";
14986
15590
  /**
14987
15591
  * Overrides an existing agent schema in the swarm system with a new or partial schema.
14988
15592
  * This function updates the configuration of an agent identified by its `agentName`, applying the provided schema properties.
@@ -15006,13 +15610,13 @@ const METHOD_NAME$W = "function.test.overrideAgent";
15006
15610
  */
15007
15611
  const overrideAgent = beginContext((agentSchema) => {
15008
15612
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15009
- swarm$1.loggerService.log(METHOD_NAME$W, {
15613
+ swarm$1.loggerService.log(METHOD_NAME$N, {
15010
15614
  agentSchema,
15011
15615
  });
15012
15616
  return swarm$1.agentSchemaService.override(agentSchema.agentName, agentSchema);
15013
15617
  });
15014
15618
 
15015
- const METHOD_NAME$V = "function.test.overrideCompletion";
15619
+ const METHOD_NAME$M = "function.test.overrideCompletion";
15016
15620
  /**
15017
15621
  * Overrides an existing completion schema in the swarm system with a new or partial schema.
15018
15622
  * This function updates the configuration of a completion mechanism identified by its `completionName`, applying the provided schema properties.
@@ -15036,13 +15640,13 @@ const METHOD_NAME$V = "function.test.overrideCompletion";
15036
15640
  */
15037
15641
  const overrideCompletion = beginContext((completionSchema) => {
15038
15642
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15039
- swarm$1.loggerService.log(METHOD_NAME$V, {
15643
+ swarm$1.loggerService.log(METHOD_NAME$M, {
15040
15644
  completionSchema,
15041
15645
  });
15042
15646
  return swarm$1.completionSchemaService.override(completionSchema.completionName, completionSchema);
15043
15647
  });
15044
15648
 
15045
- const METHOD_NAME$U = "function.test.overrideEmbeding";
15649
+ const METHOD_NAME$L = "function.test.overrideEmbeding";
15046
15650
  /**
15047
15651
  * Overrides an existing embedding schema in the swarm system with a new or partial schema.
15048
15652
  * This function updates the configuration of an embedding mechanism identified by its `embeddingName`, applying the provided schema properties.
@@ -15068,13 +15672,13 @@ const METHOD_NAME$U = "function.test.overrideEmbeding";
15068
15672
  */
15069
15673
  const overrideEmbeding = beginContext((embeddingSchema) => {
15070
15674
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15071
- swarm$1.loggerService.log(METHOD_NAME$U, {
15675
+ swarm$1.loggerService.log(METHOD_NAME$L, {
15072
15676
  embeddingSchema,
15073
15677
  });
15074
15678
  return swarm$1.embeddingSchemaService.override(embeddingSchema.embeddingName, embeddingSchema);
15075
15679
  });
15076
15680
 
15077
- const METHOD_NAME$T = "function.test.overridePolicy";
15681
+ const METHOD_NAME$K = "function.test.overridePolicy";
15078
15682
  /**
15079
15683
  * Overrides an existing policy schema in the swarm system with a new or partial schema.
15080
15684
  * This function updates the configuration of a policy identified by its `policyName`, applying the provided schema properties.
@@ -15098,13 +15702,13 @@ const METHOD_NAME$T = "function.test.overridePolicy";
15098
15702
  */
15099
15703
  const overridePolicy = beginContext((policySchema) => {
15100
15704
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15101
- swarm$1.loggerService.log(METHOD_NAME$T, {
15705
+ swarm$1.loggerService.log(METHOD_NAME$K, {
15102
15706
  policySchema,
15103
15707
  });
15104
15708
  return swarm$1.policySchemaService.override(policySchema.policyName, policySchema);
15105
15709
  });
15106
15710
 
15107
- const METHOD_NAME$S = "function.test.overrideState";
15711
+ const METHOD_NAME$J = "function.test.overrideState";
15108
15712
  /**
15109
15713
  * Overrides an existing state schema in the swarm system with a new or partial schema.
15110
15714
  * This function updates the configuration of a state identified by its `stateName`, applying the provided schema properties.
@@ -15129,13 +15733,13 @@ const METHOD_NAME$S = "function.test.overrideState";
15129
15733
  */
15130
15734
  const overrideState = beginContext((stateSchema) => {
15131
15735
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15132
- swarm$1.loggerService.log(METHOD_NAME$S, {
15736
+ swarm$1.loggerService.log(METHOD_NAME$J, {
15133
15737
  stateSchema,
15134
15738
  });
15135
15739
  return swarm$1.stateSchemaService.override(stateSchema.stateName, stateSchema);
15136
15740
  });
15137
15741
 
15138
- const METHOD_NAME$R = "function.test.overrideStorage";
15742
+ const METHOD_NAME$I = "function.test.overrideStorage";
15139
15743
  /**
15140
15744
  * Overrides an existing storage schema in the swarm system with a new or partial schema.
15141
15745
  * This function updates the configuration of a storage identified by its `storageName`, applying the provided schema properties.
@@ -15161,13 +15765,13 @@ const METHOD_NAME$R = "function.test.overrideStorage";
15161
15765
  */
15162
15766
  const overrideStorage = beginContext((storageSchema) => {
15163
15767
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15164
- swarm$1.loggerService.log(METHOD_NAME$R, {
15768
+ swarm$1.loggerService.log(METHOD_NAME$I, {
15165
15769
  storageSchema,
15166
15770
  });
15167
15771
  return swarm$1.storageSchemaService.override(storageSchema.storageName, storageSchema);
15168
15772
  });
15169
15773
 
15170
- const METHOD_NAME$Q = "function.test.overrideSwarm";
15774
+ const METHOD_NAME$H = "function.test.overrideSwarm";
15171
15775
  /**
15172
15776
  * Overrides an existing swarm schema in the swarm system with a new or partial schema.
15173
15777
  * This function updates the configuration of a swarm identified by its `swarmName`, applying the provided schema properties.
@@ -15191,13 +15795,13 @@ const METHOD_NAME$Q = "function.test.overrideSwarm";
15191
15795
  */
15192
15796
  const overrideSwarm = beginContext((swarmSchema) => {
15193
15797
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15194
- swarm$1.loggerService.log(METHOD_NAME$Q, {
15798
+ swarm$1.loggerService.log(METHOD_NAME$H, {
15195
15799
  swarmSchema,
15196
15800
  });
15197
15801
  return swarm$1.swarmSchemaService.override(swarmSchema.swarmName, swarmSchema);
15198
15802
  });
15199
15803
 
15200
- const METHOD_NAME$P = "function.test.overrideTool";
15804
+ const METHOD_NAME$G = "function.test.overrideTool";
15201
15805
  /**
15202
15806
  * Overrides an existing tool schema in the swarm system with a new or partial schema.
15203
15807
  * This function updates the configuration of a tool identified by its `toolName`, applying the provided schema properties.
@@ -15221,13 +15825,13 @@ const METHOD_NAME$P = "function.test.overrideTool";
15221
15825
  */
15222
15826
  const overrideTool = beginContext((toolSchema) => {
15223
15827
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15224
- swarm$1.loggerService.log(METHOD_NAME$P, {
15828
+ swarm$1.loggerService.log(METHOD_NAME$G, {
15225
15829
  toolSchema,
15226
15830
  });
15227
15831
  return swarm$1.toolSchemaService.override(toolSchema.toolName, toolSchema);
15228
15832
  });
15229
15833
 
15230
- const METHOD_NAME$O = "function.test.overrideWiki";
15834
+ const METHOD_NAME$F = "function.test.overrideWiki";
15231
15835
  /**
15232
15836
  * Overrides an existing wiki schema in the swarm system with a new or partial schema.
15233
15837
  * This function updates the configuration of a wiki identified by its `wikiName`, applying the provided schema properties.
@@ -15251,13 +15855,13 @@ const METHOD_NAME$O = "function.test.overrideWiki";
15251
15855
  */
15252
15856
  const overrideWiki = beginContext((wikiSchema) => {
15253
15857
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15254
- swarm$1.loggerService.log(METHOD_NAME$O, {
15858
+ swarm$1.loggerService.log(METHOD_NAME$F, {
15255
15859
  wikiSchema,
15256
15860
  });
15257
15861
  return swarm$1.wikiSchemaService.override(wikiSchema.wikiName, wikiSchema);
15258
15862
  });
15259
15863
 
15260
- const METHOD_NAME$N = "function.other.markOnline";
15864
+ const METHOD_NAME$E = "function.other.markOnline";
15261
15865
  /**
15262
15866
  * Marks a client as online in the specified swarm.
15263
15867
  *
@@ -15269,16 +15873,16 @@ const METHOD_NAME$N = "function.other.markOnline";
15269
15873
  const markOnline = async (clientId, swarmName) => {
15270
15874
  // Log the operation if logging is enabled in the global configuration
15271
15875
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15272
- swarm.loggerService.log(METHOD_NAME$N, {
15876
+ swarm.loggerService.log(METHOD_NAME$E, {
15273
15877
  clientId,
15274
15878
  });
15275
15879
  // Validate the swarm name
15276
- swarm.swarmValidationService.validate(swarmName, METHOD_NAME$N);
15880
+ swarm.swarmValidationService.validate(swarmName, METHOD_NAME$E);
15277
15881
  // Run the operation in the method context
15278
15882
  return await MethodContextService.runInContext(async () => {
15279
- await swarm.aliveService.markOnline(clientId, swarmName, METHOD_NAME$N);
15883
+ await swarm.aliveService.markOnline(clientId, swarmName, METHOD_NAME$E);
15280
15884
  }, {
15281
- methodName: METHOD_NAME$N,
15885
+ methodName: METHOD_NAME$E,
15282
15886
  agentName: "",
15283
15887
  policyName: "",
15284
15888
  stateName: "",
@@ -15288,7 +15892,7 @@ const markOnline = async (clientId, swarmName) => {
15288
15892
  });
15289
15893
  };
15290
15894
 
15291
- const METHOD_NAME$M = "function.other.markOffline";
15895
+ const METHOD_NAME$D = "function.other.markOffline";
15292
15896
  /**
15293
15897
  * Marks a client as offline in the specified swarm.
15294
15898
  *
@@ -15303,14 +15907,14 @@ const METHOD_NAME$M = "function.other.markOffline";
15303
15907
  */
15304
15908
  const markOffline = async (clientId, swarmName) => {
15305
15909
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15306
- swarm.loggerService.log(METHOD_NAME$M, {
15910
+ swarm.loggerService.log(METHOD_NAME$D, {
15307
15911
  clientId,
15308
15912
  });
15309
- swarm.swarmValidationService.validate(swarmName, METHOD_NAME$M);
15913
+ swarm.swarmValidationService.validate(swarmName, METHOD_NAME$D);
15310
15914
  return await MethodContextService.runInContext(async () => {
15311
- await swarm.aliveService.markOffline(clientId, swarmName, METHOD_NAME$M);
15915
+ await swarm.aliveService.markOffline(clientId, swarmName, METHOD_NAME$D);
15312
15916
  }, {
15313
- methodName: METHOD_NAME$M,
15917
+ methodName: METHOD_NAME$D,
15314
15918
  agentName: "",
15315
15919
  policyName: "",
15316
15920
  stateName: "",
@@ -15320,7 +15924,7 @@ const markOffline = async (clientId, swarmName) => {
15320
15924
  });
15321
15925
  };
15322
15926
 
15323
- const METHOD_NAME$L = "function.commit.commitToolOutput";
15927
+ const METHOD_NAME$C = "function.commit.commitToolOutput";
15324
15928
  /**
15325
15929
  * Commits the output of a tool execution to the active agent in a swarm session.
15326
15930
  *
@@ -15340,19 +15944,19 @@ const METHOD_NAME$L = "function.commit.commitToolOutput";
15340
15944
  const commitToolOutput = beginContext(async (toolId, content, clientId, agentName) => {
15341
15945
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
15342
15946
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15343
- swarm$1.loggerService.log(METHOD_NAME$L, {
15947
+ swarm$1.loggerService.log(METHOD_NAME$C, {
15344
15948
  toolId,
15345
15949
  content,
15346
15950
  clientId,
15347
15951
  agentName,
15348
15952
  });
15349
15953
  // Validate the agent, session, and swarm to ensure they exist and are accessible
15350
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$L);
15351
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$L);
15954
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$C);
15955
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$C);
15352
15956
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15353
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$L);
15957
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$C);
15354
15958
  // Check if the specified agent is still the active agent in the swarm session
15355
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$L, clientId, swarmName);
15959
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$C, clientId, swarmName);
15356
15960
  if (currentAgentName !== agentName) {
15357
15961
  // Log a skip message if the agent has changed during the operation
15358
15962
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
@@ -15365,11 +15969,11 @@ const commitToolOutput = beginContext(async (toolId, content, clientId, agentNam
15365
15969
  return;
15366
15970
  }
15367
15971
  // Commit the tool output to the session via the session public service
15368
- await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$L, clientId, swarmName);
15972
+ await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$C, clientId, swarmName);
15369
15973
  });
15370
15974
 
15371
15975
  /** @private Constant defining the method name for logging and validation context */
15372
- const METHOD_NAME$K = "function.commit.commitSystemMessage";
15976
+ const METHOD_NAME$B = "function.commit.commitSystemMessage";
15373
15977
  /**
15374
15978
  * Commits a system-generated message to the active agent in the swarm system.
15375
15979
  * Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before committing the message.
@@ -15388,20 +15992,20 @@ const METHOD_NAME$K = "function.commit.commitSystemMessage";
15388
15992
  const commitSystemMessage = beginContext(async (content, clientId, agentName) => {
15389
15993
  // Log the commit attempt if enabled
15390
15994
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15391
- swarm$1.loggerService.log(METHOD_NAME$K, {
15995
+ swarm$1.loggerService.log(METHOD_NAME$B, {
15392
15996
  content,
15393
15997
  clientId,
15394
15998
  agentName,
15395
15999
  });
15396
16000
  // Validate the agent exists
15397
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$K);
16001
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$B);
15398
16002
  // Validate the session exists and retrieve the associated swarm
15399
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$K);
16003
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$B);
15400
16004
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15401
16005
  // Validate the swarm configuration
15402
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$K);
16006
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$B);
15403
16007
  // Check if the current agent matches the provided agent
15404
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$K, clientId, swarmName);
16008
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$B, clientId, swarmName);
15405
16009
  if (currentAgentName !== agentName) {
15406
16010
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15407
16011
  swarm$1.loggerService.log('function "commitSystemMessage" skipped due to the agent change', {
@@ -15412,11 +16016,11 @@ const commitSystemMessage = beginContext(async (content, clientId, agentName) =>
15412
16016
  return;
15413
16017
  }
15414
16018
  // Commit the system message via SessionPublicService
15415
- await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$K, clientId, swarmName);
16019
+ await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$B, clientId, swarmName);
15416
16020
  });
15417
16021
 
15418
16022
  /** @private Constant defining the method name for logging and validation context */
15419
- const METHOD_NAME$J = "function.commit.commitFlush";
16023
+ const METHOD_NAME$A = "function.commit.commitFlush";
15420
16024
  /**
15421
16025
  * Commits a flush of agent history for a specific client and agent in the swarm system.
15422
16026
  * Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before flushing the history.
@@ -15433,19 +16037,19 @@ const METHOD_NAME$J = "function.commit.commitFlush";
15433
16037
  const commitFlush = beginContext(async (clientId, agentName) => {
15434
16038
  // Log the flush attempt if enabled
15435
16039
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15436
- swarm$1.loggerService.log(METHOD_NAME$J, {
16040
+ swarm$1.loggerService.log(METHOD_NAME$A, {
15437
16041
  clientId,
15438
16042
  agentName,
15439
16043
  });
15440
16044
  // Validate the agent exists
15441
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$J);
16045
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$A);
15442
16046
  // Validate the session exists and retrieve the associated swarm
15443
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$J);
16047
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$A);
15444
16048
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15445
16049
  // Validate the swarm configuration
15446
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
16050
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$A);
15447
16051
  // Check if the current agent matches the provided agent
15448
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$J, clientId, swarmName);
16052
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$A, clientId, swarmName);
15449
16053
  if (currentAgentName !== agentName) {
15450
16054
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15451
16055
  swarm$1.loggerService.log('function "commitFlush" skipped due to the agent change', {
@@ -15456,10 +16060,10 @@ const commitFlush = beginContext(async (clientId, agentName) => {
15456
16060
  return;
15457
16061
  }
15458
16062
  // Commit the flush of agent history via SessionPublicService
15459
- await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$J, clientId, swarmName);
16063
+ await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$A, clientId, swarmName);
15460
16064
  });
15461
16065
 
15462
- const METHOD_NAME$I = "function.commit.commitSystemMessage";
16066
+ const METHOD_NAME$z = "function.commit.commitSystemMessage";
15463
16067
  /**
15464
16068
  * Commits a user message to the active agent's history in a swarm session without triggering a response.
15465
16069
  *
@@ -15478,19 +16082,19 @@ const METHOD_NAME$I = "function.commit.commitSystemMessage";
15478
16082
  const commitUserMessage = beginContext(async (content, mode, clientId, agentName, payload) => {
15479
16083
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
15480
16084
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15481
- swarm$1.loggerService.log(METHOD_NAME$I, {
16085
+ swarm$1.loggerService.log(METHOD_NAME$z, {
15482
16086
  content,
15483
16087
  clientId,
15484
16088
  agentName,
15485
16089
  mode,
15486
16090
  });
15487
16091
  // Validate the agent, session, and swarm to ensure they exist and are accessible
15488
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$I);
15489
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$I);
16092
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$z);
16093
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
15490
16094
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15491
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$I);
16095
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
15492
16096
  // Check if the specified agent is still the active agent in the swarm session
15493
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$I, clientId, swarmName);
16097
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$z, clientId, swarmName);
15494
16098
  if (currentAgentName !== agentName) {
15495
16099
  // Log a skip message if the agent has changed during the operation
15496
16100
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
@@ -15503,50 +16107,18 @@ const commitUserMessage = beginContext(async (content, mode, clientId, agentName
15503
16107
  }
15504
16108
  if (payload) {
15505
16109
  return await PayloadContextService.runInContext(async () => {
15506
- await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$I, clientId, swarmName);
16110
+ await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$z, clientId, swarmName);
15507
16111
  }, {
15508
16112
  clientId,
15509
16113
  payload,
15510
16114
  });
15511
16115
  }
15512
16116
  // Commit the user message to the agent's history via the session public service
15513
- return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$I, clientId, swarmName);
15514
- });
15515
-
15516
- const METHOD_NAME$H = "function.commit.commitToolOutputForce";
15517
- /**
15518
- * Commits the output of a tool execution to the active agent in a swarm session without checking the active agent.
15519
- *
15520
- * This function forcefully commits the tool output to the session, bypassing the check for whether the agent is still active in the swarm session.
15521
- * It performs validation on the session and swarm, logs the operation if enabled, and delegates the commit operation to the session public service.
15522
- * The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts, providing a clean execution environment.
15523
- *
15524
- * @param {string} toolId - The unique identifier of the tool whose output is being committed.
15525
- * @param {string} content - The content or result of the tool execution to be committed.
15526
- * @param {string} clientId - The unique identifier of the client session associated with the operation.
15527
- * @returns {Promise<void>} A promise that resolves when the tool output is successfully committed.
15528
- * @throws {Error} If validation fails (e.g., invalid session or swarm) or if the session public service encounters an error during the commit operation.
15529
- * @example
15530
- * await commitToolOutputForce("tool-123", "Tool execution result", "client-456");
15531
- */
15532
- const commitToolOutputForce = beginContext(async (toolId, content, clientId) => {
15533
- // Log the operation details if logging is enabled in GLOBAL_CONFIG
15534
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15535
- swarm$1.loggerService.log(METHOD_NAME$H, {
15536
- toolId,
15537
- content,
15538
- clientId,
15539
- });
15540
- // Validate the session and swarm to ensure they exist and are accessible
15541
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$H);
15542
- const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15543
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$H);
15544
- // Commit the tool output to the session via the session public service without checking the active agent
15545
- await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$H, clientId, swarmName);
16117
+ return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$z, clientId, swarmName);
15546
16118
  });
15547
16119
 
15548
16120
  /** @private Constant defining the method name for logging and validation context */
15549
- const METHOD_NAME$G = "function.commit.commitSystemMessageForce";
16121
+ const METHOD_NAME$y = "function.commit.commitSystemMessageForce";
15550
16122
  /**
15551
16123
  * Forcefully commits a system-generated message to a session in the swarm system, without checking the active agent.
15552
16124
  * Validates the session and swarm, then proceeds with committing the message regardless of the current agent state.
@@ -15565,52 +16137,20 @@ const METHOD_NAME$G = "function.commit.commitSystemMessageForce";
15565
16137
  const commitSystemMessageForce = beginContext(async (content, clientId) => {
15566
16138
  // Log the commit attempt if enabled
15567
16139
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15568
- swarm$1.loggerService.log(METHOD_NAME$G, {
16140
+ swarm$1.loggerService.log(METHOD_NAME$y, {
15569
16141
  content,
15570
16142
  clientId,
15571
16143
  });
15572
16144
  // Validate the session exists and retrieve the associated swarm
15573
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$G);
16145
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
15574
16146
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15575
16147
  // Validate the swarm configuration
15576
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$G);
16148
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
15577
16149
  // Commit the system message via SessionPublicService without agent checks
15578
- await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$G, clientId, swarmName);
15579
- });
15580
-
15581
- /** @private Constant defining the method name for logging and validation context */
15582
- const METHOD_NAME$F = "function.commit.commitFlushForce";
15583
- /**
15584
- * Forcefully commits a flush of agent history for a specific client in the swarm system, without checking the active agent.
15585
- * Validates the session and swarm, then proceeds with flushing the history regardless of the current agent state.
15586
- * Runs within a beginContext wrapper for execution context management, logging operations via LoggerService.
15587
- * Integrates with SessionValidationService (session and swarm retrieval), SwarmValidationService (swarm validation),
15588
- * SessionPublicService (history flush), and LoggerService (logging).
15589
- * Unlike commitFlush, this function skips agent validation and active agent checks, providing a more aggressive flush mechanism,
15590
- * analogous to commitAssistantMessageForce vs. commitAssistantMessage.
15591
- *
15592
- * @param {string} clientId - The ID of the client associated with the session, validated against active sessions.
15593
- * @param {string} agentName - The name of the agent (unused in this implementation, included for interface consistency with commitFlush).
15594
- * @returns {Promise<void>} A promise that resolves when the history flush is committed.
15595
- * @throws {Error} If session or swarm validation fails, propagated from respective validation services.
15596
- */
15597
- const commitFlushForce = beginContext(async (clientId) => {
15598
- // Log the flush attempt if enabled
15599
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15600
- swarm$1.loggerService.log(METHOD_NAME$F, {
15601
- clientId,
15602
- METHOD_NAME: METHOD_NAME$F,
15603
- });
15604
- // Validate the session exists and retrieve the associated swarm
15605
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$F);
15606
- const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15607
- // Validate the swarm configuration
15608
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$F);
15609
- // Commit the flush of agent history via SessionPublicService without agent checks
15610
- await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$F, clientId, swarmName);
16150
+ await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$y, clientId, swarmName);
15611
16151
  });
15612
16152
 
15613
- const METHOD_NAME$E = "function.commit.commitSystemMessage";
16153
+ const METHOD_NAME$x = "function.commit.commitSystemMessage";
15614
16154
  /**
15615
16155
  * Commits a user message to the active agent's history in a swarm session without triggering a response and without checking the active agent.
15616
16156
  *
@@ -15628,29 +16168,29 @@ const METHOD_NAME$E = "function.commit.commitSystemMessage";
15628
16168
  const commitUserMessageForce = beginContext(async (content, mode, clientId, payload) => {
15629
16169
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
15630
16170
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15631
- swarm$1.loggerService.log(METHOD_NAME$E, {
16171
+ swarm$1.loggerService.log(METHOD_NAME$x, {
15632
16172
  content,
15633
16173
  clientId,
15634
16174
  mode,
15635
16175
  });
15636
16176
  // Validate the session and swarm to ensure they exist and are accessible
15637
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$E);
16177
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
15638
16178
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15639
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$E);
16179
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
15640
16180
  if (payload) {
15641
16181
  return await PayloadContextService.runInContext(async () => {
15642
- await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$E, clientId, swarmName);
16182
+ await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$x, clientId, swarmName);
15643
16183
  }, {
15644
16184
  clientId,
15645
16185
  payload,
15646
16186
  });
15647
16187
  }
15648
16188
  // Commit the user message to the agent's history via the session public service without checking the active agent
15649
- return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$E, clientId, swarmName);
16189
+ return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$x, clientId, swarmName);
15650
16190
  });
15651
16191
 
15652
16192
  /** @private Constant defining the method name for logging and validation context */
15653
- const METHOD_NAME$D = "function.commit.commitAssistantMessage";
16193
+ const METHOD_NAME$w = "function.commit.commitAssistantMessage";
15654
16194
  /**
15655
16195
  * Commits an assistant-generated message to the active agent in the swarm system.
15656
16196
  * Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before committing the message.
@@ -15668,20 +16208,20 @@ const METHOD_NAME$D = "function.commit.commitAssistantMessage";
15668
16208
  const commitAssistantMessage = beginContext(async (content, clientId, agentName) => {
15669
16209
  // Log the commit attempt if enabled
15670
16210
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15671
- swarm$1.loggerService.log(METHOD_NAME$D, {
16211
+ swarm$1.loggerService.log(METHOD_NAME$w, {
15672
16212
  content,
15673
16213
  clientId,
15674
16214
  agentName,
15675
16215
  });
15676
16216
  // Validate the agent exists
15677
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$D);
16217
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$w);
15678
16218
  // Validate the session exists and retrieve the associated swarm
15679
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$D);
16219
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
15680
16220
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15681
16221
  // Validate the swarm configuration
15682
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$D);
16222
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
15683
16223
  // Check if the current agent matches the provided agent
15684
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$D, clientId, swarmName);
16224
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$w, clientId, swarmName);
15685
16225
  if (currentAgentName !== agentName) {
15686
16226
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15687
16227
  swarm$1.loggerService.log('function "commitAssistantMessage" skipped due to the agent change', {
@@ -15692,11 +16232,11 @@ const commitAssistantMessage = beginContext(async (content, clientId, agentName)
15692
16232
  return;
15693
16233
  }
15694
16234
  // Commit the assistant message via SessionPublicService
15695
- await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$D, clientId, swarmName);
16235
+ await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$w, clientId, swarmName);
15696
16236
  });
15697
16237
 
15698
16238
  /** @private Constant defining the method name for logging and validation context */
15699
- const METHOD_NAME$C = "function.commit.commitAssistantMessageForce";
16239
+ const METHOD_NAME$v = "function.commit.commitAssistantMessageForce";
15700
16240
  /**
15701
16241
  * Forcefully commits an assistant-generated message to a session in the swarm system, without checking the active agent.
15702
16242
  * Validates the session and swarm, then proceeds with committing the message regardless of the current agent state.
@@ -15715,21 +16255,21 @@ const METHOD_NAME$C = "function.commit.commitAssistantMessageForce";
15715
16255
  const commitAssistantMessageForce = beginContext(async (content, clientId) => {
15716
16256
  // Log the commit attempt if enabled
15717
16257
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15718
- swarm$1.loggerService.log(METHOD_NAME$C, {
16258
+ swarm$1.loggerService.log(METHOD_NAME$v, {
15719
16259
  content,
15720
16260
  clientId,
15721
16261
  });
15722
16262
  // Validate the session exists and retrieve the associated swarm
15723
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$C);
16263
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
15724
16264
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15725
16265
  // Validate the swarm configuration
15726
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$C);
16266
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
15727
16267
  // Commit the assistant message via SessionPublicService without agent checks
15728
- await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$C, clientId, swarmName);
16268
+ await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$v, clientId, swarmName);
15729
16269
  });
15730
16270
 
15731
16271
  /** @private Constant defining the method name for logging and validation context */
15732
- const METHOD_NAME$B = "function.commit.cancelOutput";
16272
+ const METHOD_NAME$u = "function.commit.cancelOutput";
15733
16273
  /**
15734
16274
  * Cancels the awaited output for a specific client and agent by emitting an empty string.
15735
16275
  * Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before cancellation.
@@ -15745,19 +16285,19 @@ const METHOD_NAME$B = "function.commit.cancelOutput";
15745
16285
  const cancelOutput = beginContext(async (clientId, agentName) => {
15746
16286
  // Log the cancellation attempt if enabled
15747
16287
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15748
- swarm$1.loggerService.log(METHOD_NAME$B, {
16288
+ swarm$1.loggerService.log(METHOD_NAME$u, {
15749
16289
  clientId,
15750
16290
  agentName,
15751
16291
  });
15752
16292
  // Validate the agent exists
15753
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$B);
16293
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$u);
15754
16294
  // Validate the session exists and retrieve the associated swarm
15755
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$B);
16295
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
15756
16296
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15757
16297
  // Validate the swarm configuration
15758
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$B);
16298
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
15759
16299
  // Check if the current agent matches the provided agent
15760
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$B, clientId, swarmName);
16300
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$u, clientId, swarmName);
15761
16301
  if (currentAgentName !== agentName) {
15762
16302
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15763
16303
  swarm$1.loggerService.log('function "cancelOutput" skipped due to the agent change', {
@@ -15768,11 +16308,11 @@ const cancelOutput = beginContext(async (clientId, agentName) => {
15768
16308
  return;
15769
16309
  }
15770
16310
  // Perform the output cancellation via SwarmPublicService
15771
- await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$B, clientId, swarmName);
16311
+ await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$u, clientId, swarmName);
15772
16312
  });
15773
16313
 
15774
16314
  /** @private Constant defining the method name for logging and validation context */
15775
- const METHOD_NAME$A = "function.commit.cancelOutputForce";
16315
+ const METHOD_NAME$t = "function.commit.cancelOutputForce";
15776
16316
  /**
15777
16317
  * Forcefully cancels the awaited output for a specific client by emitting an empty string, without checking the active agent.
15778
16318
  * Validates the session and swarm, then proceeds with cancellation regardless of the current agent state.
@@ -15789,20 +16329,20 @@ const METHOD_NAME$A = "function.commit.cancelOutputForce";
15789
16329
  const cancelOutputForce = beginContext(async (clientId) => {
15790
16330
  // Log the cancellation attempt if enabled
15791
16331
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15792
- swarm$1.loggerService.log(METHOD_NAME$A, {
16332
+ swarm$1.loggerService.log(METHOD_NAME$t, {
15793
16333
  clientId,
15794
16334
  });
15795
16335
  // Validate the session exists and retrieve the associated swarm
15796
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$A);
16336
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
15797
16337
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15798
16338
  // Validate the swarm configuration
15799
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$A);
16339
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
15800
16340
  // Perform the output cancellation via SwarmPublicService without agent checks
15801
- await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$A, clientId, swarmName);
16341
+ await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$t, clientId, swarmName);
15802
16342
  });
15803
16343
 
15804
16344
  /** @private Constant defining the method name for logging and validation context */
15805
- const METHOD_NAME$z = "function.commit.commitStopTools";
16345
+ const METHOD_NAME$s = "function.commit.commitStopTools";
15806
16346
  /**
15807
16347
  * Prevents the next tool from being executed for a specific client and agent in the swarm system.
15808
16348
  * Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before stopping tool execution.
@@ -15819,19 +16359,19 @@ const METHOD_NAME$z = "function.commit.commitStopTools";
15819
16359
  const commitStopTools = beginContext(async (clientId, agentName) => {
15820
16360
  // Log the stop tools attempt if enabled
15821
16361
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15822
- swarm$1.loggerService.log(METHOD_NAME$z, {
16362
+ swarm$1.loggerService.log(METHOD_NAME$s, {
15823
16363
  clientId,
15824
16364
  agentName,
15825
16365
  });
15826
16366
  // Validate the agent exists
15827
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$z);
16367
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$s);
15828
16368
  // Validate the session exists and retrieve the associated swarm
15829
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
16369
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
15830
16370
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15831
16371
  // Validate the swarm configuration
15832
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
16372
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$s);
15833
16373
  // Check if the current agent matches the provided agent
15834
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$z, clientId, swarmName);
16374
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$s, clientId, swarmName);
15835
16375
  if (currentAgentName !== agentName) {
15836
16376
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15837
16377
  swarm$1.loggerService.log('function "commitStopTools" skipped due to the agent change', {
@@ -15842,11 +16382,11 @@ const commitStopTools = beginContext(async (clientId, agentName) => {
15842
16382
  return;
15843
16383
  }
15844
16384
  // Commit the stop of the next tool execution via SessionPublicService
15845
- await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$z, clientId, swarmName);
16385
+ await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$s, clientId, swarmName);
15846
16386
  });
15847
16387
 
15848
16388
  /** @private Constant defining the method name for logging and validation context */
15849
- const METHOD_NAME$y = "function.commit.commitStopToolsForce";
16389
+ const METHOD_NAME$r = "function.commit.commitStopToolsForce";
15850
16390
  /**
15851
16391
  * Forcefully prevents the next tool from being executed for a specific client in the swarm system, without checking the active agent.
15852
16392
  * Validates the session and swarm, then proceeds with stopping tool execution regardless of the current agent state.
@@ -15864,105 +16404,21 @@ const METHOD_NAME$y = "function.commit.commitStopToolsForce";
15864
16404
  const commitStopToolsForce = beginContext(async (clientId) => {
15865
16405
  // Log the stop tools attempt if enabled
15866
16406
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15867
- swarm$1.loggerService.log(METHOD_NAME$y, {
16407
+ swarm$1.loggerService.log(METHOD_NAME$r, {
15868
16408
  clientId,
15869
- METHOD_NAME: METHOD_NAME$y,
16409
+ METHOD_NAME: METHOD_NAME$r,
15870
16410
  });
15871
16411
  // Validate the session exists and retrieve the associated swarm
15872
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
16412
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
15873
16413
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15874
16414
  // Validate the swarm configuration
15875
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
16415
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
15876
16416
  // Commit the stop of the next tool execution via SessionPublicService without agent checks
15877
- await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$y, clientId, swarmName);
15878
- });
15879
-
15880
- const METHOD_NAME$x = "function.target.emitForce";
15881
- /**
15882
- * Emits a string as model output without executing an incoming message or checking the active agent.
15883
- *
15884
- * This function directly emits a provided string as output from the swarm session, bypassing message execution and agent activity checks.
15885
- * It is designed exclusively for sessions established via `makeConnection`, ensuring compatibility with its connection model.
15886
- * The execution is wrapped in `beginContext` for a clean environment, validates the session and swarm, and throws an error if the session mode
15887
- * is not "makeConnection". The operation is logged if enabled, and resolves when the content is successfully emitted.
15888
- *
15889
- * @param {string} content - The content to be emitted as the model output.
15890
- * @param {string} clientId - The unique identifier of the client session emitting the content.
15891
- * @returns {Promise<void>} A promise that resolves when the content is emitted.
15892
- * @throws {Error} If the session mode is not "makeConnection", or if session or swarm validation fails.
15893
- * @example
15894
- * await emitForce("Direct output", "client-123"); // Emits "Direct output" in a makeConnection session
15895
- */
15896
- const emitForce = beginContext(async (content, clientId) => {
15897
- // Log the operation details if logging is enabled in GLOBAL_CONFIG
15898
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15899
- swarm$1.loggerService.log(METHOD_NAME$x, {
15900
- content,
15901
- clientId,
15902
- });
15903
- // Validate the session and swarm
15904
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
15905
- const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15906
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
15907
- // Emit the content directly via the session public service
15908
- return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$x, clientId, swarmName);
15909
- });
15910
-
15911
- const METHOD_NAME$w = "function.target.executeForce";
15912
- /**
15913
- * Sends a message to the active agent in a swarm session as if it originated from the client side, forcing execution regardless of agent activity.
15914
- *
15915
- * This function executes a command or message on behalf of the active agent within a swarm session, designed for scenarios like reviewing tool output
15916
- * or initiating a model-to-client conversation. Unlike `execute`, it does not check if the agent is currently active, ensuring execution even if the
15917
- * agent has changed or is inactive. It validates the session and swarm, executes the content with performance tracking and event bus notifications,
15918
- * and is wrapped in `beginContext` for a clean environment and `ExecutionContextService` for metadata tracking.
15919
- *
15920
- * @param {string} content - The content or command to be executed by the active agent.
15921
- * @param {string} clientId - The unique identifier of the client session requesting the execution.
15922
- * @returns {Promise<string>} A promise that resolves to the result of the execution.
15923
- * @throws {Error} If session or swarm validation fails, or if the execution process encounters an error.
15924
- * @example
15925
- * const result = await executeForce("Force this execution", "client-123");
15926
- * console.log(result); // Outputs the agent's response regardless of its active state
15927
- */
15928
- const executeForce = beginContext(async (content, clientId) => {
15929
- const executionId = functoolsKit.randomString();
15930
- // Log the operation details if logging is enabled in GLOBAL_CONFIG
15931
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15932
- swarm$1.loggerService.log(METHOD_NAME$w, {
15933
- content,
15934
- clientId,
15935
- executionId,
15936
- });
15937
- // Validate the session and swarm
15938
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
15939
- const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15940
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
15941
- // Execute the command within an execution context with performance tracking
15942
- return ExecutionContextService.runInContext(async () => {
15943
- let isFinished = false;
15944
- swarm$1.perfService.startExecution(executionId, clientId, content.length);
15945
- try {
15946
- swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
15947
- const result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$w, clientId, swarmName);
15948
- isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
15949
- swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
15950
- return result;
15951
- }
15952
- finally {
15953
- if (!isFinished) {
15954
- swarm$1.perfService.endExecution(executionId, clientId, 0);
15955
- }
15956
- }
15957
- }, {
15958
- clientId,
15959
- executionId,
15960
- processId: GLOBAL_CONFIG.CC_PROCESS_UUID,
15961
- });
16417
+ await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$r, clientId, swarmName);
15962
16418
  });
15963
16419
 
15964
16420
  /** @constant {string} METHOD_NAME - The name of the method used for logging and validation */
15965
- const METHOD_NAME$v = "function.target.question";
16421
+ const METHOD_NAME$q = "function.target.question";
15966
16422
  /**
15967
16423
  * Initiates a question process within a chat context
15968
16424
  * @function question
@@ -15974,21 +16430,21 @@ const METHOD_NAME$v = "function.target.question";
15974
16430
  */
15975
16431
  const question = beginContext(async (message, clientId, agentName, wikiName) => {
15976
16432
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15977
- swarm$1.loggerService.log(METHOD_NAME$v, {
16433
+ swarm$1.loggerService.log(METHOD_NAME$q, {
15978
16434
  message,
15979
16435
  clientId,
15980
16436
  agentName,
15981
16437
  wikiName,
15982
16438
  });
15983
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
15984
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$v);
16439
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
16440
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$q);
15985
16441
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
15986
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
15987
- swarm$1.wikiValidationService.validate(wikiName, METHOD_NAME$v);
16442
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
16443
+ swarm$1.wikiValidationService.validate(wikiName, METHOD_NAME$q);
15988
16444
  if (!swarm$1.agentValidationService.hasWiki(agentName, wikiName)) {
15989
- throw new Error(`agent-swarm ${METHOD_NAME$v} ${wikiName} not registered in ${agentName}`);
16445
+ throw new Error(`agent-swarm ${METHOD_NAME$q} ${wikiName} not registered in ${agentName}`);
15990
16446
  }
15991
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$v, clientId, swarmName);
16447
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$q, clientId, swarmName);
15992
16448
  if (currentAgentName !== agentName) {
15993
16449
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15994
16450
  swarm$1.loggerService.log('function "question" skipped due to the agent change', {
@@ -16011,7 +16467,7 @@ const question = beginContext(async (message, clientId, agentName, wikiName) =>
16011
16467
  });
16012
16468
 
16013
16469
  /** @constant {string} METHOD_NAME - The name of the method used for logging and validation */
16014
- const METHOD_NAME$u = "function.target.questionForce";
16470
+ const METHOD_NAME$p = "function.target.questionForce";
16015
16471
  /**
16016
16472
  * Initiates a forced question process within a chat context
16017
16473
  * @function questionForce
@@ -16022,17 +16478,17 @@ const METHOD_NAME$u = "function.target.questionForce";
16022
16478
  */
16023
16479
  const questionForce = beginContext(async (message, clientId, wikiName) => {
16024
16480
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16025
- swarm$1.loggerService.log(METHOD_NAME$u, {
16481
+ swarm$1.loggerService.log(METHOD_NAME$p, {
16026
16482
  message,
16027
16483
  clientId,
16028
16484
  wikiName,
16029
16485
  });
16030
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
16486
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$p);
16031
16487
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
16032
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
16033
- swarm$1.wikiValidationService.validate(wikiName, METHOD_NAME$u);
16488
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$p);
16489
+ swarm$1.wikiValidationService.validate(wikiName, METHOD_NAME$p);
16034
16490
  const { getChat, callbacks } = swarm$1.wikiSchemaService.get(wikiName);
16035
- const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$u, clientId, swarmName);
16491
+ const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$p, clientId, swarmName);
16036
16492
  const args = {
16037
16493
  clientId,
16038
16494
  message,
@@ -16044,7 +16500,7 @@ const questionForce = beginContext(async (message, clientId, wikiName) => {
16044
16500
  return await getChat(args);
16045
16501
  });
16046
16502
 
16047
- const METHOD_NAME$t = "function.target.disposeConnection";
16503
+ const METHOD_NAME$o = "function.target.disposeConnection";
16048
16504
  /**
16049
16505
  * Disposes of a client session and all related resources within a swarm.
16050
16506
  *
@@ -16061,10 +16517,10 @@ const METHOD_NAME$t = "function.target.disposeConnection";
16061
16517
  * @example
16062
16518
  * await disposeConnection("client-123", "TaskSwarm");
16063
16519
  */
16064
- const disposeConnection = beginContext(async (clientId, swarmName, methodName = METHOD_NAME$t) => {
16520
+ const disposeConnection = beginContext(async (clientId, swarmName, methodName = METHOD_NAME$o) => {
16065
16521
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16066
16522
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16067
- swarm$1.loggerService.log(METHOD_NAME$t, {
16523
+ swarm$1.loggerService.log(METHOD_NAME$o, {
16068
16524
  clientId,
16069
16525
  swarmName,
16070
16526
  });
@@ -16136,7 +16592,7 @@ const disposeConnection = beginContext(async (clientId, swarmName, methodName =
16136
16592
  PersistMemoryAdapter.dispose(clientId);
16137
16593
  });
16138
16594
 
16139
- const METHOD_NAME$s = "function.target.makeAutoDispose";
16595
+ const METHOD_NAME$n = "function.target.makeAutoDispose";
16140
16596
  /**
16141
16597
  * Default timeout in seconds before auto-dispose is triggered.
16142
16598
  * @constant {number}
@@ -16167,7 +16623,7 @@ const DEFAULT_TIMEOUT = 15 * 60;
16167
16623
  const makeAutoDispose = beginContext((clientId, swarmName, { timeoutSeconds = DEFAULT_TIMEOUT, onDestroy, } = {}) => {
16168
16624
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16169
16625
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16170
- swarm$1.loggerService.log(METHOD_NAME$s, {
16626
+ swarm$1.loggerService.log(METHOD_NAME$n, {
16171
16627
  clientId,
16172
16628
  swarmName,
16173
16629
  });
@@ -16200,7 +16656,7 @@ const makeAutoDispose = beginContext((clientId, swarmName, { timeoutSeconds = DE
16200
16656
  };
16201
16657
  });
16202
16658
 
16203
- const METHOD_NAME$r = "function.target.execute";
16659
+ const METHOD_NAME$m = "function.target.execute";
16204
16660
  /**
16205
16661
  * Sends a message to the active agent in a swarm session as if it originated from the client side.
16206
16662
  *
@@ -16222,19 +16678,19 @@ const execute = beginContext(async (content, clientId, agentName) => {
16222
16678
  const executionId = functoolsKit.randomString();
16223
16679
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16224
16680
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16225
- swarm$1.loggerService.log(METHOD_NAME$r, {
16681
+ swarm$1.loggerService.log(METHOD_NAME$m, {
16226
16682
  content,
16227
16683
  clientId,
16228
16684
  agentName,
16229
16685
  executionId,
16230
16686
  });
16231
16687
  // Validate the agent, session, and swarm
16232
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$r);
16233
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
16688
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$m);
16689
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$m);
16234
16690
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
16235
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
16691
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$m);
16236
16692
  // Check if the specified agent is still the active agent
16237
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$r, clientId, swarmName);
16693
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$m, clientId, swarmName);
16238
16694
  if (currentAgentName !== agentName) {
16239
16695
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16240
16696
  swarm$1.loggerService.log('function "execute" skipped due to the agent change', {
@@ -16253,7 +16709,7 @@ const execute = beginContext(async (content, clientId, agentName) => {
16253
16709
  agentName,
16254
16710
  swarmName,
16255
16711
  });
16256
- const result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$r, clientId, swarmName);
16712
+ const result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$m, clientId, swarmName);
16257
16713
  isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
16258
16714
  swarm$1.busService.commitExecutionEnd(clientId, {
16259
16715
  agentName,
@@ -16273,7 +16729,7 @@ const execute = beginContext(async (content, clientId, agentName) => {
16273
16729
  });
16274
16730
  });
16275
16731
 
16276
- const METHOD_NAME$q = "function.target.emit";
16732
+ const METHOD_NAME$l = "function.target.emit";
16277
16733
  /**
16278
16734
  * Emits a string as model output without executing an incoming message, with agent activity validation.
16279
16735
  *
@@ -16293,18 +16749,18 @@ const METHOD_NAME$q = "function.target.emit";
16293
16749
  const emit = beginContext(async (content, clientId, agentName) => {
16294
16750
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16295
16751
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16296
- swarm$1.loggerService.log(METHOD_NAME$q, {
16752
+ swarm$1.loggerService.log(METHOD_NAME$l, {
16297
16753
  content,
16298
16754
  clientId,
16299
16755
  agentName,
16300
16756
  });
16301
16757
  // Validate the agent, session, and swarm
16302
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$q);
16303
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
16758
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$l);
16759
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$l);
16304
16760
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
16305
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
16761
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$l);
16306
16762
  // Check if the specified agent is still the active agent
16307
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$q, clientId, swarmName);
16763
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$l, clientId, swarmName);
16308
16764
  if (currentAgentName !== agentName) {
16309
16765
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16310
16766
  swarm$1.loggerService.log('function "emit" skipped due to the agent change', {
@@ -16315,10 +16771,10 @@ const emit = beginContext(async (content, clientId, agentName) => {
16315
16771
  return;
16316
16772
  }
16317
16773
  // Emit the content directly via the session public service
16318
- return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$q, clientId, swarmName);
16774
+ return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$l, clientId, swarmName);
16319
16775
  });
16320
16776
 
16321
- const METHOD_NAME$p = "function.target.notify";
16777
+ const METHOD_NAME$k = "function.target.notify";
16322
16778
  /**
16323
16779
  * Sends a notification message as output from the swarm session without executing an incoming message.
16324
16780
  *
@@ -16338,23 +16794,23 @@ const METHOD_NAME$p = "function.target.notify";
16338
16794
  const notify = beginContext(async (content, clientId, agentName) => {
16339
16795
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16340
16796
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16341
- swarm$1.loggerService.log(METHOD_NAME$p, {
16797
+ swarm$1.loggerService.log(METHOD_NAME$k, {
16342
16798
  content,
16343
16799
  clientId,
16344
16800
  agentName,
16345
16801
  });
16346
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$p);
16802
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$k);
16347
16803
  // Check if the session mode is "makeConnection"
16348
16804
  if (swarm$1.sessionValidationService.getSessionMode(clientId) !==
16349
16805
  "makeConnection") {
16350
16806
  throw new Error(`agent-swarm-kit notify session is not makeConnection clientId=${clientId}`);
16351
16807
  }
16352
16808
  // Validate the agent, session, and swarm
16353
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$p);
16809
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$k);
16354
16810
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
16355
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$p);
16811
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$k);
16356
16812
  // Check if the specified agent is still the active agent
16357
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$p, clientId, swarmName);
16813
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$k, clientId, swarmName);
16358
16814
  if (currentAgentName !== agentName) {
16359
16815
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16360
16816
  swarm$1.loggerService.log('function "notify" skipped due to the agent change', {
@@ -16365,10 +16821,10 @@ const notify = beginContext(async (content, clientId, agentName) => {
16365
16821
  return;
16366
16822
  }
16367
16823
  // Notify the content directly via the session public service
16368
- return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$p, clientId, swarmName);
16824
+ return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$k, clientId, swarmName);
16369
16825
  });
16370
16826
 
16371
- const METHOD_NAME$o = "function.target.notifyForce";
16827
+ const METHOD_NAME$j = "function.target.notifyForce";
16372
16828
  /**
16373
16829
  * Sends a notification message as output from the swarm session without executing an incoming message.
16374
16830
  *
@@ -16387,11 +16843,11 @@ const METHOD_NAME$o = "function.target.notifyForce";
16387
16843
  const notifyForce = beginContext(async (content, clientId) => {
16388
16844
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16389
16845
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16390
- swarm$1.loggerService.log(METHOD_NAME$o, {
16846
+ swarm$1.loggerService.log(METHOD_NAME$j, {
16391
16847
  content,
16392
16848
  clientId,
16393
16849
  });
16394
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$o);
16850
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$j);
16395
16851
  // Check if the session mode is "makeConnection"
16396
16852
  if (swarm$1.sessionValidationService.getSessionMode(clientId) !==
16397
16853
  "makeConnection") {
@@ -16399,12 +16855,12 @@ const notifyForce = beginContext(async (content, clientId) => {
16399
16855
  }
16400
16856
  // Validate the agent, session, and swarm
16401
16857
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
16402
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$o);
16858
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$j);
16403
16859
  // Notify the content directly via the session public service
16404
- return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$o, clientId, swarmName);
16860
+ return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$j, clientId, swarmName);
16405
16861
  });
16406
16862
 
16407
- const METHOD_NAME$n = "function.target.runStateless";
16863
+ const METHOD_NAME$i = "function.target.runStateless";
16408
16864
  /**
16409
16865
  * Executes a message statelessly with an agent in a swarm session, bypassing chat history.
16410
16866
  *
@@ -16427,19 +16883,19 @@ const runStateless = beginContext(async (content, clientId, agentName) => {
16427
16883
  const executionId = functoolsKit.randomString();
16428
16884
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16429
16885
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16430
- swarm$1.loggerService.log(METHOD_NAME$n, {
16886
+ swarm$1.loggerService.log(METHOD_NAME$i, {
16431
16887
  content,
16432
16888
  clientId,
16433
16889
  agentName,
16434
16890
  executionId,
16435
16891
  });
16436
16892
  // Validate the agent, session, and swarm
16437
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$n);
16438
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$n);
16893
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$i);
16894
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$i);
16439
16895
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
16440
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$n);
16896
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$i);
16441
16897
  // Check if the specified agent is still the active agent
16442
- const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$n, clientId, swarmName);
16898
+ const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$i, clientId, swarmName);
16443
16899
  if (currentAgentName !== agentName) {
16444
16900
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16445
16901
  swarm$1.loggerService.log('function "runStateless" skipped due to the agent change', {
@@ -16458,7 +16914,7 @@ const runStateless = beginContext(async (content, clientId, agentName) => {
16458
16914
  agentName,
16459
16915
  swarmName,
16460
16916
  });
16461
- const result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$n, clientId, swarmName);
16917
+ const result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$i, clientId, swarmName);
16462
16918
  isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
16463
16919
  swarm$1.busService.commitExecutionEnd(clientId, {
16464
16920
  agentName,
@@ -16478,7 +16934,7 @@ const runStateless = beginContext(async (content, clientId, agentName) => {
16478
16934
  });
16479
16935
  });
16480
16936
 
16481
- const METHOD_NAME$m = "function.target.runStatelessForce";
16937
+ const METHOD_NAME$h = "function.target.runStatelessForce";
16482
16938
  /**
16483
16939
  * Executes a message statelessly with the active agent in a swarm session, bypassing chat history and forcing execution regardless of agent activity.
16484
16940
  *
@@ -16499,22 +16955,22 @@ const runStatelessForce = beginContext(async (content, clientId) => {
16499
16955
  const executionId = functoolsKit.randomString();
16500
16956
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16501
16957
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16502
- swarm$1.loggerService.log(METHOD_NAME$m, {
16958
+ swarm$1.loggerService.log(METHOD_NAME$h, {
16503
16959
  content,
16504
16960
  clientId,
16505
16961
  executionId,
16506
16962
  });
16507
16963
  // Validate the session and swarm
16508
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$m);
16964
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$h);
16509
16965
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
16510
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$m);
16966
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$h);
16511
16967
  // Execute the command statelessly within an execution context with performance tracking
16512
16968
  return ExecutionContextService.runInContext(async () => {
16513
16969
  let isFinished = false;
16514
16970
  swarm$1.perfService.startExecution(executionId, clientId, content.length);
16515
16971
  try {
16516
16972
  swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
16517
- const result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$m, clientId, swarmName);
16973
+ const result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$h, clientId, swarmName);
16518
16974
  isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
16519
16975
  swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
16520
16976
  return result;
@@ -16541,7 +16997,7 @@ const SCHEDULED_DELAY$1 = 1000;
16541
16997
  * @constant {number}
16542
16998
  */
16543
16999
  const RATE_DELAY = 10000;
16544
- const METHOD_NAME$l = "function.target.makeConnection";
17000
+ const METHOD_NAME$g = "function.target.makeConnection";
16545
17001
  /**
16546
17002
  * Internal implementation of the connection factory for a client to a swarm.
16547
17003
  *
@@ -16556,21 +17012,21 @@ const METHOD_NAME$l = "function.target.makeConnection";
16556
17012
  const makeConnectionInternal = (connector, clientId, swarmName) => {
16557
17013
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16558
17014
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16559
- swarm$1.loggerService.log(METHOD_NAME$l, {
17015
+ swarm$1.loggerService.log(METHOD_NAME$g, {
16560
17016
  clientId,
16561
17017
  swarmName,
16562
17018
  });
16563
17019
  // Validate the swarm and initialize the session
16564
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$l);
17020
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$g);
16565
17021
  swarm$1.sessionValidationService.addSession(clientId, swarmName, "makeConnection");
16566
17022
  // Create a queued send function using the session public service
16567
- const send = functoolsKit.queued(swarm$1.sessionPublicService.connect(connector, METHOD_NAME$l, clientId, swarmName));
17023
+ const send = functoolsKit.queued(swarm$1.sessionPublicService.connect(connector, METHOD_NAME$g, clientId, swarmName));
16568
17024
  // Return a wrapped send function with validation and agent context
16569
17025
  return (async (outgoing) => {
16570
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$l);
17026
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$g);
16571
17027
  return await send({
16572
17028
  data: outgoing,
16573
- agentName: await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$l, clientId, swarmName),
17029
+ agentName: await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$g, clientId, swarmName),
16574
17030
  clientId,
16575
17031
  });
16576
17032
  });
@@ -16653,13 +17109,13 @@ makeConnection.scheduled = (connector, clientId, swarmName, { delay = SCHEDULED_
16653
17109
  await online();
16654
17110
  if (payload) {
16655
17111
  return await PayloadContextService.runInContext(async () => {
16656
- await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$l, clientId, swarmName);
17112
+ await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$g, clientId, swarmName);
16657
17113
  }, {
16658
17114
  clientId,
16659
17115
  payload,
16660
17116
  });
16661
17117
  }
16662
- await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$l, clientId, swarmName);
17118
+ await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$g, clientId, swarmName);
16663
17119
  }),
16664
17120
  delay,
16665
17121
  });
@@ -16722,7 +17178,7 @@ makeConnection.rate = (connector, clientId, swarmName, { delay = RATE_DELAY } =
16722
17178
  };
16723
17179
  };
16724
17180
 
16725
- const METHOD_NAME$k = "function.target.complete";
17181
+ const METHOD_NAME$f = "function.target.complete";
16726
17182
  /**
16727
17183
  * Time-to-live for the complete function in milliseconds.
16728
17184
  * Defines how long the cached complete function remains valid before expiring.
@@ -16764,7 +17220,7 @@ const createComplete = functoolsKit.ttl((clientId, swarmName) => functoolsKit.qu
16764
17220
  *
16765
17221
  * @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
16766
17222
  */
16767
- const createGc$3 = functoolsKit.singleshot(async () => {
17223
+ const createGc$1 = functoolsKit.singleshot(async () => {
16768
17224
  setInterval(createComplete.gc, COMPLETE_GC);
16769
17225
  });
16770
17226
  /**
@@ -16788,7 +17244,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
16788
17244
  const executionId = functoolsKit.randomString();
16789
17245
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16790
17246
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16791
- swarm$1.loggerService.log(METHOD_NAME$k, {
17247
+ swarm$1.loggerService.log(METHOD_NAME$f, {
16792
17248
  content,
16793
17249
  clientId,
16794
17250
  executionId,
@@ -16797,7 +17253,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
16797
17253
  await markOnline(clientId, swarmName);
16798
17254
  // Set up the TTL-limited, queued execution function and garbage collector
16799
17255
  const run = await createComplete(clientId, swarmName);
16800
- createGc$3();
17256
+ createGc$1();
16801
17257
  // Execute the command within an execution context with performance tracking
16802
17258
  const handleRun = async () => {
16803
17259
  return await ExecutionContextService.runInContext(async () => {
@@ -16806,7 +17262,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
16806
17262
  swarm$1.navigationValidationService.beginMonit(clientId, swarmName);
16807
17263
  try {
16808
17264
  swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
16809
- const result = await run(METHOD_NAME$k, content);
17265
+ const result = await run(METHOD_NAME$f, content);
16810
17266
  isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
16811
17267
  swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
16812
17268
  return result;
@@ -16836,7 +17292,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
16836
17292
  * @constant {number}
16837
17293
  */
16838
17294
  const SCHEDULED_DELAY = 1000;
16839
- const METHOD_NAME$j = "function.target.session";
17295
+ const METHOD_NAME$e = "function.target.session";
16840
17296
  /**
16841
17297
  * Internal implementation of the session factory for a client and swarm.
16842
17298
  *
@@ -16851,23 +17307,23 @@ const sessionInternal = (clientId, swarmName, { onDispose = () => { } } = {}) =>
16851
17307
  const executionId = functoolsKit.randomString();
16852
17308
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
16853
17309
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16854
- swarm$1.loggerService.log(METHOD_NAME$j, {
17310
+ swarm$1.loggerService.log(METHOD_NAME$e, {
16855
17311
  clientId,
16856
17312
  swarmName,
16857
17313
  executionId,
16858
17314
  });
16859
17315
  // Validate the swarm and initialize the session
16860
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$j);
17316
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$e);
16861
17317
  swarm$1.sessionValidationService.addSession(clientId, swarmName, "session");
16862
17318
  const complete = functoolsKit.queued(async (content) => {
16863
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$j);
17319
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$e);
16864
17320
  return ExecutionContextService.runInContext(async () => {
16865
17321
  let isFinished = false;
16866
17322
  swarm$1.perfService.startExecution(executionId, clientId, content.length);
16867
17323
  swarm$1.navigationValidationService.beginMonit(clientId, swarmName);
16868
17324
  try {
16869
17325
  swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
16870
- const result = await swarm$1.sessionPublicService.execute(content, "user", METHOD_NAME$j, clientId, swarmName);
17326
+ const result = await swarm$1.sessionPublicService.execute(content, "user", METHOD_NAME$e, clientId, swarmName);
16871
17327
  isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
16872
17328
  swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
16873
17329
  return result;
@@ -16888,7 +17344,7 @@ const sessionInternal = (clientId, swarmName, { onDispose = () => { } } = {}) =>
16888
17344
  return await complete(content);
16889
17345
  }),
16890
17346
  dispose: async () => {
16891
- await disposeConnection(clientId, swarmName, METHOD_NAME$j);
17347
+ await disposeConnection(clientId, swarmName, METHOD_NAME$e);
16892
17348
  await onDispose();
16893
17349
  },
16894
17350
  };
@@ -16988,13 +17444,13 @@ session.scheduled = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose }
16988
17444
  await online();
16989
17445
  if (payload) {
16990
17446
  return await PayloadContextService.runInContext(async () => {
16991
- return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$j, clientId, swarmName);
17447
+ return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$e, clientId, swarmName);
16992
17448
  }, {
16993
17449
  clientId,
16994
17450
  payload,
16995
17451
  });
16996
17452
  }
16997
- return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$j, clientId, swarmName);
17453
+ return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$e, clientId, swarmName);
16998
17454
  }),
16999
17455
  delay,
17000
17456
  });
@@ -17074,7 +17530,7 @@ session.rate = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose } = {}
17074
17530
  };
17075
17531
 
17076
17532
  /** @private Constant defining the method name for logging purposes */
17077
- const METHOD_NAME$i = "function.common.hasSession";
17533
+ const METHOD_NAME$d = "function.common.hasSession";
17078
17534
  /**
17079
17535
  * Checks if a session exists for the given client ID.
17080
17536
  *
@@ -17086,35 +17542,11 @@ const METHOD_NAME$i = "function.common.hasSession";
17086
17542
  */
17087
17543
  const hasSession = (clientId) => {
17088
17544
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17089
- swarm$1.loggerService.log(METHOD_NAME$i, { clientId });
17545
+ swarm$1.loggerService.log(METHOD_NAME$d, { clientId });
17090
17546
  return swarm$1.sessionValidationService.hasSession(clientId);
17091
17547
  };
17092
17548
 
17093
- /**
17094
- * @private Constant defining the method name for logging and validation purposes.
17095
- * Used as an identifier in log messages and validation checks to track calls to `hasNavigation`.
17096
- */
17097
- const METHOD_NAME$h = "function.common.hasNavigation";
17098
- /**
17099
- * Checks if a specific agent is part of the navigation route for a given client.
17100
- * Validates the agent and client session, retrieves the associated swarm, and queries the navigation route.
17101
- * Logs the operation if enabled by global configuration.
17102
- * @param {string} clientId - The unique identifier of the client whose navigation route is being checked.
17103
- * @param {AgentName} agentName - The name of the agent to check within the navigation route.
17104
- * @returns {Promise<boolean>} A promise resolving to true if the agent is in the navigation route, false otherwise.
17105
- */
17106
- const hasNavigation = async (clientId, agentName) => {
17107
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17108
- swarm$1.loggerService.log(METHOD_NAME$h, { clientId });
17109
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$h);
17110
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$h);
17111
- const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
17112
- return swarm$1.navigationValidationService
17113
- .getNavigationRoute(clientId, swarmName)
17114
- .has(agentName);
17115
- };
17116
-
17117
- const METHOD_NAME$g = "function.common.getAgentName";
17549
+ const METHOD_NAME$c = "function.common.getAgentName";
17118
17550
  /**
17119
17551
  * Retrieves the name of the active agent for a given client session in a swarm.
17120
17552
  *
@@ -17132,18 +17564,18 @@ const METHOD_NAME$g = "function.common.getAgentName";
17132
17564
  const getAgentName = beginContext(async (clientId) => {
17133
17565
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17134
17566
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17135
- swarm$1.loggerService.log(METHOD_NAME$g, {
17567
+ swarm$1.loggerService.log(METHOD_NAME$c, {
17136
17568
  clientId,
17137
17569
  });
17138
17570
  // Validate the session and swarm to ensure they exist and are accessible
17139
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$g);
17571
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$c);
17140
17572
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
17141
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$g);
17573
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$c);
17142
17574
  // Retrieve the active agent name via the swarm public service
17143
- return await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$g, clientId, swarmName);
17575
+ return await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$c, clientId, swarmName);
17144
17576
  });
17145
17577
 
17146
- const METHOD_NAME$f = "function.common.getAgentHistory";
17578
+ const METHOD_NAME$b = "function.common.getAgentHistory";
17147
17579
  /**
17148
17580
  * Retrieves the history prepared for a specific agent, incorporating rescue algorithm tweaks.
17149
17581
  *
@@ -17162,22 +17594,22 @@ const METHOD_NAME$f = "function.common.getAgentHistory";
17162
17594
  const getAgentHistory = beginContext(async (clientId, agentName) => {
17163
17595
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17164
17596
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17165
- swarm$1.loggerService.log(METHOD_NAME$f, {
17597
+ swarm$1.loggerService.log(METHOD_NAME$b, {
17166
17598
  clientId,
17167
17599
  agentName,
17168
17600
  });
17169
17601
  // Validate the session and agent to ensure they exist and are accessible
17170
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$f);
17171
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$f);
17602
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$b);
17603
+ swarm$1.agentValidationService.validate(agentName, METHOD_NAME$b);
17172
17604
  // Retrieve the agent's prompt configuration from the agent schema service
17173
17605
  const { prompt } = swarm$1.agentSchemaService.get(agentName);
17174
17606
  // Fetch the agent's history using the prompt and rescue tweaks via the history public service
17175
- const history = await swarm$1.historyPublicService.toArrayForAgent(prompt, METHOD_NAME$f, clientId, agentName);
17607
+ const history = await swarm$1.historyPublicService.toArrayForAgent(prompt, METHOD_NAME$b, clientId, agentName);
17176
17608
  // Return a shallow copy of the history array
17177
17609
  return [...history];
17178
17610
  });
17179
17611
 
17180
- const METHOD_NAME$e = "function.common.getSessionMode";
17612
+ const METHOD_NAME$a = "function.common.getSessionMode";
17181
17613
  /**
17182
17614
  * Retrieves the session mode for a given client session in a swarm.
17183
17615
  *
@@ -17195,18 +17627,18 @@ const METHOD_NAME$e = "function.common.getSessionMode";
17195
17627
  const getSessionMode = beginContext(async (clientId) => {
17196
17628
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17197
17629
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17198
- swarm$1.loggerService.log(METHOD_NAME$e, {
17630
+ swarm$1.loggerService.log(METHOD_NAME$a, {
17199
17631
  clientId,
17200
17632
  });
17201
17633
  // Validate the session and swarm to ensure they exist and are accessible
17202
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$e);
17634
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$a);
17203
17635
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
17204
- swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$e);
17636
+ swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$a);
17205
17637
  // Retrieve the session mode from the session validation service
17206
17638
  return swarm$1.sessionValidationService.getSessionMode(clientId);
17207
17639
  });
17208
17640
 
17209
- const METHOD_NAME$d = "function.common.getSessionContext";
17641
+ const METHOD_NAME$9 = "function.common.getSessionContext";
17210
17642
  /**
17211
17643
  * Retrieves the session context for the current execution environment.
17212
17644
  *
@@ -17223,7 +17655,7 @@ const METHOD_NAME$d = "function.common.getSessionContext";
17223
17655
  const getSessionContext = async () => {
17224
17656
  // Log the operation if logging is enabled in GLOBAL_CONFIG
17225
17657
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17226
- swarm$1.loggerService.log(METHOD_NAME$d);
17658
+ swarm$1.loggerService.log(METHOD_NAME$9);
17227
17659
  // Determine the method context, if active
17228
17660
  const methodContext = MethodContextService.hasContext()
17229
17661
  ? swarm$1.methodContextService.context
@@ -17234,99 +17666,39 @@ const getSessionContext = async () => {
17234
17666
  : null;
17235
17667
  // Derive the client ID from either the method or execution context, if available
17236
17668
  const clientId = methodContext?.clientId ?? executionContext?.clientId;
17237
- // Return the constructed session context
17238
- return {
17239
- clientId,
17240
- processId: GLOBAL_CONFIG.CC_PROCESS_UUID,
17241
- methodContext,
17242
- executionContext,
17243
- };
17244
- };
17245
-
17246
- /**
17247
- * @private Constant defining the method name for logging purposes.
17248
- * Used as an identifier in log messages to track calls to `getNavigationRoute`.
17249
- */
17250
- const METHOD_NAME$c = "function.common.getNavigationRoute";
17251
- /**
17252
- * Retrieves the navigation route for a given client and swarm.
17253
- * Delegates to `NavigationValidationService.getNavigationRoute` to obtain a `Set` of visited agent names,
17254
- * with optional logging based on global configuration.
17255
- * @param {string} clientId - The unique identifier of the client requesting the navigation route.
17256
- * @param {SwarmName} swarmName - The name of the swarm context for which the route is retrieved.
17257
- * @returns {Set<string>} A set of `AgentName`s representing the visited agents in the navigation route.
17258
- */
17259
- const getNavigationRoute = (clientId, swarmName) => {
17260
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17261
- swarm$1.loggerService.log(METHOD_NAME$c, {
17262
- clientId,
17263
- swarmName,
17264
- });
17265
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$c);
17266
- return swarm$1.navigationValidationService.getNavigationRoute(clientId, swarmName);
17267
- };
17268
-
17269
- const METHOD_NAME$b = "function.history.getRawHistory";
17270
- /**
17271
- * Retrieves the raw, unmodified history for a given client session.
17272
- *
17273
- * This function fetches the complete history associated with a client’s active agent in a swarm session, without any filtering or modifications.
17274
- * It is wrapped in `beginContext` for a clean execution environment and logs the operation if enabled via `GLOBAL_CONFIG`. The function validates
17275
- * the session and swarm, retrieves the current agent, and uses `historyPublicService.toArrayForRaw` to obtain the raw history as an array.
17276
- * The result is a fresh copy of the history array.
17277
- *
17278
- * @param {string} clientId - The unique identifier of the client session whose raw history is to be retrieved.
17279
- * @param {string} [methodName="function.history.getRawHistory"] - The name of the calling method, used for validation and logging (defaults to `METHOD_NAME`).
17280
- * @returns {Promise<object[]>} A promise that resolves to an array containing the raw history entries.
17281
- * @throws {Error} If session or swarm validation fails, or if history retrieval encounters an issue.
17282
- * @example
17283
- * const rawHistory = await getRawHistory("client-123");
17284
- * console.log(rawHistory); // Outputs the full raw history array
17285
- */
17286
- const getRawHistory = beginContext(async (clientId, methodName = METHOD_NAME$b) => {
17287
- // Log the operation details if logging is enabled in GLOBAL_CONFIG
17288
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17289
- swarm$1.loggerService.log(METHOD_NAME$b, {
17290
- clientId,
17291
- });
17292
- // Validate the session and swarm
17293
- swarm$1.sessionValidationService.validate(clientId, methodName);
17294
- const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
17295
- swarm$1.swarmValidationService.validate(swarmName, methodName);
17296
- // Get the current agent and fetch raw history
17297
- const agentName = await swarm$1.swarmPublicService.getAgentName(methodName, clientId, swarmName);
17298
- const history = await swarm$1.historyPublicService.toArrayForRaw(methodName, clientId, agentName);
17299
- return [...history];
17300
- });
17669
+ // Return the constructed session context
17670
+ return {
17671
+ clientId,
17672
+ processId: GLOBAL_CONFIG.CC_PROCESS_UUID,
17673
+ methodContext,
17674
+ executionContext,
17675
+ };
17676
+ };
17301
17677
 
17302
- const METHOD_NAME$a = "function.history.getLastUserMessage";
17303
17678
  /**
17304
- * Retrieves the content of the most recent user message from a client's session history.
17305
- *
17306
- * This function fetches the raw history for a specified client using `getRawHistory` and finds the last entry where the role is "user" and the mode
17307
- * is "user". It is wrapped in `beginContext` for a clean execution environment and logs the operation if enabled via `GLOBAL_CONFIG`. The result is
17308
- * the content of the last user message as a string, or `null` if no matching user message exists in the history.
17309
- *
17310
- * @param {string} clientId - The unique identifier of the client session whose last user message is to be retrieved.
17311
- * @returns {Promise<string | null>} A promise that resolves to the content of the last user message, or `null` if none is found.
17312
- * @throws {Error} If `getRawHistory` fails due to session validation or history retrieval issues.
17313
- * @example
17314
- * const lastMessage = await getLastUserMessage("client-123");
17315
- * console.log(lastMessage); // Outputs the last user message or null
17679
+ * @private Constant defining the method name for logging purposes.
17680
+ * Used as an identifier in log messages to track calls to `getNavigationRoute`.
17316
17681
  */
17317
- const getLastUserMessage = beginContext(async (clientId) => {
17318
- // Log the operation details if logging is enabled in GLOBAL_CONFIG
17682
+ const METHOD_NAME$8 = "function.common.getNavigationRoute";
17683
+ /**
17684
+ * Retrieves the navigation route for a given client and swarm.
17685
+ * Delegates to `NavigationValidationService.getNavigationRoute` to obtain a `Set` of visited agent names,
17686
+ * with optional logging based on global configuration.
17687
+ * @param {string} clientId - The unique identifier of the client requesting the navigation route.
17688
+ * @param {SwarmName} swarmName - The name of the swarm context for which the route is retrieved.
17689
+ * @returns {Set<string>} A set of `AgentName`s representing the visited agents in the navigation route.
17690
+ */
17691
+ const getNavigationRoute = (clientId, swarmName) => {
17319
17692
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17320
- swarm$1.loggerService.log(METHOD_NAME$a, {
17693
+ swarm$1.loggerService.log(METHOD_NAME$8, {
17321
17694
  clientId,
17695
+ swarmName,
17322
17696
  });
17323
- // Fetch raw history and find the last user message
17324
- const history = await getRawHistory(clientId, METHOD_NAME$a);
17325
- const last = history.findLast(({ role, mode }) => role === "user" && mode === "user");
17326
- return last ? last.content : null;
17327
- });
17697
+ swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$8);
17698
+ return swarm$1.navigationValidationService.getNavigationRoute(clientId, swarmName);
17699
+ };
17328
17700
 
17329
- const METHOD_NAME$9 = "function.history.getUserHistory";
17701
+ const METHOD_NAME$7 = "function.history.getUserHistory";
17330
17702
  /**
17331
17703
  * Retrieves the user-specific history entries for a given client session.
17332
17704
  *
@@ -17344,15 +17716,15 @@ const METHOD_NAME$9 = "function.history.getUserHistory";
17344
17716
  const getUserHistory = beginContext(async (clientId) => {
17345
17717
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17346
17718
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17347
- swarm$1.loggerService.log(METHOD_NAME$9, {
17719
+ swarm$1.loggerService.log(METHOD_NAME$7, {
17348
17720
  clientId,
17349
17721
  });
17350
17722
  // Fetch raw history and filter for user role and mode
17351
- const history = await getRawHistory(clientId, METHOD_NAME$9);
17723
+ const history = await getRawHistory(clientId, METHOD_NAME$7);
17352
17724
  return history.filter(({ role, mode }) => role === "user" && mode === "user");
17353
17725
  });
17354
17726
 
17355
- const METHOD_NAME$8 = "function.history.getAssistantHistory";
17727
+ const METHOD_NAME$6 = "function.history.getAssistantHistory";
17356
17728
  /**
17357
17729
  * Retrieves the assistant's history entries for a given client session.
17358
17730
  *
@@ -17370,15 +17742,15 @@ const METHOD_NAME$8 = "function.history.getAssistantHistory";
17370
17742
  const getAssistantHistory = beginContext(async (clientId) => {
17371
17743
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17372
17744
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17373
- swarm$1.loggerService.log(METHOD_NAME$8, {
17745
+ swarm$1.loggerService.log(METHOD_NAME$6, {
17374
17746
  clientId,
17375
17747
  });
17376
17748
  // Fetch raw history and filter for assistant role
17377
- const history = await getRawHistory(clientId, METHOD_NAME$8);
17749
+ const history = await getRawHistory(clientId, METHOD_NAME$6);
17378
17750
  return history.filter(({ role }) => role === "assistant");
17379
17751
  });
17380
17752
 
17381
- const METHOD_NAME$7 = "function.history.getLastAssistantMessage";
17753
+ const METHOD_NAME$5 = "function.history.getLastAssistantMessage";
17382
17754
  /**
17383
17755
  * Retrieves the content of the most recent assistant message from a client's session history.
17384
17756
  *
@@ -17396,16 +17768,16 @@ const METHOD_NAME$7 = "function.history.getLastAssistantMessage";
17396
17768
  const getLastAssistantMessage = beginContext(async (clientId) => {
17397
17769
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17398
17770
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17399
- swarm$1.loggerService.log(METHOD_NAME$7, {
17771
+ swarm$1.loggerService.log(METHOD_NAME$5, {
17400
17772
  clientId,
17401
17773
  });
17402
17774
  // Fetch raw history and find the last assistant message
17403
- const history = await getRawHistory(clientId, METHOD_NAME$7);
17775
+ const history = await getRawHistory(clientId, METHOD_NAME$5);
17404
17776
  const last = history.findLast(({ role }) => role === "assistant");
17405
17777
  return last ? last.content : null;
17406
17778
  });
17407
17779
 
17408
- const METHOD_NAME$6 = "function.history.getLastSystemMessage";
17780
+ const METHOD_NAME$4 = "function.history.getLastSystemMessage";
17409
17781
  /**
17410
17782
  * Retrieves the content of the most recent system message from a client's session history.
17411
17783
  *
@@ -17423,16 +17795,16 @@ const METHOD_NAME$6 = "function.history.getLastSystemMessage";
17423
17795
  const getLastSystemMessage = beginContext(async (clientId) => {
17424
17796
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17425
17797
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17426
- swarm$1.loggerService.log(METHOD_NAME$6, {
17798
+ swarm$1.loggerService.log(METHOD_NAME$4, {
17427
17799
  clientId,
17428
17800
  });
17429
17801
  // Fetch raw history and find the last system message
17430
- const history = await getRawHistory(clientId, METHOD_NAME$6);
17802
+ const history = await getRawHistory(clientId, METHOD_NAME$4);
17431
17803
  const last = history.findLast(({ role }) => role === "system");
17432
17804
  return last ? last.content : null;
17433
17805
  });
17434
17806
 
17435
- const METHOD_NAME$5 = "function.event.listenEvent";
17807
+ const METHOD_NAME$3 = "function.event.listenEvent";
17436
17808
  /**
17437
17809
  * Set of reserved event source names that cannot be used for custom events.
17438
17810
  * @constant {Set<EventSource>}
@@ -17468,7 +17840,7 @@ const DISALLOWED_EVENT_SOURCE_LIST$2 = new Set([
17468
17840
  const event = beginContext((clientId, topicName, payload) => {
17469
17841
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17470
17842
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17471
- swarm$1.loggerService.log(METHOD_NAME$5, {
17843
+ swarm$1.loggerService.log(METHOD_NAME$3, {
17472
17844
  clientId,
17473
17845
  });
17474
17846
  // Check if the topic name is reserved
@@ -17483,7 +17855,7 @@ const event = beginContext((clientId, topicName, payload) => {
17483
17855
  });
17484
17856
  });
17485
17857
 
17486
- const METHOD_NAME$4 = "function.event.listenEvent";
17858
+ const METHOD_NAME$2 = "function.event.listenEvent";
17487
17859
  /**
17488
17860
  * Set of reserved event source names that cannot be used for custom event topics.
17489
17861
  * @constant {Set<EventSource>}
@@ -17535,7 +17907,7 @@ const validateClientId$g = (clientId) => {
17535
17907
  const listenEvent = beginContext((clientId, topicName, fn) => {
17536
17908
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17537
17909
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17538
- swarm$1.loggerService.log(METHOD_NAME$4, {
17910
+ swarm$1.loggerService.log(METHOD_NAME$2, {
17539
17911
  clientId,
17540
17912
  });
17541
17913
  // Check if the topic name is reserved
@@ -17548,7 +17920,7 @@ const listenEvent = beginContext((clientId, topicName, fn) => {
17548
17920
  return swarm$1.busService.subscribe(clientId, topicName, functoolsKit.queued(async ({ payload }) => await fn(payload)));
17549
17921
  });
17550
17922
 
17551
- const METHOD_NAME$3 = "function.event.listenEventOnce";
17923
+ const METHOD_NAME$1 = "function.event.listenEventOnce";
17552
17924
  /**
17553
17925
  * Set of reserved event source names that cannot be used for custom event topics.
17554
17926
  * @constant {Set<EventSource>}
@@ -17606,7 +17978,7 @@ const validateClientId$f = (clientId) => {
17606
17978
  const listenEventOnce = beginContext((clientId, topicName, filterFn, fn) => {
17607
17979
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17608
17980
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17609
- swarm$1.loggerService.log(METHOD_NAME$3, {
17981
+ swarm$1.loggerService.log(METHOD_NAME$1, {
17610
17982
  clientId,
17611
17983
  });
17612
17984
  // Check if the topic name is reserved
@@ -17619,125 +17991,19 @@ const listenEventOnce = beginContext((clientId, topicName, filterFn, fn) => {
17619
17991
  return swarm$1.busService.once(clientId, topicName, ({ payload }) => filterFn(payload), functoolsKit.queued(async ({ payload }) => await fn(payload)));
17620
17992
  });
17621
17993
 
17622
- const METHOD_NAME$2 = "function.navigate.changeToAgent";
17623
- /**
17624
- * Time-to-live for the change agent function in milliseconds.
17625
- * Defines how long the cached change agent function remains valid before expiring.
17626
- * @constant {number}
17627
- */
17628
- const CHANGE_AGENT_TTL$2 = 15 * 60 * 1000;
17629
- /**
17630
- * Garbage collection interval for the change agent function in milliseconds.
17631
- * Specifies the frequency at which expired TTL entries are cleaned up.
17632
- * @constant {number}
17633
- */
17634
- const CHANGE_AGENT_GC$2 = 60 * 1000;
17635
- /**
17636
- * Creates a change agent function with time-to-live (TTL) and queuing capabilities.
17637
- *
17638
- * This factory function generates a queued, TTL-limited function to handle agent changes for a specific client session,
17639
- * ensuring operations are executed sequentially and cached results are reused within the TTL period.
17640
- *
17641
- * @function
17642
- * @param {string} clientId - The unique identifier of the client session.
17643
- * @returns {TChangeToAgentRun} A function that performs the agent change operation with queuing and TTL.
17644
- */
17645
- const createChangeToAgent = functoolsKit.ttl((clientId) => functoolsKit.queued(async (methodName, agentName, swarmName) => {
17646
- if (!swarm$1.navigationValidationService.shouldNavigate(agentName, clientId, swarmName)) {
17647
- console.warn(`function "changeToAgent" skipped due to the circular route found clientId=${clientId} swarmName=${swarmName} agentNameTo=${agentName}`);
17648
- return false;
17649
- }
17650
- // Notify all agents in the swarm of the change
17651
- await Promise.all(swarm$1.swarmValidationService
17652
- .getAgentList(swarmName)
17653
- .map(async (agentName) => {
17654
- await swarm$1.agentPublicService.commitAgentChange(methodName, clientId, agentName);
17655
- }));
17656
- {
17657
- // Dispose of the current agent's resources and set up the new agent
17658
- const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$2, clientId, swarmName);
17659
- await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
17660
- await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
17661
- await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
17662
- }
17663
- // Set the new agent as the active agent
17664
- await swarm$1.swarmPublicService.setAgentName(agentName, methodName, clientId, swarmName);
17665
- return true;
17666
- }), {
17667
- key: ([clientId]) => `${clientId}`,
17668
- timeout: CHANGE_AGENT_TTL$2,
17669
- });
17670
- /**
17671
- * Creates a garbage collector for the change agent function.
17672
- *
17673
- * This function sets up a singleton interval-based garbage collector to periodically clean up expired TTL entries from `createChangeToAgent`.
17674
- *
17675
- * @function
17676
- * @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
17677
- */
17678
- const createGc$2 = functoolsKit.singleshot(async () => {
17679
- setInterval(createChangeToAgent.gc, CHANGE_AGENT_GC$2);
17680
- });
17681
- /**
17682
- * Changes the active agent for a given client session in a swarm.
17683
- *
17684
- * This function facilitates switching the active agent in a swarm session, validating the session and agent dependencies,
17685
- * logging the operation if enabled, and executing the change using a TTL-limited, queued runner.
17686
- * The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts.
17687
- *
17688
- * @param {AgentName} agentName - The name of the agent to switch to.
17689
- * @param {string} clientId - The unique identifier of the client session.
17690
- * @returns {Promise<boolean>} A promise that resolves when the agent change is complete. If it resolved false, the navigation is canceled due to recursion
17691
- * @throws {Error} If session or agent validation fails, or if the agent change process encounters an error.
17692
- * @example
17693
- * await changeToAgent("AgentX", "client-123");
17694
- */
17695
- const changeToAgent = beginContext(async (agentName, clientId) => {
17696
- // Log the operation details if logging is enabled in GLOBAL_CONFIG
17697
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17698
- swarm$1.loggerService.log(METHOD_NAME$2, {
17699
- agentName,
17700
- clientId,
17701
- });
17702
- const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
17703
- {
17704
- // Validate session, agent, and dependencies
17705
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$2);
17706
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$2);
17707
- const activeAgent = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$2, clientId, swarmName);
17708
- if (!swarm$1.agentValidationService.hasDependency(activeAgent, agentName)) {
17709
- console.error(`agent-swarm missing dependency detected for activeAgent=${activeAgent} dependencyAgent=${agentName}`);
17710
- }
17711
- }
17712
- if (!swarm$1.swarmValidationService.getAgentSet(swarmName).has(agentName)) {
17713
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17714
- swarm$1.loggerService.log('function "changeToAgent" skipped due to the agent is not in the swarm', {
17715
- agentName,
17716
- clientId,
17717
- swarmName,
17718
- });
17719
- console.warn(`function "changeToAgent" skipped due to the agent is not in the swarm clientId=${clientId} agentName=${agentName} swarmName=${swarmName}`);
17720
- return false;
17721
- }
17722
- // Execute the agent change with TTL and queuing
17723
- const run = await createChangeToAgent(clientId);
17724
- createGc$2();
17725
- return await run(METHOD_NAME$2, agentName, swarmName);
17726
- });
17727
-
17728
- const METHOD_NAME$1 = "function.navigate.changeToPrevAgent";
17994
+ const METHOD_NAME = "function.navigate.changeToPrevAgent";
17729
17995
  /**
17730
17996
  * Time-to-live for the change agent function in milliseconds.
17731
17997
  * Defines how long the cached change agent function remains valid before expiring.
17732
17998
  * @constant {number}
17733
17999
  */
17734
- const CHANGE_AGENT_TTL$1 = 15 * 60 * 1000;
18000
+ const CHANGE_AGENT_TTL = 15 * 60 * 1000;
17735
18001
  /**
17736
18002
  * Garbage collection interval for the change agent function in milliseconds.
17737
18003
  * Specifies the frequency at which expired TTL entries are cleaned up.
17738
18004
  * @constant {number}
17739
18005
  */
17740
- const CHANGE_AGENT_GC$1 = 60 * 1000;
18006
+ const CHANGE_AGENT_GC = 60 * 1000;
17741
18007
  /**
17742
18008
  * Creates a change agent function with time-to-live (TTL) and queuing capabilities for switching to the previous agent.
17743
18009
  *
@@ -17760,7 +18026,7 @@ const createChangeToPrevAgent = functoolsKit.ttl((clientId) => functoolsKit.queu
17760
18026
  }));
17761
18027
  {
17762
18028
  // Dispose of the current agent's resources and set up the new agent
17763
- const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1, clientId, swarmName);
18029
+ const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME, clientId, swarmName);
17764
18030
  await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
17765
18031
  await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
17766
18032
  await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
@@ -17770,7 +18036,7 @@ const createChangeToPrevAgent = functoolsKit.ttl((clientId) => functoolsKit.queu
17770
18036
  return true;
17771
18037
  }), {
17772
18038
  key: ([clientId]) => `${clientId}`,
17773
- timeout: CHANGE_AGENT_TTL$1,
18039
+ timeout: CHANGE_AGENT_TTL,
17774
18040
  });
17775
18041
  /**
17776
18042
  * Creates a garbage collector for the change agent function.
@@ -17780,8 +18046,8 @@ const createChangeToPrevAgent = functoolsKit.ttl((clientId) => functoolsKit.queu
17780
18046
  * @function
17781
18047
  * @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
17782
18048
  */
17783
- const createGc$1 = functoolsKit.singleshot(async () => {
17784
- setInterval(createChangeToPrevAgent.gc, CHANGE_AGENT_GC$1);
18049
+ const createGc = functoolsKit.singleshot(async () => {
18050
+ setInterval(createChangeToPrevAgent.gc, CHANGE_AGENT_GC);
17785
18051
  });
17786
18052
  /**
17787
18053
  * Navigates back to the previous or default agent for a given client session in a swarm.
@@ -17797,110 +18063,20 @@ const createGc$1 = functoolsKit.singleshot(async () => {
17797
18063
  * await changeToPrevAgent("client-123");
17798
18064
  */
17799
18065
  const changeToPrevAgent = beginContext(async (clientId) => {
17800
- // Log the operation details if logging is enabled in GLOBAL_CONFIG
17801
- GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17802
- swarm$1.loggerService.log(METHOD_NAME$1, {
17803
- clientId,
17804
- });
17805
- const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
17806
- const agentName = await swarm$1.swarmPublicService.navigationPop(METHOD_NAME$1, clientId, swarmName);
17807
- {
17808
- // Validate session and the retrieved agent
17809
- swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1);
17810
- swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1);
17811
- }
17812
- // Execute the agent change with TTL and queuing
17813
- const run = await createChangeToPrevAgent(clientId);
17814
- createGc$1();
17815
- return await run(METHOD_NAME$1, agentName, swarmName);
17816
- });
17817
-
17818
- const METHOD_NAME = "function.navigate.changeToDefaultAgent";
17819
- /**
17820
- * Time-to-live for the change agent function in milliseconds.
17821
- * Defines how long the cached change agent function remains valid before expiring.
17822
- * @constant {number}
17823
- */
17824
- const CHANGE_AGENT_TTL = 15 * 60 * 1000;
17825
- /**
17826
- * Garbage collection interval for the change agent function in milliseconds.
17827
- * Specifies the frequency at which expired TTL entries are cleaned up.
17828
- * @constant {number}
17829
- */
17830
- const CHANGE_AGENT_GC = 60 * 1000;
17831
- /**
17832
- * Creates a change agent function with time-to-live (TTL) and queuing capabilities for switching to the default agent.
17833
- *
17834
- * This factory function generates a queued, TTL-limited function to handle agent changes to the default agent for a specific client session,
17835
- * ensuring operations are executed sequentially and cached results are reused within the TTL period.
17836
- *
17837
- * @function
17838
- * @param {string} clientId - The unique identifier of the client session.
17839
- * @returns {TChangeToDefaultAgentRun} A function that performs the default agent change operation with queuing and TTL.
17840
- */
17841
- const createChangeToDefaultAgent = functoolsKit.ttl((clientId) => functoolsKit.queued(async (methodName, agentName, swarmName) => {
17842
- if (!swarm$1.navigationValidationService.shouldNavigate(agentName, clientId, swarmName)) {
17843
- return false;
17844
- }
17845
- // Notify all agents in the swarm of the change
17846
- await Promise.all(swarm$1.swarmValidationService
17847
- .getAgentList(swarmName)
17848
- .map(async (agentName) => {
17849
- await swarm$1.agentPublicService.commitAgentChange(methodName, clientId, agentName);
17850
- }));
17851
- {
17852
- // Dispose of the current agent's resources and set up the new default agent
17853
- const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME, clientId, swarmName);
17854
- await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
17855
- await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
17856
- await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
17857
- }
17858
- // Set the default agent as the active agent
17859
- await swarm$1.swarmPublicService.setAgentName(agentName, methodName, clientId, swarmName);
17860
- return true;
17861
- }), {
17862
- key: ([clientId]) => `${clientId}`,
17863
- timeout: CHANGE_AGENT_TTL,
17864
- });
17865
- /**
17866
- * Creates a garbage collector for the change agent function.
17867
- *
17868
- * This function sets up a singleton interval-based garbage collector to periodically clean up expired TTL entries from `createChangeToDefaultAgent`.
17869
- *
17870
- * @function
17871
- * @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
17872
- */
17873
- const createGc = functoolsKit.singleshot(async () => {
17874
- setInterval(createChangeToDefaultAgent.gc, CHANGE_AGENT_GC);
17875
- });
17876
- /**
17877
- * Navigates back to the default agent for a given client session in a swarm.
17878
- *
17879
- * This function switches the active agent to the default agent defined in the swarm schema for the specified client session.
17880
- * It validates the session and default agent, logs the operation if enabled, and executes the change using a TTL-limited, queued runner.
17881
- * The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts.
17882
- *
17883
- * @param {string} clientId - The unique identifier of the client session.
17884
- * @returns {Promise<boolean>} A promise that resolves when the default agent change is complete. If navigation stack contains recursion being canceled
17885
- * @throws {Error} If session or agent validation fails, or if the agent change process encounters an error.
17886
- * @example
17887
- * await changeToDefaultAgent("client-123");
17888
- */
17889
- const changeToDefaultAgent = beginContext(async (clientId) => {
17890
18066
  // Log the operation details if logging is enabled in GLOBAL_CONFIG
17891
18067
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
17892
18068
  swarm$1.loggerService.log(METHOD_NAME, {
17893
18069
  clientId,
17894
18070
  });
17895
18071
  const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
17896
- const { defaultAgent: agentName } = swarm$1.swarmSchemaService.get(swarmName);
18072
+ const agentName = await swarm$1.swarmPublicService.navigationPop(METHOD_NAME, clientId, swarmName);
17897
18073
  {
17898
- // Validate session and default agent
18074
+ // Validate session and the retrieved agent
17899
18075
  swarm$1.sessionValidationService.validate(clientId, METHOD_NAME);
17900
18076
  swarm$1.agentValidationService.validate(agentName, METHOD_NAME);
17901
18077
  }
17902
18078
  // Execute the agent change with TTL and queuing
17903
- const run = await createChangeToDefaultAgent(clientId);
18079
+ const run = await createChangeToPrevAgent(clientId);
17904
18080
  createGc();
17905
18081
  return await run(METHOD_NAME, agentName, swarmName);
17906
18082
  });
@@ -19962,6 +20138,8 @@ exports.commitToolOutputForce = commitToolOutputForce;
19962
20138
  exports.commitUserMessage = commitUserMessage;
19963
20139
  exports.commitUserMessageForce = commitUserMessageForce;
19964
20140
  exports.complete = complete;
20141
+ exports.createNavigateToAgent = createNavigateToAgent;
20142
+ exports.createNavigateToTriageAgent = createNavigateToTriageAgent;
19965
20143
  exports.disposeConnection = disposeConnection;
19966
20144
  exports.dumpAgent = dumpAgent;
19967
20145
  exports.dumpClientPerformance = dumpClientPerformance;