agent-swarm-kit 1.1.3 → 1.1.5
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 +791 -708
- package/build/index.mjs +792 -710
- package/package.json +1 -1
- package/types.d.ts +65 -1
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$
|
|
4843
|
+
const METHOD_NAME$1a = "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$
|
|
4854
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1a);
|
|
4855
4855
|
if (PayloadContextService.hasContext()) {
|
|
4856
4856
|
const { payload } = swarm$1.payloadContextService.context;
|
|
4857
4857
|
return payload;
|
|
@@ -9537,6 +9537,9 @@ const CREATE_EMBEDDING_FN = async (item, self) => {
|
|
|
9537
9537
|
const WAIT_FOR_INIT_FN$1 = async (self) => {
|
|
9538
9538
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
9539
9539
|
self.params.logger.debug(`ClientStorage storageName=${self.params.storageName} clientId=${self.params.clientId} shared=${self.params.shared} waitForInit`);
|
|
9540
|
+
if (GLOBAL_CONFIG.CC_STORAGE_DISABLE_GET_DATA) {
|
|
9541
|
+
return;
|
|
9542
|
+
}
|
|
9540
9543
|
if (!self.params.getData) {
|
|
9541
9544
|
return;
|
|
9542
9545
|
}
|
|
@@ -14520,7 +14523,7 @@ const swarm = {
|
|
|
14520
14523
|
init();
|
|
14521
14524
|
var swarm$1 = swarm;
|
|
14522
14525
|
|
|
14523
|
-
const METHOD_NAME$
|
|
14526
|
+
const METHOD_NAME$19 = "cli.dumpDocs";
|
|
14524
14527
|
/**
|
|
14525
14528
|
* Dumps the documentation for the agents and swarms.
|
|
14526
14529
|
*
|
|
@@ -14530,7 +14533,7 @@ const METHOD_NAME$18 = "cli.dumpDocs";
|
|
|
14530
14533
|
*/
|
|
14531
14534
|
const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantUML) => {
|
|
14532
14535
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14533
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
14536
|
+
swarm$1.loggerService.log(METHOD_NAME$19, {
|
|
14534
14537
|
dirName,
|
|
14535
14538
|
});
|
|
14536
14539
|
if (PlantUML) {
|
|
@@ -14540,10 +14543,10 @@ const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantU
|
|
|
14540
14543
|
}
|
|
14541
14544
|
swarm$1.agentValidationService
|
|
14542
14545
|
.getAgentList()
|
|
14543
|
-
.forEach((agentName) => swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
14546
|
+
.forEach((agentName) => swarm$1.agentValidationService.validate(agentName, METHOD_NAME$19));
|
|
14544
14547
|
swarm$1.swarmValidationService
|
|
14545
14548
|
.getSwarmList()
|
|
14546
|
-
.forEach((swarmName) => swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
14549
|
+
.forEach((swarmName) => swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$19));
|
|
14547
14550
|
swarm$1.agentValidationService.getAgentList().forEach((agentName) => {
|
|
14548
14551
|
const { dependsOn } = swarm$1.agentSchemaService.get(agentName);
|
|
14549
14552
|
if (!dependsOn) {
|
|
@@ -14553,7 +14556,7 @@ const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantU
|
|
|
14553
14556
|
return swarm$1.docService.dumpDocs(prefix, dirName);
|
|
14554
14557
|
});
|
|
14555
14558
|
|
|
14556
|
-
const METHOD_NAME$
|
|
14559
|
+
const METHOD_NAME$18 = "cli.dumpAgent";
|
|
14557
14560
|
/**
|
|
14558
14561
|
* Dumps the agent information into PlantUML format.
|
|
14559
14562
|
*
|
|
@@ -14562,14 +14565,14 @@ const METHOD_NAME$17 = "cli.dumpAgent";
|
|
|
14562
14565
|
*/
|
|
14563
14566
|
const dumpAgent = beginContext((agentName, { withSubtree = false } = {}) => {
|
|
14564
14567
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14565
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
14568
|
+
swarm$1.loggerService.log(METHOD_NAME$18, {
|
|
14566
14569
|
agentName,
|
|
14567
14570
|
});
|
|
14568
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
14571
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$18);
|
|
14569
14572
|
return swarm$1.agentMetaService.toUML(agentName, withSubtree);
|
|
14570
14573
|
});
|
|
14571
14574
|
|
|
14572
|
-
const METHOD_NAME$
|
|
14575
|
+
const METHOD_NAME$17 = "cli.dumpSwarm";
|
|
14573
14576
|
/**
|
|
14574
14577
|
* Dumps the swarm information into PlantUML format.
|
|
14575
14578
|
*
|
|
@@ -14578,14 +14581,14 @@ const METHOD_NAME$16 = "cli.dumpSwarm";
|
|
|
14578
14581
|
*/
|
|
14579
14582
|
const dumpSwarm = beginContext((swarmName) => {
|
|
14580
14583
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14581
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
14584
|
+
swarm$1.loggerService.log(METHOD_NAME$17, {
|
|
14582
14585
|
swarmName,
|
|
14583
14586
|
});
|
|
14584
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
14587
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$17);
|
|
14585
14588
|
return swarm$1.swarmMetaService.toUML(swarmName);
|
|
14586
14589
|
});
|
|
14587
14590
|
|
|
14588
|
-
const METHOD_NAME$
|
|
14591
|
+
const METHOD_NAME$16 = "cli.dumpPerfomance";
|
|
14589
14592
|
const METHOD_NAME_INTERNAL$1 = "cli.dumpPerfomance.internal";
|
|
14590
14593
|
const METHOD_NAME_INTERVAL = "cli.dumpPerfomance.interval";
|
|
14591
14594
|
/**
|
|
@@ -14604,7 +14607,7 @@ const dumpPerfomanceInternal = beginContext(async (dirName = "./logs/meta") => {
|
|
|
14604
14607
|
* @returns {Promise<void>} A promise that resolves when the performance data has been dumped.
|
|
14605
14608
|
*/
|
|
14606
14609
|
const dumpPerfomance = async (dirName = "./logs/meta") => {
|
|
14607
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
14610
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$16);
|
|
14608
14611
|
await dumpPerfomanceInternal(dirName);
|
|
14609
14612
|
};
|
|
14610
14613
|
/**
|
|
@@ -14662,7 +14665,7 @@ const listenExecutionEvent = beginContext((clientId, fn) => {
|
|
|
14662
14665
|
return swarm$1.busService.subscribe(clientId, "execution-bus", functoolsKit.queued(async (e) => await fn(e)));
|
|
14663
14666
|
});
|
|
14664
14667
|
|
|
14665
|
-
const METHOD_NAME$
|
|
14668
|
+
const METHOD_NAME$15 = "cli.dumpClientPerformance";
|
|
14666
14669
|
const METHOD_NAME_INTERNAL = "cli.dumpClientPerformance.internal";
|
|
14667
14670
|
const METHOD_NAME_EXECUTE = "cli.dumpClientPerformance.execute";
|
|
14668
14671
|
/**
|
|
@@ -14686,7 +14689,7 @@ const dumpClientPerformanceInternal = beginContext(async (clientId, dirName = ".
|
|
|
14686
14689
|
* @returns {Promise<void>} A promise that resolves when the performance data has been dumped.
|
|
14687
14690
|
*/
|
|
14688
14691
|
const dumpClientPerformance = async (clientId, dirName = "./logs/client") => {
|
|
14689
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
14692
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$15);
|
|
14690
14693
|
await dumpClientPerformanceInternal(clientId, dirName);
|
|
14691
14694
|
};
|
|
14692
14695
|
/**
|
|
@@ -14706,172 +14709,573 @@ dumpClientPerformance.runAfterExecute = beginContext(async (dirName = "./logs/cl
|
|
|
14706
14709
|
});
|
|
14707
14710
|
});
|
|
14708
14711
|
|
|
14709
|
-
/** @
|
|
14710
|
-
const METHOD_NAME$
|
|
14712
|
+
/** @private Constant defining the method name for logging and validation context */
|
|
14713
|
+
const METHOD_NAME$14 = "function.commit.commitFlushForce";
|
|
14711
14714
|
/**
|
|
14712
|
-
*
|
|
14713
|
-
*
|
|
14714
|
-
*
|
|
14715
|
-
*
|
|
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.
|
|
14716
14727
|
*/
|
|
14717
|
-
const
|
|
14728
|
+
const commitFlushForce = beginContext(async (clientId) => {
|
|
14729
|
+
// Log the flush attempt if enabled
|
|
14718
14730
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14719
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
14720
|
-
|
|
14731
|
+
swarm$1.loggerService.log(METHOD_NAME$14, {
|
|
14732
|
+
clientId,
|
|
14733
|
+
METHOD_NAME: METHOD_NAME$14,
|
|
14721
14734
|
});
|
|
14722
|
-
swarm
|
|
14723
|
-
swarm$1.
|
|
14724
|
-
|
|
14735
|
+
// Validate the session exists and retrieve the associated swarm
|
|
14736
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$14);
|
|
14737
|
+
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
14738
|
+
// Validate the swarm configuration
|
|
14739
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$14);
|
|
14740
|
+
// Commit the flush of agent history via SessionPublicService without agent checks
|
|
14741
|
+
await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$14, clientId, swarmName);
|
|
14725
14742
|
});
|
|
14726
14743
|
|
|
14727
|
-
const METHOD_NAME$
|
|
14744
|
+
const METHOD_NAME$13 = "function.commit.commitToolOutputForce";
|
|
14728
14745
|
/**
|
|
14729
|
-
*
|
|
14746
|
+
* Commits the output of a tool execution to the active agent in a swarm session without checking the active agent.
|
|
14730
14747
|
*
|
|
14731
|
-
* This function
|
|
14732
|
-
*
|
|
14733
|
-
* outside of existing method and execution contexts, providing a clean execution environment.
|
|
14734
|
-
* and returns the agent's name upon successful registration.
|
|
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.
|
|
14735
14751
|
*
|
|
14736
|
-
* @param {
|
|
14737
|
-
* @
|
|
14738
|
-
* @
|
|
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.
|
|
14739
14757
|
* @example
|
|
14740
|
-
*
|
|
14741
|
-
* const agentName = addAgent(agentSchema);
|
|
14742
|
-
* console.log(agentName); // Outputs "AgentX"
|
|
14758
|
+
* await commitToolOutputForce("tool-123", "Tool execution result", "client-456");
|
|
14743
14759
|
*/
|
|
14744
|
-
const
|
|
14760
|
+
const commitToolOutputForce = beginContext(async (toolId, content, clientId) => {
|
|
14745
14761
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
14746
14762
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14747
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
14748
|
-
|
|
14763
|
+
swarm$1.loggerService.log(METHOD_NAME$13, {
|
|
14764
|
+
toolId,
|
|
14765
|
+
content,
|
|
14766
|
+
clientId,
|
|
14749
14767
|
});
|
|
14750
|
-
//
|
|
14751
|
-
swarm$1.
|
|
14752
|
-
swarm$1.
|
|
14753
|
-
|
|
14754
|
-
|
|
14768
|
+
// Validate the session and swarm to ensure they exist and are accessible
|
|
14769
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$13);
|
|
14770
|
+
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
14771
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$13);
|
|
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$13, clientId, swarmName);
|
|
14755
14774
|
});
|
|
14756
14775
|
|
|
14757
|
-
const METHOD_NAME$11 = "function.setup.addCompletion";
|
|
14758
14776
|
/**
|
|
14759
|
-
*
|
|
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$12 = "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$12, { clientId });
|
|
14792
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$12);
|
|
14793
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$12);
|
|
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$11 = "function.history.getRawHistory";
|
|
14801
|
+
/**
|
|
14802
|
+
* Retrieves the raw, unmodified history for a given client session.
|
|
14760
14803
|
*
|
|
14761
|
-
* This function
|
|
14762
|
-
*
|
|
14763
|
-
*
|
|
14764
|
-
* The
|
|
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.
|
|
14765
14808
|
*
|
|
14766
|
-
* @param {
|
|
14767
|
-
* @
|
|
14768
|
-
* @
|
|
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.
|
|
14769
14813
|
* @example
|
|
14770
|
-
* const
|
|
14771
|
-
*
|
|
14772
|
-
* console.log(completionName); // Outputs "OpenAI"
|
|
14814
|
+
* const rawHistory = await getRawHistory("client-123");
|
|
14815
|
+
* console.log(rawHistory); // Outputs the full raw history array
|
|
14773
14816
|
*/
|
|
14774
|
-
const
|
|
14817
|
+
const getRawHistory = beginContext(async (clientId, methodName = METHOD_NAME$11) => {
|
|
14775
14818
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
14776
14819
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14777
14820
|
swarm$1.loggerService.log(METHOD_NAME$11, {
|
|
14778
|
-
|
|
14821
|
+
clientId,
|
|
14779
14822
|
});
|
|
14780
|
-
//
|
|
14781
|
-
swarm$1.
|
|
14782
|
-
swarm$1.
|
|
14783
|
-
|
|
14784
|
-
|
|
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];
|
|
14785
14831
|
});
|
|
14786
14832
|
|
|
14787
|
-
const METHOD_NAME$10 = "function.
|
|
14833
|
+
const METHOD_NAME$10 = "function.history.getLastUserMessage";
|
|
14788
14834
|
/**
|
|
14789
|
-
*
|
|
14835
|
+
* Retrieves the content of the most recent user message from a client's session history.
|
|
14790
14836
|
*
|
|
14791
|
-
* This function
|
|
14792
|
-
*
|
|
14793
|
-
*
|
|
14794
|
-
* providing a clean execution environment. The function logs the operation if enabled and returns the swarm's name upon successful registration.
|
|
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.
|
|
14795
14840
|
*
|
|
14796
|
-
* @param {
|
|
14797
|
-
* @returns {string}
|
|
14798
|
-
* @throws {Error} If
|
|
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.
|
|
14799
14844
|
* @example
|
|
14800
|
-
* const
|
|
14801
|
-
*
|
|
14802
|
-
* console.log(swarmName); // Outputs "TaskSwarm"
|
|
14845
|
+
* const lastMessage = await getLastUserMessage("client-123");
|
|
14846
|
+
* console.log(lastMessage); // Outputs the last user message or null
|
|
14803
14847
|
*/
|
|
14804
|
-
const
|
|
14848
|
+
const getLastUserMessage = beginContext(async (clientId) => {
|
|
14805
14849
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
14806
14850
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14807
14851
|
swarm$1.loggerService.log(METHOD_NAME$10, {
|
|
14808
|
-
|
|
14852
|
+
clientId,
|
|
14809
14853
|
});
|
|
14810
|
-
//
|
|
14811
|
-
|
|
14812
|
-
|
|
14813
|
-
|
|
14814
|
-
return swarmSchema.swarmName;
|
|
14854
|
+
// Fetch raw history and find the last user message
|
|
14855
|
+
const history = await getRawHistory(clientId, METHOD_NAME$10);
|
|
14856
|
+
const last = history.findLast(({ role, mode }) => role === "user" && mode === "user");
|
|
14857
|
+
return last ? last.content : null;
|
|
14815
14858
|
});
|
|
14816
14859
|
|
|
14817
|
-
const METHOD_NAME$$ = "function.
|
|
14860
|
+
const METHOD_NAME$$ = "function.navigate.changeToDefaultAgent";
|
|
14818
14861
|
/**
|
|
14819
|
-
*
|
|
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.
|
|
14820
14875
|
*
|
|
14821
|
-
* This function
|
|
14822
|
-
*
|
|
14823
|
-
* `addAgent`, likely intending that tools are linked to agent capabilities. The execution is wrapped in `beginContext` to ensure it runs
|
|
14824
|
-
* outside of existing method and execution contexts, providing a clean execution environment. The function logs the operation if enabled
|
|
14825
|
-
* and returns the tool's name upon successful registration.
|
|
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.
|
|
14826
14878
|
*
|
|
14827
|
-
* @
|
|
14828
|
-
* @param {
|
|
14829
|
-
* @returns {
|
|
14830
|
-
* @throws {Error} If the tool schema is invalid or if registration fails due to conflicts or service errors (e.g., duplicate tool name).
|
|
14831
|
-
* @example
|
|
14832
|
-
* const toolSchema = { toolName: "Calculator", fn: (x: number) => x * 2, description: "Doubles a number" };
|
|
14833
|
-
* const toolName = addTool(toolSchema);
|
|
14834
|
-
* console.log(toolName); // Outputs "Calculator"
|
|
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.
|
|
14835
14882
|
*/
|
|
14836
|
-
const
|
|
14837
|
-
|
|
14838
|
-
|
|
14839
|
-
|
|
14840
|
-
|
|
14841
|
-
|
|
14842
|
-
|
|
14843
|
-
|
|
14844
|
-
|
|
14845
|
-
|
|
14846
|
-
|
|
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$$, 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,
|
|
14847
14906
|
});
|
|
14848
|
-
|
|
14849
|
-
const METHOD_NAME$_ = "function.setup.addState";
|
|
14850
14907
|
/**
|
|
14851
|
-
*
|
|
14908
|
+
* Creates a garbage collector for the change agent function.
|
|
14852
14909
|
*
|
|
14853
|
-
* This function
|
|
14854
|
-
* Only states registered through this function are recognized by the swarm. If the state is marked as shared, it initializes a connection
|
|
14855
|
-
* to the shared state service and waits for its initialization. The execution is wrapped in `beginContext` to ensure it runs outside of
|
|
14856
|
-
* existing method and execution contexts, providing a clean execution environment. The function logs the operation if enabled and returns
|
|
14857
|
-
* the state's name upon successful registration.
|
|
14910
|
+
* This function sets up a singleton interval-based garbage collector to periodically clean up expired TTL entries from `createChangeToDefaultAgent`.
|
|
14858
14911
|
*
|
|
14859
|
-
* @
|
|
14860
|
-
* @
|
|
14861
|
-
* @returns {string} The name of the newly added state (`stateSchema.stateName`), confirming its registration.
|
|
14862
|
-
* @throws {Error} If the state schema is invalid, registration fails (e.g., duplicate state name), or shared state initialization encounters an error.
|
|
14863
|
-
* @example
|
|
14864
|
-
* const stateSchema = { stateName: "UserPrefs", shared: true, initialValue: { theme: "dark" } };
|
|
14865
|
-
* const stateName = addState(stateSchema);
|
|
14866
|
-
* console.log(stateName); // Outputs "UserPrefs"
|
|
14912
|
+
* @function
|
|
14913
|
+
* @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
|
|
14867
14914
|
*/
|
|
14868
|
-
const
|
|
14869
|
-
|
|
14870
|
-
|
|
14871
|
-
|
|
14872
|
-
|
|
14873
|
-
|
|
14874
|
-
|
|
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$$, {
|
|
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$$);
|
|
14942
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$$);
|
|
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$$, 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$Z = "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$Z, {
|
|
15003
|
+
content,
|
|
15004
|
+
clientId,
|
|
15005
|
+
executionId,
|
|
15006
|
+
});
|
|
15007
|
+
// Validate the session and swarm
|
|
15008
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$Z);
|
|
15009
|
+
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15010
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$Z);
|
|
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$Z, 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$Y = "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$Y, {
|
|
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
|
+
/** @constant {string} METHOD_NAME - The name of the method used for logging */
|
|
15114
|
+
const METHOD_NAME$X = "function.setup.addWiki";
|
|
15115
|
+
/**
|
|
15116
|
+
* Adds a wiki schema to the system
|
|
15117
|
+
* @function addWiki
|
|
15118
|
+
* @param {IWikiSchema} wikiSchema - The wiki schema to add
|
|
15119
|
+
* @returns {string} The name of the added wiki
|
|
15120
|
+
*/
|
|
15121
|
+
const addWiki = beginContext((wikiSchema) => {
|
|
15122
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15123
|
+
swarm$1.loggerService.log(METHOD_NAME$X, {
|
|
15124
|
+
wikiSchema,
|
|
15125
|
+
});
|
|
15126
|
+
swarm$1.wikiValidationService.addWiki(wikiSchema.wikiName, wikiSchema);
|
|
15127
|
+
swarm$1.wikiSchemaService.register(wikiSchema.wikiName, wikiSchema);
|
|
15128
|
+
return wikiSchema.wikiName;
|
|
15129
|
+
});
|
|
15130
|
+
|
|
15131
|
+
const METHOD_NAME$W = "function.setup.addAgent";
|
|
15132
|
+
/**
|
|
15133
|
+
* Adds a new agent to the agent registry for use within the swarm system.
|
|
15134
|
+
*
|
|
15135
|
+
* This function registers a new agent by adding it to the agent validation and schema services, making it available for swarm operations.
|
|
15136
|
+
* Only agents registered through this function can be utilized by the swarm. The execution is wrapped in `beginContext` to ensure it runs
|
|
15137
|
+
* outside of existing method and execution contexts, providing a clean execution environment. The function logs the operation if enabled
|
|
15138
|
+
* and returns the agent's name upon successful registration.
|
|
15139
|
+
*
|
|
15140
|
+
* @param {IAgentSchema} agentSchema - The schema defining the agent's properties, including its name (`agentName`) and other configuration details.
|
|
15141
|
+
* @returns {string} The name of the newly added agent (`agentSchema.agentName`), confirming its registration.
|
|
15142
|
+
* @throws {Error} If the agent schema is invalid or if registration fails due to conflicts or service errors (e.g., duplicate agent name).
|
|
15143
|
+
* @example
|
|
15144
|
+
* const agentSchema = { agentName: "AgentX", prompt: "Handle tasks" };
|
|
15145
|
+
* const agentName = addAgent(agentSchema);
|
|
15146
|
+
* console.log(agentName); // Outputs "AgentX"
|
|
15147
|
+
*/
|
|
15148
|
+
const addAgent = beginContext((agentSchema) => {
|
|
15149
|
+
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15150
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15151
|
+
swarm$1.loggerService.log(METHOD_NAME$W, {
|
|
15152
|
+
agentSchema,
|
|
15153
|
+
});
|
|
15154
|
+
// Register the agent in the validation and schema services
|
|
15155
|
+
swarm$1.agentValidationService.addAgent(agentSchema.agentName, agentSchema);
|
|
15156
|
+
swarm$1.agentSchemaService.register(agentSchema.agentName, agentSchema);
|
|
15157
|
+
// Return the agent's name as confirmation of registration
|
|
15158
|
+
return agentSchema.agentName;
|
|
15159
|
+
});
|
|
15160
|
+
|
|
15161
|
+
const METHOD_NAME$V = "function.setup.addCompletion";
|
|
15162
|
+
/**
|
|
15163
|
+
* Adds a completion engine to the registry for use by agents in the swarm system.
|
|
15164
|
+
*
|
|
15165
|
+
* This function registers a completion engine, enabling agents to utilize various models and frameworks (e.g., mock, GPT4All, Ollama, OpenAI)
|
|
15166
|
+
* for generating completions. The completion schema is added to the validation and schema services, making it available for agent operations.
|
|
15167
|
+
* The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts, providing a clean execution environment.
|
|
15168
|
+
* The function logs the operation if enabled and returns the completion's name upon successful registration.
|
|
15169
|
+
*
|
|
15170
|
+
* @param {ICompletionSchema} completionSchema - The schema defining the completion engine's properties, including its name (`completionName`) and configuration details.
|
|
15171
|
+
* @returns {string} The name of the newly added completion (`completionSchema.completionName`), confirming its registration.
|
|
15172
|
+
* @throws {Error} If the completion schema is invalid or if registration fails due to conflicts or service errors (e.g., duplicate completion name).
|
|
15173
|
+
* @example
|
|
15174
|
+
* const completionSchema = { completionName: "OpenAI", model: "gpt-3.5-turbo" };
|
|
15175
|
+
* const completionName = addCompletion(completionSchema);
|
|
15176
|
+
* console.log(completionName); // Outputs "OpenAI"
|
|
15177
|
+
*/
|
|
15178
|
+
const addCompletion = beginContext((completionSchema) => {
|
|
15179
|
+
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15180
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15181
|
+
swarm$1.loggerService.log(METHOD_NAME$V, {
|
|
15182
|
+
completionSchema,
|
|
15183
|
+
});
|
|
15184
|
+
// Register the completion in the validation and schema services
|
|
15185
|
+
swarm$1.completionValidationService.addCompletion(completionSchema.completionName);
|
|
15186
|
+
swarm$1.completionSchemaService.register(completionSchema.completionName, completionSchema);
|
|
15187
|
+
// Return the completion's name as confirmation of registration
|
|
15188
|
+
return completionSchema.completionName;
|
|
15189
|
+
});
|
|
15190
|
+
|
|
15191
|
+
const METHOD_NAME$U = "function.setup.addSwarm";
|
|
15192
|
+
/**
|
|
15193
|
+
* Adds a new swarm to the system for managing client sessions.
|
|
15194
|
+
*
|
|
15195
|
+
* This function registers a new swarm, which serves as the root entity for initiating and managing client sessions within the system.
|
|
15196
|
+
* The swarm defines the structure and behavior of agent interactions and session workflows. Only swarms registered through this function
|
|
15197
|
+
* are recognized by the system. The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts,
|
|
15198
|
+
* providing a clean execution environment. The function logs the operation if enabled and returns the swarm's name upon successful registration.
|
|
15199
|
+
*
|
|
15200
|
+
* @param {ISwarmSchema} swarmSchema - The schema defining the swarm's properties, including its name (`swarmName`), default agent, and other configuration details.
|
|
15201
|
+
* @returns {string} The name of the newly added swarm (`swarmSchema.swarmName`), confirming its registration.
|
|
15202
|
+
* @throws {Error} If the swarm schema is invalid or if registration fails due to conflicts or service errors (e.g., duplicate swarm name).
|
|
15203
|
+
* @example
|
|
15204
|
+
* const swarmSchema = { swarmName: "TaskSwarm", defaultAgent: "AgentX" };
|
|
15205
|
+
* const swarmName = addSwarm(swarmSchema);
|
|
15206
|
+
* console.log(swarmName); // Outputs "TaskSwarm"
|
|
15207
|
+
*/
|
|
15208
|
+
const addSwarm = beginContext((swarmSchema) => {
|
|
15209
|
+
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15210
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15211
|
+
swarm$1.loggerService.log(METHOD_NAME$U, {
|
|
15212
|
+
swarmSchema,
|
|
15213
|
+
});
|
|
15214
|
+
// Register the swarm in the validation and schema services
|
|
15215
|
+
swarm$1.swarmValidationService.addSwarm(swarmSchema.swarmName, swarmSchema);
|
|
15216
|
+
swarm$1.swarmSchemaService.register(swarmSchema.swarmName, swarmSchema);
|
|
15217
|
+
// Return the swarm's name as confirmation of registration
|
|
15218
|
+
return swarmSchema.swarmName;
|
|
15219
|
+
});
|
|
15220
|
+
|
|
15221
|
+
const METHOD_NAME$T = "function.setup.addTool";
|
|
15222
|
+
/**
|
|
15223
|
+
* Adds a new tool to the tool registry for use by agents in the swarm system.
|
|
15224
|
+
*
|
|
15225
|
+
* This function registers a new tool, enabling agents within the swarm to utilize it for performing specific tasks or operations.
|
|
15226
|
+
* Tools must be registered through this function to be recognized by the swarm, though the original comment suggests an association with
|
|
15227
|
+
* `addAgent`, likely intending that tools are linked to agent capabilities. The execution is wrapped in `beginContext` to ensure it runs
|
|
15228
|
+
* outside of existing method and execution contexts, providing a clean execution environment. The function logs the operation if enabled
|
|
15229
|
+
* and returns the tool's name upon successful registration.
|
|
15230
|
+
*
|
|
15231
|
+
* @template T - The type of the tool's input/output data, defaulting to a record of string keys and `ToolValue` values if unspecified.
|
|
15232
|
+
* @param {IAgentTool<T>} toolSchema - The schema defining the tool's properties, including its name (`toolName`) and other configuration details (e.g., function, description).
|
|
15233
|
+
* @returns {string} The name of the newly added tool (`toolSchema.toolName`), confirming its registration.
|
|
15234
|
+
* @throws {Error} If the tool schema is invalid or if registration fails due to conflicts or service errors (e.g., duplicate tool name).
|
|
15235
|
+
* @example
|
|
15236
|
+
* const toolSchema = { toolName: "Calculator", fn: (x: number) => x * 2, description: "Doubles a number" };
|
|
15237
|
+
* const toolName = addTool(toolSchema);
|
|
15238
|
+
* console.log(toolName); // Outputs "Calculator"
|
|
15239
|
+
*/
|
|
15240
|
+
const addTool = beginContext((toolSchema) => {
|
|
15241
|
+
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15242
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15243
|
+
swarm$1.loggerService.log(METHOD_NAME$T, {
|
|
15244
|
+
toolSchema,
|
|
15245
|
+
});
|
|
15246
|
+
// Register the tool in the validation and schema services
|
|
15247
|
+
swarm$1.toolValidationService.addTool(toolSchema.toolName, toolSchema);
|
|
15248
|
+
swarm$1.toolSchemaService.register(toolSchema.toolName, toolSchema);
|
|
15249
|
+
// Return the tool's name as confirmation of registration
|
|
15250
|
+
return toolSchema.toolName;
|
|
15251
|
+
});
|
|
15252
|
+
|
|
15253
|
+
const METHOD_NAME$S = "function.setup.addState";
|
|
15254
|
+
/**
|
|
15255
|
+
* Adds a new state to the state registry for use within the swarm system.
|
|
15256
|
+
*
|
|
15257
|
+
* This function registers a new state, enabling the swarm to manage and utilize it for agent operations or shared data persistence.
|
|
15258
|
+
* Only states registered through this function are recognized by the swarm. If the state is marked as shared, it initializes a connection
|
|
15259
|
+
* to the shared state service and waits for its initialization. The execution is wrapped in `beginContext` to ensure it runs outside of
|
|
15260
|
+
* existing method and execution contexts, providing a clean execution environment. The function logs the operation if enabled and returns
|
|
15261
|
+
* the state's name upon successful registration.
|
|
15262
|
+
*
|
|
15263
|
+
* @template T - The type of data stored in the state (defaults to `any` if unspecified).
|
|
15264
|
+
* @param {IStateSchema<T>} stateSchema - The schema defining the state's properties, including its name (`stateName`), shared status (`shared`), and other configuration details.
|
|
15265
|
+
* @returns {string} The name of the newly added state (`stateSchema.stateName`), confirming its registration.
|
|
15266
|
+
* @throws {Error} If the state schema is invalid, registration fails (e.g., duplicate state name), or shared state initialization encounters an error.
|
|
15267
|
+
* @example
|
|
15268
|
+
* const stateSchema = { stateName: "UserPrefs", shared: true, initialValue: { theme: "dark" } };
|
|
15269
|
+
* const stateName = addState(stateSchema);
|
|
15270
|
+
* console.log(stateName); // Outputs "UserPrefs"
|
|
15271
|
+
*/
|
|
15272
|
+
const addState = beginContext((stateSchema) => {
|
|
15273
|
+
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15274
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15275
|
+
swarm$1.loggerService.log(METHOD_NAME$S, {
|
|
15276
|
+
stateSchema,
|
|
15277
|
+
});
|
|
15278
|
+
// Register the state in the schema service
|
|
14875
15279
|
swarm$1.stateSchemaService.register(stateSchema.stateName, stateSchema);
|
|
14876
15280
|
// If the state is shared, initialize and wait for the shared state connection
|
|
14877
15281
|
if (stateSchema.shared) {
|
|
@@ -14883,7 +15287,7 @@ const addState = beginContext((stateSchema) => {
|
|
|
14883
15287
|
return stateSchema.stateName;
|
|
14884
15288
|
});
|
|
14885
15289
|
|
|
14886
|
-
const METHOD_NAME$
|
|
15290
|
+
const METHOD_NAME$R = "function.setup.addEmbedding";
|
|
14887
15291
|
/**
|
|
14888
15292
|
* Adds a new embedding engine to the embedding registry for use within the swarm system.
|
|
14889
15293
|
*
|
|
@@ -14903,7 +15307,7 @@ const METHOD_NAME$Z = "function.setup.addEmbedding";
|
|
|
14903
15307
|
const addEmbedding = beginContext((embeddingSchema) => {
|
|
14904
15308
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
14905
15309
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14906
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15310
|
+
swarm$1.loggerService.log(METHOD_NAME$R, {
|
|
14907
15311
|
embeddingSchema,
|
|
14908
15312
|
});
|
|
14909
15313
|
// Register the embedding in the validation and schema services
|
|
@@ -14913,7 +15317,7 @@ const addEmbedding = beginContext((embeddingSchema) => {
|
|
|
14913
15317
|
return embeddingSchema.embeddingName;
|
|
14914
15318
|
});
|
|
14915
15319
|
|
|
14916
|
-
const METHOD_NAME$
|
|
15320
|
+
const METHOD_NAME$Q = "function.setup.addStorage";
|
|
14917
15321
|
/**
|
|
14918
15322
|
* Adds a new storage engine to the storage registry for use within the swarm system.
|
|
14919
15323
|
*
|
|
@@ -14935,7 +15339,7 @@ const METHOD_NAME$Y = "function.setup.addStorage";
|
|
|
14935
15339
|
const addStorage = beginContext((storageSchema) => {
|
|
14936
15340
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
14937
15341
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14938
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15342
|
+
swarm$1.loggerService.log(METHOD_NAME$Q, {
|
|
14939
15343
|
storageSchema,
|
|
14940
15344
|
});
|
|
14941
15345
|
// Register the storage in the validation and schema services
|
|
@@ -14952,7 +15356,7 @@ const addStorage = beginContext((storageSchema) => {
|
|
|
14952
15356
|
});
|
|
14953
15357
|
|
|
14954
15358
|
/** @private Constant defining the method name for logging and validation context */
|
|
14955
|
-
const METHOD_NAME$
|
|
15359
|
+
const METHOD_NAME$P = "function.setup.addPolicy";
|
|
14956
15360
|
/**
|
|
14957
15361
|
* Adds a new policy for agents in the swarm system by registering it with validation and schema services.
|
|
14958
15362
|
* Registers the policy with PolicyValidationService for runtime validation and PolicySchemaService for schema management.
|
|
@@ -14968,7 +15372,7 @@ const METHOD_NAME$X = "function.setup.addPolicy";
|
|
|
14968
15372
|
const addPolicy = beginContext((policySchema) => {
|
|
14969
15373
|
// Log the policy addition attempt if enabled
|
|
14970
15374
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
14971
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15375
|
+
swarm$1.loggerService.log(METHOD_NAME$P, {
|
|
14972
15376
|
policySchema,
|
|
14973
15377
|
});
|
|
14974
15378
|
// Register the policy with PolicyValidationService for runtime validation
|
|
@@ -14979,7 +15383,7 @@ const addPolicy = beginContext((policySchema) => {
|
|
|
14979
15383
|
return policySchema.policyName;
|
|
14980
15384
|
});
|
|
14981
15385
|
|
|
14982
|
-
const METHOD_NAME$
|
|
15386
|
+
const METHOD_NAME$O = "function.test.overrideAgent";
|
|
14983
15387
|
/**
|
|
14984
15388
|
* Overrides an existing agent schema in the swarm system with a new or partial schema.
|
|
14985
15389
|
* This function updates the configuration of an agent identified by its `agentName`, applying the provided schema properties.
|
|
@@ -15003,13 +15407,13 @@ const METHOD_NAME$W = "function.test.overrideAgent";
|
|
|
15003
15407
|
*/
|
|
15004
15408
|
const overrideAgent = beginContext((agentSchema) => {
|
|
15005
15409
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15006
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15410
|
+
swarm$1.loggerService.log(METHOD_NAME$O, {
|
|
15007
15411
|
agentSchema,
|
|
15008
15412
|
});
|
|
15009
15413
|
return swarm$1.agentSchemaService.override(agentSchema.agentName, agentSchema);
|
|
15010
15414
|
});
|
|
15011
15415
|
|
|
15012
|
-
const METHOD_NAME$
|
|
15416
|
+
const METHOD_NAME$N = "function.test.overrideCompletion";
|
|
15013
15417
|
/**
|
|
15014
15418
|
* Overrides an existing completion schema in the swarm system with a new or partial schema.
|
|
15015
15419
|
* This function updates the configuration of a completion mechanism identified by its `completionName`, applying the provided schema properties.
|
|
@@ -15033,13 +15437,13 @@ const METHOD_NAME$V = "function.test.overrideCompletion";
|
|
|
15033
15437
|
*/
|
|
15034
15438
|
const overrideCompletion = beginContext((completionSchema) => {
|
|
15035
15439
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15036
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15440
|
+
swarm$1.loggerService.log(METHOD_NAME$N, {
|
|
15037
15441
|
completionSchema,
|
|
15038
15442
|
});
|
|
15039
15443
|
return swarm$1.completionSchemaService.override(completionSchema.completionName, completionSchema);
|
|
15040
15444
|
});
|
|
15041
15445
|
|
|
15042
|
-
const METHOD_NAME$
|
|
15446
|
+
const METHOD_NAME$M = "function.test.overrideEmbeding";
|
|
15043
15447
|
/**
|
|
15044
15448
|
* Overrides an existing embedding schema in the swarm system with a new or partial schema.
|
|
15045
15449
|
* This function updates the configuration of an embedding mechanism identified by its `embeddingName`, applying the provided schema properties.
|
|
@@ -15065,13 +15469,13 @@ const METHOD_NAME$U = "function.test.overrideEmbeding";
|
|
|
15065
15469
|
*/
|
|
15066
15470
|
const overrideEmbeding = beginContext((embeddingSchema) => {
|
|
15067
15471
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15068
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15472
|
+
swarm$1.loggerService.log(METHOD_NAME$M, {
|
|
15069
15473
|
embeddingSchema,
|
|
15070
15474
|
});
|
|
15071
15475
|
return swarm$1.embeddingSchemaService.override(embeddingSchema.embeddingName, embeddingSchema);
|
|
15072
15476
|
});
|
|
15073
15477
|
|
|
15074
|
-
const METHOD_NAME$
|
|
15478
|
+
const METHOD_NAME$L = "function.test.overridePolicy";
|
|
15075
15479
|
/**
|
|
15076
15480
|
* Overrides an existing policy schema in the swarm system with a new or partial schema.
|
|
15077
15481
|
* This function updates the configuration of a policy identified by its `policyName`, applying the provided schema properties.
|
|
@@ -15095,13 +15499,13 @@ const METHOD_NAME$T = "function.test.overridePolicy";
|
|
|
15095
15499
|
*/
|
|
15096
15500
|
const overridePolicy = beginContext((policySchema) => {
|
|
15097
15501
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15098
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15502
|
+
swarm$1.loggerService.log(METHOD_NAME$L, {
|
|
15099
15503
|
policySchema,
|
|
15100
15504
|
});
|
|
15101
15505
|
return swarm$1.policySchemaService.override(policySchema.policyName, policySchema);
|
|
15102
15506
|
});
|
|
15103
15507
|
|
|
15104
|
-
const METHOD_NAME$
|
|
15508
|
+
const METHOD_NAME$K = "function.test.overrideState";
|
|
15105
15509
|
/**
|
|
15106
15510
|
* Overrides an existing state schema in the swarm system with a new or partial schema.
|
|
15107
15511
|
* This function updates the configuration of a state identified by its `stateName`, applying the provided schema properties.
|
|
@@ -15126,13 +15530,13 @@ const METHOD_NAME$S = "function.test.overrideState";
|
|
|
15126
15530
|
*/
|
|
15127
15531
|
const overrideState = beginContext((stateSchema) => {
|
|
15128
15532
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15129
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15533
|
+
swarm$1.loggerService.log(METHOD_NAME$K, {
|
|
15130
15534
|
stateSchema,
|
|
15131
15535
|
});
|
|
15132
15536
|
return swarm$1.stateSchemaService.override(stateSchema.stateName, stateSchema);
|
|
15133
15537
|
});
|
|
15134
15538
|
|
|
15135
|
-
const METHOD_NAME$
|
|
15539
|
+
const METHOD_NAME$J = "function.test.overrideStorage";
|
|
15136
15540
|
/**
|
|
15137
15541
|
* Overrides an existing storage schema in the swarm system with a new or partial schema.
|
|
15138
15542
|
* This function updates the configuration of a storage identified by its `storageName`, applying the provided schema properties.
|
|
@@ -15158,13 +15562,13 @@ const METHOD_NAME$R = "function.test.overrideStorage";
|
|
|
15158
15562
|
*/
|
|
15159
15563
|
const overrideStorage = beginContext((storageSchema) => {
|
|
15160
15564
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15161
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15565
|
+
swarm$1.loggerService.log(METHOD_NAME$J, {
|
|
15162
15566
|
storageSchema,
|
|
15163
15567
|
});
|
|
15164
15568
|
return swarm$1.storageSchemaService.override(storageSchema.storageName, storageSchema);
|
|
15165
15569
|
});
|
|
15166
15570
|
|
|
15167
|
-
const METHOD_NAME$
|
|
15571
|
+
const METHOD_NAME$I = "function.test.overrideSwarm";
|
|
15168
15572
|
/**
|
|
15169
15573
|
* Overrides an existing swarm schema in the swarm system with a new or partial schema.
|
|
15170
15574
|
* This function updates the configuration of a swarm identified by its `swarmName`, applying the provided schema properties.
|
|
@@ -15188,13 +15592,13 @@ const METHOD_NAME$Q = "function.test.overrideSwarm";
|
|
|
15188
15592
|
*/
|
|
15189
15593
|
const overrideSwarm = beginContext((swarmSchema) => {
|
|
15190
15594
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15191
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15595
|
+
swarm$1.loggerService.log(METHOD_NAME$I, {
|
|
15192
15596
|
swarmSchema,
|
|
15193
15597
|
});
|
|
15194
15598
|
return swarm$1.swarmSchemaService.override(swarmSchema.swarmName, swarmSchema);
|
|
15195
15599
|
});
|
|
15196
15600
|
|
|
15197
|
-
const METHOD_NAME$
|
|
15601
|
+
const METHOD_NAME$H = "function.test.overrideTool";
|
|
15198
15602
|
/**
|
|
15199
15603
|
* Overrides an existing tool schema in the swarm system with a new or partial schema.
|
|
15200
15604
|
* This function updates the configuration of a tool identified by its `toolName`, applying the provided schema properties.
|
|
@@ -15218,13 +15622,13 @@ const METHOD_NAME$P = "function.test.overrideTool";
|
|
|
15218
15622
|
*/
|
|
15219
15623
|
const overrideTool = beginContext((toolSchema) => {
|
|
15220
15624
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15221
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15625
|
+
swarm$1.loggerService.log(METHOD_NAME$H, {
|
|
15222
15626
|
toolSchema,
|
|
15223
15627
|
});
|
|
15224
15628
|
return swarm$1.toolSchemaService.override(toolSchema.toolName, toolSchema);
|
|
15225
15629
|
});
|
|
15226
15630
|
|
|
15227
|
-
const METHOD_NAME$
|
|
15631
|
+
const METHOD_NAME$G = "function.test.overrideWiki";
|
|
15228
15632
|
/**
|
|
15229
15633
|
* Overrides an existing wiki schema in the swarm system with a new or partial schema.
|
|
15230
15634
|
* This function updates the configuration of a wiki identified by its `wikiName`, applying the provided schema properties.
|
|
@@ -15248,13 +15652,13 @@ const METHOD_NAME$O = "function.test.overrideWiki";
|
|
|
15248
15652
|
*/
|
|
15249
15653
|
const overrideWiki = beginContext((wikiSchema) => {
|
|
15250
15654
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15251
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15655
|
+
swarm$1.loggerService.log(METHOD_NAME$G, {
|
|
15252
15656
|
wikiSchema,
|
|
15253
15657
|
});
|
|
15254
15658
|
return swarm$1.wikiSchemaService.override(wikiSchema.wikiName, wikiSchema);
|
|
15255
15659
|
});
|
|
15256
15660
|
|
|
15257
|
-
const METHOD_NAME$
|
|
15661
|
+
const METHOD_NAME$F = "function.other.markOnline";
|
|
15258
15662
|
/**
|
|
15259
15663
|
* Marks a client as online in the specified swarm.
|
|
15260
15664
|
*
|
|
@@ -15266,16 +15670,16 @@ const METHOD_NAME$N = "function.other.markOnline";
|
|
|
15266
15670
|
const markOnline = async (clientId, swarmName) => {
|
|
15267
15671
|
// Log the operation if logging is enabled in the global configuration
|
|
15268
15672
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15269
|
-
swarm.loggerService.log(METHOD_NAME$
|
|
15673
|
+
swarm.loggerService.log(METHOD_NAME$F, {
|
|
15270
15674
|
clientId,
|
|
15271
15675
|
});
|
|
15272
15676
|
// Validate the swarm name
|
|
15273
|
-
swarm.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15677
|
+
swarm.swarmValidationService.validate(swarmName, METHOD_NAME$F);
|
|
15274
15678
|
// Run the operation in the method context
|
|
15275
15679
|
return await MethodContextService.runInContext(async () => {
|
|
15276
|
-
await swarm.aliveService.markOnline(clientId, swarmName, METHOD_NAME$
|
|
15680
|
+
await swarm.aliveService.markOnline(clientId, swarmName, METHOD_NAME$F);
|
|
15277
15681
|
}, {
|
|
15278
|
-
methodName: METHOD_NAME$
|
|
15682
|
+
methodName: METHOD_NAME$F,
|
|
15279
15683
|
agentName: "",
|
|
15280
15684
|
policyName: "",
|
|
15281
15685
|
stateName: "",
|
|
@@ -15285,7 +15689,7 @@ const markOnline = async (clientId, swarmName) => {
|
|
|
15285
15689
|
});
|
|
15286
15690
|
};
|
|
15287
15691
|
|
|
15288
|
-
const METHOD_NAME$
|
|
15692
|
+
const METHOD_NAME$E = "function.other.markOffline";
|
|
15289
15693
|
/**
|
|
15290
15694
|
* Marks a client as offline in the specified swarm.
|
|
15291
15695
|
*
|
|
@@ -15300,14 +15704,14 @@ const METHOD_NAME$M = "function.other.markOffline";
|
|
|
15300
15704
|
*/
|
|
15301
15705
|
const markOffline = async (clientId, swarmName) => {
|
|
15302
15706
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15303
|
-
swarm.loggerService.log(METHOD_NAME$
|
|
15707
|
+
swarm.loggerService.log(METHOD_NAME$E, {
|
|
15304
15708
|
clientId,
|
|
15305
15709
|
});
|
|
15306
|
-
swarm.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15710
|
+
swarm.swarmValidationService.validate(swarmName, METHOD_NAME$E);
|
|
15307
15711
|
return await MethodContextService.runInContext(async () => {
|
|
15308
|
-
await swarm.aliveService.markOffline(clientId, swarmName, METHOD_NAME$
|
|
15712
|
+
await swarm.aliveService.markOffline(clientId, swarmName, METHOD_NAME$E);
|
|
15309
15713
|
}, {
|
|
15310
|
-
methodName: METHOD_NAME$
|
|
15714
|
+
methodName: METHOD_NAME$E,
|
|
15311
15715
|
agentName: "",
|
|
15312
15716
|
policyName: "",
|
|
15313
15717
|
stateName: "",
|
|
@@ -15317,7 +15721,7 @@ const markOffline = async (clientId, swarmName) => {
|
|
|
15317
15721
|
});
|
|
15318
15722
|
};
|
|
15319
15723
|
|
|
15320
|
-
const METHOD_NAME$
|
|
15724
|
+
const METHOD_NAME$D = "function.commit.commitToolOutput";
|
|
15321
15725
|
/**
|
|
15322
15726
|
* Commits the output of a tool execution to the active agent in a swarm session.
|
|
15323
15727
|
*
|
|
@@ -15337,19 +15741,19 @@ const METHOD_NAME$L = "function.commit.commitToolOutput";
|
|
|
15337
15741
|
const commitToolOutput = beginContext(async (toolId, content, clientId, agentName) => {
|
|
15338
15742
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15339
15743
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15340
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15744
|
+
swarm$1.loggerService.log(METHOD_NAME$D, {
|
|
15341
15745
|
toolId,
|
|
15342
15746
|
content,
|
|
15343
15747
|
clientId,
|
|
15344
15748
|
agentName,
|
|
15345
15749
|
});
|
|
15346
15750
|
// Validate the agent, session, and swarm to ensure they exist and are accessible
|
|
15347
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
15348
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
15751
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$D);
|
|
15752
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$D);
|
|
15349
15753
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15350
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15754
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$D);
|
|
15351
15755
|
// Check if the specified agent is still the active agent in the swarm session
|
|
15352
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
15756
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$D, clientId, swarmName);
|
|
15353
15757
|
if (currentAgentName !== agentName) {
|
|
15354
15758
|
// Log a skip message if the agent has changed during the operation
|
|
15355
15759
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
@@ -15362,11 +15766,11 @@ const commitToolOutput = beginContext(async (toolId, content, clientId, agentNam
|
|
|
15362
15766
|
return;
|
|
15363
15767
|
}
|
|
15364
15768
|
// Commit the tool output to the session via the session public service
|
|
15365
|
-
await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$
|
|
15769
|
+
await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$D, clientId, swarmName);
|
|
15366
15770
|
});
|
|
15367
15771
|
|
|
15368
15772
|
/** @private Constant defining the method name for logging and validation context */
|
|
15369
|
-
const METHOD_NAME$
|
|
15773
|
+
const METHOD_NAME$C = "function.commit.commitSystemMessage";
|
|
15370
15774
|
/**
|
|
15371
15775
|
* Commits a system-generated message to the active agent in the swarm system.
|
|
15372
15776
|
* Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before committing the message.
|
|
@@ -15385,20 +15789,20 @@ const METHOD_NAME$K = "function.commit.commitSystemMessage";
|
|
|
15385
15789
|
const commitSystemMessage = beginContext(async (content, clientId, agentName) => {
|
|
15386
15790
|
// Log the commit attempt if enabled
|
|
15387
15791
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15388
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15792
|
+
swarm$1.loggerService.log(METHOD_NAME$C, {
|
|
15389
15793
|
content,
|
|
15390
15794
|
clientId,
|
|
15391
15795
|
agentName,
|
|
15392
15796
|
});
|
|
15393
15797
|
// Validate the agent exists
|
|
15394
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
15798
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$C);
|
|
15395
15799
|
// Validate the session exists and retrieve the associated swarm
|
|
15396
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
15800
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$C);
|
|
15397
15801
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15398
15802
|
// Validate the swarm configuration
|
|
15399
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15803
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$C);
|
|
15400
15804
|
// Check if the current agent matches the provided agent
|
|
15401
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
15805
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$C, clientId, swarmName);
|
|
15402
15806
|
if (currentAgentName !== agentName) {
|
|
15403
15807
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15404
15808
|
swarm$1.loggerService.log('function "commitSystemMessage" skipped due to the agent change', {
|
|
@@ -15409,11 +15813,11 @@ const commitSystemMessage = beginContext(async (content, clientId, agentName) =>
|
|
|
15409
15813
|
return;
|
|
15410
15814
|
}
|
|
15411
15815
|
// Commit the system message via SessionPublicService
|
|
15412
|
-
await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$
|
|
15816
|
+
await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$C, clientId, swarmName);
|
|
15413
15817
|
});
|
|
15414
15818
|
|
|
15415
15819
|
/** @private Constant defining the method name for logging and validation context */
|
|
15416
|
-
const METHOD_NAME$
|
|
15820
|
+
const METHOD_NAME$B = "function.commit.commitFlush";
|
|
15417
15821
|
/**
|
|
15418
15822
|
* Commits a flush of agent history for a specific client and agent in the swarm system.
|
|
15419
15823
|
* Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before flushing the history.
|
|
@@ -15430,19 +15834,19 @@ const METHOD_NAME$J = "function.commit.commitFlush";
|
|
|
15430
15834
|
const commitFlush = beginContext(async (clientId, agentName) => {
|
|
15431
15835
|
// Log the flush attempt if enabled
|
|
15432
15836
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15433
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15837
|
+
swarm$1.loggerService.log(METHOD_NAME$B, {
|
|
15434
15838
|
clientId,
|
|
15435
15839
|
agentName,
|
|
15436
15840
|
});
|
|
15437
15841
|
// Validate the agent exists
|
|
15438
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
15842
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$B);
|
|
15439
15843
|
// Validate the session exists and retrieve the associated swarm
|
|
15440
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
15844
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$B);
|
|
15441
15845
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15442
15846
|
// Validate the swarm configuration
|
|
15443
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15847
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$B);
|
|
15444
15848
|
// Check if the current agent matches the provided agent
|
|
15445
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
15849
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$B, clientId, swarmName);
|
|
15446
15850
|
if (currentAgentName !== agentName) {
|
|
15447
15851
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15448
15852
|
swarm$1.loggerService.log('function "commitFlush" skipped due to the agent change', {
|
|
@@ -15453,10 +15857,10 @@ const commitFlush = beginContext(async (clientId, agentName) => {
|
|
|
15453
15857
|
return;
|
|
15454
15858
|
}
|
|
15455
15859
|
// Commit the flush of agent history via SessionPublicService
|
|
15456
|
-
await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$
|
|
15860
|
+
await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$B, clientId, swarmName);
|
|
15457
15861
|
});
|
|
15458
15862
|
|
|
15459
|
-
const METHOD_NAME$
|
|
15863
|
+
const METHOD_NAME$A = "function.commit.commitSystemMessage";
|
|
15460
15864
|
/**
|
|
15461
15865
|
* Commits a user message to the active agent's history in a swarm session without triggering a response.
|
|
15462
15866
|
*
|
|
@@ -15475,19 +15879,19 @@ const METHOD_NAME$I = "function.commit.commitSystemMessage";
|
|
|
15475
15879
|
const commitUserMessage = beginContext(async (content, mode, clientId, agentName, payload) => {
|
|
15476
15880
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15477
15881
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15478
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15882
|
+
swarm$1.loggerService.log(METHOD_NAME$A, {
|
|
15479
15883
|
content,
|
|
15480
15884
|
clientId,
|
|
15481
15885
|
agentName,
|
|
15482
15886
|
mode,
|
|
15483
15887
|
});
|
|
15484
15888
|
// Validate the agent, session, and swarm to ensure they exist and are accessible
|
|
15485
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
15486
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
15889
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$A);
|
|
15890
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$A);
|
|
15487
15891
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15488
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15892
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$A);
|
|
15489
15893
|
// Check if the specified agent is still the active agent in the swarm session
|
|
15490
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
15894
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$A, clientId, swarmName);
|
|
15491
15895
|
if (currentAgentName !== agentName) {
|
|
15492
15896
|
// Log a skip message if the agent has changed during the operation
|
|
15493
15897
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
@@ -15500,50 +15904,18 @@ const commitUserMessage = beginContext(async (content, mode, clientId, agentName
|
|
|
15500
15904
|
}
|
|
15501
15905
|
if (payload) {
|
|
15502
15906
|
return await PayloadContextService.runInContext(async () => {
|
|
15503
|
-
await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$
|
|
15907
|
+
await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$A, clientId, swarmName);
|
|
15504
15908
|
}, {
|
|
15505
15909
|
clientId,
|
|
15506
15910
|
payload,
|
|
15507
15911
|
});
|
|
15508
15912
|
}
|
|
15509
15913
|
// Commit the user message to the agent's history via the session public service
|
|
15510
|
-
return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$
|
|
15511
|
-
});
|
|
15512
|
-
|
|
15513
|
-
const METHOD_NAME$H = "function.commit.commitToolOutputForce";
|
|
15514
|
-
/**
|
|
15515
|
-
* Commits the output of a tool execution to the active agent in a swarm session without checking the active agent.
|
|
15516
|
-
*
|
|
15517
|
-
* This function forcefully commits the tool output to the session, bypassing the check for whether the agent is still active in the swarm session.
|
|
15518
|
-
* It performs validation on the session and swarm, logs the operation if enabled, and delegates the commit operation to the session public service.
|
|
15519
|
-
* The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts, providing a clean execution environment.
|
|
15520
|
-
*
|
|
15521
|
-
* @param {string} toolId - The unique identifier of the tool whose output is being committed.
|
|
15522
|
-
* @param {string} content - The content or result of the tool execution to be committed.
|
|
15523
|
-
* @param {string} clientId - The unique identifier of the client session associated with the operation.
|
|
15524
|
-
* @returns {Promise<void>} A promise that resolves when the tool output is successfully committed.
|
|
15525
|
-
* @throws {Error} If validation fails (e.g., invalid session or swarm) or if the session public service encounters an error during the commit operation.
|
|
15526
|
-
* @example
|
|
15527
|
-
* await commitToolOutputForce("tool-123", "Tool execution result", "client-456");
|
|
15528
|
-
*/
|
|
15529
|
-
const commitToolOutputForce = beginContext(async (toolId, content, clientId) => {
|
|
15530
|
-
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15531
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15532
|
-
swarm$1.loggerService.log(METHOD_NAME$H, {
|
|
15533
|
-
toolId,
|
|
15534
|
-
content,
|
|
15535
|
-
clientId,
|
|
15536
|
-
});
|
|
15537
|
-
// Validate the session and swarm to ensure they exist and are accessible
|
|
15538
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$H);
|
|
15539
|
-
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15540
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$H);
|
|
15541
|
-
// Commit the tool output to the session via the session public service without checking the active agent
|
|
15542
|
-
await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$H, clientId, swarmName);
|
|
15914
|
+
return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$A, clientId, swarmName);
|
|
15543
15915
|
});
|
|
15544
15916
|
|
|
15545
15917
|
/** @private Constant defining the method name for logging and validation context */
|
|
15546
|
-
const METHOD_NAME$
|
|
15918
|
+
const METHOD_NAME$z = "function.commit.commitSystemMessageForce";
|
|
15547
15919
|
/**
|
|
15548
15920
|
* Forcefully commits a system-generated message to a session in the swarm system, without checking the active agent.
|
|
15549
15921
|
* Validates the session and swarm, then proceeds with committing the message regardless of the current agent state.
|
|
@@ -15562,52 +15934,20 @@ const METHOD_NAME$G = "function.commit.commitSystemMessageForce";
|
|
|
15562
15934
|
const commitSystemMessageForce = beginContext(async (content, clientId) => {
|
|
15563
15935
|
// Log the commit attempt if enabled
|
|
15564
15936
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15565
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15937
|
+
swarm$1.loggerService.log(METHOD_NAME$z, {
|
|
15566
15938
|
content,
|
|
15567
15939
|
clientId,
|
|
15568
15940
|
});
|
|
15569
15941
|
// Validate the session exists and retrieve the associated swarm
|
|
15570
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
15942
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
|
|
15571
15943
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15572
15944
|
// Validate the swarm configuration
|
|
15573
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15945
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
|
|
15574
15946
|
// Commit the system message via SessionPublicService without agent checks
|
|
15575
|
-
await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$
|
|
15576
|
-
});
|
|
15577
|
-
|
|
15578
|
-
/** @private Constant defining the method name for logging and validation context */
|
|
15579
|
-
const METHOD_NAME$F = "function.commit.commitFlushForce";
|
|
15580
|
-
/**
|
|
15581
|
-
* Forcefully commits a flush of agent history for a specific client in the swarm system, without checking the active agent.
|
|
15582
|
-
* Validates the session and swarm, then proceeds with flushing the history regardless of the current agent state.
|
|
15583
|
-
* Runs within a beginContext wrapper for execution context management, logging operations via LoggerService.
|
|
15584
|
-
* Integrates with SessionValidationService (session and swarm retrieval), SwarmValidationService (swarm validation),
|
|
15585
|
-
* SessionPublicService (history flush), and LoggerService (logging).
|
|
15586
|
-
* Unlike commitFlush, this function skips agent validation and active agent checks, providing a more aggressive flush mechanism,
|
|
15587
|
-
* analogous to commitAssistantMessageForce vs. commitAssistantMessage.
|
|
15588
|
-
*
|
|
15589
|
-
* @param {string} clientId - The ID of the client associated with the session, validated against active sessions.
|
|
15590
|
-
* @param {string} agentName - The name of the agent (unused in this implementation, included for interface consistency with commitFlush).
|
|
15591
|
-
* @returns {Promise<void>} A promise that resolves when the history flush is committed.
|
|
15592
|
-
* @throws {Error} If session or swarm validation fails, propagated from respective validation services.
|
|
15593
|
-
*/
|
|
15594
|
-
const commitFlushForce = beginContext(async (clientId) => {
|
|
15595
|
-
// Log the flush attempt if enabled
|
|
15596
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15597
|
-
swarm$1.loggerService.log(METHOD_NAME$F, {
|
|
15598
|
-
clientId,
|
|
15599
|
-
METHOD_NAME: METHOD_NAME$F,
|
|
15600
|
-
});
|
|
15601
|
-
// Validate the session exists and retrieve the associated swarm
|
|
15602
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$F);
|
|
15603
|
-
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15604
|
-
// Validate the swarm configuration
|
|
15605
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$F);
|
|
15606
|
-
// Commit the flush of agent history via SessionPublicService without agent checks
|
|
15607
|
-
await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$F, clientId, swarmName);
|
|
15947
|
+
await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$z, clientId, swarmName);
|
|
15608
15948
|
});
|
|
15609
15949
|
|
|
15610
|
-
const METHOD_NAME$
|
|
15950
|
+
const METHOD_NAME$y = "function.commit.commitSystemMessage";
|
|
15611
15951
|
/**
|
|
15612
15952
|
* Commits a user message to the active agent's history in a swarm session without triggering a response and without checking the active agent.
|
|
15613
15953
|
*
|
|
@@ -15625,29 +15965,29 @@ const METHOD_NAME$E = "function.commit.commitSystemMessage";
|
|
|
15625
15965
|
const commitUserMessageForce = beginContext(async (content, mode, clientId, payload) => {
|
|
15626
15966
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15627
15967
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15628
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
15968
|
+
swarm$1.loggerService.log(METHOD_NAME$y, {
|
|
15629
15969
|
content,
|
|
15630
15970
|
clientId,
|
|
15631
15971
|
mode,
|
|
15632
15972
|
});
|
|
15633
15973
|
// Validate the session and swarm to ensure they exist and are accessible
|
|
15634
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
15974
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
|
|
15635
15975
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15636
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15976
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
|
|
15637
15977
|
if (payload) {
|
|
15638
15978
|
return await PayloadContextService.runInContext(async () => {
|
|
15639
|
-
await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$
|
|
15979
|
+
await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$y, clientId, swarmName);
|
|
15640
15980
|
}, {
|
|
15641
15981
|
clientId,
|
|
15642
15982
|
payload,
|
|
15643
15983
|
});
|
|
15644
15984
|
}
|
|
15645
15985
|
// Commit the user message to the agent's history via the session public service without checking the active agent
|
|
15646
|
-
return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$
|
|
15986
|
+
return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$y, clientId, swarmName);
|
|
15647
15987
|
});
|
|
15648
15988
|
|
|
15649
15989
|
/** @private Constant defining the method name for logging and validation context */
|
|
15650
|
-
const METHOD_NAME$
|
|
15990
|
+
const METHOD_NAME$x = "function.commit.commitAssistantMessage";
|
|
15651
15991
|
/**
|
|
15652
15992
|
* Commits an assistant-generated message to the active agent in the swarm system.
|
|
15653
15993
|
* Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before committing the message.
|
|
@@ -15665,20 +16005,20 @@ const METHOD_NAME$D = "function.commit.commitAssistantMessage";
|
|
|
15665
16005
|
const commitAssistantMessage = beginContext(async (content, clientId, agentName) => {
|
|
15666
16006
|
// Log the commit attempt if enabled
|
|
15667
16007
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15668
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16008
|
+
swarm$1.loggerService.log(METHOD_NAME$x, {
|
|
15669
16009
|
content,
|
|
15670
16010
|
clientId,
|
|
15671
16011
|
agentName,
|
|
15672
16012
|
});
|
|
15673
16013
|
// Validate the agent exists
|
|
15674
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
16014
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$x);
|
|
15675
16015
|
// Validate the session exists and retrieve the associated swarm
|
|
15676
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16016
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
|
|
15677
16017
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15678
16018
|
// Validate the swarm configuration
|
|
15679
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16019
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
|
|
15680
16020
|
// Check if the current agent matches the provided agent
|
|
15681
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16021
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$x, clientId, swarmName);
|
|
15682
16022
|
if (currentAgentName !== agentName) {
|
|
15683
16023
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15684
16024
|
swarm$1.loggerService.log('function "commitAssistantMessage" skipped due to the agent change', {
|
|
@@ -15689,11 +16029,11 @@ const commitAssistantMessage = beginContext(async (content, clientId, agentName)
|
|
|
15689
16029
|
return;
|
|
15690
16030
|
}
|
|
15691
16031
|
// Commit the assistant message via SessionPublicService
|
|
15692
|
-
await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$
|
|
16032
|
+
await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$x, clientId, swarmName);
|
|
15693
16033
|
});
|
|
15694
16034
|
|
|
15695
16035
|
/** @private Constant defining the method name for logging and validation context */
|
|
15696
|
-
const METHOD_NAME$
|
|
16036
|
+
const METHOD_NAME$w = "function.commit.commitAssistantMessageForce";
|
|
15697
16037
|
/**
|
|
15698
16038
|
* Forcefully commits an assistant-generated message to a session in the swarm system, without checking the active agent.
|
|
15699
16039
|
* Validates the session and swarm, then proceeds with committing the message regardless of the current agent state.
|
|
@@ -15712,21 +16052,21 @@ const METHOD_NAME$C = "function.commit.commitAssistantMessageForce";
|
|
|
15712
16052
|
const commitAssistantMessageForce = beginContext(async (content, clientId) => {
|
|
15713
16053
|
// Log the commit attempt if enabled
|
|
15714
16054
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15715
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16055
|
+
swarm$1.loggerService.log(METHOD_NAME$w, {
|
|
15716
16056
|
content,
|
|
15717
16057
|
clientId,
|
|
15718
16058
|
});
|
|
15719
16059
|
// Validate the session exists and retrieve the associated swarm
|
|
15720
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16060
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
|
|
15721
16061
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15722
16062
|
// Validate the swarm configuration
|
|
15723
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16063
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
|
|
15724
16064
|
// Commit the assistant message via SessionPublicService without agent checks
|
|
15725
|
-
await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$
|
|
16065
|
+
await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$w, clientId, swarmName);
|
|
15726
16066
|
});
|
|
15727
16067
|
|
|
15728
16068
|
/** @private Constant defining the method name for logging and validation context */
|
|
15729
|
-
const METHOD_NAME$
|
|
16069
|
+
const METHOD_NAME$v = "function.commit.cancelOutput";
|
|
15730
16070
|
/**
|
|
15731
16071
|
* Cancels the awaited output for a specific client and agent by emitting an empty string.
|
|
15732
16072
|
* Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before cancellation.
|
|
@@ -15742,19 +16082,19 @@ const METHOD_NAME$B = "function.commit.cancelOutput";
|
|
|
15742
16082
|
const cancelOutput = beginContext(async (clientId, agentName) => {
|
|
15743
16083
|
// Log the cancellation attempt if enabled
|
|
15744
16084
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15745
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16085
|
+
swarm$1.loggerService.log(METHOD_NAME$v, {
|
|
15746
16086
|
clientId,
|
|
15747
16087
|
agentName,
|
|
15748
16088
|
});
|
|
15749
16089
|
// Validate the agent exists
|
|
15750
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
16090
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$v);
|
|
15751
16091
|
// Validate the session exists and retrieve the associated swarm
|
|
15752
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16092
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
|
|
15753
16093
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15754
16094
|
// Validate the swarm configuration
|
|
15755
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16095
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
|
|
15756
16096
|
// Check if the current agent matches the provided agent
|
|
15757
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16097
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$v, clientId, swarmName);
|
|
15758
16098
|
if (currentAgentName !== agentName) {
|
|
15759
16099
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15760
16100
|
swarm$1.loggerService.log('function "cancelOutput" skipped due to the agent change', {
|
|
@@ -15765,11 +16105,11 @@ const cancelOutput = beginContext(async (clientId, agentName) => {
|
|
|
15765
16105
|
return;
|
|
15766
16106
|
}
|
|
15767
16107
|
// Perform the output cancellation via SwarmPublicService
|
|
15768
|
-
await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$
|
|
16108
|
+
await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$v, clientId, swarmName);
|
|
15769
16109
|
});
|
|
15770
16110
|
|
|
15771
16111
|
/** @private Constant defining the method name for logging and validation context */
|
|
15772
|
-
const METHOD_NAME$
|
|
16112
|
+
const METHOD_NAME$u = "function.commit.cancelOutputForce";
|
|
15773
16113
|
/**
|
|
15774
16114
|
* Forcefully cancels the awaited output for a specific client by emitting an empty string, without checking the active agent.
|
|
15775
16115
|
* Validates the session and swarm, then proceeds with cancellation regardless of the current agent state.
|
|
@@ -15786,20 +16126,20 @@ const METHOD_NAME$A = "function.commit.cancelOutputForce";
|
|
|
15786
16126
|
const cancelOutputForce = beginContext(async (clientId) => {
|
|
15787
16127
|
// Log the cancellation attempt if enabled
|
|
15788
16128
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15789
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16129
|
+
swarm$1.loggerService.log(METHOD_NAME$u, {
|
|
15790
16130
|
clientId,
|
|
15791
16131
|
});
|
|
15792
16132
|
// Validate the session exists and retrieve the associated swarm
|
|
15793
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16133
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$u);
|
|
15794
16134
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15795
16135
|
// Validate the swarm configuration
|
|
15796
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16136
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$u);
|
|
15797
16137
|
// Perform the output cancellation via SwarmPublicService without agent checks
|
|
15798
|
-
await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$
|
|
16138
|
+
await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$u, clientId, swarmName);
|
|
15799
16139
|
});
|
|
15800
16140
|
|
|
15801
16141
|
/** @private Constant defining the method name for logging and validation context */
|
|
15802
|
-
const METHOD_NAME$
|
|
16142
|
+
const METHOD_NAME$t = "function.commit.commitStopTools";
|
|
15803
16143
|
/**
|
|
15804
16144
|
* Prevents the next tool from being executed for a specific client and agent in the swarm system.
|
|
15805
16145
|
* Validates the agent, session, and swarm, ensuring the current agent matches the provided agent before stopping tool execution.
|
|
@@ -15816,19 +16156,19 @@ const METHOD_NAME$z = "function.commit.commitStopTools";
|
|
|
15816
16156
|
const commitStopTools = beginContext(async (clientId, agentName) => {
|
|
15817
16157
|
// Log the stop tools attempt if enabled
|
|
15818
16158
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15819
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16159
|
+
swarm$1.loggerService.log(METHOD_NAME$t, {
|
|
15820
16160
|
clientId,
|
|
15821
16161
|
agentName,
|
|
15822
16162
|
});
|
|
15823
16163
|
// Validate the agent exists
|
|
15824
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
16164
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$t);
|
|
15825
16165
|
// Validate the session exists and retrieve the associated swarm
|
|
15826
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16166
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
|
|
15827
16167
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15828
16168
|
// Validate the swarm configuration
|
|
15829
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16169
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$t);
|
|
15830
16170
|
// Check if the current agent matches the provided agent
|
|
15831
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16171
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$t, clientId, swarmName);
|
|
15832
16172
|
if (currentAgentName !== agentName) {
|
|
15833
16173
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15834
16174
|
swarm$1.loggerService.log('function "commitStopTools" skipped due to the agent change', {
|
|
@@ -15839,11 +16179,11 @@ const commitStopTools = beginContext(async (clientId, agentName) => {
|
|
|
15839
16179
|
return;
|
|
15840
16180
|
}
|
|
15841
16181
|
// Commit the stop of the next tool execution via SessionPublicService
|
|
15842
|
-
await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$
|
|
16182
|
+
await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$t, clientId, swarmName);
|
|
15843
16183
|
});
|
|
15844
16184
|
|
|
15845
16185
|
/** @private Constant defining the method name for logging and validation context */
|
|
15846
|
-
const METHOD_NAME$
|
|
16186
|
+
const METHOD_NAME$s = "function.commit.commitStopToolsForce";
|
|
15847
16187
|
/**
|
|
15848
16188
|
* Forcefully prevents the next tool from being executed for a specific client in the swarm system, without checking the active agent.
|
|
15849
16189
|
* Validates the session and swarm, then proceeds with stopping tool execution regardless of the current agent state.
|
|
@@ -15861,105 +16201,21 @@ const METHOD_NAME$y = "function.commit.commitStopToolsForce";
|
|
|
15861
16201
|
const commitStopToolsForce = beginContext(async (clientId) => {
|
|
15862
16202
|
// Log the stop tools attempt if enabled
|
|
15863
16203
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15864
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16204
|
+
swarm$1.loggerService.log(METHOD_NAME$s, {
|
|
15865
16205
|
clientId,
|
|
15866
|
-
METHOD_NAME: METHOD_NAME$
|
|
16206
|
+
METHOD_NAME: METHOD_NAME$s,
|
|
15867
16207
|
});
|
|
15868
16208
|
// Validate the session exists and retrieve the associated swarm
|
|
15869
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16209
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$s);
|
|
15870
16210
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15871
16211
|
// Validate the swarm configuration
|
|
15872
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16212
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$s);
|
|
15873
16213
|
// Commit the stop of the next tool execution via SessionPublicService without agent checks
|
|
15874
|
-
await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$
|
|
15875
|
-
});
|
|
15876
|
-
|
|
15877
|
-
const METHOD_NAME$x = "function.target.emitForce";
|
|
15878
|
-
/**
|
|
15879
|
-
* Emits a string as model output without executing an incoming message or checking the active agent.
|
|
15880
|
-
*
|
|
15881
|
-
* This function directly emits a provided string as output from the swarm session, bypassing message execution and agent activity checks.
|
|
15882
|
-
* It is designed exclusively for sessions established via `makeConnection`, ensuring compatibility with its connection model.
|
|
15883
|
-
* The execution is wrapped in `beginContext` for a clean environment, validates the session and swarm, and throws an error if the session mode
|
|
15884
|
-
* is not "makeConnection". The operation is logged if enabled, and resolves when the content is successfully emitted.
|
|
15885
|
-
*
|
|
15886
|
-
* @param {string} content - The content to be emitted as the model output.
|
|
15887
|
-
* @param {string} clientId - The unique identifier of the client session emitting the content.
|
|
15888
|
-
* @returns {Promise<void>} A promise that resolves when the content is emitted.
|
|
15889
|
-
* @throws {Error} If the session mode is not "makeConnection", or if session or swarm validation fails.
|
|
15890
|
-
* @example
|
|
15891
|
-
* await emitForce("Direct output", "client-123"); // Emits "Direct output" in a makeConnection session
|
|
15892
|
-
*/
|
|
15893
|
-
const emitForce = beginContext(async (content, clientId) => {
|
|
15894
|
-
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15895
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15896
|
-
swarm$1.loggerService.log(METHOD_NAME$x, {
|
|
15897
|
-
content,
|
|
15898
|
-
clientId,
|
|
15899
|
-
});
|
|
15900
|
-
// Validate the session and swarm
|
|
15901
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$x);
|
|
15902
|
-
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15903
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$x);
|
|
15904
|
-
// Emit the content directly via the session public service
|
|
15905
|
-
return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$x, clientId, swarmName);
|
|
15906
|
-
});
|
|
15907
|
-
|
|
15908
|
-
const METHOD_NAME$w = "function.target.executeForce";
|
|
15909
|
-
/**
|
|
15910
|
-
* 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.
|
|
15911
|
-
*
|
|
15912
|
-
* This function executes a command or message on behalf of the active agent within a swarm session, designed for scenarios like reviewing tool output
|
|
15913
|
-
* or initiating a model-to-client conversation. Unlike `execute`, it does not check if the agent is currently active, ensuring execution even if the
|
|
15914
|
-
* agent has changed or is inactive. It validates the session and swarm, executes the content with performance tracking and event bus notifications,
|
|
15915
|
-
* and is wrapped in `beginContext` for a clean environment and `ExecutionContextService` for metadata tracking.
|
|
15916
|
-
*
|
|
15917
|
-
* @param {string} content - The content or command to be executed by the active agent.
|
|
15918
|
-
* @param {string} clientId - The unique identifier of the client session requesting the execution.
|
|
15919
|
-
* @returns {Promise<string>} A promise that resolves to the result of the execution.
|
|
15920
|
-
* @throws {Error} If session or swarm validation fails, or if the execution process encounters an error.
|
|
15921
|
-
* @example
|
|
15922
|
-
* const result = await executeForce("Force this execution", "client-123");
|
|
15923
|
-
* console.log(result); // Outputs the agent's response regardless of its active state
|
|
15924
|
-
*/
|
|
15925
|
-
const executeForce = beginContext(async (content, clientId) => {
|
|
15926
|
-
const executionId = functoolsKit.randomString();
|
|
15927
|
-
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
15928
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15929
|
-
swarm$1.loggerService.log(METHOD_NAME$w, {
|
|
15930
|
-
content,
|
|
15931
|
-
clientId,
|
|
15932
|
-
executionId,
|
|
15933
|
-
});
|
|
15934
|
-
// Validate the session and swarm
|
|
15935
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
|
|
15936
|
-
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15937
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
|
|
15938
|
-
// Execute the command within an execution context with performance tracking
|
|
15939
|
-
return ExecutionContextService.runInContext(async () => {
|
|
15940
|
-
let isFinished = false;
|
|
15941
|
-
swarm$1.perfService.startExecution(executionId, clientId, content.length);
|
|
15942
|
-
try {
|
|
15943
|
-
swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
|
|
15944
|
-
const result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$w, clientId, swarmName);
|
|
15945
|
-
isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
|
|
15946
|
-
swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
|
|
15947
|
-
return result;
|
|
15948
|
-
}
|
|
15949
|
-
finally {
|
|
15950
|
-
if (!isFinished) {
|
|
15951
|
-
swarm$1.perfService.endExecution(executionId, clientId, 0);
|
|
15952
|
-
}
|
|
15953
|
-
}
|
|
15954
|
-
}, {
|
|
15955
|
-
clientId,
|
|
15956
|
-
executionId,
|
|
15957
|
-
processId: GLOBAL_CONFIG.CC_PROCESS_UUID,
|
|
15958
|
-
});
|
|
16214
|
+
await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$s, clientId, swarmName);
|
|
15959
16215
|
});
|
|
15960
16216
|
|
|
15961
16217
|
/** @constant {string} METHOD_NAME - The name of the method used for logging and validation */
|
|
15962
|
-
const METHOD_NAME$
|
|
16218
|
+
const METHOD_NAME$r = "function.target.question";
|
|
15963
16219
|
/**
|
|
15964
16220
|
* Initiates a question process within a chat context
|
|
15965
16221
|
* @function question
|
|
@@ -15971,21 +16227,21 @@ const METHOD_NAME$v = "function.target.question";
|
|
|
15971
16227
|
*/
|
|
15972
16228
|
const question = beginContext(async (message, clientId, agentName, wikiName) => {
|
|
15973
16229
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15974
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16230
|
+
swarm$1.loggerService.log(METHOD_NAME$r, {
|
|
15975
16231
|
message,
|
|
15976
16232
|
clientId,
|
|
15977
16233
|
agentName,
|
|
15978
16234
|
wikiName,
|
|
15979
16235
|
});
|
|
15980
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
15981
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
16236
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
|
|
16237
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$r);
|
|
15982
16238
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
15983
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
15984
|
-
swarm$1.wikiValidationService.validate(wikiName, METHOD_NAME$
|
|
16239
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
|
|
16240
|
+
swarm$1.wikiValidationService.validate(wikiName, METHOD_NAME$r);
|
|
15985
16241
|
if (!swarm$1.agentValidationService.hasWiki(agentName, wikiName)) {
|
|
15986
|
-
throw new Error(`agent-swarm ${METHOD_NAME$
|
|
16242
|
+
throw new Error(`agent-swarm ${METHOD_NAME$r} ${wikiName} not registered in ${agentName}`);
|
|
15987
16243
|
}
|
|
15988
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16244
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$r, clientId, swarmName);
|
|
15989
16245
|
if (currentAgentName !== agentName) {
|
|
15990
16246
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15991
16247
|
swarm$1.loggerService.log('function "question" skipped due to the agent change', {
|
|
@@ -16008,7 +16264,7 @@ const question = beginContext(async (message, clientId, agentName, wikiName) =>
|
|
|
16008
16264
|
});
|
|
16009
16265
|
|
|
16010
16266
|
/** @constant {string} METHOD_NAME - The name of the method used for logging and validation */
|
|
16011
|
-
const METHOD_NAME$
|
|
16267
|
+
const METHOD_NAME$q = "function.target.questionForce";
|
|
16012
16268
|
/**
|
|
16013
16269
|
* Initiates a forced question process within a chat context
|
|
16014
16270
|
* @function questionForce
|
|
@@ -16019,17 +16275,17 @@ const METHOD_NAME$u = "function.target.questionForce";
|
|
|
16019
16275
|
*/
|
|
16020
16276
|
const questionForce = beginContext(async (message, clientId, wikiName) => {
|
|
16021
16277
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16022
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16278
|
+
swarm$1.loggerService.log(METHOD_NAME$q, {
|
|
16023
16279
|
message,
|
|
16024
16280
|
clientId,
|
|
16025
16281
|
wikiName,
|
|
16026
16282
|
});
|
|
16027
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16283
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
|
|
16028
16284
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
16029
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16030
|
-
swarm$1.wikiValidationService.validate(wikiName, METHOD_NAME$
|
|
16285
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$q);
|
|
16286
|
+
swarm$1.wikiValidationService.validate(wikiName, METHOD_NAME$q);
|
|
16031
16287
|
const { getChat, callbacks } = swarm$1.wikiSchemaService.get(wikiName);
|
|
16032
|
-
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16288
|
+
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$q, clientId, swarmName);
|
|
16033
16289
|
const args = {
|
|
16034
16290
|
clientId,
|
|
16035
16291
|
message,
|
|
@@ -16041,7 +16297,7 @@ const questionForce = beginContext(async (message, clientId, wikiName) => {
|
|
|
16041
16297
|
return await getChat(args);
|
|
16042
16298
|
});
|
|
16043
16299
|
|
|
16044
|
-
const METHOD_NAME$
|
|
16300
|
+
const METHOD_NAME$p = "function.target.disposeConnection";
|
|
16045
16301
|
/**
|
|
16046
16302
|
* Disposes of a client session and all related resources within a swarm.
|
|
16047
16303
|
*
|
|
@@ -16058,10 +16314,10 @@ const METHOD_NAME$t = "function.target.disposeConnection";
|
|
|
16058
16314
|
* @example
|
|
16059
16315
|
* await disposeConnection("client-123", "TaskSwarm");
|
|
16060
16316
|
*/
|
|
16061
|
-
const disposeConnection = beginContext(async (clientId, swarmName, methodName = METHOD_NAME$
|
|
16317
|
+
const disposeConnection = beginContext(async (clientId, swarmName, methodName = METHOD_NAME$p) => {
|
|
16062
16318
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16063
16319
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16064
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16320
|
+
swarm$1.loggerService.log(METHOD_NAME$p, {
|
|
16065
16321
|
clientId,
|
|
16066
16322
|
swarmName,
|
|
16067
16323
|
});
|
|
@@ -16133,7 +16389,7 @@ const disposeConnection = beginContext(async (clientId, swarmName, methodName =
|
|
|
16133
16389
|
PersistMemoryAdapter.dispose(clientId);
|
|
16134
16390
|
});
|
|
16135
16391
|
|
|
16136
|
-
const METHOD_NAME$
|
|
16392
|
+
const METHOD_NAME$o = "function.target.makeAutoDispose";
|
|
16137
16393
|
/**
|
|
16138
16394
|
* Default timeout in seconds before auto-dispose is triggered.
|
|
16139
16395
|
* @constant {number}
|
|
@@ -16164,7 +16420,7 @@ const DEFAULT_TIMEOUT = 15 * 60;
|
|
|
16164
16420
|
const makeAutoDispose = beginContext((clientId, swarmName, { timeoutSeconds = DEFAULT_TIMEOUT, onDestroy, } = {}) => {
|
|
16165
16421
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16166
16422
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16167
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16423
|
+
swarm$1.loggerService.log(METHOD_NAME$o, {
|
|
16168
16424
|
clientId,
|
|
16169
16425
|
swarmName,
|
|
16170
16426
|
});
|
|
@@ -16197,7 +16453,7 @@ const makeAutoDispose = beginContext((clientId, swarmName, { timeoutSeconds = DE
|
|
|
16197
16453
|
};
|
|
16198
16454
|
});
|
|
16199
16455
|
|
|
16200
|
-
const METHOD_NAME$
|
|
16456
|
+
const METHOD_NAME$n = "function.target.execute";
|
|
16201
16457
|
/**
|
|
16202
16458
|
* Sends a message to the active agent in a swarm session as if it originated from the client side.
|
|
16203
16459
|
*
|
|
@@ -16219,19 +16475,19 @@ const execute = beginContext(async (content, clientId, agentName) => {
|
|
|
16219
16475
|
const executionId = functoolsKit.randomString();
|
|
16220
16476
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16221
16477
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16222
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16478
|
+
swarm$1.loggerService.log(METHOD_NAME$n, {
|
|
16223
16479
|
content,
|
|
16224
16480
|
clientId,
|
|
16225
16481
|
agentName,
|
|
16226
16482
|
executionId,
|
|
16227
16483
|
});
|
|
16228
16484
|
// Validate the agent, session, and swarm
|
|
16229
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
16230
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16485
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$n);
|
|
16486
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$n);
|
|
16231
16487
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
16232
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16488
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$n);
|
|
16233
16489
|
// Check if the specified agent is still the active agent
|
|
16234
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16490
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$n, clientId, swarmName);
|
|
16235
16491
|
if (currentAgentName !== agentName) {
|
|
16236
16492
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16237
16493
|
swarm$1.loggerService.log('function "execute" skipped due to the agent change', {
|
|
@@ -16250,7 +16506,7 @@ const execute = beginContext(async (content, clientId, agentName) => {
|
|
|
16250
16506
|
agentName,
|
|
16251
16507
|
swarmName,
|
|
16252
16508
|
});
|
|
16253
|
-
const result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$
|
|
16509
|
+
const result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$n, clientId, swarmName);
|
|
16254
16510
|
isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
|
|
16255
16511
|
swarm$1.busService.commitExecutionEnd(clientId, {
|
|
16256
16512
|
agentName,
|
|
@@ -16270,7 +16526,7 @@ const execute = beginContext(async (content, clientId, agentName) => {
|
|
|
16270
16526
|
});
|
|
16271
16527
|
});
|
|
16272
16528
|
|
|
16273
|
-
const METHOD_NAME$
|
|
16529
|
+
const METHOD_NAME$m = "function.target.emit";
|
|
16274
16530
|
/**
|
|
16275
16531
|
* Emits a string as model output without executing an incoming message, with agent activity validation.
|
|
16276
16532
|
*
|
|
@@ -16290,18 +16546,18 @@ const METHOD_NAME$q = "function.target.emit";
|
|
|
16290
16546
|
const emit = beginContext(async (content, clientId, agentName) => {
|
|
16291
16547
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16292
16548
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16293
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16549
|
+
swarm$1.loggerService.log(METHOD_NAME$m, {
|
|
16294
16550
|
content,
|
|
16295
16551
|
clientId,
|
|
16296
16552
|
agentName,
|
|
16297
16553
|
});
|
|
16298
16554
|
// Validate the agent, session, and swarm
|
|
16299
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
16300
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16555
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$m);
|
|
16556
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$m);
|
|
16301
16557
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
16302
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16558
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$m);
|
|
16303
16559
|
// Check if the specified agent is still the active agent
|
|
16304
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16560
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$m, clientId, swarmName);
|
|
16305
16561
|
if (currentAgentName !== agentName) {
|
|
16306
16562
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16307
16563
|
swarm$1.loggerService.log('function "emit" skipped due to the agent change', {
|
|
@@ -16312,10 +16568,10 @@ const emit = beginContext(async (content, clientId, agentName) => {
|
|
|
16312
16568
|
return;
|
|
16313
16569
|
}
|
|
16314
16570
|
// Emit the content directly via the session public service
|
|
16315
|
-
return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$
|
|
16571
|
+
return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$m, clientId, swarmName);
|
|
16316
16572
|
});
|
|
16317
16573
|
|
|
16318
|
-
const METHOD_NAME$
|
|
16574
|
+
const METHOD_NAME$l = "function.target.notify";
|
|
16319
16575
|
/**
|
|
16320
16576
|
* Sends a notification message as output from the swarm session without executing an incoming message.
|
|
16321
16577
|
*
|
|
@@ -16335,23 +16591,23 @@ const METHOD_NAME$p = "function.target.notify";
|
|
|
16335
16591
|
const notify = beginContext(async (content, clientId, agentName) => {
|
|
16336
16592
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16337
16593
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16338
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16594
|
+
swarm$1.loggerService.log(METHOD_NAME$l, {
|
|
16339
16595
|
content,
|
|
16340
16596
|
clientId,
|
|
16341
16597
|
agentName,
|
|
16342
16598
|
});
|
|
16343
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16599
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$l);
|
|
16344
16600
|
// Check if the session mode is "makeConnection"
|
|
16345
16601
|
if (swarm$1.sessionValidationService.getSessionMode(clientId) !==
|
|
16346
16602
|
"makeConnection") {
|
|
16347
16603
|
throw new Error(`agent-swarm-kit notify session is not makeConnection clientId=${clientId}`);
|
|
16348
16604
|
}
|
|
16349
16605
|
// Validate the agent, session, and swarm
|
|
16350
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
16606
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$l);
|
|
16351
16607
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
16352
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16608
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$l);
|
|
16353
16609
|
// Check if the specified agent is still the active agent
|
|
16354
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16610
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$l, clientId, swarmName);
|
|
16355
16611
|
if (currentAgentName !== agentName) {
|
|
16356
16612
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16357
16613
|
swarm$1.loggerService.log('function "notify" skipped due to the agent change', {
|
|
@@ -16362,10 +16618,10 @@ const notify = beginContext(async (content, clientId, agentName) => {
|
|
|
16362
16618
|
return;
|
|
16363
16619
|
}
|
|
16364
16620
|
// Notify the content directly via the session public service
|
|
16365
|
-
return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$
|
|
16621
|
+
return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$l, clientId, swarmName);
|
|
16366
16622
|
});
|
|
16367
16623
|
|
|
16368
|
-
const METHOD_NAME$
|
|
16624
|
+
const METHOD_NAME$k = "function.target.notifyForce";
|
|
16369
16625
|
/**
|
|
16370
16626
|
* Sends a notification message as output from the swarm session without executing an incoming message.
|
|
16371
16627
|
*
|
|
@@ -16384,11 +16640,11 @@ const METHOD_NAME$o = "function.target.notifyForce";
|
|
|
16384
16640
|
const notifyForce = beginContext(async (content, clientId) => {
|
|
16385
16641
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16386
16642
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16387
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16643
|
+
swarm$1.loggerService.log(METHOD_NAME$k, {
|
|
16388
16644
|
content,
|
|
16389
16645
|
clientId,
|
|
16390
16646
|
});
|
|
16391
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16647
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$k);
|
|
16392
16648
|
// Check if the session mode is "makeConnection"
|
|
16393
16649
|
if (swarm$1.sessionValidationService.getSessionMode(clientId) !==
|
|
16394
16650
|
"makeConnection") {
|
|
@@ -16396,12 +16652,12 @@ const notifyForce = beginContext(async (content, clientId) => {
|
|
|
16396
16652
|
}
|
|
16397
16653
|
// Validate the agent, session, and swarm
|
|
16398
16654
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
16399
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16655
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$k);
|
|
16400
16656
|
// Notify the content directly via the session public service
|
|
16401
|
-
return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$
|
|
16657
|
+
return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$k, clientId, swarmName);
|
|
16402
16658
|
});
|
|
16403
16659
|
|
|
16404
|
-
const METHOD_NAME$
|
|
16660
|
+
const METHOD_NAME$j = "function.target.runStateless";
|
|
16405
16661
|
/**
|
|
16406
16662
|
* Executes a message statelessly with an agent in a swarm session, bypassing chat history.
|
|
16407
16663
|
*
|
|
@@ -16424,19 +16680,19 @@ const runStateless = beginContext(async (content, clientId, agentName) => {
|
|
|
16424
16680
|
const executionId = functoolsKit.randomString();
|
|
16425
16681
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16426
16682
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16427
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16683
|
+
swarm$1.loggerService.log(METHOD_NAME$j, {
|
|
16428
16684
|
content,
|
|
16429
16685
|
clientId,
|
|
16430
16686
|
agentName,
|
|
16431
16687
|
executionId,
|
|
16432
16688
|
});
|
|
16433
16689
|
// Validate the agent, session, and swarm
|
|
16434
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
16435
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16690
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$j);
|
|
16691
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$j);
|
|
16436
16692
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
16437
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16693
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$j);
|
|
16438
16694
|
// Check if the specified agent is still the active agent
|
|
16439
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16695
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$j, clientId, swarmName);
|
|
16440
16696
|
if (currentAgentName !== agentName) {
|
|
16441
16697
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16442
16698
|
swarm$1.loggerService.log('function "runStateless" skipped due to the agent change', {
|
|
@@ -16455,7 +16711,7 @@ const runStateless = beginContext(async (content, clientId, agentName) => {
|
|
|
16455
16711
|
agentName,
|
|
16456
16712
|
swarmName,
|
|
16457
16713
|
});
|
|
16458
|
-
const result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$
|
|
16714
|
+
const result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$j, clientId, swarmName);
|
|
16459
16715
|
isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
|
|
16460
16716
|
swarm$1.busService.commitExecutionEnd(clientId, {
|
|
16461
16717
|
agentName,
|
|
@@ -16475,7 +16731,7 @@ const runStateless = beginContext(async (content, clientId, agentName) => {
|
|
|
16475
16731
|
});
|
|
16476
16732
|
});
|
|
16477
16733
|
|
|
16478
|
-
const METHOD_NAME$
|
|
16734
|
+
const METHOD_NAME$i = "function.target.runStatelessForce";
|
|
16479
16735
|
/**
|
|
16480
16736
|
* Executes a message statelessly with the active agent in a swarm session, bypassing chat history and forcing execution regardless of agent activity.
|
|
16481
16737
|
*
|
|
@@ -16496,22 +16752,22 @@ const runStatelessForce = beginContext(async (content, clientId) => {
|
|
|
16496
16752
|
const executionId = functoolsKit.randomString();
|
|
16497
16753
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16498
16754
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16499
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16755
|
+
swarm$1.loggerService.log(METHOD_NAME$i, {
|
|
16500
16756
|
content,
|
|
16501
16757
|
clientId,
|
|
16502
16758
|
executionId,
|
|
16503
16759
|
});
|
|
16504
16760
|
// Validate the session and swarm
|
|
16505
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16761
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$i);
|
|
16506
16762
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
16507
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16763
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$i);
|
|
16508
16764
|
// Execute the command statelessly within an execution context with performance tracking
|
|
16509
16765
|
return ExecutionContextService.runInContext(async () => {
|
|
16510
16766
|
let isFinished = false;
|
|
16511
16767
|
swarm$1.perfService.startExecution(executionId, clientId, content.length);
|
|
16512
16768
|
try {
|
|
16513
16769
|
swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
|
|
16514
|
-
const result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$
|
|
16770
|
+
const result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$i, clientId, swarmName);
|
|
16515
16771
|
isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
|
|
16516
16772
|
swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
|
|
16517
16773
|
return result;
|
|
@@ -16538,7 +16794,7 @@ const SCHEDULED_DELAY$1 = 1000;
|
|
|
16538
16794
|
* @constant {number}
|
|
16539
16795
|
*/
|
|
16540
16796
|
const RATE_DELAY = 10000;
|
|
16541
|
-
const METHOD_NAME$
|
|
16797
|
+
const METHOD_NAME$h = "function.target.makeConnection";
|
|
16542
16798
|
/**
|
|
16543
16799
|
* Internal implementation of the connection factory for a client to a swarm.
|
|
16544
16800
|
*
|
|
@@ -16553,21 +16809,21 @@ const METHOD_NAME$l = "function.target.makeConnection";
|
|
|
16553
16809
|
const makeConnectionInternal = (connector, clientId, swarmName) => {
|
|
16554
16810
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16555
16811
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16556
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
16812
|
+
swarm$1.loggerService.log(METHOD_NAME$h, {
|
|
16557
16813
|
clientId,
|
|
16558
16814
|
swarmName,
|
|
16559
16815
|
});
|
|
16560
16816
|
// Validate the swarm and initialize the session
|
|
16561
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
16817
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$h);
|
|
16562
16818
|
swarm$1.sessionValidationService.addSession(clientId, swarmName, "makeConnection");
|
|
16563
16819
|
// Create a queued send function using the session public service
|
|
16564
|
-
const send = functoolsKit.queued(swarm$1.sessionPublicService.connect(connector, METHOD_NAME$
|
|
16820
|
+
const send = functoolsKit.queued(swarm$1.sessionPublicService.connect(connector, METHOD_NAME$h, clientId, swarmName));
|
|
16565
16821
|
// Return a wrapped send function with validation and agent context
|
|
16566
16822
|
return (async (outgoing) => {
|
|
16567
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
16823
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$h);
|
|
16568
16824
|
return await send({
|
|
16569
16825
|
data: outgoing,
|
|
16570
|
-
agentName: await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
16826
|
+
agentName: await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$h, clientId, swarmName),
|
|
16571
16827
|
clientId,
|
|
16572
16828
|
});
|
|
16573
16829
|
});
|
|
@@ -16650,13 +16906,13 @@ makeConnection.scheduled = (connector, clientId, swarmName, { delay = SCHEDULED_
|
|
|
16650
16906
|
await online();
|
|
16651
16907
|
if (payload) {
|
|
16652
16908
|
return await PayloadContextService.runInContext(async () => {
|
|
16653
|
-
await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$
|
|
16909
|
+
await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$h, clientId, swarmName);
|
|
16654
16910
|
}, {
|
|
16655
16911
|
clientId,
|
|
16656
16912
|
payload,
|
|
16657
16913
|
});
|
|
16658
16914
|
}
|
|
16659
|
-
await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$
|
|
16915
|
+
await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$h, clientId, swarmName);
|
|
16660
16916
|
}),
|
|
16661
16917
|
delay,
|
|
16662
16918
|
});
|
|
@@ -16719,7 +16975,7 @@ makeConnection.rate = (connector, clientId, swarmName, { delay = RATE_DELAY } =
|
|
|
16719
16975
|
};
|
|
16720
16976
|
};
|
|
16721
16977
|
|
|
16722
|
-
const METHOD_NAME$
|
|
16978
|
+
const METHOD_NAME$g = "function.target.complete";
|
|
16723
16979
|
/**
|
|
16724
16980
|
* Time-to-live for the complete function in milliseconds.
|
|
16725
16981
|
* Defines how long the cached complete function remains valid before expiring.
|
|
@@ -16761,7 +17017,7 @@ const createComplete = functoolsKit.ttl((clientId, swarmName) => functoolsKit.qu
|
|
|
16761
17017
|
*
|
|
16762
17018
|
* @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
|
|
16763
17019
|
*/
|
|
16764
|
-
const createGc$
|
|
17020
|
+
const createGc$2 = functoolsKit.singleshot(async () => {
|
|
16765
17021
|
setInterval(createComplete.gc, COMPLETE_GC);
|
|
16766
17022
|
});
|
|
16767
17023
|
/**
|
|
@@ -16785,7 +17041,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
|
|
|
16785
17041
|
const executionId = functoolsKit.randomString();
|
|
16786
17042
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16787
17043
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16788
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17044
|
+
swarm$1.loggerService.log(METHOD_NAME$g, {
|
|
16789
17045
|
content,
|
|
16790
17046
|
clientId,
|
|
16791
17047
|
executionId,
|
|
@@ -16794,7 +17050,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
|
|
|
16794
17050
|
await markOnline(clientId, swarmName);
|
|
16795
17051
|
// Set up the TTL-limited, queued execution function and garbage collector
|
|
16796
17052
|
const run = await createComplete(clientId, swarmName);
|
|
16797
|
-
createGc$
|
|
17053
|
+
createGc$2();
|
|
16798
17054
|
// Execute the command within an execution context with performance tracking
|
|
16799
17055
|
const handleRun = async () => {
|
|
16800
17056
|
return await ExecutionContextService.runInContext(async () => {
|
|
@@ -16803,7 +17059,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
|
|
|
16803
17059
|
swarm$1.navigationValidationService.beginMonit(clientId, swarmName);
|
|
16804
17060
|
try {
|
|
16805
17061
|
swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
|
|
16806
|
-
const result = await run(METHOD_NAME$
|
|
17062
|
+
const result = await run(METHOD_NAME$g, content);
|
|
16807
17063
|
isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
|
|
16808
17064
|
swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
|
|
16809
17065
|
return result;
|
|
@@ -16833,7 +17089,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
|
|
|
16833
17089
|
* @constant {number}
|
|
16834
17090
|
*/
|
|
16835
17091
|
const SCHEDULED_DELAY = 1000;
|
|
16836
|
-
const METHOD_NAME$
|
|
17092
|
+
const METHOD_NAME$f = "function.target.session";
|
|
16837
17093
|
/**
|
|
16838
17094
|
* Internal implementation of the session factory for a client and swarm.
|
|
16839
17095
|
*
|
|
@@ -16848,23 +17104,23 @@ const sessionInternal = (clientId, swarmName, { onDispose = () => { } } = {}) =>
|
|
|
16848
17104
|
const executionId = functoolsKit.randomString();
|
|
16849
17105
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
16850
17106
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
16851
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17107
|
+
swarm$1.loggerService.log(METHOD_NAME$f, {
|
|
16852
17108
|
clientId,
|
|
16853
17109
|
swarmName,
|
|
16854
17110
|
executionId,
|
|
16855
17111
|
});
|
|
16856
17112
|
// Validate the swarm and initialize the session
|
|
16857
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
17113
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$f);
|
|
16858
17114
|
swarm$1.sessionValidationService.addSession(clientId, swarmName, "session");
|
|
16859
17115
|
const complete = functoolsKit.queued(async (content) => {
|
|
16860
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17116
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$f);
|
|
16861
17117
|
return ExecutionContextService.runInContext(async () => {
|
|
16862
17118
|
let isFinished = false;
|
|
16863
17119
|
swarm$1.perfService.startExecution(executionId, clientId, content.length);
|
|
16864
17120
|
swarm$1.navigationValidationService.beginMonit(clientId, swarmName);
|
|
16865
17121
|
try {
|
|
16866
17122
|
swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
|
|
16867
|
-
const result = await swarm$1.sessionPublicService.execute(content, "user", METHOD_NAME$
|
|
17123
|
+
const result = await swarm$1.sessionPublicService.execute(content, "user", METHOD_NAME$f, clientId, swarmName);
|
|
16868
17124
|
isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
|
|
16869
17125
|
swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
|
|
16870
17126
|
return result;
|
|
@@ -16885,7 +17141,7 @@ const sessionInternal = (clientId, swarmName, { onDispose = () => { } } = {}) =>
|
|
|
16885
17141
|
return await complete(content);
|
|
16886
17142
|
}),
|
|
16887
17143
|
dispose: async () => {
|
|
16888
|
-
await disposeConnection(clientId, swarmName, METHOD_NAME$
|
|
17144
|
+
await disposeConnection(clientId, swarmName, METHOD_NAME$f);
|
|
16889
17145
|
await onDispose();
|
|
16890
17146
|
},
|
|
16891
17147
|
};
|
|
@@ -16985,13 +17241,13 @@ session.scheduled = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose }
|
|
|
16985
17241
|
await online();
|
|
16986
17242
|
if (payload) {
|
|
16987
17243
|
return await PayloadContextService.runInContext(async () => {
|
|
16988
|
-
return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$
|
|
17244
|
+
return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$f, clientId, swarmName);
|
|
16989
17245
|
}, {
|
|
16990
17246
|
clientId,
|
|
16991
17247
|
payload,
|
|
16992
17248
|
});
|
|
16993
17249
|
}
|
|
16994
|
-
return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$
|
|
17250
|
+
return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$f, clientId, swarmName);
|
|
16995
17251
|
}),
|
|
16996
17252
|
delay,
|
|
16997
17253
|
});
|
|
@@ -17071,7 +17327,7 @@ session.rate = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose } = {}
|
|
|
17071
17327
|
};
|
|
17072
17328
|
|
|
17073
17329
|
/** @private Constant defining the method name for logging purposes */
|
|
17074
|
-
const METHOD_NAME$
|
|
17330
|
+
const METHOD_NAME$e = "function.common.hasSession";
|
|
17075
17331
|
/**
|
|
17076
17332
|
* Checks if a session exists for the given client ID.
|
|
17077
17333
|
*
|
|
@@ -17083,35 +17339,11 @@ const METHOD_NAME$i = "function.common.hasSession";
|
|
|
17083
17339
|
*/
|
|
17084
17340
|
const hasSession = (clientId) => {
|
|
17085
17341
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17086
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17342
|
+
swarm$1.loggerService.log(METHOD_NAME$e, { clientId });
|
|
17087
17343
|
return swarm$1.sessionValidationService.hasSession(clientId);
|
|
17088
17344
|
};
|
|
17089
17345
|
|
|
17090
|
-
|
|
17091
|
-
* @private Constant defining the method name for logging and validation purposes.
|
|
17092
|
-
* Used as an identifier in log messages and validation checks to track calls to `hasNavigation`.
|
|
17093
|
-
*/
|
|
17094
|
-
const METHOD_NAME$h = "function.common.hasNavigation";
|
|
17095
|
-
/**
|
|
17096
|
-
* Checks if a specific agent is part of the navigation route for a given client.
|
|
17097
|
-
* Validates the agent and client session, retrieves the associated swarm, and queries the navigation route.
|
|
17098
|
-
* Logs the operation if enabled by global configuration.
|
|
17099
|
-
* @param {string} clientId - The unique identifier of the client whose navigation route is being checked.
|
|
17100
|
-
* @param {AgentName} agentName - The name of the agent to check within the navigation route.
|
|
17101
|
-
* @returns {Promise<boolean>} A promise resolving to true if the agent is in the navigation route, false otherwise.
|
|
17102
|
-
*/
|
|
17103
|
-
const hasNavigation = async (clientId, agentName) => {
|
|
17104
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17105
|
-
swarm$1.loggerService.log(METHOD_NAME$h, { clientId });
|
|
17106
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$h);
|
|
17107
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$h);
|
|
17108
|
-
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17109
|
-
return swarm$1.navigationValidationService
|
|
17110
|
-
.getNavigationRoute(clientId, swarmName)
|
|
17111
|
-
.has(agentName);
|
|
17112
|
-
};
|
|
17113
|
-
|
|
17114
|
-
const METHOD_NAME$g = "function.common.getAgentName";
|
|
17346
|
+
const METHOD_NAME$d = "function.common.getAgentName";
|
|
17115
17347
|
/**
|
|
17116
17348
|
* Retrieves the name of the active agent for a given client session in a swarm.
|
|
17117
17349
|
*
|
|
@@ -17129,18 +17361,18 @@ const METHOD_NAME$g = "function.common.getAgentName";
|
|
|
17129
17361
|
const getAgentName = beginContext(async (clientId) => {
|
|
17130
17362
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17131
17363
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17132
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17364
|
+
swarm$1.loggerService.log(METHOD_NAME$d, {
|
|
17133
17365
|
clientId,
|
|
17134
17366
|
});
|
|
17135
17367
|
// Validate the session and swarm to ensure they exist and are accessible
|
|
17136
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17368
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$d);
|
|
17137
17369
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17138
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
17370
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$d);
|
|
17139
17371
|
// Retrieve the active agent name via the swarm public service
|
|
17140
|
-
return await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
17372
|
+
return await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$d, clientId, swarmName);
|
|
17141
17373
|
});
|
|
17142
17374
|
|
|
17143
|
-
const METHOD_NAME$
|
|
17375
|
+
const METHOD_NAME$c = "function.common.getAgentHistory";
|
|
17144
17376
|
/**
|
|
17145
17377
|
* Retrieves the history prepared for a specific agent, incorporating rescue algorithm tweaks.
|
|
17146
17378
|
*
|
|
@@ -17159,22 +17391,22 @@ const METHOD_NAME$f = "function.common.getAgentHistory";
|
|
|
17159
17391
|
const getAgentHistory = beginContext(async (clientId, agentName) => {
|
|
17160
17392
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17161
17393
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17162
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17394
|
+
swarm$1.loggerService.log(METHOD_NAME$c, {
|
|
17163
17395
|
clientId,
|
|
17164
17396
|
agentName,
|
|
17165
17397
|
});
|
|
17166
17398
|
// Validate the session and agent to ensure they exist and are accessible
|
|
17167
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17168
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
17399
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$c);
|
|
17400
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$c);
|
|
17169
17401
|
// Retrieve the agent's prompt configuration from the agent schema service
|
|
17170
17402
|
const { prompt } = swarm$1.agentSchemaService.get(agentName);
|
|
17171
17403
|
// Fetch the agent's history using the prompt and rescue tweaks via the history public service
|
|
17172
|
-
const history = await swarm$1.historyPublicService.toArrayForAgent(prompt, METHOD_NAME$
|
|
17404
|
+
const history = await swarm$1.historyPublicService.toArrayForAgent(prompt, METHOD_NAME$c, clientId, agentName);
|
|
17173
17405
|
// Return a shallow copy of the history array
|
|
17174
17406
|
return [...history];
|
|
17175
17407
|
});
|
|
17176
17408
|
|
|
17177
|
-
const METHOD_NAME$
|
|
17409
|
+
const METHOD_NAME$b = "function.common.getSessionMode";
|
|
17178
17410
|
/**
|
|
17179
17411
|
* Retrieves the session mode for a given client session in a swarm.
|
|
17180
17412
|
*
|
|
@@ -17192,18 +17424,18 @@ const METHOD_NAME$e = "function.common.getSessionMode";
|
|
|
17192
17424
|
const getSessionMode = beginContext(async (clientId) => {
|
|
17193
17425
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17194
17426
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17195
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17427
|
+
swarm$1.loggerService.log(METHOD_NAME$b, {
|
|
17196
17428
|
clientId,
|
|
17197
17429
|
});
|
|
17198
17430
|
// Validate the session and swarm to ensure they exist and are accessible
|
|
17199
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17431
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$b);
|
|
17200
17432
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17201
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
17433
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$b);
|
|
17202
17434
|
// Retrieve the session mode from the session validation service
|
|
17203
17435
|
return swarm$1.sessionValidationService.getSessionMode(clientId);
|
|
17204
17436
|
});
|
|
17205
17437
|
|
|
17206
|
-
const METHOD_NAME$
|
|
17438
|
+
const METHOD_NAME$a = "function.common.getSessionContext";
|
|
17207
17439
|
/**
|
|
17208
17440
|
* Retrieves the session context for the current execution environment.
|
|
17209
17441
|
*
|
|
@@ -17220,7 +17452,7 @@ const METHOD_NAME$d = "function.common.getSessionContext";
|
|
|
17220
17452
|
const getSessionContext = async () => {
|
|
17221
17453
|
// Log the operation if logging is enabled in GLOBAL_CONFIG
|
|
17222
17454
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17223
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17455
|
+
swarm$1.loggerService.log(METHOD_NAME$a);
|
|
17224
17456
|
// Determine the method context, if active
|
|
17225
17457
|
const methodContext = MethodContextService.hasContext()
|
|
17226
17458
|
? swarm$1.methodContextService.context
|
|
@@ -17244,7 +17476,7 @@ const getSessionContext = async () => {
|
|
|
17244
17476
|
* @private Constant defining the method name for logging purposes.
|
|
17245
17477
|
* Used as an identifier in log messages to track calls to `getNavigationRoute`.
|
|
17246
17478
|
*/
|
|
17247
|
-
const METHOD_NAME$
|
|
17479
|
+
const METHOD_NAME$9 = "function.common.getNavigationRoute";
|
|
17248
17480
|
/**
|
|
17249
17481
|
* Retrieves the navigation route for a given client and swarm.
|
|
17250
17482
|
* Delegates to `NavigationValidationService.getNavigationRoute` to obtain a `Set` of visited agent names,
|
|
@@ -17255,75 +17487,15 @@ const METHOD_NAME$c = "function.common.getNavigationRoute";
|
|
|
17255
17487
|
*/
|
|
17256
17488
|
const getNavigationRoute = (clientId, swarmName) => {
|
|
17257
17489
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17258
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17490
|
+
swarm$1.loggerService.log(METHOD_NAME$9, {
|
|
17259
17491
|
clientId,
|
|
17260
17492
|
swarmName,
|
|
17261
17493
|
});
|
|
17262
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17494
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$9);
|
|
17263
17495
|
return swarm$1.navigationValidationService.getNavigationRoute(clientId, swarmName);
|
|
17264
17496
|
};
|
|
17265
17497
|
|
|
17266
|
-
const METHOD_NAME$
|
|
17267
|
-
/**
|
|
17268
|
-
* Retrieves the raw, unmodified history for a given client session.
|
|
17269
|
-
*
|
|
17270
|
-
* This function fetches the complete history associated with a client’s active agent in a swarm session, without any filtering or modifications.
|
|
17271
|
-
* It is wrapped in `beginContext` for a clean execution environment and logs the operation if enabled via `GLOBAL_CONFIG`. The function validates
|
|
17272
|
-
* the session and swarm, retrieves the current agent, and uses `historyPublicService.toArrayForRaw` to obtain the raw history as an array.
|
|
17273
|
-
* The result is a fresh copy of the history array.
|
|
17274
|
-
*
|
|
17275
|
-
* @param {string} clientId - The unique identifier of the client session whose raw history is to be retrieved.
|
|
17276
|
-
* @param {string} [methodName="function.history.getRawHistory"] - The name of the calling method, used for validation and logging (defaults to `METHOD_NAME`).
|
|
17277
|
-
* @returns {Promise<object[]>} A promise that resolves to an array containing the raw history entries.
|
|
17278
|
-
* @throws {Error} If session or swarm validation fails, or if history retrieval encounters an issue.
|
|
17279
|
-
* @example
|
|
17280
|
-
* const rawHistory = await getRawHistory("client-123");
|
|
17281
|
-
* console.log(rawHistory); // Outputs the full raw history array
|
|
17282
|
-
*/
|
|
17283
|
-
const getRawHistory = beginContext(async (clientId, methodName = METHOD_NAME$b) => {
|
|
17284
|
-
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17285
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17286
|
-
swarm$1.loggerService.log(METHOD_NAME$b, {
|
|
17287
|
-
clientId,
|
|
17288
|
-
});
|
|
17289
|
-
// Validate the session and swarm
|
|
17290
|
-
swarm$1.sessionValidationService.validate(clientId, methodName);
|
|
17291
|
-
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17292
|
-
swarm$1.swarmValidationService.validate(swarmName, methodName);
|
|
17293
|
-
// Get the current agent and fetch raw history
|
|
17294
|
-
const agentName = await swarm$1.swarmPublicService.getAgentName(methodName, clientId, swarmName);
|
|
17295
|
-
const history = await swarm$1.historyPublicService.toArrayForRaw(methodName, clientId, agentName);
|
|
17296
|
-
return [...history];
|
|
17297
|
-
});
|
|
17298
|
-
|
|
17299
|
-
const METHOD_NAME$a = "function.history.getLastUserMessage";
|
|
17300
|
-
/**
|
|
17301
|
-
* Retrieves the content of the most recent user message from a client's session history.
|
|
17302
|
-
*
|
|
17303
|
-
* 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
|
|
17304
|
-
* is "user". It is wrapped in `beginContext` for a clean execution environment and logs the operation if enabled via `GLOBAL_CONFIG`. The result is
|
|
17305
|
-
* the content of the last user message as a string, or `null` if no matching user message exists in the history.
|
|
17306
|
-
*
|
|
17307
|
-
* @param {string} clientId - The unique identifier of the client session whose last user message is to be retrieved.
|
|
17308
|
-
* @returns {Promise<string | null>} A promise that resolves to the content of the last user message, or `null` if none is found.
|
|
17309
|
-
* @throws {Error} If `getRawHistory` fails due to session validation or history retrieval issues.
|
|
17310
|
-
* @example
|
|
17311
|
-
* const lastMessage = await getLastUserMessage("client-123");
|
|
17312
|
-
* console.log(lastMessage); // Outputs the last user message or null
|
|
17313
|
-
*/
|
|
17314
|
-
const getLastUserMessage = beginContext(async (clientId) => {
|
|
17315
|
-
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17316
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17317
|
-
swarm$1.loggerService.log(METHOD_NAME$a, {
|
|
17318
|
-
clientId,
|
|
17319
|
-
});
|
|
17320
|
-
// Fetch raw history and find the last user message
|
|
17321
|
-
const history = await getRawHistory(clientId, METHOD_NAME$a);
|
|
17322
|
-
const last = history.findLast(({ role, mode }) => role === "user" && mode === "user");
|
|
17323
|
-
return last ? last.content : null;
|
|
17324
|
-
});
|
|
17325
|
-
|
|
17326
|
-
const METHOD_NAME$9 = "function.history.getUserHistory";
|
|
17498
|
+
const METHOD_NAME$8 = "function.history.getUserHistory";
|
|
17327
17499
|
/**
|
|
17328
17500
|
* Retrieves the user-specific history entries for a given client session.
|
|
17329
17501
|
*
|
|
@@ -17341,15 +17513,15 @@ const METHOD_NAME$9 = "function.history.getUserHistory";
|
|
|
17341
17513
|
const getUserHistory = beginContext(async (clientId) => {
|
|
17342
17514
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17343
17515
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17344
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17516
|
+
swarm$1.loggerService.log(METHOD_NAME$8, {
|
|
17345
17517
|
clientId,
|
|
17346
17518
|
});
|
|
17347
17519
|
// Fetch raw history and filter for user role and mode
|
|
17348
|
-
const history = await getRawHistory(clientId, METHOD_NAME$
|
|
17520
|
+
const history = await getRawHistory(clientId, METHOD_NAME$8);
|
|
17349
17521
|
return history.filter(({ role, mode }) => role === "user" && mode === "user");
|
|
17350
17522
|
});
|
|
17351
17523
|
|
|
17352
|
-
const METHOD_NAME$
|
|
17524
|
+
const METHOD_NAME$7 = "function.history.getAssistantHistory";
|
|
17353
17525
|
/**
|
|
17354
17526
|
* Retrieves the assistant's history entries for a given client session.
|
|
17355
17527
|
*
|
|
@@ -17367,15 +17539,15 @@ const METHOD_NAME$8 = "function.history.getAssistantHistory";
|
|
|
17367
17539
|
const getAssistantHistory = beginContext(async (clientId) => {
|
|
17368
17540
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17369
17541
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17370
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17542
|
+
swarm$1.loggerService.log(METHOD_NAME$7, {
|
|
17371
17543
|
clientId,
|
|
17372
17544
|
});
|
|
17373
17545
|
// Fetch raw history and filter for assistant role
|
|
17374
|
-
const history = await getRawHistory(clientId, METHOD_NAME$
|
|
17546
|
+
const history = await getRawHistory(clientId, METHOD_NAME$7);
|
|
17375
17547
|
return history.filter(({ role }) => role === "assistant");
|
|
17376
17548
|
});
|
|
17377
17549
|
|
|
17378
|
-
const METHOD_NAME$
|
|
17550
|
+
const METHOD_NAME$6 = "function.history.getLastAssistantMessage";
|
|
17379
17551
|
/**
|
|
17380
17552
|
* Retrieves the content of the most recent assistant message from a client's session history.
|
|
17381
17553
|
*
|
|
@@ -17393,16 +17565,16 @@ const METHOD_NAME$7 = "function.history.getLastAssistantMessage";
|
|
|
17393
17565
|
const getLastAssistantMessage = beginContext(async (clientId) => {
|
|
17394
17566
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17395
17567
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17396
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17568
|
+
swarm$1.loggerService.log(METHOD_NAME$6, {
|
|
17397
17569
|
clientId,
|
|
17398
17570
|
});
|
|
17399
17571
|
// Fetch raw history and find the last assistant message
|
|
17400
|
-
const history = await getRawHistory(clientId, METHOD_NAME$
|
|
17572
|
+
const history = await getRawHistory(clientId, METHOD_NAME$6);
|
|
17401
17573
|
const last = history.findLast(({ role }) => role === "assistant");
|
|
17402
17574
|
return last ? last.content : null;
|
|
17403
17575
|
});
|
|
17404
17576
|
|
|
17405
|
-
const METHOD_NAME$
|
|
17577
|
+
const METHOD_NAME$5 = "function.history.getLastSystemMessage";
|
|
17406
17578
|
/**
|
|
17407
17579
|
* Retrieves the content of the most recent system message from a client's session history.
|
|
17408
17580
|
*
|
|
@@ -17420,16 +17592,16 @@ const METHOD_NAME$6 = "function.history.getLastSystemMessage";
|
|
|
17420
17592
|
const getLastSystemMessage = beginContext(async (clientId) => {
|
|
17421
17593
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17422
17594
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17423
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17595
|
+
swarm$1.loggerService.log(METHOD_NAME$5, {
|
|
17424
17596
|
clientId,
|
|
17425
17597
|
});
|
|
17426
17598
|
// Fetch raw history and find the last system message
|
|
17427
|
-
const history = await getRawHistory(clientId, METHOD_NAME$
|
|
17599
|
+
const history = await getRawHistory(clientId, METHOD_NAME$5);
|
|
17428
17600
|
const last = history.findLast(({ role }) => role === "system");
|
|
17429
17601
|
return last ? last.content : null;
|
|
17430
17602
|
});
|
|
17431
17603
|
|
|
17432
|
-
const METHOD_NAME$
|
|
17604
|
+
const METHOD_NAME$4 = "function.event.listenEvent";
|
|
17433
17605
|
/**
|
|
17434
17606
|
* Set of reserved event source names that cannot be used for custom events.
|
|
17435
17607
|
* @constant {Set<EventSource>}
|
|
@@ -17465,7 +17637,7 @@ const DISALLOWED_EVENT_SOURCE_LIST$2 = new Set([
|
|
|
17465
17637
|
const event = beginContext((clientId, topicName, payload) => {
|
|
17466
17638
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17467
17639
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17468
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17640
|
+
swarm$1.loggerService.log(METHOD_NAME$4, {
|
|
17469
17641
|
clientId,
|
|
17470
17642
|
});
|
|
17471
17643
|
// Check if the topic name is reserved
|
|
@@ -17480,7 +17652,7 @@ const event = beginContext((clientId, topicName, payload) => {
|
|
|
17480
17652
|
});
|
|
17481
17653
|
});
|
|
17482
17654
|
|
|
17483
|
-
const METHOD_NAME$
|
|
17655
|
+
const METHOD_NAME$3 = "function.event.listenEvent";
|
|
17484
17656
|
/**
|
|
17485
17657
|
* Set of reserved event source names that cannot be used for custom event topics.
|
|
17486
17658
|
* @constant {Set<EventSource>}
|
|
@@ -17532,7 +17704,7 @@ const validateClientId$g = (clientId) => {
|
|
|
17532
17704
|
const listenEvent = beginContext((clientId, topicName, fn) => {
|
|
17533
17705
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17534
17706
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17535
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17707
|
+
swarm$1.loggerService.log(METHOD_NAME$3, {
|
|
17536
17708
|
clientId,
|
|
17537
17709
|
});
|
|
17538
17710
|
// Check if the topic name is reserved
|
|
@@ -17545,7 +17717,7 @@ const listenEvent = beginContext((clientId, topicName, fn) => {
|
|
|
17545
17717
|
return swarm$1.busService.subscribe(clientId, topicName, functoolsKit.queued(async ({ payload }) => await fn(payload)));
|
|
17546
17718
|
});
|
|
17547
17719
|
|
|
17548
|
-
const METHOD_NAME$
|
|
17720
|
+
const METHOD_NAME$2 = "function.event.listenEventOnce";
|
|
17549
17721
|
/**
|
|
17550
17722
|
* Set of reserved event source names that cannot be used for custom event topics.
|
|
17551
17723
|
* @constant {Set<EventSource>}
|
|
@@ -17603,7 +17775,7 @@ const validateClientId$f = (clientId) => {
|
|
|
17603
17775
|
const listenEventOnce = beginContext((clientId, topicName, filterFn, fn) => {
|
|
17604
17776
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17605
17777
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17606
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17778
|
+
swarm$1.loggerService.log(METHOD_NAME$2, {
|
|
17607
17779
|
clientId,
|
|
17608
17780
|
});
|
|
17609
17781
|
// Check if the topic name is reserved
|
|
@@ -17616,19 +17788,19 @@ const listenEventOnce = beginContext((clientId, topicName, filterFn, fn) => {
|
|
|
17616
17788
|
return swarm$1.busService.once(clientId, topicName, ({ payload }) => filterFn(payload), functoolsKit.queued(async ({ payload }) => await fn(payload)));
|
|
17617
17789
|
});
|
|
17618
17790
|
|
|
17619
|
-
const METHOD_NAME$
|
|
17791
|
+
const METHOD_NAME$1 = "function.navigate.changeToAgent";
|
|
17620
17792
|
/**
|
|
17621
17793
|
* Time-to-live for the change agent function in milliseconds.
|
|
17622
17794
|
* Defines how long the cached change agent function remains valid before expiring.
|
|
17623
17795
|
* @constant {number}
|
|
17624
17796
|
*/
|
|
17625
|
-
const CHANGE_AGENT_TTL$
|
|
17797
|
+
const CHANGE_AGENT_TTL$1 = 15 * 60 * 1000;
|
|
17626
17798
|
/**
|
|
17627
17799
|
* Garbage collection interval for the change agent function in milliseconds.
|
|
17628
17800
|
* Specifies the frequency at which expired TTL entries are cleaned up.
|
|
17629
17801
|
* @constant {number}
|
|
17630
17802
|
*/
|
|
17631
|
-
const CHANGE_AGENT_GC$
|
|
17803
|
+
const CHANGE_AGENT_GC$1 = 60 * 1000;
|
|
17632
17804
|
/**
|
|
17633
17805
|
* Creates a change agent function with time-to-live (TTL) and queuing capabilities.
|
|
17634
17806
|
*
|
|
@@ -17652,7 +17824,7 @@ const createChangeToAgent = functoolsKit.ttl((clientId) => functoolsKit.queued(a
|
|
|
17652
17824
|
}));
|
|
17653
17825
|
{
|
|
17654
17826
|
// Dispose of the current agent's resources and set up the new agent
|
|
17655
|
-
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
17827
|
+
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1, clientId, swarmName);
|
|
17656
17828
|
await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
|
|
17657
17829
|
await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
|
|
17658
17830
|
await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
|
|
@@ -17662,7 +17834,7 @@ const createChangeToAgent = functoolsKit.ttl((clientId) => functoolsKit.queued(a
|
|
|
17662
17834
|
return true;
|
|
17663
17835
|
}), {
|
|
17664
17836
|
key: ([clientId]) => `${clientId}`,
|
|
17665
|
-
timeout: CHANGE_AGENT_TTL$
|
|
17837
|
+
timeout: CHANGE_AGENT_TTL$1,
|
|
17666
17838
|
});
|
|
17667
17839
|
/**
|
|
17668
17840
|
* Creates a garbage collector for the change agent function.
|
|
@@ -17672,8 +17844,8 @@ const createChangeToAgent = functoolsKit.ttl((clientId) => functoolsKit.queued(a
|
|
|
17672
17844
|
* @function
|
|
17673
17845
|
* @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
|
|
17674
17846
|
*/
|
|
17675
|
-
const createGc$
|
|
17676
|
-
setInterval(createChangeToAgent.gc, CHANGE_AGENT_GC$
|
|
17847
|
+
const createGc$1 = functoolsKit.singleshot(async () => {
|
|
17848
|
+
setInterval(createChangeToAgent.gc, CHANGE_AGENT_GC$1);
|
|
17677
17849
|
});
|
|
17678
17850
|
/**
|
|
17679
17851
|
* Changes the active agent for a given client session in a swarm.
|
|
@@ -17692,16 +17864,16 @@ const createGc$2 = functoolsKit.singleshot(async () => {
|
|
|
17692
17864
|
const changeToAgent = beginContext(async (agentName, clientId) => {
|
|
17693
17865
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17694
17866
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17695
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17867
|
+
swarm$1.loggerService.log(METHOD_NAME$1, {
|
|
17696
17868
|
agentName,
|
|
17697
17869
|
clientId,
|
|
17698
17870
|
});
|
|
17699
17871
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17700
17872
|
{
|
|
17701
17873
|
// Validate session, agent, and dependencies
|
|
17702
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17703
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
17704
|
-
const activeAgent = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
17874
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1);
|
|
17875
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1);
|
|
17876
|
+
const activeAgent = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1, clientId, swarmName);
|
|
17705
17877
|
if (!swarm$1.agentValidationService.hasDependency(activeAgent, agentName)) {
|
|
17706
17878
|
console.error(`agent-swarm missing dependency detected for activeAgent=${activeAgent} dependencyAgent=${agentName}`);
|
|
17707
17879
|
}
|
|
@@ -17718,23 +17890,23 @@ const changeToAgent = beginContext(async (agentName, clientId) => {
|
|
|
17718
17890
|
}
|
|
17719
17891
|
// Execute the agent change with TTL and queuing
|
|
17720
17892
|
const run = await createChangeToAgent(clientId);
|
|
17721
|
-
createGc$
|
|
17722
|
-
return await run(METHOD_NAME$
|
|
17893
|
+
createGc$1();
|
|
17894
|
+
return await run(METHOD_NAME$1, agentName, swarmName);
|
|
17723
17895
|
});
|
|
17724
17896
|
|
|
17725
|
-
const METHOD_NAME
|
|
17897
|
+
const METHOD_NAME = "function.navigate.changeToPrevAgent";
|
|
17726
17898
|
/**
|
|
17727
17899
|
* Time-to-live for the change agent function in milliseconds.
|
|
17728
17900
|
* Defines how long the cached change agent function remains valid before expiring.
|
|
17729
17901
|
* @constant {number}
|
|
17730
17902
|
*/
|
|
17731
|
-
const CHANGE_AGENT_TTL
|
|
17903
|
+
const CHANGE_AGENT_TTL = 15 * 60 * 1000;
|
|
17732
17904
|
/**
|
|
17733
17905
|
* Garbage collection interval for the change agent function in milliseconds.
|
|
17734
17906
|
* Specifies the frequency at which expired TTL entries are cleaned up.
|
|
17735
17907
|
* @constant {number}
|
|
17736
17908
|
*/
|
|
17737
|
-
const CHANGE_AGENT_GC
|
|
17909
|
+
const CHANGE_AGENT_GC = 60 * 1000;
|
|
17738
17910
|
/**
|
|
17739
17911
|
* Creates a change agent function with time-to-live (TTL) and queuing capabilities for switching to the previous agent.
|
|
17740
17912
|
*
|
|
@@ -17757,7 +17929,7 @@ const createChangeToPrevAgent = functoolsKit.ttl((clientId) => functoolsKit.queu
|
|
|
17757
17929
|
}));
|
|
17758
17930
|
{
|
|
17759
17931
|
// Dispose of the current agent's resources and set up the new agent
|
|
17760
|
-
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME
|
|
17932
|
+
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME, clientId, swarmName);
|
|
17761
17933
|
await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
|
|
17762
17934
|
await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
|
|
17763
17935
|
await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
|
|
@@ -17767,7 +17939,7 @@ const createChangeToPrevAgent = functoolsKit.ttl((clientId) => functoolsKit.queu
|
|
|
17767
17939
|
return true;
|
|
17768
17940
|
}), {
|
|
17769
17941
|
key: ([clientId]) => `${clientId}`,
|
|
17770
|
-
timeout: CHANGE_AGENT_TTL
|
|
17942
|
+
timeout: CHANGE_AGENT_TTL,
|
|
17771
17943
|
});
|
|
17772
17944
|
/**
|
|
17773
17945
|
* Creates a garbage collector for the change agent function.
|
|
@@ -17777,8 +17949,8 @@ const createChangeToPrevAgent = functoolsKit.ttl((clientId) => functoolsKit.queu
|
|
|
17777
17949
|
* @function
|
|
17778
17950
|
* @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
|
|
17779
17951
|
*/
|
|
17780
|
-
const createGc
|
|
17781
|
-
setInterval(createChangeToPrevAgent.gc, CHANGE_AGENT_GC
|
|
17952
|
+
const createGc = functoolsKit.singleshot(async () => {
|
|
17953
|
+
setInterval(createChangeToPrevAgent.gc, CHANGE_AGENT_GC);
|
|
17782
17954
|
});
|
|
17783
17955
|
/**
|
|
17784
17956
|
* Navigates back to the previous or default agent for a given client session in a swarm.
|
|
@@ -17794,110 +17966,20 @@ const createGc$1 = functoolsKit.singleshot(async () => {
|
|
|
17794
17966
|
* await changeToPrevAgent("client-123");
|
|
17795
17967
|
*/
|
|
17796
17968
|
const changeToPrevAgent = beginContext(async (clientId) => {
|
|
17797
|
-
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17798
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17799
|
-
swarm$1.loggerService.log(METHOD_NAME$1, {
|
|
17800
|
-
clientId,
|
|
17801
|
-
});
|
|
17802
|
-
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17803
|
-
const agentName = await swarm$1.swarmPublicService.navigationPop(METHOD_NAME$1, clientId, swarmName);
|
|
17804
|
-
{
|
|
17805
|
-
// Validate session and the retrieved agent
|
|
17806
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1);
|
|
17807
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1);
|
|
17808
|
-
}
|
|
17809
|
-
// Execute the agent change with TTL and queuing
|
|
17810
|
-
const run = await createChangeToPrevAgent(clientId);
|
|
17811
|
-
createGc$1();
|
|
17812
|
-
return await run(METHOD_NAME$1, agentName, swarmName);
|
|
17813
|
-
});
|
|
17814
|
-
|
|
17815
|
-
const METHOD_NAME = "function.navigate.changeToDefaultAgent";
|
|
17816
|
-
/**
|
|
17817
|
-
* Time-to-live for the change agent function in milliseconds.
|
|
17818
|
-
* Defines how long the cached change agent function remains valid before expiring.
|
|
17819
|
-
* @constant {number}
|
|
17820
|
-
*/
|
|
17821
|
-
const CHANGE_AGENT_TTL = 15 * 60 * 1000;
|
|
17822
|
-
/**
|
|
17823
|
-
* Garbage collection interval for the change agent function in milliseconds.
|
|
17824
|
-
* Specifies the frequency at which expired TTL entries are cleaned up.
|
|
17825
|
-
* @constant {number}
|
|
17826
|
-
*/
|
|
17827
|
-
const CHANGE_AGENT_GC = 60 * 1000;
|
|
17828
|
-
/**
|
|
17829
|
-
* Creates a change agent function with time-to-live (TTL) and queuing capabilities for switching to the default agent.
|
|
17830
|
-
*
|
|
17831
|
-
* This factory function generates a queued, TTL-limited function to handle agent changes to the default agent for a specific client session,
|
|
17832
|
-
* ensuring operations are executed sequentially and cached results are reused within the TTL period.
|
|
17833
|
-
*
|
|
17834
|
-
* @function
|
|
17835
|
-
* @param {string} clientId - The unique identifier of the client session.
|
|
17836
|
-
* @returns {TChangeToDefaultAgentRun} A function that performs the default agent change operation with queuing and TTL.
|
|
17837
|
-
*/
|
|
17838
|
-
const createChangeToDefaultAgent = functoolsKit.ttl((clientId) => functoolsKit.queued(async (methodName, agentName, swarmName) => {
|
|
17839
|
-
if (!swarm$1.navigationValidationService.shouldNavigate(agentName, clientId, swarmName)) {
|
|
17840
|
-
return false;
|
|
17841
|
-
}
|
|
17842
|
-
// Notify all agents in the swarm of the change
|
|
17843
|
-
await Promise.all(swarm$1.swarmValidationService
|
|
17844
|
-
.getAgentList(swarmName)
|
|
17845
|
-
.map(async (agentName) => {
|
|
17846
|
-
await swarm$1.agentPublicService.commitAgentChange(methodName, clientId, agentName);
|
|
17847
|
-
}));
|
|
17848
|
-
{
|
|
17849
|
-
// Dispose of the current agent's resources and set up the new default agent
|
|
17850
|
-
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME, clientId, swarmName);
|
|
17851
|
-
await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
|
|
17852
|
-
await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
|
|
17853
|
-
await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
|
|
17854
|
-
}
|
|
17855
|
-
// Set the default agent as the active agent
|
|
17856
|
-
await swarm$1.swarmPublicService.setAgentName(agentName, methodName, clientId, swarmName);
|
|
17857
|
-
return true;
|
|
17858
|
-
}), {
|
|
17859
|
-
key: ([clientId]) => `${clientId}`,
|
|
17860
|
-
timeout: CHANGE_AGENT_TTL,
|
|
17861
|
-
});
|
|
17862
|
-
/**
|
|
17863
|
-
* Creates a garbage collector for the change agent function.
|
|
17864
|
-
*
|
|
17865
|
-
* This function sets up a singleton interval-based garbage collector to periodically clean up expired TTL entries from `createChangeToDefaultAgent`.
|
|
17866
|
-
*
|
|
17867
|
-
* @function
|
|
17868
|
-
* @returns {Promise<void>} A promise that resolves when the garbage collector is initialized.
|
|
17869
|
-
*/
|
|
17870
|
-
const createGc = functoolsKit.singleshot(async () => {
|
|
17871
|
-
setInterval(createChangeToDefaultAgent.gc, CHANGE_AGENT_GC);
|
|
17872
|
-
});
|
|
17873
|
-
/**
|
|
17874
|
-
* Navigates back to the default agent for a given client session in a swarm.
|
|
17875
|
-
*
|
|
17876
|
-
* This function switches the active agent to the default agent defined in the swarm schema for the specified client session.
|
|
17877
|
-
* It validates the session and default agent, logs the operation if enabled, and executes the change using a TTL-limited, queued runner.
|
|
17878
|
-
* The execution is wrapped in `beginContext` to ensure it runs outside of existing method and execution contexts.
|
|
17879
|
-
*
|
|
17880
|
-
* @param {string} clientId - The unique identifier of the client session.
|
|
17881
|
-
* @returns {Promise<boolean>} A promise that resolves when the default agent change is complete. If navigation stack contains recursion being canceled
|
|
17882
|
-
* @throws {Error} If session or agent validation fails, or if the agent change process encounters an error.
|
|
17883
|
-
* @example
|
|
17884
|
-
* await changeToDefaultAgent("client-123");
|
|
17885
|
-
*/
|
|
17886
|
-
const changeToDefaultAgent = beginContext(async (clientId) => {
|
|
17887
17969
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17888
17970
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17889
17971
|
swarm$1.loggerService.log(METHOD_NAME, {
|
|
17890
17972
|
clientId,
|
|
17891
17973
|
});
|
|
17892
17974
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17893
|
-
const
|
|
17975
|
+
const agentName = await swarm$1.swarmPublicService.navigationPop(METHOD_NAME, clientId, swarmName);
|
|
17894
17976
|
{
|
|
17895
|
-
// Validate session and
|
|
17977
|
+
// Validate session and the retrieved agent
|
|
17896
17978
|
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME);
|
|
17897
17979
|
swarm$1.agentValidationService.validate(agentName, METHOD_NAME);
|
|
17898
17980
|
}
|
|
17899
17981
|
// Execute the agent change with TTL and queuing
|
|
17900
|
-
const run = await
|
|
17982
|
+
const run = await createChangeToPrevAgent(clientId);
|
|
17901
17983
|
createGc();
|
|
17902
17984
|
return await run(METHOD_NAME, agentName, swarmName);
|
|
17903
17985
|
});
|
|
@@ -19959,6 +20041,7 @@ exports.commitToolOutputForce = commitToolOutputForce;
|
|
|
19959
20041
|
exports.commitUserMessage = commitUserMessage;
|
|
19960
20042
|
exports.commitUserMessageForce = commitUserMessageForce;
|
|
19961
20043
|
exports.complete = complete;
|
|
20044
|
+
exports.createNavigateToTriageAgent = createNavigateToTriageAgent;
|
|
19962
20045
|
exports.disposeConnection = disposeConnection;
|
|
19963
20046
|
exports.dumpAgent = dumpAgent;
|
|
19964
20047
|
exports.dumpClientPerformance = dumpClientPerformance;
|