@signalwire/sdk 3.5.0 → 3.7.1

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.
@@ -0,0 +1,554 @@
1
+ /**
2
+ * Semantic gates: natural-language preconditions on a SWAIG function.
3
+ *
4
+ * A semantic gate is a yes/no question a decision model answers about the call
5
+ * right before the platform dispatches the function. Every gate on the function
6
+ * must pass for it to run. When one doesn't, the function isn't dispatched, and
7
+ * the model gets that gate's `on_fail` output instead, as if a data_map had
8
+ * returned it.
9
+ *
10
+ * The platform refuses the whole function when any of its gates is invalid, so
11
+ * the SDK checks gates by the platform's rules when a tool is defined, and
12
+ * throws instead of sending a function the platform would drop. A platform
13
+ * release without semantic gates ignores them and runs the function ungated.
14
+ *
15
+ * Python equivalent: `signalwire/core/semantic_gate.py`.
16
+ */
17
+ import { FunctionResult } from './FunctionResult.js';
18
+ /** The most gates one function can carry. */
19
+ export const MAX_GATES = 8;
20
+ /** The longest gate question, in UTF-8 bytes. */
21
+ export const MAX_QUESTION_BYTES = 8192;
22
+ /** The longest `criteria.true` or `criteria.false`, in UTF-8 bytes. */
23
+ export const MAX_CRITERIA_BYTES = 2048;
24
+ /** The largest `on_fail` output, as compact JSON in UTF-8 bytes. */
25
+ export const MAX_ON_FAIL_BYTES = 8192;
26
+ /** The most caller video frames a gate may ask for (the platform's AI_VISUAL_INPUT_MAX). */
27
+ export const MAX_VISUAL_INPUT = 5;
28
+ const GATE_KEYS = new Set([
29
+ 'id',
30
+ 'question',
31
+ 'criteria',
32
+ 'threshold',
33
+ 'on_fail',
34
+ 'visual_input',
35
+ ]);
36
+ const GATE_ID = /^[A-Za-z0-9_]{1,64}$/;
37
+ const UNPAIRED_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
38
+ /**
39
+ * Hooks the platform calls itself, the function it intercepts by name, and the
40
+ * built-in function names: gates on any of them are refused.
41
+ */
42
+ export const RESERVED_FUNCTION_NAMES = new Set([
43
+ 'startup_hook',
44
+ 'hangup_hook',
45
+ 'check_for_input',
46
+ 'end_call',
47
+ 'hangup',
48
+ 'check_time',
49
+ 'wait_for_user',
50
+ 'wait_seconds',
51
+ 'adjust_response_latency',
52
+ 'next_step',
53
+ 'change_context',
54
+ 'gather_submit',
55
+ 'get_visual_input',
56
+ 'get_ideal_strategy',
57
+ 'pause_conversation',
58
+ ]);
59
+ /**
60
+ * One semantic gate: a yes/no question about the call, and what the model gets
61
+ * when the answer isn't yes.
62
+ *
63
+ * The decision model sees the recent dialogue as `conversation`, the call's
64
+ * `global_data.semantic_state` as `semantic_state`, and the proposed call as
65
+ * `proposed_function`. Write each question as one proposition and name what
66
+ * it's about with those field names, in backticks. The model reads literally
67
+ * and doesn't do arithmetic or compare dates, so put a computed result in
68
+ * `semantic_state` instead of asking for it.
69
+ *
70
+ * The gate is checked when the tool that carries it is defined, not when it's
71
+ * built.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * new SemanticGate(
76
+ * 'Has the caller explicitly asked to cancel their account in `conversation`?',
77
+ * 0.95,
78
+ * new FunctionResult()
79
+ * .setToolResponse(
80
+ * 'cancel_account was not run.',
81
+ * 'Ask the caller to confirm that they want to cancel.',
82
+ * )
83
+ * .updateGlobalData({ cancel_attempted: true }),
84
+ * {
85
+ * id: 'explicit_request',
86
+ * trueMeans: 'The caller says they want to cancel.',
87
+ * falseMeans: 'The caller asked about cancelling, or said something else.',
88
+ * },
89
+ * );
90
+ * ```
91
+ */
92
+ export class SemanticGate {
93
+ /** The yes/no question. */
94
+ question;
95
+ /** The probability of yes, above 0 and at most 1, at or above which the gate passes. */
96
+ threshold;
97
+ /** The gate's id, or undefined for the default `gate_<n>`. */
98
+ id;
99
+ /** What yes and no mean, keyed `true` and `false`. */
100
+ criteria;
101
+ /** The output the model gets when this is the first gate that fails. */
102
+ onFail;
103
+ /** The caller's video frames the decision model sees, or undefined for none. */
104
+ visualInput;
105
+ /**
106
+ * @param question - The yes/no question, at most 8 KB. Its `${...}`
107
+ * variables are expanded from the call's global data when the gate is
108
+ * checked; `@{...}` functions are not.
109
+ * @param threshold - The probability of yes, above 0 and at most 1, at or
110
+ * above which the gate passes. Thresholds are calibrated per decision model
111
+ * version.
112
+ * @param onFail - What the model gets when this is the first gate that fails:
113
+ * the tool result text, a FunctionResult, or a data_map output object. A
114
+ * FunctionResult's response and actions are used; its `tool_prompt` becomes
115
+ * a system message after the tool result in the text pipeline, which OpenAI
116
+ * Realtime agents don't use. The actions run as written, without template
117
+ * expansion.
118
+ * @param opts - The gate's id, what yes and no mean, and the caller's video
119
+ * frames it looks at.
120
+ * @throws {Error} When `onFail` has no response: a blocked call must never
121
+ * read as a success.
122
+ */
123
+ constructor(question, threshold, onFail, opts = {}) {
124
+ this.question = question;
125
+ this.threshold = threshold;
126
+ this.id = opts.id;
127
+ this.criteria = {};
128
+ if (opts.trueMeans !== undefined)
129
+ this.criteria.true = opts.trueMeans;
130
+ if (opts.falseMeans !== undefined)
131
+ this.criteria.false = opts.falseMeans;
132
+ this.onFail = onFailOutput(onFail);
133
+ this.visualInput = opts.visualInput;
134
+ }
135
+ /**
136
+ * The gate as the platform reads it.
137
+ * @returns The gate object: `id` (when set), `question`, `criteria` (when
138
+ * set), `threshold`, `on_fail` and `visual_input` (when set).
139
+ */
140
+ toDict() {
141
+ const gate = {};
142
+ if (this.id !== undefined)
143
+ gate['id'] = this.id;
144
+ gate['question'] = this.question;
145
+ if (Object.keys(this.criteria).length > 0)
146
+ gate['criteria'] = { ...this.criteria };
147
+ gate['threshold'] = this.threshold;
148
+ gate['on_fail'] = deepCopy(this.onFail);
149
+ if (this.visualInput !== undefined)
150
+ gate['visual_input'] = this.visualInput;
151
+ return gate;
152
+ }
153
+ }
154
+ /** Build an on_fail output object from a string, FunctionResult or object. */
155
+ function onFailOutput(onFail) {
156
+ if (onFail instanceof FunctionResult) {
157
+ const dict = onFail.toDict();
158
+ // toDict() fills in "Action completed." when there is no response; a
159
+ // blocked call must never read as a success, so the platform requires one.
160
+ const hasResponse = typeof dict['response'] === 'object' || onFail.response !== '';
161
+ if (!hasResponse) {
162
+ throw new Error("on_fail needs a response saying the function didn't run");
163
+ }
164
+ const output = { response: dict['response'] };
165
+ if (onFail.action.length > 0) {
166
+ output['action'] = onFail.action;
167
+ if (onFail.postProcess)
168
+ output['post_process'] = true;
169
+ }
170
+ return output;
171
+ }
172
+ if (typeof onFail === 'string') {
173
+ if (!onFail)
174
+ throw new Error("on_fail needs a response saying the function didn't run");
175
+ return { response: onFail };
176
+ }
177
+ return onFail;
178
+ }
179
+ function isPlainObject(value) {
180
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
181
+ }
182
+ function utf8Length(text) {
183
+ return Buffer.byteLength(text, 'utf8');
184
+ }
185
+ function deepCopy(value) {
186
+ return JSON.parse(JSON.stringify(value));
187
+ }
188
+ /**
189
+ * A value as the platform receives it: the JSON the SDK sends, so an optional
190
+ * key set to undefined is absent, while an explicit null stays null. A value
191
+ * JSON can't carry at the top level (undefined) is kept as is, for the checks
192
+ * to refuse.
193
+ */
194
+ function wireForm(value) {
195
+ return value === undefined ? undefined : JSON.parse(JSON.stringify(value));
196
+ }
197
+ /**
198
+ * The platform looks keys up the way cJSON_GetObjectItem does: without regard
199
+ * to case, and the first match wins.
200
+ */
201
+ function isAscii(text) {
202
+ for (let i = 0; i < text.length; i++)
203
+ if (text.charCodeAt(i) > 0x7f)
204
+ return false;
205
+ return true;
206
+ }
207
+ function sameKey(name, key) {
208
+ // cJSON compares ASCII letters without case and every other byte exactly
209
+ return isAscii(name) && name.toLowerCase() === key;
210
+ }
211
+ function firstKey(object, key) {
212
+ // A key left undefined isn't in the JSON sent, so the platform never sees it
213
+ return Object.keys(object).find((name) => object[name] !== undefined && sameKey(name, key));
214
+ }
215
+ function cjsonGet(object, key) {
216
+ const found = firstKey(object, key);
217
+ return found === undefined ? undefined : object[found];
218
+ }
219
+ function cjsonHas(object, key) {
220
+ return firstKey(object, key) !== undefined;
221
+ }
222
+ /**
223
+ * Whether a function definition has a `gates` or `gate_fillers` key, found as
224
+ * the platform finds it: without regard to ASCII case.
225
+ *
226
+ * Internal: AgentBase and SWMLService use it to decide what to check.
227
+ * @param fields - A function definition.
228
+ * @returns True when either key is present.
229
+ */
230
+ export function _hasGateFields(fields) {
231
+ return cjsonHas(fields, 'gates') || cjsonHas(fields, 'gate_fillers');
232
+ }
233
+ /** The bytes cJSON uses for one string, quotes included. */
234
+ function cjsonStringLength(text) {
235
+ let length = 2;
236
+ for (const char of text) {
237
+ const code = char.codePointAt(0);
238
+ if ('"\\\b\f\n\r\t'.includes(char))
239
+ length += 2;
240
+ else if (code < 32)
241
+ length += 6;
242
+ else
243
+ length += utf8Length(char);
244
+ }
245
+ return length;
246
+ }
247
+ /** The bytes cJSON uses for one number, as FreeSWITCH's cJSON prints it. */
248
+ function cjsonNumberLength(value) {
249
+ if (!Number.isFinite(value))
250
+ return 4; // "null"
251
+ // An integral value prints with %ld, any other with %lf (six decimals)
252
+ if (Number.isInteger(value))
253
+ return BigInt(value).toString().length;
254
+ return value.toFixed(6).length;
255
+ }
256
+ /**
257
+ * How many bytes cJSON_PrintUnformatted gives the JSON value, as the platform
258
+ * measures it. Exported for tests; the emitted values aren't changed.
259
+ */
260
+ export function _cjsonPrintedLength(value) {
261
+ if (value === null || value === undefined)
262
+ return 4;
263
+ if (typeof value === 'boolean')
264
+ return value ? 4 : 5;
265
+ if (typeof value === 'number')
266
+ return cjsonNumberLength(value);
267
+ if (typeof value === 'string')
268
+ return cjsonStringLength(value);
269
+ if (Array.isArray(value)) {
270
+ const items = value.map(_cjsonPrintedLength);
271
+ return 2 + items.reduce((sum, n) => sum + n, 0) + Math.max(0, items.length - 1);
272
+ }
273
+ const entries = Object.entries(value);
274
+ let length = 2 + Math.max(0, entries.length - 1);
275
+ for (const [key, item] of entries)
276
+ length += cjsonStringLength(key) + 1 + _cjsonPrintedLength(item);
277
+ return length;
278
+ }
279
+ /**
280
+ * Why a string can't reach the platform as written, or an empty string. C
281
+ * reads a string up to its first NUL, and cJSON refuses an unpaired surrogate,
282
+ * so the SDK refuses both rather than send a gate the platform reads
283
+ * differently.
284
+ */
285
+ function checkText(value, where) {
286
+ if (typeof value === 'string') {
287
+ if (value.includes('\0'))
288
+ return `${where} contains a NUL character`;
289
+ if (UNPAIRED_SURROGATE.test(value))
290
+ return `${where} contains an unpaired surrogate`;
291
+ return '';
292
+ }
293
+ if (Array.isArray(value)) {
294
+ for (const item of value) {
295
+ const why = checkText(item, where);
296
+ if (why)
297
+ return why;
298
+ }
299
+ }
300
+ else if (isPlainObject(value)) {
301
+ for (const [key, item] of Object.entries(value)) {
302
+ const why = checkText(key, where) || checkText(item, where);
303
+ if (why)
304
+ return why;
305
+ }
306
+ }
307
+ return '';
308
+ }
309
+ /** Why the platform would refuse `on_fail`, or an empty string. */
310
+ function checkOnFail(onFail) {
311
+ if (!isPlainObject(onFail))
312
+ return 'on_fail must be an object';
313
+ const response = cjsonGet(onFail, 'response');
314
+ if (typeof response === 'string') {
315
+ if (!response)
316
+ return 'on_fail.response is empty';
317
+ }
318
+ else if (isPlainObject(response)) {
319
+ const toolResult = cjsonGet(response, 'tool_result');
320
+ if (typeof toolResult !== 'string' || !toolResult) {
321
+ return 'on_fail.response.tool_result is missing or empty';
322
+ }
323
+ if (cjsonHas(response, 'tool_prompt') &&
324
+ typeof cjsonGet(response, 'tool_prompt') !== 'string') {
325
+ return 'on_fail.response.tool_prompt must be a string';
326
+ }
327
+ }
328
+ else {
329
+ return 'on_fail.response is missing';
330
+ }
331
+ if (cjsonHas(onFail, 'action') && !Array.isArray(cjsonGet(onFail, 'action'))) {
332
+ return 'on_fail.action must be an array';
333
+ }
334
+ const textWhy = checkText(onFail, 'on_fail');
335
+ if (textWhy)
336
+ return textWhy;
337
+ // Measured as the platform measures it: cJSON_PrintUnformatted of the JSON sent
338
+ if (_cjsonPrintedLength(deepCopy(onFail)) > MAX_ON_FAIL_BYTES) {
339
+ return `on_fail is larger than ${MAX_ON_FAIL_BYTES} bytes`;
340
+ }
341
+ return '';
342
+ }
343
+ /** Why the platform would refuse `criteria`, or an empty string. */
344
+ function checkCriteria(criteria) {
345
+ if (!isPlainObject(criteria) || Object.keys(criteria).length === 0) {
346
+ return 'criteria must be an object with true and/or false';
347
+ }
348
+ for (const [key, value] of Object.entries(criteria)) {
349
+ if (key !== 'true' && key !== 'false') {
350
+ return `criteria has an unknown key '${key}'; only true and false are allowed`;
351
+ }
352
+ if (typeof value !== 'string' || !value)
353
+ return `criteria.${key} must be a non-empty string`;
354
+ const textWhy = checkText(value, `criteria.${key}`);
355
+ if (textWhy)
356
+ return textWhy;
357
+ if (utf8Length(value) > MAX_CRITERIA_BYTES) {
358
+ return `criteria.${key} is longer than ${MAX_CRITERIA_BYTES} bytes`;
359
+ }
360
+ }
361
+ return '';
362
+ }
363
+ /**
364
+ * Whether the platform reads `value` as a frame count: a boolean, or a whole
365
+ * number from 0 to 5. 2.0 counts as 2; 1.5, -1, 6, null and strings are refused.
366
+ */
367
+ function validVisualInput(value) {
368
+ if (typeof value === 'boolean')
369
+ return true;
370
+ return Number.isInteger(value) && value >= 0 && value <= MAX_VISUAL_INPUT;
371
+ }
372
+ /** Why the platform would refuse one gate, or an empty string. */
373
+ function checkGate(gate) {
374
+ if (!isPlainObject(gate))
375
+ return 'must be an object';
376
+ for (const key of Object.keys(gate)) {
377
+ if (!GATE_KEYS.has(key))
378
+ return `unknown key '${key}'`;
379
+ }
380
+ const question = gate['question'];
381
+ if (typeof question !== 'string' || !question)
382
+ return 'question is missing or empty';
383
+ const questionWhy = checkText(question, 'question');
384
+ if (questionWhy)
385
+ return questionWhy;
386
+ if (utf8Length(question) > MAX_QUESTION_BYTES) {
387
+ return `question is longer than ${MAX_QUESTION_BYTES} bytes`;
388
+ }
389
+ const threshold = gate['threshold'];
390
+ if (typeof threshold !== 'number' ||
391
+ !Number.isFinite(threshold) ||
392
+ !(threshold > 0 && threshold <= 1)) {
393
+ return 'threshold must be a number above 0 and at most 1';
394
+ }
395
+ if (!('on_fail' in gate))
396
+ return 'on_fail is missing';
397
+ const onFailWhy = checkOnFail(gate['on_fail']);
398
+ if (onFailWhy)
399
+ return onFailWhy;
400
+ if ('criteria' in gate) {
401
+ const criteriaWhy = checkCriteria(gate['criteria']);
402
+ if (criteriaWhy)
403
+ return criteriaWhy;
404
+ }
405
+ if ('visual_input' in gate && !validVisualInput(gate['visual_input'])) {
406
+ return `visual_input must be true, false or a whole number from 0 to ${MAX_VISUAL_INPUT}`;
407
+ }
408
+ if ('id' in gate) {
409
+ const id = gate['id'];
410
+ if (typeof id !== 'string' || !GATE_ID.test(id)) {
411
+ return 'id must be 1 to 64 letters, digits or underscores';
412
+ }
413
+ }
414
+ return '';
415
+ }
416
+ /**
417
+ * Return a function's gates as the platform reads them.
418
+ *
419
+ * Every way to define a tool runs this through {@link applyGateFields}.
420
+ * @param gates - SemanticGate objects or gate objects, 1 to 8.
421
+ * @param functionName - The function's name.
422
+ * @returns Each gate as a plain object, deep-copied.
423
+ * @throws {Error} For anything that would make the platform refuse the
424
+ * function, with the platform's reason.
425
+ */
426
+ export function gateDefinitions(gates, functionName) {
427
+ if (RESERVED_FUNCTION_NAMES.has(functionName)) {
428
+ throw new Error(`gates are not supported on ${functionName}, a hook or built-in function name`);
429
+ }
430
+ if (!Array.isArray(gates))
431
+ throw new Error(`${functionName}: gates must be a list`);
432
+ if (gates.length < 1 || gates.length > MAX_GATES) {
433
+ throw new Error(`${functionName}: gates must hold 1 to ${MAX_GATES} gates, not ${gates.length}`);
434
+ }
435
+ const definitions = [];
436
+ const ids = [];
437
+ // Every index, holes included: a hole is sent as null, which the platform refuses
438
+ for (let index = 0; index < gates.length; index++) {
439
+ const gate = gates[index];
440
+ const definition = wireForm(gate instanceof SemanticGate ? gate.toDict() : gate);
441
+ const why = checkGate(definition);
442
+ if (why)
443
+ throw new Error(`${functionName}: gate ${index + 1}: ${why}`);
444
+ const gateDefinition = definition;
445
+ const id = gateDefinition['id'] ?? `gate_${index + 1}`;
446
+ const earlier = ids.indexOf(id);
447
+ if (earlier >= 0) {
448
+ throw new Error(`${functionName}: gate ${index + 1}: id '${id}' is already used by gate ${earlier + 1}`);
449
+ }
450
+ ids.push(id);
451
+ definitions.push(gateDefinition);
452
+ }
453
+ return definitions;
454
+ }
455
+ /**
456
+ * Check and normalize `gates` and `gate_fillers` in a function's fields, in
457
+ * place.
458
+ *
459
+ * `fields` is a function definition, or the extra fields of one. Its `gates`
460
+ * become the objects the platform reads. A `gate_fillers` left out or `null`
461
+ * is removed, as the platform ignores it.
462
+ * @param fields - The function definition or its extra fields.
463
+ * @param functionName - The function's name.
464
+ * @param opts - Options.
465
+ * @param opts.definition - True when `fields` is a whole function definition
466
+ * sent as written, such as a DataMap's or a raw one. Then its `gates` and
467
+ * `gate_fillers` keys are found as the platform finds them, without regard
468
+ * to case; `gates: null` is refused, as the platform refuses the function
469
+ * for a JSON null; and a gated function needs a description. Otherwise a
470
+ * null or undefined `gates` means no gates, as an option left out does.
471
+ * @throws {Error} For gates the platform would refuse, `gate_fillers` on a
472
+ * function without gates, which the platform ignores, or a gated
473
+ * definition without a description.
474
+ */
475
+ export function applyGateFields(fields, functionName, opts = {}) {
476
+ const definition = opts.definition ?? false;
477
+ const gatesKey = definition ? firstKey(fields, 'gates') : 'gates' in fields ? 'gates' : undefined;
478
+ let gated = false;
479
+ if (gatesKey !== undefined) {
480
+ const gates = fields[gatesKey];
481
+ if (gates === undefined || (gates === null && !definition)) {
482
+ delete fields[gatesKey];
483
+ }
484
+ else {
485
+ // Raw definitions carry anything; gateDefinitions checks it at run time
486
+ fields[gatesKey] = gateDefinitions(gates, functionName);
487
+ gated = true;
488
+ }
489
+ }
490
+ if (gated && definition) {
491
+ // The platform reads purpose, then description; any string counts
492
+ if (typeof cjsonGet(fields, 'purpose') !== 'string' &&
493
+ typeof cjsonGet(fields, 'description') !== 'string') {
494
+ throw new Error(`${functionName}: a gated function needs a description; the platform refuses it without one`);
495
+ }
496
+ }
497
+ const fillersKey = definition
498
+ ? firstKey(fields, 'gate_fillers')
499
+ : 'gate_fillers' in fields
500
+ ? 'gate_fillers'
501
+ : undefined;
502
+ if (fillersKey === undefined)
503
+ return;
504
+ const gateFillers = fields[fillersKey];
505
+ if (gateFillers === undefined || gateFillers === null) {
506
+ // The platform reads only the first match and ignores a null one, so in a
507
+ // whole definition every spelling goes, lest a later one take effect
508
+ for (const name of Object.keys(fields)) {
509
+ if (definition ? sameKey(name, 'gate_fillers') : name === fillersKey)
510
+ delete fields[name];
511
+ }
512
+ return;
513
+ }
514
+ if (!gated) {
515
+ throw new Error(`${functionName}: gate_fillers needs gates; the platform ignores them on a ` +
516
+ 'function without gates');
517
+ }
518
+ if (!isPlainObject(gateFillers)) {
519
+ throw new Error(`${functionName}: gate_fillers must map a language code, 'auto' or ` +
520
+ "'default' to a list of phrases");
521
+ }
522
+ }
523
+ /**
524
+ * Check a gated function as it will be sent, after every merge and expansion.
525
+ *
526
+ * Besides its gates, the platform needs a gated function to have a name, a
527
+ * description (`description` or `purpose`), and a `web_hook_url` or a
528
+ * `data_map`; a function without them isn't registered at all. The SWAIG
529
+ * `defaults.web_hook_url` counts as its URL.
530
+ *
531
+ * Internal: AgentBase calls it on each function it renders.
532
+ * @param definition - The function definition as it will be sent.
533
+ * @param defaultWebhookUrl - The SWAIG defaults `web_hook_url`, if any.
534
+ * @throws {Error} For gates the platform would refuse, or a gated function
535
+ * the platform wouldn't register.
536
+ */
537
+ export function _checkGatedFunction(definition, defaultWebhookUrl) {
538
+ if (!_hasGateFields(definition))
539
+ return;
540
+ const name = typeof definition['function'] === 'string' ? definition['function'] : '';
541
+ applyGateFields(definition, name || '(unnamed)', { definition: true });
542
+ if (!cjsonHas(definition, 'gates'))
543
+ return;
544
+ // As the platform reads them: any string counts, an empty one included, as
545
+ // does any data_map; the SWAIG defaults' URL counts as the function's.
546
+ const hasUrl = typeof cjsonGet(definition, 'web_hook_url') === 'string' || Boolean(defaultWebhookUrl);
547
+ const dataMap = cjsonGet(definition, 'data_map');
548
+ if (typeof definition['function'] !== 'string' ||
549
+ (!hasUrl && (dataMap === undefined || dataMap === null))) {
550
+ throw new Error(`${name || '(unnamed)'}: a gated function needs a name, a description, and a ` +
551
+ 'web_hook_url or data_map');
552
+ }
553
+ }
554
+ //# sourceMappingURL=SemanticGate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SemanticGate.js","sourceRoot":"","sources":["../src/SemanticGate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AASrD,6CAA6C;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,iDAAiD;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,oEAAoE;AACpE,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,MAAM,SAAS,GAAwB,IAAI,GAAG,CAAC;IAC7C,IAAI;IACJ,UAAU;IACV,UAAU;IACV,WAAW;IACX,SAAS;IACT,cAAc;CACf,CAAC,CAAC;AACH,MAAM,OAAO,GAAG,sBAAsB,CAAC;AACvC,MAAM,kBAAkB,GAAG,wEAAwE,CAAC;AAEpG;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IAClE,cAAc;IACd,aAAa;IACb,iBAAiB;IACjB,UAAU;IACV,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,cAAc;IACd,yBAAyB;IACzB,WAAW;IACX,gBAAgB;IAChB,eAAe;IACf,kBAAkB;IAClB,oBAAoB;IACpB,oBAAoB;CACrB,CAAC,CAAC;AAwBH;;;;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AC,UAAU,CAAC;QAAE,OAAO;IACxC,MAAM,IAAI,GAAG,OAAO,UAAU,CAAC,UAAU,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtF,eAAe,CAAC,UAAU,EAAE,IAAI,IAAI,WAAW,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;QAAE,OAAO;IAC3C,2EAA2E;IAC3E,uEAAuE;IACvE,MAAM,MAAM,GACV,OAAO,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACzF,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACjD,IACE,OAAO,UAAU,CAAC,UAAU,CAAC,KAAK,QAAQ;QAC1C,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC,EACxD,CAAC;QACD,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,IAAI,WAAW,wDAAwD;YAC5E,0BAA0B,CAC7B,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -4,6 +4,7 @@
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 FillerPhrases, type SemanticGate } from './SemanticGate.js';
7
8
  /** @internal How many argument validators have been compiled (for tests). */
8
9
  export declare function _compiledValidatorCount(): number;
9
10
  /**
@@ -105,12 +106,33 @@ export interface SwaigFunctionOptions {
105
106
  * `secure=True`.
106
107
  */
107
108
  secure?: boolean;
108
- /** Language-keyed filler phrases spoken while the tool executes. */
109
+ /**
110
+ * Phrases the AI says while the function runs, keyed by language code,
111
+ * `"auto"` (translated into the call's language on first use) or
112
+ * `"default"`. An entry may also be a list of phrases, a wait script, spoken
113
+ * one at a time while the call waits; the type predates wait scripts, so one needs a cast (the platform
114
+ * accepts it). {@link gateFillers} is typed for both.
115
+ */
109
116
  fillers?: Record<string, string[]>;
110
117
  /** Audio file URL to play while waiting for the tool to complete. */
111
118
  waitFile?: string;
112
119
  /** Number of times to loop the wait file. */
113
120
  waitFileLoops?: number;
121
+ /**
122
+ * Semantic gates, 1 to 8 {@link SemanticGate} objects or gate objects:
123
+ * yes/no preconditions a decision model checks right before the platform
124
+ * dispatches the function. When one fails, the function doesn't run and the
125
+ * model gets that gate's `on_fail` output. The fillers and wait file start
126
+ * only once the gates pass. Checked by the platform's rules when the tool is
127
+ * defined. A platform release without semantic gates runs the function
128
+ * ungated.
129
+ */
130
+ gates?: ReadonlyArray<SemanticGate | Record<string, unknown>>;
131
+ /**
132
+ * Phrases the AI says while the gates are checked, shaped like
133
+ * {@link fillers}. Only with {@link gates}.
134
+ */
135
+ gateFillers?: FillerPhrases;
114
136
  /** External webhook URL; makes this an externally-hosted tool. */
115
137
  webhookUrl?: string;
116
138
  /** List of required parameter names. */
@@ -190,7 +212,7 @@ export declare class SwaigFunction {
190
212
  parameters: Record<string, unknown>;
191
213
  /** Whether this tool requires session token authentication. */
192
214
  secure: boolean;
193
- /** Language-keyed filler phrases spoken while the tool executes. */
215
+ /** Phrases the AI says while the function runs (see {@link SwaigFunctionOptions.fillers}). */
194
216
  fillers?: Record<string, string[]>;
195
217
  /** Audio file URL to play while waiting for the tool to complete. */
196
218
  waitFile?: string;
@@ -218,7 +240,11 @@ export declare class SwaigFunction {
218
240
  * (e.g. `meta_data_token`, `web_hook_auth_user`, `web_hook_auth_password`).
219
241
  * This mirrors the Python constructor's `**extra_swaig_fields` kwargs:
220
242
  * both are merged directly into the serialized SWAIG definition, so the
221
- * wire format is identical — only the call-site syntax differs.
243
+ * wire format is identical — only the call-site syntax differs. `gates`
244
+ * and `gate_fillers` there are checked like `opts.gates` and
245
+ * `opts.gateFillers`.
246
+ * @throws {Error} For gates the platform would refuse, or gate fillers
247
+ * without gates.
222
248
  */
223
249
  constructor(opts: SwaigFunctionOptions);
224
250
  private ensureParameterStructure;