agent-swarm-kit 1.1.109 → 1.1.111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.cjs CHANGED
@@ -3652,6 +3652,12 @@ const TOOL_ERROR_SYMBOL = Symbol("tool-error");
3652
3652
  const TOOL_STOP_SYMBOL = Symbol("tool-stop");
3653
3653
  const TOOL_NO_OUTPUT_WARNING_TIMEOUT = 15000;
3654
3654
  const TOOL_NO_OUTPUT_WARNING_SYMBOL = Symbol("tool-warning-timeout");
3655
+ /**
3656
+ * This tool availability function is used as a default for tools that do not specify their availability.
3657
+ * It always returns true, indicating that the tool is available by default.
3658
+ * @returns {boolean} A function that always returns true, indicating the tool is available by default.
3659
+ */
3660
+ const TOOL_AVAILABLE_DEFAULT = () => true;
3655
3661
  /**
3656
3662
  * A utility class for managing the lifecycle of an `AbortController` instance.
3657
3663
  * Provides a mechanism to signal and handle abort events for asynchronous operations.
@@ -4129,12 +4135,16 @@ class ClientAgent {
4129
4135
  const agentToolList = [];
4130
4136
  if (this.params.tools) {
4131
4137
  await Promise.all(this.params.tools.map(async (tool) => {
4132
- const { function: upperFn, ...other } = tool;
4138
+ const { toolName, function: upperFn, isAvailable = TOOL_AVAILABLE_DEFAULT, ...other } = tool;
4139
+ if (await functoolsKit.not(isAvailable(this.params.clientId, this.params.agentName, toolName))) {
4140
+ return;
4141
+ }
4133
4142
  const fn = typeof upperFn === "function"
4134
4143
  ? await upperFn(this.params.clientId, this.params.agentName)
4135
4144
  : upperFn;
4136
4145
  agentToolList.push({
4137
4146
  ...other,
4147
+ toolName,
4138
4148
  function: fn,
4139
4149
  });
4140
4150
  }));
@@ -6197,8 +6207,11 @@ class ToolSchemaService {
6197
6207
  if (typeof toolSchema.call !== "function") {
6198
6208
  throw new Error(`agent-swarm tool schema validation failed: missing call for toolName=${toolSchema.toolName}`);
6199
6209
  }
6210
+ if (toolSchema.isAvailable && typeof toolSchema.isAvailable !== "function") {
6211
+ throw new Error(`agent-swarm tool schema validation failed: invalid isAvailable for toolName=${toolSchema.toolName}`);
6212
+ }
6200
6213
  if (toolSchema.validate && typeof toolSchema.validate !== "function") {
6201
- throw new Error(`agent-swarm tool schema validation failed: missing validate for toolName=${toolSchema.toolName}`);
6214
+ throw new Error(`agent-swarm tool schema validation failed: invalid validate for toolName=${toolSchema.toolName}`);
6202
6215
  }
6203
6216
  if (!functoolsKit.isObject(toolSchema.function) && typeof toolSchema.function !== "function") {
6204
6217
  throw new Error(`agent-swarm tool schema validation failed: missing function for toolName=${toolSchema.toolName}`);
package/build/index.mjs CHANGED
@@ -3650,6 +3650,12 @@ const TOOL_ERROR_SYMBOL = Symbol("tool-error");
3650
3650
  const TOOL_STOP_SYMBOL = Symbol("tool-stop");
3651
3651
  const TOOL_NO_OUTPUT_WARNING_TIMEOUT = 15000;
3652
3652
  const TOOL_NO_OUTPUT_WARNING_SYMBOL = Symbol("tool-warning-timeout");
3653
+ /**
3654
+ * This tool availability function is used as a default for tools that do not specify their availability.
3655
+ * It always returns true, indicating that the tool is available by default.
3656
+ * @returns {boolean} A function that always returns true, indicating the tool is available by default.
3657
+ */
3658
+ const TOOL_AVAILABLE_DEFAULT = () => true;
3653
3659
  /**
3654
3660
  * A utility class for managing the lifecycle of an `AbortController` instance.
3655
3661
  * Provides a mechanism to signal and handle abort events for asynchronous operations.
@@ -4127,12 +4133,16 @@ class ClientAgent {
4127
4133
  const agentToolList = [];
4128
4134
  if (this.params.tools) {
4129
4135
  await Promise.all(this.params.tools.map(async (tool) => {
4130
- const { function: upperFn, ...other } = tool;
4136
+ const { toolName, function: upperFn, isAvailable = TOOL_AVAILABLE_DEFAULT, ...other } = tool;
4137
+ if (await not(isAvailable(this.params.clientId, this.params.agentName, toolName))) {
4138
+ return;
4139
+ }
4131
4140
  const fn = typeof upperFn === "function"
4132
4141
  ? await upperFn(this.params.clientId, this.params.agentName)
4133
4142
  : upperFn;
4134
4143
  agentToolList.push({
4135
4144
  ...other,
4145
+ toolName,
4136
4146
  function: fn,
4137
4147
  });
4138
4148
  }));
@@ -6195,8 +6205,11 @@ class ToolSchemaService {
6195
6205
  if (typeof toolSchema.call !== "function") {
6196
6206
  throw new Error(`agent-swarm tool schema validation failed: missing call for toolName=${toolSchema.toolName}`);
6197
6207
  }
6208
+ if (toolSchema.isAvailable && typeof toolSchema.isAvailable !== "function") {
6209
+ throw new Error(`agent-swarm tool schema validation failed: invalid isAvailable for toolName=${toolSchema.toolName}`);
6210
+ }
6198
6211
  if (toolSchema.validate && typeof toolSchema.validate !== "function") {
6199
- throw new Error(`agent-swarm tool schema validation failed: missing validate for toolName=${toolSchema.toolName}`);
6212
+ throw new Error(`agent-swarm tool schema validation failed: invalid validate for toolName=${toolSchema.toolName}`);
6200
6213
  }
6201
6214
  if (!isObject$1(toolSchema.function) && typeof toolSchema.function !== "function") {
6202
6215
  throw new Error(`agent-swarm tool schema validation failed: missing function for toolName=${toolSchema.toolName}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.1.109",
3
+ "version": "1.1.111",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
@@ -81,7 +81,7 @@
81
81
  "dependencies": {
82
82
  "di-kit": "^1.0.18",
83
83
  "di-scoped": "^1.0.20",
84
- "functools-kit": "^1.0.87",
84
+ "functools-kit": "^1.0.88",
85
85
  "get-moment-stamp": "^1.1.1",
86
86
  "lodash-es": "4.17.21",
87
87
  "xml2js": "0.6.2"
package/types.d.ts CHANGED
@@ -3396,6 +3396,15 @@ interface IAgentTool<T = Record<string, ToolValue>> {
3396
3396
  callReason: string;
3397
3397
  isLast: boolean;
3398
3398
  }): Promise<void>;
3399
+ /**
3400
+ * Checks if the tool is available for execution.
3401
+ * This method can be used to determine if the tool can be executed based on the current context.
3402
+ * @param {string} clientId - The ID of the client invoking the tool.
3403
+ * @param {AgentName} agentName - The name of the agent using the tool.
3404
+ * @param {ToolName} toolName - The name of the tool to check availability for.
3405
+ * @returns {boolean | Promise<boolean>} True if the tool is available, false otherwise
3406
+ */
3407
+ isAvailable?: (clientId: string, agentName: AgentName, toolName: ToolName) => (boolean | Promise<boolean>);
3399
3408
  /**
3400
3409
  * Validates the tool parameters before execution.
3401
3410
  * Can return synchronously or asynchronously based on validation complexity.