agent-swarm-kit 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +639 -639
- package/build/index.cjs +1382 -613
- package/build/index.mjs +1379 -612
- package/package.json +89 -89
- package/types.d.ts +125 -18
- package/build/index.cjs.map +0 -1
- package/build/index.mjs.map +0 -1
package/build/index.mjs
CHANGED
|
@@ -273,33 +273,32 @@ const validateDefault = async (output) => {
|
|
|
273
273
|
};
|
|
274
274
|
|
|
275
275
|
/**
|
|
276
|
-
* Removes XML tags
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* Returns an empty string if the input is falsy.
|
|
276
|
+
* Removes XML-like blocks — the tags TOGETHER with everything between them — from a string, cleaning up excess whitespace.
|
|
277
|
+
* Any `<tag>content</tag>` pair is stripped entirely (tag and content), so only text outside such blocks survives.
|
|
278
|
+
* Returns an empty string if the input is falsy.
|
|
280
279
|
*
|
|
281
280
|
* @example
|
|
282
|
-
* //
|
|
283
|
-
* console.log(removeXmlTags("<p>Hello</p>")); // "
|
|
284
|
-
* console.log(removeXmlTags("<
|
|
281
|
+
* // Whole blocks are removed, including their contents
|
|
282
|
+
* console.log(removeXmlTags("<p>Hello</p>")); // ""
|
|
283
|
+
* console.log(removeXmlTags("Text <tool>action</tool>")); // "Text"
|
|
285
284
|
* console.log(removeXmlTags("No tags here")); // "No tags here"
|
|
286
285
|
*
|
|
287
286
|
* @example
|
|
288
|
-
* //
|
|
289
|
-
* console.log(removeXmlTags("<
|
|
290
|
-
* console.log(removeXmlTags("<
|
|
287
|
+
* // Edge cases
|
|
288
|
+
* console.log(removeXmlTags("<think>\nreasoning\n</think>Answer")); // "Answer"
|
|
289
|
+
* console.log(removeXmlTags("<invalid>")); // "<invalid>" (unpaired tags are kept)
|
|
291
290
|
* console.log(removeXmlTags("")); // ""
|
|
292
291
|
* console.log(removeXmlTags(null)); // ""
|
|
293
292
|
*
|
|
294
293
|
* @remarks
|
|
295
294
|
* This function:
|
|
296
295
|
* - Returns an empty string (`""`) for falsy inputs (e.g., `null`, `undefined`, empty string) to ensure safe handling.
|
|
297
|
-
* - Uses a regular expression (`/<[^>]+>[\s\S]*?<\/[^>]+>/g`) to match
|
|
298
|
-
*
|
|
296
|
+
* - Uses a regular expression (`/<[^>]+>[\s\S]*?<\/[^>]+>/g`) to match an opening tag, its (non-greedy) contents across
|
|
297
|
+
* newlines, and a closing tag, removing the whole block; unpaired tags without a closing counterpart are left as-is.
|
|
299
298
|
* - Collapses multiple consecutive newlines (`\n\s*\n`) into a single newline (`\n`) to clean up formatting.
|
|
300
299
|
* - Trims leading and trailing whitespace from the final result for a polished output.
|
|
301
|
-
* Useful in the agent swarm system for
|
|
302
|
-
*
|
|
300
|
+
* Useful in the agent swarm system for stripping structured blocks from model outputs — e.g., `<think>…</think>`
|
|
301
|
+
* reasoning sections or inline `<tool_call>…</tool_call>` artifacts — leaving only the plain-text answer.
|
|
303
302
|
*
|
|
304
303
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions|Regular Expressions}
|
|
305
304
|
* for details on the regex patterns used.
|
|
@@ -317,6 +316,12 @@ const removeXmlTags = (input) => {
|
|
|
317
316
|
};
|
|
318
317
|
|
|
319
318
|
const IS_WINDOWS = os.platform() === "win32";
|
|
319
|
+
/**
|
|
320
|
+
* Default prefix for temporary files created during atomic writes.
|
|
321
|
+
* Exposed so directory scanners (e.g. PersistBase) can exclude in-flight
|
|
322
|
+
* or leftover temporary files from entity listings.
|
|
323
|
+
*/
|
|
324
|
+
const TMP_FILE_PREFIX = ".tmp-";
|
|
320
325
|
/**
|
|
321
326
|
* Atomically writes data to a file, ensuring the operation either fully completes or leaves the original file unchanged.
|
|
322
327
|
* Uses a temporary file with a rename strategy on POSIX systems for atomicity, or direct writing with sync on Windows (or when POSIX rename is skipped).
|
|
@@ -367,7 +372,7 @@ async function writeFileAtomic(file, data, options = {}) {
|
|
|
367
372
|
else if (!options) {
|
|
368
373
|
options = {};
|
|
369
374
|
}
|
|
370
|
-
const { encoding = "utf8", mode = 0o666, tmpPrefix =
|
|
375
|
+
const { encoding = "utf8", mode = 0o666, tmpPrefix = TMP_FILE_PREFIX } = options;
|
|
371
376
|
let fileHandle = null;
|
|
372
377
|
if (IS_WINDOWS || GLOBAL_CONFIG.CC_SKIP_POSIX_RENAME) {
|
|
373
378
|
try {
|
|
@@ -423,6 +428,13 @@ async function writeFileAtomic(file, data, options = {}) {
|
|
|
423
428
|
}
|
|
424
429
|
|
|
425
430
|
var _a$4, _b$1, _c, _d;
|
|
431
|
+
/**
|
|
432
|
+
* Checks whether a directory entry name represents a persisted entity file.
|
|
433
|
+
* Excludes temporary files produced by atomic writes so in-flight or leftover
|
|
434
|
+
* `.tmp-*` files are never listed, counted, read, or removed as entities.
|
|
435
|
+
* @private
|
|
436
|
+
*/
|
|
437
|
+
const isEntityFileName = (name) => name.endsWith(".json") && !name.startsWith(TMP_FILE_PREFIX);
|
|
426
438
|
/** @private Symbol for memoizing the wait-for-initialization operation in PersistBase*/
|
|
427
439
|
const BASE_WAIT_FOR_INIT_SYMBOL = Symbol("wait-for-init");
|
|
428
440
|
/** @private Symbol for creating a new key in a persistent list*/
|
|
@@ -525,6 +537,8 @@ const LIST_GET_LAST_KEY_FN_METHOD_NAME = "PersistList.getLastKeyFn";
|
|
|
525
537
|
const BASE_UNLINK_RETRY_COUNT = 5;
|
|
526
538
|
/** @private Delay for retry attempts for unlink in waitForInit (in milliseconds)*/
|
|
527
539
|
const BASE_UNLINK_RETRY_DELAY = 1000;
|
|
540
|
+
/** @private Minimum age for a temporary atomic-write file to be reaped as a leftover in waitForInit (in milliseconds)*/
|
|
541
|
+
const BASE_STALE_TMP_FILE_AGE = 120000;
|
|
528
542
|
/**
|
|
529
543
|
* Attempts to remove a file if invalid JSON is detected during initialization.
|
|
530
544
|
* Retries the operation multiple times with delays to handle transient errors, ensuring robust setup.
|
|
@@ -555,6 +569,21 @@ const BASE_WAIT_FOR_INIT_FN = async (self) => {
|
|
|
555
569
|
directory: self._directory,
|
|
556
570
|
});
|
|
557
571
|
await fs__default.mkdir(self._directory, { recursive: true });
|
|
572
|
+
for await (const entry of await fs__default.opendir(self._directory)) {
|
|
573
|
+
if (entry.isFile() && entry.name.startsWith(TMP_FILE_PREFIX)) {
|
|
574
|
+
const filePath = join(self._directory, entry.name);
|
|
575
|
+
// An in-flight atomic write from a concurrent process also produces a
|
|
576
|
+
// temporary file here; only reap ones old enough to be true leftovers.
|
|
577
|
+
const stat = await fs__default.stat(filePath).catch(() => null);
|
|
578
|
+
if (!stat || Date.now() - stat.mtimeMs < BASE_STALE_TMP_FILE_AGE) {
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
console.error(`agent-swarm PersistBase found leftover temporary file for filePath=${filePath} entityName=${self.entityName}`);
|
|
582
|
+
if (await not(BASE_WAIT_FOR_INIT_UNLINK_FN(filePath))) {
|
|
583
|
+
console.error(`agent-swarm PersistBase failed to remove leftover temporary file for filePath=${filePath} entityName=${self.entityName}`);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
558
587
|
for await (const key of self.keys()) {
|
|
559
588
|
try {
|
|
560
589
|
await self.readValue(key);
|
|
@@ -678,7 +707,11 @@ class PersistBase {
|
|
|
678
707
|
* @private
|
|
679
708
|
*/
|
|
680
709
|
_getFilePath(entityId) {
|
|
681
|
-
|
|
710
|
+
// entityId comes from clientId/stateName/etc. which may be attacker-supplied:
|
|
711
|
+
// strip path separators and traversal so a value like "../../x" cannot escape
|
|
712
|
+
// the entity directory and read/overwrite arbitrary files.
|
|
713
|
+
const safeId = String(entityId).replace(/[/\\]/g, "_").replace(/\.\./g, "_");
|
|
714
|
+
return join(this.baseDir, this.entityName, `${safeId}.json`);
|
|
682
715
|
}
|
|
683
716
|
/**
|
|
684
717
|
* Initializes the storage directory, creating it if it doesn’t exist, and validates existing entities.
|
|
@@ -701,7 +734,7 @@ class PersistBase {
|
|
|
701
734
|
async getCount() {
|
|
702
735
|
let count = 0;
|
|
703
736
|
for await (const entry of await fs__default.opendir(this._directory)) {
|
|
704
|
-
if (entry.isFile() && entry.name
|
|
737
|
+
if (entry.isFile() && isEntityFileName(entry.name)) {
|
|
705
738
|
count++;
|
|
706
739
|
}
|
|
707
740
|
}
|
|
@@ -810,7 +843,7 @@ class PersistBase {
|
|
|
810
843
|
try {
|
|
811
844
|
const filesToRemove = [];
|
|
812
845
|
for await (const entry of await fs__default.opendir(this._directory)) {
|
|
813
|
-
if (entry.isFile() && entry.name
|
|
846
|
+
if (entry.isFile() && isEntityFileName(entry.name)) {
|
|
814
847
|
filesToRemove.push(entry.name);
|
|
815
848
|
}
|
|
816
849
|
}
|
|
@@ -836,7 +869,7 @@ class PersistBase {
|
|
|
836
869
|
try {
|
|
837
870
|
const entityIds = [];
|
|
838
871
|
for await (const entry of await fs__default.opendir(this._directory)) {
|
|
839
|
-
if (entry.isFile() && entry.name
|
|
872
|
+
if (entry.isFile() && isEntityFileName(entry.name)) {
|
|
840
873
|
entityIds.push(entry.name.slice(0, -5));
|
|
841
874
|
}
|
|
842
875
|
}
|
|
@@ -866,7 +899,7 @@ class PersistBase {
|
|
|
866
899
|
try {
|
|
867
900
|
const entityIds = [];
|
|
868
901
|
for await (const entry of await fs__default.opendir(this._directory)) {
|
|
869
|
-
if (entry.isFile() && entry.name
|
|
902
|
+
if (entry.isFile() && isEntityFileName(entry.name)) {
|
|
870
903
|
entityIds.push(entry.name.slice(0, -5));
|
|
871
904
|
}
|
|
872
905
|
}
|
|
@@ -1791,6 +1824,16 @@ class HistoryPersistInstance {
|
|
|
1791
1824
|
this.callbacks.onRead(item, this.clientId, agentName);
|
|
1792
1825
|
yield item;
|
|
1793
1826
|
}
|
|
1827
|
+
if (this.callbacks.getSystemPrompt) {
|
|
1828
|
+
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
1829
|
+
yield {
|
|
1830
|
+
role: "system",
|
|
1831
|
+
content,
|
|
1832
|
+
agentName,
|
|
1833
|
+
mode: "tool",
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1794
1837
|
this.callbacks.onReadEnd &&
|
|
1795
1838
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1796
1839
|
return;
|
|
@@ -1972,6 +2015,16 @@ class HistoryMemoryInstance {
|
|
|
1972
2015
|
this.callbacks.onRead(item, this.clientId, agentName);
|
|
1973
2016
|
yield item;
|
|
1974
2017
|
}
|
|
2018
|
+
if (this.callbacks.getSystemPrompt) {
|
|
2019
|
+
for (const content of await this.callbacks.getSystemPrompt(this.clientId, agentName)) {
|
|
2020
|
+
yield {
|
|
2021
|
+
role: "system",
|
|
2022
|
+
content,
|
|
2023
|
+
agentName,
|
|
2024
|
+
mode: "tool",
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
1975
2028
|
this.callbacks.onReadEnd &&
|
|
1976
2029
|
this.callbacks.onReadEnd(this.clientId, agentName);
|
|
1977
2030
|
return;
|
|
@@ -2731,7 +2784,7 @@ class OperatorUtils {
|
|
|
2731
2784
|
isInitial && operator.init();
|
|
2732
2785
|
return (message, next) => {
|
|
2733
2786
|
operator.connectAnswer(next);
|
|
2734
|
-
operator.recieveMessage(message);
|
|
2787
|
+
Promise.resolve(operator.recieveMessage(message)).catch((error) => console.error(`agent-swarm operator recieveMessage error clientId=${clientId} agentName=${agentName} error=${getErrorMessage(error)}`));
|
|
2735
2788
|
return async () => {
|
|
2736
2789
|
this.getOperator.clear(`${clientId}-${agentName}`);
|
|
2737
2790
|
await operator.dispose();
|
|
@@ -2836,6 +2889,9 @@ const CC_DEFAULT_CONNECT_OPERATOR = (clientId, agentName) => OperatorAdapter.con
|
|
|
2836
2889
|
* Flag to enable operator timeout, used in `ClientOperator` for message processing.
|
|
2837
2890
|
*/
|
|
2838
2891
|
const CC_ENABLE_OPERATOR_TIMEOUT = false;
|
|
2892
|
+
const CC_OPERATOR_SIGNAL_TIMEOUT = 90000;
|
|
2893
|
+
const CC_CHAT_INACTIVITY_CHECK = 60 * 1000;
|
|
2894
|
+
const CC_CHAT_INACTIVITY_TIMEOUT = 15 * 60 * 1000;
|
|
2839
2895
|
/**
|
|
2840
2896
|
* Disable fetch of data from all storages. Quite usefull for unit tests
|
|
2841
2897
|
*/
|
|
@@ -2895,6 +2951,9 @@ const GLOBAL_CONFIG = {
|
|
|
2895
2951
|
CC_THROW_WHEN_NAVIGATION_RECURSION,
|
|
2896
2952
|
CC_DEFAULT_CONNECT_OPERATOR,
|
|
2897
2953
|
CC_ENABLE_OPERATOR_TIMEOUT,
|
|
2954
|
+
CC_OPERATOR_SIGNAL_TIMEOUT,
|
|
2955
|
+
CC_CHAT_INACTIVITY_CHECK,
|
|
2956
|
+
CC_CHAT_INACTIVITY_TIMEOUT,
|
|
2898
2957
|
CC_STORAGE_DISABLE_GET_DATA,
|
|
2899
2958
|
CC_MAX_NESTED_EXECUTIONS,
|
|
2900
2959
|
};
|
|
@@ -3323,6 +3382,9 @@ const resolveTools = async (clientId, agentName, tools) => {
|
|
|
3323
3382
|
})));
|
|
3324
3383
|
};
|
|
3325
3384
|
|
|
3385
|
+
const disposeSubject = new Subject();
|
|
3386
|
+
const errorSubject = new Subject();
|
|
3387
|
+
|
|
3326
3388
|
const CANCEL_OUTPUT_SYMBOL = Symbol("cancel-output");
|
|
3327
3389
|
const AGENT_CHANGE_SYMBOL = Symbol("agent-change");
|
|
3328
3390
|
const MODEL_RESQUE_SYMBOL = Symbol("model-resque");
|
|
@@ -3391,7 +3453,8 @@ const createPlaceholder = () => GLOBAL_CONFIG.CC_EMPTY_OUTPUT_PLACEHOLDERS[Math.
|
|
|
3391
3453
|
* Emits events via subjects (e.g., _toolErrorSubject) to manage execution flow in ClientAgent.
|
|
3392
3454
|
* Supports AgentConnectionService by executing tools defined in ToolSchemaService and referenced in AgentSchemaService.
|
|
3393
3455
|
*/
|
|
3394
|
-
const createToolCall = async (idx, tool, toolCalls, targetFn, reason, self) => {
|
|
3456
|
+
const createToolCall = async (idx, tool, toolCalls, targetFn, reason, mode, outputEpoch, self) => {
|
|
3457
|
+
self._runningToolCalls += 1;
|
|
3395
3458
|
try {
|
|
3396
3459
|
await targetFn.call({
|
|
3397
3460
|
toolId: tool.id,
|
|
@@ -3404,8 +3467,15 @@ const createToolCall = async (idx, tool, toolCalls, targetFn, reason, self) => {
|
|
|
3404
3467
|
callReason: reason,
|
|
3405
3468
|
toolCalls,
|
|
3406
3469
|
});
|
|
3407
|
-
|
|
3408
|
-
targetFn.callbacks?.onAfterCall
|
|
3470
|
+
try {
|
|
3471
|
+
targetFn.callbacks?.onAfterCall &&
|
|
3472
|
+
targetFn.callbacks?.onAfterCall(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments);
|
|
3473
|
+
}
|
|
3474
|
+
catch (error) {
|
|
3475
|
+
// Callbacks are observers: a throwing onAfterCall must not turn a
|
|
3476
|
+
// successful tool call into a tool error.
|
|
3477
|
+
console.error(`agent-swarm onAfterCall callback error functionName=${tool.function.name} error=${getErrorMessage(error)}`);
|
|
3478
|
+
}
|
|
3409
3479
|
}
|
|
3410
3480
|
catch (error) {
|
|
3411
3481
|
console.error(`agent-swarm tool call error functionName=${tool.function.name} error=${getErrorMessage(error)}`, {
|
|
@@ -3415,11 +3485,29 @@ const createToolCall = async (idx, tool, toolCalls, targetFn, reason, self) => {
|
|
|
3415
3485
|
arguments: tool.function.arguments,
|
|
3416
3486
|
error: errorData(error),
|
|
3417
3487
|
});
|
|
3418
|
-
|
|
3419
|
-
targetFn.callbacks?.onCallError
|
|
3420
|
-
|
|
3421
|
-
self.params.
|
|
3422
|
-
|
|
3488
|
+
try {
|
|
3489
|
+
targetFn.callbacks?.onCallError &&
|
|
3490
|
+
targetFn.callbacks?.onCallError(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments, error);
|
|
3491
|
+
self.params.onToolError &&
|
|
3492
|
+
self.params.onToolError(self.params.clientId, self.params.agentName, targetFn.toolName, error);
|
|
3493
|
+
}
|
|
3494
|
+
catch (callbackError) {
|
|
3495
|
+
// Error callbacks must not be able to suppress the TOOL_ERROR signal
|
|
3496
|
+
// below — otherwise the execution would never recover and hang.
|
|
3497
|
+
console.error(`agent-swarm onCallError callback error functionName=${tool.function.name} error=${getErrorMessage(callbackError)}`);
|
|
3498
|
+
}
|
|
3499
|
+
await self._toolErrorSubject.next(TOOL_ERROR_SYMBOL);
|
|
3500
|
+
if (!self._activeToolChains) {
|
|
3501
|
+
// The status chain already consumed TOOL_COMMIT and finished, so nobody
|
|
3502
|
+
// handles this late error (e.g. changeToAgent recursion guard thrown after
|
|
3503
|
+
// commitToolOutput). Without a recovery emission the pending waitForOutput
|
|
3504
|
+
// of the enclosing execution would hang forever.
|
|
3505
|
+
const result = await self._resurrectModel(mode, `Late tool error after commit: name=${tool.function.name} error=${getErrorMessage(error)}`);
|
|
3506
|
+
await self._emitOutput(mode, result, outputEpoch);
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
finally {
|
|
3510
|
+
self._runningToolCalls -= 1;
|
|
3423
3511
|
}
|
|
3424
3512
|
};
|
|
3425
3513
|
/**
|
|
@@ -3449,7 +3537,7 @@ const mapMcpToolCall = ({ name, description = name, inputSchema }, self) => {
|
|
|
3449
3537
|
enum: e,
|
|
3450
3538
|
},
|
|
3451
3539
|
}), {}),
|
|
3452
|
-
required: inputSchema
|
|
3540
|
+
required: inputSchema?.required,
|
|
3453
3541
|
},
|
|
3454
3542
|
},
|
|
3455
3543
|
call: async (dto) => {
|
|
@@ -3538,6 +3626,7 @@ const EXECUTE_FN = async (incoming, mode, self) => {
|
|
|
3538
3626
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} maxToolCalls=${self.params.maxToolCalls} execute begin`, { incoming, mode });
|
|
3539
3627
|
self.params.onExecute &&
|
|
3540
3628
|
self.params.onExecute(self.params.clientId, self.params.agentName, incoming, mode);
|
|
3629
|
+
const outputEpoch = self._outputEpoch;
|
|
3541
3630
|
await self.params.history.push({
|
|
3542
3631
|
role: "user",
|
|
3543
3632
|
mode,
|
|
@@ -3555,7 +3644,39 @@ const EXECUTE_FN = async (incoming, mode, self) => {
|
|
|
3555
3644
|
id: call.id ?? randomString(),
|
|
3556
3645
|
type: call.type ?? "function",
|
|
3557
3646
|
})), self.params.clientId, self.params.agentName);
|
|
3558
|
-
|
|
3647
|
+
{
|
|
3648
|
+
const toolCallIds = new Set(toolCalls.map(({ id }) => id));
|
|
3649
|
+
if (toolCallIds.size !== toolCalls.length) {
|
|
3650
|
+
// Duplicate ids break the call-to-output linkage in history and mean
|
|
3651
|
+
// the model output is malformed: surface it as an exception to the
|
|
3652
|
+
// caller (via errorSubject) and recover the flow with a placeholder.
|
|
3653
|
+
const error = new Error(`agent-swarm duplicate tool call id detected agentName=${self.params.agentName} clientId=${self.params.clientId} ids=${JSON.stringify(toolCalls.map(({ id }) => id))}`);
|
|
3654
|
+
console.error(error.message);
|
|
3655
|
+
await errorSubject.next([self.params.clientId, error]);
|
|
3656
|
+
const result = await self._resurrectModel(mode, `Duplicate tool call id in model output`);
|
|
3657
|
+
await self._emitOutput(mode, result, outputEpoch);
|
|
3658
|
+
return;
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
// slice(-0) === slice(0) returns the WHOLE array, so maxToolCalls=0 would
|
|
3662
|
+
// run every call instead of none — clamp explicitly.
|
|
3663
|
+
toolCalls =
|
|
3664
|
+
self.params.maxToolCalls > 0
|
|
3665
|
+
? toolCalls.slice(-self.params.maxToolCalls)
|
|
3666
|
+
: [];
|
|
3667
|
+
if (!toolCalls.length) {
|
|
3668
|
+
// maxToolCalls=0 dropped every call: the model wanted tools but none may
|
|
3669
|
+
// run. Emit the (tool-stripped) content as the answer instead of leaving
|
|
3670
|
+
// the pending waitForOutput hanging forever.
|
|
3671
|
+
const result = await self.params.transform(message.content, self.params.clientId, self.params.agentName);
|
|
3672
|
+
await self.params.history.push({
|
|
3673
|
+
...message,
|
|
3674
|
+
tool_calls: [],
|
|
3675
|
+
agentName: self.params.agentName,
|
|
3676
|
+
});
|
|
3677
|
+
await self._emitOutput(mode, result, outputEpoch);
|
|
3678
|
+
return;
|
|
3679
|
+
}
|
|
3559
3680
|
{
|
|
3560
3681
|
const priorityTool = toolCalls.find((call) => swarm$1.navigationSchemaService.hasTool(call.function.name) ||
|
|
3561
3682
|
swarm$1.actionSchemaService.hasTool(call.function.name));
|
|
@@ -3563,11 +3684,15 @@ const EXECUTE_FN = async (incoming, mode, self) => {
|
|
|
3563
3684
|
toolCalls = [priorityTool];
|
|
3564
3685
|
}
|
|
3565
3686
|
}
|
|
3687
|
+
// Persist the normalized tool calls (ids ensured, sliced, priority-filtered)
|
|
3688
|
+
// so history keeps the call-to-output linkage even when the model omits ids.
|
|
3566
3689
|
await self.params.history.push({
|
|
3567
3690
|
...message,
|
|
3691
|
+
tool_calls: toolCalls,
|
|
3568
3692
|
agentName: self.params.agentName,
|
|
3569
3693
|
});
|
|
3570
3694
|
let lastToolStatusRef = Promise.resolve(null);
|
|
3695
|
+
self._activeToolChains += 1;
|
|
3571
3696
|
const [runAwaiter, { resolve: run }] = createAwaiter();
|
|
3572
3697
|
for (let idx = 0; idx !== toolCalls.length; idx++) {
|
|
3573
3698
|
const tool = toolCalls[idx];
|
|
@@ -3578,29 +3703,52 @@ const EXECUTE_FN = async (incoming, mode, self) => {
|
|
|
3578
3703
|
const result = await self._resurrectModel(mode, `No target function for ${tool.function.name}`);
|
|
3579
3704
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3580
3705
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} execute end result=${result}`);
|
|
3581
|
-
await self._emitOutput(mode, result);
|
|
3706
|
+
await self._emitOutput(mode, result, outputEpoch);
|
|
3582
3707
|
run(false);
|
|
3583
3708
|
return;
|
|
3584
3709
|
}
|
|
3585
|
-
|
|
3586
|
-
targetFn.callbacks?.onValidate
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3710
|
+
try {
|
|
3711
|
+
targetFn.callbacks?.onValidate &&
|
|
3712
|
+
targetFn.callbacks?.onValidate(self.params.clientId, self.params.agentName, tool.function.arguments);
|
|
3713
|
+
}
|
|
3714
|
+
catch (error) {
|
|
3715
|
+
// Callbacks are observers: a throwing onValidate must not reject the
|
|
3716
|
+
// queued EXECUTE_FN (unhandled rejection + hung waitForOutput).
|
|
3717
|
+
console.error(`agent-swarm onValidate callback error functionName=${tool.function.name} error=${getErrorMessage(error)}`);
|
|
3718
|
+
}
|
|
3719
|
+
let validationPassed = false;
|
|
3720
|
+
try {
|
|
3721
|
+
validationPassed = !(await not(targetFn.validate({
|
|
3722
|
+
clientId: self.params.clientId,
|
|
3723
|
+
agentName: self.params.agentName,
|
|
3724
|
+
params: tool.function.arguments,
|
|
3725
|
+
toolCalls,
|
|
3726
|
+
})));
|
|
3727
|
+
}
|
|
3728
|
+
catch (error) {
|
|
3729
|
+
// A throwing validate is a failed validation, not a crashed execution.
|
|
3730
|
+
console.error(`agent-swarm tool validate error functionName=${tool.function.name} error=${getErrorMessage(error)}`);
|
|
3731
|
+
validationPassed = false;
|
|
3732
|
+
}
|
|
3733
|
+
if (!validationPassed) {
|
|
3593
3734
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3594
3735
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} functionName=${tool.function.name} tool validation not passed`);
|
|
3595
3736
|
const result = await self._resurrectModel(mode, `Function validation failed: name=${tool.function.name} arguments=${JSON.stringify(tool.function.arguments)}`);
|
|
3596
3737
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3597
3738
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} execute end result=${result}`);
|
|
3598
|
-
await self._emitOutput(mode, result);
|
|
3739
|
+
await self._emitOutput(mode, result, outputEpoch);
|
|
3599
3740
|
run(false);
|
|
3600
3741
|
return;
|
|
3601
3742
|
}
|
|
3602
|
-
|
|
3603
|
-
targetFn.callbacks?.onBeforeCall
|
|
3743
|
+
try {
|
|
3744
|
+
targetFn.callbacks?.onBeforeCall &&
|
|
3745
|
+
targetFn.callbacks?.onBeforeCall(tool.id, self.params.clientId, self.params.agentName, tool.function.arguments);
|
|
3746
|
+
}
|
|
3747
|
+
catch (error) {
|
|
3748
|
+
// Callbacks are observers: a throwing onBeforeCall must not reject the
|
|
3749
|
+
// queued EXECUTE_FN (unhandled rejection + hung waitForOutput).
|
|
3750
|
+
console.error(`agent-swarm onBeforeCall callback error functionName=${tool.function.name} error=${getErrorMessage(error)}`);
|
|
3751
|
+
}
|
|
3604
3752
|
/**
|
|
3605
3753
|
* Do not await directly to avoid deadlock! The tool can send messages to other agents by emulating user messages.
|
|
3606
3754
|
*/
|
|
@@ -3638,33 +3786,33 @@ const EXECUTE_FN = async (incoming, mode, self) => {
|
|
|
3638
3786
|
console.warn(`agent-swarm no tool output after ${TOOL_NO_OUTPUT_WARNING_TIMEOUT}ms clientId=${self.params.clientId} agentName=${self.params.agentName} toolId=${tool.id} functionName=${tool.function.name}`);
|
|
3639
3787
|
}
|
|
3640
3788
|
});
|
|
3641
|
-
createToolCall(idx, tool, toolCalls, targetFn, message.content || "", self);
|
|
3789
|
+
createToolCall(idx, tool, toolCalls, targetFn, message.content || "", mode, outputEpoch, self);
|
|
3642
3790
|
const status = await statusAwaiter;
|
|
3643
3791
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3644
3792
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} functionName=${tool.function.name} tool call end`);
|
|
3645
3793
|
if (status === MODEL_RESQUE_SYMBOL) {
|
|
3646
3794
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3647
3795
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} functionName=${tool.function.name} the next tool execution stopped due to the model resque`);
|
|
3648
|
-
self.params.
|
|
3649
|
-
self.params.
|
|
3796
|
+
self.params.onAfterToolCalls &&
|
|
3797
|
+
self.params.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
|
|
3650
3798
|
}
|
|
3651
3799
|
if (status === AGENT_CHANGE_SYMBOL) {
|
|
3652
3800
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3653
3801
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} functionName=${tool.function.name} the next tool execution stopped due to the agent changed`);
|
|
3654
|
-
self.params.
|
|
3655
|
-
self.params.
|
|
3802
|
+
self.params.onAfterToolCalls &&
|
|
3803
|
+
self.params.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
|
|
3656
3804
|
}
|
|
3657
3805
|
if (status === TOOL_STOP_SYMBOL) {
|
|
3658
3806
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3659
3807
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} functionName=${tool.function.name} the next tool execution stopped due to the commitStopTools call`);
|
|
3660
|
-
self.params.
|
|
3661
|
-
self.params.
|
|
3808
|
+
self.params.onAfterToolCalls &&
|
|
3809
|
+
self.params.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
|
|
3662
3810
|
}
|
|
3663
3811
|
if (status === CANCEL_OUTPUT_SYMBOL) {
|
|
3664
3812
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3665
3813
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} functionName=${tool.function.name} the next tool execution stopped due to the commitCancelOutput call`);
|
|
3666
|
-
self.params.
|
|
3667
|
-
self.params.
|
|
3814
|
+
self.params.onAfterToolCalls &&
|
|
3815
|
+
self.params.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
|
|
3668
3816
|
}
|
|
3669
3817
|
if (status === TOOL_ERROR_SYMBOL) {
|
|
3670
3818
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
@@ -3672,14 +3820,15 @@ const EXECUTE_FN = async (incoming, mode, self) => {
|
|
|
3672
3820
|
const result = await self._resurrectModel(mode, `Function call failed with error: name=${tool.function.name} arguments=${JSON.stringify(tool.function.arguments)}`);
|
|
3673
3821
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3674
3822
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} execute end result=${result}`);
|
|
3675
|
-
await self._emitOutput(mode, result);
|
|
3823
|
+
await self._emitOutput(mode, result, outputEpoch);
|
|
3676
3824
|
}
|
|
3677
3825
|
return status;
|
|
3678
3826
|
});
|
|
3679
3827
|
}
|
|
3680
3828
|
lastToolStatusRef.finally(() => {
|
|
3681
|
-
self.
|
|
3682
|
-
|
|
3829
|
+
self._activeToolChains -= 1;
|
|
3830
|
+
self.params.onAfterToolCalls &&
|
|
3831
|
+
self.params.onAfterToolCalls(self.params.clientId, self.params.agentName, toolCalls);
|
|
3683
3832
|
});
|
|
3684
3833
|
run(true);
|
|
3685
3834
|
return;
|
|
@@ -3698,12 +3847,12 @@ const EXECUTE_FN = async (incoming, mode, self) => {
|
|
|
3698
3847
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3699
3848
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} execute invalid tool call detected: ${validation}`, { result });
|
|
3700
3849
|
const result1 = await self._resurrectModel(mode, `Invalid model output: ${result}`);
|
|
3701
|
-
await self._emitOutput(mode, result1);
|
|
3850
|
+
await self._emitOutput(mode, result1, outputEpoch);
|
|
3702
3851
|
return;
|
|
3703
3852
|
}
|
|
3704
3853
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3705
3854
|
self.params.logger.debug(`ClientAgent agentName=${self.params.agentName} clientId=${self.params.clientId} execute end result=${result}`);
|
|
3706
|
-
await self._emitOutput(mode, result);
|
|
3855
|
+
await self._emitOutput(mode, result, outputEpoch);
|
|
3707
3856
|
};
|
|
3708
3857
|
/**
|
|
3709
3858
|
* Represents a client-side agent in the swarm system, implementing the IAgent interface.
|
|
@@ -3726,6 +3875,35 @@ class ClientAgent {
|
|
|
3726
3875
|
* @readonly
|
|
3727
3876
|
*/
|
|
3728
3877
|
this._toolAbortController = new ToolAbortController();
|
|
3878
|
+
/**
|
|
3879
|
+
* Count of tool calls currently executing for this agent.
|
|
3880
|
+
* Non-zero while any targetFn.call promise is pending; ClientSession uses it to
|
|
3881
|
+
* detect nested tool-mode executions that must join the parent output waiter.
|
|
3882
|
+
*/
|
|
3883
|
+
this._runningToolCalls = 0;
|
|
3884
|
+
/**
|
|
3885
|
+
* Count of EXECUTE_FN tool status chains still consuming tool events.
|
|
3886
|
+
* While non-zero, tool errors are handled by the chain (stop + resurrect);
|
|
3887
|
+
* once it drops to zero a late tool error must recover on its own in
|
|
3888
|
+
* createToolCall, or the pending execution output would never be emitted.
|
|
3889
|
+
*/
|
|
3890
|
+
this._activeToolChains = 0;
|
|
3891
|
+
/**
|
|
3892
|
+
* Count of EXECUTE_FN executions currently in flight for this agent instance.
|
|
3893
|
+
* dispose() checks it: tearing the instance down mid-execution (e.g. a
|
|
3894
|
+
* server-side changeToAgent while the completion is still running) must
|
|
3895
|
+
* resolve the pending output waiter with an empty result — otherwise the
|
|
3896
|
+
* waiter and the session busy lock would hang forever.
|
|
3897
|
+
*/
|
|
3898
|
+
this._activeExecutions = 0;
|
|
3899
|
+
/**
|
|
3900
|
+
* Generation counter for output emissions. Bumped by commitCancelOutput and by
|
|
3901
|
+
* swarm-level output substitution (emit). Executions capture the epoch at start
|
|
3902
|
+
* and _emitOutput drops their result when the epoch moved on — otherwise the
|
|
3903
|
+
* stale output of a cancelled/substituted execution would resolve the waiter
|
|
3904
|
+
* of the NEXT message, poisoning that exchange.
|
|
3905
|
+
*/
|
|
3906
|
+
this._outputEpoch = 0;
|
|
3729
3907
|
/**
|
|
3730
3908
|
* Subject for signaling agent changes, halting subsequent tool executions via commitAgentChange.
|
|
3731
3909
|
* @readonly
|
|
@@ -3765,7 +3943,15 @@ class ClientAgent {
|
|
|
3765
3943
|
* Executes the incoming message and processes tool calls if present, queued to prevent overlapping executions.
|
|
3766
3944
|
* Implements IAgent.execute, delegating to EXECUTE_FN with queuing via functools-kit’s queued decorator.
|
|
3767
3945
|
*/
|
|
3768
|
-
this.execute = queued(async (incoming, mode) =>
|
|
3946
|
+
this.execute = queued(async (incoming, mode) => {
|
|
3947
|
+
this._activeExecutions += 1;
|
|
3948
|
+
try {
|
|
3949
|
+
return await EXECUTE_FN(incoming, mode, this);
|
|
3950
|
+
}
|
|
3951
|
+
finally {
|
|
3952
|
+
this._activeExecutions -= 1;
|
|
3953
|
+
}
|
|
3954
|
+
});
|
|
3769
3955
|
/**
|
|
3770
3956
|
* Runs a stateless completion for the incoming message, queued to prevent overlapping executions.
|
|
3771
3957
|
* Implements IAgent.run, delegating to RUN_FN with queuing via functools-kit’s queued decorator.
|
|
@@ -3789,12 +3975,32 @@ class ClientAgent {
|
|
|
3789
3975
|
if (this.params.tools) {
|
|
3790
3976
|
await Promise.all(this.params.tools.map(async (tool) => {
|
|
3791
3977
|
const { toolName, function: upperFn, isAvailable = TOOL_AVAILABLE_DEFAULT, ...other } = tool;
|
|
3792
|
-
|
|
3978
|
+
try {
|
|
3979
|
+
if (await not(isAvailable(this.params.clientId, this.params.agentName, toolName))) {
|
|
3980
|
+
return;
|
|
3981
|
+
}
|
|
3982
|
+
}
|
|
3983
|
+
catch (error) {
|
|
3984
|
+
// A throwing isAvailable would reject the queued EXECUTE_FN and
|
|
3985
|
+
// hang the pending waitForOutput: treat it as "not available".
|
|
3986
|
+
console.error(`agent-swarm isAvailable error toolName=${toolName} error=${getErrorMessage(error)}`);
|
|
3987
|
+
await errorSubject.next([this.params.clientId, error]);
|
|
3988
|
+
return;
|
|
3989
|
+
}
|
|
3990
|
+
let fn;
|
|
3991
|
+
try {
|
|
3992
|
+
fn =
|
|
3993
|
+
typeof upperFn === "function"
|
|
3994
|
+
? await upperFn(this.params.clientId, this.params.agentName)
|
|
3995
|
+
: upperFn;
|
|
3996
|
+
}
|
|
3997
|
+
catch (error) {
|
|
3998
|
+
// Same rationale: a throwing dynamic tool schema must not crash
|
|
3999
|
+
// the execution — the tool is skipped for this completion.
|
|
4000
|
+
console.error(`agent-swarm dynamic tool function error toolName=${toolName} error=${getErrorMessage(error)}`);
|
|
4001
|
+
await errorSubject.next([this.params.clientId, error]);
|
|
3793
4002
|
return;
|
|
3794
4003
|
}
|
|
3795
|
-
const fn = typeof upperFn === "function"
|
|
3796
|
-
? await upperFn(this.params.clientId, this.params.agentName)
|
|
3797
|
-
: upperFn;
|
|
3798
4004
|
agentToolList.push({
|
|
3799
4005
|
...other,
|
|
3800
4006
|
toolName,
|
|
@@ -3802,10 +4008,19 @@ class ClientAgent {
|
|
|
3802
4008
|
});
|
|
3803
4009
|
}));
|
|
3804
4010
|
}
|
|
3805
|
-
|
|
4011
|
+
let mcpToolList = [];
|
|
4012
|
+
try {
|
|
4013
|
+
mcpToolList = await this.params.mcp.listTools(this.params.clientId);
|
|
4014
|
+
}
|
|
4015
|
+
catch (error) {
|
|
4016
|
+
// A throwing MCP listTools would reject the queued EXECUTE_FN and hang
|
|
4017
|
+
// the pending waitForOutput: continue without MCP tools and surface the
|
|
4018
|
+
// error to the caller through errorSubject.
|
|
4019
|
+
console.error(`agent-swarm mcp listTools error agentName=${this.params.agentName} clientId=${this.params.clientId} error=${getErrorMessage(error)}`);
|
|
4020
|
+
await errorSubject.next([this.params.clientId, error]);
|
|
4021
|
+
}
|
|
3806
4022
|
if (mcpToolList.length) {
|
|
3807
4023
|
let commitActionFound = false;
|
|
3808
|
-
let navigationFound = false;
|
|
3809
4024
|
return agentToolList
|
|
3810
4025
|
.concat(mcpToolList.map((tool) => mapMcpToolCall(tool, this)))
|
|
3811
4026
|
.filter(({ function: { name } }) => {
|
|
@@ -3821,13 +4036,11 @@ class ClientAgent {
|
|
|
3821
4036
|
return aStarts === bStarts ? 0 : aStarts ? -1 : 1;
|
|
3822
4037
|
})
|
|
3823
4038
|
.filter((tool) => {
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
navigationFound = true;
|
|
3830
|
-
}
|
|
4039
|
+
// Do NOT collapse navigation tools to a single one: a router agent
|
|
4040
|
+
// legitimately exposes several (nav-to-sales/tech/human) and the model
|
|
4041
|
+
// must be able to call any of them. Only commit-action tools are
|
|
4042
|
+
// limited to one, since running multiple actions in one turn is
|
|
4043
|
+
// ambiguous.
|
|
3831
4044
|
const isCommitAction = swarm$1.actionSchemaService.hasTool(tool.toolName);
|
|
3832
4045
|
if (isCommitAction) {
|
|
3833
4046
|
if (commitActionFound) {
|
|
@@ -3839,7 +4052,6 @@ class ClientAgent {
|
|
|
3839
4052
|
});
|
|
3840
4053
|
}
|
|
3841
4054
|
let commitActionFound = false;
|
|
3842
|
-
let navigationFound = false;
|
|
3843
4055
|
return agentToolList
|
|
3844
4056
|
.filter(({ function: { name } }) => {
|
|
3845
4057
|
if (!seen.has(name)) {
|
|
@@ -3854,13 +4066,8 @@ class ClientAgent {
|
|
|
3854
4066
|
return aStarts === bStarts ? 0 : aStarts ? -1 : 1;
|
|
3855
4067
|
})
|
|
3856
4068
|
.filter((tool) => {
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
if (navigationFound) {
|
|
3860
|
-
return false;
|
|
3861
|
-
}
|
|
3862
|
-
navigationFound = true;
|
|
3863
|
-
}
|
|
4069
|
+
// See the MCP branch above: navigation tools are not deduplicated —
|
|
4070
|
+
// only commit-action tools are limited to one per turn.
|
|
3864
4071
|
const isCommitAction = swarm$1.actionSchemaService.hasTool(tool.toolName);
|
|
3865
4072
|
if (isCommitAction) {
|
|
3866
4073
|
if (commitActionFound) {
|
|
@@ -3902,7 +4109,12 @@ class ClientAgent {
|
|
|
3902
4109
|
* Supports SwarmConnectionService by broadcasting agent outputs within the swarm.
|
|
3903
4110
|
* @throws {Error} If validation fails after model resurrection, indicating an unrecoverable state.
|
|
3904
4111
|
**/
|
|
3905
|
-
async _emitOutput(mode, rawResult) {
|
|
4112
|
+
async _emitOutput(mode, rawResult, outputEpoch = this._outputEpoch) {
|
|
4113
|
+
if (outputEpoch !== this._outputEpoch) {
|
|
4114
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4115
|
+
this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} _emitOutput skipped for stale execution (cancelled or substituted)`, { mode, rawResult });
|
|
4116
|
+
return;
|
|
4117
|
+
}
|
|
3906
4118
|
const result = await this.params.transform(rawResult, this.params.clientId, this.params.agentName);
|
|
3907
4119
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
3908
4120
|
this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} _emitOutput`, { mode, result, rawResult });
|
|
@@ -3913,6 +4125,9 @@ class ClientAgent {
|
|
|
3913
4125
|
if ((validation = await this.params.validate(result))) {
|
|
3914
4126
|
throw new Error(`agent-swarm-kit ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} model resurrect failed: ${validation}`);
|
|
3915
4127
|
}
|
|
4128
|
+
if (outputEpoch !== this._outputEpoch) {
|
|
4129
|
+
return;
|
|
4130
|
+
}
|
|
3916
4131
|
this.params.onOutput &&
|
|
3917
4132
|
this.params.onOutput(this.params.clientId, this.params.agentName, result);
|
|
3918
4133
|
this.params.onAssistantMessage &&
|
|
@@ -3935,6 +4150,9 @@ class ClientAgent {
|
|
|
3935
4150
|
});
|
|
3936
4151
|
return;
|
|
3937
4152
|
}
|
|
4153
|
+
if (outputEpoch !== this._outputEpoch) {
|
|
4154
|
+
return;
|
|
4155
|
+
}
|
|
3938
4156
|
this.params.onOutput &&
|
|
3939
4157
|
this.params.onOutput(this.params.clientId, this.params.agentName, result);
|
|
3940
4158
|
await this._outputSubject.next(result);
|
|
@@ -4028,6 +4246,16 @@ class ClientAgent {
|
|
|
4028
4246
|
await this._resqueSubject.next(MODEL_RESQUE_SYMBOL);
|
|
4029
4247
|
return placeholder;
|
|
4030
4248
|
}
|
|
4249
|
+
/**
|
|
4250
|
+
* Marks in-flight executions as substituted: the swarm emitted a replacement
|
|
4251
|
+
* output (ClientSwarm.emit), so results of executions started earlier must not
|
|
4252
|
+
* reach _outputSubject — they would pair with the next waiter otherwise.
|
|
4253
|
+
*/
|
|
4254
|
+
commitOutputSubstituted() {
|
|
4255
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4256
|
+
this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} commitOutputSubstituted`);
|
|
4257
|
+
this._outputEpoch += 1;
|
|
4258
|
+
}
|
|
4031
4259
|
/**
|
|
4032
4260
|
* Waits for the next output to be emitted via _outputSubject, typically after execute or run.
|
|
4033
4261
|
* Useful for external consumers (e.g., SwarmConnectionService) awaiting agent responses.
|
|
@@ -4126,7 +4354,22 @@ class ClientAgent {
|
|
|
4126
4354
|
}
|
|
4127
4355
|
else if (GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom") {
|
|
4128
4356
|
console.warn(`agent-swarm model using custom resurrect for agentName=${this.params.agentName} clientId=${this.params.clientId} validation=${validation}`);
|
|
4129
|
-
|
|
4357
|
+
let output;
|
|
4358
|
+
try {
|
|
4359
|
+
output = await GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION(this.params.clientId, this.params.agentName);
|
|
4360
|
+
}
|
|
4361
|
+
catch (error) {
|
|
4362
|
+
// A throwing custom resque function must not reject the queued
|
|
4363
|
+
// EXECUTE_FN: degrade to a placeholder answer instead.
|
|
4364
|
+
console.error(`agent-swarm CC_TOOL_CALL_EXCEPTION_CUSTOM_FUNCTION error agentName=${this.params.agentName} error=${getErrorMessage(error)}`);
|
|
4365
|
+
await errorSubject.next([this.params.clientId, error]);
|
|
4366
|
+
output = {
|
|
4367
|
+
agentName: this.params.agentName,
|
|
4368
|
+
mode: "tool",
|
|
4369
|
+
role: "assistant",
|
|
4370
|
+
content: createPlaceholder(),
|
|
4371
|
+
};
|
|
4372
|
+
}
|
|
4130
4373
|
this.params.completion.callbacks?.onComplete &&
|
|
4131
4374
|
this.params.completion.callbacks?.onComplete(args, output);
|
|
4132
4375
|
return output;
|
|
@@ -4241,6 +4484,7 @@ class ClientAgent {
|
|
|
4241
4484
|
async commitCancelOutput() {
|
|
4242
4485
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4243
4486
|
this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} commitCancelOutput`);
|
|
4487
|
+
this._outputEpoch += 1;
|
|
4244
4488
|
this._toolAbortController.abort();
|
|
4245
4489
|
await this._cancelOutputSubject.next(CANCEL_OUTPUT_SYMBOL);
|
|
4246
4490
|
await this.params.bus.emit(this.params.clientId, {
|
|
@@ -4409,6 +4653,14 @@ class ClientAgent {
|
|
|
4409
4653
|
async dispose() {
|
|
4410
4654
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4411
4655
|
this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} dispose`);
|
|
4656
|
+
if (this._activeExecutions > 0) {
|
|
4657
|
+
// The instance is being torn down while its execution is still running
|
|
4658
|
+
// (e.g. changeToAgent mid-completion). Resolve the pending waiter with an
|
|
4659
|
+
// empty output and invalidate the epoch so the late completion result of
|
|
4660
|
+
// the dying instance is dropped instead of poisoning the next waiter.
|
|
4661
|
+
this._outputEpoch += 1;
|
|
4662
|
+
await this._outputSubject.next("");
|
|
4663
|
+
}
|
|
4412
4664
|
{
|
|
4413
4665
|
this._agentChangeSubject.unsubscribeAll();
|
|
4414
4666
|
this._resqueSubject.unsubscribeAll();
|
|
@@ -4424,8 +4676,6 @@ class ClientAgent {
|
|
|
4424
4676
|
}
|
|
4425
4677
|
}
|
|
4426
4678
|
|
|
4427
|
-
/** Timeout duration for operator signal in milliseconds*/
|
|
4428
|
-
const OPERATOR_SIGNAL_TIMEOUT = 90000;
|
|
4429
4679
|
/** Symbol representing operator timeout*/
|
|
4430
4680
|
const OPERATOR_SIGNAL_SYMBOL = Symbol("operator-timeout");
|
|
4431
4681
|
/**
|
|
@@ -4457,8 +4707,9 @@ class OperatorSignal {
|
|
|
4457
4707
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4458
4708
|
this.params.logger.debug(`OperatorSignal agentName=${this.params.agentName} clientId=${this.params.clientId} dispose`);
|
|
4459
4709
|
if (this._disposeRef) {
|
|
4710
|
+
const disposeRef = this._disposeRef;
|
|
4460
4711
|
this._disposeRef = null;
|
|
4461
|
-
await
|
|
4712
|
+
await disposeRef();
|
|
4462
4713
|
}
|
|
4463
4714
|
}
|
|
4464
4715
|
}
|
|
@@ -4493,10 +4744,13 @@ class ClientOperator {
|
|
|
4493
4744
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4494
4745
|
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} execute begin`, { input, mode });
|
|
4495
4746
|
if (mode === "tool") {
|
|
4496
|
-
|
|
4747
|
+
// A tool-mode execute reaching an operator is normal: navigation to an
|
|
4748
|
+
// operator agent ends with executeForce (mode "tool"). Forward it to the
|
|
4749
|
+
// human instead of returning silently — returning would leave the
|
|
4750
|
+
// enclosing waitForOutput hanging forever, making the operator agent
|
|
4751
|
+
// unreachable through navigation.
|
|
4497
4752
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4498
|
-
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} execute
|
|
4499
|
-
return;
|
|
4753
|
+
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} execute tool mode forwarded to operator`);
|
|
4500
4754
|
}
|
|
4501
4755
|
this._operatorSignal.sendMessage(input, this._outgoingSubject.next);
|
|
4502
4756
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
@@ -4513,11 +4767,11 @@ class ClientOperator {
|
|
|
4513
4767
|
}
|
|
4514
4768
|
const result = await Promise.race([
|
|
4515
4769
|
this._outgoingSubject.toPromise(),
|
|
4516
|
-
sleep(
|
|
4770
|
+
sleep(GLOBAL_CONFIG.CC_OPERATOR_SIGNAL_TIMEOUT).then(() => OPERATOR_SIGNAL_SYMBOL),
|
|
4517
4771
|
]);
|
|
4518
4772
|
if (typeof result === "symbol") {
|
|
4519
4773
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
4520
|
-
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} waitForOutput timeout after ${
|
|
4774
|
+
this.params.logger.debug(`ClientOperator agentName=${this.params.agentName} clientId=${this.params.clientId} waitForOutput timeout after ${GLOBAL_CONFIG.CC_OPERATOR_SIGNAL_TIMEOUT}ms`);
|
|
4521
4775
|
await this._operatorSignal.dispose();
|
|
4522
4776
|
return "";
|
|
4523
4777
|
}
|
|
@@ -4624,26 +4878,26 @@ class ClientOperator {
|
|
|
4624
4878
|
}
|
|
4625
4879
|
}
|
|
4626
4880
|
|
|
4627
|
-
const METHOD_NAME$
|
|
4881
|
+
const METHOD_NAME$1M = "function.commit.commitToolOutput";
|
|
4628
4882
|
/**
|
|
4629
4883
|
* Function implementation
|
|
4630
4884
|
*/
|
|
4631
4885
|
const commitToolOutputInternal = beginContext(async (toolId, content, clientId, agentName) => {
|
|
4632
4886
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
4633
4887
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4634
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
4888
|
+
swarm$1.loggerService.log(METHOD_NAME$1M, {
|
|
4635
4889
|
toolId,
|
|
4636
4890
|
content,
|
|
4637
4891
|
clientId,
|
|
4638
4892
|
agentName,
|
|
4639
4893
|
});
|
|
4640
4894
|
// Validate the agent, session, and swarm to ensure they exist and are accessible
|
|
4641
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
4642
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
4895
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1M);
|
|
4896
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1M);
|
|
4643
4897
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
4644
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
4898
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1M);
|
|
4645
4899
|
// Check if the specified agent is still the active agent in the swarm session
|
|
4646
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
4900
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1M, clientId, swarmName);
|
|
4647
4901
|
if (currentAgentName !== agentName) {
|
|
4648
4902
|
// Log a skip message if the agent has changed during the operation
|
|
4649
4903
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
@@ -4656,7 +4910,7 @@ const commitToolOutputInternal = beginContext(async (toolId, content, clientId,
|
|
|
4656
4910
|
return;
|
|
4657
4911
|
}
|
|
4658
4912
|
// Commit the tool output to the session via the session public service
|
|
4659
|
-
await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$
|
|
4913
|
+
await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$1M, clientId, swarmName);
|
|
4660
4914
|
});
|
|
4661
4915
|
/**
|
|
4662
4916
|
* Commits the output of a tool execution to the active agent in a swarm session.
|
|
@@ -4678,10 +4932,7 @@ async function commitToolOutput(toolId, content, clientId, agentName) {
|
|
|
4678
4932
|
return await commitToolOutputInternal(toolId, content, clientId, agentName);
|
|
4679
4933
|
}
|
|
4680
4934
|
|
|
4681
|
-
const
|
|
4682
|
-
const errorSubject = new Subject();
|
|
4683
|
-
|
|
4684
|
-
const METHOD_NAME$1K = "function.target.execute";
|
|
4935
|
+
const METHOD_NAME$1L = "function.target.execute";
|
|
4685
4936
|
/**
|
|
4686
4937
|
* Function implementation
|
|
4687
4938
|
*/
|
|
@@ -4689,19 +4940,19 @@ const executeInternal = beginContext(async (content, clientId, agentName) => {
|
|
|
4689
4940
|
const executionId = randomString();
|
|
4690
4941
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
4691
4942
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4692
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
4943
|
+
swarm$1.loggerService.log(METHOD_NAME$1L, {
|
|
4693
4944
|
content,
|
|
4694
4945
|
clientId,
|
|
4695
4946
|
agentName,
|
|
4696
4947
|
executionId,
|
|
4697
4948
|
});
|
|
4698
4949
|
// Validate the agent, session, and swarm
|
|
4699
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
4700
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
4950
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1L);
|
|
4951
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1L);
|
|
4701
4952
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
4702
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
4953
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1L);
|
|
4703
4954
|
// Check if the specified agent is still the active agent
|
|
4704
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
4955
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1L, clientId, swarmName);
|
|
4705
4956
|
if (currentAgentName !== agentName) {
|
|
4706
4957
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4707
4958
|
swarm$1.loggerService.log('function "execute" skipped due to the agent change', {
|
|
@@ -4727,7 +4978,7 @@ const executeInternal = beginContext(async (content, clientId, agentName) => {
|
|
|
4727
4978
|
errorValue = error;
|
|
4728
4979
|
}
|
|
4729
4980
|
});
|
|
4730
|
-
result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$
|
|
4981
|
+
result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$1L, clientId, swarmName);
|
|
4731
4982
|
unError();
|
|
4732
4983
|
if (errorValue) {
|
|
4733
4984
|
throw errorValue;
|
|
@@ -4773,26 +5024,26 @@ async function execute(content, clientId, agentName) {
|
|
|
4773
5024
|
}
|
|
4774
5025
|
|
|
4775
5026
|
/** @private Constant defining the method name for logging and validation context*/
|
|
4776
|
-
const METHOD_NAME$
|
|
5027
|
+
const METHOD_NAME$1K = "function.commit.commitFlush";
|
|
4777
5028
|
/**
|
|
4778
5029
|
* Function implementation
|
|
4779
5030
|
*/
|
|
4780
5031
|
const commitFlushInternal = beginContext(async (clientId, agentName) => {
|
|
4781
5032
|
// Log the flush attempt if enabled
|
|
4782
5033
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4783
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
5034
|
+
swarm$1.loggerService.log(METHOD_NAME$1K, {
|
|
4784
5035
|
clientId,
|
|
4785
5036
|
agentName,
|
|
4786
5037
|
});
|
|
4787
5038
|
// Validate the agent exists
|
|
4788
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
5039
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1K);
|
|
4789
5040
|
// Validate the session exists and retrieve the associated swarm
|
|
4790
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
5041
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1K);
|
|
4791
5042
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
4792
5043
|
// Validate the swarm configuration
|
|
4793
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
5044
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1K);
|
|
4794
5045
|
// Check if the current agent matches the provided agent
|
|
4795
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
5046
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1K, clientId, swarmName);
|
|
4796
5047
|
if (currentAgentName !== agentName) {
|
|
4797
5048
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4798
5049
|
swarm$1.loggerService.log('function "commitFlush" skipped due to the agent change', {
|
|
@@ -4803,7 +5054,7 @@ const commitFlushInternal = beginContext(async (clientId, agentName) => {
|
|
|
4803
5054
|
return;
|
|
4804
5055
|
}
|
|
4805
5056
|
// Commit the flush of agent history via SessionPublicService
|
|
4806
|
-
await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$
|
|
5057
|
+
await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$1K, clientId, swarmName);
|
|
4807
5058
|
});
|
|
4808
5059
|
/**
|
|
4809
5060
|
* Commits a flush of agent history for a specific client and agent in the swarm system.
|
|
@@ -4822,25 +5073,25 @@ async function commitFlush(clientId, agentName) {
|
|
|
4822
5073
|
return await commitFlushInternal(clientId, agentName);
|
|
4823
5074
|
}
|
|
4824
5075
|
|
|
4825
|
-
const METHOD_NAME$
|
|
5076
|
+
const METHOD_NAME$1J = "function.target.emit";
|
|
4826
5077
|
/**
|
|
4827
5078
|
* Function implementation
|
|
4828
5079
|
*/
|
|
4829
5080
|
const emitInternal = beginContext(async (content, clientId, agentName) => {
|
|
4830
5081
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
4831
5082
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4832
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
5083
|
+
swarm$1.loggerService.log(METHOD_NAME$1J, {
|
|
4833
5084
|
content,
|
|
4834
5085
|
clientId,
|
|
4835
5086
|
agentName,
|
|
4836
5087
|
});
|
|
4837
5088
|
// Validate the agent, session, and swarm
|
|
4838
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
4839
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
5089
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1J);
|
|
5090
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1J);
|
|
4840
5091
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
4841
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
5092
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1J);
|
|
4842
5093
|
// Check if the specified agent is still the active agent
|
|
4843
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
5094
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1J, clientId, swarmName);
|
|
4844
5095
|
if (currentAgentName !== agentName) {
|
|
4845
5096
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4846
5097
|
swarm$1.loggerService.log('function "emit" skipped due to the agent change', {
|
|
@@ -4851,21 +5102,21 @@ const emitInternal = beginContext(async (content, clientId, agentName) => {
|
|
|
4851
5102
|
return;
|
|
4852
5103
|
}
|
|
4853
5104
|
// Emit the content directly via the session public service
|
|
4854
|
-
return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$
|
|
5105
|
+
return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$1J, clientId, swarmName);
|
|
4855
5106
|
});
|
|
4856
5107
|
/**
|
|
4857
5108
|
* Emits a string as model output without executing an incoming message, with agent activity validation.
|
|
4858
5109
|
*
|
|
4859
|
-
* This function directly emits a provided string as output from the swarm session, bypassing message execution
|
|
4860
|
-
*
|
|
4861
|
-
*
|
|
4862
|
-
* logs the operation if enabled
|
|
5110
|
+
* This function directly emits a provided string as output from the swarm session, bypassing message execution.
|
|
5111
|
+
* It validates the session, swarm, and specified agent, ensuring the agent is still active before emitting.
|
|
5112
|
+
* If the active agent has changed, the operation is skipped. The execution is wrapped in `beginContext` for a
|
|
5113
|
+
* clean environment and logs the operation if enabled. Works for any session mode.
|
|
4863
5114
|
*
|
|
4864
5115
|
*
|
|
4865
5116
|
* @param {string} content - The content to be processed or stored.
|
|
4866
5117
|
* @param {string} clientId - The unique identifier of the client session.
|
|
4867
5118
|
* @param {AgentName} agentName - The name of the agent to use or reference.
|
|
4868
|
-
* @throws {Error} If
|
|
5119
|
+
* @throws {Error} If agent, session, or swarm validation fails.
|
|
4869
5120
|
* @example
|
|
4870
5121
|
* await emit("Direct output", "client-123", "AgentX"); // Emits "Direct output" if AgentX is active
|
|
4871
5122
|
*/
|
|
@@ -4873,22 +5124,22 @@ async function emit(content, clientId, agentName) {
|
|
|
4873
5124
|
return await emitInternal(content, clientId, agentName);
|
|
4874
5125
|
}
|
|
4875
5126
|
|
|
4876
|
-
const METHOD_NAME$
|
|
5127
|
+
const METHOD_NAME$1I = "function.common.getAgentName";
|
|
4877
5128
|
/**
|
|
4878
5129
|
* Function implementation
|
|
4879
5130
|
*/
|
|
4880
5131
|
const getAgentNameInternal = beginContext(async (clientId) => {
|
|
4881
5132
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
4882
5133
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4883
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
5134
|
+
swarm$1.loggerService.log(METHOD_NAME$1I, {
|
|
4884
5135
|
clientId,
|
|
4885
5136
|
});
|
|
4886
5137
|
// Validate the session and swarm to ensure they exist and are accessible
|
|
4887
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
5138
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1I);
|
|
4888
5139
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
4889
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
5140
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1I);
|
|
4890
5141
|
// Retrieve the active agent name via the swarm public service
|
|
4891
|
-
return await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
5142
|
+
return await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1I, clientId, swarmName);
|
|
4892
5143
|
});
|
|
4893
5144
|
/**
|
|
4894
5145
|
* Retrieves the name of the active agent for a given client session in a swarm.
|
|
@@ -4909,26 +5160,26 @@ async function getAgentName(clientId) {
|
|
|
4909
5160
|
}
|
|
4910
5161
|
|
|
4911
5162
|
/** @private Constant defining the method name for logging and validation context*/
|
|
4912
|
-
const METHOD_NAME$
|
|
5163
|
+
const METHOD_NAME$1H = "function.commit.commitStopTools";
|
|
4913
5164
|
/**
|
|
4914
5165
|
* Function implementation
|
|
4915
5166
|
*/
|
|
4916
5167
|
const commitStopToolsInternal = beginContext(async (clientId, agentName) => {
|
|
4917
5168
|
// Log the stop tools attempt if enabled
|
|
4918
5169
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4919
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
5170
|
+
swarm$1.loggerService.log(METHOD_NAME$1H, {
|
|
4920
5171
|
clientId,
|
|
4921
5172
|
agentName,
|
|
4922
5173
|
});
|
|
4923
5174
|
// Validate the agent exists
|
|
4924
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
5175
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1H);
|
|
4925
5176
|
// Validate the session exists and retrieve the associated swarm
|
|
4926
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
5177
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1H);
|
|
4927
5178
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
4928
5179
|
// Validate the swarm configuration
|
|
4929
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
5180
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1H);
|
|
4930
5181
|
// Check if the current agent matches the provided agent
|
|
4931
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
5182
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1H, clientId, swarmName);
|
|
4932
5183
|
if (currentAgentName !== agentName) {
|
|
4933
5184
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
4934
5185
|
swarm$1.loggerService.log('function "commitStopTools" skipped due to the agent change', {
|
|
@@ -4939,7 +5190,7 @@ const commitStopToolsInternal = beginContext(async (clientId, agentName) => {
|
|
|
4939
5190
|
return;
|
|
4940
5191
|
}
|
|
4941
5192
|
// Commit the stop of the next tool execution via SessionPublicService
|
|
4942
|
-
await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$
|
|
5193
|
+
await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$1H, clientId, swarmName);
|
|
4943
5194
|
});
|
|
4944
5195
|
/**
|
|
4945
5196
|
* Prevents the next tool from being executed for a specific client and agent in the swarm system.
|
|
@@ -5158,6 +5409,63 @@ class MCPUtils {
|
|
|
5158
5409
|
*/
|
|
5159
5410
|
const MCP = new MCPUtils();
|
|
5160
5411
|
|
|
5412
|
+
/**
|
|
5413
|
+
* Wraps schema observer callbacks (onExecute, onOutput, onInit, ...) so a throwing
|
|
5414
|
+
* callback cannot reject the queued agent execution. ClientAgent invokes these
|
|
5415
|
+
* fire-and-forget from EXECUTE_FN/RUN_FN: an uncaught throw there becomes an
|
|
5416
|
+
* unhandled rejection and the pending waitForOutput hangs forever.
|
|
5417
|
+
* Callbacks are observers — log the error and keep the flow running.
|
|
5418
|
+
*/
|
|
5419
|
+
const guardAgentCallbacks = (callbacks, agentName) => {
|
|
5420
|
+
if (!callbacks) {
|
|
5421
|
+
return {};
|
|
5422
|
+
}
|
|
5423
|
+
const result = {};
|
|
5424
|
+
for (const [key, value] of Object.entries(callbacks)) {
|
|
5425
|
+
if (typeof value !== "function") {
|
|
5426
|
+
result[key] = value;
|
|
5427
|
+
continue;
|
|
5428
|
+
}
|
|
5429
|
+
result[key] = (...args) => {
|
|
5430
|
+
try {
|
|
5431
|
+
const output = value(...args);
|
|
5432
|
+
if (output && typeof output.catch === "function") {
|
|
5433
|
+
output.catch((error) => console.error(`agent-swarm ${key} agent callback error agentName=${agentName} error=${getErrorMessage(error)}`));
|
|
5434
|
+
}
|
|
5435
|
+
return output;
|
|
5436
|
+
}
|
|
5437
|
+
catch (error) {
|
|
5438
|
+
console.error(`agent-swarm ${key} agent callback error agentName=${agentName} error=${getErrorMessage(error)}`);
|
|
5439
|
+
}
|
|
5440
|
+
};
|
|
5441
|
+
}
|
|
5442
|
+
return result;
|
|
5443
|
+
};
|
|
5444
|
+
/**
|
|
5445
|
+
* Wraps a schema transformer hook (transform/map/mapToolCalls/prompt/systemDynamic).
|
|
5446
|
+
* A throwing transformer is a configuration error: it is surfaced to the caller
|
|
5447
|
+
* through errorSubject (session.complete/execute reject after the exchange), while
|
|
5448
|
+
* the flow continues with the untouched input value — falling back to an empty
|
|
5449
|
+
* result here would re-enter the resurrect path whose own transform call throws
|
|
5450
|
+
* again, deadlocking the execution.
|
|
5451
|
+
*
|
|
5452
|
+
* @param fn - The user transformer to guard.
|
|
5453
|
+
* @param name - Hook name for logging.
|
|
5454
|
+
* @param agentName - Owning agent name for logging.
|
|
5455
|
+
* @param getClientId - Extracts clientId from the call arguments for errorSubject.
|
|
5456
|
+
* @param getFallback - Produces the fallback result from the call arguments.
|
|
5457
|
+
*/
|
|
5458
|
+
const guardAgentTransformer = (fn, name, agentName, getClientId, getFallback) => (async (...args) => {
|
|
5459
|
+
try {
|
|
5460
|
+
return await fn(...args);
|
|
5461
|
+
}
|
|
5462
|
+
catch (error) {
|
|
5463
|
+
console.error(`agent-swarm ${name} hook error agentName=${agentName} error=${getErrorMessage(error)}`);
|
|
5464
|
+
await errorSubject.next([getClientId(...args), error]);
|
|
5465
|
+
return getFallback(...args);
|
|
5466
|
+
}
|
|
5467
|
+
});
|
|
5468
|
+
|
|
5161
5469
|
/**
|
|
5162
5470
|
* Service class for managing agent connections and operations in the swarm system.
|
|
5163
5471
|
* Implements IAgent to provide an interface for agent instantiation, execution, message handling, and lifecycle management.
|
|
@@ -5246,10 +5554,12 @@ class AgentConnectionService {
|
|
|
5246
5554
|
this.sessionValidationService.addAgentUsage(clientId, agentName);
|
|
5247
5555
|
storages?.forEach((storageName) => this.storageConnectionService
|
|
5248
5556
|
.getStorage(clientId, storageName)
|
|
5249
|
-
.waitForInit()
|
|
5557
|
+
.waitForInit()
|
|
5558
|
+
.catch((error) => console.error(`agent-swarm storage waitForInit error storageName=${storageName} clientId=${clientId} error=${getErrorMessage(error)}`)));
|
|
5250
5559
|
states?.forEach((stateName) => this.stateConnectionService
|
|
5251
5560
|
.getStateRef(clientId, stateName)
|
|
5252
|
-
.waitForInit()
|
|
5561
|
+
.waitForInit()
|
|
5562
|
+
.catch((error) => console.error(`agent-swarm state waitForInit error stateName=${stateName} clientId=${clientId} error=${getErrorMessage(error)}`)));
|
|
5253
5563
|
if (operator) {
|
|
5254
5564
|
return new ClientOperator({
|
|
5255
5565
|
clientId,
|
|
@@ -5258,29 +5568,33 @@ class AgentConnectionService {
|
|
|
5258
5568
|
history,
|
|
5259
5569
|
logger: this.loggerService,
|
|
5260
5570
|
connectOperator,
|
|
5261
|
-
...callbacks,
|
|
5571
|
+
...guardAgentCallbacks(callbacks, agentName),
|
|
5262
5572
|
});
|
|
5263
5573
|
}
|
|
5264
5574
|
return new ClientAgent({
|
|
5265
5575
|
clientId,
|
|
5266
5576
|
agentName,
|
|
5267
|
-
validate,
|
|
5577
|
+
validate: guardAgentTransformer(validate, "validate", agentName, () => clientId, () => null),
|
|
5268
5578
|
maxToolCalls,
|
|
5269
|
-
mapToolCalls,
|
|
5579
|
+
mapToolCalls: guardAgentTransformer(mapToolCalls, "mapToolCalls", agentName, (_calls, callClientId) => callClientId, (calls) => calls),
|
|
5270
5580
|
logger: this.loggerService,
|
|
5271
5581
|
bus: this.busService,
|
|
5272
5582
|
mcp: mcp
|
|
5273
5583
|
? new MergeMCP(mcp.map(this.mcpConnectionService.getMCP), agentName)
|
|
5274
5584
|
: new NoopMCP(agentName),
|
|
5275
5585
|
history,
|
|
5276
|
-
prompt
|
|
5586
|
+
prompt: typeof prompt === "function"
|
|
5587
|
+
? guardAgentTransformer(prompt, "prompt", agentName, (callClientId) => callClientId, () => "")
|
|
5588
|
+
: prompt,
|
|
5277
5589
|
systemStatic,
|
|
5278
|
-
systemDynamic
|
|
5279
|
-
|
|
5280
|
-
|
|
5590
|
+
systemDynamic: systemDynamic
|
|
5591
|
+
? guardAgentTransformer(systemDynamic, "systemDynamic", agentName, (callClientId) => callClientId, () => [])
|
|
5592
|
+
: systemDynamic,
|
|
5593
|
+
transform: guardAgentTransformer(transform, "transform", agentName, (_text, callClientId) => callClientId, (text) => text),
|
|
5594
|
+
map: guardAgentTransformer(map, "map", agentName, (_message, callClientId) => callClientId, (message) => message),
|
|
5281
5595
|
tools: tools?.map(this.toolSchemaService.get),
|
|
5282
5596
|
completion: this.completionSchemaService.get(completionName),
|
|
5283
|
-
...callbacks,
|
|
5597
|
+
...guardAgentCallbacks(callbacks, agentName),
|
|
5284
5598
|
});
|
|
5285
5599
|
});
|
|
5286
5600
|
/**
|
|
@@ -5453,12 +5767,12 @@ class AgentConnectionService {
|
|
|
5453
5767
|
}
|
|
5454
5768
|
|
|
5455
5769
|
/** @private Constant defining the method name for logging purposes*/
|
|
5456
|
-
const METHOD_NAME$
|
|
5770
|
+
const METHOD_NAME$1G = "function.common.getPayload";
|
|
5457
5771
|
/**
|
|
5458
5772
|
* Function implementation
|
|
5459
5773
|
*/
|
|
5460
5774
|
const getPayloadInternal = () => {
|
|
5461
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
5775
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1G);
|
|
5462
5776
|
if (PayloadContextService.hasContext()) {
|
|
5463
5777
|
const { payload } = swarm$1.payloadContextService.context;
|
|
5464
5778
|
return payload;
|
|
@@ -5507,7 +5821,16 @@ class ClientHistory {
|
|
|
5507
5821
|
if (message.mode === "user" && message.role === "user") {
|
|
5508
5822
|
message = { ...message, payload: getPayload() };
|
|
5509
5823
|
}
|
|
5510
|
-
|
|
5824
|
+
try {
|
|
5825
|
+
await this.params.items.push(message, this.params.clientId, this.params.agentName);
|
|
5826
|
+
}
|
|
5827
|
+
catch (error) {
|
|
5828
|
+
// A throwing history adapter must not reject the queued EXECUTE_FN
|
|
5829
|
+
// (unhandled rejection + hung waitForOutput): drop the record, surface
|
|
5830
|
+
// the error through errorSubject so the caller's complete() rejects.
|
|
5831
|
+
console.error(`agent-swarm history push error agentName=${this.params.agentName} clientId=${this.params.clientId} error=${getErrorMessage(error)}`);
|
|
5832
|
+
await errorSubject.next([this.params.clientId, error]);
|
|
5833
|
+
}
|
|
5511
5834
|
await this.params.bus.emit(this.params.clientId, {
|
|
5512
5835
|
type: "push",
|
|
5513
5836
|
source: "history-bus",
|
|
@@ -5552,8 +5875,14 @@ class ClientHistory {
|
|
|
5552
5875
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
5553
5876
|
this.params.logger.debug(`ClientHistory agentName=${this.params.agentName} toArrayForRaw`);
|
|
5554
5877
|
const result = [];
|
|
5555
|
-
|
|
5556
|
-
|
|
5878
|
+
try {
|
|
5879
|
+
for await (const item of this.params.items.iterate(this.params.clientId, this.params.agentName)) {
|
|
5880
|
+
result.push(item);
|
|
5881
|
+
}
|
|
5882
|
+
}
|
|
5883
|
+
catch (error) {
|
|
5884
|
+
console.error(`agent-swarm history iterate error agentName=${this.params.agentName} clientId=${this.params.clientId} error=${getErrorMessage(error)}`);
|
|
5885
|
+
await errorSubject.next([this.params.clientId, error]);
|
|
5557
5886
|
}
|
|
5558
5887
|
return result;
|
|
5559
5888
|
}
|
|
@@ -5568,7 +5897,19 @@ class ClientHistory {
|
|
|
5568
5897
|
this.params.logger.debug(`ClientHistory agentName=${this.params.agentName} toArrayForAgent`);
|
|
5569
5898
|
const commonMessagesRaw = [];
|
|
5570
5899
|
const systemMessagesRaw = [];
|
|
5571
|
-
|
|
5900
|
+
const iterated = [];
|
|
5901
|
+
try {
|
|
5902
|
+
for await (const content of this.params.items.iterate(this.params.clientId, this.params.agentName)) {
|
|
5903
|
+
iterated.push(content);
|
|
5904
|
+
}
|
|
5905
|
+
}
|
|
5906
|
+
catch (error) {
|
|
5907
|
+
// A throwing history adapter or filter must not reject getCompletion
|
|
5908
|
+
// inside the queued EXECUTE_FN: continue with what was collected.
|
|
5909
|
+
console.error(`agent-swarm history iterate error agentName=${this.params.agentName} clientId=${this.params.clientId} error=${getErrorMessage(error)}`);
|
|
5910
|
+
await errorSubject.next([this.params.clientId, error]);
|
|
5911
|
+
}
|
|
5912
|
+
for (const content of iterated) {
|
|
5572
5913
|
const message = content;
|
|
5573
5914
|
if (message.role === "resque") {
|
|
5574
5915
|
commonMessagesRaw.splice(0, commonMessagesRaw.length);
|
|
@@ -5591,15 +5932,27 @@ class ClientHistory {
|
|
|
5591
5932
|
}
|
|
5592
5933
|
}
|
|
5593
5934
|
const systemMessages = systemMessagesRaw.filter(({ agentName }) => agentName === this.params.agentName);
|
|
5594
|
-
const
|
|
5935
|
+
const filteredCommonMessages = commonMessagesRaw
|
|
5595
5936
|
.map(({ content, tool_calls, ...other }) => ({
|
|
5596
5937
|
...other,
|
|
5597
5938
|
tool_calls,
|
|
5598
5939
|
content: content || "",
|
|
5599
5940
|
}))
|
|
5600
5941
|
.filter(({ content, tool_calls }) => !!content || !!tool_calls?.length)
|
|
5601
|
-
.filter(
|
|
5602
|
-
|
|
5942
|
+
.filter((message) => {
|
|
5943
|
+
try {
|
|
5944
|
+
return this._filterCondition(message);
|
|
5945
|
+
}
|
|
5946
|
+
catch (error) {
|
|
5947
|
+
console.error(`agent-swarm history filter error agentName=${this.params.agentName} error=${getErrorMessage(error)}`);
|
|
5948
|
+
return true;
|
|
5949
|
+
}
|
|
5950
|
+
});
|
|
5951
|
+
// slice(-0) === slice(0) keeps the WHOLE array, so keepMessages=0 would keep
|
|
5952
|
+
// all history instead of none — clamp explicitly to an empty window.
|
|
5953
|
+
const commonMessages = this.params.keepMessages > 0
|
|
5954
|
+
? filteredCommonMessages.slice(-this.params.keepMessages)
|
|
5955
|
+
: [];
|
|
5603
5956
|
const assistantToolOutputCallSet = new Set(commonMessages
|
|
5604
5957
|
.filter(({ tool_call_id }) => !!tool_call_id)
|
|
5605
5958
|
.map(({ tool_call_id }) => tool_call_id));
|
|
@@ -6187,10 +6540,50 @@ class ClientSwarm {
|
|
|
6187
6540
|
*/
|
|
6188
6541
|
this._cancelOutputSubject = new Subject();
|
|
6189
6542
|
/**
|
|
6190
|
-
*
|
|
6191
|
-
*
|
|
6543
|
+
* Chain of pending waitForOutput calls, reset to a resolved promise whenever
|
|
6544
|
+
* the most recently started waiter settles. See waitForOutput for the rationale.
|
|
6545
|
+
*/
|
|
6546
|
+
this._lastOutputAwaiter = Promise.resolve();
|
|
6547
|
+
/**
|
|
6548
|
+
* Waiters created by waitForOutput that have not settled yet, in creation order.
|
|
6549
|
+
* joinOutput attaches nested tool executions to the head of this list.
|
|
6550
|
+
*/
|
|
6551
|
+
this._pendingOutputAwaiters = [];
|
|
6552
|
+
/**
|
|
6553
|
+
* Waits for output from the active agent, delegating to WAIT_FOR_OUTPUT_FN.
|
|
6554
|
+
* Pending waiters run in FIFO order so each one consumes the next emitted output,
|
|
6555
|
+
* but once a started waiter settles the chain is reset: a waiter that subscribed
|
|
6556
|
+
* too late to observe its output stays pending without blocking waiters created
|
|
6557
|
+
* afterwards. Strict sequential queueing must be avoided here — a nested tool
|
|
6558
|
+
* execute whose output was already consumed would deadlock every later completion.
|
|
6192
6559
|
*/
|
|
6193
|
-
this.waitForOutput =
|
|
6560
|
+
this.waitForOutput = () => {
|
|
6561
|
+
const currentPromise = this._lastOutputAwaiter.then(async () => await WAIT_FOR_OUTPUT_FN(this));
|
|
6562
|
+
this._lastOutputAwaiter = currentPromise;
|
|
6563
|
+
this._pendingOutputAwaiters.push(currentPromise);
|
|
6564
|
+
const reset = () => {
|
|
6565
|
+
this._lastOutputAwaiter = Promise.resolve();
|
|
6566
|
+
const idx = this._pendingOutputAwaiters.indexOf(currentPromise);
|
|
6567
|
+
if (idx !== -1) {
|
|
6568
|
+
this._pendingOutputAwaiters.splice(idx, 1);
|
|
6569
|
+
}
|
|
6570
|
+
};
|
|
6571
|
+
currentPromise.then(reset, reset);
|
|
6572
|
+
return currentPromise;
|
|
6573
|
+
};
|
|
6574
|
+
/**
|
|
6575
|
+
* Awaits the same output as the oldest pending waitForOutput call, or starts a
|
|
6576
|
+
* fresh wait when none is pending. Nested executions triggered from inside a tool
|
|
6577
|
+
* (execute/executeForce with "tool" mode) must use this instead of waitForOutput:
|
|
6578
|
+
* their emitted output resolves the parent waiter, so queueing behind it would
|
|
6579
|
+
* leave the nested caller pending forever and skip the tool's onAfterCall.
|
|
6580
|
+
*/
|
|
6581
|
+
this.joinOutput = () => {
|
|
6582
|
+
if (this._pendingOutputAwaiters.length) {
|
|
6583
|
+
return this._pendingOutputAwaiters[0];
|
|
6584
|
+
}
|
|
6585
|
+
return this.waitForOutput();
|
|
6586
|
+
};
|
|
6194
6587
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
6195
6588
|
this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} CTOR`, {
|
|
6196
6589
|
params,
|
|
@@ -6204,6 +6597,13 @@ class ClientSwarm {
|
|
|
6204
6597
|
async emit(message) {
|
|
6205
6598
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
6206
6599
|
this.params.logger.debug(`ClientSwarm swarmName=${this.params.swarmName} clientId=${this.params.clientId} emit`);
|
|
6600
|
+
// The emitted message substitutes the output of any in-flight execution:
|
|
6601
|
+
// invalidate agents' pending emissions so a stale result cannot resolve
|
|
6602
|
+
// the waiter of the next message.
|
|
6603
|
+
for (const [, agent] of this._agentList) {
|
|
6604
|
+
const agentRef = agent;
|
|
6605
|
+
agentRef.commitOutputSubstituted?.();
|
|
6606
|
+
}
|
|
6207
6607
|
await this._emitSubject.next({
|
|
6208
6608
|
agentName: await this.getAgentName(),
|
|
6209
6609
|
output: message,
|
|
@@ -6231,6 +6631,13 @@ class ClientSwarm {
|
|
|
6231
6631
|
if (this._navigationStack === STACK_NEED_FETCH) {
|
|
6232
6632
|
this._navigationStack = await this.params.getNavigationStack(this.params.clientId, this.params.swarmName);
|
|
6233
6633
|
}
|
|
6634
|
+
// setAgentName pushes the NEW agent, so the top of the stack is the agent
|
|
6635
|
+
// we are currently on — drop it first, otherwise "previous" would resolve
|
|
6636
|
+
// to the active agent itself (self-navigation instead of going back).
|
|
6637
|
+
const activeAgent = await this.getAgentName();
|
|
6638
|
+
if (this._navigationStack[this._navigationStack.length - 1] === activeAgent) {
|
|
6639
|
+
this._navigationStack.pop();
|
|
6640
|
+
}
|
|
6234
6641
|
const prevAgent = this._navigationStack.pop();
|
|
6235
6642
|
await this.params.setNavigationStack(this.params.clientId, this._navigationStack, this.params.swarmName);
|
|
6236
6643
|
return prevAgent ? prevAgent : this.params.defaultAgent;
|
|
@@ -6376,6 +6783,18 @@ class ClientSwarm {
|
|
|
6376
6783
|
async dispose() {
|
|
6377
6784
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
6378
6785
|
this.params.logger.debug(`ClientSession clientId=${this.params.clientId} dispose`);
|
|
6786
|
+
if (this._pendingOutputAwaiters.length) {
|
|
6787
|
+
// Resolve in-flight waitForOutput calls with an empty output (same
|
|
6788
|
+
// contract as cancelOutput) before unsubscribing — otherwise a complete()
|
|
6789
|
+
// pending at dispose time would never settle.
|
|
6790
|
+
const agentName = this._activeAgent === AGENT_NEED_FETCH
|
|
6791
|
+
? this.params.defaultAgent
|
|
6792
|
+
: this._activeAgent;
|
|
6793
|
+
await this._cancelOutputSubject.next({
|
|
6794
|
+
agentName,
|
|
6795
|
+
output: "",
|
|
6796
|
+
});
|
|
6797
|
+
}
|
|
6379
6798
|
{
|
|
6380
6799
|
this._agentChangedSubject.unsubscribeAll();
|
|
6381
6800
|
this._emitSubject.unsubscribeAll();
|
|
@@ -6759,10 +7178,10 @@ class CompletionSchemaService {
|
|
|
6759
7178
|
throw new Error(`agent-swarm completion schema validation failed: missing getCompletion for completionName=${completionSchema.completionName}`);
|
|
6760
7179
|
}
|
|
6761
7180
|
if (completionSchema.flags && !Array.isArray(completionSchema.flags)) {
|
|
6762
|
-
throw new Error(`agent-swarm completion schema validation failed: invalid flags for
|
|
7181
|
+
throw new Error(`agent-swarm completion schema validation failed: invalid flags for completionName=${completionSchema.completionName} flags=${completionSchema.flags}`);
|
|
6763
7182
|
}
|
|
6764
7183
|
if (completionSchema.flags?.some((value) => typeof value !== "string")) {
|
|
6765
|
-
throw new Error(`agent-swarm completion schema validation failed: invalid flags for
|
|
7184
|
+
throw new Error(`agent-swarm completion schema validation failed: invalid flags for completionName=${completionSchema.completionName} flags=[${completionSchema.flags}]`);
|
|
6766
7185
|
}
|
|
6767
7186
|
};
|
|
6768
7187
|
/**
|
|
@@ -6945,7 +7364,15 @@ class ClientSession {
|
|
|
6945
7364
|
if (mode === "user") {
|
|
6946
7365
|
await this.AQUIRE_LOCK(this);
|
|
6947
7366
|
}
|
|
6948
|
-
|
|
7367
|
+
// A tool-mode execute issued while a tool call is still running is a nested
|
|
7368
|
+
// continuation of that execution: its output resolves the already pending
|
|
7369
|
+
// waiter, so it must join it. Standalone server-side tool-mode executes keep
|
|
7370
|
+
// the FIFO waitForOutput pairing.
|
|
7371
|
+
const isNestedToolExecution = mode === "tool" &&
|
|
7372
|
+
Object.values(this.params.swarm.params.agentMap).some((agentRef) => agentRef instanceof ClientAgent && agentRef._runningToolCalls > 0);
|
|
7373
|
+
const outputAwaiter = isNestedToolExecution
|
|
7374
|
+
? this.params.swarm.joinOutput()
|
|
7375
|
+
: this.params.swarm.waitForOutput();
|
|
6949
7376
|
agent.execute(message, mode);
|
|
6950
7377
|
let output = "";
|
|
6951
7378
|
try {
|
|
@@ -7229,12 +7656,19 @@ class ClientSession {
|
|
|
7229
7656
|
clientId: this.params.clientId,
|
|
7230
7657
|
});
|
|
7231
7658
|
this._notifySubject.subscribe(async (data) => {
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
|
-
|
|
7659
|
+
try {
|
|
7660
|
+
await swarm$1.executionValidationService.flushCount(this.params.clientId, this.params.swarmName);
|
|
7661
|
+
await connector({
|
|
7662
|
+
data,
|
|
7663
|
+
agentName: await this.params.swarm.getAgentName(),
|
|
7664
|
+
clientId: this.params.clientId,
|
|
7665
|
+
});
|
|
7666
|
+
}
|
|
7667
|
+
catch (error) {
|
|
7668
|
+
// A throwing connector must not reject the notify subject chain
|
|
7669
|
+
// (unhandled rejection that can crash the host process).
|
|
7670
|
+
console.error(`agent-swarm connector error clientId=${this.params.clientId} error=${getErrorMessage(error)}`);
|
|
7671
|
+
}
|
|
7238
7672
|
});
|
|
7239
7673
|
return async (incoming) => {
|
|
7240
7674
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
@@ -9270,9 +9704,13 @@ class AgentValidationService {
|
|
|
9270
9704
|
if (!agent) {
|
|
9271
9705
|
throw new Error(`agent-swarm agent ${agentName} not found source=${source}`);
|
|
9272
9706
|
}
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9707
|
+
// Operator agents may omit completion entirely (see validateShallow),
|
|
9708
|
+
// so the JSON-flag check only applies when a completion is configured.
|
|
9709
|
+
if (agent.completion) {
|
|
9710
|
+
const completionSchema = this.completionSchemaService.get(agent.completion);
|
|
9711
|
+
if (completionSchema.json) {
|
|
9712
|
+
throw new Error(`agent-swarm agent ${agentName} completion schema is JSON source=${source}`);
|
|
9713
|
+
}
|
|
9276
9714
|
}
|
|
9277
9715
|
if (!agent.operator) {
|
|
9278
9716
|
this.completionValidationService.validate(agent.completion, source);
|
|
@@ -10280,12 +10718,21 @@ const WAIT_FOR_INIT_FN$1 = async (self) => {
|
|
|
10280
10718
|
if (!self.params.getData) {
|
|
10281
10719
|
return;
|
|
10282
10720
|
}
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10721
|
+
try {
|
|
10722
|
+
const data = await self.params.getData(self.params.clientId, self.params.storageName, await self.params.getDefaultData(self.params.clientId, self.params.storageName));
|
|
10723
|
+
await Promise.all(data.map(execpool(self._createEmbedding, {
|
|
10724
|
+
delay: STORAGE_POOL_DELAY,
|
|
10725
|
+
maxExec: GLOBAL_CONFIG.CC_STORAGE_SEARCH_POOL,
|
|
10726
|
+
})));
|
|
10727
|
+
self._itemMap = new Map(data.map((item) => [item.id, item]));
|
|
10728
|
+
}
|
|
10729
|
+
catch (error) {
|
|
10730
|
+
// waitForInit is fired without await from AgentConnectionService.getAgent:
|
|
10731
|
+
// a rejecting persistence adapter would otherwise crash the host process.
|
|
10732
|
+
// Degrade to an empty storage and surface the error.
|
|
10733
|
+
console.error(`agent-swarm storage init error storageName=${self.params.storageName} clientId=${self.params.clientId} error=${getErrorMessage(error)}`);
|
|
10734
|
+
await errorSubject.next([self.params.clientId, error]);
|
|
10735
|
+
}
|
|
10289
10736
|
};
|
|
10290
10737
|
/**
|
|
10291
10738
|
* Upserts an item into the storage, updates embeddings, and persists the data via params.setData.
|
|
@@ -10449,9 +10896,11 @@ class ClientStorage {
|
|
|
10449
10896
|
total,
|
|
10450
10897
|
});
|
|
10451
10898
|
const indexed = new SortedArray();
|
|
10452
|
-
|
|
10899
|
+
const searchHash = createSHA256Hash(search);
|
|
10900
|
+
let searchEmbeddings = await this.params.readEmbeddingCache(this.params.embedding, searchHash);
|
|
10453
10901
|
if (!searchEmbeddings) {
|
|
10454
10902
|
searchEmbeddings = await this.params.createEmbedding(search, this.params.embedding);
|
|
10903
|
+
await this.params.writeEmbeddingCache(searchEmbeddings, this.params.embedding, searchHash);
|
|
10455
10904
|
}
|
|
10456
10905
|
if (this.params.onCreate) {
|
|
10457
10906
|
this.params.onCreate(search, searchEmbeddings, this.params.clientId, this.params.embedding);
|
|
@@ -11279,7 +11728,15 @@ const DISPATCH_FN = async (action, self, payload) => {
|
|
|
11279
11728
|
const WAIT_FOR_INIT_FN = async (self) => {
|
|
11280
11729
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
11281
11730
|
self.params.logger.debug(`ClientState stateName=${self.params.stateName} clientId=${self.params.clientId} shared=${self.params.shared} waitForInit`);
|
|
11282
|
-
|
|
11731
|
+
try {
|
|
11732
|
+
self._state = await self.params.getState(self.params.clientId, self.params.stateName, await self.params.getDefaultState(self.params.clientId, self.params.stateName));
|
|
11733
|
+
}
|
|
11734
|
+
catch (error) {
|
|
11735
|
+
// waitForInit is fired without await from AgentConnectionService.getAgent:
|
|
11736
|
+
// a rejecting persistence adapter would otherwise crash the host process.
|
|
11737
|
+
console.error(`agent-swarm state init error stateName=${self.params.stateName} clientId=${self.params.clientId} error=${getErrorMessage(error)}`);
|
|
11738
|
+
await errorSubject.next([self.params.clientId, error]);
|
|
11739
|
+
}
|
|
11283
11740
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
11284
11741
|
self.params.logger.debug(`ClientState stateName=${self.params.stateName} clientId=${self.params.clientId} shared=${self.params.shared} waitForInit output`, { initialState: self._state });
|
|
11285
11742
|
if (self.params.callbacks?.onLoad) {
|
|
@@ -11300,6 +11757,12 @@ class ClientState {
|
|
|
11300
11757
|
constructor(params) {
|
|
11301
11758
|
this.params = params;
|
|
11302
11759
|
this.stateChanged = new Subject();
|
|
11760
|
+
/**
|
|
11761
|
+
* True while a queued dispatch (read/write) is executing for this instance.
|
|
11762
|
+
* getState checks it to serve reentrant reads (getState inside a setState
|
|
11763
|
+
* dispatchFn) without re-entering the queue, which would deadlock.
|
|
11764
|
+
*/
|
|
11765
|
+
this._inDispatch = false;
|
|
11303
11766
|
/**
|
|
11304
11767
|
* The current state data, initialized as null and set during waitForInit.
|
|
11305
11768
|
* Updated by setState and clearState, persisted via params.setState if provided.
|
|
@@ -11309,7 +11772,15 @@ class ClientState {
|
|
|
11309
11772
|
* Queued dispatch function to read or write the state, delegating to DISPATCH_FN.
|
|
11310
11773
|
* Ensures thread-safe state operations, supporting concurrent access from ClientAgent or tools.
|
|
11311
11774
|
*/
|
|
11312
|
-
this.dispatch = queued(async (action, payload) =>
|
|
11775
|
+
this.dispatch = queued(async (action, payload) => {
|
|
11776
|
+
this._inDispatch = true;
|
|
11777
|
+
try {
|
|
11778
|
+
return await DISPATCH_FN(action, this, payload);
|
|
11779
|
+
}
|
|
11780
|
+
finally {
|
|
11781
|
+
this._inDispatch = false;
|
|
11782
|
+
}
|
|
11783
|
+
});
|
|
11313
11784
|
/**
|
|
11314
11785
|
* Waits for the state to initialize via WAIT_FOR_INIT_FN, ensuring it’s only called once using singleshot.
|
|
11315
11786
|
* Loads the initial state into _state, supporting StateConnectionService’s lifecycle management.
|
|
@@ -11398,7 +11869,14 @@ class ClientState {
|
|
|
11398
11869
|
async getState() {
|
|
11399
11870
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
11400
11871
|
this.params.logger.debug(`ClientState stateName=${this.params.stateName} clientId=${this.params.clientId} shared=${this.params.shared} getState`);
|
|
11401
|
-
|
|
11872
|
+
// Reads normally go through the dispatch queue to observe writes in order.
|
|
11873
|
+
// A read issued from INSIDE a running write (getState within a setState
|
|
11874
|
+
// dispatchFn) would deadlock behind that write, so _inDispatch lets such a
|
|
11875
|
+
// reentrant read return the current field directly.
|
|
11876
|
+
if (this._inDispatch) ;
|
|
11877
|
+
else {
|
|
11878
|
+
await this.dispatch("read");
|
|
11879
|
+
}
|
|
11402
11880
|
if (this.params.callbacks?.onRead) {
|
|
11403
11881
|
this.params.callbacks.onRead(this._state, this.params.clientId, this.params.stateName);
|
|
11404
11882
|
}
|
|
@@ -11702,8 +12180,27 @@ class StatePublicService {
|
|
|
11702
12180
|
}
|
|
11703
12181
|
|
|
11704
12182
|
/**
|
|
11705
|
-
*
|
|
11706
|
-
*
|
|
12183
|
+
* Wraps a bus listener so its exceptions cannot escape into the emit path.
|
|
12184
|
+
* ClientAgent awaits bus.emit inside executions: a throwing subscriber would
|
|
12185
|
+
* otherwise surface as an unhandled rejection (crashing the host process on
|
|
12186
|
+
* modern Node) or reject the execution itself.
|
|
12187
|
+
*/
|
|
12188
|
+
const GUARD_LISTENER_FN = (fn, clientId, source) => (event) => {
|
|
12189
|
+
try {
|
|
12190
|
+
const output = fn(event);
|
|
12191
|
+
if (output &&
|
|
12192
|
+
typeof output.catch === "function") {
|
|
12193
|
+
output.catch((error) => console.error(`agent-swarm bus listener error clientId=${clientId} source=${source} error=${getErrorMessage(error)}`));
|
|
12194
|
+
}
|
|
12195
|
+
return output;
|
|
12196
|
+
}
|
|
12197
|
+
catch (error) {
|
|
12198
|
+
console.error(`agent-swarm bus listener error clientId=${clientId} source=${source} error=${getErrorMessage(error)}`);
|
|
12199
|
+
}
|
|
12200
|
+
};
|
|
12201
|
+
/**
|
|
12202
|
+
* Service class implementing the IBus interface to manage event subscriptions and emissions in the swarm system.
|
|
12203
|
+
* Provides methods to subscribe to events (subscribe, once), emit events (emit, commitExecutionBegin, commitExecutionEnd), and dispose of subscriptions (dispose), using a memoized Subject per clientId and EventSource.
|
|
11707
12204
|
* Integrates with ClientAgent (e.g., execution events in EXECUTE_FN), PerfService (e.g., execution tracking via emit), and DocService (e.g., performance logging), leveraging LoggerService for info-level logging and SessionValidationService for session validation.
|
|
11708
12205
|
* Supports wildcard subscriptions (clientId="*") and execution-specific event aliases, enhancing event-driven communication across the system.
|
|
11709
12206
|
*/
|
|
@@ -11755,7 +12252,7 @@ class BusService {
|
|
|
11755
12252
|
this._eventWildcardMap.set(source, true);
|
|
11756
12253
|
}
|
|
11757
12254
|
this._eventSourceSet.add(source);
|
|
11758
|
-
return this.getEventSubject(clientId, source).subscribe(fn);
|
|
12255
|
+
return this.getEventSubject(clientId, source).subscribe(GUARD_LISTENER_FN(fn, clientId, source));
|
|
11759
12256
|
};
|
|
11760
12257
|
/**
|
|
11761
12258
|
* Subscribes to a single event for a specific client and event source, invoking the callback once when the filter condition is met.
|
|
@@ -11773,7 +12270,9 @@ class BusService {
|
|
|
11773
12270
|
this._eventWildcardMap.set(source, true);
|
|
11774
12271
|
}
|
|
11775
12272
|
this._eventSourceSet.add(source);
|
|
11776
|
-
return this.getEventSubject(clientId, source)
|
|
12273
|
+
return this.getEventSubject(clientId, source)
|
|
12274
|
+
.filter(filterFn)
|
|
12275
|
+
.once(GUARD_LISTENER_FN(fn, clientId, source));
|
|
11777
12276
|
};
|
|
11778
12277
|
/**
|
|
11779
12278
|
* Emits an event for a specific client, broadcasting to subscribers of the event’s source, including wildcard subscribers.
|
|
@@ -12738,7 +13237,7 @@ class DocService {
|
|
|
12738
13237
|
}
|
|
12739
13238
|
{
|
|
12740
13239
|
result.push("");
|
|
12741
|
-
result.push(`*Required:* [${fn.parameters.required
|
|
13240
|
+
result.push(`*Required:* [${fn.parameters.required?.includes(key) ? "x" : " "}]`);
|
|
12742
13241
|
}
|
|
12743
13242
|
});
|
|
12744
13243
|
if (!entries.length) {
|
|
@@ -13579,7 +14078,7 @@ class MemorySchemaService {
|
|
|
13579
14078
|
* console.log(msToTime(3600000)); // "01:00:00.0"
|
|
13580
14079
|
* console.log(msToTime(61000)); // "00:01:01.0"
|
|
13581
14080
|
* console.log(msToTime(500)); // "00:00:00.500"
|
|
13582
|
-
* console.log(msToTime(0)); // ""
|
|
14081
|
+
* console.log(msToTime(0)); // "00:00:00.0"
|
|
13583
14082
|
*
|
|
13584
14083
|
* @example
|
|
13585
14084
|
* // Edge cases
|
|
@@ -13591,8 +14090,7 @@ class MemorySchemaService {
|
|
|
13591
14090
|
* - Breaks down milliseconds into hours, minutes, seconds, and remaining milliseconds using integer division and modulo operations.
|
|
13592
14091
|
* - Pads hours, minutes, and seconds with leading zeros if they are single-digit (e.g., "5" becomes "05").
|
|
13593
14092
|
* - Includes milliseconds with no leading zeros, fixed to zero decimal places for simplicity (e.g., "500" not "500.0").
|
|
13594
|
-
* -
|
|
13595
|
-
* - Returns an empty string for an input of 0, treating it as no duration.
|
|
14093
|
+
* - Always includes all components, so an input of 0 yields "00:00:00.0".
|
|
13596
14094
|
* Useful in the agent swarm system for logging execution times, profiling operations, or displaying human-readable durations.
|
|
13597
14095
|
*
|
|
13598
14096
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed|Number.toFixed}
|
|
@@ -14432,6 +14930,15 @@ class ClientPolicy {
|
|
|
14432
14930
|
* Updated by banClient and unbanClient, persisted if params.setBannedClients is provided.
|
|
14433
14931
|
*/
|
|
14434
14932
|
this._banSet = BAN_NEED_FETCH;
|
|
14933
|
+
/**
|
|
14934
|
+
* Serializes the read-modify-write of _banSet shared by banClient/unbanClient.
|
|
14935
|
+
* Without it two concurrent bans of different clients both read the same ban
|
|
14936
|
+
* set, each adds only its own client, and the later setBannedClients overwrites
|
|
14937
|
+
* the earlier one — one ban is silently lost in memory and in the persisted
|
|
14938
|
+
* store. queued() runs the mutations one at a time so each observes the result
|
|
14939
|
+
* of the previous one.
|
|
14940
|
+
*/
|
|
14941
|
+
this._banQueue = queued(async (fn) => await fn());
|
|
14435
14942
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
14436
14943
|
this.params.logger.debug(`ClientPolicy policyName=${this.params.policyName} CTOR`, {
|
|
14437
14944
|
params,
|
|
@@ -14589,16 +15096,18 @@ class ClientPolicy {
|
|
|
14589
15096
|
},
|
|
14590
15097
|
clientId,
|
|
14591
15098
|
});
|
|
14592
|
-
|
|
14593
|
-
this._banSet
|
|
14594
|
-
|
|
14595
|
-
|
|
14596
|
-
|
|
14597
|
-
|
|
14598
|
-
|
|
14599
|
-
|
|
14600
|
-
|
|
14601
|
-
|
|
15099
|
+
await this._banQueue(async () => {
|
|
15100
|
+
if (this._banSet === BAN_NEED_FETCH) {
|
|
15101
|
+
this._banSet = new Set(await this.params.getBannedClients(this.params.policyName, swarmName));
|
|
15102
|
+
}
|
|
15103
|
+
if (this._banSet.has(clientId)) {
|
|
15104
|
+
return;
|
|
15105
|
+
}
|
|
15106
|
+
this._banSet = new Set(this._banSet).add(clientId);
|
|
15107
|
+
if (this.params.setBannedClients) {
|
|
15108
|
+
await this.params.setBannedClients([...this._banSet], this.params.policyName, swarmName);
|
|
15109
|
+
}
|
|
15110
|
+
});
|
|
14602
15111
|
}
|
|
14603
15112
|
/**
|
|
14604
15113
|
* Unbans a client, removing them from the ban set and persisting the change if params.setBannedClients is provided.
|
|
@@ -14625,20 +15134,22 @@ class ClientPolicy {
|
|
|
14625
15134
|
},
|
|
14626
15135
|
clientId,
|
|
14627
15136
|
});
|
|
14628
|
-
|
|
14629
|
-
this._banSet
|
|
14630
|
-
|
|
14631
|
-
|
|
14632
|
-
|
|
14633
|
-
|
|
14634
|
-
|
|
14635
|
-
|
|
14636
|
-
|
|
14637
|
-
|
|
14638
|
-
|
|
14639
|
-
|
|
14640
|
-
|
|
14641
|
-
|
|
15137
|
+
await this._banQueue(async () => {
|
|
15138
|
+
if (this._banSet === BAN_NEED_FETCH) {
|
|
15139
|
+
this._banSet = new Set(await this.params.getBannedClients(this.params.policyName, swarmName));
|
|
15140
|
+
}
|
|
15141
|
+
if (!this._banSet.has(clientId)) {
|
|
15142
|
+
return;
|
|
15143
|
+
}
|
|
15144
|
+
{
|
|
15145
|
+
const banSet = new Set(this._banSet);
|
|
15146
|
+
banSet.delete(clientId);
|
|
15147
|
+
this._banSet = banSet;
|
|
15148
|
+
}
|
|
15149
|
+
if (this.params.setBannedClients) {
|
|
15150
|
+
await this.params.setBannedClients([...this._banSet], this.params.policyName, swarmName);
|
|
15151
|
+
}
|
|
15152
|
+
});
|
|
14642
15153
|
}
|
|
14643
15154
|
}
|
|
14644
15155
|
|
|
@@ -15111,7 +15622,16 @@ class ClientMCP {
|
|
|
15111
15622
|
if (this.params.callbacks?.onList) {
|
|
15112
15623
|
this.params.callbacks.onList(clientId);
|
|
15113
15624
|
}
|
|
15114
|
-
|
|
15625
|
+
let toolMap;
|
|
15626
|
+
try {
|
|
15627
|
+
toolMap = await this.fetchTools(clientId);
|
|
15628
|
+
}
|
|
15629
|
+
catch (error) {
|
|
15630
|
+
// Never cache a rejected fetch: the memoized promise would keep this
|
|
15631
|
+
// client permanently broken even after the MCP recovers.
|
|
15632
|
+
this.fetchTools.clear(clientId);
|
|
15633
|
+
throw error;
|
|
15634
|
+
}
|
|
15115
15635
|
return Array.from(toolMap.values());
|
|
15116
15636
|
}
|
|
15117
15637
|
/**
|
|
@@ -15123,7 +15643,14 @@ class ClientMCP {
|
|
|
15123
15643
|
toolName,
|
|
15124
15644
|
clientId,
|
|
15125
15645
|
});
|
|
15126
|
-
|
|
15646
|
+
let toolMap;
|
|
15647
|
+
try {
|
|
15648
|
+
toolMap = await this.fetchTools(clientId);
|
|
15649
|
+
}
|
|
15650
|
+
catch (error) {
|
|
15651
|
+
this.fetchTools.clear(clientId);
|
|
15652
|
+
throw error;
|
|
15653
|
+
}
|
|
15127
15654
|
return toolMap.has(toolName);
|
|
15128
15655
|
}
|
|
15129
15656
|
/**
|
|
@@ -15209,12 +15736,13 @@ class MCPConnectionService {
|
|
|
15209
15736
|
this.dispose = async (clientId) => {
|
|
15210
15737
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
15211
15738
|
this.loggerService.info(`mcpConnectionService dispose`, { clientId });
|
|
15212
|
-
const key = `${this.methodContextService.context.
|
|
15739
|
+
const key = `${this.methodContextService.context.mcpName}`;
|
|
15213
15740
|
if (!this.getMCP.has(key)) {
|
|
15214
15741
|
return;
|
|
15215
15742
|
}
|
|
15743
|
+
// The ClientMCP instance is shared across clients (memoized by mcpName),
|
|
15744
|
+
// so only the client-scoped resources are released; the instance stays cached.
|
|
15216
15745
|
await this.getMCP(this.methodContextService.context.mcpName).dispose(clientId);
|
|
15217
|
-
this.getMCP.clear(clientId);
|
|
15218
15746
|
};
|
|
15219
15747
|
}
|
|
15220
15748
|
/**
|
|
@@ -16112,7 +16640,7 @@ class SharedComputeConnectionService {
|
|
|
16112
16640
|
* @throws {Error} If the compute is not marked as shared.
|
|
16113
16641
|
*/
|
|
16114
16642
|
this.getComputeRef = memoize(([computeName]) => `${computeName}`, (computeName) => {
|
|
16115
|
-
const { getComputeData, dependsOn, middlewares = [], callbacks, shared = false, } = this.computeSchemaService.get(computeName);
|
|
16643
|
+
const { getComputeData, dependsOn = [], middlewares = [], callbacks, shared = false, } = this.computeSchemaService.get(computeName);
|
|
16116
16644
|
if (!shared) {
|
|
16117
16645
|
throw new Error(`agent-swarm compute not shared computeName=${computeName}`);
|
|
16118
16646
|
}
|
|
@@ -17095,14 +17623,14 @@ const swarm = {
|
|
|
17095
17623
|
init();
|
|
17096
17624
|
var swarm$1 = swarm;
|
|
17097
17625
|
|
|
17098
|
-
const METHOD_NAME$
|
|
17626
|
+
const METHOD_NAME$1F = "cli.dumpDocs";
|
|
17099
17627
|
/**
|
|
17100
17628
|
* Dumps the documentation for the agents and swarms.
|
|
17101
17629
|
*
|
|
17102
17630
|
*/
|
|
17103
17631
|
const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantUML, sanitizeMarkdown = (t) => t) => {
|
|
17104
17632
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17105
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17633
|
+
swarm$1.loggerService.log(METHOD_NAME$1F, {
|
|
17106
17634
|
dirName,
|
|
17107
17635
|
});
|
|
17108
17636
|
if (PlantUML) {
|
|
@@ -17112,10 +17640,10 @@ const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantU
|
|
|
17112
17640
|
}
|
|
17113
17641
|
swarm$1.agentValidationService
|
|
17114
17642
|
.getAgentList()
|
|
17115
|
-
.forEach((agentName) => swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
17643
|
+
.forEach((agentName) => swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1F));
|
|
17116
17644
|
swarm$1.swarmValidationService
|
|
17117
17645
|
.getSwarmList()
|
|
17118
|
-
.forEach((swarmName) => swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
17646
|
+
.forEach((swarmName) => swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1F));
|
|
17119
17647
|
swarm$1.agentValidationService.getAgentList().forEach((agentName) => {
|
|
17120
17648
|
const { dependsOn } = swarm$1.agentSchemaService.get(agentName);
|
|
17121
17649
|
if (!dependsOn) {
|
|
@@ -17124,39 +17652,39 @@ const dumpDocs = beginContext((prefix = "swarm", dirName = "./docs/chat", PlantU
|
|
|
17124
17652
|
});
|
|
17125
17653
|
swarm$1.outlineValidationService
|
|
17126
17654
|
.getOutlineList()
|
|
17127
|
-
.forEach((swarmName) => swarm$1.outlineValidationService.validate(swarmName, METHOD_NAME$
|
|
17655
|
+
.forEach((swarmName) => swarm$1.outlineValidationService.validate(swarmName, METHOD_NAME$1F));
|
|
17128
17656
|
return swarm$1.docService.dumpDocs(prefix, dirName, sanitizeMarkdown);
|
|
17129
17657
|
});
|
|
17130
17658
|
|
|
17131
|
-
const METHOD_NAME$
|
|
17659
|
+
const METHOD_NAME$1E = "cli.dumpAgent";
|
|
17132
17660
|
/**
|
|
17133
17661
|
* Dumps the agent information into PlantUML format.
|
|
17134
17662
|
*
|
|
17135
17663
|
*/
|
|
17136
17664
|
const dumpAgent = beginContext((agentName, { withSubtree = false } = {}) => {
|
|
17137
17665
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17138
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17666
|
+
swarm$1.loggerService.log(METHOD_NAME$1E, {
|
|
17139
17667
|
agentName,
|
|
17140
17668
|
});
|
|
17141
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
17669
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1E);
|
|
17142
17670
|
return swarm$1.agentMetaService.toUML(agentName, withSubtree);
|
|
17143
17671
|
});
|
|
17144
17672
|
|
|
17145
|
-
const METHOD_NAME$
|
|
17673
|
+
const METHOD_NAME$1D = "cli.dumpSwarm";
|
|
17146
17674
|
/**
|
|
17147
17675
|
* Dumps the swarm information into PlantUML format.
|
|
17148
17676
|
*
|
|
17149
17677
|
*/
|
|
17150
17678
|
const dumpSwarm = beginContext((swarmName) => {
|
|
17151
17679
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17152
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17680
|
+
swarm$1.loggerService.log(METHOD_NAME$1D, {
|
|
17153
17681
|
swarmName,
|
|
17154
17682
|
});
|
|
17155
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
17683
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1D);
|
|
17156
17684
|
return swarm$1.swarmMetaService.toUML(swarmName);
|
|
17157
17685
|
});
|
|
17158
17686
|
|
|
17159
|
-
const METHOD_NAME$
|
|
17687
|
+
const METHOD_NAME$1C = "cli.dumpPerfomance";
|
|
17160
17688
|
const METHOD_NAME_INTERNAL$1 = "cli.dumpPerfomance.internal";
|
|
17161
17689
|
const METHOD_NAME_INTERVAL = "cli.dumpPerfomance.interval";
|
|
17162
17690
|
/**
|
|
@@ -17173,7 +17701,7 @@ const dumpPerfomanceInternal = beginContext(async (dirName = "./dump/agent/meta"
|
|
|
17173
17701
|
*
|
|
17174
17702
|
*/
|
|
17175
17703
|
const dumpPerfomance = async (dirName = "./dump/agent/meta") => {
|
|
17176
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
17704
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1C);
|
|
17177
17705
|
await dumpPerfomanceInternal(dirName);
|
|
17178
17706
|
};
|
|
17179
17707
|
/**
|
|
@@ -17222,10 +17750,19 @@ const listenExecutionEvent = beginContext((clientId, fn) => {
|
|
|
17222
17750
|
// Validate the client ID
|
|
17223
17751
|
validateClientId$h(clientId);
|
|
17224
17752
|
// Subscribe to execution events with a queued callback
|
|
17225
|
-
return swarm$1.busService.subscribe(clientId, "execution-bus", queued(async (e) =>
|
|
17753
|
+
return swarm$1.busService.subscribe(clientId, "execution-bus", queued(async (e) => {
|
|
17754
|
+
try {
|
|
17755
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
17756
|
+
// as an unhandled rejection and can crash the host process.
|
|
17757
|
+
return await fn(e);
|
|
17758
|
+
}
|
|
17759
|
+
catch (error) {
|
|
17760
|
+
console.error(`agent-swarm event listener error source=listenExecutionEvent error=${getErrorMessage(error)}`);
|
|
17761
|
+
}
|
|
17762
|
+
}));
|
|
17226
17763
|
});
|
|
17227
17764
|
|
|
17228
|
-
const METHOD_NAME$
|
|
17765
|
+
const METHOD_NAME$1B = "cli.dumpClientPerformance";
|
|
17229
17766
|
const METHOD_NAME_INTERNAL = "cli.dumpClientPerformance.internal";
|
|
17230
17767
|
const METHOD_NAME_EXECUTE = "cli.dumpClientPerformance.execute";
|
|
17231
17768
|
/**
|
|
@@ -17243,7 +17780,7 @@ const dumpClientPerformanceInternal = beginContext(async (clientId, dirName = ".
|
|
|
17243
17780
|
*
|
|
17244
17781
|
*/
|
|
17245
17782
|
const dumpClientPerformance = async (clientId, dirName = "./dump/agent/client") => {
|
|
17246
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
17783
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1B);
|
|
17247
17784
|
await dumpClientPerformanceInternal(clientId, dirName);
|
|
17248
17785
|
};
|
|
17249
17786
|
/**
|
|
@@ -17391,24 +17928,24 @@ const dumpAdvisorResult = async (resultId, content) => {
|
|
|
17391
17928
|
};
|
|
17392
17929
|
|
|
17393
17930
|
/** @private Constant defining the method name for logging and validation context*/
|
|
17394
|
-
const METHOD_NAME$
|
|
17931
|
+
const METHOD_NAME$1A = "function.commit.commitFlushForce";
|
|
17395
17932
|
/**
|
|
17396
17933
|
* Function implementation
|
|
17397
17934
|
*/
|
|
17398
17935
|
const commitFlushForceInternal = beginContext(async (clientId) => {
|
|
17399
17936
|
// Log the flush attempt if enabled
|
|
17400
17937
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17401
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17938
|
+
swarm$1.loggerService.log(METHOD_NAME$1A, {
|
|
17402
17939
|
clientId,
|
|
17403
|
-
METHOD_NAME: METHOD_NAME$
|
|
17940
|
+
METHOD_NAME: METHOD_NAME$1A,
|
|
17404
17941
|
});
|
|
17405
17942
|
// Validate the session exists and retrieve the associated swarm
|
|
17406
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17943
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1A);
|
|
17407
17944
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17408
17945
|
// Validate the swarm configuration
|
|
17409
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
17946
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1A);
|
|
17410
17947
|
// Commit the flush of agent history via SessionPublicService without agent checks
|
|
17411
|
-
await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$
|
|
17948
|
+
await swarm$1.sessionPublicService.commitFlush(METHOD_NAME$1A, clientId, swarmName);
|
|
17412
17949
|
});
|
|
17413
17950
|
/**
|
|
17414
17951
|
* Forcefully commits a flush of agent history for a specific client in the swarm system, without checking the active agent.
|
|
@@ -17427,24 +17964,24 @@ async function commitFlushForce(clientId) {
|
|
|
17427
17964
|
return await commitFlushForceInternal(clientId);
|
|
17428
17965
|
}
|
|
17429
17966
|
|
|
17430
|
-
const METHOD_NAME$
|
|
17967
|
+
const METHOD_NAME$1z = "function.commit.commitToolOutputForce";
|
|
17431
17968
|
/**
|
|
17432
17969
|
* Function implementation
|
|
17433
17970
|
*/
|
|
17434
17971
|
const commitToolOutputForceInternal = beginContext(async (toolId, content, clientId) => {
|
|
17435
17972
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17436
17973
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17437
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17974
|
+
swarm$1.loggerService.log(METHOD_NAME$1z, {
|
|
17438
17975
|
toolId,
|
|
17439
17976
|
content,
|
|
17440
17977
|
clientId,
|
|
17441
17978
|
});
|
|
17442
17979
|
// Validate the session and swarm to ensure they exist and are accessible
|
|
17443
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17980
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1z);
|
|
17444
17981
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17445
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
17982
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1z);
|
|
17446
17983
|
// Commit the tool output to the session via the session public service without checking the active agent
|
|
17447
|
-
await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$
|
|
17984
|
+
await swarm$1.sessionPublicService.commitToolOutput(toolId, content, METHOD_NAME$1z, clientId, swarmName);
|
|
17448
17985
|
});
|
|
17449
17986
|
/**
|
|
17450
17987
|
* Commits the output of a tool execution to the active agent in a swarm session without checking the active agent.
|
|
@@ -17469,15 +18006,15 @@ async function commitToolOutputForce(toolId, content, clientId) {
|
|
|
17469
18006
|
* @private Constant defining the method name for logging and validation purposes.
|
|
17470
18007
|
* Used as an identifier in log messages and validation checks to track calls to `hasNavigation`.
|
|
17471
18008
|
*/
|
|
17472
|
-
const METHOD_NAME$
|
|
18009
|
+
const METHOD_NAME$1y = "function.common.hasNavigation";
|
|
17473
18010
|
/**
|
|
17474
18011
|
* Function implementation
|
|
17475
18012
|
*/
|
|
17476
18013
|
const hasNavigationInternal = async (clientId, agentName) => {
|
|
17477
18014
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17478
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
17479
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
17480
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
18015
|
+
swarm$1.loggerService.log(METHOD_NAME$1y, { clientId });
|
|
18016
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1y);
|
|
18017
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1y);
|
|
17481
18018
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17482
18019
|
return swarm$1.navigationValidationService
|
|
17483
18020
|
.getNavigationRoute(clientId, swarmName)
|
|
@@ -17494,14 +18031,14 @@ async function hasNavigation(clientId, agentName) {
|
|
|
17494
18031
|
return await hasNavigationInternal(clientId, agentName);
|
|
17495
18032
|
}
|
|
17496
18033
|
|
|
17497
|
-
const METHOD_NAME$
|
|
18034
|
+
const METHOD_NAME$1x = "function.history.getRawHistory";
|
|
17498
18035
|
/**
|
|
17499
18036
|
* Function implementation
|
|
17500
18037
|
*/
|
|
17501
18038
|
const getRawHistoryInternal = beginContext(async (clientId, methodName) => {
|
|
17502
18039
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17503
18040
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17504
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18041
|
+
swarm$1.loggerService.log(METHOD_NAME$1x, {
|
|
17505
18042
|
clientId,
|
|
17506
18043
|
});
|
|
17507
18044
|
// Validate the session and swarm
|
|
@@ -17529,21 +18066,21 @@ const getRawHistoryInternal = beginContext(async (clientId, methodName) => {
|
|
|
17529
18066
|
* console.log(rawHistory); // Outputs the full raw history array
|
|
17530
18067
|
*/
|
|
17531
18068
|
async function getRawHistory(clientId) {
|
|
17532
|
-
return await getRawHistoryInternal(clientId, METHOD_NAME$
|
|
18069
|
+
return await getRawHistoryInternal(clientId, METHOD_NAME$1x);
|
|
17533
18070
|
}
|
|
17534
18071
|
|
|
17535
|
-
const METHOD_NAME$
|
|
18072
|
+
const METHOD_NAME$1w = "function.history.getLastUserMessage";
|
|
17536
18073
|
/**
|
|
17537
18074
|
* Function implementation
|
|
17538
18075
|
*/
|
|
17539
18076
|
const getLastUserMessageInternal = beginContext(async (clientId) => {
|
|
17540
18077
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17541
18078
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17542
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18079
|
+
swarm$1.loggerService.log(METHOD_NAME$1w, {
|
|
17543
18080
|
clientId,
|
|
17544
18081
|
});
|
|
17545
18082
|
// Fetch raw history and find the last user message
|
|
17546
|
-
const history = await getRawHistoryInternal(clientId, METHOD_NAME$
|
|
18083
|
+
const history = await getRawHistoryInternal(clientId, METHOD_NAME$1w);
|
|
17547
18084
|
const last = history.findLast(({ role, mode }) => role === "user" && mode === "user");
|
|
17548
18085
|
return last?.content ? last.content : null;
|
|
17549
18086
|
});
|
|
@@ -17565,7 +18102,7 @@ async function getLastUserMessage(clientId) {
|
|
|
17565
18102
|
return await getLastUserMessageInternal(clientId);
|
|
17566
18103
|
}
|
|
17567
18104
|
|
|
17568
|
-
const METHOD_NAME$
|
|
18105
|
+
const METHOD_NAME$1v = "function.navigate.changeToDefaultAgent";
|
|
17569
18106
|
/**
|
|
17570
18107
|
* Creates a change agent function with time-to-live (TTL) and queuing capabilities for switching to the default agent.
|
|
17571
18108
|
*
|
|
@@ -17586,7 +18123,7 @@ const createChangeToDefaultAgent = memoize(([clientId]) => `${clientId}`, (clien
|
|
|
17586
18123
|
}));
|
|
17587
18124
|
{
|
|
17588
18125
|
// Dispose of the current agent's resources and set up the new default agent
|
|
17589
|
-
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
18126
|
+
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1v, clientId, swarmName);
|
|
17590
18127
|
await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
|
|
17591
18128
|
await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
|
|
17592
18129
|
await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
|
|
@@ -17613,20 +18150,20 @@ const createGc$3 = singleshot(async () => {
|
|
|
17613
18150
|
const changeToDefaultAgentInternal = beginContext(async (clientId) => {
|
|
17614
18151
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17615
18152
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17616
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18153
|
+
swarm$1.loggerService.log(METHOD_NAME$1v, {
|
|
17617
18154
|
clientId,
|
|
17618
18155
|
});
|
|
17619
18156
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17620
18157
|
const { defaultAgent: agentName } = swarm$1.swarmSchemaService.get(swarmName);
|
|
17621
18158
|
{
|
|
17622
18159
|
// Validate session and default agent
|
|
17623
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17624
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
18160
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1v);
|
|
18161
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1v);
|
|
17625
18162
|
}
|
|
17626
18163
|
// Execute the agent change with TTL and queuing
|
|
17627
18164
|
const run = await createChangeToDefaultAgent(clientId);
|
|
17628
18165
|
createGc$3();
|
|
17629
|
-
return await run(METHOD_NAME$
|
|
18166
|
+
return await run(METHOD_NAME$1v, agentName, swarmName);
|
|
17630
18167
|
});
|
|
17631
18168
|
/**
|
|
17632
18169
|
* Navigates back to the default agent for a given client session in a swarm.
|
|
@@ -17645,44 +18182,44 @@ async function changeToDefaultAgent(clientId) {
|
|
|
17645
18182
|
return await changeToDefaultAgentInternal(clientId);
|
|
17646
18183
|
}
|
|
17647
18184
|
|
|
17648
|
-
const METHOD_NAME$
|
|
18185
|
+
const METHOD_NAME$1u = "function.target.emitForce";
|
|
17649
18186
|
/**
|
|
17650
18187
|
* Function implementation
|
|
17651
18188
|
*/
|
|
17652
18189
|
const emitForceInternal = beginContext(async (content, clientId) => {
|
|
17653
18190
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17654
18191
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17655
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18192
|
+
swarm$1.loggerService.log(METHOD_NAME$1u, {
|
|
17656
18193
|
content,
|
|
17657
18194
|
clientId,
|
|
17658
18195
|
});
|
|
17659
18196
|
// Validate the session and swarm
|
|
17660
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
18197
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1u);
|
|
17661
18198
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17662
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
18199
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1u);
|
|
17663
18200
|
// Emit the content directly via the session public service
|
|
17664
|
-
return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$
|
|
18201
|
+
return await swarm$1.sessionPublicService.emit(content, METHOD_NAME$1u, clientId, swarmName);
|
|
17665
18202
|
});
|
|
17666
18203
|
/**
|
|
17667
18204
|
* Emits a string as model output without executing an incoming message or checking the active agent.
|
|
17668
18205
|
*
|
|
17669
18206
|
* This function directly emits a provided string as output from the swarm session, bypassing message execution and agent activity checks.
|
|
17670
|
-
*
|
|
17671
|
-
* The execution is wrapped in `beginContext` for a clean environment, validates the session and swarm,
|
|
17672
|
-
*
|
|
18207
|
+
* Unlike `emit`, it does not verify that a specific agent is still active, ensuring emission even after navigation.
|
|
18208
|
+
* The execution is wrapped in `beginContext` for a clean environment, validates the session and swarm,
|
|
18209
|
+
* logs the operation if enabled, and resolves when the content is successfully emitted. Works for any session mode.
|
|
17673
18210
|
*
|
|
17674
18211
|
*
|
|
17675
18212
|
* @param {string} content - The content to be processed or stored.
|
|
17676
18213
|
* @param {string} clientId - The unique identifier of the client session.
|
|
17677
|
-
* @throws {Error} If
|
|
18214
|
+
* @throws {Error} If session or swarm validation fails.
|
|
17678
18215
|
* @example
|
|
17679
|
-
* await emitForce("Direct output", "client-123"); // Emits "Direct output"
|
|
18216
|
+
* await emitForce("Direct output", "client-123"); // Emits "Direct output" regardless of the active agent
|
|
17680
18217
|
*/
|
|
17681
18218
|
async function emitForce(content, clientId) {
|
|
17682
18219
|
return await emitForceInternal(content, clientId);
|
|
17683
18220
|
}
|
|
17684
18221
|
|
|
17685
|
-
const METHOD_NAME$
|
|
18222
|
+
const METHOD_NAME$1t = "function.target.executeForce";
|
|
17686
18223
|
/**
|
|
17687
18224
|
* Function implementation
|
|
17688
18225
|
*/
|
|
@@ -17690,15 +18227,15 @@ const executeForceInternal = beginContext(async (content, clientId) => {
|
|
|
17690
18227
|
const executionId = randomString();
|
|
17691
18228
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17692
18229
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17693
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18230
|
+
swarm$1.loggerService.log(METHOD_NAME$1t, {
|
|
17694
18231
|
content,
|
|
17695
18232
|
clientId,
|
|
17696
18233
|
executionId,
|
|
17697
18234
|
});
|
|
17698
18235
|
// Validate the session and swarm
|
|
17699
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
18236
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1t);
|
|
17700
18237
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17701
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
18238
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1t);
|
|
17702
18239
|
// Execute the command within an execution context with performance tracking
|
|
17703
18240
|
return ExecutionContextService.runInContext(async () => {
|
|
17704
18241
|
let isFinished = false;
|
|
@@ -17712,7 +18249,7 @@ const executeForceInternal = beginContext(async (content, clientId) => {
|
|
|
17712
18249
|
errorValue = error;
|
|
17713
18250
|
}
|
|
17714
18251
|
});
|
|
17715
|
-
result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$
|
|
18252
|
+
result = await swarm$1.sessionPublicService.execute(content, "tool", METHOD_NAME$1t, clientId, swarmName);
|
|
17716
18253
|
unError();
|
|
17717
18254
|
if (errorValue) {
|
|
17718
18255
|
throw errorValue;
|
|
@@ -17754,24 +18291,24 @@ async function executeForce(content, clientId) {
|
|
|
17754
18291
|
}
|
|
17755
18292
|
|
|
17756
18293
|
/** @private Constant defining the method name for logging and validation context*/
|
|
17757
|
-
const METHOD_NAME$
|
|
18294
|
+
const METHOD_NAME$1s = "function.commit.commitStopToolsForce";
|
|
17758
18295
|
/**
|
|
17759
18296
|
* Function implementation
|
|
17760
18297
|
*/
|
|
17761
18298
|
const commitStopToolsForceInternal = beginContext(async (clientId) => {
|
|
17762
18299
|
// Log the stop tools attempt if enabled
|
|
17763
18300
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17764
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18301
|
+
swarm$1.loggerService.log(METHOD_NAME$1s, {
|
|
17765
18302
|
clientId,
|
|
17766
|
-
METHOD_NAME: METHOD_NAME$
|
|
18303
|
+
METHOD_NAME: METHOD_NAME$1s,
|
|
17767
18304
|
});
|
|
17768
18305
|
// Validate the session exists and retrieve the associated swarm
|
|
17769
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
18306
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1s);
|
|
17770
18307
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17771
18308
|
// Validate the swarm configuration
|
|
17772
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
18309
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$1s);
|
|
17773
18310
|
// Commit the stop of the next tool execution via SessionPublicService without agent checks
|
|
17774
|
-
await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$
|
|
18311
|
+
await swarm$1.sessionPublicService.commitStopTools(METHOD_NAME$1s, clientId, swarmName);
|
|
17775
18312
|
});
|
|
17776
18313
|
/**
|
|
17777
18314
|
* Forcefully prevents the next tool from being executed for a specific client in the swarm system, without checking the active agent.
|
|
@@ -17790,7 +18327,7 @@ async function commitStopToolsForce(clientId) {
|
|
|
17790
18327
|
return await commitStopToolsForceInternal(clientId);
|
|
17791
18328
|
}
|
|
17792
18329
|
|
|
17793
|
-
const METHOD_NAME$
|
|
18330
|
+
const METHOD_NAME$1r = "function.template.navigateToTriageAgent";
|
|
17794
18331
|
/**
|
|
17795
18332
|
* Will send tool output directly to the model without any additions
|
|
17796
18333
|
*/
|
|
@@ -17832,7 +18369,7 @@ const createNavigateToTriageAgent = ({ flushMessage, beforeNavigate, lastMessage
|
|
|
17832
18369
|
*/
|
|
17833
18370
|
return beginContext(async (toolId, clientId) => {
|
|
17834
18371
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17835
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18372
|
+
swarm$1.loggerService.log(METHOD_NAME$1r, {
|
|
17836
18373
|
clientId,
|
|
17837
18374
|
toolId,
|
|
17838
18375
|
});
|
|
@@ -17846,7 +18383,7 @@ const createNavigateToTriageAgent = ({ flushMessage, beforeNavigate, lastMessage
|
|
|
17846
18383
|
beforeNavigate && await beforeNavigate(clientId, lastMessage, lastAgent, defaultAgent);
|
|
17847
18384
|
await commitToolOutputForce(toolId, typeof toolOutputAccept === "string"
|
|
17848
18385
|
? toolOutputAccept
|
|
17849
|
-
: await toolOutputAccept(clientId,
|
|
18386
|
+
: await toolOutputAccept(clientId, defaultAgent), clientId);
|
|
17850
18387
|
await changeToDefaultAgent(clientId);
|
|
17851
18388
|
await executeForce(lastMessage, clientId);
|
|
17852
18389
|
return;
|
|
@@ -17867,7 +18404,7 @@ const createNavigateToTriageAgent = ({ flushMessage, beforeNavigate, lastMessage
|
|
|
17867
18404
|
});
|
|
17868
18405
|
};
|
|
17869
18406
|
|
|
17870
|
-
const METHOD_NAME$
|
|
18407
|
+
const METHOD_NAME$1q = "function.navigate.changeToAgent";
|
|
17871
18408
|
/**
|
|
17872
18409
|
* Creates a change agent function with time-to-live (TTL) and queuing capabilities.
|
|
17873
18410
|
*
|
|
@@ -17889,7 +18426,7 @@ const createChangeToAgent = memoize(([clientId]) => `${clientId}`, (clientId) =>
|
|
|
17889
18426
|
}));
|
|
17890
18427
|
{
|
|
17891
18428
|
// Dispose of the current agent's resources and set up the new agent
|
|
17892
|
-
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
18429
|
+
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1q, clientId, swarmName);
|
|
17893
18430
|
await swarm$1.agentPublicService.dispose(methodName, clientId, agentName);
|
|
17894
18431
|
await swarm$1.historyPublicService.dispose(methodName, clientId, agentName);
|
|
17895
18432
|
await swarm$1.swarmPublicService.setAgentRef(methodName, clientId, swarmName, agentName, await swarm$1.agentPublicService.createAgentRef(methodName, clientId, agentName));
|
|
@@ -17916,16 +18453,16 @@ const createGc$2 = singleshot(async () => {
|
|
|
17916
18453
|
const changeToAgentInternal = beginContext(async (agentName, clientId) => {
|
|
17917
18454
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
17918
18455
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
17919
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18456
|
+
swarm$1.loggerService.log(METHOD_NAME$1q, {
|
|
17920
18457
|
agentName,
|
|
17921
18458
|
clientId,
|
|
17922
18459
|
});
|
|
17923
18460
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
17924
18461
|
{
|
|
17925
18462
|
// Validate session, agent, and dependencies
|
|
17926
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
17927
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
17928
|
-
const activeAgent = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
18463
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$1q);
|
|
18464
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$1q);
|
|
18465
|
+
const activeAgent = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1q, clientId, swarmName);
|
|
17929
18466
|
if (!swarm$1.agentValidationService.hasDependency(activeAgent, agentName)) {
|
|
17930
18467
|
console.error(`agent-swarm missing dependency detected for activeAgent=${activeAgent} dependencyAgent=${agentName}`);
|
|
17931
18468
|
}
|
|
@@ -17943,7 +18480,7 @@ const changeToAgentInternal = beginContext(async (agentName, clientId) => {
|
|
|
17943
18480
|
// Execute the agent change with TTL and queuing
|
|
17944
18481
|
const run = await createChangeToAgent(clientId);
|
|
17945
18482
|
createGc$2();
|
|
17946
|
-
return await run(METHOD_NAME$
|
|
18483
|
+
return await run(METHOD_NAME$1q, agentName, swarmName);
|
|
17947
18484
|
});
|
|
17948
18485
|
/**
|
|
17949
18486
|
* Changes the active agent for a given client session in a swarm.
|
|
@@ -17963,7 +18500,7 @@ async function changeToAgent(agentName, clientId) {
|
|
|
17963
18500
|
return await changeToAgentInternal(agentName, clientId);
|
|
17964
18501
|
}
|
|
17965
18502
|
|
|
17966
|
-
const METHOD_NAME$
|
|
18503
|
+
const METHOD_NAME$1p = "function.template.navigateToAgent";
|
|
17967
18504
|
/**
|
|
17968
18505
|
* Will send tool output directly to the model without any additions
|
|
17969
18506
|
*/
|
|
@@ -18019,7 +18556,7 @@ const createNavigateToAgent = ({ beforeNavigate, lastMessage: lastMessageFn = DE
|
|
|
18019
18556
|
*/
|
|
18020
18557
|
return beginContext(async (toolId, clientId, agentName) => {
|
|
18021
18558
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18022
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18559
|
+
swarm$1.loggerService.log(METHOD_NAME$1p, {
|
|
18023
18560
|
clientId,
|
|
18024
18561
|
toolId,
|
|
18025
18562
|
});
|
|
@@ -18057,7 +18594,7 @@ const createNavigateToAgent = ({ beforeNavigate, lastMessage: lastMessageFn = DE
|
|
|
18057
18594
|
});
|
|
18058
18595
|
};
|
|
18059
18596
|
|
|
18060
|
-
const METHOD_NAME$
|
|
18597
|
+
const METHOD_NAME$1o = "function.template.commitAction";
|
|
18061
18598
|
/**
|
|
18062
18599
|
* Creates a commit action handler that executes actions and modifies system state (WRITE pattern).
|
|
18063
18600
|
*
|
|
@@ -18106,7 +18643,7 @@ const createCommitAction = ({ validateParams, executeAction, emptyContent, fallb
|
|
|
18106
18643
|
return beginContext(async (toolId, clientId, agentName, toolName, params, toolCalls, isLast) => {
|
|
18107
18644
|
let executeMessage = "";
|
|
18108
18645
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18109
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18646
|
+
swarm$1.loggerService.log(METHOD_NAME$1o, {
|
|
18110
18647
|
clientId,
|
|
18111
18648
|
toolId,
|
|
18112
18649
|
agentName,
|
|
@@ -18200,7 +18737,7 @@ const createCommitAction = ({ validateParams, executeAction, emptyContent, fallb
|
|
|
18200
18737
|
});
|
|
18201
18738
|
};
|
|
18202
18739
|
|
|
18203
|
-
const METHOD_NAME$
|
|
18740
|
+
const METHOD_NAME$1n = "function.template.fetchInfo";
|
|
18204
18741
|
/**
|
|
18205
18742
|
* Default message when content is empty.
|
|
18206
18743
|
*/
|
|
@@ -18246,7 +18783,7 @@ const createFetchInfo = ({ fetchContent, fallback, emptyContent = DEFAULT_EMPTY_
|
|
|
18246
18783
|
return beginContext(async (toolId, clientId, agentName, toolName, params, isLast) => {
|
|
18247
18784
|
let executeMessage = "";
|
|
18248
18785
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18249
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18786
|
+
swarm$1.loggerService.log(METHOD_NAME$1n, {
|
|
18250
18787
|
clientId,
|
|
18251
18788
|
toolId,
|
|
18252
18789
|
agentName,
|
|
@@ -18257,7 +18794,7 @@ const createFetchInfo = ({ fetchContent, fallback, emptyContent = DEFAULT_EMPTY_
|
|
|
18257
18794
|
const currentAgentName = await getAgentName(clientId);
|
|
18258
18795
|
if (currentAgentName !== agentName) {
|
|
18259
18796
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18260
|
-
swarm$1.loggerService.log(`${METHOD_NAME$
|
|
18797
|
+
swarm$1.loggerService.log(`${METHOD_NAME$1n} skipped due to agent change`, {
|
|
18261
18798
|
currentAgentName,
|
|
18262
18799
|
agentName,
|
|
18263
18800
|
clientId,
|
|
@@ -18292,14 +18829,14 @@ const createFetchInfo = ({ fetchContent, fallback, emptyContent = DEFAULT_EMPTY_
|
|
|
18292
18829
|
});
|
|
18293
18830
|
};
|
|
18294
18831
|
|
|
18295
|
-
const METHOD_NAME$
|
|
18832
|
+
const METHOD_NAME$1m = "function.setup.addTool";
|
|
18296
18833
|
/**
|
|
18297
18834
|
* Function implementation
|
|
18298
18835
|
*/
|
|
18299
18836
|
const addToolInternal = beginContext((toolSchema) => {
|
|
18300
18837
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
18301
18838
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18302
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
18839
|
+
swarm$1.loggerService.log(METHOD_NAME$1m, {
|
|
18303
18840
|
toolSchema,
|
|
18304
18841
|
});
|
|
18305
18842
|
// Register the tool in the validation and schema services
|
|
@@ -18333,12 +18870,12 @@ function addTool(toolSchema) {
|
|
|
18333
18870
|
* Adds navigation functionality to an agent by creating a tool that allows navigation to a specified agent.
|
|
18334
18871
|
* @module addAgentNavigation
|
|
18335
18872
|
*/
|
|
18336
|
-
const METHOD_NAME$
|
|
18873
|
+
const METHOD_NAME$1l = "function.alias.addAgentNavigation";
|
|
18337
18874
|
/**
|
|
18338
18875
|
* Function implementation
|
|
18339
18876
|
*/
|
|
18340
18877
|
const addAgentNavigationInternal = beginContext(({ toolName, docNote, description, navigateTo, isAvailable, ...navigateProps }) => {
|
|
18341
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
18878
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1l);
|
|
18342
18879
|
const navigate = createNavigateToAgent(navigateProps);
|
|
18343
18880
|
const toolSchema = addTool({
|
|
18344
18881
|
toolName,
|
|
@@ -18377,12 +18914,12 @@ function addAgentNavigation(params) {
|
|
|
18377
18914
|
* Adds triage navigation functionality to an agent by creating a tool that facilitates navigation to a triage agent.
|
|
18378
18915
|
* @module addTriageNavigation
|
|
18379
18916
|
*/
|
|
18380
|
-
const METHOD_NAME$
|
|
18917
|
+
const METHOD_NAME$1k = "function.alias.addTriageNavigation";
|
|
18381
18918
|
/**
|
|
18382
18919
|
* Function implementation
|
|
18383
18920
|
*/
|
|
18384
18921
|
const addTriageNavigationInternal = beginContext(({ toolName, docNote, description, isAvailable, ...navigateProps }) => {
|
|
18385
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
18922
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1k);
|
|
18386
18923
|
const navigate = createNavigateToTriageAgent(navigateProps);
|
|
18387
18924
|
const toolSchema = addTool({
|
|
18388
18925
|
toolName,
|
|
@@ -18421,12 +18958,12 @@ function addTriageNavigation(params) {
|
|
|
18421
18958
|
* Adds commit action functionality to an agent by creating a tool that validates and executes actions.
|
|
18422
18959
|
* @module addCommitAction
|
|
18423
18960
|
*/
|
|
18424
|
-
const METHOD_NAME$
|
|
18961
|
+
const METHOD_NAME$1j = "function.alias.addCommitAction";
|
|
18425
18962
|
/**
|
|
18426
18963
|
* Function implementation
|
|
18427
18964
|
*/
|
|
18428
18965
|
const addCommitActionInternal = beginContext(({ toolName, docNote, function: functionSchema, isAvailable, ...actionProps }) => {
|
|
18429
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
18966
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1j);
|
|
18430
18967
|
const action = createCommitAction(actionProps);
|
|
18431
18968
|
const toolSchema = addTool({
|
|
18432
18969
|
toolName,
|
|
@@ -18503,12 +19040,12 @@ function addCommitAction(params) {
|
|
|
18503
19040
|
* Adds fetch info functionality to an agent by creating a tool that fetches and provides information.
|
|
18504
19041
|
* @module addFetchInfo
|
|
18505
19042
|
*/
|
|
18506
|
-
const METHOD_NAME$
|
|
19043
|
+
const METHOD_NAME$1i = "function.alias.addFetchInfo";
|
|
18507
19044
|
/**
|
|
18508
19045
|
* Function implementation
|
|
18509
19046
|
*/
|
|
18510
19047
|
const addFetchInfoInternal = beginContext(({ toolName, docNote, function: functionSchema, isAvailable, validateParams: validate, ...fetchProps }) => {
|
|
18511
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
19048
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$1i);
|
|
18512
19049
|
const fetch = createFetchInfo(fetchProps);
|
|
18513
19050
|
const toolSchema = addTool({
|
|
18514
19051
|
toolName,
|
|
@@ -18574,13 +19111,13 @@ function addFetchInfo(params) {
|
|
|
18574
19111
|
}
|
|
18575
19112
|
|
|
18576
19113
|
/** @constant {string} METHOD_NAME - The name of the method used for logging*/
|
|
18577
|
-
const METHOD_NAME$
|
|
19114
|
+
const METHOD_NAME$1h = "function.setup.addAdvisor";
|
|
18578
19115
|
/**
|
|
18579
19116
|
* Function implementation
|
|
18580
19117
|
*/
|
|
18581
19118
|
const addAdvisorInternal = beginContext((advisorSchema) => {
|
|
18582
19119
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18583
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19120
|
+
swarm$1.loggerService.log(METHOD_NAME$1h, {
|
|
18584
19121
|
advisorSchema,
|
|
18585
19122
|
});
|
|
18586
19123
|
swarm$1.advisorValidationService.addAdvisor(advisorSchema.advisorName, advisorSchema);
|
|
@@ -18691,14 +19228,14 @@ const mapAgentSchema = ({ system, systemDynamic, systemStatic, ...schema }) => r
|
|
|
18691
19228
|
: systemDynamic,
|
|
18692
19229
|
});
|
|
18693
19230
|
|
|
18694
|
-
const METHOD_NAME$
|
|
19231
|
+
const METHOD_NAME$1g = "function.setup.addAgent";
|
|
18695
19232
|
/**
|
|
18696
19233
|
* Function implementation
|
|
18697
19234
|
*/
|
|
18698
19235
|
const addAgentInternal = beginContext((publicAgentSchema) => {
|
|
18699
19236
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
18700
19237
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18701
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19238
|
+
swarm$1.loggerService.log(METHOD_NAME$1g, {
|
|
18702
19239
|
agentSchema: publicAgentSchema,
|
|
18703
19240
|
});
|
|
18704
19241
|
const agentSchema = mapAgentSchema(publicAgentSchema);
|
|
@@ -18734,8 +19271,26 @@ function addAgent(agentSchema) {
|
|
|
18734
19271
|
* Also removes any undefined properties from the resulting schema object.
|
|
18735
19272
|
*
|
|
18736
19273
|
*/
|
|
18737
|
-
const mapCompletionSchema = ({ getCompletion, ...schema }) => removeUndefined({
|
|
19274
|
+
const mapCompletionSchema = ({ getCompletion, callbacks, ...schema }) => removeUndefined({
|
|
18738
19275
|
...schema,
|
|
19276
|
+
callbacks: callbacks
|
|
19277
|
+
? {
|
|
19278
|
+
...callbacks,
|
|
19279
|
+
onComplete: callbacks.onComplete
|
|
19280
|
+
? (...args) => {
|
|
19281
|
+
try {
|
|
19282
|
+
// Observer callback: a throw here would reject getCompletion
|
|
19283
|
+
// inside the queued EXECUTE_FN and hang the pending
|
|
19284
|
+
// waitForOutput of the execution.
|
|
19285
|
+
return callbacks.onComplete(...args);
|
|
19286
|
+
}
|
|
19287
|
+
catch (error) {
|
|
19288
|
+
console.error(`agent-swarm onComplete completion callback error completionName=${schema.completionName} error=${getErrorMessage(error)}`);
|
|
19289
|
+
}
|
|
19290
|
+
}
|
|
19291
|
+
: undefined,
|
|
19292
|
+
}
|
|
19293
|
+
: undefined,
|
|
18739
19294
|
getCompletion: getCompletion
|
|
18740
19295
|
? async (args) => {
|
|
18741
19296
|
try {
|
|
@@ -18757,14 +19312,14 @@ const mapCompletionSchema = ({ getCompletion, ...schema }) => removeUndefined({
|
|
|
18757
19312
|
: undefined,
|
|
18758
19313
|
});
|
|
18759
19314
|
|
|
18760
|
-
const METHOD_NAME$
|
|
19315
|
+
const METHOD_NAME$1f = "function.setup.addCompletion";
|
|
18761
19316
|
/**
|
|
18762
19317
|
* Function implementation
|
|
18763
19318
|
*/
|
|
18764
19319
|
const addCompletionInternal = beginContext((completionPublicSchema) => {
|
|
18765
19320
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
18766
19321
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18767
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19322
|
+
swarm$1.loggerService.log(METHOD_NAME$1f, {
|
|
18768
19323
|
completionSchema: completionPublicSchema,
|
|
18769
19324
|
});
|
|
18770
19325
|
const completionSchema = mapCompletionSchema(completionPublicSchema);
|
|
@@ -18794,14 +19349,14 @@ function addCompletion(completionSchema) {
|
|
|
18794
19349
|
return addCompletionInternal(completionSchema);
|
|
18795
19350
|
}
|
|
18796
19351
|
|
|
18797
|
-
const METHOD_NAME$
|
|
19352
|
+
const METHOD_NAME$1e = "function.setup.addSwarm";
|
|
18798
19353
|
/**
|
|
18799
19354
|
* Function implementation
|
|
18800
19355
|
*/
|
|
18801
19356
|
const addSwarmInternal = beginContext((swarmSchema) => {
|
|
18802
19357
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
18803
19358
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18804
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19359
|
+
swarm$1.loggerService.log(METHOD_NAME$1e, {
|
|
18805
19360
|
swarmSchema,
|
|
18806
19361
|
});
|
|
18807
19362
|
// Register the swarm in the validation and schema services
|
|
@@ -18830,13 +19385,13 @@ function addSwarm(swarmSchema) {
|
|
|
18830
19385
|
return addSwarmInternal(swarmSchema);
|
|
18831
19386
|
}
|
|
18832
19387
|
|
|
18833
|
-
const METHOD_NAME$
|
|
19388
|
+
const METHOD_NAME$1d = "function.setup.addMCP";
|
|
18834
19389
|
/**
|
|
18835
19390
|
* Function implementation
|
|
18836
19391
|
*/
|
|
18837
19392
|
const addMCPInternal = beginContext((mcpSchema) => {
|
|
18838
19393
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18839
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19394
|
+
swarm$1.loggerService.log(METHOD_NAME$1d, {
|
|
18840
19395
|
mcpSchema,
|
|
18841
19396
|
});
|
|
18842
19397
|
swarm$1.mcpValidationService.addMCP(mcpSchema.mcpName, mcpSchema);
|
|
@@ -18851,14 +19406,14 @@ function addMCP(mcpSchema) {
|
|
|
18851
19406
|
return addMCPInternal(mcpSchema);
|
|
18852
19407
|
}
|
|
18853
19408
|
|
|
18854
|
-
const METHOD_NAME$
|
|
19409
|
+
const METHOD_NAME$1c = "function.setup.addState";
|
|
18855
19410
|
/**
|
|
18856
19411
|
* Function implementation
|
|
18857
19412
|
*/
|
|
18858
19413
|
const addStateInternal = beginContext((stateSchema) => {
|
|
18859
19414
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
18860
19415
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18861
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19416
|
+
swarm$1.loggerService.log(METHOD_NAME$1c, {
|
|
18862
19417
|
stateSchema,
|
|
18863
19418
|
});
|
|
18864
19419
|
// Register the policy with StateValidationService for runtime validation
|
|
@@ -18869,7 +19424,8 @@ const addStateInternal = beginContext((stateSchema) => {
|
|
|
18869
19424
|
if (stateSchema.shared) {
|
|
18870
19425
|
swarm$1.sharedStateConnectionService
|
|
18871
19426
|
.getStateRef(stateSchema.stateName)
|
|
18872
|
-
.waitForInit()
|
|
19427
|
+
.waitForInit()
|
|
19428
|
+
.catch((error) => console.error(`agent-swarm shared state waitForInit error error=${getErrorMessage(error)}`));
|
|
18873
19429
|
}
|
|
18874
19430
|
// Return the state's name as confirmation of registration
|
|
18875
19431
|
return stateSchema.stateName;
|
|
@@ -18896,14 +19452,14 @@ function addState(stateSchema) {
|
|
|
18896
19452
|
return addStateInternal(stateSchema);
|
|
18897
19453
|
}
|
|
18898
19454
|
|
|
18899
|
-
const METHOD_NAME$
|
|
19455
|
+
const METHOD_NAME$1b = "function.setup.addEmbedding";
|
|
18900
19456
|
/**
|
|
18901
19457
|
* Function implementation
|
|
18902
19458
|
*/
|
|
18903
19459
|
const addEmbeddingInternal = beginContext((embeddingSchema) => {
|
|
18904
19460
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
18905
19461
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18906
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19462
|
+
swarm$1.loggerService.log(METHOD_NAME$1b, {
|
|
18907
19463
|
embeddingSchema,
|
|
18908
19464
|
});
|
|
18909
19465
|
// Register the embedding in the validation and schema services
|
|
@@ -18932,14 +19488,14 @@ function addEmbedding(embeddingSchema) {
|
|
|
18932
19488
|
return addEmbeddingInternal(embeddingSchema);
|
|
18933
19489
|
}
|
|
18934
19490
|
|
|
18935
|
-
const METHOD_NAME$
|
|
19491
|
+
const METHOD_NAME$1a = "function.setup.addStorage";
|
|
18936
19492
|
/**
|
|
18937
19493
|
* Function implementation
|
|
18938
19494
|
*/
|
|
18939
19495
|
const addStorageInternal = beginContext((storageSchema) => {
|
|
18940
19496
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
18941
19497
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18942
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19498
|
+
swarm$1.loggerService.log(METHOD_NAME$1a, {
|
|
18943
19499
|
storageSchema,
|
|
18944
19500
|
});
|
|
18945
19501
|
// Register the storage in the validation and schema services
|
|
@@ -18949,7 +19505,8 @@ const addStorageInternal = beginContext((storageSchema) => {
|
|
|
18949
19505
|
if (storageSchema.shared) {
|
|
18950
19506
|
swarm$1.sharedStorageConnectionService
|
|
18951
19507
|
.getStorage(storageSchema.storageName)
|
|
18952
|
-
.waitForInit()
|
|
19508
|
+
.waitForInit()
|
|
19509
|
+
.catch((error) => console.error(`agent-swarm shared storage waitForInit error error=${getErrorMessage(error)}`));
|
|
18953
19510
|
}
|
|
18954
19511
|
// Return the storage's name as confirmation of registration
|
|
18955
19512
|
return storageSchema.storageName;
|
|
@@ -18977,14 +19534,14 @@ function addStorage(storageSchema) {
|
|
|
18977
19534
|
}
|
|
18978
19535
|
|
|
18979
19536
|
/** @private Constant defining the method name for logging and validation context*/
|
|
18980
|
-
const METHOD_NAME$
|
|
19537
|
+
const METHOD_NAME$19 = "function.setup.addPolicy";
|
|
18981
19538
|
/**
|
|
18982
19539
|
* Function implementation
|
|
18983
19540
|
*/
|
|
18984
19541
|
const addPolicyInternal = beginContext((policySchema) => {
|
|
18985
19542
|
// Log the policy addition attempt if enabled
|
|
18986
19543
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
18987
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19544
|
+
swarm$1.loggerService.log(METHOD_NAME$19, {
|
|
18988
19545
|
policySchema,
|
|
18989
19546
|
});
|
|
18990
19547
|
// Register the policy with PolicyValidationService for runtime validation
|
|
@@ -19045,13 +19602,13 @@ function addCompute(computeSchema) {
|
|
|
19045
19602
|
* Method name for the addPipeline operation.
|
|
19046
19603
|
* @private
|
|
19047
19604
|
*/
|
|
19048
|
-
const METHOD_NAME$
|
|
19605
|
+
const METHOD_NAME$18 = "function.setup.addPipeline";
|
|
19049
19606
|
/**
|
|
19050
19607
|
* Function implementation
|
|
19051
19608
|
*/
|
|
19052
19609
|
const addPipelineInternal = beginContext((pipelineSchema) => {
|
|
19053
19610
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19054
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19611
|
+
swarm$1.loggerService.log(METHOD_NAME$18, {
|
|
19055
19612
|
pipelineSchema,
|
|
19056
19613
|
});
|
|
19057
19614
|
swarm$1.pipelineValidationService.addPipeline(pipelineSchema.pipelineName, pipelineSchema);
|
|
@@ -19074,7 +19631,7 @@ function addPipeline(pipelineSchema) {
|
|
|
19074
19631
|
* @private
|
|
19075
19632
|
* @constant {string}
|
|
19076
19633
|
*/
|
|
19077
|
-
const METHOD_NAME$
|
|
19634
|
+
const METHOD_NAME$17 = "function.setup.addOutline";
|
|
19078
19635
|
/**
|
|
19079
19636
|
* Internal implementation of the outline addition logic, wrapped in a clean context.
|
|
19080
19637
|
* Registers the outline schema with both the validation and schema services and logs the operation if enabled.
|
|
@@ -19082,7 +19639,7 @@ const METHOD_NAME$16 = "function.setup.addOutline";
|
|
|
19082
19639
|
*/
|
|
19083
19640
|
const addOutlineInternal = beginContext((outlineSchema) => {
|
|
19084
19641
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19085
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19642
|
+
swarm$1.loggerService.log(METHOD_NAME$17, {
|
|
19086
19643
|
outlineSchema,
|
|
19087
19644
|
});
|
|
19088
19645
|
swarm$1.outlineValidationService.addOutline(outlineSchema.outlineName, outlineSchema);
|
|
@@ -19101,16 +19658,16 @@ function addOutline(outlineSchema) {
|
|
|
19101
19658
|
return addOutlineInternal(outlineSchema);
|
|
19102
19659
|
}
|
|
19103
19660
|
|
|
19104
|
-
const METHOD_NAME$
|
|
19661
|
+
const METHOD_NAME$16 = "function.test.overrideAgent";
|
|
19105
19662
|
/**
|
|
19106
19663
|
* Function implementation
|
|
19107
19664
|
*/
|
|
19108
19665
|
const overrideAgentInternal = beginContext(async (publicAgentSchema) => {
|
|
19109
19666
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19110
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19667
|
+
swarm$1.loggerService.log(METHOD_NAME$16, {
|
|
19111
19668
|
agentSchema: publicAgentSchema,
|
|
19112
19669
|
});
|
|
19113
|
-
await swarm$1.agentValidationService.validate(publicAgentSchema.agentName, METHOD_NAME$
|
|
19670
|
+
await swarm$1.agentValidationService.validate(publicAgentSchema.agentName, METHOD_NAME$16);
|
|
19114
19671
|
const agentSchema = mapAgentSchema(publicAgentSchema);
|
|
19115
19672
|
return swarm$1.agentSchemaService.override(agentSchema.agentName, agentSchema);
|
|
19116
19673
|
});
|
|
@@ -19137,16 +19694,16 @@ async function overrideAgent(agentSchema) {
|
|
|
19137
19694
|
return await overrideAgentInternal(agentSchema);
|
|
19138
19695
|
}
|
|
19139
19696
|
|
|
19140
|
-
const METHOD_NAME$
|
|
19697
|
+
const METHOD_NAME$15 = "function.test.overrideCompletion";
|
|
19141
19698
|
/**
|
|
19142
19699
|
* Function implementation
|
|
19143
19700
|
*/
|
|
19144
19701
|
const overrideCompletionInternal = beginContext(async (publicCompletionSchema) => {
|
|
19145
19702
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19146
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19703
|
+
swarm$1.loggerService.log(METHOD_NAME$15, {
|
|
19147
19704
|
completionSchema: publicCompletionSchema,
|
|
19148
19705
|
});
|
|
19149
|
-
await swarm$1.completionValidationService.validate(publicCompletionSchema.completionName, METHOD_NAME$
|
|
19706
|
+
await swarm$1.completionValidationService.validate(publicCompletionSchema.completionName, METHOD_NAME$15);
|
|
19150
19707
|
const completionSchema = mapCompletionSchema(publicCompletionSchema);
|
|
19151
19708
|
return swarm$1.completionSchemaService.override(completionSchema.completionName, completionSchema);
|
|
19152
19709
|
});
|
|
@@ -19174,16 +19731,16 @@ async function overrideCompletion(completionSchema) {
|
|
|
19174
19731
|
return await overrideCompletionInternal(completionSchema);
|
|
19175
19732
|
}
|
|
19176
19733
|
|
|
19177
|
-
const METHOD_NAME$
|
|
19734
|
+
const METHOD_NAME$14 = "function.test.overrideEmbedding";
|
|
19178
19735
|
/**
|
|
19179
19736
|
* Function implementation
|
|
19180
19737
|
*/
|
|
19181
|
-
const
|
|
19738
|
+
const overrideEmbeddingInternal = beginContext(async (publicEmbeddingSchema) => {
|
|
19182
19739
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19183
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19740
|
+
swarm$1.loggerService.log(METHOD_NAME$14, {
|
|
19184
19741
|
embeddingSchema: publicEmbeddingSchema,
|
|
19185
19742
|
});
|
|
19186
|
-
await swarm$1.embeddingValidationService.validate(publicEmbeddingSchema.embeddingName, METHOD_NAME$
|
|
19743
|
+
await swarm$1.embeddingValidationService.validate(publicEmbeddingSchema.embeddingName, METHOD_NAME$14);
|
|
19187
19744
|
const embeddingSchema = removeUndefined(publicEmbeddingSchema);
|
|
19188
19745
|
return swarm$1.embeddingSchemaService.override(embeddingSchema.embeddingName, embeddingSchema);
|
|
19189
19746
|
});
|
|
@@ -19199,7 +19756,7 @@ const overrideEmbedingInternal = beginContext(async (publicEmbeddingSchema) => {
|
|
|
19199
19756
|
*
|
|
19200
19757
|
* @example
|
|
19201
19758
|
* // Override an embedding’s schema with new properties
|
|
19202
|
-
*
|
|
19759
|
+
* overrideEmbedding({
|
|
19203
19760
|
* embeddingName: "TextEmbedding",
|
|
19204
19761
|
* persist: true,
|
|
19205
19762
|
* callbacks: {
|
|
@@ -19208,20 +19765,20 @@ const overrideEmbedingInternal = beginContext(async (publicEmbeddingSchema) => {
|
|
|
19208
19765
|
* });
|
|
19209
19766
|
* // Logs the operation (if enabled) and updates the embedding schema in the swarm.
|
|
19210
19767
|
*/
|
|
19211
|
-
async function
|
|
19212
|
-
return await
|
|
19768
|
+
async function overrideEmbedding(embeddingSchema) {
|
|
19769
|
+
return await overrideEmbeddingInternal(embeddingSchema);
|
|
19213
19770
|
}
|
|
19214
19771
|
|
|
19215
|
-
const METHOD_NAME$
|
|
19772
|
+
const METHOD_NAME$13 = "function.test.overridePolicy";
|
|
19216
19773
|
/**
|
|
19217
19774
|
* Function implementation
|
|
19218
19775
|
*/
|
|
19219
19776
|
const overridePolicyInternal = beginContext(async (publicPolicySchema) => {
|
|
19220
19777
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19221
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19778
|
+
swarm$1.loggerService.log(METHOD_NAME$13, {
|
|
19222
19779
|
policySchema: publicPolicySchema,
|
|
19223
19780
|
});
|
|
19224
|
-
await swarm$1.policyValidationService.validate(publicPolicySchema.policyName, METHOD_NAME$
|
|
19781
|
+
await swarm$1.policyValidationService.validate(publicPolicySchema.policyName, METHOD_NAME$13);
|
|
19225
19782
|
const policySchema = removeUndefined(publicPolicySchema);
|
|
19226
19783
|
return swarm$1.policySchemaService.override(policySchema.policyName, policySchema);
|
|
19227
19784
|
});
|
|
@@ -19248,16 +19805,16 @@ async function overridePolicy(policySchema) {
|
|
|
19248
19805
|
return await overridePolicyInternal(policySchema);
|
|
19249
19806
|
}
|
|
19250
19807
|
|
|
19251
|
-
const METHOD_NAME$
|
|
19808
|
+
const METHOD_NAME$12 = "function.test.overrideState";
|
|
19252
19809
|
/**
|
|
19253
19810
|
* Function implementation
|
|
19254
19811
|
*/
|
|
19255
19812
|
const overrideStateInternal = beginContext(async (publicStateSchema) => {
|
|
19256
19813
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19257
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19814
|
+
swarm$1.loggerService.log(METHOD_NAME$12, {
|
|
19258
19815
|
stateSchema: publicStateSchema,
|
|
19259
19816
|
});
|
|
19260
|
-
await swarm$1.stateValidationService.validate(publicStateSchema.stateName, METHOD_NAME$
|
|
19817
|
+
await swarm$1.stateValidationService.validate(publicStateSchema.stateName, METHOD_NAME$12);
|
|
19261
19818
|
const stateSchema = removeUndefined(publicStateSchema);
|
|
19262
19819
|
return swarm$1.stateSchemaService.override(stateSchema.stateName, stateSchema);
|
|
19263
19820
|
});
|
|
@@ -19285,16 +19842,16 @@ async function overrideState(stateSchema) {
|
|
|
19285
19842
|
return await overrideStateInternal(stateSchema);
|
|
19286
19843
|
}
|
|
19287
19844
|
|
|
19288
|
-
const METHOD_NAME$
|
|
19845
|
+
const METHOD_NAME$11 = "function.test.overrideStorage";
|
|
19289
19846
|
/**
|
|
19290
19847
|
* Function implementation
|
|
19291
19848
|
*/
|
|
19292
19849
|
const overrideStorageInternal = beginContext(async (publicStorageSchema) => {
|
|
19293
19850
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19294
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19851
|
+
swarm$1.loggerService.log(METHOD_NAME$11, {
|
|
19295
19852
|
storageSchema: publicStorageSchema,
|
|
19296
19853
|
});
|
|
19297
|
-
await swarm$1.storageValidationService.validate(publicStorageSchema.storageName, METHOD_NAME$
|
|
19854
|
+
await swarm$1.storageValidationService.validate(publicStorageSchema.storageName, METHOD_NAME$11);
|
|
19298
19855
|
const storageSchema = removeUndefined(publicStorageSchema);
|
|
19299
19856
|
return swarm$1.storageSchemaService.override(storageSchema.storageName, storageSchema);
|
|
19300
19857
|
});
|
|
@@ -19323,16 +19880,16 @@ async function overrideStorage(storageSchema) {
|
|
|
19323
19880
|
return await overrideStorageInternal(storageSchema);
|
|
19324
19881
|
}
|
|
19325
19882
|
|
|
19326
|
-
const METHOD_NAME
|
|
19883
|
+
const METHOD_NAME$10 = "function.test.overrideSwarm";
|
|
19327
19884
|
/**
|
|
19328
19885
|
* Function implementation
|
|
19329
19886
|
*/
|
|
19330
19887
|
const overrideSwarmInternal = beginContext(async (publicSwarmSchema) => {
|
|
19331
19888
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19332
|
-
swarm$1.loggerService.log(METHOD_NAME
|
|
19889
|
+
swarm$1.loggerService.log(METHOD_NAME$10, {
|
|
19333
19890
|
swarmSchema: publicSwarmSchema,
|
|
19334
19891
|
});
|
|
19335
|
-
await swarm$1.swarmValidationService.validate(publicSwarmSchema.swarmName, METHOD_NAME
|
|
19892
|
+
await swarm$1.swarmValidationService.validate(publicSwarmSchema.swarmName, METHOD_NAME$10);
|
|
19336
19893
|
const swarmSchema = removeUndefined(publicSwarmSchema);
|
|
19337
19894
|
return swarm$1.swarmSchemaService.override(swarmSchema.swarmName, swarmSchema);
|
|
19338
19895
|
});
|
|
@@ -19359,16 +19916,16 @@ async function overrideSwarm(swarmSchema) {
|
|
|
19359
19916
|
return await overrideSwarmInternal(swarmSchema);
|
|
19360
19917
|
}
|
|
19361
19918
|
|
|
19362
|
-
const METHOD_NAME
|
|
19919
|
+
const METHOD_NAME$$ = "function.test.overrideTool";
|
|
19363
19920
|
/**
|
|
19364
19921
|
* Function implementation
|
|
19365
19922
|
*/
|
|
19366
19923
|
const overrideToolInternal = beginContext(async (publicToolSchema) => {
|
|
19367
19924
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19368
|
-
swarm$1.loggerService.log(METHOD_NAME
|
|
19925
|
+
swarm$1.loggerService.log(METHOD_NAME$$, {
|
|
19369
19926
|
toolSchema: publicToolSchema,
|
|
19370
19927
|
});
|
|
19371
|
-
await swarm$1.toolValidationService.validate(publicToolSchema.toolName, METHOD_NAME
|
|
19928
|
+
await swarm$1.toolValidationService.validate(publicToolSchema.toolName, METHOD_NAME$$);
|
|
19372
19929
|
const toolSchema = removeUndefined(publicToolSchema);
|
|
19373
19930
|
return swarm$1.toolSchemaService.override(toolSchema.toolName, toolSchema);
|
|
19374
19931
|
});
|
|
@@ -19394,16 +19951,16 @@ async function overrideTool(toolSchema) {
|
|
|
19394
19951
|
return await overrideToolInternal(toolSchema);
|
|
19395
19952
|
}
|
|
19396
19953
|
|
|
19397
|
-
const METHOD_NAME$
|
|
19954
|
+
const METHOD_NAME$_ = "function.test.overrideMCP";
|
|
19398
19955
|
/**
|
|
19399
19956
|
* Function implementation
|
|
19400
19957
|
*/
|
|
19401
19958
|
const overrideMCPInternal = beginContext(async (publicMcpSchema) => {
|
|
19402
19959
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19403
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19960
|
+
swarm$1.loggerService.log(METHOD_NAME$_, {
|
|
19404
19961
|
mcpSchema: publicMcpSchema,
|
|
19405
19962
|
});
|
|
19406
|
-
await swarm$1.mcpValidationService.validate(publicMcpSchema.mcpName, METHOD_NAME$
|
|
19963
|
+
await swarm$1.mcpValidationService.validate(publicMcpSchema.mcpName, METHOD_NAME$_);
|
|
19407
19964
|
const mcpSchema = removeUndefined(publicMcpSchema);
|
|
19408
19965
|
return swarm$1.mcpSchemaService.override(mcpSchema.mcpName, mcpSchema);
|
|
19409
19966
|
});
|
|
@@ -19415,16 +19972,16 @@ async function overrideMCP(mcpSchema) {
|
|
|
19415
19972
|
return await overrideMCPInternal(mcpSchema);
|
|
19416
19973
|
}
|
|
19417
19974
|
|
|
19418
|
-
const METHOD_NAME$
|
|
19975
|
+
const METHOD_NAME$Z = "function.test.overrideAdvisor";
|
|
19419
19976
|
/**
|
|
19420
19977
|
* Function implementation
|
|
19421
19978
|
*/
|
|
19422
19979
|
const overrideAdvisorInternal = beginContext(async (publicAdvisorSchema) => {
|
|
19423
19980
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19424
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
19981
|
+
swarm$1.loggerService.log(METHOD_NAME$Z, {
|
|
19425
19982
|
advisorSchema: publicAdvisorSchema,
|
|
19426
19983
|
});
|
|
19427
|
-
await swarm$1.advisorValidationService.validate(publicAdvisorSchema.advisorName, METHOD_NAME$
|
|
19984
|
+
await swarm$1.advisorValidationService.validate(publicAdvisorSchema.advisorName, METHOD_NAME$Z);
|
|
19428
19985
|
const advisorSchema = removeUndefined(publicAdvisorSchema);
|
|
19429
19986
|
return swarm$1.advisorSchemaService.override(advisorSchema.advisorName, advisorSchema);
|
|
19430
19987
|
});
|
|
@@ -19469,16 +20026,16 @@ async function overrideAdvisor(advisorSchema) {
|
|
|
19469
20026
|
* Method name for the overrideCompute operation.
|
|
19470
20027
|
* @private
|
|
19471
20028
|
*/
|
|
19472
|
-
const METHOD_NAME$
|
|
20029
|
+
const METHOD_NAME$Y = "function.test.overrideCompute";
|
|
19473
20030
|
/**
|
|
19474
20031
|
* Function implementation
|
|
19475
20032
|
*/
|
|
19476
20033
|
const overrideComputeInternal = beginContext(async (publicComputeSchema) => {
|
|
19477
20034
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19478
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20035
|
+
swarm$1.loggerService.log(METHOD_NAME$Y, {
|
|
19479
20036
|
computeSchema: publicComputeSchema,
|
|
19480
20037
|
});
|
|
19481
|
-
await swarm$1.computeValidationService.validate(publicComputeSchema.computeName, METHOD_NAME$
|
|
20038
|
+
await swarm$1.computeValidationService.validate(publicComputeSchema.computeName, METHOD_NAME$Y);
|
|
19482
20039
|
const computeSchema = removeUndefined(publicComputeSchema);
|
|
19483
20040
|
return swarm$1.computeSchemaService.override(computeSchema.computeName, computeSchema);
|
|
19484
20041
|
});
|
|
@@ -19500,16 +20057,16 @@ async function overrideCompute(computeSchema) {
|
|
|
19500
20057
|
* Method name for the overridePipeline operation.
|
|
19501
20058
|
* @private
|
|
19502
20059
|
*/
|
|
19503
|
-
const METHOD_NAME$
|
|
20060
|
+
const METHOD_NAME$X = "function.test.overridePipeline";
|
|
19504
20061
|
/**
|
|
19505
20062
|
* Function implementation
|
|
19506
20063
|
*/
|
|
19507
20064
|
const overridePipelineInternal = beginContext(async (publicPipelineSchema) => {
|
|
19508
20065
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19509
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20066
|
+
swarm$1.loggerService.log(METHOD_NAME$X, {
|
|
19510
20067
|
pipelineSchema: publicPipelineSchema,
|
|
19511
20068
|
});
|
|
19512
|
-
await swarm$1.pipelineValidationService.validate(publicPipelineSchema.pipelineName, METHOD_NAME$
|
|
20069
|
+
await swarm$1.pipelineValidationService.validate(publicPipelineSchema.pipelineName, METHOD_NAME$X);
|
|
19513
20070
|
const pipelineSchema = removeUndefined(publicPipelineSchema);
|
|
19514
20071
|
return swarm$1.pipelineSchemaService.override(pipelineSchema.pipelineName, pipelineSchema);
|
|
19515
20072
|
});
|
|
@@ -19529,7 +20086,7 @@ async function overridePipeline(pipelineSchema) {
|
|
|
19529
20086
|
* @private
|
|
19530
20087
|
* @constant {string}
|
|
19531
20088
|
*/
|
|
19532
|
-
const METHOD_NAME$
|
|
20089
|
+
const METHOD_NAME$W = "function.test.overrideOutline";
|
|
19533
20090
|
/**
|
|
19534
20091
|
* Internal implementation of the outline override logic, wrapped in a clean context.
|
|
19535
20092
|
* Updates the specified outline schema in the swarm's schema service and logs the operation if enabled.
|
|
@@ -19537,10 +20094,10 @@ const METHOD_NAME$V = "function.test.overrideOutline";
|
|
|
19537
20094
|
*/
|
|
19538
20095
|
const overrideOutlineInternal = beginContext(async (publicOutlineSchema) => {
|
|
19539
20096
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19540
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20097
|
+
swarm$1.loggerService.log(METHOD_NAME$W, {
|
|
19541
20098
|
outlineSchema: publicOutlineSchema,
|
|
19542
20099
|
});
|
|
19543
|
-
await swarm$1.outlineValidationService.validate(publicOutlineSchema.outlineName, METHOD_NAME$
|
|
20100
|
+
await swarm$1.outlineValidationService.validate(publicOutlineSchema.outlineName, METHOD_NAME$W);
|
|
19544
20101
|
const outlineSchema = removeUndefined(publicOutlineSchema);
|
|
19545
20102
|
return swarm$1.outlineSchemaService.override(outlineSchema.outlineName, outlineSchema);
|
|
19546
20103
|
});
|
|
@@ -19556,23 +20113,23 @@ async function overrideOutline(outlineSchema) {
|
|
|
19556
20113
|
return await overrideOutlineInternal(outlineSchema);
|
|
19557
20114
|
}
|
|
19558
20115
|
|
|
19559
|
-
const METHOD_NAME$
|
|
20116
|
+
const METHOD_NAME$V = "function.other.markOnline";
|
|
19560
20117
|
/**
|
|
19561
20118
|
* Function implementation
|
|
19562
20119
|
*/
|
|
19563
20120
|
const markOnlineInternal = async (clientId, swarmName) => {
|
|
19564
20121
|
// Log the operation if logging is enabled in the global configuration
|
|
19565
20122
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19566
|
-
swarm.loggerService.log(METHOD_NAME$
|
|
20123
|
+
swarm.loggerService.log(METHOD_NAME$V, {
|
|
19567
20124
|
clientId,
|
|
19568
20125
|
});
|
|
19569
20126
|
// Validate the swarm name
|
|
19570
|
-
swarm.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20127
|
+
swarm.swarmValidationService.validate(swarmName, METHOD_NAME$V);
|
|
19571
20128
|
// Run the operation in the method context
|
|
19572
20129
|
return await MethodContextService.runInContext(async () => {
|
|
19573
|
-
await swarm.aliveService.markOnline(clientId, swarmName, METHOD_NAME$
|
|
20130
|
+
await swarm.aliveService.markOnline(clientId, swarmName, METHOD_NAME$V);
|
|
19574
20131
|
}, {
|
|
19575
|
-
methodName: METHOD_NAME$
|
|
20132
|
+
methodName: METHOD_NAME$V,
|
|
19576
20133
|
agentName: "",
|
|
19577
20134
|
policyName: "",
|
|
19578
20135
|
stateName: "",
|
|
@@ -19595,20 +20152,20 @@ async function markOnline(clientId, swarmName) {
|
|
|
19595
20152
|
return await markOnlineInternal(clientId, swarmName);
|
|
19596
20153
|
}
|
|
19597
20154
|
|
|
19598
|
-
const METHOD_NAME$
|
|
20155
|
+
const METHOD_NAME$U = "function.other.markOffline";
|
|
19599
20156
|
/**
|
|
19600
20157
|
* Function implementation
|
|
19601
20158
|
*/
|
|
19602
20159
|
const markOfflineInternal = async (clientId, swarmName) => {
|
|
19603
20160
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19604
|
-
swarm.loggerService.log(METHOD_NAME$
|
|
20161
|
+
swarm.loggerService.log(METHOD_NAME$U, {
|
|
19605
20162
|
clientId,
|
|
19606
20163
|
});
|
|
19607
|
-
swarm.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20164
|
+
swarm.swarmValidationService.validate(swarmName, METHOD_NAME$U);
|
|
19608
20165
|
return await MethodContextService.runInContext(async () => {
|
|
19609
|
-
await swarm.aliveService.markOffline(clientId, swarmName, METHOD_NAME$
|
|
20166
|
+
await swarm.aliveService.markOffline(clientId, swarmName, METHOD_NAME$U);
|
|
19610
20167
|
}, {
|
|
19611
|
-
methodName: METHOD_NAME$
|
|
20168
|
+
methodName: METHOD_NAME$U,
|
|
19612
20169
|
agentName: "",
|
|
19613
20170
|
policyName: "",
|
|
19614
20171
|
stateName: "",
|
|
@@ -19636,27 +20193,27 @@ async function markOffline(clientId, swarmName) {
|
|
|
19636
20193
|
}
|
|
19637
20194
|
|
|
19638
20195
|
/** @private Constant defining the method name for logging and validation context*/
|
|
19639
|
-
const METHOD_NAME$
|
|
20196
|
+
const METHOD_NAME$T = "function.commit.commitSystemMessage";
|
|
19640
20197
|
/**
|
|
19641
20198
|
* Function implementation
|
|
19642
20199
|
*/
|
|
19643
20200
|
const commitSystemMessageInternal = beginContext(async (content, clientId, agentName) => {
|
|
19644
20201
|
// Log the commit attempt if enabled
|
|
19645
20202
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19646
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20203
|
+
swarm$1.loggerService.log(METHOD_NAME$T, {
|
|
19647
20204
|
content,
|
|
19648
20205
|
clientId,
|
|
19649
20206
|
agentName,
|
|
19650
20207
|
});
|
|
19651
20208
|
// Validate the agent exists
|
|
19652
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
20209
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$T);
|
|
19653
20210
|
// Validate the session exists and retrieve the associated swarm
|
|
19654
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20211
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$T);
|
|
19655
20212
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
19656
20213
|
// Validate the swarm configuration
|
|
19657
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20214
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$T);
|
|
19658
20215
|
// Check if the current agent matches the provided agent
|
|
19659
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
20216
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$T, clientId, swarmName);
|
|
19660
20217
|
if (currentAgentName !== agentName) {
|
|
19661
20218
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19662
20219
|
swarm$1.loggerService.log('function "commitSystemMessage" skipped due to the agent change', {
|
|
@@ -19667,7 +20224,7 @@ const commitSystemMessageInternal = beginContext(async (content, clientId, agent
|
|
|
19667
20224
|
return;
|
|
19668
20225
|
}
|
|
19669
20226
|
// Commit the system message via SessionPublicService
|
|
19670
|
-
await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$
|
|
20227
|
+
await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$T, clientId, swarmName);
|
|
19671
20228
|
});
|
|
19672
20229
|
/**
|
|
19673
20230
|
* Commits a system-generated message to the active agent in the swarm system.
|
|
@@ -19689,22 +20246,22 @@ async function commitSystemMessage(content, clientId, agentName) {
|
|
|
19689
20246
|
}
|
|
19690
20247
|
|
|
19691
20248
|
/** @private Constant defining the method name for logging and validation context*/
|
|
19692
|
-
const METHOD_NAME$
|
|
20249
|
+
const METHOD_NAME$S = "function.commit.commitDeveloperMessage";
|
|
19693
20250
|
/**
|
|
19694
20251
|
* Function implementation
|
|
19695
20252
|
*/
|
|
19696
20253
|
const commitDeveloperMessageInternal = beginContext(async (content, clientId, agentName) => {
|
|
19697
20254
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19698
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20255
|
+
swarm$1.loggerService.log(METHOD_NAME$S, {
|
|
19699
20256
|
content,
|
|
19700
20257
|
clientId,
|
|
19701
20258
|
agentName,
|
|
19702
20259
|
});
|
|
19703
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
19704
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20260
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$S);
|
|
20261
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$S);
|
|
19705
20262
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
19706
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
19707
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
20263
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$S);
|
|
20264
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$S, clientId, swarmName);
|
|
19708
20265
|
if (currentAgentName !== agentName) {
|
|
19709
20266
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19710
20267
|
swarm$1.loggerService.log('function "commitDeveloperMessage" skipped due to the agent change', {
|
|
@@ -19714,7 +20271,7 @@ const commitDeveloperMessageInternal = beginContext(async (content, clientId, ag
|
|
|
19714
20271
|
});
|
|
19715
20272
|
return;
|
|
19716
20273
|
}
|
|
19717
|
-
await swarm$1.sessionPublicService.commitDeveloperMessage(content, METHOD_NAME$
|
|
20274
|
+
await swarm$1.sessionPublicService.commitDeveloperMessage(content, METHOD_NAME$S, clientId, swarmName);
|
|
19718
20275
|
});
|
|
19719
20276
|
/**
|
|
19720
20277
|
* Commits a developer-generated message to the active agent in the swarm system.
|
|
@@ -19735,26 +20292,26 @@ async function commitDeveloperMessage(content, clientId, agentName) {
|
|
|
19735
20292
|
return await commitDeveloperMessageInternal(content, clientId, agentName);
|
|
19736
20293
|
}
|
|
19737
20294
|
|
|
19738
|
-
const METHOD_NAME$
|
|
20295
|
+
const METHOD_NAME$R = "function.commit.commitUserMessage";
|
|
19739
20296
|
/**
|
|
19740
20297
|
* Function implementation
|
|
19741
20298
|
*/
|
|
19742
20299
|
const commitUserMessageInternal = beginContext(async (content, mode, clientId, agentName, payload) => {
|
|
19743
20300
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
19744
20301
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19745
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20302
|
+
swarm$1.loggerService.log(METHOD_NAME$R, {
|
|
19746
20303
|
content,
|
|
19747
20304
|
clientId,
|
|
19748
20305
|
agentName,
|
|
19749
20306
|
mode,
|
|
19750
20307
|
});
|
|
19751
20308
|
// Validate the agent, session, and swarm to ensure they exist and are accessible
|
|
19752
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
19753
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20309
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$R);
|
|
20310
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$R);
|
|
19754
20311
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
19755
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20312
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$R);
|
|
19756
20313
|
// Check if the specified agent is still the active agent in the swarm session
|
|
19757
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
20314
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$R, clientId, swarmName);
|
|
19758
20315
|
if (currentAgentName !== agentName) {
|
|
19759
20316
|
// Log a skip message if the agent has changed during the operation
|
|
19760
20317
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
@@ -19767,14 +20324,14 @@ const commitUserMessageInternal = beginContext(async (content, mode, clientId, a
|
|
|
19767
20324
|
}
|
|
19768
20325
|
if (payload) {
|
|
19769
20326
|
return await PayloadContextService.runInContext(async () => {
|
|
19770
|
-
await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$
|
|
20327
|
+
await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$R, clientId, swarmName);
|
|
19771
20328
|
}, {
|
|
19772
20329
|
clientId,
|
|
19773
20330
|
payload,
|
|
19774
20331
|
});
|
|
19775
20332
|
}
|
|
19776
20333
|
// Commit the user message to the agent's history via the session public service
|
|
19777
|
-
return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$
|
|
20334
|
+
return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$R, clientId, swarmName);
|
|
19778
20335
|
});
|
|
19779
20336
|
/**
|
|
19780
20337
|
* Commits a user message to the active agent's history in a swarm session without triggering a response.
|
|
@@ -19798,24 +20355,24 @@ async function commitUserMessage(content, mode, clientId, agentName, payload) {
|
|
|
19798
20355
|
}
|
|
19799
20356
|
|
|
19800
20357
|
/** @private Constant defining the method name for logging and validation context*/
|
|
19801
|
-
const METHOD_NAME$
|
|
20358
|
+
const METHOD_NAME$Q = "function.commit.commitSystemMessageForce";
|
|
19802
20359
|
/**
|
|
19803
20360
|
* Function implementation
|
|
19804
20361
|
*/
|
|
19805
20362
|
const commitSystemMessageForceInternal = beginContext(async (content, clientId) => {
|
|
19806
20363
|
// Log the commit attempt if enabled
|
|
19807
20364
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19808
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20365
|
+
swarm$1.loggerService.log(METHOD_NAME$Q, {
|
|
19809
20366
|
content,
|
|
19810
20367
|
clientId,
|
|
19811
20368
|
});
|
|
19812
20369
|
// Validate the session exists and retrieve the associated swarm
|
|
19813
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20370
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$Q);
|
|
19814
20371
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
19815
20372
|
// Validate the swarm configuration
|
|
19816
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20373
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$Q);
|
|
19817
20374
|
// Commit the system message via SessionPublicService without agent checks
|
|
19818
|
-
await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$
|
|
20375
|
+
await swarm$1.sessionPublicService.commitSystemMessage(content, METHOD_NAME$Q, clientId, swarmName);
|
|
19819
20376
|
});
|
|
19820
20377
|
/**
|
|
19821
20378
|
* Forcefully commits a system-generated message to a session in the swarm system, without checking the active agent.
|
|
@@ -19836,7 +20393,7 @@ async function commitSystemMessageForce(content, clientId) {
|
|
|
19836
20393
|
}
|
|
19837
20394
|
|
|
19838
20395
|
/** @private Constant defining the method name for logging and validation context*/
|
|
19839
|
-
const METHOD_NAME$
|
|
20396
|
+
const METHOD_NAME$P = "function.commit.commitDeveloperMessageForce";
|
|
19840
20397
|
/**
|
|
19841
20398
|
* Internal implementation for forcefully committing a developer message to a session in the swarm system.
|
|
19842
20399
|
* Logs the operation if enabled, validates the session and swarm, and commits the message via SessionPublicService.
|
|
@@ -19849,14 +20406,14 @@ const METHOD_NAME$O = "function.commit.commitDeveloperMessageForce";
|
|
|
19849
20406
|
*/
|
|
19850
20407
|
const commitDeveloperMessageForceInternal = beginContext(async (content, clientId) => {
|
|
19851
20408
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19852
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20409
|
+
swarm$1.loggerService.log(METHOD_NAME$P, {
|
|
19853
20410
|
content,
|
|
19854
20411
|
clientId,
|
|
19855
20412
|
});
|
|
19856
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20413
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$P);
|
|
19857
20414
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
19858
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
19859
|
-
await swarm$1.sessionPublicService.commitDeveloperMessage(content, METHOD_NAME$
|
|
20415
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$P);
|
|
20416
|
+
await swarm$1.sessionPublicService.commitDeveloperMessage(content, METHOD_NAME$P, clientId, swarmName);
|
|
19860
20417
|
});
|
|
19861
20418
|
/**
|
|
19862
20419
|
* Forcefully commits a developer-generated message to a session in the swarm system, without checking the active agent.
|
|
@@ -19875,32 +20432,32 @@ async function commitDeveloperMessageForce(content, clientId) {
|
|
|
19875
20432
|
return await commitDeveloperMessageForceInternal(content, clientId);
|
|
19876
20433
|
}
|
|
19877
20434
|
|
|
19878
|
-
const METHOD_NAME$
|
|
20435
|
+
const METHOD_NAME$O = "function.commit.commitUserMessageForce";
|
|
19879
20436
|
/**
|
|
19880
20437
|
* Function implementation
|
|
19881
20438
|
*/
|
|
19882
20439
|
const commitUserMessageForceInternal = beginContext(async (content, mode, clientId, payload) => {
|
|
19883
20440
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
19884
20441
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19885
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20442
|
+
swarm$1.loggerService.log(METHOD_NAME$O, {
|
|
19886
20443
|
content,
|
|
19887
20444
|
clientId,
|
|
19888
20445
|
mode,
|
|
19889
20446
|
});
|
|
19890
20447
|
// Validate the session and swarm to ensure they exist and are accessible
|
|
19891
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20448
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$O);
|
|
19892
20449
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
19893
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20450
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$O);
|
|
19894
20451
|
if (payload) {
|
|
19895
20452
|
return await PayloadContextService.runInContext(async () => {
|
|
19896
|
-
await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$
|
|
20453
|
+
await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$O, clientId, swarmName);
|
|
19897
20454
|
}, {
|
|
19898
20455
|
clientId,
|
|
19899
20456
|
payload,
|
|
19900
20457
|
});
|
|
19901
20458
|
}
|
|
19902
20459
|
// Commit the user message to the agent's history via the session public service without checking the active agent
|
|
19903
|
-
return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$
|
|
20460
|
+
return await swarm$1.sessionPublicService.commitUserMessage(content, mode, METHOD_NAME$O, clientId, swarmName);
|
|
19904
20461
|
});
|
|
19905
20462
|
/**
|
|
19906
20463
|
* Commits a user message to the active agent's history in a swarm session without triggering a response and without checking the active agent.
|
|
@@ -19923,27 +20480,27 @@ async function commitUserMessageForce(content, mode, clientId, payload) {
|
|
|
19923
20480
|
}
|
|
19924
20481
|
|
|
19925
20482
|
/** @private Constant defining the method name for logging and validation context*/
|
|
19926
|
-
const METHOD_NAME$
|
|
20483
|
+
const METHOD_NAME$N = "function.commit.commitAssistantMessage";
|
|
19927
20484
|
/**
|
|
19928
20485
|
* Function implementation
|
|
19929
20486
|
*/
|
|
19930
20487
|
const commitAssistantMessageInternal = beginContext(async (content, clientId, agentName) => {
|
|
19931
20488
|
// Log the commit attempt if enabled
|
|
19932
20489
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19933
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20490
|
+
swarm$1.loggerService.log(METHOD_NAME$N, {
|
|
19934
20491
|
content,
|
|
19935
20492
|
clientId,
|
|
19936
20493
|
agentName,
|
|
19937
20494
|
});
|
|
19938
20495
|
// Validate the agent exists
|
|
19939
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
20496
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$N);
|
|
19940
20497
|
// Validate the session exists and retrieve the associated swarm
|
|
19941
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20498
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$N);
|
|
19942
20499
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
19943
20500
|
// Validate the swarm configuration
|
|
19944
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20501
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$N);
|
|
19945
20502
|
// Check if the current agent matches the provided agent
|
|
19946
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
20503
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$N, clientId, swarmName);
|
|
19947
20504
|
if (currentAgentName !== agentName) {
|
|
19948
20505
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19949
20506
|
swarm$1.loggerService.log('function "commitAssistantMessage" skipped due to the agent change', {
|
|
@@ -19954,7 +20511,7 @@ const commitAssistantMessageInternal = beginContext(async (content, clientId, ag
|
|
|
19954
20511
|
return;
|
|
19955
20512
|
}
|
|
19956
20513
|
// Commit the assistant message via SessionPublicService
|
|
19957
|
-
await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$
|
|
20514
|
+
await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$N, clientId, swarmName);
|
|
19958
20515
|
});
|
|
19959
20516
|
/**
|
|
19960
20517
|
* Commits an assistant-generated message to the active agent in the swarm system.
|
|
@@ -19975,24 +20532,24 @@ async function commitAssistantMessage(content, clientId, agentName) {
|
|
|
19975
20532
|
}
|
|
19976
20533
|
|
|
19977
20534
|
/** @private Constant defining the method name for logging and validation context*/
|
|
19978
|
-
const METHOD_NAME$
|
|
20535
|
+
const METHOD_NAME$M = "function.commit.commitAssistantMessageForce";
|
|
19979
20536
|
/**
|
|
19980
20537
|
* Function implementation
|
|
19981
20538
|
*/
|
|
19982
20539
|
const commitAssistantMessageForceInternal = beginContext(async (content, clientId) => {
|
|
19983
20540
|
// Log the commit attempt if enabled
|
|
19984
20541
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
19985
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20542
|
+
swarm$1.loggerService.log(METHOD_NAME$M, {
|
|
19986
20543
|
content,
|
|
19987
20544
|
clientId,
|
|
19988
20545
|
});
|
|
19989
20546
|
// Validate the session exists and retrieve the associated swarm
|
|
19990
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20547
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$M);
|
|
19991
20548
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
19992
20549
|
// Validate the swarm configuration
|
|
19993
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20550
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$M);
|
|
19994
20551
|
// Commit the assistant message via SessionPublicService without agent checks
|
|
19995
|
-
await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$
|
|
20552
|
+
await swarm$1.sessionPublicService.commitAssistantMessage(content, METHOD_NAME$M, clientId, swarmName);
|
|
19996
20553
|
});
|
|
19997
20554
|
/**
|
|
19998
20555
|
* Forcefully commits an assistant-generated message to a session in the swarm system, without checking the active agent.
|
|
@@ -20013,26 +20570,26 @@ async function commitAssistantMessageForce(content, clientId) {
|
|
|
20013
20570
|
}
|
|
20014
20571
|
|
|
20015
20572
|
/** @private Constant defining the method name for logging and validation context*/
|
|
20016
|
-
const METHOD_NAME$
|
|
20573
|
+
const METHOD_NAME$L = "function.commit.cancelOutput";
|
|
20017
20574
|
/**
|
|
20018
20575
|
* Function implementation
|
|
20019
20576
|
*/
|
|
20020
20577
|
const cancelOutputInternal = beginContext(async (clientId, agentName) => {
|
|
20021
20578
|
// Log the cancellation attempt if enabled
|
|
20022
20579
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20023
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20580
|
+
swarm$1.loggerService.log(METHOD_NAME$L, {
|
|
20024
20581
|
clientId,
|
|
20025
20582
|
agentName,
|
|
20026
20583
|
});
|
|
20027
20584
|
// Validate the agent exists
|
|
20028
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
20585
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$L);
|
|
20029
20586
|
// Validate the session exists and retrieve the associated swarm
|
|
20030
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20587
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$L);
|
|
20031
20588
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
20032
20589
|
// Validate the swarm configuration
|
|
20033
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20590
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$L);
|
|
20034
20591
|
// Check if the current agent matches the provided agent
|
|
20035
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
20592
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$L, clientId, swarmName);
|
|
20036
20593
|
if (currentAgentName !== agentName) {
|
|
20037
20594
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20038
20595
|
swarm$1.loggerService.log('function "cancelOutput" skipped due to the agent change', {
|
|
@@ -20043,7 +20600,7 @@ const cancelOutputInternal = beginContext(async (clientId, agentName) => {
|
|
|
20043
20600
|
return;
|
|
20044
20601
|
}
|
|
20045
20602
|
// Perform the output cancellation via SwarmPublicService
|
|
20046
|
-
await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$
|
|
20603
|
+
await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$L, clientId, swarmName);
|
|
20047
20604
|
});
|
|
20048
20605
|
/**
|
|
20049
20606
|
* Cancels the awaited output for a specific client and agent by emitting an empty string.
|
|
@@ -20062,23 +20619,23 @@ async function cancelOutput(clientId, agentName) {
|
|
|
20062
20619
|
}
|
|
20063
20620
|
|
|
20064
20621
|
/** @private Constant defining the method name for logging and validation context*/
|
|
20065
|
-
const METHOD_NAME$
|
|
20622
|
+
const METHOD_NAME$K = "function.commit.cancelOutputForce";
|
|
20066
20623
|
/**
|
|
20067
20624
|
* Function implementation
|
|
20068
20625
|
*/
|
|
20069
20626
|
const cancelOutputForceInternal = beginContext(async (clientId) => {
|
|
20070
20627
|
// Log the cancellation attempt if enabled
|
|
20071
20628
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20072
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20629
|
+
swarm$1.loggerService.log(METHOD_NAME$K, {
|
|
20073
20630
|
clientId,
|
|
20074
20631
|
});
|
|
20075
20632
|
// Validate the session exists and retrieve the associated swarm
|
|
20076
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20633
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$K);
|
|
20077
20634
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
20078
20635
|
// Validate the swarm configuration
|
|
20079
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20636
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$K);
|
|
20080
20637
|
// Perform the output cancellation via SwarmPublicService without agent checks
|
|
20081
|
-
await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$
|
|
20638
|
+
await swarm$1.swarmPublicService.cancelOutput(METHOD_NAME$K, clientId, swarmName);
|
|
20082
20639
|
});
|
|
20083
20640
|
/**
|
|
20084
20641
|
* Forcefully cancels the awaited output for a specific client by emitting an empty string, without checking the active agent.
|
|
@@ -20096,22 +20653,22 @@ async function cancelOutputForce(clientId) {
|
|
|
20096
20653
|
return await cancelOutputForceInternal(clientId);
|
|
20097
20654
|
}
|
|
20098
20655
|
|
|
20099
|
-
const METHOD_NAME$
|
|
20656
|
+
const METHOD_NAME$J = "function.commit.commitToolRequest";
|
|
20100
20657
|
/**
|
|
20101
20658
|
* Function implementation
|
|
20102
20659
|
*/
|
|
20103
20660
|
const commitToolRequestInternal = beginContext(async (request, clientId, agentName) => {
|
|
20104
20661
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20105
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20662
|
+
swarm$1.loggerService.log(METHOD_NAME$J, {
|
|
20106
20663
|
request,
|
|
20107
20664
|
clientId,
|
|
20108
20665
|
agentName,
|
|
20109
20666
|
});
|
|
20110
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
20111
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20667
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$J);
|
|
20668
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$J);
|
|
20112
20669
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
20113
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20114
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
20670
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$J);
|
|
20671
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$J, clientId, swarmName);
|
|
20115
20672
|
if (currentAgentName !== agentName) {
|
|
20116
20673
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20117
20674
|
swarm$1.loggerService.log('function "commitToolRequest" skipped due to the agent change', {
|
|
@@ -20121,7 +20678,7 @@ const commitToolRequestInternal = beginContext(async (request, clientId, agentNa
|
|
|
20121
20678
|
});
|
|
20122
20679
|
return null;
|
|
20123
20680
|
}
|
|
20124
|
-
return await swarm$1.sessionPublicService.commitToolRequest(Array.isArray(request) ? request : [request], METHOD_NAME$
|
|
20681
|
+
return await swarm$1.sessionPublicService.commitToolRequest(Array.isArray(request) ? request : [request], METHOD_NAME$J, clientId, swarmName);
|
|
20125
20682
|
});
|
|
20126
20683
|
/**
|
|
20127
20684
|
* Commits a tool request to the active agent in the swarm system.
|
|
@@ -20136,21 +20693,21 @@ async function commitToolRequest(request, clientId, agentName) {
|
|
|
20136
20693
|
return await commitToolRequestInternal(request, clientId, agentName);
|
|
20137
20694
|
}
|
|
20138
20695
|
|
|
20139
|
-
const METHOD_NAME$
|
|
20696
|
+
const METHOD_NAME$I = "function.commit.commitToolRequestForce";
|
|
20140
20697
|
/**
|
|
20141
20698
|
* Function implementation
|
|
20142
20699
|
*/
|
|
20143
20700
|
const commitToolRequestForceInternal = beginContext(async (request, clientId) => {
|
|
20144
20701
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20145
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20702
|
+
swarm$1.loggerService.log(METHOD_NAME$I, {
|
|
20146
20703
|
request,
|
|
20147
20704
|
clientId,
|
|
20148
20705
|
});
|
|
20149
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
20706
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$I);
|
|
20150
20707
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
20151
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
20708
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$I);
|
|
20152
20709
|
const requests = Array.isArray(request) ? request : [request];
|
|
20153
|
-
return await swarm$1.sessionPublicService.commitToolRequest(requests, METHOD_NAME$
|
|
20710
|
+
return await swarm$1.sessionPublicService.commitToolRequest(requests, METHOD_NAME$I, clientId, swarmName);
|
|
20154
20711
|
});
|
|
20155
20712
|
/**
|
|
20156
20713
|
* Forcefully commits a tool request to the active agent in the swarm system.
|
|
@@ -20167,18 +20724,18 @@ async function commitToolRequestForce(request, clientId) {
|
|
|
20167
20724
|
}
|
|
20168
20725
|
|
|
20169
20726
|
/** @constant {string} METHOD_NAME - The name of the method used for logging and validation*/
|
|
20170
|
-
const METHOD_NAME$
|
|
20727
|
+
const METHOD_NAME$H = "function.target.ask";
|
|
20171
20728
|
/**
|
|
20172
20729
|
* Function implementation
|
|
20173
20730
|
*/
|
|
20174
20731
|
const askInternal = beginContext(async (message, advisorName) => {
|
|
20175
20732
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20176
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20733
|
+
swarm$1.loggerService.log(METHOD_NAME$H, {
|
|
20177
20734
|
message,
|
|
20178
20735
|
advisorName,
|
|
20179
20736
|
});
|
|
20180
20737
|
const resultId = randomString();
|
|
20181
|
-
swarm$1.advisorValidationService.validate(advisorName, METHOD_NAME$
|
|
20738
|
+
swarm$1.advisorValidationService.validate(advisorName, METHOD_NAME$H);
|
|
20182
20739
|
const { getChat, callbacks } = swarm$1.advisorSchemaService.get(advisorName);
|
|
20183
20740
|
if (callbacks?.onChat) {
|
|
20184
20741
|
callbacks.onChat(message);
|
|
@@ -20221,7 +20778,7 @@ async function ask(message, advisorName) {
|
|
|
20221
20778
|
return await askInternal(message, advisorName);
|
|
20222
20779
|
}
|
|
20223
20780
|
|
|
20224
|
-
const METHOD_NAME$
|
|
20781
|
+
const METHOD_NAME$G = "function.target.json";
|
|
20225
20782
|
const MAX_ATTEMPTS = 5;
|
|
20226
20783
|
/**
|
|
20227
20784
|
* A class implementing the IOutlineHistory interface to manage a history of outline messages.
|
|
@@ -20265,12 +20822,12 @@ class OutlineHistory {
|
|
|
20265
20822
|
*/
|
|
20266
20823
|
const jsonInternal = beginContext(async (outlineName, ...params) => {
|
|
20267
20824
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20268
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20269
|
-
swarm$1.outlineValidationService.validate(outlineName, METHOD_NAME$
|
|
20825
|
+
swarm$1.loggerService.log(METHOD_NAME$G, {});
|
|
20826
|
+
swarm$1.outlineValidationService.validate(outlineName, METHOD_NAME$G);
|
|
20270
20827
|
const resultId = randomString();
|
|
20271
20828
|
const clientId = `${resultId}_outline`;
|
|
20272
20829
|
const { getOutlineHistory, completion, validations = [], maxAttempts = MAX_ATTEMPTS, format, prompt, system, callbacks: outlineCallbacks, } = swarm$1.outlineSchemaService.get(outlineName);
|
|
20273
|
-
swarm$1.completionValidationService.validate(completion, METHOD_NAME$
|
|
20830
|
+
swarm$1.completionValidationService.validate(completion, METHOD_NAME$G);
|
|
20274
20831
|
const completionSchema = swarm$1.completionSchemaService.get(completion);
|
|
20275
20832
|
const { getCompletion, flags = [], callbacks: completionCallbacks, } = completionSchema;
|
|
20276
20833
|
let errorMessage = "";
|
|
@@ -20403,7 +20960,7 @@ async function json(outlineName, ...params) {
|
|
|
20403
20960
|
return await jsonInternal(outlineName, ...params);
|
|
20404
20961
|
}
|
|
20405
20962
|
|
|
20406
|
-
const METHOD_NAME$
|
|
20963
|
+
const METHOD_NAME$F = "function.target.chat";
|
|
20407
20964
|
/**
|
|
20408
20965
|
* Internal function to process a chat completion request.
|
|
20409
20966
|
* Executes outside existing contexts using `beginContext` to ensure isolation.
|
|
@@ -20413,13 +20970,13 @@ const METHOD_NAME$E = "function.target.chat";
|
|
|
20413
20970
|
*/
|
|
20414
20971
|
const chatInternal = beginContext(async (completionName, messages) => {
|
|
20415
20972
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20416
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
20417
|
-
swarm$1.completionValidationService.validate(completionName, METHOD_NAME$
|
|
20973
|
+
swarm$1.loggerService.log(METHOD_NAME$F, {});
|
|
20974
|
+
swarm$1.completionValidationService.validate(completionName, METHOD_NAME$F);
|
|
20418
20975
|
const resultId = randomString();
|
|
20419
20976
|
const clientId = `${resultId}_chat`;
|
|
20420
20977
|
const completionSchema = swarm$1.completionSchemaService.get(completionName);
|
|
20421
20978
|
if (completionSchema.json) {
|
|
20422
|
-
throw new Error(`${METHOD_NAME$
|
|
20979
|
+
throw new Error(`${METHOD_NAME$F} completion ${completionName} should not have json=true. Use a non-JSON completion for chat.`);
|
|
20423
20980
|
}
|
|
20424
20981
|
const { getCompletion } = completionSchema;
|
|
20425
20982
|
let errorValue = null;
|
|
@@ -20459,7 +21016,7 @@ async function chat(completionName, messages) {
|
|
|
20459
21016
|
return await chatInternal(completionName, messages);
|
|
20460
21017
|
}
|
|
20461
21018
|
|
|
20462
|
-
const METHOD_NAME$
|
|
21019
|
+
const METHOD_NAME$E = "function.target.disposeConnection";
|
|
20463
21020
|
/**
|
|
20464
21021
|
* Disposes of a client session and all related resources within a swarm.
|
|
20465
21022
|
*
|
|
@@ -20472,10 +21029,10 @@ const METHOD_NAME$D = "function.target.disposeConnection";
|
|
|
20472
21029
|
* @example
|
|
20473
21030
|
* await disposeConnection("client-123", "TaskSwarm");
|
|
20474
21031
|
*/
|
|
20475
|
-
const disposeConnection = beginContext(async (clientId, swarmName, methodName = METHOD_NAME$
|
|
21032
|
+
const disposeConnection = beginContext(async (clientId, swarmName, methodName = METHOD_NAME$E) => {
|
|
20476
21033
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
20477
21034
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20478
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21035
|
+
swarm$1.loggerService.log(METHOD_NAME$E, {
|
|
20479
21036
|
clientId,
|
|
20480
21037
|
swarmName,
|
|
20481
21038
|
});
|
|
@@ -20581,7 +21138,7 @@ const disposeConnection = beginContext(async (clientId, swarmName, methodName =
|
|
|
20581
21138
|
PersistMemoryAdapter.dispose(clientId);
|
|
20582
21139
|
});
|
|
20583
21140
|
|
|
20584
|
-
const METHOD_NAME$
|
|
21141
|
+
const METHOD_NAME$D = "function.target.makeAutoDispose";
|
|
20585
21142
|
/**
|
|
20586
21143
|
* Default timeout in seconds before auto-dispose is triggered.
|
|
20587
21144
|
* @constant {number}
|
|
@@ -20608,7 +21165,7 @@ const DEFAULT_TIMEOUT = 15 * 60;
|
|
|
20608
21165
|
const makeAutoDispose = beginContext((clientId, swarmName, { timeoutSeconds = DEFAULT_TIMEOUT, onDestroy, } = {}) => {
|
|
20609
21166
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
20610
21167
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20611
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21168
|
+
swarm$1.loggerService.log(METHOD_NAME$D, {
|
|
20612
21169
|
clientId,
|
|
20613
21170
|
swarmName,
|
|
20614
21171
|
});
|
|
@@ -20641,30 +21198,30 @@ const makeAutoDispose = beginContext((clientId, swarmName, { timeoutSeconds = DE
|
|
|
20641
21198
|
};
|
|
20642
21199
|
});
|
|
20643
21200
|
|
|
20644
|
-
const METHOD_NAME$
|
|
21201
|
+
const METHOD_NAME$C = "function.target.notify";
|
|
20645
21202
|
/**
|
|
20646
21203
|
* Function implementation
|
|
20647
21204
|
*/
|
|
20648
21205
|
const notifyInternal = beginContext(async (content, clientId, agentName) => {
|
|
20649
21206
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
20650
21207
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20651
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21208
|
+
swarm$1.loggerService.log(METHOD_NAME$C, {
|
|
20652
21209
|
content,
|
|
20653
21210
|
clientId,
|
|
20654
21211
|
agentName,
|
|
20655
21212
|
});
|
|
20656
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21213
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$C);
|
|
20657
21214
|
// Check if the session mode is "makeConnection"
|
|
20658
21215
|
if (swarm$1.sessionValidationService.getSessionMode(clientId) !==
|
|
20659
21216
|
"makeConnection") {
|
|
20660
21217
|
throw new Error(`agent-swarm-kit notify session is not makeConnection clientId=${clientId}`);
|
|
20661
21218
|
}
|
|
20662
21219
|
// Validate the agent, session, and swarm
|
|
20663
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
21220
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$C);
|
|
20664
21221
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
20665
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
21222
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$C);
|
|
20666
21223
|
// Check if the specified agent is still the active agent
|
|
20667
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
21224
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$C, clientId, swarmName);
|
|
20668
21225
|
if (currentAgentName !== agentName) {
|
|
20669
21226
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20670
21227
|
swarm$1.loggerService.log('function "notify" skipped due to the agent change', {
|
|
@@ -20675,7 +21232,7 @@ const notifyInternal = beginContext(async (content, clientId, agentName) => {
|
|
|
20675
21232
|
return;
|
|
20676
21233
|
}
|
|
20677
21234
|
// Notify the content directly via the session public service
|
|
20678
|
-
return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$
|
|
21235
|
+
return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$C, clientId, swarmName);
|
|
20679
21236
|
});
|
|
20680
21237
|
/**
|
|
20681
21238
|
* Sends a notification message as output from the swarm session without executing an incoming message.
|
|
@@ -20697,18 +21254,18 @@ async function notify(content, clientId, agentName) {
|
|
|
20697
21254
|
return await notifyInternal(content, clientId, agentName);
|
|
20698
21255
|
}
|
|
20699
21256
|
|
|
20700
|
-
const METHOD_NAME$
|
|
21257
|
+
const METHOD_NAME$B = "function.target.notifyForce";
|
|
20701
21258
|
/**
|
|
20702
21259
|
* Function implementation
|
|
20703
21260
|
*/
|
|
20704
21261
|
const notifyForceInternal = beginContext(async (content, clientId) => {
|
|
20705
21262
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
20706
21263
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20707
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21264
|
+
swarm$1.loggerService.log(METHOD_NAME$B, {
|
|
20708
21265
|
content,
|
|
20709
21266
|
clientId,
|
|
20710
21267
|
});
|
|
20711
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21268
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$B);
|
|
20712
21269
|
// Check if the session mode is "makeConnection"
|
|
20713
21270
|
if (swarm$1.sessionValidationService.getSessionMode(clientId) !==
|
|
20714
21271
|
"makeConnection") {
|
|
@@ -20716,9 +21273,9 @@ const notifyForceInternal = beginContext(async (content, clientId) => {
|
|
|
20716
21273
|
}
|
|
20717
21274
|
// Validate the agent, session, and swarm
|
|
20718
21275
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
20719
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
21276
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$B);
|
|
20720
21277
|
// Notify the content directly via the session public service
|
|
20721
|
-
return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$
|
|
21278
|
+
return await swarm$1.sessionPublicService.notify(content, METHOD_NAME$B, clientId, swarmName);
|
|
20722
21279
|
});
|
|
20723
21280
|
/**
|
|
20724
21281
|
* Sends a notification message as output from the swarm session without executing an incoming message.
|
|
@@ -20739,7 +21296,7 @@ async function notifyForce(content, clientId) {
|
|
|
20739
21296
|
return await notifyForceInternal(content, clientId);
|
|
20740
21297
|
}
|
|
20741
21298
|
|
|
20742
|
-
const METHOD_NAME$
|
|
21299
|
+
const METHOD_NAME$A = "function.target.runStateless";
|
|
20743
21300
|
/**
|
|
20744
21301
|
* Function implementation
|
|
20745
21302
|
*/
|
|
@@ -20747,19 +21304,19 @@ const runStatelessInternal = beginContext(async (content, clientId, agentName) =
|
|
|
20747
21304
|
const executionId = randomString();
|
|
20748
21305
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
20749
21306
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20750
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21307
|
+
swarm$1.loggerService.log(METHOD_NAME$A, {
|
|
20751
21308
|
content,
|
|
20752
21309
|
clientId,
|
|
20753
21310
|
agentName,
|
|
20754
21311
|
executionId,
|
|
20755
21312
|
});
|
|
20756
21313
|
// Validate the agent, session, and swarm
|
|
20757
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
20758
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21314
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$A);
|
|
21315
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$A);
|
|
20759
21316
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
20760
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
21317
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$A);
|
|
20761
21318
|
// Check if the specified agent is still the active agent
|
|
20762
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
21319
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$A, clientId, swarmName);
|
|
20763
21320
|
if (currentAgentName !== agentName) {
|
|
20764
21321
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20765
21322
|
swarm$1.loggerService.log('function "runStateless" skipped due to the agent change', {
|
|
@@ -20785,7 +21342,7 @@ const runStatelessInternal = beginContext(async (content, clientId, agentName) =
|
|
|
20785
21342
|
errorValue = error;
|
|
20786
21343
|
}
|
|
20787
21344
|
});
|
|
20788
|
-
result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$
|
|
21345
|
+
result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$A, clientId, swarmName);
|
|
20789
21346
|
unError();
|
|
20790
21347
|
if (errorValue) {
|
|
20791
21348
|
throw errorValue;
|
|
@@ -20831,7 +21388,7 @@ async function runStateless(content, clientId, agentName) {
|
|
|
20831
21388
|
return await runStatelessInternal(content, clientId, agentName);
|
|
20832
21389
|
}
|
|
20833
21390
|
|
|
20834
|
-
const METHOD_NAME$
|
|
21391
|
+
const METHOD_NAME$z = "function.target.runStatelessForce";
|
|
20835
21392
|
/**
|
|
20836
21393
|
* Function implementation
|
|
20837
21394
|
*/
|
|
@@ -20839,15 +21396,15 @@ const runStatelessForceInternal = beginContext(async (content, clientId) => {
|
|
|
20839
21396
|
const executionId = randomString();
|
|
20840
21397
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
20841
21398
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20842
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21399
|
+
swarm$1.loggerService.log(METHOD_NAME$z, {
|
|
20843
21400
|
content,
|
|
20844
21401
|
clientId,
|
|
20845
21402
|
executionId,
|
|
20846
21403
|
});
|
|
20847
21404
|
// Validate the session and swarm
|
|
20848
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21405
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$z);
|
|
20849
21406
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
20850
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
21407
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$z);
|
|
20851
21408
|
// Execute the command statelessly within an execution context with performance tracking
|
|
20852
21409
|
return ExecutionContextService.runInContext(async () => {
|
|
20853
21410
|
let isFinished = false;
|
|
@@ -20861,7 +21418,7 @@ const runStatelessForceInternal = beginContext(async (content, clientId) => {
|
|
|
20861
21418
|
errorValue = error;
|
|
20862
21419
|
}
|
|
20863
21420
|
});
|
|
20864
|
-
result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$
|
|
21421
|
+
result = await swarm$1.sessionPublicService.run(content, METHOD_NAME$z, clientId, swarmName);
|
|
20865
21422
|
unError();
|
|
20866
21423
|
if (errorValue) {
|
|
20867
21424
|
throw errorValue;
|
|
@@ -20912,7 +21469,7 @@ const SCHEDULED_DELAY$1 = 1000;
|
|
|
20912
21469
|
* @constant {number}
|
|
20913
21470
|
*/
|
|
20914
21471
|
const RATE_DELAY = 10000;
|
|
20915
|
-
const METHOD_NAME$
|
|
21472
|
+
const METHOD_NAME$y = "function.target.makeConnection";
|
|
20916
21473
|
/**
|
|
20917
21474
|
* Internal implementation of the connection factory for a client to a swarm.
|
|
20918
21475
|
*
|
|
@@ -20923,21 +21480,21 @@ const METHOD_NAME$x = "function.target.makeConnection";
|
|
|
20923
21480
|
const makeConnectionInternal = (connector, clientId, swarmName) => {
|
|
20924
21481
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
20925
21482
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
20926
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21483
|
+
swarm$1.loggerService.log(METHOD_NAME$y, {
|
|
20927
21484
|
clientId,
|
|
20928
21485
|
swarmName,
|
|
20929
21486
|
});
|
|
20930
21487
|
// Validate the swarm and initialize the session
|
|
20931
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
21488
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$y);
|
|
20932
21489
|
swarm$1.sessionValidationService.addSession(clientId, swarmName, "makeConnection");
|
|
20933
21490
|
// Create a queued send function using the session public service
|
|
20934
|
-
const send = queued(swarm$1.sessionPublicService.connect(connector, METHOD_NAME$
|
|
21491
|
+
const send = queued(swarm$1.sessionPublicService.connect(connector, METHOD_NAME$y, clientId, swarmName));
|
|
20935
21492
|
// Return a wrapped send function with validation and agent context
|
|
20936
21493
|
return (async (outgoing) => {
|
|
20937
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21494
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$y);
|
|
20938
21495
|
return await send({
|
|
20939
21496
|
data: outgoing,
|
|
20940
|
-
agentName: await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
21497
|
+
agentName: await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$y, clientId, swarmName),
|
|
20941
21498
|
clientId,
|
|
20942
21499
|
});
|
|
20943
21500
|
});
|
|
@@ -21011,13 +21568,13 @@ makeConnection.scheduled = (connector, clientId, swarmName, { delay = SCHEDULED_
|
|
|
21011
21568
|
await online();
|
|
21012
21569
|
if (payload) {
|
|
21013
21570
|
return await PayloadContextService.runInContext(async () => {
|
|
21014
|
-
await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$
|
|
21571
|
+
await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$y, clientId, swarmName);
|
|
21015
21572
|
}, {
|
|
21016
21573
|
clientId,
|
|
21017
21574
|
payload,
|
|
21018
21575
|
});
|
|
21019
21576
|
}
|
|
21020
|
-
await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$
|
|
21577
|
+
await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$y, clientId, swarmName);
|
|
21021
21578
|
}),
|
|
21022
21579
|
delay,
|
|
21023
21580
|
});
|
|
@@ -21075,7 +21632,7 @@ makeConnection.rate = (connector, clientId, swarmName, { delay = RATE_DELAY } =
|
|
|
21075
21632
|
};
|
|
21076
21633
|
};
|
|
21077
21634
|
|
|
21078
|
-
const METHOD_NAME$
|
|
21635
|
+
const METHOD_NAME$x = "function.target.complete";
|
|
21079
21636
|
/**
|
|
21080
21637
|
* Creates a complete function with time-to-live (TTL) and queuing capabilities.
|
|
21081
21638
|
*
|
|
@@ -21120,7 +21677,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
|
|
|
21120
21677
|
const executionId = randomString();
|
|
21121
21678
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
21122
21679
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21123
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21680
|
+
swarm$1.loggerService.log(METHOD_NAME$x, {
|
|
21124
21681
|
content,
|
|
21125
21682
|
clientId,
|
|
21126
21683
|
executionId,
|
|
@@ -21138,7 +21695,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
|
|
|
21138
21695
|
swarm$1.navigationValidationService.beginMonit(clientId, swarmName);
|
|
21139
21696
|
try {
|
|
21140
21697
|
swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
|
|
21141
|
-
const result = await run(METHOD_NAME$
|
|
21698
|
+
const result = await run(METHOD_NAME$x, content);
|
|
21142
21699
|
isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
|
|
21143
21700
|
swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
|
|
21144
21701
|
return result;
|
|
@@ -21169,7 +21726,7 @@ const complete = beginContext(async (content, clientId, swarmName, payload = nul
|
|
|
21169
21726
|
* @constant {number}
|
|
21170
21727
|
*/
|
|
21171
21728
|
const SCHEDULED_DELAY = 1000;
|
|
21172
|
-
const METHOD_NAME$
|
|
21729
|
+
const METHOD_NAME$w = "function.target.session";
|
|
21173
21730
|
/**
|
|
21174
21731
|
* Internal implementation of the session factory for a client and swarm.
|
|
21175
21732
|
*
|
|
@@ -21181,23 +21738,33 @@ const sessionInternal = (clientId, swarmName, { onDispose = () => { } } = {}) =>
|
|
|
21181
21738
|
const executionId = randomString();
|
|
21182
21739
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
21183
21740
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21184
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21741
|
+
swarm$1.loggerService.log(METHOD_NAME$w, {
|
|
21185
21742
|
clientId,
|
|
21186
21743
|
swarmName,
|
|
21187
21744
|
executionId,
|
|
21188
21745
|
});
|
|
21189
21746
|
// Validate the swarm and initialize the session
|
|
21190
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
21747
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$w);
|
|
21191
21748
|
swarm$1.sessionValidationService.addSession(clientId, swarmName, "session");
|
|
21192
21749
|
const complete = queued(async (content) => {
|
|
21193
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21750
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$w);
|
|
21194
21751
|
return ExecutionContextService.runInContext(async () => {
|
|
21195
21752
|
let isFinished = false;
|
|
21196
21753
|
swarm$1.perfService.startExecution(executionId, clientId, content.length);
|
|
21197
21754
|
swarm$1.navigationValidationService.beginMonit(clientId, swarmName);
|
|
21198
21755
|
try {
|
|
21199
21756
|
swarm$1.busService.commitExecutionBegin(clientId, { swarmName });
|
|
21200
|
-
|
|
21757
|
+
let errorValue = null;
|
|
21758
|
+
const unError = errorSubject.subscribe(([errorClientId, error]) => {
|
|
21759
|
+
if (clientId === errorClientId) {
|
|
21760
|
+
errorValue = error;
|
|
21761
|
+
}
|
|
21762
|
+
});
|
|
21763
|
+
const result = await swarm$1.sessionPublicService.execute(content, "user", METHOD_NAME$w, clientId, swarmName);
|
|
21764
|
+
unError();
|
|
21765
|
+
if (errorValue) {
|
|
21766
|
+
throw errorValue;
|
|
21767
|
+
}
|
|
21201
21768
|
isFinished = swarm$1.perfService.endExecution(executionId, clientId, result.length);
|
|
21202
21769
|
swarm$1.busService.commitExecutionEnd(clientId, { swarmName });
|
|
21203
21770
|
return result;
|
|
@@ -21219,7 +21786,7 @@ const sessionInternal = (clientId, swarmName, { onDispose = () => { } } = {}) =>
|
|
|
21219
21786
|
return await complete(content);
|
|
21220
21787
|
}),
|
|
21221
21788
|
dispose: async () => {
|
|
21222
|
-
await disposeConnection(clientId, swarmName, METHOD_NAME$
|
|
21789
|
+
await disposeConnection(clientId, swarmName, METHOD_NAME$w);
|
|
21223
21790
|
await onDispose();
|
|
21224
21791
|
},
|
|
21225
21792
|
};
|
|
@@ -21312,13 +21879,13 @@ session.scheduled = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose }
|
|
|
21312
21879
|
await online();
|
|
21313
21880
|
if (payload) {
|
|
21314
21881
|
return await PayloadContextService.runInContext(async () => {
|
|
21315
|
-
return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$
|
|
21882
|
+
return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$w, clientId, swarmName);
|
|
21316
21883
|
}, {
|
|
21317
21884
|
clientId,
|
|
21318
21885
|
payload,
|
|
21319
21886
|
});
|
|
21320
21887
|
}
|
|
21321
|
-
return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$
|
|
21888
|
+
return await swarm$1.sessionPublicService.commitUserMessage(content, "user", METHOD_NAME$w, clientId, swarmName);
|
|
21322
21889
|
}),
|
|
21323
21890
|
delay,
|
|
21324
21891
|
});
|
|
@@ -21402,13 +21969,13 @@ session.rate = (clientId, swarmName, { delay = SCHEDULED_DELAY, onDispose } = {}
|
|
|
21402
21969
|
* Method name for the scope operation.
|
|
21403
21970
|
* @private
|
|
21404
21971
|
*/
|
|
21405
|
-
const METHOD_NAME$
|
|
21972
|
+
const METHOD_NAME$v = "function.target.fork";
|
|
21406
21973
|
/**
|
|
21407
21974
|
* Function implementation
|
|
21408
21975
|
*/
|
|
21409
21976
|
const forkInternal = beginContext(async (runFn, { clientId, swarmName, onError }) => {
|
|
21410
21977
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21411
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
21978
|
+
swarm$1.loggerService.log(METHOD_NAME$v, {
|
|
21412
21979
|
clientId,
|
|
21413
21980
|
swarmName,
|
|
21414
21981
|
});
|
|
@@ -21416,9 +21983,9 @@ const forkInternal = beginContext(async (runFn, { clientId, swarmName, onError }
|
|
|
21416
21983
|
throw new Error(`agent-swarm scope Session already exists for clientId=${clientId}`);
|
|
21417
21984
|
}
|
|
21418
21985
|
swarm$1.sessionValidationService.addSession(clientId, swarmName, "scope");
|
|
21419
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
21420
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21421
|
-
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
21986
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$v);
|
|
21987
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$v);
|
|
21988
|
+
const agentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$v, clientId, swarmName);
|
|
21422
21989
|
let result = null;
|
|
21423
21990
|
try {
|
|
21424
21991
|
result = (await runFn(clientId, agentName));
|
|
@@ -21428,7 +21995,7 @@ const forkInternal = beginContext(async (runFn, { clientId, swarmName, onError }
|
|
|
21428
21995
|
onError && onError(error);
|
|
21429
21996
|
}
|
|
21430
21997
|
finally {
|
|
21431
|
-
await disposeConnection(clientId, swarmName, METHOD_NAME$
|
|
21998
|
+
await disposeConnection(clientId, swarmName, METHOD_NAME$v);
|
|
21432
21999
|
}
|
|
21433
22000
|
return result;
|
|
21434
22001
|
});
|
|
@@ -21453,12 +22020,12 @@ async function fork(runFn, options) {
|
|
|
21453
22020
|
* Method name for the scope operation.
|
|
21454
22021
|
* @private
|
|
21455
22022
|
*/
|
|
21456
|
-
const METHOD_NAME$
|
|
22023
|
+
const METHOD_NAME$u = "function.target.scope";
|
|
21457
22024
|
/**
|
|
21458
22025
|
* Function implementation
|
|
21459
22026
|
*/
|
|
21460
22027
|
const scopeInternal = beginContext(async (runFn, { agentSchemaService = swarm$1.agentSchemaService.registry, completionSchemaService = swarm$1.completionSchemaService.registry, computeSchemaService = swarm$1.computeSchemaService.registry, embeddingSchemaService = swarm$1.embeddingSchemaService.registry, mcpSchemaService = swarm$1.mcpSchemaService.registry, pipelineSchemaService = swarm$1.pipelineSchemaService.registry, policySchemaService = swarm$1.policySchemaService.registry, stateSchemaService = swarm$1.stateSchemaService.registry, storageSchemaService = swarm$1.storageSchemaService.registry, swarmSchemaService = swarm$1.swarmSchemaService.registry, toolSchemaService = swarm$1.toolSchemaService.registry, advisorSchemaService = swarm$1.advisorSchemaService.registry, outlineSchemaService = swarm$1.outlineSchemaService.registry, } = {}) => {
|
|
21461
|
-
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$
|
|
22028
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG && swarm$1.loggerService.log(METHOD_NAME$u);
|
|
21462
22029
|
return await SchemaContextService.runInContext(runFn, {
|
|
21463
22030
|
registry: {
|
|
21464
22031
|
agentSchemaService,
|
|
@@ -21497,20 +22064,20 @@ async function scope(runFn, options) {
|
|
|
21497
22064
|
* Method name for the startPipeline operation.
|
|
21498
22065
|
* @private
|
|
21499
22066
|
*/
|
|
21500
|
-
const METHOD_NAME$
|
|
22067
|
+
const METHOD_NAME$t = "function.target.startPipeline";
|
|
21501
22068
|
/**
|
|
21502
22069
|
* Function implementation
|
|
21503
22070
|
*/
|
|
21504
22071
|
const startPipelineInternal = beginContext(async (clientId, pipelineName, agentName, payload = {}) => {
|
|
21505
22072
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21506
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22073
|
+
swarm$1.loggerService.log(METHOD_NAME$t, {
|
|
21507
22074
|
clientId,
|
|
21508
22075
|
pipelineName,
|
|
21509
22076
|
});
|
|
21510
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21511
|
-
swarm$1.pipelineValidationService.validate(pipelineName, METHOD_NAME$
|
|
21512
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
21513
|
-
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$
|
|
22077
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$t);
|
|
22078
|
+
swarm$1.pipelineValidationService.validate(pipelineName, METHOD_NAME$t);
|
|
22079
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$t);
|
|
22080
|
+
const currentAgentName = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$t, clientId, await swarm$1.sessionValidationService.getSwarm(clientId));
|
|
21514
22081
|
if (currentAgentName !== agentName) {
|
|
21515
22082
|
await changeToAgent(agentName, clientId);
|
|
21516
22083
|
}
|
|
@@ -21555,13 +22122,13 @@ async function startPipeline(clientId, pipelineName, agentName, payload) {
|
|
|
21555
22122
|
}
|
|
21556
22123
|
|
|
21557
22124
|
/** @private Constant defining the method name for logging purposes*/
|
|
21558
|
-
const METHOD_NAME$
|
|
22125
|
+
const METHOD_NAME$s = "function.common.hasSession";
|
|
21559
22126
|
/**
|
|
21560
22127
|
* Function implementation
|
|
21561
22128
|
*/
|
|
21562
22129
|
const hasSessionInternal = (clientId) => {
|
|
21563
22130
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21564
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22131
|
+
swarm$1.loggerService.log(METHOD_NAME$s, { clientId });
|
|
21565
22132
|
return swarm$1.sessionValidationService.hasSession(clientId);
|
|
21566
22133
|
};
|
|
21567
22134
|
/**
|
|
@@ -21576,22 +22143,22 @@ function hasSession(clientId) {
|
|
|
21576
22143
|
return hasSessionInternal(clientId);
|
|
21577
22144
|
}
|
|
21578
22145
|
|
|
21579
|
-
const METHOD_NAME$
|
|
22146
|
+
const METHOD_NAME$r = "function.common.getCheckBusy";
|
|
21580
22147
|
/**
|
|
21581
22148
|
* Function implementation
|
|
21582
22149
|
*/
|
|
21583
22150
|
const getCheckBusyInternal = beginContext(async (clientId) => {
|
|
21584
22151
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21585
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22152
|
+
swarm$1.loggerService.log(METHOD_NAME$r, {
|
|
21586
22153
|
clientId,
|
|
21587
22154
|
});
|
|
21588
22155
|
if (!swarm$1.sessionValidationService.hasSession(clientId)) {
|
|
21589
22156
|
return false;
|
|
21590
22157
|
}
|
|
21591
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
22158
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$r);
|
|
21592
22159
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
21593
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
21594
|
-
return await swarm$1.swarmPublicService.getCheckBusy(METHOD_NAME$
|
|
22160
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$r);
|
|
22161
|
+
return await swarm$1.swarmPublicService.getCheckBusy(METHOD_NAME$r, clientId, swarmName);
|
|
21595
22162
|
});
|
|
21596
22163
|
/**
|
|
21597
22164
|
* Checks if the swarm associated with the given client ID is currently busy.
|
|
@@ -21602,20 +22169,20 @@ async function getCheckBusy(clientId) {
|
|
|
21602
22169
|
return await getCheckBusyInternal(clientId);
|
|
21603
22170
|
}
|
|
21604
22171
|
|
|
21605
|
-
const METHOD_NAME$
|
|
22172
|
+
const METHOD_NAME$q = "function.common.getAgentHistory";
|
|
21606
22173
|
/**
|
|
21607
22174
|
* Function implementation
|
|
21608
22175
|
*/
|
|
21609
22176
|
const getAgentHistoryInternal = beginContext(async (clientId, agentName) => {
|
|
21610
22177
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
21611
22178
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21612
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22179
|
+
swarm$1.loggerService.log(METHOD_NAME$q, {
|
|
21613
22180
|
clientId,
|
|
21614
22181
|
agentName,
|
|
21615
22182
|
});
|
|
21616
22183
|
// Validate the session and agent to ensure they exist and are accessible
|
|
21617
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
21618
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
22184
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$q);
|
|
22185
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$q);
|
|
21619
22186
|
// Retrieve the agent's prompt configuration from the agent schema service
|
|
21620
22187
|
const { prompt: upperPrompt } = swarm$1.agentSchemaService.get(agentName);
|
|
21621
22188
|
const prompt = upperPrompt
|
|
@@ -21624,7 +22191,7 @@ const getAgentHistoryInternal = beginContext(async (clientId, agentName) => {
|
|
|
21624
22191
|
: await upperPrompt(clientId, agentName)
|
|
21625
22192
|
: "";
|
|
21626
22193
|
// Fetch the agent's history using the prompt and rescue tweaks via the history public service
|
|
21627
|
-
const history = await swarm$1.historyPublicService.toArrayForAgent(prompt, METHOD_NAME$
|
|
22194
|
+
const history = await swarm$1.historyPublicService.toArrayForAgent(prompt, METHOD_NAME$q, clientId, agentName);
|
|
21628
22195
|
// Return a shallow copy of the history array
|
|
21629
22196
|
return [...history];
|
|
21630
22197
|
});
|
|
@@ -21647,17 +22214,17 @@ async function getAgentHistory(clientId, agentName) {
|
|
|
21647
22214
|
return await getAgentHistoryInternal(clientId, agentName);
|
|
21648
22215
|
}
|
|
21649
22216
|
|
|
21650
|
-
const METHOD_NAME$
|
|
22217
|
+
const METHOD_NAME$p = "function.common.getSessionMode";
|
|
21651
22218
|
const getSessionModeInternal = beginContext(async (clientId) => {
|
|
21652
22219
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
21653
22220
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21654
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22221
|
+
swarm$1.loggerService.log(METHOD_NAME$p, {
|
|
21655
22222
|
clientId,
|
|
21656
22223
|
});
|
|
21657
22224
|
// Validate the session and swarm to ensure they exist and are accessible
|
|
21658
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
22225
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$p);
|
|
21659
22226
|
const swarmName = swarm$1.sessionValidationService.getSwarm(clientId);
|
|
21660
|
-
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$
|
|
22227
|
+
swarm$1.swarmValidationService.validate(swarmName, METHOD_NAME$p);
|
|
21661
22228
|
// Retrieve the session mode from the session validation service
|
|
21662
22229
|
return swarm$1.sessionValidationService.getSessionMode(clientId);
|
|
21663
22230
|
});
|
|
@@ -21679,14 +22246,14 @@ async function getSessionMode(clientId) {
|
|
|
21679
22246
|
return await getSessionModeInternal(clientId);
|
|
21680
22247
|
}
|
|
21681
22248
|
|
|
21682
|
-
const METHOD_NAME$
|
|
22249
|
+
const METHOD_NAME$o = "function.common.getSessionContext";
|
|
21683
22250
|
/**
|
|
21684
22251
|
* Function implementation
|
|
21685
22252
|
*/
|
|
21686
22253
|
const getSessionContextInternal = async () => {
|
|
21687
22254
|
// Log the operation if logging is enabled in GLOBAL_CONFIG
|
|
21688
22255
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21689
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22256
|
+
swarm$1.loggerService.log(METHOD_NAME$o);
|
|
21690
22257
|
// Determine the method context, if active
|
|
21691
22258
|
const methodContext = MethodContextService.hasContext()
|
|
21692
22259
|
? swarm$1.methodContextService.context
|
|
@@ -21725,17 +22292,17 @@ async function getSessionContext() {
|
|
|
21725
22292
|
* @private Constant defining the method name for logging purposes.
|
|
21726
22293
|
* Used as an identifier in log messages to track calls to `getNavigationRoute`.
|
|
21727
22294
|
*/
|
|
21728
|
-
const METHOD_NAME$
|
|
22295
|
+
const METHOD_NAME$n = "function.common.getNavigationRoute";
|
|
21729
22296
|
/**
|
|
21730
22297
|
* Function implementation
|
|
21731
22298
|
*/
|
|
21732
22299
|
const getNavigationRouteInternal = (clientId, swarmName) => {
|
|
21733
22300
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21734
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22301
|
+
swarm$1.loggerService.log(METHOD_NAME$n, {
|
|
21735
22302
|
clientId,
|
|
21736
22303
|
swarmName,
|
|
21737
22304
|
});
|
|
21738
|
-
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$
|
|
22305
|
+
swarm$1.sessionValidationService.validate(clientId, METHOD_NAME$n);
|
|
21739
22306
|
return swarm$1.navigationValidationService.getNavigationRoute(clientId, swarmName);
|
|
21740
22307
|
};
|
|
21741
22308
|
/**
|
|
@@ -21753,7 +22320,7 @@ function getNavigationRoute(clientId, swarmName) {
|
|
|
21753
22320
|
* Provides a utility to retrieve the model-facing name of a tool for a given agent and client context.
|
|
21754
22321
|
* Validates tool and agent existence, logs the operation if enabled, and supports both static and dynamic tool name resolution.
|
|
21755
22322
|
*/
|
|
21756
|
-
const METHOD_NAME$
|
|
22323
|
+
const METHOD_NAME$m = "function.common.getToolNameForModel";
|
|
21757
22324
|
/**
|
|
21758
22325
|
* Internal implementation for resolving the model-facing tool name.
|
|
21759
22326
|
* Validates the tool and agent, logs the operation, and invokes the tool schema's function property if dynamic.
|
|
@@ -21762,13 +22329,13 @@ const METHOD_NAME$l = "function.common.getToolNameForModel";
|
|
|
21762
22329
|
*/
|
|
21763
22330
|
const getToolNameForModelInternal = beginContext(async (toolName, clientId, agentName) => {
|
|
21764
22331
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21765
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22332
|
+
swarm$1.loggerService.log(METHOD_NAME$m, {
|
|
21766
22333
|
toolName,
|
|
21767
22334
|
clientId,
|
|
21768
22335
|
agentName,
|
|
21769
22336
|
});
|
|
21770
|
-
swarm$1.toolValidationService.validate(toolName, METHOD_NAME$
|
|
21771
|
-
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$
|
|
22337
|
+
swarm$1.toolValidationService.validate(toolName, METHOD_NAME$m);
|
|
22338
|
+
swarm$1.agentValidationService.validate(agentName, METHOD_NAME$m);
|
|
21772
22339
|
const { function: fn } = swarm$1.toolSchemaService.get(toolName);
|
|
21773
22340
|
if (typeof fn === "function") {
|
|
21774
22341
|
const { name } = await fn(clientId, agentName);
|
|
@@ -21791,18 +22358,18 @@ async function getToolNameForModel(toolName, clientId, agentName) {
|
|
|
21791
22358
|
return await getToolNameForModelInternal(toolName, clientId, agentName);
|
|
21792
22359
|
}
|
|
21793
22360
|
|
|
21794
|
-
const METHOD_NAME$
|
|
22361
|
+
const METHOD_NAME$l = "function.history.getUserHistory";
|
|
21795
22362
|
/**
|
|
21796
22363
|
* Function implementation
|
|
21797
22364
|
*/
|
|
21798
22365
|
const getUserHistoryInternal = beginContext(async (clientId) => {
|
|
21799
22366
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
21800
22367
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21801
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22368
|
+
swarm$1.loggerService.log(METHOD_NAME$l, {
|
|
21802
22369
|
clientId,
|
|
21803
22370
|
});
|
|
21804
22371
|
// Fetch raw history and filter for user role and mode
|
|
21805
|
-
const history = await getRawHistoryInternal(clientId, METHOD_NAME$
|
|
22372
|
+
const history = await getRawHistoryInternal(clientId, METHOD_NAME$l);
|
|
21806
22373
|
return history.filter(({ role, mode }) => role === "user" && mode === "user");
|
|
21807
22374
|
});
|
|
21808
22375
|
/**
|
|
@@ -21823,18 +22390,18 @@ async function getUserHistory(clientId) {
|
|
|
21823
22390
|
return await getUserHistoryInternal(clientId);
|
|
21824
22391
|
}
|
|
21825
22392
|
|
|
21826
|
-
const METHOD_NAME$
|
|
22393
|
+
const METHOD_NAME$k = "function.history.getAssistantHistory";
|
|
21827
22394
|
/**
|
|
21828
22395
|
* Function implementation
|
|
21829
22396
|
*/
|
|
21830
22397
|
const getAssistantHistoryInternal = beginContext(async (clientId) => {
|
|
21831
22398
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
21832
22399
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21833
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22400
|
+
swarm$1.loggerService.log(METHOD_NAME$k, {
|
|
21834
22401
|
clientId,
|
|
21835
22402
|
});
|
|
21836
22403
|
// Fetch raw history and filter for assistant role
|
|
21837
|
-
const history = await getRawHistoryInternal(clientId, METHOD_NAME$
|
|
22404
|
+
const history = await getRawHistoryInternal(clientId, METHOD_NAME$k);
|
|
21838
22405
|
return history.filter(({ role }) => role === "assistant");
|
|
21839
22406
|
});
|
|
21840
22407
|
/**
|
|
@@ -21855,18 +22422,18 @@ async function getAssistantHistory(clientId) {
|
|
|
21855
22422
|
return await getAssistantHistoryInternal(clientId);
|
|
21856
22423
|
}
|
|
21857
22424
|
|
|
21858
|
-
const METHOD_NAME$
|
|
22425
|
+
const METHOD_NAME$j = "function.history.getLastAssistantMessage";
|
|
21859
22426
|
/**
|
|
21860
22427
|
* Function implementation
|
|
21861
22428
|
*/
|
|
21862
22429
|
const getLastAssistantMessageInternal = beginContext(async (clientId) => {
|
|
21863
22430
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
21864
22431
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21865
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22432
|
+
swarm$1.loggerService.log(METHOD_NAME$j, {
|
|
21866
22433
|
clientId,
|
|
21867
22434
|
});
|
|
21868
22435
|
// Fetch raw history and find the last assistant message
|
|
21869
|
-
const history = await getRawHistoryInternal(clientId, METHOD_NAME$
|
|
22436
|
+
const history = await getRawHistoryInternal(clientId, METHOD_NAME$j);
|
|
21870
22437
|
const last = history.findLast(({ role }) => role === "assistant");
|
|
21871
22438
|
return last?.content ? last.content : null;
|
|
21872
22439
|
});
|
|
@@ -21888,18 +22455,18 @@ async function getLastAssistantMessage(clientId) {
|
|
|
21888
22455
|
return await getLastAssistantMessageInternal(clientId);
|
|
21889
22456
|
}
|
|
21890
22457
|
|
|
21891
|
-
const METHOD_NAME$
|
|
22458
|
+
const METHOD_NAME$i = "function.history.getLastSystemMessage";
|
|
21892
22459
|
/**
|
|
21893
22460
|
* Function implementation
|
|
21894
22461
|
*/
|
|
21895
22462
|
const getLastSystemMessageInternal = beginContext(async (clientId) => {
|
|
21896
22463
|
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
21897
22464
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21898
|
-
swarm$1.loggerService.log(METHOD_NAME$
|
|
22465
|
+
swarm$1.loggerService.log(METHOD_NAME$i, {
|
|
21899
22466
|
clientId,
|
|
21900
22467
|
});
|
|
21901
22468
|
// Fetch raw history and find the last system message
|
|
21902
|
-
const history = await getRawHistoryInternal(clientId, METHOD_NAME$
|
|
22469
|
+
const history = await getRawHistoryInternal(clientId, METHOD_NAME$i);
|
|
21903
22470
|
const last = history.findLast(({ role }) => role === "system");
|
|
21904
22471
|
return last ? last.content : null;
|
|
21905
22472
|
});
|
|
@@ -21921,6 +22488,39 @@ async function getLastSystemMessage(clientId) {
|
|
|
21921
22488
|
return await getLastSystemMessageInternal(clientId);
|
|
21922
22489
|
}
|
|
21923
22490
|
|
|
22491
|
+
const METHOD_NAME$h = "function.history.getLastToolMessage";
|
|
22492
|
+
/**
|
|
22493
|
+
* Function implementation
|
|
22494
|
+
*/
|
|
22495
|
+
const getLastToolMessageInternal = beginContext(async (clientId) => {
|
|
22496
|
+
// Log the operation details if logging is enabled in GLOBAL_CONFIG
|
|
22497
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
22498
|
+
swarm$1.loggerService.log(METHOD_NAME$h, {
|
|
22499
|
+
clientId,
|
|
22500
|
+
});
|
|
22501
|
+
// Fetch raw history and find the last tool message
|
|
22502
|
+
const history = await getRawHistoryInternal(clientId, METHOD_NAME$h);
|
|
22503
|
+
const last = history.findLast(({ role }) => role === "tool");
|
|
22504
|
+
return last?.content ? last.content : null;
|
|
22505
|
+
});
|
|
22506
|
+
/**
|
|
22507
|
+
* Retrieves the content of the most recent tool message from a client's session history.
|
|
22508
|
+
*
|
|
22509
|
+
* This function fetches the raw history for a specified client using `getRawHistory` and finds the last entry where the role is "tool".
|
|
22510
|
+
* It is wrapped in `beginContext` for a clean execution environment and logs the operation if enabled via `GLOBAL_CONFIG`. The result is the content
|
|
22511
|
+
* of the last tool message as a string, or `null` if no tool message exists in the history.
|
|
22512
|
+
*
|
|
22513
|
+
*
|
|
22514
|
+
* @param {string} clientId - The unique identifier of the client session.
|
|
22515
|
+
* @throws {Error} If `getRawHistory` fails due to session validation or history retrieval issues.
|
|
22516
|
+
* @example
|
|
22517
|
+
* const lastMessage = await getLastToolMessage("client-123");
|
|
22518
|
+
* console.log(lastMessage); // Outputs the last tool message or null
|
|
22519
|
+
*/
|
|
22520
|
+
async function getLastToolMessage(clientId) {
|
|
22521
|
+
return await getLastToolMessageInternal(clientId);
|
|
22522
|
+
}
|
|
22523
|
+
|
|
21924
22524
|
const METHOD_NAME$g = "function.dump.getAgent";
|
|
21925
22525
|
/**
|
|
21926
22526
|
* Retrieves an agent schema by its name from the swarm's agent schema service.
|
|
@@ -21969,7 +22569,7 @@ function getCompute(computeName) {
|
|
|
21969
22569
|
return swarm$1.computeSchemaService.get(computeName);
|
|
21970
22570
|
}
|
|
21971
22571
|
|
|
21972
|
-
const METHOD_NAME$d = "function.dump.
|
|
22572
|
+
const METHOD_NAME$d = "function.dump.getEmbedding";
|
|
21973
22573
|
/**
|
|
21974
22574
|
* Retrieves an embedding schema by its name from the swarm's embedding schema service.
|
|
21975
22575
|
* Logs the operation if logging is enabled in the global configuration.
|
|
@@ -21977,7 +22577,7 @@ const METHOD_NAME$d = "function.dump.getEmbeding";
|
|
|
21977
22577
|
* @function getEmbedding
|
|
21978
22578
|
* @param {EmbeddingName} embeddingName - The name of the embedding.
|
|
21979
22579
|
*/
|
|
21980
|
-
function
|
|
22580
|
+
function getEmbedding(embeddingName) {
|
|
21981
22581
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
21982
22582
|
swarm$1.loggerService.log(METHOD_NAME$d, {
|
|
21983
22583
|
embeddingName,
|
|
@@ -22113,7 +22713,7 @@ function getAdvisor(advisorName) {
|
|
|
22113
22713
|
return swarm$1.advisorSchemaService.get(advisorName);
|
|
22114
22714
|
}
|
|
22115
22715
|
|
|
22116
|
-
const METHOD_NAME$4 = "function.event.
|
|
22716
|
+
const METHOD_NAME$4 = "function.event.event";
|
|
22117
22717
|
/**
|
|
22118
22718
|
* Set of reserved event source names that cannot be used for custom events.
|
|
22119
22719
|
* @constant {Set<EventSource>}
|
|
@@ -22218,7 +22818,16 @@ const listenEventInternal = beginContext((clientId, topicName, fn) => {
|
|
|
22218
22818
|
// Validate the client ID
|
|
22219
22819
|
validateClientId$g(clientId);
|
|
22220
22820
|
// Subscribe to the event with a queued callback
|
|
22221
|
-
return swarm$1.busService.subscribe(clientId, topicName, queued(async ({ payload }) =>
|
|
22821
|
+
return swarm$1.busService.subscribe(clientId, topicName, queued(async ({ payload }) => {
|
|
22822
|
+
try {
|
|
22823
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
22824
|
+
// as an unhandled rejection and can crash the host process.
|
|
22825
|
+
return await fn(payload);
|
|
22826
|
+
}
|
|
22827
|
+
catch (error) {
|
|
22828
|
+
console.error(`agent-swarm event listener error source=${METHOD_NAME$3} error=${getErrorMessage(error)}`);
|
|
22829
|
+
}
|
|
22830
|
+
}));
|
|
22222
22831
|
});
|
|
22223
22832
|
/**
|
|
22224
22833
|
* Subscribes to a custom event on the swarm bus service and executes a callback when the event is received.
|
|
@@ -22291,7 +22900,16 @@ const listenEventOnceInternal = beginContext((clientId, topicName, filterFn, fn)
|
|
|
22291
22900
|
// Validate the client ID
|
|
22292
22901
|
validateClientId$f(clientId);
|
|
22293
22902
|
// Subscribe to the event for one occurrence with a filter and queued callback
|
|
22294
|
-
return swarm$1.busService.once(clientId, topicName, ({ payload }) => filterFn(payload), queued(async ({ payload }) =>
|
|
22903
|
+
return swarm$1.busService.once(clientId, topicName, ({ payload }) => filterFn(payload), queued(async ({ payload }) => {
|
|
22904
|
+
try {
|
|
22905
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
22906
|
+
// as an unhandled rejection and can crash the host process.
|
|
22907
|
+
return await fn(payload);
|
|
22908
|
+
}
|
|
22909
|
+
catch (error) {
|
|
22910
|
+
console.error(`agent-swarm event listener error source=${METHOD_NAME$2} error=${getErrorMessage(error)}`);
|
|
22911
|
+
}
|
|
22912
|
+
}));
|
|
22295
22913
|
});
|
|
22296
22914
|
/**
|
|
22297
22915
|
* Subscribes to a custom event on the swarm bus service for a single occurrence, executing a callback when the event matches a filter.
|
|
@@ -22332,7 +22950,11 @@ const METHOD_NAME$1 = "function.navigate.changeToPrevAgent";
|
|
|
22332
22950
|
* @function
|
|
22333
22951
|
*/
|
|
22334
22952
|
const createChangeToPrevAgent = memoize(([clientId]) => `${clientId}`, (clientId) => queued(async (methodName, agentName, swarmName) => {
|
|
22335
|
-
|
|
22953
|
+
// Going back is legitimate by definition and naturally bounded by the
|
|
22954
|
+
// depth of the navigation stack, so the recursion route guard does not
|
|
22955
|
+
// apply here. Only a no-op transition to the current agent is skipped.
|
|
22956
|
+
const activeAgent = await swarm$1.swarmPublicService.getAgentName(METHOD_NAME$1, clientId, swarmName);
|
|
22957
|
+
if (agentName === activeAgent) {
|
|
22336
22958
|
return false;
|
|
22337
22959
|
}
|
|
22338
22960
|
// Notify all agents in the swarm of the change
|
|
@@ -22437,7 +23059,16 @@ const listenAgentEvent = beginContext((clientId, fn) => {
|
|
|
22437
23059
|
// Validate the client ID
|
|
22438
23060
|
validateClientId$e(clientId);
|
|
22439
23061
|
// Subscribe to agent events with a queued callback
|
|
22440
|
-
return swarm$1.busService.subscribe(clientId, "agent-bus", queued(async (e) =>
|
|
23062
|
+
return swarm$1.busService.subscribe(clientId, "agent-bus", queued(async (e) => {
|
|
23063
|
+
try {
|
|
23064
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23065
|
+
// as an unhandled rejection and can crash the host process.
|
|
23066
|
+
return await fn(e);
|
|
23067
|
+
}
|
|
23068
|
+
catch (error) {
|
|
23069
|
+
console.error(`agent-swarm event listener error source=listenAgentEvent error=${getErrorMessage(error)}`);
|
|
23070
|
+
}
|
|
23071
|
+
}));
|
|
22441
23072
|
});
|
|
22442
23073
|
|
|
22443
23074
|
/**
|
|
@@ -22475,7 +23106,16 @@ const listenHistoryEvent = beginContext((clientId, fn) => {
|
|
|
22475
23106
|
// Validate the client ID
|
|
22476
23107
|
validateClientId$d(clientId);
|
|
22477
23108
|
// Subscribe to history events with a queued callback
|
|
22478
|
-
return swarm$1.busService.subscribe(clientId, "history-bus", queued(async (e) =>
|
|
23109
|
+
return swarm$1.busService.subscribe(clientId, "history-bus", queued(async (e) => {
|
|
23110
|
+
try {
|
|
23111
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23112
|
+
// as an unhandled rejection and can crash the host process.
|
|
23113
|
+
return await fn(e);
|
|
23114
|
+
}
|
|
23115
|
+
catch (error) {
|
|
23116
|
+
console.error(`agent-swarm event listener error source=listenHistoryEvent error=${getErrorMessage(error)}`);
|
|
23117
|
+
}
|
|
23118
|
+
}));
|
|
22479
23119
|
});
|
|
22480
23120
|
|
|
22481
23121
|
/**
|
|
@@ -22513,7 +23153,16 @@ const listenSessionEvent = beginContext((clientId, fn) => {
|
|
|
22513
23153
|
// Validate the client ID
|
|
22514
23154
|
validateClientId$c(clientId);
|
|
22515
23155
|
// Subscribe to session events with a queued callback
|
|
22516
|
-
return swarm$1.busService.subscribe(clientId, "session-bus", queued(async (e) =>
|
|
23156
|
+
return swarm$1.busService.subscribe(clientId, "session-bus", queued(async (e) => {
|
|
23157
|
+
try {
|
|
23158
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23159
|
+
// as an unhandled rejection and can crash the host process.
|
|
23160
|
+
return await fn(e);
|
|
23161
|
+
}
|
|
23162
|
+
catch (error) {
|
|
23163
|
+
console.error(`agent-swarm event listener error source=listenSessionEvent error=${getErrorMessage(error)}`);
|
|
23164
|
+
}
|
|
23165
|
+
}));
|
|
22517
23166
|
});
|
|
22518
23167
|
|
|
22519
23168
|
/**
|
|
@@ -22551,7 +23200,16 @@ const listenStateEvent = beginContext((clientId, fn) => {
|
|
|
22551
23200
|
// Validate the client ID
|
|
22552
23201
|
validateClientId$b(clientId);
|
|
22553
23202
|
// Subscribe to state events with a queued callback
|
|
22554
|
-
return swarm$1.busService.subscribe(clientId, "state-bus", queued(async (e) =>
|
|
23203
|
+
return swarm$1.busService.subscribe(clientId, "state-bus", queued(async (e) => {
|
|
23204
|
+
try {
|
|
23205
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23206
|
+
// as an unhandled rejection and can crash the host process.
|
|
23207
|
+
return await fn(e);
|
|
23208
|
+
}
|
|
23209
|
+
catch (error) {
|
|
23210
|
+
console.error(`agent-swarm event listener error source=listenStateEvent error=${getErrorMessage(error)}`);
|
|
23211
|
+
}
|
|
23212
|
+
}));
|
|
22555
23213
|
});
|
|
22556
23214
|
|
|
22557
23215
|
/**
|
|
@@ -22589,7 +23247,16 @@ const listenStorageEvent = beginContext((clientId, fn) => {
|
|
|
22589
23247
|
// Validate the client ID
|
|
22590
23248
|
validateClientId$a(clientId);
|
|
22591
23249
|
// Subscribe to storage events with a queued callback
|
|
22592
|
-
return swarm$1.busService.subscribe(clientId, "storage-bus", queued(async (e) =>
|
|
23250
|
+
return swarm$1.busService.subscribe(clientId, "storage-bus", queued(async (e) => {
|
|
23251
|
+
try {
|
|
23252
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23253
|
+
// as an unhandled rejection and can crash the host process.
|
|
23254
|
+
return await fn(e);
|
|
23255
|
+
}
|
|
23256
|
+
catch (error) {
|
|
23257
|
+
console.error(`agent-swarm event listener error source=listenStorageEvent error=${getErrorMessage(error)}`);
|
|
23258
|
+
}
|
|
23259
|
+
}));
|
|
22593
23260
|
});
|
|
22594
23261
|
|
|
22595
23262
|
/**
|
|
@@ -22627,7 +23294,16 @@ const listenSwarmEvent = beginContext((clientId, fn) => {
|
|
|
22627
23294
|
// Validate the client ID
|
|
22628
23295
|
validateClientId$9(clientId);
|
|
22629
23296
|
// Subscribe to swarm events with a queued callback
|
|
22630
|
-
return swarm$1.busService.subscribe(clientId, "swarm-bus", queued(async (e) =>
|
|
23297
|
+
return swarm$1.busService.subscribe(clientId, "swarm-bus", queued(async (e) => {
|
|
23298
|
+
try {
|
|
23299
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23300
|
+
// as an unhandled rejection and can crash the host process.
|
|
23301
|
+
return await fn(e);
|
|
23302
|
+
}
|
|
23303
|
+
catch (error) {
|
|
23304
|
+
console.error(`agent-swarm event listener error source=listenSwarmEvent error=${getErrorMessage(error)}`);
|
|
23305
|
+
}
|
|
23306
|
+
}));
|
|
22631
23307
|
});
|
|
22632
23308
|
|
|
22633
23309
|
/**
|
|
@@ -22665,7 +23341,16 @@ const listenPolicyEvent = beginContext((clientId, fn) => {
|
|
|
22665
23341
|
// Validate the client ID
|
|
22666
23342
|
validateClientId$8(clientId);
|
|
22667
23343
|
// Subscribe to policy events with a queued callback
|
|
22668
|
-
return swarm$1.busService.subscribe(clientId, "policy-bus", queued(async (e) =>
|
|
23344
|
+
return swarm$1.busService.subscribe(clientId, "policy-bus", queued(async (e) => {
|
|
23345
|
+
try {
|
|
23346
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23347
|
+
// as an unhandled rejection and can crash the host process.
|
|
23348
|
+
return await fn(e);
|
|
23349
|
+
}
|
|
23350
|
+
catch (error) {
|
|
23351
|
+
console.error(`agent-swarm event listener error source=listenPolicyEvent error=${getErrorMessage(error)}`);
|
|
23352
|
+
}
|
|
23353
|
+
}));
|
|
22669
23354
|
});
|
|
22670
23355
|
|
|
22671
23356
|
/**
|
|
@@ -22708,7 +23393,16 @@ const listenAgentEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
22708
23393
|
// Validate the client ID
|
|
22709
23394
|
validateClientId$7(clientId);
|
|
22710
23395
|
// Subscribe to agent events for one occurrence with a filter and queued callback
|
|
22711
|
-
return swarm$1.busService.once(clientId, "agent-bus", filterFn, queued(async (e) =>
|
|
23396
|
+
return swarm$1.busService.once(clientId, "agent-bus", filterFn, queued(async (e) => {
|
|
23397
|
+
try {
|
|
23398
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23399
|
+
// as an unhandled rejection and can crash the host process.
|
|
23400
|
+
return await fn(e);
|
|
23401
|
+
}
|
|
23402
|
+
catch (error) {
|
|
23403
|
+
console.error(`agent-swarm event listener error source=listenAgentEventOnce error=${getErrorMessage(error)}`);
|
|
23404
|
+
}
|
|
23405
|
+
}));
|
|
22712
23406
|
});
|
|
22713
23407
|
|
|
22714
23408
|
/**
|
|
@@ -22751,7 +23445,16 @@ const listenHistoryEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
22751
23445
|
// Validate the client ID
|
|
22752
23446
|
validateClientId$6(clientId);
|
|
22753
23447
|
// Subscribe to history events for one occurrence with a filter and queued callback
|
|
22754
|
-
return swarm$1.busService.once(clientId, "history-bus", filterFn, queued(async (e) =>
|
|
23448
|
+
return swarm$1.busService.once(clientId, "history-bus", filterFn, queued(async (e) => {
|
|
23449
|
+
try {
|
|
23450
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23451
|
+
// as an unhandled rejection and can crash the host process.
|
|
23452
|
+
return await fn(e);
|
|
23453
|
+
}
|
|
23454
|
+
catch (error) {
|
|
23455
|
+
console.error(`agent-swarm event listener error source=listenHistoryEventOnce error=${getErrorMessage(error)}`);
|
|
23456
|
+
}
|
|
23457
|
+
}));
|
|
22755
23458
|
});
|
|
22756
23459
|
|
|
22757
23460
|
/**
|
|
@@ -22794,7 +23497,16 @@ const listenSessionEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
22794
23497
|
// Validate the client ID
|
|
22795
23498
|
validateClientId$5(clientId);
|
|
22796
23499
|
// Subscribe to session events for one occurrence with a filter and queued callback
|
|
22797
|
-
return swarm$1.busService.once(clientId, "session-bus", filterFn, queued(async (e) =>
|
|
23500
|
+
return swarm$1.busService.once(clientId, "session-bus", filterFn, queued(async (e) => {
|
|
23501
|
+
try {
|
|
23502
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23503
|
+
// as an unhandled rejection and can crash the host process.
|
|
23504
|
+
return await fn(e);
|
|
23505
|
+
}
|
|
23506
|
+
catch (error) {
|
|
23507
|
+
console.error(`agent-swarm event listener error source=listenSessionEventOnce error=${getErrorMessage(error)}`);
|
|
23508
|
+
}
|
|
23509
|
+
}));
|
|
22798
23510
|
});
|
|
22799
23511
|
|
|
22800
23512
|
/**
|
|
@@ -22837,7 +23549,16 @@ const listenStateEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
22837
23549
|
// Validate the client ID
|
|
22838
23550
|
validateClientId$4(clientId);
|
|
22839
23551
|
// Subscribe to state events for one occurrence with a filter and queued callback
|
|
22840
|
-
return swarm$1.busService.once(clientId, "state-bus", filterFn, queued(async (e) =>
|
|
23552
|
+
return swarm$1.busService.once(clientId, "state-bus", filterFn, queued(async (e) => {
|
|
23553
|
+
try {
|
|
23554
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23555
|
+
// as an unhandled rejection and can crash the host process.
|
|
23556
|
+
return await fn(e);
|
|
23557
|
+
}
|
|
23558
|
+
catch (error) {
|
|
23559
|
+
console.error(`agent-swarm event listener error source=listenStateEventOnce error=${getErrorMessage(error)}`);
|
|
23560
|
+
}
|
|
23561
|
+
}));
|
|
22841
23562
|
});
|
|
22842
23563
|
|
|
22843
23564
|
/**
|
|
@@ -22880,7 +23601,16 @@ const listenStorageEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
22880
23601
|
// Validate the client ID
|
|
22881
23602
|
validateClientId$3(clientId);
|
|
22882
23603
|
// Subscribe to storage events for one occurrence with a filter and queued callback
|
|
22883
|
-
return swarm$1.busService.once(clientId, "storage-bus", filterFn, queued(async (e) =>
|
|
23604
|
+
return swarm$1.busService.once(clientId, "storage-bus", filterFn, queued(async (e) => {
|
|
23605
|
+
try {
|
|
23606
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23607
|
+
// as an unhandled rejection and can crash the host process.
|
|
23608
|
+
return await fn(e);
|
|
23609
|
+
}
|
|
23610
|
+
catch (error) {
|
|
23611
|
+
console.error(`agent-swarm event listener error source=listenStorageEventOnce error=${getErrorMessage(error)}`);
|
|
23612
|
+
}
|
|
23613
|
+
}));
|
|
22884
23614
|
});
|
|
22885
23615
|
|
|
22886
23616
|
/**
|
|
@@ -22923,7 +23653,16 @@ const listenSwarmEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
22923
23653
|
// Validate the client ID
|
|
22924
23654
|
validateClientId$2(clientId);
|
|
22925
23655
|
// Subscribe to swarm events for one occurrence with a filter and queued callback
|
|
22926
|
-
return swarm$1.busService.once(clientId, "swarm-bus", filterFn, queued(async (e) =>
|
|
23656
|
+
return swarm$1.busService.once(clientId, "swarm-bus", filterFn, queued(async (e) => {
|
|
23657
|
+
try {
|
|
23658
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23659
|
+
// as an unhandled rejection and can crash the host process.
|
|
23660
|
+
return await fn(e);
|
|
23661
|
+
}
|
|
23662
|
+
catch (error) {
|
|
23663
|
+
console.error(`agent-swarm event listener error source=listenSwarmEventOnce error=${getErrorMessage(error)}`);
|
|
23664
|
+
}
|
|
23665
|
+
}));
|
|
22927
23666
|
});
|
|
22928
23667
|
|
|
22929
23668
|
/**
|
|
@@ -22966,7 +23705,16 @@ const listenExecutionEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
22966
23705
|
// Validate the client ID
|
|
22967
23706
|
validateClientId$1(clientId);
|
|
22968
23707
|
// Subscribe to execution events for one occurrence with a filter and queued callback
|
|
22969
|
-
return swarm$1.busService.once(clientId, "execution-bus", filterFn, queued(async (e) =>
|
|
23708
|
+
return swarm$1.busService.once(clientId, "execution-bus", filterFn, queued(async (e) => {
|
|
23709
|
+
try {
|
|
23710
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23711
|
+
// as an unhandled rejection and can crash the host process.
|
|
23712
|
+
return await fn(e);
|
|
23713
|
+
}
|
|
23714
|
+
catch (error) {
|
|
23715
|
+
console.error(`agent-swarm event listener error source=listenExecutionEventOnce error=${getErrorMessage(error)}`);
|
|
23716
|
+
}
|
|
23717
|
+
}));
|
|
22970
23718
|
});
|
|
22971
23719
|
|
|
22972
23720
|
/**
|
|
@@ -23009,7 +23757,16 @@ const listenPolicyEventOnce = beginContext((clientId, filterFn, fn) => {
|
|
|
23009
23757
|
// Validate the client ID
|
|
23010
23758
|
validateClientId(clientId);
|
|
23011
23759
|
// Subscribe to policy events for one occurrence with a filter and queued callback
|
|
23012
|
-
return swarm$1.busService.once(clientId, "policy-bus", filterFn, queued(async (e) =>
|
|
23760
|
+
return swarm$1.busService.once(clientId, "policy-bus", filterFn, queued(async (e) => {
|
|
23761
|
+
try {
|
|
23762
|
+
// A throwing listener must not reject the queued chain: that surfaces
|
|
23763
|
+
// as an unhandled rejection and can crash the host process.
|
|
23764
|
+
return await fn(e);
|
|
23765
|
+
}
|
|
23766
|
+
catch (error) {
|
|
23767
|
+
console.error(`agent-swarm event listener error source=listenPolicyEventOnce error=${getErrorMessage(error)}`);
|
|
23768
|
+
}
|
|
23769
|
+
}));
|
|
23013
23770
|
});
|
|
23014
23771
|
|
|
23015
23772
|
/** @private Constant for logging the call method in RoundRobin*/
|
|
@@ -23323,10 +24080,6 @@ class SharedStateUtils {
|
|
|
23323
24080
|
*/
|
|
23324
24081
|
const SharedState = new SharedStateUtils();
|
|
23325
24082
|
|
|
23326
|
-
/** @constant {number} INACTIVITY_CHECK - Interval for checking inactivity in milliseconds (1 minute)*/
|
|
23327
|
-
const INACTIVITY_CHECK = 60 * 1000;
|
|
23328
|
-
/** @constant {number} INACTIVITY_TIMEOUT - Timeout duration for inactivity in milliseconds (15 minutes)*/
|
|
23329
|
-
const INACTIVITY_TIMEOUT = 15 * 60 * 1000;
|
|
23330
24083
|
/**
|
|
23331
24084
|
* @constant {Function} BEGIN_CHAT_FN
|
|
23332
24085
|
* Function to begin a chat session
|
|
@@ -23386,7 +24139,7 @@ class ChatInstance {
|
|
|
23386
24139
|
clientId: this.clientId,
|
|
23387
24140
|
swarmName: this.swarmName,
|
|
23388
24141
|
});
|
|
23389
|
-
const isActive = now - this._lastActivity <=
|
|
24142
|
+
const isActive = now - this._lastActivity <= GLOBAL_CONFIG.CC_CHAT_INACTIVITY_TIMEOUT;
|
|
23390
24143
|
this.callbacks.onCheckActivity &&
|
|
23391
24144
|
this.callbacks.onCheckActivity(this.clientId, this.swarmName, isActive, this._lastActivity);
|
|
23392
24145
|
return isActive;
|
|
@@ -23453,13 +24206,20 @@ class ChatUtils {
|
|
|
23453
24206
|
const handleCleanup = async () => {
|
|
23454
24207
|
const now = Date.now();
|
|
23455
24208
|
for (const chat of this._chats.values()) {
|
|
23456
|
-
|
|
23457
|
-
|
|
24209
|
+
try {
|
|
24210
|
+
if (await chat.checkLastActivity(now)) {
|
|
24211
|
+
continue;
|
|
24212
|
+
}
|
|
24213
|
+
await chat.dispose();
|
|
24214
|
+
}
|
|
24215
|
+
catch (error) {
|
|
24216
|
+
// The cleanup interval is fire-and-forget: a throwing user callback
|
|
24217
|
+
// (onDispose, onCheckActivity) must not become an unhandled rejection.
|
|
24218
|
+
console.error(`agent-swarm chat cleanup error error=${getErrorMessage(error)}`);
|
|
23458
24219
|
}
|
|
23459
|
-
await chat.dispose();
|
|
23460
24220
|
}
|
|
23461
24221
|
};
|
|
23462
|
-
setInterval(handleCleanup,
|
|
24222
|
+
setInterval(handleCleanup, GLOBAL_CONFIG.CC_CHAT_INACTIVITY_CHECK);
|
|
23463
24223
|
});
|
|
23464
24224
|
/**
|
|
23465
24225
|
* Gets or creates a chat instance for a client
|
|
@@ -23701,8 +24461,18 @@ class StorageUtils {
|
|
|
23701
24461
|
if (!swarm$1.agentValidationService.hasStorage(payload.agentName, payload.storageName)) {
|
|
23702
24462
|
throw new Error(`agent-swarm StorageUtils ${payload.storageName} not registered in ${payload.agentName} (createNumericIndex)`);
|
|
23703
24463
|
}
|
|
23704
|
-
const
|
|
23705
|
-
|
|
24464
|
+
const items = await swarm$1.storagePublicService.list(METHOD_NAME_CREATE_NUMERIC_INDEX, payload.clientId, payload.storageName);
|
|
24465
|
+
// length + 1 collides with surviving ids once anything was removed
|
|
24466
|
+
// (items [1,2,3] minus 1 -> length 2 -> next "3" overwrites live item 3),
|
|
24467
|
+
// so the next index must come from the maximum numeric id instead.
|
|
24468
|
+
let maxId = 0;
|
|
24469
|
+
for (const { id } of items) {
|
|
24470
|
+
const numericId = Number(id);
|
|
24471
|
+
if (!Number.isNaN(numericId)) {
|
|
24472
|
+
maxId = Math.max(maxId, numericId);
|
|
24473
|
+
}
|
|
24474
|
+
}
|
|
24475
|
+
return maxId + 1;
|
|
23706
24476
|
});
|
|
23707
24477
|
/**
|
|
23708
24478
|
* Clears all items from the storage for a given client and agent.
|
|
@@ -24017,18 +24787,15 @@ class SchemaUtils {
|
|
|
24017
24787
|
data,
|
|
24018
24788
|
});
|
|
24019
24789
|
const { mapKey = GLOBAL_CONFIG.CC_NAME_TO_TITLE, mapValue = (_, value) => value.slice(0, 50), } = map;
|
|
24790
|
+
// objectFlat emits ["", ""] entries as structural separators; render them
|
|
24791
|
+
// as blank lines instead of leaking "undefined: " into the model prompt.
|
|
24792
|
+
const mapEntry = ([key, value]) => key ? `${mapKey(key)}: ${mapValue(key, String(value))}` : "";
|
|
24020
24793
|
if (Array.isArray(data)) {
|
|
24021
24794
|
return data
|
|
24022
|
-
.map((item) => objectFlat(item)
|
|
24023
|
-
.map(([key, value]) => [mapKey(key), mapValue(key, String(value))])
|
|
24024
|
-
.map(([key, value]) => `${key}: ${value}`)
|
|
24025
|
-
.join("\n"))
|
|
24795
|
+
.map((item) => objectFlat(item).map(mapEntry).join("\n"))
|
|
24026
24796
|
.join(`\n\n\n\n`);
|
|
24027
24797
|
}
|
|
24028
|
-
return objectFlat(data)
|
|
24029
|
-
.map(([key, value]) => [mapKey(key), mapValue(key, String(value))])
|
|
24030
|
-
.map(([key, value]) => `${key}: ${value}`)
|
|
24031
|
-
.join("\n");
|
|
24798
|
+
return objectFlat(data).map(mapEntry).join("\n");
|
|
24032
24799
|
};
|
|
24033
24800
|
}
|
|
24034
24801
|
}
|
|
@@ -24836,4 +25603,4 @@ const Utils = {
|
|
|
24836
25603
|
PersistEmbeddingUtils,
|
|
24837
25604
|
};
|
|
24838
25605
|
|
|
24839
|
-
export { Adapter, Chat, ChatInstance, Compute, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MCP, MethodContextService, Operator, OperatorInstance, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, RoundRobin, Schema, SchemaContextService, SharedCompute, SharedState, SharedStorage, State, Storage, Utils, addAdvisor, addAgent, addAgentNavigation, addCommitAction, addCompletion, addCompute, addEmbedding, addFetchInfo, addMCP, addOutline, addPipeline, addPolicy, addState, addStorage, addSwarm, addTool, addTriageNavigation, ask, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, chat, commitAssistantMessage, commitAssistantMessageForce, commitDeveloperMessage, commitDeveloperMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitToolRequest, commitToolRequestForce, commitUserMessage, commitUserMessageForce, complete, createCommitAction, createFetchInfo, createNavigateToAgent, createNavigateToTriageAgent, disposeConnection, dumpAdvisorResult, dumpAgent, dumpClientPerformance, dumpDocs, dumpOutlineResult, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, fork, getAdvisor, getAgent, getAgentHistory, getAgentName, getAssistantHistory, getCheckBusy, getCompletion, getCompute,
|
|
25606
|
+
export { Adapter, Chat, ChatInstance, Compute, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, Logger, LoggerInstance, MCP, MethodContextService, Operator, OperatorInstance, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, RoundRobin, Schema, SchemaContextService, SharedCompute, SharedState, SharedStorage, State, Storage, TOOL_PROTOCOL_PROMPT, Utils, addAdvisor, addAgent, addAgentNavigation, addCommitAction, addCompletion, addCompute, addEmbedding, addFetchInfo, addMCP, addOutline, addPipeline, addPolicy, addState, addStorage, addSwarm, addTool, addTriageNavigation, ask, beginContext, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, chat, commitAssistantMessage, commitAssistantMessageForce, commitDeveloperMessage, commitDeveloperMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitToolRequest, commitToolRequestForce, commitUserMessage, commitUserMessageForce, complete, createCommitAction, createFetchInfo, createNavigateToAgent, createNavigateToTriageAgent, disposeConnection, dumpAdvisorResult, dumpAgent, dumpClientPerformance, dumpDocs, dumpOutlineResult, dumpPerfomance, dumpSwarm, emit, emitForce, event, execute, executeForce, fork, getAdvisor, getAgent, getAgentHistory, getAgentName, getAssistantHistory, getCheckBusy, getCompletion, getCompute, getEmbedding, getLastAssistantMessage, getLastSystemMessage, getLastToolMessage, getLastUserMessage, getMCP, getNavigationRoute, getPayload, getPipeline, getPolicy, getRawHistory, getSessionContext, getSessionMode, getState, getStorage, getSwarm, getTool, getToolNameForModel, getUserHistory, hasNavigation, hasSession, json, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenExecutionEvent, listenExecutionEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenPolicyEvent, listenPolicyEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, markOffline, markOnline, notify, notifyForce, overrideAdvisor, overrideAgent, overrideCompletion, overrideCompute, overrideEmbedding, overrideMCP, overrideOutline, overridePipeline, overridePolicy, overrideState, overrideStorage, overrideSwarm, overrideTool, runStateless, runStatelessForce, scope, session, setConfig, startPipeline, swarm, toJsonSchema, validate, validateToolArguments };
|