@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spelling.js","sourceRoot":"","sources":["../../src/speech/spelling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,kBAAkB;AAClB,MAAM,YAAY,GAA2B;IAC3C,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG;IACf,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IACzB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IACpC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAChB,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG;IACf,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IACzB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAC1B,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG;IAC/B,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAChB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAChB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAChB,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,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI;YAAE,CAAC,EAAE,CAAC;QAC3D,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO;QAClB,KAAK,CAAC,CAAC,CAAE,EAAE,CAAC;QACZ,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;YAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAE,GAAG,CAAC,CAAC;IAClE,CAAC;AACH,CAAC;AAED,kEAAkE;AAClE,QAAQ,CAAC,CAAC,OAAO,CAAI,KAAgC;IACnD,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;QAAE,OAAO;IAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACjC,SAAS,CAAC;QACR,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAE,CAAC,MAAM,GAAG,CAAC;YAAE,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QACnE,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO;QAClB,KAAK,CAAC,CAAC,CAAE,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,281 @@
1
+ /**
2
+ * A call, simulated in a test: the agent's tools, steps and state, without the
3
+ * platform or a model.
4
+ *
5
+ * {@link CallSimulator} reads the agent's rendered SWML, as the platform would,
6
+ * and plays the model's side: the test says what the caller says and which
7
+ * tools the model calls. Each call is checked as the platform checks it: a tool
8
+ * the current step doesn't offer doesn't run, and a gated tool runs only when
9
+ * the test's gate callback lets it. A result's actions change the simulated
10
+ * call: global data and `semantic_state`, the step and context, which functions
11
+ * are on, `say`, and the end of the call.
12
+ *
13
+ * It's an approximation of the platform, for testing your code's decisions. It
14
+ * doesn't run a model, DataMap tools (give a stub), gather questions, or the
15
+ * gates' decision model (give a callback). It renders and runs tools on the
16
+ * agent itself: a dynamic config callback's per-request copy isn't made.
17
+ *
18
+ * {@link RequestRecorder} records real tool requests for
19
+ * {@link CallSimulator.replay}.
20
+ */
21
+ import type { AgentBase } from '../AgentBase.js';
22
+ import type { CallNext, ToolMiddleware } from '../ToolMiddleware.js';
23
+ type Json = Record<string, unknown>;
24
+ /**
25
+ * A gate callback: `gates(gate, simulator, args)` returns true or a probability
26
+ * at or above the gate's threshold to pass, false or one below it to fail, or
27
+ * "unclear". It may return a promise of the answer.
28
+ */
29
+ export type GateCallback = (gate: Json, simulator: CallSimulator, args: Json) => unknown;
30
+ /** A result for a tool that doesn't run locally: a FunctionResult, a result dict or text. */
31
+ export type ToolStub = (args: Json) => unknown;
32
+ /** A tool result named a tool the step it left the call in doesn't offer. */
33
+ export declare class ToolMentionError extends Error {
34
+ name: string;
35
+ }
36
+ /** What one tool call came to in the simulation. */
37
+ export declare class SimulatedCall {
38
+ /** The tool's name. */
39
+ name: string;
40
+ /** The arguments the model sent. */
41
+ args: Json;
42
+ /** The result, as the platform gets it. */
43
+ result: Json;
44
+ /** Whether the tool's handler (or stub) ran. */
45
+ ran: boolean;
46
+ /**
47
+ * Why it didn't: "step" for a tool the step doesn't offer, or the id of the
48
+ * gate that blocked it.
49
+ */
50
+ blockedBy: string | null;
51
+ /**
52
+ * @param name - The tool's name.
53
+ * @param args - The arguments the model sent.
54
+ * @param result - The result, as the platform gets it.
55
+ * @param opts - `ran`, and `blockedBy` for a call that didn't run.
56
+ */
57
+ constructor(name: string, args: Json, result: Json, opts: {
58
+ ran: boolean;
59
+ blockedBy?: string | null;
60
+ });
61
+ /** The result's text: its response, or its tool_result. */
62
+ get response(): string;
63
+ /** The result's tool_prompt, or null when it has none. */
64
+ get toolPrompt(): string | null;
65
+ /** The result's actions. */
66
+ get actions(): Json[];
67
+ /** The call, for a test's failure message. */
68
+ toString(): string;
69
+ }
70
+ /** Options for a {@link CallSimulator}. */
71
+ export interface CallSimulatorOptions {
72
+ /** The call's id, as the agent's tools see it. Default "simulated-call". */
73
+ callId?: string;
74
+ /** The answer to each semantic gate, in place of the decision model. Without one, every gate passes. */
75
+ gates?: GateCallback;
76
+ /**
77
+ * Results for tools that don't run locally, such as DataMap tools, by name:
78
+ * `fn(args)` returning a FunctionResult, a dict or text, or a promise of one.
79
+ */
80
+ stubs?: Record<string, ToolStub>;
81
+ /** Global data to start with, over the agent's own. */
82
+ globalData?: Json;
83
+ /**
84
+ * True to fail a call whose result, or the gate output that blocked it,
85
+ * names a tool the step it leaves the call in doesn't offer, after its own
86
+ * step or context change: the model reads the name and may call a tool it
87
+ * doesn't have. `call()` then rejects with a {@link ToolMentionError}. Names
88
+ * are found as rendering finds them in step text ({@link namedTools}).
89
+ */
90
+ checkToolMentions?: boolean;
91
+ }
92
+ /**
93
+ * A simulated call to an agent, for tests.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import assert from 'node:assert';
98
+ * import { AgentBase, CallSimulator } from '@signalwire/sdk';
99
+ *
100
+ * declare const agent: AgentBase; // an agent with review_order and place_order steps
101
+ * const sim = new CallSimulator(agent, { gates: () => true });
102
+ * sim.caller("I'd like a large tea");
103
+ * assert.equal((await sim.call('place_order', { item: 'tea' })).ran, false); // not offered yet
104
+ * await sim.call('review_order', { item: 'large tea' });
105
+ * sim.caller('yes');
106
+ * assert.equal((await sim.call('place_order')).ran, true);
107
+ * assert.equal(sim.step, 'done');
108
+ * ```
109
+ */
110
+ export declare class CallSimulator {
111
+ /** The agent. */
112
+ agent: AgentBase;
113
+ /** The call's id, as the agent's tools see it. */
114
+ callId: string;
115
+ /** The AI verb's params, as rendered. */
116
+ params: Json;
117
+ /** The call's global data. */
118
+ globalData: Json;
119
+ /** The agent's functions, as rendered, by name. */
120
+ functions: Record<string, Json>;
121
+ /** The conversation so far, as call log entries. */
122
+ callLog: Json[];
123
+ /** Whether a result ended the call. */
124
+ ended: boolean;
125
+ /** The back_to_back_functions setting, as the last result left it. */
126
+ chaining: unknown;
127
+ /** Whether a result asked the model to wait for the caller. */
128
+ waitingForUser: boolean;
129
+ /** Every tool call so far. */
130
+ calls: SimulatedCall[];
131
+ /**
132
+ * The semantic gate marks set, by name: the length of the call log when each
133
+ * was set, so `callLog.slice(marks.get(name))` is since it.
134
+ */
135
+ marks: Map<string, number>;
136
+ /** The current context, null without contexts. */
137
+ context: string | null;
138
+ /** The current step, null without contexts. */
139
+ step: string | null;
140
+ private readonly gates?;
141
+ private readonly stubs;
142
+ private readonly checkToolMentions;
143
+ private readonly contexts;
144
+ private readonly toggled;
145
+ private toolCalls;
146
+ private stepFunctions;
147
+ /**
148
+ * @param agent - The agent.
149
+ * @param opts - `callId`, `gates`, `stubs` and `globalData`.
150
+ */
151
+ constructor(agent: AgentBase, opts?: CallSimulatorOptions);
152
+ /**
153
+ * The caller says `text`.
154
+ * @param text - What they say.
155
+ * @returns This simulator, for chaining.
156
+ */
157
+ caller(text: string): this;
158
+ /**
159
+ * The agent says `text`, as the model's reply.
160
+ * @param text - What it says.
161
+ * @returns This simulator, for chaining.
162
+ */
163
+ agentSays(text: string): this;
164
+ /** `globalData.semantic_state`, or undefined. */
165
+ get semanticState(): unknown;
166
+ /**
167
+ * The tools the model is offered now, as the current step allows, in the
168
+ * agent's order, with the navigation tools after them.
169
+ * @returns Their names.
170
+ */
171
+ offered(): string[];
172
+ /**
173
+ * The model calls `name` with `args`.
174
+ *
175
+ * The call is checked as the platform checks it: a tool the current step
176
+ * doesn't offer, or one the platform doesn't know, doesn't run, and the model
177
+ * gets the platform's reply naming the tools it has. A gated tool runs only
178
+ * when every gate passes. Otherwise the tool runs as the `/swaig` route runs
179
+ * it, with a request like the platform's, and its result's actions change
180
+ * the call.
181
+ *
182
+ * @param name - The tool.
183
+ * @param args - Its arguments.
184
+ * @returns What the call came to.
185
+ * @throws Error when the call has ended, or for a DataMap tool without a stub.
186
+ * @throws {ToolMentionError} With `checkToolMentions`, for a result that names a
187
+ * tool the step it leaves the call in doesn't offer.
188
+ */
189
+ call(name: string, args?: Json): Promise<SimulatedCall>;
190
+ private checkMentions;
191
+ /**
192
+ * Run recorded tool requests against the agent again, as they came.
193
+ *
194
+ * Each request is a SWAIG request body, as {@link RequestRecorder} records
195
+ * it, with its own call data; the simulated call's state isn't used or
196
+ * changed. Use it to check that changed code still gives the results it gave
197
+ * on real calls.
198
+ *
199
+ * @param requests - The requests.
200
+ * @returns What each request came to, in order.
201
+ */
202
+ replay(requests: Iterable<Json>): Promise<SimulatedCall[]>;
203
+ /** The agent's answer to a call, as the `/swaig` route gives it. */
204
+ private run;
205
+ private dispatch;
206
+ private checkGates;
207
+ private blocked;
208
+ private navigate;
209
+ private request;
210
+ private apply;
211
+ private applyOne;
212
+ private enterContext;
213
+ private enterStep;
214
+ private stepsOf;
215
+ private currentStep;
216
+ private findStep;
217
+ private followingStep;
218
+ private validContexts;
219
+ private tools;
220
+ /** The current context's other steps whose functions include `name`, in step order. */
221
+ private stepsOffering;
222
+ /** The platform's reply to a call of a tool it won't run now. */
223
+ private unavailable;
224
+ private log;
225
+ }
226
+ /** Options for a {@link RequestRecorder}. */
227
+ export interface RequestRecorderOptions {
228
+ /** The most requests kept in `requests`, newest kept. Default 1000. */
229
+ limit?: number;
230
+ }
231
+ /**
232
+ * Tool middleware that records each tool request, for
233
+ * {@link CallSimulator.replay}.
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * import { AgentBase, CallSimulator, RequestRecorder } from '@signalwire/sdk';
238
+ *
239
+ * declare const agent: AgentBase;
240
+ * const recorder = new RequestRecorder('tool_requests.jsonl');
241
+ * agent.addToolMiddleware(recorder.middleware);
242
+ * // ...
243
+ * await new CallSimulator(agent).replay(RequestRecorder.load('tool_requests.jsonl'));
244
+ * ```
245
+ *
246
+ * The requests carry what the caller said and the call's data: keep the file
247
+ * where you'd keep call recordings.
248
+ */
249
+ export declare class RequestRecorder {
250
+ /** A file each request is appended to, one JSON object a line. */
251
+ readonly path: string | null;
252
+ /** The most requests kept in `requests`. */
253
+ readonly limit: number;
254
+ /** The requests recorded, oldest first. */
255
+ requests: Json[];
256
+ /** The file's writes, in the order the requests came. */
257
+ private writes;
258
+ /**
259
+ * @param path - A file to append each request to, one JSON object a line.
260
+ * @param opts - `limit`.
261
+ */
262
+ constructor(path?: string | null, opts?: RequestRecorderOptions);
263
+ /** This recorder as a {@link ToolMiddleware}. */
264
+ readonly middleware: ToolMiddleware;
265
+ /**
266
+ * Record a request, then run the rest of the chain.
267
+ * @param name - The tool's name.
268
+ * @param args - The arguments.
269
+ * @param rawData - The SWAIG request.
270
+ * @param callNext - The rest of the chain.
271
+ * @returns The call's result.
272
+ */
273
+ handle(name: string, args: Json, rawData: Json, callNext: CallNext): Promise<unknown>;
274
+ /**
275
+ * The requests a recorder wrote to `path`.
276
+ * @param path - The file.
277
+ * @returns The requests, in order.
278
+ */
279
+ static load(path: string): Json[];
280
+ }
281
+ export {};