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,440 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * swaig-test - CLI tool for testing SignalWire AI agents locally.
4
+ *
5
+ * Usage:
6
+ * swaig-test <agent-path> [options]
7
+ *
8
+ * Actions:
9
+ * --list-tools List all SWAIG functions with parameters
10
+ * --list-agents List all exported agents in a file
11
+ * --dump-swml Generate and output SWML document
12
+ * --exec <name> Execute a function (use --arg key=value for args)
13
+ *
14
+ * Options:
15
+ * --raw Raw JSON output (suppresses logs)
16
+ * --verbose Verbose output
17
+ * --format-json Format output as indented JSON
18
+ * --call-type sip|webrtc (default: webrtc)
19
+ * --call-direction inbound|outbound (default: inbound)
20
+ * --call-state active|ringing|hold (default: active)
21
+ * --call-id Override call ID
22
+ * --from-number Override from number
23
+ * --to-extension Override to extension
24
+ * --arg key=value Function argument (repeatable)
25
+ * --override k=v Override call data field (repeatable)
26
+ * --agent-class Name of specific agent class to use
27
+ * --route Route for agent (default: /)
28
+ * --env KEY=VALUE Set env var (repeatable)
29
+ * --env-file Load env vars from file
30
+ * --simulate-serverless <platform> Simulate serverless platform
31
+ */
32
+
33
+ import { loadAgent, listAgents } from './agent-loader.js';
34
+ import { generateFakePostData, generateMinimalPostData } from './mock-data.js';
35
+ import { suppressAllLogs, setGlobalLogLevel } from '../Logger.js';
36
+ import { ServerlessAdapter } from '../ServerlessAdapter.js';
37
+ import type { ServerlessPlatform } from '../ServerlessAdapter.js';
38
+
39
+ interface CliOptions {
40
+ agentPath: string;
41
+ action: 'list-tools' | 'list-agents' | 'dump-swml' | 'exec';
42
+ execName?: string;
43
+ raw: boolean;
44
+ verbose: boolean;
45
+ formatJson: boolean;
46
+ callType: 'sip' | 'webrtc';
47
+ callDirection: 'inbound' | 'outbound';
48
+ callState: string;
49
+ callId?: string;
50
+ fromNumber?: string;
51
+ toExtension?: string;
52
+ args: Record<string, unknown>;
53
+ overrides: Record<string, unknown>;
54
+ agentClass?: string;
55
+ route?: string;
56
+ envVars: Record<string, string>;
57
+ envFile?: string;
58
+ simulateServerless?: string;
59
+ }
60
+
61
+ function printUsage(): void {
62
+ console.log(`
63
+ swaig-test - CLI tool for testing SignalWire AI agents locally
64
+
65
+ Usage:
66
+ swaig-test <agent-path> [options]
67
+
68
+ Actions:
69
+ --list-tools List all SWAIG functions with parameters
70
+ --list-agents List all exported agents in a file
71
+ --dump-swml Generate and output SWML document
72
+ --exec <name> Execute a function (use --arg key=value for args)
73
+
74
+ Options:
75
+ --raw Raw JSON output (suppresses logs)
76
+ --verbose Verbose output
77
+ --format-json Format output as indented JSON
78
+ --call-type sip|webrtc (default: webrtc)
79
+ --call-direction inbound|outbound (default: inbound)
80
+ --call-state active|ringing|hold (default: active)
81
+ --call-id Override call ID
82
+ --from-number Override from number
83
+ --to-extension Override to extension
84
+ --arg key=value Function argument (repeatable)
85
+ --override k=v Override call data field (repeatable)
86
+ --agent-class Name of specific agent class to use
87
+ --route Route for the agent
88
+ --env KEY=VALUE Set env var (repeatable)
89
+ --env-file Load env vars from file
90
+ --simulate-serverless <platform> Simulate serverless (lambda|gcf|azure|cgi)
91
+ --help Show this help message
92
+ `);
93
+ }
94
+
95
+ function parseArgs(argv: string[]): CliOptions {
96
+ const args = argv.slice(2); // skip node + script
97
+ if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
98
+ printUsage();
99
+ process.exit(0);
100
+ }
101
+
102
+ const opts: CliOptions = {
103
+ agentPath: '',
104
+ action: 'dump-swml',
105
+ raw: false,
106
+ verbose: false,
107
+ formatJson: false,
108
+ callType: 'webrtc',
109
+ callDirection: 'inbound',
110
+ callState: 'active',
111
+ args: {},
112
+ overrides: {},
113
+ envVars: {},
114
+ };
115
+
116
+ let i = 0;
117
+
118
+ // First positional arg is the agent path
119
+ if (!args[0].startsWith('--')) {
120
+ opts.agentPath = args[0];
121
+ i = 1;
122
+ }
123
+
124
+ for (; i < args.length; i++) {
125
+ const arg = args[i];
126
+ switch (arg) {
127
+ case '--list-tools':
128
+ opts.action = 'list-tools';
129
+ break;
130
+ case '--list-agents':
131
+ opts.action = 'list-agents';
132
+ break;
133
+ case '--dump-swml':
134
+ opts.action = 'dump-swml';
135
+ break;
136
+ case '--exec':
137
+ opts.action = 'exec';
138
+ opts.execName = args[++i];
139
+ if (!opts.execName) {
140
+ console.error('Error: --exec requires a function name');
141
+ process.exit(1);
142
+ }
143
+ break;
144
+ case '--raw':
145
+ opts.raw = true;
146
+ break;
147
+ case '--verbose':
148
+ opts.verbose = true;
149
+ break;
150
+ case '--format-json':
151
+ opts.formatJson = true;
152
+ break;
153
+ case '--call-type':
154
+ opts.callType = args[++i] as 'sip' | 'webrtc';
155
+ break;
156
+ case '--call-direction':
157
+ opts.callDirection = args[++i] as 'inbound' | 'outbound';
158
+ break;
159
+ case '--call-state':
160
+ opts.callState = args[++i];
161
+ break;
162
+ case '--call-id':
163
+ opts.callId = args[++i];
164
+ break;
165
+ case '--from-number':
166
+ opts.fromNumber = args[++i];
167
+ break;
168
+ case '--to-extension':
169
+ opts.toExtension = args[++i];
170
+ break;
171
+ case '--agent-class':
172
+ opts.agentClass = args[++i];
173
+ break;
174
+ case '--route':
175
+ opts.route = args[++i];
176
+ break;
177
+ case '--simulate-serverless':
178
+ opts.simulateServerless = args[++i];
179
+ break;
180
+ case '--env-file':
181
+ opts.envFile = args[++i];
182
+ break;
183
+ case '--arg': {
184
+ const kv = args[++i];
185
+ if (!kv || !kv.includes('=')) {
186
+ console.error('Error: --arg requires key=value format');
187
+ process.exit(1);
188
+ }
189
+ const eqIdx = kv.indexOf('=');
190
+ const key = kv.slice(0, eqIdx);
191
+ const val = kv.slice(eqIdx + 1);
192
+ // Try to parse as JSON, fall back to string
193
+ try {
194
+ opts.args[key] = JSON.parse(val);
195
+ } catch {
196
+ opts.args[key] = val;
197
+ }
198
+ break;
199
+ }
200
+ case '--override': {
201
+ const kv = args[++i];
202
+ if (!kv || !kv.includes('=')) {
203
+ console.error('Error: --override requires key=value format');
204
+ process.exit(1);
205
+ }
206
+ const eqIdx = kv.indexOf('=');
207
+ const key = kv.slice(0, eqIdx);
208
+ const val = kv.slice(eqIdx + 1);
209
+ try {
210
+ opts.overrides[key] = JSON.parse(val);
211
+ } catch {
212
+ opts.overrides[key] = val;
213
+ }
214
+ break;
215
+ }
216
+ case '--env': {
217
+ const kv = args[++i];
218
+ if (!kv || !kv.includes('=')) {
219
+ console.error('Error: --env requires KEY=VALUE format');
220
+ process.exit(1);
221
+ }
222
+ const eqIdx = kv.indexOf('=');
223
+ opts.envVars[kv.slice(0, eqIdx)] = kv.slice(eqIdx + 1);
224
+ break;
225
+ }
226
+ default:
227
+ if (!opts.agentPath && !arg.startsWith('--')) {
228
+ opts.agentPath = arg;
229
+ } else {
230
+ console.error(`Unknown option: ${arg}`);
231
+ process.exit(1);
232
+ }
233
+ }
234
+ }
235
+
236
+ if (!opts.agentPath) {
237
+ console.error('Error: agent path is required');
238
+ printUsage();
239
+ process.exit(1);
240
+ }
241
+
242
+ return opts;
243
+ }
244
+
245
+ function loadEnvFile(filePath: string): void {
246
+ const { readFileSync } = require('node:fs');
247
+ const { resolve } = require('node:path');
248
+ const content = readFileSync(resolve(filePath), 'utf-8');
249
+ for (const line of content.split('\n')) {
250
+ const trimmed = line.trim();
251
+ if (!trimmed || trimmed.startsWith('#')) continue;
252
+ const eqIdx = trimmed.indexOf('=');
253
+ if (eqIdx > 0) {
254
+ const key = trimmed.slice(0, eqIdx).trim();
255
+ let val = trimmed.slice(eqIdx + 1).trim();
256
+ // Strip quotes
257
+ if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
258
+ val = val.slice(1, -1);
259
+ }
260
+ process.env[key] = val;
261
+ }
262
+ }
263
+ }
264
+
265
+ async function main(): Promise<void> {
266
+ const opts = parseArgs(process.argv);
267
+
268
+ if (opts.raw) {
269
+ suppressAllLogs(true);
270
+ } else if (opts.verbose) {
271
+ setGlobalLogLevel('debug');
272
+ }
273
+
274
+ // Apply env vars
275
+ if (opts.envFile) {
276
+ loadEnvFile(opts.envFile);
277
+ }
278
+ for (const [k, v] of Object.entries(opts.envVars)) {
279
+ process.env[k] = v;
280
+ }
281
+
282
+ // List agents action (doesn't need a loaded agent)
283
+ if (opts.action === 'list-agents') {
284
+ const agents = await listAgents(opts.agentPath);
285
+ if (opts.raw || opts.formatJson) {
286
+ console.log(JSON.stringify(agents, null, 2));
287
+ } else {
288
+ console.log(`\nExported agents in ${opts.agentPath}:\n`);
289
+ for (const name of agents) {
290
+ console.log(` ${name}`);
291
+ }
292
+ console.log();
293
+ }
294
+ return;
295
+ }
296
+
297
+ // Load agent
298
+ const agent = await loadAgent(opts.agentPath, opts.agentClass) as any;
299
+
300
+ // Apply --route override
301
+ if (opts.route && typeof agent.route !== 'undefined') {
302
+ agent.route = opts.route;
303
+ }
304
+
305
+ // Handle --simulate-serverless
306
+ if (opts.simulateServerless) {
307
+ const platform = opts.simulateServerless as ServerlessPlatform;
308
+ const adapter = new ServerlessAdapter(platform);
309
+ const app = agent.getApp();
310
+ const postData = generateFakePostData({
311
+ callType: opts.callType,
312
+ callDirection: opts.callDirection,
313
+ callState: opts.callState,
314
+ callId: opts.callId,
315
+ fromNumber: opts.fromNumber,
316
+ toExtension: opts.toExtension,
317
+ overrides: opts.overrides,
318
+ });
319
+ const event = {
320
+ httpMethod: 'POST',
321
+ path: agent.route ?? '/',
322
+ headers: {
323
+ 'content-type': 'application/json',
324
+ 'authorization': 'Basic ' + Buffer.from(`${agent.basicAuthCreds?.[0] ?? 'user'}:${agent.basicAuthCreds?.[1] ?? 'pass'}`).toString('base64'),
325
+ },
326
+ body: postData,
327
+ };
328
+ const response = await adapter.handleRequest(app, event);
329
+ if (opts.raw || opts.formatJson) {
330
+ try {
331
+ console.log(JSON.stringify(JSON.parse(response.body), null, 2));
332
+ } catch {
333
+ console.log(response.body);
334
+ }
335
+ } else {
336
+ console.log(`\n--- Serverless Simulation (${platform}) ---`);
337
+ console.log(`Status: ${response.statusCode}`);
338
+ console.log(`Headers: ${JSON.stringify(response.headers, null, 2)}`);
339
+ console.log('Body:');
340
+ try {
341
+ console.log(JSON.stringify(JSON.parse(response.body), null, 2));
342
+ } catch {
343
+ console.log(response.body);
344
+ }
345
+ console.log();
346
+ }
347
+ return;
348
+ }
349
+
350
+ switch (opts.action) {
351
+ case 'list-tools': {
352
+ const tools = agent.getRegisteredTools();
353
+ if (opts.raw || opts.formatJson) {
354
+ console.log(JSON.stringify(tools, null, 2));
355
+ } else {
356
+ if (tools.length === 0) {
357
+ console.log('No tools registered.');
358
+ } else {
359
+ console.log(`\nRegistered tools (${tools.length}):\n`);
360
+ for (const tool of tools) {
361
+ console.log(` ${tool.name}`);
362
+ console.log(` Description: ${tool.description}`);
363
+ if (tool.parameters && Object.keys(tool.parameters).length) {
364
+ console.log(` Parameters: ${JSON.stringify(tool.parameters, null, 6).replace(/\n/g, '\n ')}`);
365
+ }
366
+ console.log();
367
+ }
368
+ }
369
+ }
370
+ break;
371
+ }
372
+
373
+ case 'dump-swml': {
374
+ const postData = generateFakePostData({
375
+ callType: opts.callType,
376
+ callDirection: opts.callDirection,
377
+ callState: opts.callState,
378
+ callId: opts.callId,
379
+ fromNumber: opts.fromNumber,
380
+ toExtension: opts.toExtension,
381
+ overrides: opts.overrides,
382
+ });
383
+ const swml = agent.renderSwml(postData['call_id'] as string);
384
+ if (opts.raw || opts.formatJson) {
385
+ console.log(JSON.stringify(JSON.parse(swml), null, 2));
386
+ } else {
387
+ console.log('\n--- SWML Document ---\n');
388
+ console.log(JSON.stringify(JSON.parse(swml), null, 2));
389
+ console.log();
390
+ }
391
+ break;
392
+ }
393
+
394
+ case 'exec': {
395
+ if (!opts.execName) {
396
+ console.error('Error: --exec requires a function name');
397
+ process.exit(1);
398
+ }
399
+
400
+ const tool = agent.getTool(opts.execName);
401
+ if (!tool) {
402
+ console.error(`Error: function '${opts.execName}' not found`);
403
+ const available = agent.getRegisteredTools().map((t: any) => t.name);
404
+ if (available.length) {
405
+ console.error(`Available functions: ${available.join(', ')}`);
406
+ }
407
+ process.exit(1);
408
+ }
409
+
410
+ const postData = generateMinimalPostData(opts.execName, opts.args, {
411
+ callId: opts.callId,
412
+ overrides: opts.overrides,
413
+ });
414
+
415
+ if (!opts.raw) {
416
+ console.log(`\nExecuting: ${opts.execName}`);
417
+ if (Object.keys(opts.args).length) {
418
+ console.log(`Arguments: ${JSON.stringify(opts.args)}`);
419
+ }
420
+ console.log();
421
+ }
422
+
423
+ const result = await tool.execute(opts.args, postData);
424
+
425
+ if (opts.raw || opts.formatJson) {
426
+ console.log(JSON.stringify(result, null, 2));
427
+ } else {
428
+ console.log('--- Result ---\n');
429
+ console.log(JSON.stringify(result, null, 2));
430
+ console.log();
431
+ }
432
+ break;
433
+ }
434
+ }
435
+ }
436
+
437
+ main().catch((err) => {
438
+ console.error(err.message ?? err);
439
+ process.exit(1);
440
+ });
package/src/index.ts ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * SignalWire AI Agents SDK for TypeScript
3
+ *
4
+ * Build AI voice agents as HTTP microservices that serve SWML documents
5
+ * and handle SWAIG function callbacks.
6
+ */
7
+
8
+ // Core agent
9
+ export { AgentBase } from './AgentBase.js';
10
+ export { AgentServer } from './AgentServer.js';
11
+
12
+ // Tool results & functions
13
+ export { SwaigFunctionResult } from './SwaigFunctionResult.js';
14
+ export type { PaymentPrompt, PaymentAction, PaymentParameter } from './SwaigFunctionResult.js';
15
+ export { SwaigFunction } from './SwaigFunction.js';
16
+ export type { SwaigHandler, SwaigFunctionOptions } from './SwaigFunction.js';
17
+
18
+ // DataMap (server-side tools)
19
+ export { DataMap, createSimpleApiTool, createExpressionTool } from './DataMap.js';
20
+
21
+ // Prompt Object Model
22
+ export { PomBuilder, PomSection } from './PomBuilder.js';
23
+ export type { PomSectionData } from './PomBuilder.js';
24
+
25
+ // SWML builder
26
+ export { SwmlBuilder } from './SwmlBuilder.js';
27
+
28
+ // Prompt management
29
+ export { PromptManager } from './PromptManager.js';
30
+
31
+ // Contexts & Steps
32
+ export {
33
+ ContextBuilder,
34
+ Context,
35
+ Step,
36
+ GatherInfo,
37
+ GatherQuestion,
38
+ createSimpleContext,
39
+ } from './ContextBuilder.js';
40
+
41
+ // Security
42
+ export { SessionManager } from './SessionManager.js';
43
+
44
+ // SSL
45
+ export { SslConfig } from './SslConfig.js';
46
+ export type { SslOptions } from './SslConfig.js';
47
+
48
+ // Schema Validation
49
+ export { SchemaUtils } from './SchemaUtils.js';
50
+ export type { ValidationResult } from './SchemaUtils.js';
51
+
52
+ // Auth
53
+ export { AuthHandler } from './AuthHandler.js';
54
+ export type { AuthConfig } from './AuthHandler.js';
55
+
56
+ // Config
57
+ export { ConfigLoader } from './ConfigLoader.js';
58
+
59
+ // Logging
60
+ export { Logger, getLogger, setGlobalLogLevel, suppressAllLogs, setGlobalLogFormat, setGlobalLogColor, resetLoggingConfiguration } from './Logger.js';
61
+
62
+ // Serverless
63
+ export { ServerlessAdapter } from './ServerlessAdapter.js';
64
+ export type { ServerlessPlatform, ServerlessEvent, ServerlessResponse } from './ServerlessAdapter.js';
65
+
66
+ // Skills
67
+ export { SkillBase, SkillManager, SkillRegistry } from './skills/index.js';
68
+ export type { SkillConfig, SkillToolDefinition, SkillPromptSection, SkillManifest, SkillFactory } from './skills/index.js';
69
+
70
+ // Built-in Skills
71
+ export { registerBuiltinSkills } from './skills/builtin/index.js';
72
+ export {
73
+ DateTimeSkill, MathSkill, JokeSkill,
74
+ WeatherApiSkill, PlayBackgroundFileSkill, SwmlTransferSkill,
75
+ ApiNinjasTriviaSkill, InfoGathererSkill, CustomSkillsSkill,
76
+ WebSearchSkill, WikipediaSearchSkill, GoogleMapsSkill,
77
+ DataSphereSkill, DataSphereServerlessSkill, NativeVectorSearchSkill,
78
+ SpiderSkill, ClaudeSkill, McpGatewaySkill,
79
+ } from './skills/builtin/index.js';
80
+
81
+ // Prefab Agents
82
+ export {
83
+ InfoGathererAgent, SurveyAgent, FAQBotAgent,
84
+ ConciergeAgent, ReceptionistAgent,
85
+ } from './prefabs/index.js';
86
+ export type {
87
+ InfoGathererConfig, SurveyConfig, FAQBotConfig,
88
+ ConciergeConfig, ReceptionistConfig,
89
+ } from './prefabs/index.js';
90
+
91
+ // Types
92
+ export type {
93
+ AgentOptions,
94
+ LanguageConfig,
95
+ PronunciationRule,
96
+ FunctionInclude,
97
+ DynamicConfigCallback,
98
+ SummaryCallback,
99
+ } from './types.js';