@signalwire/sdk 3.7.1 → 3.9.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/README.md +1 -0
  3. package/dist/AgentBase.d.ts +120 -3
  4. package/dist/AgentBase.js +291 -18
  5. package/dist/AgentBase.js.map +1 -1
  6. package/dist/AgentServer.d.ts +30 -6
  7. package/dist/AgentServer.js +28 -2
  8. package/dist/AgentServer.js.map +1 -1
  9. package/dist/AiEvents.d.ts +70 -0
  10. package/dist/AiEvents.js +94 -0
  11. package/dist/AiEvents.js.map +1 -0
  12. package/dist/ContextBuilder.d.ts +197 -14
  13. package/dist/ContextBuilder.js +422 -13
  14. package/dist/ContextBuilder.js.map +1 -1
  15. package/dist/FunctionResult.d.ts +129 -0
  16. package/dist/FunctionResult.js +170 -0
  17. package/dist/FunctionResult.js.map +1 -1
  18. package/dist/Logger.d.ts +1 -1
  19. package/dist/PostPrompt.d.ts +19 -0
  20. package/dist/PostPrompt.js +43 -0
  21. package/dist/PostPrompt.js.map +1 -1
  22. package/dist/SWMLService.d.ts +151 -10
  23. package/dist/SWMLService.js +377 -61
  24. package/dist/SWMLService.js.map +1 -1
  25. package/dist/SchemaUtils.js +14 -1
  26. package/dist/SchemaUtils.js.map +1 -1
  27. package/dist/SemanticGate.d.ts +61 -1
  28. package/dist/SemanticGate.js +108 -15
  29. package/dist/SemanticGate.js.map +1 -1
  30. package/dist/SessionManager.d.ts +17 -6
  31. package/dist/SessionManager.js +16 -3
  32. package/dist/SessionManager.js.map +1 -1
  33. package/dist/SwaigFunction.d.ts +86 -9
  34. package/dist/SwaigFunction.js +215 -59
  35. package/dist/SwaigFunction.js.map +1 -1
  36. package/dist/ToolMiddleware.d.ts +82 -0
  37. package/dist/ToolMiddleware.js +131 -0
  38. package/dist/ToolMiddleware.js.map +1 -0
  39. package/dist/TypeInference.d.ts +2 -2
  40. package/dist/TypeInference.js +1 -1
  41. package/dist/TypeInference.js.map +1 -1
  42. package/dist/ai-chat/ChatGateway.d.ts +5 -5
  43. package/dist/ai-chat/HandoffRouter.d.ts +3 -3
  44. package/dist/cli/tsdocs/api-index.json +1 -1
  45. package/dist/cli/tsdocs/topics.js +24 -4
  46. package/dist/cli/tsdocs/topics.js.map +1 -1
  47. package/dist/index.d.ts +23 -8
  48. package/dist/index.js +16 -5
  49. package/dist/index.js.map +1 -1
  50. package/dist/livewire/index.d.ts +3 -0
  51. package/dist/livewire/index.js +3 -0
  52. package/dist/livewire/index.js.map +1 -1
  53. package/dist/llms.txt +1 -0
  54. package/dist/patterns/Proposal.d.ts +146 -0
  55. package/dist/patterns/Proposal.js +212 -0
  56. package/dist/patterns/Proposal.js.map +1 -0
  57. package/dist/patterns/RequestList.d.ts +136 -0
  58. package/dist/patterns/RequestList.js +169 -0
  59. package/dist/patterns/RequestList.js.map +1 -0
  60. package/dist/relay/Call.d.ts +1 -1
  61. package/dist/relay/Call.js +1 -1
  62. package/dist/relay/Message.d.ts +1 -1
  63. package/dist/relay/Message.js +1 -1
  64. package/dist/relay/RelayClient.d.ts +0 -2
  65. package/dist/relay/RelayClient.js.map +1 -1
  66. package/dist/relay/RelayEvent.d.ts +3 -3
  67. package/dist/relay/RelayEvent.js +3 -3
  68. package/dist/relay/closedSets.d.ts +10 -10
  69. package/dist/relay/closedSets.js +2 -2
  70. package/dist/relay/types.d.ts +1 -1
  71. package/dist/rest/base/CrudResource.d.ts +1 -1
  72. package/dist/rest/base/CrudResource.js +1 -1
  73. package/dist/skills/SkillBase.d.ts +26 -3
  74. package/dist/skills/SkillBase.js +14 -3
  75. package/dist/skills/SkillBase.js.map +1 -1
  76. package/dist/speech/numbers.d.ts +66 -0
  77. package/dist/speech/numbers.js +281 -0
  78. package/dist/speech/numbers.js.map +1 -0
  79. package/dist/speech/spelling.d.ts +71 -0
  80. package/dist/speech/spelling.js +294 -0
  81. package/dist/speech/spelling.js.map +1 -0
  82. package/dist/testing/CallSimulator.d.ts +281 -0
  83. package/dist/testing/CallSimulator.js +666 -0
  84. package/dist/testing/CallSimulator.js.map +1 -0
  85. package/docs/agent-guide.md +4 -4
  86. package/docs/api-reference.md +285 -28
  87. package/docs/architecture.md +8 -4
  88. package/docs/cli-guide.md +2 -0
  89. package/docs/contexts-guide.md +47 -4
  90. package/docs/conversation_patterns.md +257 -0
  91. package/docs/mcp_integration.md +1 -1
  92. package/docs/pgi_agent_guide.md +2 -1
  93. package/docs/programmatically_governed_inference.md +2 -2
  94. package/docs/swaig-reference.md +95 -3
  95. package/docs/swml_service_guide.md +31 -6
  96. package/package.json +3 -1
@@ -2,8 +2,9 @@
2
2
  * SwaigFunction - Wraps a handler function with metadata for SWAIG registration.
3
3
  */
4
4
  import Ajv from 'ajv';
5
- import { FunctionResult } from './FunctionResult.js';
5
+ import { FunctionResult, ToolRefusal, settleResult, toolErrorResult, } from './FunctionResult.js';
6
6
  import { getLogger } from './Logger.js';
7
+ import { runChain } from './ToolMiddleware.js';
7
8
  import { applyGateFields, _checkGatedFunction, } from './SemanticGate.js';
8
9
  const ajv = new Ajv({ allErrors: true });
9
10
  /**
@@ -89,8 +90,39 @@ export function normalizeParameters(parameters, required = []) {
89
90
  return result;
90
91
  }
91
92
  /**
92
- * Default user-facing message returned when a tool handler throws and no
93
- * {@link SwaigErrorHandler} supplies its own response.
93
+ * The argument a vouched tool adds, which the model sets to say every other
94
+ * argument came from the user.
95
+ */
96
+ export const VOUCHED_PARAMETER = 'data_supplied_by_user';
97
+ /** The description of {@link VOUCHED_PARAMETER}, as the model reads it. */
98
+ export const VOUCHED_DESCRIPTION = 'True only when every other argument is what the user said in this call, not a guess, an example or something assumed. False when any value did not come from the user.';
99
+ /** The `web_hook_url` that has the platform run its own implementation of a function, by name. */
100
+ export const NATIVE_WEBHOOK_URL = 'native';
101
+ /** The tool prompt the model gets when it calls a vouched tool without vouching for its arguments. */
102
+ export const VOUCHED_PROMPT = 'Get the answer from the user before using this tool.';
103
+ /** A property's schema that also takes null; one without a `type` is left as it is. */
104
+ function nullableSpec(spec) {
105
+ if (typeof spec !== 'object' || spec === null || Array.isArray(spec) || !('type' in spec)) {
106
+ return spec;
107
+ }
108
+ const s = spec;
109
+ const types = Array.isArray(s['type']) ? s['type'] : [s['type']];
110
+ const widened = {
111
+ ...s,
112
+ type: types.includes('null') ? types : [...types, 'null'],
113
+ };
114
+ if (Array.isArray(s['enum']) && !s['enum'].includes(null)) {
115
+ widened['enum'] = [...s['enum'], null];
116
+ }
117
+ return widened;
118
+ }
119
+ /**
120
+ * The message a tool handler that threw gave the model before 3.8.0.
121
+ *
122
+ * @deprecated A handler that throws, with no {@link SwaigErrorHandler}
123
+ * response and no `errorMessage`, now gives the model
124
+ * {@link toolErrorResult}: the outcome is unknown, so it mustn't say the
125
+ * action worked or that it didn't. Kept for code that imports it.
94
126
  */
95
127
  export const DEFAULT_SWAIG_ERROR_MESSAGE = "Sorry, I couldn't complete that action. Please try again or contact support if the issue persists.";
96
128
  /**
@@ -151,10 +183,18 @@ export class SwaigFunction {
151
183
  isTypedHandler;
152
184
  /** Whether this tool is externally hosted (has a webhookUrl). */
153
185
  isExternal;
154
- /** Per-tool error hook; see {@link SwaigErrorHandler}. */
186
+ /** Per-tool error hook; see `SwaigErrorHandler`. */
155
187
  onError;
156
188
  /** Per-tool user-facing error message override. */
157
189
  errorMessage;
190
+ /** Whether the model must vouch that the arguments came from the user. */
191
+ vouched;
192
+ /** Whether optional arguments take null, or undefined for the agent's setting. */
193
+ nullableOptional;
194
+ /** Whether the handler reads the conversation (turns on `swaig_post_conversation`). */
195
+ needsConversation;
196
+ /** Middleware around this tool's calls, inside the service's. */
197
+ middleware;
158
198
  /**
159
199
  * Create a new SwaigFunction.
160
200
  *
@@ -199,9 +239,79 @@ export class SwaigFunction {
199
239
  this.isExternal = opts.webhookUrl !== undefined;
200
240
  this.onError = opts.onError;
201
241
  this.errorMessage = opts.errorMessage;
242
+ this.vouched = opts.vouched ?? false;
243
+ this.nullableOptional = opts.nullableOptional;
244
+ this.needsConversation = opts.needsConversation ?? false;
245
+ this.middleware = [...(opts.middleware ?? [])];
246
+ }
247
+ ensureParameterStructure(nullableDefault) {
248
+ return this._parameterSchema(nullableDefault);
249
+ }
250
+ /**
251
+ * The parameter schema the model sees: the tool's own, with optional
252
+ * arguments widened to take null when they do, and a vouched tool's
253
+ * `data_supplied_by_user` added.
254
+ * @param nullableDefault - The agent's default for whether optional
255
+ * arguments take null, used when this tool doesn't set its own.
256
+ * @internal
257
+ */
258
+ _parameterSchema(nullableDefault) {
259
+ let result = normalizeParameters(this.parameters, this.required);
260
+ if (this._nullable(nullableDefault)) {
261
+ const required = new Set(result['required'] ?? []);
262
+ const properties = result['properties'] ?? {};
263
+ result = {
264
+ ...result,
265
+ properties: Object.fromEntries(Object.entries(properties).map(([key, spec]) => [
266
+ key,
267
+ required.has(key) ? spec : nullableSpec(spec),
268
+ ])),
269
+ };
270
+ }
271
+ if (this.vouched) {
272
+ const required = (result['required'] ?? []).filter((r) => r !== VOUCHED_PARAMETER);
273
+ result = {
274
+ ...result,
275
+ properties: {
276
+ ...(result['properties'] ?? {}),
277
+ [VOUCHED_PARAMETER]: { type: 'boolean', description: VOUCHED_DESCRIPTION },
278
+ },
279
+ required: [...required, VOUCHED_PARAMETER],
280
+ };
281
+ }
282
+ return result;
283
+ }
284
+ /** Whether optional arguments take null: this tool's own setting, else the agent's. */
285
+ _nullable(nullableDefault) {
286
+ return this.nullableOptional ?? !!nullableDefault;
202
287
  }
203
- ensureParameterStructure() {
204
- return normalizeParameters(this.parameters, this.required);
288
+ /** What the model gets for a vouched call it didn't vouch for, or null. */
289
+ _vouchedRefusal(args) {
290
+ if (!this.vouched || args?.[VOUCHED_PARAMETER] === true)
291
+ return null;
292
+ return new FunctionResult(undefined, false, `${this.name} was not run.`, VOUCHED_PROMPT);
293
+ }
294
+ /**
295
+ * The arguments the handler gets: a vouched tool's own is removed, and a
296
+ * null for an optional argument that takes null is an argument not given.
297
+ */
298
+ _handlerArgs(args, nullableDefault) {
299
+ if (!args || Object.keys(args).length === 0)
300
+ return args;
301
+ const drop = new Set();
302
+ if (this.vouched && VOUCHED_PARAMETER in args)
303
+ drop.add(VOUCHED_PARAMETER);
304
+ if (this._nullable(nullableDefault)) {
305
+ const required = new Set(normalizeParameters(this.parameters, this.required)['required'] ??
306
+ []);
307
+ for (const [key, value] of Object.entries(args)) {
308
+ if (value === null && !required.has(key))
309
+ drop.add(key);
310
+ }
311
+ }
312
+ if (drop.size === 0)
313
+ return args;
314
+ return Object.fromEntries(Object.entries(args).filter(([key]) => !drop.has(key)));
205
315
  }
206
316
  /**
207
317
  * Validate arguments against the parameter JSON schema using full
@@ -217,11 +327,13 @@ export class SwaigFunction {
217
327
  * considered valid — matching Python's early-return path.
218
328
  *
219
329
  * @param args - Arguments to validate.
330
+ * @param nullableDefault - The agent's default for whether optional
331
+ * arguments take null, used when this tool doesn't set its own.
220
332
  * @returns A tuple of `[isValid, errors]`. When no validation is needed
221
333
  * (empty schema), returns `[true, []]`.
222
334
  */
223
- validateArgs(args) {
224
- const schema = this.ensureParameterStructure();
335
+ validateArgs(args, nullableDefault) {
336
+ const schema = this.ensureParameterStructure(nullableDefault);
225
337
  const properties = schema['properties'];
226
338
  if (!properties || Object.keys(properties).length === 0) {
227
339
  return [true, []];
@@ -254,12 +366,13 @@ export class SwaigFunction {
254
366
  * request's configured copy.
255
367
  * @internal
256
368
  */
257
- async _executeAs(agent, args, rawData, agentOnError) {
369
+ async _executeAs(agent, args, rawData, agentOnError, service = agent) {
370
+ const nullableDefault = service?._nullableOptionalDefault();
258
371
  // Soft validation, as the reference's tool_mixin does: arguments that
259
372
  // don't match the schema are logged, and the handler still runs.
260
373
  if (args && Object.keys(args).length > 0) {
261
374
  try {
262
- const [valid, errors] = this.validateArgs(args);
375
+ const [valid, errors] = this.validateArgs(args, nullableDefault);
263
376
  if (!valid) {
264
377
  log.warn(`Argument validation failed for function '${this.name}': ${errors.join('; ')}`);
265
378
  }
@@ -268,59 +381,102 @@ export class SwaigFunction {
268
381
  log.debug(`Argument validation error for function '${this.name}': ${err instanceof Error ? err.message : String(err)}`);
269
382
  }
270
383
  }
271
- try {
272
- // Runtime fallback is the empty object (unchanged); the cast is
273
- // compile-time only — the backend always sends the full payload, but
274
- // `execute` allows callers to omit it (e.g. CLI/test harnesses).
275
- const result = await this.handler(args, rawData ?? {}, agent);
276
- if (result instanceof FunctionResult) {
277
- return result.toDict();
278
- }
279
- if (typeof result === 'object' && result !== null && !('response' in result)) {
280
- // Plain object without a "response" key — matches Python's behavior:
281
- // `elif isinstance(result, dict): return FunctionResult("Function completed successfully").to_dict()`
282
- // Python replaces such dicts entirely; do the same here.
283
- return new FunctionResult('Function completed successfully').toDict();
284
- }
285
- if (typeof result === 'object' && result !== null) {
286
- // Handler returned a plain object that already carries a `response`
287
- // key — it IS the SWAIG response dict; pass it through unchanged.
288
- return result;
384
+ const dispatch = async (a, raw) => {
385
+ // A vouched tool runs only when the model vouches for its arguments
386
+ const refusal = this._vouchedRefusal(a);
387
+ if (refusal)
388
+ return refusal.toDict();
389
+ try {
390
+ // Runtime fallback is the empty object (unchanged); the cast is
391
+ // compile-time only — the backend always sends the full payload, but
392
+ // `execute` allows callers to omit it (e.g. CLI/test harnesses).
393
+ const handlerArgs = this._handlerArgs(a, nullableDefault);
394
+ const result = settleResult(this.name, await this.handler(handlerArgs, raw, agent));
395
+ if (result instanceof FunctionResult) {
396
+ return result.toDict();
397
+ }
398
+ if (typeof result === 'object' && result !== null) {
399
+ // A SWAIG result already: settleResult made sure it has a response
400
+ // or an action.
401
+ return result;
402
+ }
403
+ // Neither a FunctionResult nor an object — warn and fall back to
404
+ // wrapping the stringified value. See Python's web_mixin /
405
+ // serverless_mixin / tool_mixin for the equivalent check.
406
+ if (typeof result !== 'string') {
407
+ log.warn(`SWAIG function "${this.name}" returned a value of type "${typeof result}" ` +
408
+ `that is neither FunctionResult nor object; falling back to str(result). ` +
409
+ `The AI will see the stringified value as its tool response. Wrap your ` +
410
+ `return in new FunctionResult(...) or return an object with at least a ` +
411
+ `"response" key.`);
412
+ }
413
+ return new FunctionResult(String(result)).toDict();
289
414
  }
290
- // Neither a FunctionResult nor a dict — warn and fall back to
291
- // wrapping the stringified value. See Python's web_mixin /
292
- // serverless_mixin / tool_mixin for the equivalent check.
293
- log.warn(`SWAIG function "${this.name}" returned a value of type "${typeof result}" ` +
294
- `that is neither FunctionResult nor object; falling back to str(result). ` +
295
- `The AI will see the stringified value as its tool response. Wrap your ` +
296
- `return in new FunctionResult(...) or return an object with at least a ` +
297
- `"response" key.`);
298
- return new FunctionResult(String(result)).toDict();
299
- }
300
- catch (err) {
301
- // Preserve the stack for Error instances (plain `${err}` discards it).
302
- const detail = err instanceof Error ? (err.stack ?? `${err.name}: ${err.message}`) : String(err);
303
- log.error(`Error executing SWAIG function ${this.name}: ${detail}`);
304
- // Give authors a programmatic surface: per-tool hook first, then the
305
- // agent-level hook. Either may return a FunctionResult to control what
306
- // the AI sees; if a hook itself throws, that's logged and we continue to
307
- // the next fallback (the error is always contained — a thrown handler
308
- // must never break the live call).
309
- const ctx = { functionName: this.name, args, rawData };
310
- for (const hook of [this.onError, agentOnError]) {
311
- if (!hook)
312
- continue;
313
- try {
314
- const handled = await hook(err, ctx);
315
- if (handled instanceof FunctionResult) {
316
- return handled.toDict();
415
+ catch (err) {
416
+ // A refusal is the handler's own outcome, not an error
417
+ if (err instanceof ToolRefusal)
418
+ return err.result().toDict();
419
+ // Preserve the stack for Error instances (plain `${err}` discards it).
420
+ const detail = err instanceof Error ? (err.stack ?? `${err.name}: ${err.message}`) : String(err);
421
+ log.error(`Error executing SWAIG function ${this.name}: ${detail}`);
422
+ // Give authors a programmatic surface: per-tool hook first, then the
423
+ // agent-level hook. Either may return a FunctionResult to control what
424
+ // the AI sees; if a hook itself throws, that's logged and we continue to
425
+ // the next fallback (the error is always contained — a thrown handler
426
+ // must never break the live call).
427
+ const ctx = {
428
+ functionName: this.name,
429
+ args: a,
430
+ rawData: raw,
431
+ };
432
+ for (const hook of [this.onError, agentOnError]) {
433
+ if (!hook)
434
+ continue;
435
+ try {
436
+ const handled = await hook(err, ctx);
437
+ if (handled instanceof FunctionResult) {
438
+ return handled.toDict();
439
+ }
440
+ }
441
+ catch (hookErr) {
442
+ log.error(`onError hook for SWAIG function ${this.name} threw: ${hookErr}`);
317
443
  }
318
444
  }
319
- catch (hookErr) {
320
- log.error(`onError hook for SWAIG function ${this.name} threw: ${hookErr}`);
321
- }
445
+ // The error itself isn't sent: its text can hold internals, and the
446
+ // model would read it as the outcome, which is unknown.
447
+ if (this.errorMessage !== undefined)
448
+ return new FunctionResult(this.errorMessage).toDict();
449
+ return toolErrorResult(this.name).toDict();
322
450
  }
323
- return new FunctionResult(this.errorMessage ?? DEFAULT_SWAIG_ERROR_MESSAGE).toDict();
451
+ };
452
+ const raw = (rawData ?? {});
453
+ const middleware = service?._toolMiddlewareFor(this) ?? this.middleware;
454
+ if (middleware.length === 0)
455
+ return dispatch(args, raw);
456
+ let outcome;
457
+ try {
458
+ outcome = await runChain(middleware, this.name, args, raw, dispatch);
459
+ }
460
+ catch (err) {
461
+ if (err instanceof ToolRefusal)
462
+ return err.result().toDict();
463
+ log.error(`Tool middleware for '${this.name}' threw: ${err instanceof Error ? (err.stack ?? err.message) : String(err)}`);
464
+ return toolErrorResult(this.name).toDict();
465
+ }
466
+ // Settled inside the boundary, as the reference's async path settles: a
467
+ // result that can't be (a circular object, say) is the unknown outcome,
468
+ // not a failed request, on the first attempt and on every retry of it
469
+ try {
470
+ const settled = settleResult(this.name, outcome);
471
+ if (settled instanceof FunctionResult)
472
+ return settled.toDict();
473
+ if (typeof settled === 'object' && settled !== null)
474
+ return settled;
475
+ return new FunctionResult(String(settled)).toDict();
476
+ }
477
+ catch (err) {
478
+ log.error(`The result of tool middleware for '${this.name}' couldn't be settled: ${err instanceof Error ? err.message : String(err)}`);
479
+ return toolErrorResult(this.name).toDict();
324
480
  }
325
481
  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AO,QAAQ,CAAC;QAC7B,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;YACpB,GAAG,GAAG,GAAG,GAAG,UAAU,KAAK,YAAY,MAAM,EAAE,CAAC;QAClD,CAAC;QACD,MAAM,GAAG,GAA4B;YACnC,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,wBAAwB,EAAE;SAC5C,CAAC;QACF,IAAI,GAAG;YAAE,GAAG,CAAC,cAAc,CAAC,GAAG,GAAG,CAAC;QACnC,IAAI,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzD,GAAG,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;QAChC,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ;YAAE,GAAG,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QACpD,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS;YAAE,GAAG,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC;QAClF,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACrC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Tool middleware: code that runs around every tool call.
3
+ *
4
+ * A middleware is `(name, args, rawData, callNext)`. It runs before the
5
+ * handler, and calls `callNext(args, rawData)` to run the rest of the chain and
6
+ * the handler, possibly with changed arguments. What it returns is the call's
7
+ * result, so it can return the handler's, change it, or answer without calling
8
+ * `callNext` at all. `callNext` returns a promise of the handler's result, so
9
+ * a middleware awaits it (or returns it as it is).
10
+ *
11
+ * The SDK puts one middleware first in every chain, unless it's turned off
12
+ * (`setToolResendDedupe(false)`): {@link ResendDedupe}, which keeps a transport
13
+ * retry from running a tool twice. SignalWire sends a tool request again, with
14
+ * the same body, after a timeout, a failed connection or a 5xx, so a slow tool
15
+ * can run twice. The retry carries the same `tool_call_id`; a call the model
16
+ * makes again gets a new one.
17
+ */
18
+ /** The rest of the chain, as a middleware calls it. */
19
+ export type CallNext = (args: Record<string, unknown>, rawData: Record<string, unknown>) => Promise<unknown>;
20
+ /** A tool middleware. */
21
+ export type ToolMiddleware = (name: string, args: Record<string, unknown>, rawData: Record<string, unknown>, callNext: CallNext) => unknown;
22
+ /**
23
+ * `value`, awaited when it's a promise. `callNext` always returns a promise in
24
+ * TypeScript, so a middleware can simply `await callNext(...)`; this is the
25
+ * reference's `resolve()` for code ported from it.
26
+ * @param value - A value or a promise of one.
27
+ * @returns The value.
28
+ */
29
+ export declare function resolve<T>(value: T | Promise<T>): Promise<T>;
30
+ /**
31
+ * Run `middleware` in order around `dispatch`.
32
+ * @param middleware - The chain, outermost first.
33
+ * @param name - The tool's name.
34
+ * @param args - The arguments.
35
+ * @param rawData - The SWAIG request.
36
+ * @param dispatch - The handler's end of the chain.
37
+ * @returns The call's result.
38
+ */
39
+ export declare function runChain(middleware: readonly ToolMiddleware[], name: string, args: Record<string, unknown>, rawData: Record<string, unknown>, dispatch: CallNext): Promise<unknown>;
40
+ /**
41
+ * The middleware that answers a transport retry of a tool call with the first
42
+ * attempt's result, instead of running the tool again.
43
+ *
44
+ * A call is the same when its `call_id`, `tool_call_id` and function name are.
45
+ * A retry that arrives while the first attempt is still running, as after a
46
+ * timeout, waits for it; one that arrives after it finished gets its result. A
47
+ * call without a `tool_call_id` always runs. Finished results are kept for
48
+ * `ttl` seconds, at most `maxEntries` of them; an attempt still running is
49
+ * never dropped, so a retry of it never runs the tool again. A first attempt
50
+ * whose middleware threw isn't kept, so a retry runs the tool; a handler that
51
+ * threw has an outcome (it's unknown), which is kept like any other.
52
+ *
53
+ * The state lives in the process: replicas of an agent each keep their own.
54
+ */
55
+ export declare class ResendDedupe {
56
+ /** How long a finished result is kept, in seconds. */
57
+ readonly ttl: number;
58
+ /** The most finished results kept. */
59
+ readonly maxEntries: number;
60
+ /** Attempts still running, by key. */
61
+ private readonly pending;
62
+ /** Finished results, oldest first, by key. */
63
+ private readonly done;
64
+ /**
65
+ * @param ttl - How long a finished result is kept, in seconds. Default 600.
66
+ * @param maxEntries - The most finished results kept. Default 1024.
67
+ */
68
+ constructor(ttl?: number, maxEntries?: number);
69
+ /** This dedupe as a {@link ToolMiddleware}. */
70
+ readonly middleware: ToolMiddleware;
71
+ /**
72
+ * Run a call, or answer a retry of one from its first attempt.
73
+ * @param name - The tool's name.
74
+ * @param args - The arguments.
75
+ * @param rawData - The SWAIG request.
76
+ * @param callNext - The rest of the chain.
77
+ * @returns The call's result.
78
+ */
79
+ handle(name: string, args: Record<string, unknown>, rawData: Record<string, unknown>, callNext: CallNext): Promise<unknown>;
80
+ /** Drop finished results past their time, and the oldest beyond the limit. */
81
+ private expire;
82
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Tool middleware: code that runs around every tool call.
3
+ *
4
+ * A middleware is `(name, args, rawData, callNext)`. It runs before the
5
+ * handler, and calls `callNext(args, rawData)` to run the rest of the chain and
6
+ * the handler, possibly with changed arguments. What it returns is the call's
7
+ * result, so it can return the handler's, change it, or answer without calling
8
+ * `callNext` at all. `callNext` returns a promise of the handler's result, so
9
+ * a middleware awaits it (or returns it as it is).
10
+ *
11
+ * The SDK puts one middleware first in every chain, unless it's turned off
12
+ * (`setToolResendDedupe(false)`): {@link ResendDedupe}, which keeps a transport
13
+ * retry from running a tool twice. SignalWire sends a tool request again, with
14
+ * the same body, after a timeout, a failed connection or a 5xx, so a slow tool
15
+ * can run twice. The retry carries the same `tool_call_id`; a call the model
16
+ * makes again gets a new one.
17
+ */
18
+ /**
19
+ * `value`, awaited when it's a promise. `callNext` always returns a promise in
20
+ * TypeScript, so a middleware can simply `await callNext(...)`; this is the
21
+ * reference's `resolve()` for code ported from it.
22
+ * @param value - A value or a promise of one.
23
+ * @returns The value.
24
+ */
25
+ export async function resolve(value) {
26
+ return await value;
27
+ }
28
+ /**
29
+ * Run `middleware` in order around `dispatch`.
30
+ * @param middleware - The chain, outermost first.
31
+ * @param name - The tool's name.
32
+ * @param args - The arguments.
33
+ * @param rawData - The SWAIG request.
34
+ * @param dispatch - The handler's end of the chain.
35
+ * @returns The call's result.
36
+ */
37
+ export async function runChain(middleware, name, args, rawData, dispatch) {
38
+ let call = dispatch;
39
+ for (const layer of [...middleware].reverse()) {
40
+ const next = call;
41
+ call = async (a, r) => await layer(name, a, r, next);
42
+ }
43
+ return await call(args, rawData);
44
+ }
45
+ /**
46
+ * The middleware that answers a transport retry of a tool call with the first
47
+ * attempt's result, instead of running the tool again.
48
+ *
49
+ * A call is the same when its `call_id`, `tool_call_id` and function name are.
50
+ * A retry that arrives while the first attempt is still running, as after a
51
+ * timeout, waits for it; one that arrives after it finished gets its result. A
52
+ * call without a `tool_call_id` always runs. Finished results are kept for
53
+ * `ttl` seconds, at most `maxEntries` of them; an attempt still running is
54
+ * never dropped, so a retry of it never runs the tool again. A first attempt
55
+ * whose middleware threw isn't kept, so a retry runs the tool; a handler that
56
+ * threw has an outcome (it's unknown), which is kept like any other.
57
+ *
58
+ * The state lives in the process: replicas of an agent each keep their own.
59
+ */
60
+ export class ResendDedupe {
61
+ /** How long a finished result is kept, in seconds. */
62
+ ttl;
63
+ /** The most finished results kept. */
64
+ maxEntries;
65
+ /** Attempts still running, by key. */
66
+ pending = new Map();
67
+ /** Finished results, oldest first, by key. */
68
+ done = new Map();
69
+ /**
70
+ * @param ttl - How long a finished result is kept, in seconds. Default 600.
71
+ * @param maxEntries - The most finished results kept. Default 1024.
72
+ */
73
+ constructor(ttl = 600, maxEntries = 1024) {
74
+ this.ttl = ttl;
75
+ this.maxEntries = maxEntries;
76
+ }
77
+ /** This dedupe as a {@link ToolMiddleware}. */
78
+ middleware = (name, args, rawData, callNext) => this.handle(name, args, rawData, callNext);
79
+ /**
80
+ * Run a call, or answer a retry of one from its first attempt.
81
+ * @param name - The tool's name.
82
+ * @param args - The arguments.
83
+ * @param rawData - The SWAIG request.
84
+ * @param callNext - The rest of the chain.
85
+ * @returns The call's result.
86
+ */
87
+ async handle(name, args, rawData, callNext) {
88
+ const key = dedupeKey(name, rawData);
89
+ if (key === null)
90
+ return await callNext(args, rawData);
91
+ this.expire();
92
+ const finished = this.done.get(key);
93
+ if (finished)
94
+ return finished.result;
95
+ const running = this.pending.get(key);
96
+ if (running)
97
+ return await running;
98
+ const attempt = callNext(args, rawData);
99
+ this.pending.set(key, attempt);
100
+ try {
101
+ const result = await attempt;
102
+ this.done.delete(key);
103
+ this.done.set(key, { at: Date.now(), result });
104
+ this.expire();
105
+ return result;
106
+ }
107
+ finally {
108
+ // Kept as finished, or not at all when it threw: a retry runs the tool
109
+ this.pending.delete(key);
110
+ }
111
+ }
112
+ /** Drop finished results past their time, and the oldest beyond the limit. */
113
+ expire() {
114
+ const cutoff = Date.now() - this.ttl * 1000;
115
+ for (const [key, entry] of this.done) {
116
+ if (entry.at > cutoff && this.done.size <= this.maxEntries)
117
+ break;
118
+ this.done.delete(key);
119
+ }
120
+ }
121
+ }
122
+ function dedupeKey(name, rawData) {
123
+ if (!rawData || typeof rawData !== 'object')
124
+ return null;
125
+ const toolCallId = rawData['tool_call_id'];
126
+ if (typeof toolCallId !== 'string' || !toolCallId)
127
+ return null;
128
+ const callId = rawData['call_id'];
129
+ return JSON.stringify([typeof callId === 'string' ? callId : '', toolCallId, name]);
130
+ }
131
+ //# sourceMappingURL=ToolMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolMiddleware.js","sourceRoot":"","sources":["../src/ToolMiddleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAgBH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAI,KAAqB;IACpD,OAAO,MAAM,KAAK,CAAC;AAC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AAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU;gBAAE,MAAM;YAClE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,OAA4C;IAC3E,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzD,MAAM,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3C,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IAC/D,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;AACtF,CAAC"}
@@ -29,7 +29,7 @@ import type { FunctionResult } from './FunctionResult.js';
29
29
  * matter". (`...unknown[]` would wrongly REJECT a `(city: string) => …` handler,
30
30
  * defeating the purpose.)
31
31
  */
32
- export type TypedToolHandler = (...args: never[]) => FunctionResult | Record<string, unknown> | string | Promise<FunctionResult | Record<string, unknown> | string>;
32
+ export type TypedToolHandler = (...args: never[]) => FunctionResult | Record<string, unknown> | string | null | undefined | void | Promise<FunctionResult | Record<string, unknown> | string | null | undefined | void>;
33
33
  /**
34
34
  * A function the SDK *introspects* (reads `fn.toString()` to recover parameter
35
35
  * names/defaults) but whose return value it does not consume. `inferSchema`
@@ -81,7 +81,7 @@ export declare function parseFunctionParams(source: string): ParsedParam[];
81
81
  * - No default → `"string"` (and the parameter is marked required)
82
82
  *
83
83
  * @param fn - The function to inspect. Arrow functions, regular functions, and
84
- * method shorthand all work. Typed as {@link IntrospectableFn} because only
84
+ * method shorthand all work. Typed as `IntrospectableFn` because only
85
85
  * the parameter list is read — the handler's return is irrelevant to schema
86
86
  * inference (a {@link TypedToolHandler} satisfies this).
87
87
  * @returns An {@link InferredSchema} describing the parameters, or `null` when
@@ -258,7 +258,7 @@ function extractParamName(expr) {
258
258
  * - No default → `"string"` (and the parameter is marked required)
259
259
  *
260
260
  * @param fn - The function to inspect. Arrow functions, regular functions, and
261
- * method shorthand all work. Typed as {@link IntrospectableFn} because only
261
+ * method shorthand all work. Typed as `IntrospectableFn` because only
262
262
  * the parameter list is read — the handler's return is irrelevant to schema
263
263
  * inference (a {@link TypedToolHandler} satisfies this).
264
264
  * @returns An {@link InferredSchema} describing the parameters, or `null` when