@signalwire/sdk 3.7.2 → 3.10.3
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/CHANGELOG.md +201 -0
- package/README.md +1 -0
- package/dist/AgentBase.d.ts +107 -2
- package/dist/AgentBase.js +259 -13
- package/dist/AgentBase.js.map +1 -1
- package/dist/AiEvents.d.ts +70 -0
- package/dist/AiEvents.js +94 -0
- package/dist/AiEvents.js.map +1 -0
- package/dist/ContextBuilder.d.ts +215 -14
- package/dist/ContextBuilder.js +441 -14
- package/dist/ContextBuilder.js.map +1 -1
- package/dist/FunctionResult.d.ts +146 -1
- package/dist/FunctionResult.js +188 -2
- package/dist/FunctionResult.js.map +1 -1
- package/dist/PostPrompt.d.ts +19 -0
- package/dist/PostPrompt.js +43 -0
- package/dist/PostPrompt.js.map +1 -1
- package/dist/SWMLService.d.ts +97 -1
- package/dist/SWMLService.js +129 -2
- package/dist/SWMLService.js.map +1 -1
- package/dist/SemanticGate.d.ts +61 -1
- package/dist/SemanticGate.js +108 -15
- package/dist/SemanticGate.js.map +1 -1
- package/dist/SwaigFunction.d.ts +85 -9
- package/dist/SwaigFunction.js +214 -58
- package/dist/SwaigFunction.js.map +1 -1
- package/dist/ToolMiddleware.d.ts +82 -0
- package/dist/ToolMiddleware.js +131 -0
- package/dist/ToolMiddleware.js.map +1 -0
- package/dist/TypeInference.d.ts +1 -1
- package/dist/TypeInference.js.map +1 -1
- package/dist/cli/tsdocs/api-index.json +1 -1
- package/dist/cli/tsdocs/topics.js +24 -4
- package/dist/cli/tsdocs/topics.js.map +1 -1
- package/dist/index.d.ts +22 -8
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/llms.txt +1 -0
- package/dist/patterns/Proposal.d.ts +148 -0
- package/dist/patterns/Proposal.js +214 -0
- package/dist/patterns/Proposal.js.map +1 -0
- package/dist/patterns/RequestList.d.ts +138 -0
- package/dist/patterns/RequestList.js +171 -0
- package/dist/patterns/RequestList.js.map +1 -0
- package/dist/skills/SkillBase.d.ts +24 -1
- package/dist/skills/SkillBase.js +12 -1
- package/dist/skills/SkillBase.js.map +1 -1
- package/dist/speech/numbers.d.ts +66 -0
- package/dist/speech/numbers.js +281 -0
- package/dist/speech/numbers.js.map +1 -0
- package/dist/speech/spelling.d.ts +71 -0
- package/dist/speech/spelling.js +294 -0
- package/dist/speech/spelling.js.map +1 -0
- package/dist/testing/CallSimulator.d.ts +391 -0
- package/dist/testing/CallSimulator.js +966 -0
- package/dist/testing/CallSimulator.js.map +1 -0
- package/docs/agent-guide.md +2 -2
- package/docs/api-reference.md +279 -22
- package/docs/architecture.md +8 -4
- package/docs/cli-guide.md +2 -0
- package/docs/contexts-guide.md +75 -4
- package/docs/conversation_patterns.md +257 -0
- package/docs/mcp_integration.md +1 -1
- package/docs/pgi_agent_guide.md +5 -0
- package/docs/programmatically_governed_inference.md +2 -2
- package/docs/swaig-reference.md +98 -6
- package/package.json +1 -1
package/dist/SwaigFunction.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { FunctionResult, type SwaigResultDict } from './FunctionResult.js';
|
|
5
5
|
import type { SwaigRequest } from './SwaigContracts.js';
|
|
6
6
|
import type { AgentBase } from './AgentBase.js';
|
|
7
|
+
import type { SWMLService } from './SWMLService.js';
|
|
8
|
+
import { type ToolMiddleware } from './ToolMiddleware.js';
|
|
7
9
|
import { type FillerPhrases, type SemanticGate } from './SemanticGate.js';
|
|
8
10
|
/** @internal How many argument validators have been compiled (for tests). */
|
|
9
11
|
export declare function _compiledValidatorCount(): number;
|
|
@@ -42,6 +44,17 @@ export declare function isFullParameterSchema(parameters: Record<string, unknown
|
|
|
42
44
|
* @returns A full JSON Schema object.
|
|
43
45
|
*/
|
|
44
46
|
export declare function normalizeParameters(parameters: Record<string, unknown> | undefined, required?: string[]): Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* The argument a vouched tool adds, which the model sets to say every other
|
|
49
|
+
* argument came from the user.
|
|
50
|
+
*/
|
|
51
|
+
export declare const VOUCHED_PARAMETER = "data_supplied_by_user";
|
|
52
|
+
/** The description of {@link VOUCHED_PARAMETER}, as the model reads it. */
|
|
53
|
+
export declare 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.";
|
|
54
|
+
/** The `web_hook_url` that has the platform run its own implementation of a function, by name. */
|
|
55
|
+
export declare const NATIVE_WEBHOOK_URL = "native";
|
|
56
|
+
/** The tool prompt the model gets when it calls a vouched tool without vouching for its arguments. */
|
|
57
|
+
export declare const VOUCHED_PROMPT = "Get the answer from the user before using this tool.";
|
|
45
58
|
/**
|
|
46
59
|
* Handler function for a SWAIG tool invocation.
|
|
47
60
|
* @param args - Parsed arguments extracted by the AI from user speech.
|
|
@@ -52,7 +65,7 @@ export declare function normalizeParameters(parameters: Record<string, unknown>
|
|
|
52
65
|
* caller runs {@link SwaigFunction.execute} directly.
|
|
53
66
|
* @returns A FunctionResult, a plain object with a response key, a string, or a Promise of any of these.
|
|
54
67
|
*/
|
|
55
|
-
export type SwaigHandler = (args: Record<string, unknown>, rawData: SwaigRequest, agent?: AgentBase) => FunctionResult | Record<string, unknown> | string | Promise<FunctionResult | Record<string, unknown> | string>;
|
|
68
|
+
export type SwaigHandler = (args: Record<string, unknown>, rawData: SwaigRequest, agent?: AgentBase) => FunctionResult | Record<string, unknown> | string | null | undefined | void | Promise<FunctionResult | Record<string, unknown> | string | null | undefined | void>;
|
|
56
69
|
/**
|
|
57
70
|
* Context passed to an {@link SwaigErrorHandler} when a tool handler throws.
|
|
58
71
|
*/
|
|
@@ -78,8 +91,12 @@ export interface SwaigErrorContext {
|
|
|
78
91
|
*/
|
|
79
92
|
export type SwaigErrorHandler = (error: unknown, context: SwaigErrorContext) => FunctionResult | void | Promise<FunctionResult | void>;
|
|
80
93
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
94
|
+
* The message a tool handler that threw gave the model before 3.8.0.
|
|
95
|
+
*
|
|
96
|
+
* @deprecated A handler that throws, with no {@link SwaigErrorHandler}
|
|
97
|
+
* response and no `errorMessage`, now gives the model
|
|
98
|
+
* {@link toolErrorResult}: the outcome is unknown, so it mustn't say the
|
|
99
|
+
* action worked or that it didn't. Kept for code that imports it.
|
|
83
100
|
*/
|
|
84
101
|
export declare const DEFAULT_SWAIG_ERROR_MESSAGE = "Sorry, I couldn't complete that action. Please try again or contact support if the issue persists.";
|
|
85
102
|
/** Configuration options for creating a SwaigFunction. */
|
|
@@ -160,16 +177,47 @@ export interface SwaigFunctionOptions {
|
|
|
160
177
|
isTypedHandler?: boolean;
|
|
161
178
|
/**
|
|
162
179
|
* Per-tool error hook. Invoked when this tool's handler throws, before the
|
|
163
|
-
* default error response is produced. See `SwaigErrorHandler`.
|
|
180
|
+
* default error response is produced. See `SwaigErrorHandler`. A
|
|
181
|
+
* {@link ToolRefusal} doesn't reach it.
|
|
164
182
|
*/
|
|
165
183
|
onError?: SwaigErrorHandler;
|
|
166
184
|
/**
|
|
167
185
|
* Per-tool override for the user-facing message returned when the handler
|
|
168
|
-
* throws and no {@link onError} hook supplies a response.
|
|
169
|
-
*
|
|
170
|
-
*
|
|
186
|
+
* throws and no {@link onError} hook supplies a response. Without it, the
|
|
187
|
+
* model is told the function failed before it finished, so whether it took
|
|
188
|
+
* effect is unknown, with a tool prompt not to tell the caller it worked or
|
|
189
|
+
* that it didn't.
|
|
171
190
|
*/
|
|
172
191
|
errorMessage?: string;
|
|
192
|
+
/**
|
|
193
|
+
* `true` for a tool whose arguments must come from the user, not from the
|
|
194
|
+
* model's guesses. The tool gets a required boolean argument,
|
|
195
|
+
* `data_supplied_by_user`, in which the model says they did. Unless it's
|
|
196
|
+
* `true`, the handler doesn't run, and the model gets "<name> was not run."
|
|
197
|
+
* with the tool prompt "Get the answer from the user before using this
|
|
198
|
+
* tool." The handler never sees the argument.
|
|
199
|
+
*/
|
|
200
|
+
vouched?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* `true` to let the model send null for an optional argument, as providers
|
|
203
|
+
* with strict schemas require: each argument that isn't required takes null
|
|
204
|
+
* as well as its type, and a null reaches the handler as an argument not
|
|
205
|
+
* given. Left out, it follows the agent's
|
|
206
|
+
* `setNullableOptionalParameters()`.
|
|
207
|
+
*/
|
|
208
|
+
nullableOptional?: boolean;
|
|
209
|
+
/**
|
|
210
|
+
* `true` when the handler reads the conversation, as `callerTurns(rawData)`
|
|
211
|
+
* does. It turns on the agent's `swaig_post_conversation` when the SWML is
|
|
212
|
+
* rendered, so every tool request carries the call log, unless that param
|
|
213
|
+
* was set to `false`.
|
|
214
|
+
*/
|
|
215
|
+
needsConversation?: boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Middleware that runs around this tool's calls only, inside the
|
|
218
|
+
* service's ({@link SWMLService.addToolMiddleware}).
|
|
219
|
+
*/
|
|
220
|
+
middleware?: readonly ToolMiddleware[];
|
|
173
221
|
}
|
|
174
222
|
/**
|
|
175
223
|
* A SWAIG function — exactly the same concept as a "tool" in native
|
|
@@ -233,6 +281,14 @@ export declare class SwaigFunction {
|
|
|
233
281
|
onError?: SwaigErrorHandler;
|
|
234
282
|
/** Per-tool user-facing error message override. */
|
|
235
283
|
errorMessage?: string;
|
|
284
|
+
/** Whether the model must vouch that the arguments came from the user. */
|
|
285
|
+
vouched: boolean;
|
|
286
|
+
/** Whether optional arguments take null, or undefined for the agent's setting. */
|
|
287
|
+
nullableOptional?: boolean;
|
|
288
|
+
/** Whether the handler reads the conversation (turns on `swaig_post_conversation`). */
|
|
289
|
+
needsConversation: boolean;
|
|
290
|
+
/** Middleware around this tool's calls, inside the service's. */
|
|
291
|
+
middleware: readonly ToolMiddleware[];
|
|
236
292
|
/**
|
|
237
293
|
* Create a new SwaigFunction.
|
|
238
294
|
*
|
|
@@ -249,6 +305,24 @@ export declare class SwaigFunction {
|
|
|
249
305
|
*/
|
|
250
306
|
constructor(opts: SwaigFunctionOptions);
|
|
251
307
|
private ensureParameterStructure;
|
|
308
|
+
/**
|
|
309
|
+
* The parameter schema the model sees: the tool's own, with optional
|
|
310
|
+
* arguments widened to take null when they do, and a vouched tool's
|
|
311
|
+
* `data_supplied_by_user` added.
|
|
312
|
+
* @param nullableDefault - The agent's default for whether optional
|
|
313
|
+
* arguments take null, used when this tool doesn't set its own.
|
|
314
|
+
* @internal
|
|
315
|
+
*/
|
|
316
|
+
_parameterSchema(nullableDefault?: boolean): Record<string, unknown>;
|
|
317
|
+
/** Whether optional arguments take null: this tool's own setting, else the agent's. */
|
|
318
|
+
private _nullable;
|
|
319
|
+
/** What the model gets for a vouched call it didn't vouch for, or null. */
|
|
320
|
+
private _vouchedRefusal;
|
|
321
|
+
/**
|
|
322
|
+
* The arguments the handler gets: a vouched tool's own is removed, and a
|
|
323
|
+
* null for an optional argument that takes null is an argument not given.
|
|
324
|
+
*/
|
|
325
|
+
private _handlerArgs;
|
|
252
326
|
/**
|
|
253
327
|
* Validate arguments against the parameter JSON schema using full
|
|
254
328
|
* JSON Schema Draft-7 validation (via ajv).
|
|
@@ -263,10 +337,12 @@ export declare class SwaigFunction {
|
|
|
263
337
|
* considered valid — matching Python's early-return path.
|
|
264
338
|
*
|
|
265
339
|
* @param args - Arguments to validate.
|
|
340
|
+
* @param nullableDefault - The agent's default for whether optional
|
|
341
|
+
* arguments take null, used when this tool doesn't set its own.
|
|
266
342
|
* @returns A tuple of `[isValid, errors]`. When no validation is needed
|
|
267
343
|
* (empty schema), returns `[true, []]`.
|
|
268
344
|
*/
|
|
269
|
-
validateArgs(args: Record<string, unknown
|
|
345
|
+
validateArgs(args: Record<string, unknown>, nullableDefault?: boolean): [boolean, string[]];
|
|
270
346
|
/**
|
|
271
347
|
* Invoke the handler with the given arguments and return a serialized result.
|
|
272
348
|
* @param args - Parsed arguments from the AI.
|
|
@@ -280,7 +356,7 @@ export declare class SwaigFunction {
|
|
|
280
356
|
* request's configured copy.
|
|
281
357
|
* @internal
|
|
282
358
|
*/
|
|
283
|
-
_executeAs(agent: AgentBase | undefined, args: Record<string, unknown>, rawData?: SwaigRequest, agentOnError?: SwaigErrorHandler): Promise<SwaigResultDict>;
|
|
359
|
+
_executeAs(agent: AgentBase | undefined, args: Record<string, unknown>, rawData?: SwaigRequest, agentOnError?: SwaigErrorHandler, service?: SWMLService | undefined): Promise<SwaigResultDict>;
|
|
284
360
|
/**
|
|
285
361
|
* Serialize this function to the SWAIG wire format for inclusion in SWML.
|
|
286
362
|
* @param baseUrl - The base URL of the agent server.
|
package/dist/SwaigFunction.js
CHANGED
|
@@ -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
|
-
*
|
|
93
|
-
*
|
|
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
|
/**
|
|
@@ -155,6 +187,14 @@ export class SwaigFunction {
|
|
|
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
|
-
|
|
204
|
-
|
|
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
|
-
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
`
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
320
|
-
|
|
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
|
-
|
|
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
|
}
|
|
326
482
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwaigFunction.js","sourceRoot":"","sources":["../src/SwaigFunction.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAC3E,OAAO,E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,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
|
+
}
|