Helper Functions & Utilities
Helper Functions & Utilities
Helper Functions & Utilities
The SignalWire Agents SDK exports helper functions and utilities at the top level for common
tasks like creating standalone contexts, building server-side API tools,
managing environment variable expansion, security, and type inference.
All are imported directly from @signalwire/sdk.
Create a standalone Context object
without needing a full ContextBuilder.
Useful for quick single-context agents.
Context name. For single-context agents this is typically "default".
Context — A new Context
object ready for adding steps.
Create a server-side API tool with minimal configuration. Returns a configured
DataMap that executes an HTTP
request on the SignalWire server without requiring a webhook endpoint.
The name for the SWAIG tool.
API endpoint URL. Supports ${args.paramName} substitution for injecting parameter
values (e.g., "https://api.example.com/search?q=${args.query}").
Template string for formatting the API response. Uses ${response.field}
syntax to reference fields from the API response JSON.
Parameter definitions. Each key is a parameter name, and each value is an object
with type (default "string"), description, and optionally required.
HTTP method for the API call.
HTTP headers to include in the request.
Request body for POST/PUT requests.
JSON keys whose presence in the response indicates an error.
DataMap — A configured DataMap
ready to be registered with an agent.
For more complex API integrations with multiple webhooks, fallback outputs, or
array processing, use the DataMap
builder directly.
Create a pattern-matching tool that evaluates expressions locally on the SignalWire server without making any HTTP requests. Useful for command routing and conditional responses.
The name for the SWAIG tool.
A record mapping test values to [pattern, FunctionResult] tuples. The key is a template
string (e.g., "${args.command}"), and the pattern is a regex string matched against it.
Parameter definitions, same format as createSimpleApiTool.
DataMap — A configured DataMap
with expression-based routing.
Since object keys must be unique, you cannot map multiple patterns against the same
test value using createExpressionTool. For that case, use the DataMap
builder and call .expression() multiple times.
Set the global allowed environment variable prefixes for ${ENV.*} expansion
in DataMap URLs, bodies, and outputs. Only environment variables whose names
start with one of these prefixes will be expanded.
The default prefixes are ['SIGNALWIRE_', 'SWML_', 'SW_'].
Array of prefix strings to allow. Pass an empty array to allow all environment variables (escape hatch — use with caution).
Get a copy of the current global allowed environment variable prefixes.
string[] — A copy of the current prefix list.
Copy properties from source to target, filtering out prototype-pollution
keys (__proto__, constructor, prototype). Drop-in replacement for
Object.assign() where source is untrusted.
The object to assign into.
The object to copy properties from.
The target object.
Return a copy of headers with sensitive entries removed (authorization,
cookie, x-api-key, proxy-authorization, set-cookie).
Original header record.
Record<string, string> — A new record with sensitive headers removed.
Redact credentials embedded in a URL. Replaces the password portion with ****.
The URL string to redact.
string — The URL with the password replaced by ****.
Validate that a URL is safe to fetch — rejects URLs whose hostname resolves to
a private or reserved IP range (loopback, RFC1918, link-local, IPv6 private).
Never throws; returns false on failure.
The URL to validate.
When true, skip the private-IP check.
Promise<boolean> — true if the URL is safe to fetch, false otherwise.
Maximum allowed input length for skill handler arguments (characters). Value: 1000.
Infer a JSON Schema from a function’s source code by parsing parameter names
and default values. Used internally by defineTypedTool().
The function to analyze.
InferredSchema | null — The inferred schema with parameters,
required, paramNames, and hasRawData fields, or null if inference fails.
Parse function parameter names and default values from source code text.
The function source code string (via fn.toString()).
ParsedParam[] — Array of { name: string; defaultValue?: string } objects.
Create a wrapper function that unpacks a Record<string, unknown> args dict
into named positional parameters for a typed handler.
The original typed handler function.
Ordered parameter names to extract from args.
Whether the handler accepts a rawData parameter.
SwaigHandler — A wrapped handler with the standard (args, rawData) signature.
A single section in a Prompt Object Model, with a title, body, bullets, and
nested subsections. Returned by PomBuilder.getSection() and PomBuilder.findSection().
Section heading text, or null if untitled.
Section body paragraph text.
List of bullet point strings.
Nested child sections.
Whether this section is numbered when rendered.
Whether bullet points are rendered as a numbered list.
Register all 19 built-in skills with the global SkillRegistry. Call this once
at startup if you want to use SkillRegistry.create('datetime') style registration.
None.
void