signalwire-agents 0.1.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.
- package/CLAUDE.md +112 -0
- package/README.md +417 -0
- package/dist/AgentBase.d.ts +481 -0
- package/dist/AgentBase.js +1155 -0
- package/dist/AgentBase.js.map +1 -0
- package/dist/AgentServer.d.ts +60 -0
- package/dist/AgentServer.js +128 -0
- package/dist/AgentServer.js.map +1 -0
- package/dist/AuthHandler.d.ts +56 -0
- package/dist/AuthHandler.js +119 -0
- package/dist/AuthHandler.js.map +1 -0
- package/dist/ConfigLoader.d.ts +68 -0
- package/dist/ConfigLoader.js +150 -0
- package/dist/ConfigLoader.js.map +1 -0
- package/dist/ContextBuilder.d.ts +431 -0
- package/dist/ContextBuilder.js +751 -0
- package/dist/ContextBuilder.js.map +1 -0
- package/dist/DataMap.d.ts +179 -0
- package/dist/DataMap.js +321 -0
- package/dist/DataMap.js.map +1 -0
- package/dist/Logger.d.ts +91 -0
- package/dist/Logger.js +191 -0
- package/dist/Logger.js.map +1 -0
- package/dist/PomBuilder.d.ts +144 -0
- package/dist/PomBuilder.js +249 -0
- package/dist/PomBuilder.js.map +1 -0
- package/dist/PromptManager.d.ts +85 -0
- package/dist/PromptManager.js +108 -0
- package/dist/PromptManager.js.map +1 -0
- package/dist/SchemaUtils.d.ts +42 -0
- package/dist/SchemaUtils.js +148 -0
- package/dist/SchemaUtils.js.map +1 -0
- package/dist/ServerlessAdapter.d.ts +100 -0
- package/dist/ServerlessAdapter.js +166 -0
- package/dist/ServerlessAdapter.js.map +1 -0
- package/dist/SessionManager.d.ts +86 -0
- package/dist/SessionManager.js +155 -0
- package/dist/SessionManager.js.map +1 -0
- package/dist/SslConfig.d.ts +77 -0
- package/dist/SslConfig.js +100 -0
- package/dist/SslConfig.js.map +1 -0
- package/dist/SwaigFunction.d.ts +88 -0
- package/dist/SwaigFunction.js +125 -0
- package/dist/SwaigFunction.js.map +1 -0
- package/dist/SwaigFunctionResult.d.ts +442 -0
- package/dist/SwaigFunctionResult.js +735 -0
- package/dist/SwaigFunctionResult.js.map +1 -0
- package/dist/SwmlBuilder.d.ts +37 -0
- package/dist/SwmlBuilder.js +55 -0
- package/dist/SwmlBuilder.js.map +1 -0
- package/dist/cli/agent-loader.d.ts +22 -0
- package/dist/cli/agent-loader.js +106 -0
- package/dist/cli/agent-loader.js.map +1 -0
- package/dist/cli/mock-data.d.ts +37 -0
- package/dist/cli/mock-data.js +79 -0
- package/dist/cli/mock-data.js.map +1 -0
- package/dist/cli/swaig-test.d.ts +32 -0
- package/dist/cli/swaig-test.js +405 -0
- package/dist/cli/swaig-test.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/prefabs/ConciergeAgent.d.ts +64 -0
- package/dist/prefabs/ConciergeAgent.js +188 -0
- package/dist/prefabs/ConciergeAgent.js.map +1 -0
- package/dist/prefabs/FAQBotAgent.d.ts +68 -0
- package/dist/prefabs/FAQBotAgent.js +206 -0
- package/dist/prefabs/FAQBotAgent.js.map +1 -0
- package/dist/prefabs/InfoGathererAgent.d.ts +73 -0
- package/dist/prefabs/InfoGathererAgent.js +202 -0
- package/dist/prefabs/InfoGathererAgent.js.map +1 -0
- package/dist/prefabs/ReceptionistAgent.d.ts +65 -0
- package/dist/prefabs/ReceptionistAgent.js +205 -0
- package/dist/prefabs/ReceptionistAgent.js.map +1 -0
- package/dist/prefabs/SurveyAgent.d.ts +84 -0
- package/dist/prefabs/SurveyAgent.js +324 -0
- package/dist/prefabs/SurveyAgent.js.map +1 -0
- package/dist/prefabs/index.d.ts +13 -0
- package/dist/prefabs/index.js +14 -0
- package/dist/prefabs/index.js.map +1 -0
- package/dist/skills/SkillBase.d.ts +134 -0
- package/dist/skills/SkillBase.js +105 -0
- package/dist/skills/SkillBase.js.map +1 -0
- package/dist/skills/SkillManager.d.ts +83 -0
- package/dist/skills/SkillManager.js +159 -0
- package/dist/skills/SkillManager.js.map +1 -0
- package/dist/skills/SkillRegistry.d.ts +105 -0
- package/dist/skills/SkillRegistry.js +195 -0
- package/dist/skills/SkillRegistry.js.map +1 -0
- package/dist/skills/builtin/api_ninjas_trivia.d.ts +35 -0
- package/dist/skills/builtin/api_ninjas_trivia.js +161 -0
- package/dist/skills/builtin/api_ninjas_trivia.js.map +1 -0
- package/dist/skills/builtin/claude_skills.d.ts +34 -0
- package/dist/skills/builtin/claude_skills.js +156 -0
- package/dist/skills/builtin/claude_skills.js.map +1 -0
- package/dist/skills/builtin/custom_skills.d.ts +59 -0
- package/dist/skills/builtin/custom_skills.js +231 -0
- package/dist/skills/builtin/custom_skills.js.map +1 -0
- package/dist/skills/builtin/datasphere.d.ts +34 -0
- package/dist/skills/builtin/datasphere.js +163 -0
- package/dist/skills/builtin/datasphere.js.map +1 -0
- package/dist/skills/builtin/datasphere_serverless.d.ts +54 -0
- package/dist/skills/builtin/datasphere_serverless.js +155 -0
- package/dist/skills/builtin/datasphere_serverless.js.map +1 -0
- package/dist/skills/builtin/datetime.d.ts +31 -0
- package/dist/skills/builtin/datetime.js +95 -0
- package/dist/skills/builtin/datetime.js.map +1 -0
- package/dist/skills/builtin/google_maps.d.ts +33 -0
- package/dist/skills/builtin/google_maps.js +233 -0
- package/dist/skills/builtin/google_maps.js.map +1 -0
- package/dist/skills/builtin/index.d.ts +28 -0
- package/dist/skills/builtin/index.js +75 -0
- package/dist/skills/builtin/index.js.map +1 -0
- package/dist/skills/builtin/info_gatherer.d.ts +52 -0
- package/dist/skills/builtin/info_gatherer.js +237 -0
- package/dist/skills/builtin/info_gatherer.js.map +1 -0
- package/dist/skills/builtin/joke.d.ts +32 -0
- package/dist/skills/builtin/joke.js +142 -0
- package/dist/skills/builtin/joke.js.map +1 -0
- package/dist/skills/builtin/math.d.ts +33 -0
- package/dist/skills/builtin/math.js +120 -0
- package/dist/skills/builtin/math.js.map +1 -0
- package/dist/skills/builtin/mcp_gateway.d.ts +35 -0
- package/dist/skills/builtin/mcp_gateway.js +85 -0
- package/dist/skills/builtin/mcp_gateway.js.map +1 -0
- package/dist/skills/builtin/native_vector_search.d.ts +44 -0
- package/dist/skills/builtin/native_vector_search.js +248 -0
- package/dist/skills/builtin/native_vector_search.js.map +1 -0
- package/dist/skills/builtin/play_background_file.d.ts +34 -0
- package/dist/skills/builtin/play_background_file.js +135 -0
- package/dist/skills/builtin/play_background_file.js.map +1 -0
- package/dist/skills/builtin/spider.d.ts +34 -0
- package/dist/skills/builtin/spider.js +164 -0
- package/dist/skills/builtin/spider.js.map +1 -0
- package/dist/skills/builtin/swml_transfer.d.ts +44 -0
- package/dist/skills/builtin/swml_transfer.js +204 -0
- package/dist/skills/builtin/swml_transfer.js.map +1 -0
- package/dist/skills/builtin/weather_api.d.ts +34 -0
- package/dist/skills/builtin/weather_api.js +136 -0
- package/dist/skills/builtin/weather_api.js.map +1 -0
- package/dist/skills/builtin/web_search.d.ts +34 -0
- package/dist/skills/builtin/web_search.js +141 -0
- package/dist/skills/builtin/web_search.js.map +1 -0
- package/dist/skills/builtin/wikipedia_search.d.ts +34 -0
- package/dist/skills/builtin/wikipedia_search.js +166 -0
- package/dist/skills/builtin/wikipedia_search.js.map +1 -0
- package/dist/skills/index.d.ts +11 -0
- package/dist/skills/index.js +10 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/docs/agent-guide.md +869 -0
- package/docs/api-reference.md +2419 -0
- package/docs/architecture.md +843 -0
- package/docs/cli-guide.md +579 -0
- package/docs/configuration.md +422 -0
- package/docs/contexts-guide.md +787 -0
- package/docs/datamap-guide.md +1141 -0
- package/docs/prefabs-guide.md +830 -0
- package/docs/security.md +436 -0
- package/docs/serverless-guide.md +513 -0
- package/docs/skills-guide.md +845 -0
- package/docs/swaig-reference.md +1627 -0
- package/examples/call-flow.ts +60 -0
- package/examples/contexts-steps.ts +62 -0
- package/examples/datamap-tools.ts +52 -0
- package/examples/dynamic-config.ts +51 -0
- package/examples/multi-agent.ts +67 -0
- package/examples/pom-prompt.ts +68 -0
- package/examples/simple-agent.ts +33 -0
- package/package.json +35 -0
- package/src/AgentBase.ts +1279 -0
- package/src/AgentServer.ts +149 -0
- package/src/AuthHandler.ts +141 -0
- package/src/ConfigLoader.ts +165 -0
- package/src/ContextBuilder.ts +796 -0
- package/src/DataMap.ts +365 -0
- package/src/Logger.ts +197 -0
- package/src/PomBuilder.ts +298 -0
- package/src/PromptManager.ts +133 -0
- package/src/SchemaUtils.ts +170 -0
- package/src/ServerlessAdapter.ts +218 -0
- package/src/SessionManager.ts +161 -0
- package/src/SslConfig.ts +118 -0
- package/src/SwaigFunction.ts +168 -0
- package/src/SwaigFunctionResult.ts +864 -0
- package/src/SwmlBuilder.ts +62 -0
- package/src/cli/agent-loader.ts +122 -0
- package/src/cli/mock-data.ts +110 -0
- package/src/cli/swaig-test.ts +440 -0
- package/src/index.ts +99 -0
- package/src/prefabs/ConciergeAgent.ts +251 -0
- package/src/prefabs/FAQBotAgent.ts +263 -0
- package/src/prefabs/InfoGathererAgent.ts +276 -0
- package/src/prefabs/ReceptionistAgent.ts +277 -0
- package/src/prefabs/SurveyAgent.ts +413 -0
- package/src/prefabs/index.ts +23 -0
- package/src/skills/SkillBase.ts +184 -0
- package/src/skills/SkillManager.ts +177 -0
- package/src/skills/SkillRegistry.ts +231 -0
- package/src/skills/builtin/api_ninjas_trivia.ts +230 -0
- package/src/skills/builtin/claude_skills.ts +239 -0
- package/src/skills/builtin/custom_skills.ts +326 -0
- package/src/skills/builtin/datasphere.ts +225 -0
- package/src/skills/builtin/datasphere_serverless.ts +194 -0
- package/src/skills/builtin/datetime.ts +115 -0
- package/src/skills/builtin/google_maps.ts +347 -0
- package/src/skills/builtin/index.ts +79 -0
- package/src/skills/builtin/info_gatherer.ts +331 -0
- package/src/skills/builtin/joke.ts +180 -0
- package/src/skills/builtin/math.ts +150 -0
- package/src/skills/builtin/mcp_gateway.ts +99 -0
- package/src/skills/builtin/native_vector_search.ts +327 -0
- package/src/skills/builtin/play_background_file.ts +189 -0
- package/src/skills/builtin/spider.ts +232 -0
- package/src/skills/builtin/swml_transfer.ts +285 -0
- package/src/skills/builtin/weather_api.ts +193 -0
- package/src/skills/builtin/web_search.ts +212 -0
- package/src/skills/builtin/wikipedia_search.ts +248 -0
- package/src/skills/index.ts +12 -0
- package/src/types.ts +99 -0
- package/tests/AgentBase.test.ts +693 -0
- package/tests/AgentServer.test.ts +102 -0
- package/tests/AuthHandler.test.ts +121 -0
- package/tests/ConfigLoader.test.ts +121 -0
- package/tests/DataMap.test.ts +286 -0
- package/tests/Logger.test.ts +218 -0
- package/tests/PomBuilder.test.ts +164 -0
- package/tests/ProxyDetection.test.ts +185 -0
- package/tests/SchemaUtils.test.ts +106 -0
- package/tests/ServerlessAdapter.test.ts +200 -0
- package/tests/SessionManager.test.ts +139 -0
- package/tests/SslConfig.test.ts +97 -0
- package/tests/SwaigFunctionResult.test.ts +298 -0
- package/tests/cli/mock-data.test.ts +94 -0
- package/tests/cli/swaig-test.test.ts +96 -0
- package/tests/prefabs/prefabs.test.ts +854 -0
- package/tests/setup.ts +6 -0
- package/tests/skills/SkillBase.test.ts +118 -0
- package/tests/skills/SkillManager.test.ts +164 -0
- package/tests/skills/SkillRegistry.test.ts +124 -0
- package/tests/skills/builtin.test.ts +924 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
# swaig-test CLI Guide
|
|
2
|
+
|
|
3
|
+
Complete guide to the `swaig-test` command-line tool for testing SignalWire AI agents locally without making a phone call.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Overview](#overview)
|
|
10
|
+
- [Installation and Usage](#installation-and-usage)
|
|
11
|
+
- [Agent Discovery](#agent-discovery)
|
|
12
|
+
- [Discovery Order](#discovery-order)
|
|
13
|
+
- [The --agent-class Flag](#the---agent-class-flag)
|
|
14
|
+
- [Commands](#commands)
|
|
15
|
+
- [--dump-swml](#--dump-swml)
|
|
16
|
+
- [--list-tools](#--list-tools)
|
|
17
|
+
- [--exec function_name](#--exec-function_name)
|
|
18
|
+
- [--list-agents](#--list-agents)
|
|
19
|
+
- [Execution Options](#execution-options)
|
|
20
|
+
- [Function Arguments (--arg)](#function-arguments---arg)
|
|
21
|
+
- [Call Metadata Overrides](#call-metadata-overrides)
|
|
22
|
+
- [Post Data Overrides (--override)](#post-data-overrides---override)
|
|
23
|
+
- [Mock Data](#mock-data)
|
|
24
|
+
- [Full Mock Post Data](#full-mock-post-data)
|
|
25
|
+
- [Minimal Mock Post Data](#minimal-mock-post-data)
|
|
26
|
+
- [MockCallOptions](#mockcalloptions)
|
|
27
|
+
- [Output Formatting](#output-formatting)
|
|
28
|
+
- [Route Override](#route-override)
|
|
29
|
+
- [Environment Variables](#environment-variables)
|
|
30
|
+
- [Serverless Simulation](#serverless-simulation)
|
|
31
|
+
- [Examples](#examples)
|
|
32
|
+
- [Dump the SWML Document](#dump-the-swml-document)
|
|
33
|
+
- [List Registered Tools](#list-registered-tools)
|
|
34
|
+
- [Execute a Tool](#execute-a-tool)
|
|
35
|
+
- [Test with Custom Caller Data](#test-with-custom-caller-data)
|
|
36
|
+
- [Simulate a SIP Call](#simulate-a-sip-call)
|
|
37
|
+
- [Test with Environment Variables](#test-with-environment-variables)
|
|
38
|
+
- [Machine-Readable Output](#machine-readable-output)
|
|
39
|
+
- [Discover Agents in a File](#discover-agents-in-a-file)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Overview
|
|
44
|
+
|
|
45
|
+
`swaig-test` is a CLI tool for testing SignalWire AI agents locally. It dynamically imports your agent module, generates mock call data, and lets you:
|
|
46
|
+
|
|
47
|
+
- **Dump the SWML document** your agent produces, so you can inspect its full configuration.
|
|
48
|
+
- **List all registered tools** with their descriptions and parameter schemas.
|
|
49
|
+
- **Execute a specific tool** with custom arguments and inspect the result.
|
|
50
|
+
- **List all agents** exported from a module file.
|
|
51
|
+
|
|
52
|
+
This allows you to iterate on your agent's configuration, prompt, and tool handlers without setting up a phone number, making a call, or deploying to a server.
|
|
53
|
+
|
|
54
|
+
**Source files:**
|
|
55
|
+
- `src/cli/swaig-test.ts` -- CLI entry point and argument parser.
|
|
56
|
+
- `src/cli/agent-loader.ts` -- Agent discovery via dynamic import with duck-typing.
|
|
57
|
+
- `src/cli/mock-data.ts` -- Mock call data generation.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Installation and Usage
|
|
62
|
+
|
|
63
|
+
Run the CLI via `npx tsx` during development:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx tsx src/cli/swaig-test.ts <agent-path> [options]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
If the project has been built, you can run the compiled JavaScript directly:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
node dist/cli/swaig-test.js <agent-path> [options]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The `<agent-path>` is the path to your agent module file (TypeScript or JavaScript). It is the first positional argument and is required for all commands except `--help`.
|
|
76
|
+
|
|
77
|
+
Show help:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npx tsx src/cli/swaig-test.ts --help
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Agent Discovery
|
|
86
|
+
|
|
87
|
+
The CLI uses dynamic `import()` to load your agent module, then applies a series of duck-typing heuristics to find an `AgentBase` instance. An object is considered an agent instance if it has `renderSwml`, `defineTool`, and `getPrompt` methods. A constructor function is considered an agent class if its `prototype` has those same methods.
|
|
88
|
+
|
|
89
|
+
### Discovery Order
|
|
90
|
+
|
|
91
|
+
When no `--agent-class` flag is provided, the loader tries these strategies in order and uses the first match:
|
|
92
|
+
|
|
93
|
+
| Priority | Strategy | Description |
|
|
94
|
+
|---|---|---|
|
|
95
|
+
| 1 | Named export `agent` (instance) | Checks `module.agent` and verifies it is an agent instance via duck-typing. |
|
|
96
|
+
| 2 | Default export (instance) | Checks `module.default` and verifies it is an agent instance. |
|
|
97
|
+
| 3 | Any exported instance | Iterates over all exports; uses the first agent instance found. |
|
|
98
|
+
| 4 | Default export (class) | If `module.default` is an agent class, instantiates it with `{ name: 'cli-agent' }`. |
|
|
99
|
+
| 5 | Any exported class | Iterates over all exports; instantiates the first agent class found with `{ name: 'cli-agent' }`. |
|
|
100
|
+
|
|
101
|
+
If none of these strategies succeed, the CLI throws an error with guidance:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
Could not find an AgentBase instance or subclass in /path/to/file.
|
|
105
|
+
Export your agent as `export const agent = new AgentBase(...)` or as default export.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Recommended export patterns:**
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// Pattern 1: Named export (highest priority)
|
|
112
|
+
export const agent = new MyAgent({ name: 'my-agent' });
|
|
113
|
+
|
|
114
|
+
// Pattern 2: Default export (instance)
|
|
115
|
+
export default new MyAgent({ name: 'my-agent' });
|
|
116
|
+
|
|
117
|
+
// Pattern 3: Default export (class -- will be auto-instantiated)
|
|
118
|
+
export default MyAgent;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### The --agent-class Flag
|
|
122
|
+
|
|
123
|
+
When `--agent-class <name>` is provided, the loader skips the discovery order and looks up the specific named export:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npx tsx src/cli/swaig-test.ts my-agents.ts --agent-class SalesAgent
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
If the named export is an instance, it is used directly. If it is a class, it is instantiated with `{ name: '<name_lowercased>' }`. An error is thrown if the export is not found or is not an agent.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Commands
|
|
134
|
+
|
|
135
|
+
### --dump-swml
|
|
136
|
+
|
|
137
|
+
Generate and output the SWML document the agent would serve in response to an incoming call.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --dump-swml
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This is the **default action** -- if no action flag is specified, the CLI dumps SWML.
|
|
144
|
+
|
|
145
|
+
The command generates mock call POST data (simulating an inbound WebRTC call by default), passes it to `agent.renderSwml()`, and prints the resulting JSON document.
|
|
146
|
+
|
|
147
|
+
### --list-tools
|
|
148
|
+
|
|
149
|
+
List all SWAIG functions registered on the agent, including their descriptions and parameter schemas.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --list-tools
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
For each tool, the output shows:
|
|
156
|
+
- **Name** -- the tool's function name.
|
|
157
|
+
- **Description** -- the human-readable description used by the AI model.
|
|
158
|
+
- **Parameters** -- the JSON Schema object describing the tool's input parameters.
|
|
159
|
+
|
|
160
|
+
### --exec function_name
|
|
161
|
+
|
|
162
|
+
Execute a specific SWAIG function handler and display the result.
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --exec search_faq --arg query="password reset"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The command:
|
|
169
|
+
1. Looks up the tool by name. If not found, prints an error with available function names.
|
|
170
|
+
2. Generates minimal mock POST data for function execution.
|
|
171
|
+
3. Calls `tool.execute(args, postData)` with the arguments provided via `--arg`.
|
|
172
|
+
4. Prints the result as JSON.
|
|
173
|
+
|
|
174
|
+
### --list-agents
|
|
175
|
+
|
|
176
|
+
List all exported agents (instances and classes) found in a module file.
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
npx tsx src/cli/swaig-test.ts my-agents.ts --list-agents
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
This scans all named exports and reports which ones are agent instances or agent classes. Useful when a single file exports multiple agents and you need to know the export names for `--agent-class`.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Execution Options
|
|
187
|
+
|
|
188
|
+
### Function Arguments (--arg)
|
|
189
|
+
|
|
190
|
+
Pass arguments to a SWAIG function when using `--exec`. Each `--arg` takes a `key=value` pair. The flag is repeatable for multiple arguments.
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --exec save_field \
|
|
194
|
+
--arg field_name=email \
|
|
195
|
+
--arg value=user@example.com
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Values are parsed as JSON first; if parsing fails, the raw string is used. This means you can pass numbers, booleans, and objects:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# String value (JSON parse fails, used as string)
|
|
202
|
+
--arg name=Alice
|
|
203
|
+
|
|
204
|
+
# Numeric value (JSON parse succeeds)
|
|
205
|
+
--arg count=42
|
|
206
|
+
|
|
207
|
+
# Boolean value (JSON parse succeeds)
|
|
208
|
+
--arg required=true
|
|
209
|
+
|
|
210
|
+
# JSON object value
|
|
211
|
+
--arg data='{"nested":"value"}'
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Call Metadata Overrides
|
|
215
|
+
|
|
216
|
+
These flags control the mock call metadata used when generating POST data:
|
|
217
|
+
|
|
218
|
+
| Flag | Type | Default | Description |
|
|
219
|
+
|---|---|---|---|
|
|
220
|
+
| `--call-type` | `sip \| webrtc` | `webrtc` | Call transport type. Affects `caller_id_name`, `channel_type`, and `sip_headers`. |
|
|
221
|
+
| `--call-direction` | `inbound \| outbound` | `inbound` | Direction of the call. |
|
|
222
|
+
| `--call-state` | `string` | `active` | Current call state (e.g., `active`, `ringing`, `hold`). |
|
|
223
|
+
| `--call-id` | `string` | Random UUID | Override the auto-generated call ID. |
|
|
224
|
+
| `--from-number` | `string` | `+15551234567` | Caller's phone number. |
|
|
225
|
+
| `--to-extension` | `string` | `test-agent` | Destination extension or agent name. |
|
|
226
|
+
|
|
227
|
+
### Post Data Overrides (--override)
|
|
228
|
+
|
|
229
|
+
Merge arbitrary key-value pairs into the generated POST data. Repeatable. Values are JSON-parsed when possible.
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --dump-swml \
|
|
233
|
+
--override project_id=my-project-123 \
|
|
234
|
+
--override vars='{"custom_flag":true}'
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Overrides are applied via `Object.assign` after the mock data is generated, so they can replace any auto-generated field.
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Mock Data
|
|
242
|
+
|
|
243
|
+
The CLI generates fake POST data that simulates what SignalWire would send to your agent's webhook endpoint. Two generators are available.
|
|
244
|
+
|
|
245
|
+
### Full Mock Post Data
|
|
246
|
+
|
|
247
|
+
Used by `--dump-swml` and `--simulate-serverless`. Generated by `generateFakePostData()`.
|
|
248
|
+
|
|
249
|
+
The full mock POST body includes:
|
|
250
|
+
|
|
251
|
+
| Field | Description |
|
|
252
|
+
|---|---|
|
|
253
|
+
| `call_id` | Random UUID (or overridden via `--call-id`). |
|
|
254
|
+
| `call_type` | `"sip"` or `"webrtc"`. |
|
|
255
|
+
| `call_direction` | `"inbound"` or `"outbound"`. |
|
|
256
|
+
| `call_state` | `"active"`, `"ringing"`, `"hold"`, etc. |
|
|
257
|
+
| `node_id` | Random UUID. |
|
|
258
|
+
| `project_id` | Random UUID. |
|
|
259
|
+
| `space_id` | Random UUID. |
|
|
260
|
+
| `caller_id_name` | `"WebRTC User"` for webrtc; the from number for sip. |
|
|
261
|
+
| `caller_id_number` | The from number (`+15551234567` by default). |
|
|
262
|
+
| `call_start_time` | Current ISO 8601 timestamp. |
|
|
263
|
+
| `channel_type` | `"web"` for webrtc; `"phone"` for sip. |
|
|
264
|
+
| `from` | The from number. |
|
|
265
|
+
| `to` | The to extension. |
|
|
266
|
+
| `sip_headers` | Included only for sip calls; contains `X-SignalWire-Agent: swaig-test-cli`. |
|
|
267
|
+
| `vars` | Object with `call_type` and `direction`. |
|
|
268
|
+
|
|
269
|
+
### Minimal Mock Post Data
|
|
270
|
+
|
|
271
|
+
Used by `--exec`. Generated by `generateMinimalPostData()`.
|
|
272
|
+
|
|
273
|
+
Contains only the fields needed for function execution:
|
|
274
|
+
|
|
275
|
+
| Field | Description |
|
|
276
|
+
|---|---|
|
|
277
|
+
| `function` | Name of the SWAIG function being invoked. |
|
|
278
|
+
| `argument` | Arguments object passed to the function. |
|
|
279
|
+
| `call_id` | Random UUID (or overridden). |
|
|
280
|
+
| `call_type` | `"webrtc"`. |
|
|
281
|
+
| `call_direction` | `"inbound"`. |
|
|
282
|
+
| `caller_id_name` | `"CLI Test"`. |
|
|
283
|
+
| `caller_id_number` | `+15551234567`. |
|
|
284
|
+
| `from` | `+15551234567`. |
|
|
285
|
+
| `to` | `"test-agent"`. |
|
|
286
|
+
|
|
287
|
+
### MockCallOptions
|
|
288
|
+
|
|
289
|
+
The `MockCallOptions` interface defines the parameters accepted by the mock data generators:
|
|
290
|
+
|
|
291
|
+
| Property | Type | Default | Description |
|
|
292
|
+
|---|---|---|---|
|
|
293
|
+
| `callType` | `'sip' \| 'webrtc'` | `'webrtc'` | Call transport type. |
|
|
294
|
+
| `callDirection` | `'inbound' \| 'outbound'` | `'inbound'` | Direction of the call. |
|
|
295
|
+
| `callState` | `string` | `'active'` | Current call state. |
|
|
296
|
+
| `callId` | `string` | Random UUID | Override the auto-generated call ID. |
|
|
297
|
+
| `fromNumber` | `string` | `'+15551234567'` | Caller's phone number. |
|
|
298
|
+
| `toExtension` | `string` | `'test-agent'` | Destination extension or agent name. |
|
|
299
|
+
| `overrides` | `Record<string, unknown>` | -- | Additional key-value overrides merged into the post data. |
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Output Formatting
|
|
304
|
+
|
|
305
|
+
| Flag | Description |
|
|
306
|
+
|---|---|
|
|
307
|
+
| `--format-json` | Output results as pretty-printed (indented) JSON. |
|
|
308
|
+
| `--raw` | Raw JSON output. Suppresses all SDK log output by calling `suppressAllLogs(true)`. Useful for piping to `jq` or other tools. |
|
|
309
|
+
| `--verbose` | Enable verbose output. Sets the global log level to `debug`. |
|
|
310
|
+
|
|
311
|
+
When neither `--raw` nor `--format-json` is set, the CLI adds human-readable headers (e.g., `--- SWML Document ---`, `--- Result ---`) around the output.
|
|
312
|
+
|
|
313
|
+
When `--raw` or `--format-json` is set, only JSON is written to stdout, making it suitable for programmatic consumption.
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Route Override
|
|
318
|
+
|
|
319
|
+
Override the agent's HTTP route path:
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --dump-swml --route /custom-path
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
This sets `agent.route` to the specified path before generating SWML. Useful when testing agents that use different routes in production than what is hardcoded in their configuration.
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## Environment Variables
|
|
330
|
+
|
|
331
|
+
### Inline (--env)
|
|
332
|
+
|
|
333
|
+
Set environment variables before the agent module is loaded. Repeatable.
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --dump-swml \
|
|
337
|
+
--env SIGNALWIRE_LOG_LEVEL=debug \
|
|
338
|
+
--env MY_API_KEY=abc123
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Each `--env` takes a `KEY=VALUE` pair. The variable is set on `process.env` before the agent is loaded.
|
|
342
|
+
|
|
343
|
+
### From File (--env-file)
|
|
344
|
+
|
|
345
|
+
Load environment variables from a file:
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --dump-swml --env-file .env.test
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
The file format is standard `.env` syntax:
|
|
352
|
+
|
|
353
|
+
```
|
|
354
|
+
# Comments start with hash
|
|
355
|
+
SIGNALWIRE_LOG_LEVEL=info
|
|
356
|
+
MY_SECRET="quoted value"
|
|
357
|
+
ANOTHER_VAR='single quoted'
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Processing rules:
|
|
361
|
+
- Blank lines and lines starting with `#` are skipped.
|
|
362
|
+
- Each line is split on the first `=` sign.
|
|
363
|
+
- Surrounding single or double quotes on values are stripped.
|
|
364
|
+
- Variables are set on `process.env`.
|
|
365
|
+
|
|
366
|
+
The `--env-file` is loaded before inline `--env` values, so inline values take precedence.
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## Serverless Simulation
|
|
371
|
+
|
|
372
|
+
Simulate running your agent on a serverless platform:
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
npx tsx src/cli/swaig-test.ts my-agent.ts --simulate-serverless lambda
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Supported platforms:
|
|
379
|
+
|
|
380
|
+
| Platform | Flag Value | Description |
|
|
381
|
+
|---|---|---|
|
|
382
|
+
| AWS Lambda | `lambda` | Simulates an API Gateway event. |
|
|
383
|
+
| Google Cloud Functions | `gcf` | Simulates a GCF HTTP request. |
|
|
384
|
+
| Azure Functions | `azure` | Simulates an Azure HTTP trigger. |
|
|
385
|
+
| CGI | `cgi` | Simulates CGI-style invocation. |
|
|
386
|
+
|
|
387
|
+
The simulation:
|
|
388
|
+
1. Creates a `ServerlessAdapter` for the specified platform.
|
|
389
|
+
2. Gets the Hono app from `agent.getApp()`.
|
|
390
|
+
3. Generates full mock POST data using the current call metadata options.
|
|
391
|
+
4. Constructs a simulated event with `POST` method, the agent's route, authorization headers, and the mock body.
|
|
392
|
+
5. Passes the event through the adapter's `handleRequest()`.
|
|
393
|
+
6. Prints the response status code, headers, and body.
|
|
394
|
+
|
|
395
|
+
This is useful for verifying that your agent works correctly when deployed to a serverless environment, without actually deploying.
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## Examples
|
|
400
|
+
|
|
401
|
+
### Dump the SWML Document
|
|
402
|
+
|
|
403
|
+
Inspect the complete SWML configuration your agent generates:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts --dump-swml
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Output (abridged):
|
|
410
|
+
|
|
411
|
+
```
|
|
412
|
+
--- SWML Document ---
|
|
413
|
+
|
|
414
|
+
{
|
|
415
|
+
"version": "1.0.0",
|
|
416
|
+
"sections": {
|
|
417
|
+
"main": [
|
|
418
|
+
{ "answer": {} },
|
|
419
|
+
{
|
|
420
|
+
"ai": {
|
|
421
|
+
"prompt": { ... },
|
|
422
|
+
"SWAIG": { "functions": [ ... ] }
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
]
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### List Registered Tools
|
|
431
|
+
|
|
432
|
+
See what tools your agent exposes to the AI model:
|
|
433
|
+
|
|
434
|
+
```bash
|
|
435
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts --list-tools
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
Output:
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
Registered tools (2):
|
|
442
|
+
|
|
443
|
+
save_field
|
|
444
|
+
Description: Save a collected field value from the caller.
|
|
445
|
+
Parameters: {
|
|
446
|
+
"type": "object",
|
|
447
|
+
"properties": {
|
|
448
|
+
"field_name": { "type": "string", ... },
|
|
449
|
+
"value": { "type": "string", ... }
|
|
450
|
+
},
|
|
451
|
+
"required": ["field_name", "value"]
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
get_status
|
|
455
|
+
Description: Get the current status of information gathering.
|
|
456
|
+
Parameters: {
|
|
457
|
+
"type": "object",
|
|
458
|
+
"properties": {}
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### Execute a Tool
|
|
463
|
+
|
|
464
|
+
Run a tool handler directly and see the result:
|
|
465
|
+
|
|
466
|
+
```bash
|
|
467
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts \
|
|
468
|
+
--exec save_field \
|
|
469
|
+
--arg field_name=email \
|
|
470
|
+
--arg value=alice@example.com
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
Output:
|
|
474
|
+
|
|
475
|
+
```
|
|
476
|
+
Executing: save_field
|
|
477
|
+
Arguments: {"field_name":"email","value":"alice@example.com"}
|
|
478
|
+
|
|
479
|
+
--- Result ---
|
|
480
|
+
|
|
481
|
+
{
|
|
482
|
+
"response": "Field \"email\" saved as \"alice@example.com\". Remaining required fields: phone."
|
|
483
|
+
}
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
### Test with Custom Caller Data
|
|
487
|
+
|
|
488
|
+
Simulate an inbound SIP call from a specific phone number:
|
|
489
|
+
|
|
490
|
+
```bash
|
|
491
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts --dump-swml \
|
|
492
|
+
--call-type sip \
|
|
493
|
+
--from-number +15559876543 \
|
|
494
|
+
--call-id my-test-call-001
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
### Simulate a SIP Call
|
|
498
|
+
|
|
499
|
+
Combine call metadata with tool execution to test how tools behave with SIP-specific data:
|
|
500
|
+
|
|
501
|
+
```bash
|
|
502
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts \
|
|
503
|
+
--exec search_faq \
|
|
504
|
+
--arg query="business hours" \
|
|
505
|
+
--call-type sip \
|
|
506
|
+
--from-number +15559876543 \
|
|
507
|
+
--override caller_id_name="John Doe"
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### Test with Environment Variables
|
|
511
|
+
|
|
512
|
+
Pass secrets or configuration your agent needs:
|
|
513
|
+
|
|
514
|
+
```bash
|
|
515
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts --dump-swml \
|
|
516
|
+
--env SIGNALWIRE_LOG_LEVEL=debug \
|
|
517
|
+
--env API_KEY=test-key-123
|
|
518
|
+
|
|
519
|
+
# Or from a file:
|
|
520
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts --dump-swml \
|
|
521
|
+
--env-file .env.test
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
### Machine-Readable Output
|
|
525
|
+
|
|
526
|
+
Pipe SWML or tool results to `jq` or other JSON processors:
|
|
527
|
+
|
|
528
|
+
```bash
|
|
529
|
+
# Suppress logs and get clean JSON
|
|
530
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts --dump-swml --raw | jq '.sections.main'
|
|
531
|
+
|
|
532
|
+
# Pretty-printed JSON with no log noise
|
|
533
|
+
npx tsx src/cli/swaig-test.ts ./src/my-agent.ts --list-tools --format-json > tools.json
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
### Discover Agents in a File
|
|
537
|
+
|
|
538
|
+
When a module exports multiple agents, discover them and test a specific one:
|
|
539
|
+
|
|
540
|
+
```bash
|
|
541
|
+
# List all agents
|
|
542
|
+
npx tsx src/cli/swaig-test.ts ./src/multi-agent.ts --list-agents
|
|
543
|
+
|
|
544
|
+
# Output:
|
|
545
|
+
# SalesAgent
|
|
546
|
+
# SupportAgent
|
|
547
|
+
# BillingAgent
|
|
548
|
+
|
|
549
|
+
# Test a specific agent
|
|
550
|
+
npx tsx src/cli/swaig-test.ts ./src/multi-agent.ts --dump-swml --agent-class SupportAgent
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## Complete Option Reference
|
|
556
|
+
|
|
557
|
+
| Option | Argument | Default | Description |
|
|
558
|
+
|---|---|---|---|
|
|
559
|
+
| `--dump-swml` | -- | *(default action)* | Generate and output the SWML document. |
|
|
560
|
+
| `--list-tools` | -- | -- | List all registered SWAIG functions. |
|
|
561
|
+
| `--list-agents` | -- | -- | List all exported agents in the module. |
|
|
562
|
+
| `--exec` | `<function_name>` | -- | Execute a specific SWAIG function. |
|
|
563
|
+
| `--arg` | `key=value` | -- | Function argument (repeatable). |
|
|
564
|
+
| `--override` | `key=value` | -- | Override POST data field (repeatable). |
|
|
565
|
+
| `--agent-class` | `<export_name>` | -- | Use a specific named export. |
|
|
566
|
+
| `--route` | `<path>` | Agent's default | Override the agent's HTTP route. |
|
|
567
|
+
| `--call-type` | `sip \| webrtc` | `webrtc` | Call transport type. |
|
|
568
|
+
| `--call-direction` | `inbound \| outbound` | `inbound` | Call direction. |
|
|
569
|
+
| `--call-state` | `<state>` | `active` | Call state string. |
|
|
570
|
+
| `--call-id` | `<uuid>` | Random UUID | Override call ID. |
|
|
571
|
+
| `--from-number` | `<number>` | `+15551234567` | Caller's phone number. |
|
|
572
|
+
| `--to-extension` | `<ext>` | `test-agent` | Destination extension. |
|
|
573
|
+
| `--raw` | -- | -- | Raw JSON output, suppress logs. |
|
|
574
|
+
| `--verbose` | -- | -- | Enable debug-level logging. |
|
|
575
|
+
| `--format-json` | -- | -- | Pretty-print JSON output. |
|
|
576
|
+
| `--env` | `KEY=VALUE` | -- | Set environment variable (repeatable). |
|
|
577
|
+
| `--env-file` | `<path>` | -- | Load env vars from file. |
|
|
578
|
+
| `--simulate-serverless` | `lambda \| gcf \| azure \| cgi` | -- | Simulate serverless platform. |
|
|
579
|
+
| `--help`, `-h` | -- | -- | Show help message. |
|