agent-swarm-kit 3.2.0 → 5.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/package.json CHANGED
@@ -1,89 +1,89 @@
1
- {
2
- "name": "agent-swarm-kit",
3
- "version": "3.2.0",
4
- "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
- "author": {
6
- "name": "Petr Tripolsky",
7
- "email": "tripolskypetr@gmail.com",
8
- "url": "https://github.com/tripolskypetr"
9
- },
10
- "funding": {
11
- "type": "individual",
12
- "url": "http://paypal.me/tripolskypetr"
13
- },
14
- "license": "MIT",
15
- "homepage": "https://agent-swarm.github.io/modules.html",
16
- "keywords": [
17
- "NVIDIA NIM",
18
- "OpenAI",
19
- "GPT4All",
20
- "Ollama",
21
- "LM Studio",
22
- "llama",
23
- "gpt",
24
- "mistral"
25
- ],
26
- "files": [
27
- "build",
28
- "types.d.ts",
29
- "README.md"
30
- ],
31
- "repository": {
32
- "type": "git",
33
- "url": "https://github.com/tripolskypetr/agent-swarm-kit",
34
- "documentation": "https://github.com/tripolskypetr/agent-swarm-kit/tree/master/docs"
35
- },
36
- "bugs": {
37
- "url": "https://github.com/tripolskypetr/agent-swarm-kit/issues"
38
- },
39
- "scripts": {
40
- "build": "rollup -c",
41
- "test": "npm run build && node ./test/index.mjs",
42
- "benchmark": "npm run build && node ./benchmark/index.mjs",
43
- "build:docs": "rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs",
44
- "docs:gpt": "npm run build && node ./scripts/gpt-docs.mjs",
45
- "docs:uml": "npm run build && node ./scripts/uml.mjs",
46
- "docs:www": "rimraf docs/wwwroot && typedoc && node ./packages/typedoc-yandex-metrica/index.mjs",
47
- "docs:demo:win": ".\\scripts\\win\\build_demo_docs.bat",
48
- "docs:demo": "sh ./scripts/linux/build_demo_docs.sh",
49
- "docs:demo:concat": "node ./packages/concat-demo-docs/index.mjs",
50
- "repl": "dotenv -e .env -- npm run build && node -e \"import('./scripts/repl.mjs')\" --interactive"
51
- },
52
- "main": "build/index.cjs",
53
- "module": "build/index.mjs",
54
- "source": "src/index.ts",
55
- "types": "./types.d.ts",
56
- "exports": {
57
- "require": "./build/index.cjs",
58
- "types": "./types.d.ts",
59
- "import": "./build/index.mjs",
60
- "default": "./build/index.cjs"
61
- },
62
- "devDependencies": {
63
- "@rollup/plugin-typescript": "11.1.6",
64
- "@types/lodash-es": "4.17.12",
65
- "@types/node": "22.9.0",
66
- "@types/xml2js": "0.4.14",
67
- "glob": "11.0.1",
68
- "ollama": "0.5.14",
69
- "rimraf": "6.0.1",
70
- "rollup": "3.29.5",
71
- "rollup-plugin-dts": "6.1.1",
72
- "rollup-plugin-peer-deps-external": "2.2.4",
73
- "tslib": "2.7.0",
74
- "typedoc": "0.27.9",
75
- "undici": "6.21.2",
76
- "worker-testbed": "2.1.0"
77
- },
78
- "peerDependencies": {
79
- "typescript": "^5.0.0"
80
- },
81
- "dependencies": {
82
- "di-kit": "^1.1.1",
83
- "di-scoped": "^1.0.21",
84
- "functools-kit": "^3.0.0",
85
- "get-moment-stamp": "^2.0.0",
86
- "lodash-es": "4.17.21",
87
- "xml2js": "0.6.2"
88
- }
89
- }
1
+ {
2
+ "name": "agent-swarm-kit",
3
+ "version": "5.0.0",
4
+ "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
+ "author": {
6
+ "name": "Petr Tripolsky",
7
+ "email": "tripolskypetr@gmail.com",
8
+ "url": "https://github.com/tripolskypetr"
9
+ },
10
+ "funding": {
11
+ "type": "individual",
12
+ "url": "http://paypal.me/tripolskypetr"
13
+ },
14
+ "license": "MIT",
15
+ "homepage": "https://agent-swarm.github.io/modules.html",
16
+ "keywords": [
17
+ "NVIDIA NIM",
18
+ "OpenAI",
19
+ "GPT4All",
20
+ "Ollama",
21
+ "LM Studio",
22
+ "llama",
23
+ "gpt",
24
+ "mistral"
25
+ ],
26
+ "files": [
27
+ "build",
28
+ "types.d.ts",
29
+ "README.md"
30
+ ],
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/tripolskypetr/agent-swarm-kit",
34
+ "documentation": "https://github.com/tripolskypetr/agent-swarm-kit/tree/master/docs"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/tripolskypetr/agent-swarm-kit/issues"
38
+ },
39
+ "scripts": {
40
+ "build": "rollup -c",
41
+ "test": "npm run build && node ./test/index.mjs",
42
+ "benchmark": "npm run build && node ./benchmark/index.mjs",
43
+ "build:docs": "rimraf docs && mkdir docs && node ./scripts/dts-docs.cjs ./types.d.ts ./docs",
44
+ "docs:gpt": "npm run build && node ./scripts/gpt-docs.mjs",
45
+ "docs:uml": "npm run build && node ./scripts/uml.mjs",
46
+ "docs:www": "rimraf docs/wwwroot && typedoc && node ./packages/typedoc-yandex-metrica/index.mjs",
47
+ "docs:demo:win": ".\\scripts\\win\\build_demo_docs.bat",
48
+ "docs:demo": "sh ./scripts/linux/build_demo_docs.sh",
49
+ "docs:demo:concat": "node ./packages/concat-demo-docs/index.mjs",
50
+ "repl": "dotenv -e .env -- npm run build && node -e \"import('./scripts/repl.mjs')\" --interactive"
51
+ },
52
+ "main": "build/index.cjs",
53
+ "module": "build/index.mjs",
54
+ "source": "src/index.ts",
55
+ "types": "./types.d.ts",
56
+ "exports": {
57
+ "require": "./build/index.cjs",
58
+ "types": "./types.d.ts",
59
+ "import": "./build/index.mjs",
60
+ "default": "./build/index.cjs"
61
+ },
62
+ "devDependencies": {
63
+ "@rollup/plugin-typescript": "11.1.6",
64
+ "@types/lodash-es": "4.17.12",
65
+ "@types/node": "22.9.0",
66
+ "@types/xml2js": "0.4.14",
67
+ "glob": "11.0.1",
68
+ "ollama": "0.5.14",
69
+ "rimraf": "6.0.1",
70
+ "rollup": "3.29.5",
71
+ "rollup-plugin-dts": "6.1.1",
72
+ "rollup-plugin-peer-deps-external": "2.2.4",
73
+ "tslib": "2.7.0",
74
+ "typedoc": "0.27.9",
75
+ "undici": "6.21.2",
76
+ "worker-testbed": "3.0.0"
77
+ },
78
+ "peerDependencies": {
79
+ "typescript": "^5.0.0"
80
+ },
81
+ "dependencies": {
82
+ "di-kit": "^1.1.1",
83
+ "di-scoped": "^1.0.21",
84
+ "functools-kit": "^4.0.0",
85
+ "get-moment-stamp": "^2.0.0",
86
+ "lodash-es": "4.17.21",
87
+ "xml2js": "0.6.2"
88
+ }
89
+ }
package/types.d.ts CHANGED
@@ -3197,6 +3197,35 @@ declare class ClientAgent implements IAgent {
3197
3197
  * @readonly
3198
3198
  */
3199
3199
  readonly _toolAbortController: ToolAbortController;
3200
+ /**
3201
+ * Count of tool calls currently executing for this agent.
3202
+ * Non-zero while any targetFn.call promise is pending; ClientSession uses it to
3203
+ * detect nested tool-mode executions that must join the parent output waiter.
3204
+ */
3205
+ _runningToolCalls: number;
3206
+ /**
3207
+ * Count of EXECUTE_FN tool status chains still consuming tool events.
3208
+ * While non-zero, tool errors are handled by the chain (stop + resurrect);
3209
+ * once it drops to zero a late tool error must recover on its own in
3210
+ * createToolCall, or the pending execution output would never be emitted.
3211
+ */
3212
+ _activeToolChains: number;
3213
+ /**
3214
+ * Count of EXECUTE_FN executions currently in flight for this agent instance.
3215
+ * dispose() checks it: tearing the instance down mid-execution (e.g. a
3216
+ * server-side changeToAgent while the completion is still running) must
3217
+ * resolve the pending output waiter with an empty result — otherwise the
3218
+ * waiter and the session busy lock would hang forever.
3219
+ */
3220
+ _activeExecutions: number;
3221
+ /**
3222
+ * Generation counter for output emissions. Bumped by commitCancelOutput and by
3223
+ * swarm-level output substitution (emit). Executions capture the epoch at start
3224
+ * and _emitOutput drops their result when the epoch moved on — otherwise the
3225
+ * stale output of a cancelled/substituted execution would resolve the waiter
3226
+ * of the NEXT message, poisoning that exchange.
3227
+ */
3228
+ _outputEpoch: number;
3200
3229
  /**
3201
3230
  * Subject for signaling agent changes, halting subsequent tool executions via commitAgentChange.
3202
3231
  * @readonly
@@ -3259,13 +3288,19 @@ declare class ClientAgent implements IAgent {
3259
3288
  * Supports SwarmConnectionService by broadcasting agent outputs within the swarm.
3260
3289
  * @throws {Error} If validation fails after model resurrection, indicating an unrecoverable state.
3261
3290
  **/
3262
- _emitOutput(mode: ExecutionMode, rawResult: string): Promise<void>;
3291
+ _emitOutput(mode: ExecutionMode, rawResult: string, outputEpoch?: number): Promise<void>;
3263
3292
  /**
3264
3293
  * Resurrects the model in case of failures using configured strategies (flush, recomplete, custom).
3265
3294
  * Updates history with failure details and returns a placeholder or transformed result, signaling via _resqueSubject.
3266
3295
  * Supports error recovery for CompletionSchemaService’s getCompletion calls.
3267
3296
  */
3268
3297
  _resurrectModel(mode: ExecutionMode, reason?: string): Promise<string>;
3298
+ /**
3299
+ * Marks in-flight executions as substituted: the swarm emitted a replacement
3300
+ * output (ClientSwarm.emit), so results of executions started earlier must not
3301
+ * reach _outputSubject — they would pair with the next waiter otherwise.
3302
+ */
3303
+ commitOutputSubstituted(): void;
3269
3304
  /**
3270
3305
  * Waits for the next output to be emitted via _outputSubject, typically after execute or run.
3271
3306
  * Useful for external consumers (e.g., SwarmConnectionService) awaiting agent responses.
@@ -4483,10 +4518,32 @@ declare class ClientSwarm implements ISwarm {
4483
4518
  */
4484
4519
  cancelOutput(): Promise<void>;
4485
4520
  /**
4486
- * Waits for output from the active agent in a queued manner, delegating to WAIT_FOR_OUTPUT_FN.
4487
- * Ensures only one wait operation runs at a time, handling cancellation and agent changes, supporting ClientSession's output retrieval.
4521
+ * Chain of pending waitForOutput calls, reset to a resolved promise whenever
4522
+ * the most recently started waiter settles. See waitForOutput for the rationale.
4523
+ */
4524
+ private _lastOutputAwaiter;
4525
+ /**
4526
+ * Waiters created by waitForOutput that have not settled yet, in creation order.
4527
+ * joinOutput attaches nested tool executions to the head of this list.
4528
+ */
4529
+ private _pendingOutputAwaiters;
4530
+ /**
4531
+ * Waits for output from the active agent, delegating to WAIT_FOR_OUTPUT_FN.
4532
+ * Pending waiters run in FIFO order so each one consumes the next emitted output,
4533
+ * but once a started waiter settles the chain is reset: a waiter that subscribed
4534
+ * too late to observe its output stays pending without blocking waiters created
4535
+ * afterwards. Strict sequential queueing must be avoided here — a nested tool
4536
+ * execute whose output was already consumed would deadlock every later completion.
4488
4537
  */
4489
4538
  waitForOutput: () => Promise<string>;
4539
+ /**
4540
+ * Awaits the same output as the oldest pending waitForOutput call, or starts a
4541
+ * fresh wait when none is pending. Nested executions triggered from inside a tool
4542
+ * (execute/executeForce with "tool" mode) must use this instead of waitForOutput:
4543
+ * their emitted output resolves the parent waiter, so queueing behind it would
4544
+ * leave the nested caller pending forever and skip the tool's onAfterCall.
4545
+ */
4546
+ joinOutput: () => Promise<string>;
4490
4547
  /**
4491
4548
  * Retrieves the name of the active agent, lazily fetching it via params.getActiveAgent if not loaded.
4492
4549
  * Emits an event via BusService with the result, supporting ClientSession's agent identification.
@@ -6082,8 +6139,18 @@ declare class ClientStorage<T extends IStorageData = IStorageData> implements IS
6082
6139
  */
6083
6140
  constructor(params: IStorageParams<T>);
6084
6141
  /**
6085
- * Dispatches a storage action (upsert, remove, or clear) in a queued manner, delegating to DISPATCH_FN.
6086
- * Ensures sequential execution of storage operations, supporting thread-safe updates from ClientAgent or tools.
6142
+ * Queued core of dispatch. The wrapped function must never reject: queued()
6143
+ * chains every call on the previous promise, so a rejection inside the queue
6144
+ * (e.g. a throwing createIndex/createEmbedding/setData) would reject every
6145
+ * already-queued dispatch with this foreign error WITHOUT running it — a
6146
+ * concurrent upsert/remove/clear would be silently dropped. Errors are boxed
6147
+ * here and rethrown outside the queue, so only the failing caller observes them.
6148
+ */
6149
+ private _dispatchQueue;
6150
+ /**
6151
+ * Dispatches a storage action (upsert, remove, or clear) through the serialized
6152
+ * queue, delegating to DISPATCH_FN. Ensures sequential execution of storage
6153
+ * operations, supporting thread-safe updates from ClientAgent or tools.
6087
6154
  */
6088
6155
  dispatch: (action: Action$1, payload: Partial<Payload<T>>) => Promise<void>;
6089
6156
  /**
@@ -6425,14 +6492,38 @@ type Action = "read" | "write";
6425
6492
  declare class ClientState<State extends IStateData = IStateData> implements IState<State>, IStateChangeEvent {
6426
6493
  readonly params: IStateParams<State>;
6427
6494
  readonly stateChanged: Subject<string>;
6495
+ /**
6496
+ * Marks the async execution context of a running dispatch (read/write).
6497
+ * getState checks it to serve reentrant reads (getState called from INSIDE a
6498
+ * setState dispatchFn/middleware) without re-entering the queue, which would
6499
+ * deadlock. Scoping this per async-context — instead of a plain instance flag —
6500
+ * ensures an UNRELATED concurrent getState still queues and observes writes in
6501
+ * order, rather than reading a stale field while some other write is in flight.
6502
+ */
6503
+ private _dispatchContext;
6504
+ /**
6505
+ * True only while the caller runs inside the async context of an active
6506
+ * dispatch on this instance (i.e. a reentrant call from within a dispatchFn).
6507
+ */
6508
+ get _inDispatch(): boolean;
6428
6509
  /**
6429
6510
  * The current state data, initialized as null and set during waitForInit.
6430
6511
  * Updated by setState and clearState, persisted via params.setState if provided.
6431
6512
  */
6432
6513
  _state: State;
6433
6514
  /**
6434
- * Queued dispatch function to read or write the state, delegating to DISPATCH_FN.
6435
- * Ensures thread-safe state operations, supporting concurrent access from ClientAgent or tools.
6515
+ * Queued core of dispatch. The wrapped function must never reject: queued()
6516
+ * chains every call on the previous promise, so a rejection inside the queue
6517
+ * would reject every already-queued dispatch with this foreign error WITHOUT
6518
+ * running it — a concurrent setState would be silently dropped. Errors (e.g.
6519
+ * a throwing user dispatchFn or middleware) are boxed here and rethrown
6520
+ * outside the queue, so only the caller whose operation failed observes them.
6521
+ */
6522
+ private _dispatchQueue;
6523
+ /**
6524
+ * Dispatches a read or write of the state through the serialized queue,
6525
+ * delegating to DISPATCH_FN. Ensures thread-safe state operations, supporting
6526
+ * concurrent access from ClientAgent or tools.
6436
6527
  */
6437
6528
  dispatch: (action: Action, payload?: DispatchFn<State>) => Promise<State>;
6438
6529
  /**
@@ -7804,7 +7895,6 @@ declare class PolicyValidationService {
7804
7895
  validate: (policyName: PolicyName, source: string) => void;
7805
7896
  }
7806
7897
 
7807
- declare const BAN_NEED_FETCH: unique symbol;
7808
7898
  /**
7809
7899
  * Class representing a client policy in the swarm system, implementing the IPolicy interface.
7810
7900
  * Manages client bans, input/output validation, and restrictions, with lazy-loaded ban lists and event emission via BusService.
@@ -7815,11 +7905,40 @@ declare const BAN_NEED_FETCH: unique symbol;
7815
7905
  declare class ClientPolicy implements IPolicy {
7816
7906
  readonly params: IPolicyParams;
7817
7907
  /**
7818
- * Set of banned client IDs or a symbol indicating the ban list needs to be fetched.
7819
- * Initialized as BAN_NEED_FETCH, lazily populated via params.getBannedClients on first use in hasBan, validateInput, etc.
7820
- * Updated by banClient and unbanClient, persisted if params.setBannedClients is provided.
7908
+ * Ban sets keyed by swarm name, lazily populated via params.getBannedClients.
7909
+ * A ClientPolicy instance is memoized per policyName and shared by every swarm
7910
+ * that lists the policy, while bans are persisted per (policy, swarm) — a
7911
+ * single shared set would leak bans of one swarm into another and persist
7912
+ * the mixed set into the wrong store.
7913
+ */
7914
+ _banSetBySwarm: Map<string, Set<string>>;
7915
+ /**
7916
+ * Returns the ban set of the given swarm, fetching it on first access.
7917
+ * Re-checks the map after the await: a ban committed through _banQueue while
7918
+ * the fetch was in flight must not be overwritten by the stale fetch result.
7821
7919
  */
7822
- _banSet: Set<SessionId> | typeof BAN_NEED_FETCH;
7920
+ private _getBanSet;
7921
+ /**
7922
+ * Serializes the read-modify-write of _banSet shared by banClient/unbanClient.
7923
+ * Without it two concurrent bans of different clients both read the same ban
7924
+ * set, each adds only its own client, and the later setBannedClients overwrites
7925
+ * the earlier one — one ban is silently lost in memory and in the persisted
7926
+ * store. queued() runs the mutations one at a time so each observes the result
7927
+ * of the previous one.
7928
+ *
7929
+ * The wrapped function must never reject: queued() chains every call on the
7930
+ * previous promise, so a rejection inside the queue (e.g. a throwing
7931
+ * setBannedClients adapter) would reject every already-queued ban/unban with
7932
+ * this foreign error WITHOUT running it — a concurrent ban of another client
7933
+ * would be silently lost. Errors are boxed here and rethrown by the caller
7934
+ * outside the queue.
7935
+ */
7936
+ private _banQueue;
7937
+ /**
7938
+ * Runs a ban-set mutation through _banQueue, rethrowing its boxed error
7939
+ * outside the queue so only the failing caller observes it.
7940
+ */
7941
+ private _runBanQueue;
7823
7942
  /**
7824
7943
  * Constructs a ClientPolicy instance with the provided parameters.
7825
7944
  * Invokes the onInit callback if defined and logs construction if debugging is enabled.
@@ -10521,7 +10640,7 @@ type TEmbeddingSchema = {
10521
10640
  *
10522
10641
  * @example
10523
10642
  * // Override an embedding’s schema with new properties
10524
- * overrideEmbeding({
10643
+ * overrideEmbedding({
10525
10644
  * embeddingName: "TextEmbedding",
10526
10645
  * persist: true,
10527
10646
  * callbacks: {
@@ -10530,7 +10649,7 @@ type TEmbeddingSchema = {
10530
10649
  * });
10531
10650
  * // Logs the operation (if enabled) and updates the embedding schema in the swarm.
10532
10651
  */
10533
- declare function overrideEmbeding(embeddingSchema: TEmbeddingSchema): Promise<IEmbeddingSchema>;
10652
+ declare function overrideEmbedding(embeddingSchema: TEmbeddingSchema): Promise<IEmbeddingSchema>;
10534
10653
 
10535
10654
  /**
10536
10655
  * Type representing a partial policy schema with required policyName.
@@ -11113,16 +11232,16 @@ declare function commitToolRequestForce(request: IToolRequest[], clientId: strin
11113
11232
  * Emits a string as model output without executing an incoming message or checking the active agent.
11114
11233
  *
11115
11234
  * This function directly emits a provided string as output from the swarm session, bypassing message execution and agent activity checks.
11116
- * It is designed exclusively for sessions established via `makeConnection`, ensuring compatibility with its connection model.
11117
- * The execution is wrapped in `beginContext` for a clean environment, validates the session and swarm, and throws an error if the session mode
11118
- * is not "makeConnection". The operation is logged if enabled, and resolves when the content is successfully emitted.
11235
+ * Unlike `emit`, it does not verify that a specific agent is still active, ensuring emission even after navigation.
11236
+ * The execution is wrapped in `beginContext` for a clean environment, validates the session and swarm,
11237
+ * logs the operation if enabled, and resolves when the content is successfully emitted. Works for any session mode.
11119
11238
  *
11120
11239
  *
11121
11240
  * @param {string} content - The content to be processed or stored.
11122
11241
  * @param {string} clientId - The unique identifier of the client session.
11123
- * @throws {Error} If the session mode is not "makeConnection", or if session or swarm validation fails.
11242
+ * @throws {Error} If session or swarm validation fails.
11124
11243
  * @example
11125
- * await emitForce("Direct output", "client-123"); // Emits "Direct output" in a makeConnection session
11244
+ * await emitForce("Direct output", "client-123"); // Emits "Direct output" regardless of the active agent
11126
11245
  */
11127
11246
  declare function emitForce(content: string, clientId: string): Promise<void>;
11128
11247
 
@@ -11263,16 +11382,16 @@ declare function execute(content: string, clientId: string, agentName: AgentName
11263
11382
  /**
11264
11383
  * Emits a string as model output without executing an incoming message, with agent activity validation.
11265
11384
  *
11266
- * This function directly emits a provided string as output from the swarm session, bypassing message execution, and is designed exclusively
11267
- * for sessions established via `makeConnection`. It validates the session, swarm, and specified agent, ensuring the agent is still active
11268
- * before emitting. If the active agent has changed, the operation is skipped. The execution is wrapped in `beginContext` for a clean environment,
11269
- * logs the operation if enabled, and throws an error if the session mode is not "makeConnection".
11385
+ * This function directly emits a provided string as output from the swarm session, bypassing message execution.
11386
+ * It validates the session, swarm, and specified agent, ensuring the agent is still active before emitting.
11387
+ * If the active agent has changed, the operation is skipped. The execution is wrapped in `beginContext` for a
11388
+ * clean environment and logs the operation if enabled. Works for any session mode.
11270
11389
  *
11271
11390
  *
11272
11391
  * @param {string} content - The content to be processed or stored.
11273
11392
  * @param {string} clientId - The unique identifier of the client session.
11274
11393
  * @param {AgentName} agentName - The name of the agent to use or reference.
11275
- * @throws {Error} If the session mode is not "makeConnection", or if agent, session, or swarm validation fails.
11394
+ * @throws {Error} If agent, session, or swarm validation fails.
11276
11395
  * @example
11277
11396
  * await emit("Direct output", "client-123", "AgentX"); // Emits "Direct output" if AgentX is active
11278
11397
  */
@@ -11796,6 +11915,22 @@ declare function getLastAssistantMessage(clientId: string): Promise<string>;
11796
11915
  */
11797
11916
  declare function getLastSystemMessage(clientId: string): Promise<string>;
11798
11917
 
11918
+ /**
11919
+ * Retrieves the content of the most recent tool message from a client's session history.
11920
+ *
11921
+ * This function fetches the raw history for a specified client using `getRawHistory` and finds the last entry where the role is "tool".
11922
+ * It is wrapped in `beginContext` for a clean execution environment and logs the operation if enabled via `GLOBAL_CONFIG`. The result is the content
11923
+ * of the last tool message as a string, or `null` if no tool message exists in the history.
11924
+ *
11925
+ *
11926
+ * @param {string} clientId - The unique identifier of the client session.
11927
+ * @throws {Error} If `getRawHistory` fails due to session validation or history retrieval issues.
11928
+ * @example
11929
+ * const lastMessage = await getLastToolMessage("client-123");
11930
+ * console.log(lastMessage); // Outputs the last tool message or null
11931
+ */
11932
+ declare function getLastToolMessage(clientId: string): Promise<string>;
11933
+
11799
11934
  /**
11800
11935
  * Retrieves an agent schema by its name from the swarm's agent schema service.
11801
11936
  * Logs the operation if logging is enabled in the global configuration.
@@ -11830,7 +11965,7 @@ declare function getCompute(computeName: ComputeName): IComputeSchema<any>;
11830
11965
  * @function getEmbedding
11831
11966
  * @param {EmbeddingName} embeddingName - The name of the embedding.
11832
11967
  */
11833
- declare function getEmbeding(embeddingName: EmbeddingName): IEmbeddingSchema;
11968
+ declare function getEmbedding(embeddingName: EmbeddingName): IEmbeddingSchema;
11834
11969
 
11835
11970
  /**
11836
11971
  * Retrieves an MCP (Model Context Protocol) schema by its name from the swarm's MCP schema service.
@@ -12874,6 +13009,19 @@ interface IGlobalConfig {
12874
13009
  * Flag to enable operator timeout, used in `ClientOperator` for message processing.
12875
13010
  */
12876
13011
  CC_ENABLE_OPERATOR_TIMEOUT: boolean;
13012
+ /**
13013
+ * Timeout in milliseconds for operator signal waiting in `ClientOperator.waitForOutput`.
13014
+ * Applied only when CC_ENABLE_OPERATOR_TIMEOUT is true; expired wait resolves with an empty output.
13015
+ */
13016
+ CC_OPERATOR_SIGNAL_TIMEOUT: number;
13017
+ /**
13018
+ * Interval in milliseconds between chat inactivity sweeps in `ChatUtils`.
13019
+ */
13020
+ CC_CHAT_INACTIVITY_CHECK: number;
13021
+ /**
13022
+ * Inactivity duration in milliseconds after which an idle chat instance is disposed by `ChatUtils`.
13023
+ */
13024
+ CC_CHAT_INACTIVITY_TIMEOUT: number;
12877
13025
  /**
12878
13026
  * Disable fetch of data from all storages. Quite usefull for unit tests
12879
13027
  */
@@ -13189,7 +13337,7 @@ declare class SharedComputeUtils {
13189
13337
  * Retrieves shared compute data with validation and context management.
13190
13338
  * @async
13191
13339
  */
13192
- getComputeData: <T extends IComputeData = any>(clientId: string, computeName: ComputeName) => Promise<T>;
13340
+ getComputeData: <T extends IComputeData = any>(computeName: ComputeName) => Promise<T>;
13193
13341
  }
13194
13342
  /**
13195
13343
  * @constant {SharedComputeUtils} SharedCompute
@@ -13627,6 +13775,12 @@ declare class SchemaUtils {
13627
13775
  */
13628
13776
  declare const Schema: SchemaUtils;
13629
13777
 
13778
+ /**
13779
+ * Prompt template for instructing models on how to format tool calls in responses.
13780
+ * Uses XML-like `<tool_call>` tags containing JSON objects with function name and arguments.
13781
+ * @see https://github.com/ollama/ollama/blob/86a622cbdc69e9fd501764ff7565e977fc98f00a/server/model.go#L158
13782
+ */
13783
+ declare const TOOL_PROTOCOL_PROMPT: string;
13630
13784
  /**
13631
13785
  * Function type for completing AI model requests.
13632
13786
  * Takes completion arguments and returns a promise resolving to a model message response.
@@ -13912,4 +14066,4 @@ declare const Utils: {
13912
14066
  PersistEmbeddingUtils: typeof PersistEmbeddingUtils;
13913
14067
  };
13914
14068
 
13915
- export { Adapter, type BaseMessageRole, Chat, ChatInstance, Compute, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAdvisorSchema, type IAgentSchemaInternal, type IAgentTool, type IBaseCompletionArgs, type IBaseEvent, type IBaseMessage, type IBusEvent, type IBusEventContext, type IChatInstance, type IChatInstanceCallbacks, type ICommitActionParams, type ICompletionSchema, type IComputeSchema, type ICustomEvent, type IEmbeddingSchema, type IFetchInfoParams, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMCPSchema, type IMCPTool, type IMCPToolCallDto, type IMakeConnectionConfig, type IMakeDisposeParams, type INavigateToAgentParams, type INavigateToTriageParams, type IOutgoingMessage, type IOutlineCompletionArgs, type IOutlineFormat, type IOutlineHistory, type IOutlineMessage, type IOutlineObjectFormat, type IOutlineResult, type IOutlineSchema, type IOutlineSchemaFormat, type IOutlineValidationFn, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPipelineSchema, type IPolicySchema, type IScopeOptions, type ISessionConfig, type ISessionContext, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmCompletionArgs, type ISwarmMessage, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerInstance, MCP, type MCPToolProperties, MethodContextService, Operator, OperatorInstance, type OutlineMessageRole, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, SchemaContextService, type SendMessageFn, SharedCompute, SharedState, SharedStorage, State, Storage, type SwarmMessageRole, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, type TOperatorInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, type ToolValue, 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, getEmbeding, getLastAssistantMessage, getLastSystemMessage, 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, overrideEmbeding, overrideMCP, overrideOutline, overridePipeline, overridePolicy, overrideState, overrideStorage, overrideSwarm, overrideTool, runStateless, runStatelessForce, scope, session, setConfig, startPipeline, swarm, toJsonSchema, validate, validateToolArguments };
14069
+ export { Adapter, type BaseMessageRole, Chat, ChatInstance, Compute, type EventSource, ExecutionContextService, History, HistoryMemoryInstance, HistoryPersistInstance, type IAdvisorSchema, type IAgentSchemaInternal, type IAgentTool, type IBaseCompletionArgs, type IBaseEvent, type IBaseMessage, type IBusEvent, type IBusEventContext, type IChatInstance, type IChatInstanceCallbacks, type ICommitActionParams, type ICompletionSchema, type IComputeSchema, type ICustomEvent, type IEmbeddingSchema, type IFetchInfoParams, type IGlobalConfig, type IHistoryAdapter, type IHistoryControl, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMCPSchema, type IMCPTool, type IMCPToolCallDto, type IMakeConnectionConfig, type IMakeDisposeParams, type INavigateToAgentParams, type INavigateToTriageParams, type IOutgoingMessage, type IOutlineCompletionArgs, type IOutlineFormat, type IOutlineHistory, type IOutlineMessage, type IOutlineObjectFormat, type IOutlineResult, type IOutlineSchema, type IOutlineSchemaFormat, type IOutlineValidationFn, type IPersistActiveAgentData, type IPersistAliveData, type IPersistBase, type IPersistEmbeddingData, type IPersistMemoryData, type IPersistNavigationStackData, type IPersistPolicyData, type IPersistStateData, type IPersistStorageData, type IPipelineSchema, type IPolicySchema, type IScopeOptions, type ISessionConfig, type ISessionContext, type IStateSchema, type IStorageData, type IStorageSchema, type ISwarmCompletionArgs, type ISwarmMessage, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerInstance, MCP, type MCPToolProperties, MethodContextService, Operator, OperatorInstance, type OutlineMessageRole, PayloadContextService, PersistAlive, PersistBase, PersistEmbedding, PersistList, PersistMemory, PersistPolicy, PersistState, PersistStorage, PersistSwarm, Policy, type ReceiveMessageFn, RoundRobin, Schema, SchemaContextService, type SendMessageFn, SharedCompute, SharedState, SharedStorage, State, Storage, type SwarmMessageRole, type THistoryInstanceCtor, type THistoryMemoryInstance, type THistoryPersistInstance, type TLoggerInstance, TOOL_PROTOCOL_PROMPT, type TOperatorInstance, type TPersistBase, type TPersistBaseCtor, type TPersistList, type ToolValue, 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 };