@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
|
@@ -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;IA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CAAC;QACnE,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO;QAClB,KAAK,CAAC,CAAC,CAAE,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,391 @@
|
|
|
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,
|
|
15
|
+
* consolidation, the sliding window, or the gates' decision model (give a
|
|
16
|
+
* callback). {@link CallSimulator.modelView} shows what the model gets after
|
|
17
|
+
* the steps' history modes, and {@link CallSimulator.gateConversation} the
|
|
18
|
+
* dialogue a gate judges. It renders and runs tools on the
|
|
19
|
+
* agent itself: a dynamic config callback's per-request copy isn't made.
|
|
20
|
+
*
|
|
21
|
+
* {@link RequestRecorder} records real tool requests for
|
|
22
|
+
* {@link CallSimulator.replay}.
|
|
23
|
+
*/
|
|
24
|
+
import type { AgentBase } from '../AgentBase.js';
|
|
25
|
+
import type { CallNext, ToolMiddleware } from '../ToolMiddleware.js';
|
|
26
|
+
type Json = Record<string, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* A gate callback: `gates(gate, simulator, args)` returns true or a probability
|
|
29
|
+
* at or above the gate's threshold to pass, false or one below it to fail, or
|
|
30
|
+
* "unclear". It may return a promise of the answer.
|
|
31
|
+
*/
|
|
32
|
+
export type GateCallback = (gate: Json, simulator: CallSimulator, args: Json) => unknown;
|
|
33
|
+
/** A result for a tool that doesn't run locally: a FunctionResult, a result dict or text. */
|
|
34
|
+
export type ToolStub = (args: Json) => unknown;
|
|
35
|
+
/** A tool result named a tool the step it left the call in doesn't offer. */
|
|
36
|
+
export declare class ToolMentionError extends Error {
|
|
37
|
+
name: string;
|
|
38
|
+
}
|
|
39
|
+
/** What one tool call came to in the simulation. */
|
|
40
|
+
export declare class SimulatedCall {
|
|
41
|
+
/** The tool's name. */
|
|
42
|
+
name: string;
|
|
43
|
+
/** The arguments the model sent. */
|
|
44
|
+
args: Json;
|
|
45
|
+
/** The result, as the platform gets it. */
|
|
46
|
+
result: Json;
|
|
47
|
+
/** Whether the tool's handler (or stub) ran. */
|
|
48
|
+
ran: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Why it didn't: "step" for a tool the step doesn't offer, or the id of the
|
|
51
|
+
* gate that blocked it.
|
|
52
|
+
*/
|
|
53
|
+
blockedBy: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* @param name - The tool's name.
|
|
56
|
+
* @param args - The arguments the model sent.
|
|
57
|
+
* @param result - The result, as the platform gets it.
|
|
58
|
+
* @param opts - `ran`, and `blockedBy` for a call that didn't run.
|
|
59
|
+
*/
|
|
60
|
+
constructor(name: string, args: Json, result: Json, opts: {
|
|
61
|
+
ran: boolean;
|
|
62
|
+
blockedBy?: string | null;
|
|
63
|
+
});
|
|
64
|
+
/** The result's text: its response, or its tool_result. */
|
|
65
|
+
get response(): string;
|
|
66
|
+
/** The result's tool_prompt, or null when it has none. */
|
|
67
|
+
get toolPrompt(): string | null;
|
|
68
|
+
/** The result's actions. */
|
|
69
|
+
get actions(): Json[];
|
|
70
|
+
/** The call, for a test's failure message. */
|
|
71
|
+
toString(): string;
|
|
72
|
+
}
|
|
73
|
+
/** Options for a {@link CallSimulator}. */
|
|
74
|
+
export interface CallSimulatorOptions {
|
|
75
|
+
/** The call's id, as the agent's tools see it. Default "simulated-call". */
|
|
76
|
+
callId?: string;
|
|
77
|
+
/** The answer to each semantic gate, in place of the decision model. Without one, every gate passes. */
|
|
78
|
+
gates?: GateCallback;
|
|
79
|
+
/**
|
|
80
|
+
* Results for tools that don't run locally, such as DataMap tools, by name:
|
|
81
|
+
* `fn(args)` returning a FunctionResult, a dict or text, or a promise of one.
|
|
82
|
+
*/
|
|
83
|
+
stubs?: Record<string, ToolStub>;
|
|
84
|
+
/** Global data to start with, over the agent's own. */
|
|
85
|
+
globalData?: Json;
|
|
86
|
+
/**
|
|
87
|
+
* True to fail a call whose result, or the gate output that blocked it,
|
|
88
|
+
* names a tool the step it leaves the call in doesn't offer, after its own
|
|
89
|
+
* step or context change: the model reads the name and may call a tool it
|
|
90
|
+
* doesn't have. `call()` then rejects with a {@link ToolMentionError}. Names
|
|
91
|
+
* are found as rendering finds them in step text ({@link namedTools}).
|
|
92
|
+
*/
|
|
93
|
+
checkToolMentions?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A simulated call to an agent, for tests.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import assert from 'node:assert';
|
|
101
|
+
* import { AgentBase, CallSimulator } from '@signalwire/sdk';
|
|
102
|
+
*
|
|
103
|
+
* declare const agent: AgentBase; // an agent with review_order and place_order steps
|
|
104
|
+
* const sim = new CallSimulator(agent, { gates: () => true });
|
|
105
|
+
* sim.caller("I'd like a large tea");
|
|
106
|
+
* assert.equal((await sim.call('place_order', { item: 'tea' })).ran, false); // not offered yet
|
|
107
|
+
* await sim.call('review_order', { item: 'large tea' });
|
|
108
|
+
* sim.caller('yes');
|
|
109
|
+
* assert.equal((await sim.call('place_order')).ran, true);
|
|
110
|
+
* assert.equal(sim.step, 'done');
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare class CallSimulator {
|
|
114
|
+
/** The agent. */
|
|
115
|
+
agent: AgentBase;
|
|
116
|
+
/** The call's id, as the agent's tools see it. */
|
|
117
|
+
callId: string;
|
|
118
|
+
/** The AI verb's params, as rendered. */
|
|
119
|
+
params: Json;
|
|
120
|
+
/** The call's global data. */
|
|
121
|
+
globalData: Json;
|
|
122
|
+
/** The agent's functions, as rendered, by name. */
|
|
123
|
+
functions: Record<string, Json>;
|
|
124
|
+
/** The conversation so far, as call log entries. */
|
|
125
|
+
callLog: Json[];
|
|
126
|
+
/** Whether a result ended the call. */
|
|
127
|
+
ended: boolean;
|
|
128
|
+
/** The back_to_back_functions setting, as the last result left it. */
|
|
129
|
+
chaining: unknown;
|
|
130
|
+
/** Whether a result asked the model to wait for the caller. */
|
|
131
|
+
waitingForUser: boolean;
|
|
132
|
+
/** Every tool call so far. */
|
|
133
|
+
calls: SimulatedCall[];
|
|
134
|
+
/**
|
|
135
|
+
* The semantic gate marks set, by name: the call log position where the
|
|
136
|
+
* action list that set each began, so `callLog.slice(marks.get(name))` is
|
|
137
|
+
* since it.
|
|
138
|
+
*/
|
|
139
|
+
marks: Map<string, number>;
|
|
140
|
+
/** The current context, null without contexts. */
|
|
141
|
+
context: string | null;
|
|
142
|
+
/** The current step, null without contexts. */
|
|
143
|
+
step: string | null;
|
|
144
|
+
private readonly gates?;
|
|
145
|
+
private readonly stubs;
|
|
146
|
+
private readonly checkToolMentions;
|
|
147
|
+
private readonly contexts;
|
|
148
|
+
private readonly toggled;
|
|
149
|
+
private toolCalls;
|
|
150
|
+
private stepFunctions;
|
|
151
|
+
private readonly kinds;
|
|
152
|
+
private readonly hidden;
|
|
153
|
+
private readonly isolatedEntries;
|
|
154
|
+
private readonly cleared;
|
|
155
|
+
private readonly says;
|
|
156
|
+
private injectPending;
|
|
157
|
+
private callStart;
|
|
158
|
+
private enteredAt;
|
|
159
|
+
private deferred;
|
|
160
|
+
private instruction;
|
|
161
|
+
private readonly shown;
|
|
162
|
+
private proposalAt;
|
|
163
|
+
private actionStart;
|
|
164
|
+
private resetStep;
|
|
165
|
+
/**
|
|
166
|
+
* @param agent - The agent.
|
|
167
|
+
* @param opts - `callId`, `gates`, `stubs` and `globalData`.
|
|
168
|
+
*/
|
|
169
|
+
constructor(agent: AgentBase, opts?: CallSimulatorOptions);
|
|
170
|
+
/**
|
|
171
|
+
* The caller says `text`.
|
|
172
|
+
* @param text - What they say.
|
|
173
|
+
* @returns This simulator, for chaining.
|
|
174
|
+
*/
|
|
175
|
+
caller(text: string): this;
|
|
176
|
+
/**
|
|
177
|
+
* The agent says `text`, as the model's reply. The actions of a
|
|
178
|
+
* `post_process` result waiting for it run after it.
|
|
179
|
+
* @param text - What it says.
|
|
180
|
+
* @returns This simulator, for chaining.
|
|
181
|
+
*/
|
|
182
|
+
agentSays(text: string): this;
|
|
183
|
+
/** `globalData.semantic_state`, or undefined. */
|
|
184
|
+
get semanticState(): unknown;
|
|
185
|
+
/**
|
|
186
|
+
* The tools the model is offered now, as the current step allows, in the
|
|
187
|
+
* agent's order, with the navigation tools after them.
|
|
188
|
+
* @returns Their names.
|
|
189
|
+
*/
|
|
190
|
+
offered(): string[];
|
|
191
|
+
/**
|
|
192
|
+
* The model calls `name` with `args`.
|
|
193
|
+
*
|
|
194
|
+
* The call is checked as the platform checks it: a tool the current step
|
|
195
|
+
* doesn't offer, or one the platform doesn't know, doesn't run, and the model
|
|
196
|
+
* gets the platform's reply naming the tools it has. A gated tool runs only
|
|
197
|
+
* when every gate passes. Otherwise the tool runs as the `/swaig` route runs
|
|
198
|
+
* it, with a request like the platform's, and its result's actions change
|
|
199
|
+
* the call. A result with `post_process` runs its actions after the model's
|
|
200
|
+
* reply to it, as the platform does: give the reply with {@link agentSays}. A
|
|
201
|
+
* newer such result replaces actions still waiting.
|
|
202
|
+
*
|
|
203
|
+
* @param name - The tool.
|
|
204
|
+
* @param args - Its arguments.
|
|
205
|
+
* @returns What the call came to.
|
|
206
|
+
* @throws Error when the call has ended, or for a DataMap tool without a stub.
|
|
207
|
+
* @throws {ToolMentionError} With `checkToolMentions`, for a result that names a
|
|
208
|
+
* tool the step it leaves the call in doesn't offer.
|
|
209
|
+
*/
|
|
210
|
+
call(name: string, args?: Json): Promise<SimulatedCall>;
|
|
211
|
+
private checkMentions;
|
|
212
|
+
/**
|
|
213
|
+
* Run recorded tool requests against the agent again, as they came.
|
|
214
|
+
*
|
|
215
|
+
* Each request is a SWAIG request body, as {@link RequestRecorder} records
|
|
216
|
+
* it, with its own call data; the simulated call's state isn't used or
|
|
217
|
+
* changed. Use it to check that changed code still gives the results it gave
|
|
218
|
+
* on real calls.
|
|
219
|
+
*
|
|
220
|
+
* @param requests - The requests.
|
|
221
|
+
* @returns What each request came to, in order.
|
|
222
|
+
*/
|
|
223
|
+
replay(requests: Iterable<Json>): Promise<SimulatedCall[]>;
|
|
224
|
+
/** The agent's answer to a call, as the `/swaig` route gives it. */
|
|
225
|
+
private run;
|
|
226
|
+
private dispatch;
|
|
227
|
+
private checkGates;
|
|
228
|
+
private blocked;
|
|
229
|
+
private navigate;
|
|
230
|
+
private request;
|
|
231
|
+
private apply;
|
|
232
|
+
private runActions;
|
|
233
|
+
private applyOne;
|
|
234
|
+
private enterContext;
|
|
235
|
+
private enterStep;
|
|
236
|
+
private stepsOf;
|
|
237
|
+
private currentStep;
|
|
238
|
+
private findStep;
|
|
239
|
+
private followingStep;
|
|
240
|
+
private validContexts;
|
|
241
|
+
private tools;
|
|
242
|
+
/** The current context's other steps whose functions include `name`, in step order. */
|
|
243
|
+
private stepsOffering;
|
|
244
|
+
/** The platform's reply to a call of a tool it won't run now. */
|
|
245
|
+
private unavailable;
|
|
246
|
+
private log;
|
|
247
|
+
/**
|
|
248
|
+
* The current step's history mode: its own, its context's, or "default".
|
|
249
|
+
* @returns The mode.
|
|
250
|
+
*/
|
|
251
|
+
historyMode(): string;
|
|
252
|
+
/**
|
|
253
|
+
* The conversation entries the model gets now, oldest first, after the
|
|
254
|
+
* history modes of the steps entered so far.
|
|
255
|
+
*
|
|
256
|
+
* At each step's injection, the platform first restores what an isolate
|
|
257
|
+
* step hid, then applies the new step's mode to everything before it:
|
|
258
|
+
*
|
|
259
|
+
* - `keep`: nothing leaves.
|
|
260
|
+
* - `default`: earlier step instructions leave.
|
|
261
|
+
* - `hide`: earlier instructions, and every earlier spoken turn, tool call,
|
|
262
|
+
* tool result and system note, leave for the rest of the call.
|
|
263
|
+
* - `isolate`: as `hide`, until the call leaves the step.
|
|
264
|
+
* - `spoken`: earlier instructions, and every earlier tool call, tool result
|
|
265
|
+
* and system note, leave for the rest of the call; every spoken turn stays.
|
|
266
|
+
*
|
|
267
|
+
* `hide`, `isolate` and `spoken` keep the exchange that entered the step, as
|
|
268
|
+
* its start: the call whose action changed it, its result, notes and say,
|
|
269
|
+
* and caller words stored before the step was injected. For a `post_process`
|
|
270
|
+
* action's change, which runs after the model's reply, that's the call and
|
|
271
|
+
* everything stored from it on, the reply included. A change by `next_step`
|
|
272
|
+
* keeps nothing. After that they're ordinary entries, which each later
|
|
273
|
+
* step's mode treats like the rest.
|
|
274
|
+
*
|
|
275
|
+
* It's the view for the model's next request: a step entered by a `say` or
|
|
276
|
+
* another action outside a tool call is injected before it, as the platform
|
|
277
|
+
* injects a step before the next request. A result's `say` is the agent's
|
|
278
|
+
* turn after the call's result and notes: the platform holds it until the
|
|
279
|
+
* next caller or agent turn, past system entries such as a step's
|
|
280
|
+
* instructions, or to the end. The current step's instructions are its text
|
|
281
|
+
* expanded with the global data now, as the platform expands it again when a
|
|
282
|
+
* value it reads changes; `callLog` keeps the text as it went in. An end
|
|
283
|
+
* step keeps the text it went in with. An end step takes no pass: steps end
|
|
284
|
+
* there, so what an `isolate` step hid is back, and earlier instructions
|
|
285
|
+
* stay. The base prompt isn't included.
|
|
286
|
+
*
|
|
287
|
+
* @returns The entries, without their timestamps.
|
|
288
|
+
* @throws Error once the call has entered a step with a reset, which starts a
|
|
289
|
+
* new context or consolidates the conversation in place of the step's
|
|
290
|
+
* text: the simulation doesn't follow it.
|
|
291
|
+
*/
|
|
292
|
+
modelView(): Json[];
|
|
293
|
+
/**
|
|
294
|
+
* The dialogue a semantic gate judges now, as `"role: text"` lines, oldest
|
|
295
|
+
* first: the spoken turns the model sees ({@link modelView}), chosen as the
|
|
296
|
+
* platform chooses them.
|
|
297
|
+
*
|
|
298
|
+
* With the gate's `since` mark set, the turns from the agent's first turn at
|
|
299
|
+
* or after the mark. Otherwise, with `dialogue` "proposal" (the gate's, or
|
|
300
|
+
* the agent's `semantic_gate_dialogue`) and a proposal marked, the turns
|
|
301
|
+
* from the agent's first turn after `semantic_state` last changed. Otherwise
|
|
302
|
+
* the window. Then at most `history` of the newest (the gate's, the agent's
|
|
303
|
+
* `semantic_gate_history`, or 20).
|
|
304
|
+
*
|
|
305
|
+
* Give it to a gate callback: `gates: (gate, sim) =>
|
|
306
|
+
* judge(gate['question'], sim.gateConversation(gate))`.
|
|
307
|
+
*
|
|
308
|
+
* @param gate - The gate, as rendered; default none.
|
|
309
|
+
* @returns The lines.
|
|
310
|
+
* @throws Error once the call has entered a step with a reset, as for
|
|
311
|
+
* {@link modelView}.
|
|
312
|
+
*/
|
|
313
|
+
gateConversation(gate?: Json): string[];
|
|
314
|
+
/**
|
|
315
|
+
* Before a request to the model: inject the current step's instructions,
|
|
316
|
+
* applying its history mode to what came before, once a step change is
|
|
317
|
+
* pending; otherwise expand the current step's text again.
|
|
318
|
+
*/
|
|
319
|
+
private inject;
|
|
320
|
+
/**
|
|
321
|
+
* A semantic_state being set: `{}` leaves no proposal, and any other state
|
|
322
|
+
* that differs from the current one, compared as serialized as the engine
|
|
323
|
+
* compares it (so a reordered state is a change), starts one.
|
|
324
|
+
*/
|
|
325
|
+
private noteState;
|
|
326
|
+
/** The current step's history mode, applied to everything before its start. */
|
|
327
|
+
private historyPass;
|
|
328
|
+
/** Throw for a view the simulator can't give: after a reset step. */
|
|
329
|
+
private checkModelled;
|
|
330
|
+
/**
|
|
331
|
+
* The platform rewrites the step's instruction entry in place when its
|
|
332
|
+
* expansion changes; the call log keeps the text as it went in.
|
|
333
|
+
*/
|
|
334
|
+
private refresh;
|
|
335
|
+
}
|
|
336
|
+
/** Options for a {@link RequestRecorder}. */
|
|
337
|
+
export interface RequestRecorderOptions {
|
|
338
|
+
/** The most requests kept in `requests`, newest kept. Default 1000. */
|
|
339
|
+
limit?: number;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Tool middleware that records each tool request, for
|
|
343
|
+
* {@link CallSimulator.replay}.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```ts
|
|
347
|
+
* import { AgentBase, CallSimulator, RequestRecorder } from '@signalwire/sdk';
|
|
348
|
+
*
|
|
349
|
+
* declare const agent: AgentBase;
|
|
350
|
+
* const recorder = new RequestRecorder('tool_requests.jsonl');
|
|
351
|
+
* agent.addToolMiddleware(recorder.middleware);
|
|
352
|
+
* // ...
|
|
353
|
+
* await new CallSimulator(agent).replay(RequestRecorder.load('tool_requests.jsonl'));
|
|
354
|
+
* ```
|
|
355
|
+
*
|
|
356
|
+
* The requests carry what the caller said and the call's data: keep the file
|
|
357
|
+
* where you'd keep call recordings.
|
|
358
|
+
*/
|
|
359
|
+
export declare class RequestRecorder {
|
|
360
|
+
/** A file each request is appended to, one JSON object a line. */
|
|
361
|
+
readonly path: string | null;
|
|
362
|
+
/** The most requests kept in `requests`. */
|
|
363
|
+
readonly limit: number;
|
|
364
|
+
/** The requests recorded, oldest first. */
|
|
365
|
+
requests: Json[];
|
|
366
|
+
/** The file's writes, in the order the requests came. */
|
|
367
|
+
private writes;
|
|
368
|
+
/**
|
|
369
|
+
* @param path - A file to append each request to, one JSON object a line.
|
|
370
|
+
* @param opts - `limit`.
|
|
371
|
+
*/
|
|
372
|
+
constructor(path?: string | null, opts?: RequestRecorderOptions);
|
|
373
|
+
/** This recorder as a {@link ToolMiddleware}. */
|
|
374
|
+
readonly middleware: ToolMiddleware;
|
|
375
|
+
/**
|
|
376
|
+
* Record a request, then run the rest of the chain.
|
|
377
|
+
* @param name - The tool's name.
|
|
378
|
+
* @param args - The arguments.
|
|
379
|
+
* @param rawData - The SWAIG request.
|
|
380
|
+
* @param callNext - The rest of the chain.
|
|
381
|
+
* @returns The call's result.
|
|
382
|
+
*/
|
|
383
|
+
handle(name: string, args: Json, rawData: Json, callNext: CallNext): Promise<unknown>;
|
|
384
|
+
/**
|
|
385
|
+
* The requests a recorder wrote to `path`.
|
|
386
|
+
* @param path - The file.
|
|
387
|
+
* @returns The requests, in order.
|
|
388
|
+
*/
|
|
389
|
+
static load(path: string): Json[];
|
|
390
|
+
}
|
|
391
|
+
export {};
|