Skip to navigation

applyGateFields

View as MarkdownOpen in Claude

Check and normalize gates and gate_fillers in a function’s fields, in place. fields is a function definition or the extra fields of one. Its gates become the plain objects the platform reads, as returned by gateDefinitions(). A gate_fillers that is left out or null is removed, because the platform ignores it.

Parameters

fields
Record<string, unknown>Required

The function definition or its extra fields. Modified in place.

functionName
stringRequired

The function’s name, used in error messages and checked against the reserved function names.

opts
{ definition?: boolean }

Optional settings.

opts.definition
booleanDefaults to false

Set to true when fields is a whole function definition sent as written, such as a DataMap’s or a raw one. Then the gates and gate_fillers keys are found without regard to case, gates: null is refused, and a gated function needs a description (or purpose). When false, a null or undefined gates means no gates, as an option left out does.

Returns

void

Throws Error for gates the platform would refuse, for gate_fillers on a function without gates (the platform ignores them there), for gate_fillers that isn’t an object mapping a language code, 'auto', or 'default' to a list of phrases, and, with definition: true, for a gated definition without a description.

Examples

import { applyGateFields } from '@signalwire/sdk';
const fields: Record<string, unknown> = {
gates: [
{
question: 'Has the caller explicitly asked to cancel their account in `conversation`?',
threshold: 0.95,
on_fail: { response: 'cancel_account was not run. Ask the caller to confirm.' },
},
],
gate_fillers: { 'en-US': ['One moment.'] },
};
applyGateFields(fields, 'cancel_account');
console.log(fields.gates); // the gate as a plain object, deep-copied