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.
Files changed (245) hide show
  1. package/CLAUDE.md +112 -0
  2. package/README.md +417 -0
  3. package/dist/AgentBase.d.ts +481 -0
  4. package/dist/AgentBase.js +1155 -0
  5. package/dist/AgentBase.js.map +1 -0
  6. package/dist/AgentServer.d.ts +60 -0
  7. package/dist/AgentServer.js +128 -0
  8. package/dist/AgentServer.js.map +1 -0
  9. package/dist/AuthHandler.d.ts +56 -0
  10. package/dist/AuthHandler.js +119 -0
  11. package/dist/AuthHandler.js.map +1 -0
  12. package/dist/ConfigLoader.d.ts +68 -0
  13. package/dist/ConfigLoader.js +150 -0
  14. package/dist/ConfigLoader.js.map +1 -0
  15. package/dist/ContextBuilder.d.ts +431 -0
  16. package/dist/ContextBuilder.js +751 -0
  17. package/dist/ContextBuilder.js.map +1 -0
  18. package/dist/DataMap.d.ts +179 -0
  19. package/dist/DataMap.js +321 -0
  20. package/dist/DataMap.js.map +1 -0
  21. package/dist/Logger.d.ts +91 -0
  22. package/dist/Logger.js +191 -0
  23. package/dist/Logger.js.map +1 -0
  24. package/dist/PomBuilder.d.ts +144 -0
  25. package/dist/PomBuilder.js +249 -0
  26. package/dist/PomBuilder.js.map +1 -0
  27. package/dist/PromptManager.d.ts +85 -0
  28. package/dist/PromptManager.js +108 -0
  29. package/dist/PromptManager.js.map +1 -0
  30. package/dist/SchemaUtils.d.ts +42 -0
  31. package/dist/SchemaUtils.js +148 -0
  32. package/dist/SchemaUtils.js.map +1 -0
  33. package/dist/ServerlessAdapter.d.ts +100 -0
  34. package/dist/ServerlessAdapter.js +166 -0
  35. package/dist/ServerlessAdapter.js.map +1 -0
  36. package/dist/SessionManager.d.ts +86 -0
  37. package/dist/SessionManager.js +155 -0
  38. package/dist/SessionManager.js.map +1 -0
  39. package/dist/SslConfig.d.ts +77 -0
  40. package/dist/SslConfig.js +100 -0
  41. package/dist/SslConfig.js.map +1 -0
  42. package/dist/SwaigFunction.d.ts +88 -0
  43. package/dist/SwaigFunction.js +125 -0
  44. package/dist/SwaigFunction.js.map +1 -0
  45. package/dist/SwaigFunctionResult.d.ts +442 -0
  46. package/dist/SwaigFunctionResult.js +735 -0
  47. package/dist/SwaigFunctionResult.js.map +1 -0
  48. package/dist/SwmlBuilder.d.ts +37 -0
  49. package/dist/SwmlBuilder.js +55 -0
  50. package/dist/SwmlBuilder.js.map +1 -0
  51. package/dist/cli/agent-loader.d.ts +22 -0
  52. package/dist/cli/agent-loader.js +106 -0
  53. package/dist/cli/agent-loader.js.map +1 -0
  54. package/dist/cli/mock-data.d.ts +37 -0
  55. package/dist/cli/mock-data.js +79 -0
  56. package/dist/cli/mock-data.js.map +1 -0
  57. package/dist/cli/swaig-test.d.ts +32 -0
  58. package/dist/cli/swaig-test.js +405 -0
  59. package/dist/cli/swaig-test.js.map +1 -0
  60. package/dist/index.d.ts +36 -0
  61. package/dist/index.js +44 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/prefabs/ConciergeAgent.d.ts +64 -0
  64. package/dist/prefabs/ConciergeAgent.js +188 -0
  65. package/dist/prefabs/ConciergeAgent.js.map +1 -0
  66. package/dist/prefabs/FAQBotAgent.d.ts +68 -0
  67. package/dist/prefabs/FAQBotAgent.js +206 -0
  68. package/dist/prefabs/FAQBotAgent.js.map +1 -0
  69. package/dist/prefabs/InfoGathererAgent.d.ts +73 -0
  70. package/dist/prefabs/InfoGathererAgent.js +202 -0
  71. package/dist/prefabs/InfoGathererAgent.js.map +1 -0
  72. package/dist/prefabs/ReceptionistAgent.d.ts +65 -0
  73. package/dist/prefabs/ReceptionistAgent.js +205 -0
  74. package/dist/prefabs/ReceptionistAgent.js.map +1 -0
  75. package/dist/prefabs/SurveyAgent.d.ts +84 -0
  76. package/dist/prefabs/SurveyAgent.js +324 -0
  77. package/dist/prefabs/SurveyAgent.js.map +1 -0
  78. package/dist/prefabs/index.d.ts +13 -0
  79. package/dist/prefabs/index.js +14 -0
  80. package/dist/prefabs/index.js.map +1 -0
  81. package/dist/skills/SkillBase.d.ts +134 -0
  82. package/dist/skills/SkillBase.js +105 -0
  83. package/dist/skills/SkillBase.js.map +1 -0
  84. package/dist/skills/SkillManager.d.ts +83 -0
  85. package/dist/skills/SkillManager.js +159 -0
  86. package/dist/skills/SkillManager.js.map +1 -0
  87. package/dist/skills/SkillRegistry.d.ts +105 -0
  88. package/dist/skills/SkillRegistry.js +195 -0
  89. package/dist/skills/SkillRegistry.js.map +1 -0
  90. package/dist/skills/builtin/api_ninjas_trivia.d.ts +35 -0
  91. package/dist/skills/builtin/api_ninjas_trivia.js +161 -0
  92. package/dist/skills/builtin/api_ninjas_trivia.js.map +1 -0
  93. package/dist/skills/builtin/claude_skills.d.ts +34 -0
  94. package/dist/skills/builtin/claude_skills.js +156 -0
  95. package/dist/skills/builtin/claude_skills.js.map +1 -0
  96. package/dist/skills/builtin/custom_skills.d.ts +59 -0
  97. package/dist/skills/builtin/custom_skills.js +231 -0
  98. package/dist/skills/builtin/custom_skills.js.map +1 -0
  99. package/dist/skills/builtin/datasphere.d.ts +34 -0
  100. package/dist/skills/builtin/datasphere.js +163 -0
  101. package/dist/skills/builtin/datasphere.js.map +1 -0
  102. package/dist/skills/builtin/datasphere_serverless.d.ts +54 -0
  103. package/dist/skills/builtin/datasphere_serverless.js +155 -0
  104. package/dist/skills/builtin/datasphere_serverless.js.map +1 -0
  105. package/dist/skills/builtin/datetime.d.ts +31 -0
  106. package/dist/skills/builtin/datetime.js +95 -0
  107. package/dist/skills/builtin/datetime.js.map +1 -0
  108. package/dist/skills/builtin/google_maps.d.ts +33 -0
  109. package/dist/skills/builtin/google_maps.js +233 -0
  110. package/dist/skills/builtin/google_maps.js.map +1 -0
  111. package/dist/skills/builtin/index.d.ts +28 -0
  112. package/dist/skills/builtin/index.js +75 -0
  113. package/dist/skills/builtin/index.js.map +1 -0
  114. package/dist/skills/builtin/info_gatherer.d.ts +52 -0
  115. package/dist/skills/builtin/info_gatherer.js +237 -0
  116. package/dist/skills/builtin/info_gatherer.js.map +1 -0
  117. package/dist/skills/builtin/joke.d.ts +32 -0
  118. package/dist/skills/builtin/joke.js +142 -0
  119. package/dist/skills/builtin/joke.js.map +1 -0
  120. package/dist/skills/builtin/math.d.ts +33 -0
  121. package/dist/skills/builtin/math.js +120 -0
  122. package/dist/skills/builtin/math.js.map +1 -0
  123. package/dist/skills/builtin/mcp_gateway.d.ts +35 -0
  124. package/dist/skills/builtin/mcp_gateway.js +85 -0
  125. package/dist/skills/builtin/mcp_gateway.js.map +1 -0
  126. package/dist/skills/builtin/native_vector_search.d.ts +44 -0
  127. package/dist/skills/builtin/native_vector_search.js +248 -0
  128. package/dist/skills/builtin/native_vector_search.js.map +1 -0
  129. package/dist/skills/builtin/play_background_file.d.ts +34 -0
  130. package/dist/skills/builtin/play_background_file.js +135 -0
  131. package/dist/skills/builtin/play_background_file.js.map +1 -0
  132. package/dist/skills/builtin/spider.d.ts +34 -0
  133. package/dist/skills/builtin/spider.js +164 -0
  134. package/dist/skills/builtin/spider.js.map +1 -0
  135. package/dist/skills/builtin/swml_transfer.d.ts +44 -0
  136. package/dist/skills/builtin/swml_transfer.js +204 -0
  137. package/dist/skills/builtin/swml_transfer.js.map +1 -0
  138. package/dist/skills/builtin/weather_api.d.ts +34 -0
  139. package/dist/skills/builtin/weather_api.js +136 -0
  140. package/dist/skills/builtin/weather_api.js.map +1 -0
  141. package/dist/skills/builtin/web_search.d.ts +34 -0
  142. package/dist/skills/builtin/web_search.js +141 -0
  143. package/dist/skills/builtin/web_search.js.map +1 -0
  144. package/dist/skills/builtin/wikipedia_search.d.ts +34 -0
  145. package/dist/skills/builtin/wikipedia_search.js +166 -0
  146. package/dist/skills/builtin/wikipedia_search.js.map +1 -0
  147. package/dist/skills/index.d.ts +11 -0
  148. package/dist/skills/index.js +10 -0
  149. package/dist/skills/index.js.map +1 -0
  150. package/dist/types.d.ts +85 -0
  151. package/dist/types.js +5 -0
  152. package/dist/types.js.map +1 -0
  153. package/docs/agent-guide.md +869 -0
  154. package/docs/api-reference.md +2419 -0
  155. package/docs/architecture.md +843 -0
  156. package/docs/cli-guide.md +579 -0
  157. package/docs/configuration.md +422 -0
  158. package/docs/contexts-guide.md +787 -0
  159. package/docs/datamap-guide.md +1141 -0
  160. package/docs/prefabs-guide.md +830 -0
  161. package/docs/security.md +436 -0
  162. package/docs/serverless-guide.md +513 -0
  163. package/docs/skills-guide.md +845 -0
  164. package/docs/swaig-reference.md +1627 -0
  165. package/examples/call-flow.ts +60 -0
  166. package/examples/contexts-steps.ts +62 -0
  167. package/examples/datamap-tools.ts +52 -0
  168. package/examples/dynamic-config.ts +51 -0
  169. package/examples/multi-agent.ts +67 -0
  170. package/examples/pom-prompt.ts +68 -0
  171. package/examples/simple-agent.ts +33 -0
  172. package/package.json +35 -0
  173. package/src/AgentBase.ts +1279 -0
  174. package/src/AgentServer.ts +149 -0
  175. package/src/AuthHandler.ts +141 -0
  176. package/src/ConfigLoader.ts +165 -0
  177. package/src/ContextBuilder.ts +796 -0
  178. package/src/DataMap.ts +365 -0
  179. package/src/Logger.ts +197 -0
  180. package/src/PomBuilder.ts +298 -0
  181. package/src/PromptManager.ts +133 -0
  182. package/src/SchemaUtils.ts +170 -0
  183. package/src/ServerlessAdapter.ts +218 -0
  184. package/src/SessionManager.ts +161 -0
  185. package/src/SslConfig.ts +118 -0
  186. package/src/SwaigFunction.ts +168 -0
  187. package/src/SwaigFunctionResult.ts +864 -0
  188. package/src/SwmlBuilder.ts +62 -0
  189. package/src/cli/agent-loader.ts +122 -0
  190. package/src/cli/mock-data.ts +110 -0
  191. package/src/cli/swaig-test.ts +440 -0
  192. package/src/index.ts +99 -0
  193. package/src/prefabs/ConciergeAgent.ts +251 -0
  194. package/src/prefabs/FAQBotAgent.ts +263 -0
  195. package/src/prefabs/InfoGathererAgent.ts +276 -0
  196. package/src/prefabs/ReceptionistAgent.ts +277 -0
  197. package/src/prefabs/SurveyAgent.ts +413 -0
  198. package/src/prefabs/index.ts +23 -0
  199. package/src/skills/SkillBase.ts +184 -0
  200. package/src/skills/SkillManager.ts +177 -0
  201. package/src/skills/SkillRegistry.ts +231 -0
  202. package/src/skills/builtin/api_ninjas_trivia.ts +230 -0
  203. package/src/skills/builtin/claude_skills.ts +239 -0
  204. package/src/skills/builtin/custom_skills.ts +326 -0
  205. package/src/skills/builtin/datasphere.ts +225 -0
  206. package/src/skills/builtin/datasphere_serverless.ts +194 -0
  207. package/src/skills/builtin/datetime.ts +115 -0
  208. package/src/skills/builtin/google_maps.ts +347 -0
  209. package/src/skills/builtin/index.ts +79 -0
  210. package/src/skills/builtin/info_gatherer.ts +331 -0
  211. package/src/skills/builtin/joke.ts +180 -0
  212. package/src/skills/builtin/math.ts +150 -0
  213. package/src/skills/builtin/mcp_gateway.ts +99 -0
  214. package/src/skills/builtin/native_vector_search.ts +327 -0
  215. package/src/skills/builtin/play_background_file.ts +189 -0
  216. package/src/skills/builtin/spider.ts +232 -0
  217. package/src/skills/builtin/swml_transfer.ts +285 -0
  218. package/src/skills/builtin/weather_api.ts +193 -0
  219. package/src/skills/builtin/web_search.ts +212 -0
  220. package/src/skills/builtin/wikipedia_search.ts +248 -0
  221. package/src/skills/index.ts +12 -0
  222. package/src/types.ts +99 -0
  223. package/tests/AgentBase.test.ts +693 -0
  224. package/tests/AgentServer.test.ts +102 -0
  225. package/tests/AuthHandler.test.ts +121 -0
  226. package/tests/ConfigLoader.test.ts +121 -0
  227. package/tests/DataMap.test.ts +286 -0
  228. package/tests/Logger.test.ts +218 -0
  229. package/tests/PomBuilder.test.ts +164 -0
  230. package/tests/ProxyDetection.test.ts +185 -0
  231. package/tests/SchemaUtils.test.ts +106 -0
  232. package/tests/ServerlessAdapter.test.ts +200 -0
  233. package/tests/SessionManager.test.ts +139 -0
  234. package/tests/SslConfig.test.ts +97 -0
  235. package/tests/SwaigFunctionResult.test.ts +298 -0
  236. package/tests/cli/mock-data.test.ts +94 -0
  237. package/tests/cli/swaig-test.test.ts +96 -0
  238. package/tests/prefabs/prefabs.test.ts +854 -0
  239. package/tests/setup.ts +6 -0
  240. package/tests/skills/SkillBase.test.ts +118 -0
  241. package/tests/skills/SkillManager.test.ts +164 -0
  242. package/tests/skills/SkillRegistry.test.ts +124 -0
  243. package/tests/skills/builtin.test.ts +924 -0
  244. package/tsconfig.json +18 -0
  245. 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. |