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,150 @@
1
+ /**
2
+ * ConfigLoader - JSON config file loader with env var interpolation.
3
+ *
4
+ * Supports ${VAR|default} syntax for env var substitution and
5
+ * dot-notation access for nested values.
6
+ */
7
+ import { readFileSync, existsSync } from 'node:fs';
8
+ import { resolve, join } from 'node:path';
9
+ const ENV_VAR_PATTERN = /\$\{([^}|]+)(?:\|([^}]*))?\}/g;
10
+ /** JSON configuration file loader with environment variable interpolation and dot-notation access. */
11
+ export class ConfigLoader {
12
+ data = {};
13
+ filePath = null;
14
+ /**
15
+ * Create a new ConfigLoader, optionally loading a JSON file immediately.
16
+ * @param filePath - Path to a JSON config file to load on construction.
17
+ */
18
+ constructor(filePath) {
19
+ if (filePath) {
20
+ this.load(filePath);
21
+ }
22
+ }
23
+ /**
24
+ * Load configuration from a JSON file, performing `${VAR|default}` env var interpolation on the raw text.
25
+ * @param filePath - Path to the JSON config file.
26
+ * @returns This instance for chaining.
27
+ */
28
+ load(filePath) {
29
+ const absPath = resolve(filePath);
30
+ if (!existsSync(absPath)) {
31
+ throw new Error(`Config file not found: ${absPath}`);
32
+ }
33
+ const raw = readFileSync(absPath, 'utf-8');
34
+ const interpolated = this.interpolateEnvVars(raw);
35
+ this.data = JSON.parse(interpolated);
36
+ this.filePath = absPath;
37
+ return this;
38
+ }
39
+ /**
40
+ * Search for a config file in standard locations (CWD, `./config`, `$HOME/.signalwire`).
41
+ * @param filename - The config file name to search for.
42
+ * @returns A loaded ConfigLoader if found, or null if the file does not exist in any search path.
43
+ */
44
+ static search(filename) {
45
+ const searchPaths = [
46
+ process.cwd(),
47
+ join(process.cwd(), 'config'),
48
+ join(process.env['HOME'] ?? '', '.signalwire'),
49
+ ];
50
+ for (const dir of searchPaths) {
51
+ const filePath = join(dir, filename);
52
+ if (existsSync(filePath)) {
53
+ return new ConfigLoader(filePath);
54
+ }
55
+ }
56
+ return null;
57
+ }
58
+ /**
59
+ * Retrieve a configuration value using a dot-notation path (e.g. `'server.port'`).
60
+ * @param path - Dot-separated key path into the config object.
61
+ * @param defaultValue - Value returned when the path does not exist.
62
+ * @returns The resolved value, or defaultValue if not found.
63
+ */
64
+ get(path, defaultValue) {
65
+ const parts = path.split('.');
66
+ let current = this.data;
67
+ for (const part of parts) {
68
+ if (current === null || current === undefined || typeof current !== 'object') {
69
+ return defaultValue;
70
+ }
71
+ current = current[part];
72
+ }
73
+ return (current !== undefined ? current : defaultValue);
74
+ }
75
+ /**
76
+ * Set a configuration value at the given dot-notation path, creating intermediate objects as needed.
77
+ * @param path - Dot-separated key path into the config object.
78
+ * @param value - The value to store.
79
+ * @returns This instance for chaining.
80
+ */
81
+ set(path, value) {
82
+ const parts = path.split('.');
83
+ let current = this.data;
84
+ for (let i = 0; i < parts.length - 1; i++) {
85
+ const part = parts[i];
86
+ if (!(part in current) || typeof current[part] !== 'object' || current[part] === null) {
87
+ current[part] = {};
88
+ }
89
+ current = current[part];
90
+ }
91
+ current[parts[parts.length - 1]] = value;
92
+ return this;
93
+ }
94
+ /**
95
+ * Check whether a dot-notation path exists in the loaded configuration.
96
+ * @param path - Dot-separated key path to check.
97
+ * @returns True if the path resolves to a defined value.
98
+ */
99
+ has(path) {
100
+ const parts = path.split('.');
101
+ let current = this.data;
102
+ for (const part of parts) {
103
+ if (current === null || current === undefined || typeof current !== 'object') {
104
+ return false;
105
+ }
106
+ if (!(part in current))
107
+ return false;
108
+ current = current[part];
109
+ }
110
+ return true;
111
+ }
112
+ /**
113
+ * Return a shallow copy of the entire configuration object.
114
+ * @returns A copy of the top-level config data.
115
+ */
116
+ getAll() {
117
+ return { ...this.data };
118
+ }
119
+ /**
120
+ * Return the absolute path of the loaded config file, if any.
121
+ * @returns The file path, or null if config was loaded from an object.
122
+ */
123
+ getFilePath() {
124
+ return this.filePath;
125
+ }
126
+ /**
127
+ * Load configuration from a plain object instead of a file, useful for testing or programmatic setup.
128
+ * @param obj - The configuration object to use.
129
+ * @returns This instance for chaining.
130
+ */
131
+ loadFromObject(obj) {
132
+ this.data = { ...obj };
133
+ this.filePath = null;
134
+ return this;
135
+ }
136
+ /**
137
+ * Interpolate ${VAR|default} patterns in a string.
138
+ */
139
+ interpolateEnvVars(input) {
140
+ return input.replace(ENV_VAR_PATTERN, (_match, varName, defaultValue) => {
141
+ const envVal = process.env[varName.trim()];
142
+ if (envVal !== undefined)
143
+ return envVal;
144
+ if (defaultValue !== undefined)
145
+ return defaultValue;
146
+ return '';
147
+ });
148
+ }
149
+ }
150
+ //# sourceMappingURL=ConfigLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigLoader.js","sourceRoot":"","sources":["../src/ConfigLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,eAAe,GAAG,+BAA+B,CAAC;AAExD,sGAAsG;AACtG,MAAM,OAAO,YAAY;IACf,IAAI,GAA4B,EAAE,CAAC;IACnC,QAAQ,GAAkB,IAAI,CAAC;IAEvC;;;OAGG;IACH,YAAY,QAAiB;QAC3B,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,QAAgB;QACnB,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAClC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAA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C7E,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,CAAC,CAAC,IAAI,IAAK,OAAmC,CAAC;gBAAE,OAAO,KAAK,CAAC;YAClE,OAAO,GAAI,OAAmC,CAAC,IAAI,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,MAAM;QACJ,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,GAA4B;QACzC,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,KAAa;QACtC,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,OAAe,EAAE,YAAqB,EAAE,EAAE;YACvF,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YAC3C,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,MAAM,CAAC;YACxC,IAAI,YAAY,KAAK,SAAS;gBAAE,OAAO,YAAY,CAAC;YACpD,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,431 @@
1
+ /**
2
+ * ContextBuilder - Contexts and Steps workflow system.
3
+ *
4
+ * Contexts contain ordered Steps, each with prompt text/POM sections,
5
+ * completion criteria, function restrictions, and navigation rules.
6
+ */
7
+ /** Represents a single question within a gather operation. */
8
+ export declare class GatherQuestion {
9
+ /** Unique key used to store the answer. */
10
+ key: string;
11
+ /** The question text presented to the user. */
12
+ question: string;
13
+ /** Expected answer type (e.g., "string", "number"). */
14
+ type: string;
15
+ /** Whether the answer requires user confirmation. */
16
+ confirm: boolean;
17
+ /** Optional additional prompt context for this question. */
18
+ prompt?: string;
19
+ /** Optional list of SWAIG function names available during this question. */
20
+ functions?: string[];
21
+ /**
22
+ * Creates a new GatherQuestion.
23
+ * @param opts - Question configuration including key, question text, and optional type/confirm/prompt/functions.
24
+ */
25
+ constructor(opts: {
26
+ key: string;
27
+ question: string;
28
+ type?: string;
29
+ confirm?: boolean;
30
+ prompt?: string;
31
+ functions?: string[];
32
+ });
33
+ /**
34
+ * Serializes this question to a plain object for SWML output.
35
+ * @returns A dictionary representation of this question.
36
+ */
37
+ toDict(): Record<string, unknown>;
38
+ }
39
+ /** Collects structured information from the user through a series of questions. */
40
+ export declare class GatherInfo {
41
+ private questions;
42
+ private outputKey?;
43
+ private completionAction?;
44
+ private prompt?;
45
+ /**
46
+ * Creates a new GatherInfo.
47
+ * @param opts - Optional output key, completion action, and prompt configuration.
48
+ */
49
+ constructor(opts?: {
50
+ outputKey?: string;
51
+ completionAction?: string;
52
+ prompt?: string;
53
+ });
54
+ /**
55
+ * Adds a question to this gather operation.
56
+ * @param opts - Question configuration including key, question text, and optional type/confirm/prompt/functions.
57
+ * @returns This GatherInfo for chaining.
58
+ */
59
+ addQuestion(opts: {
60
+ key: string;
61
+ question: string;
62
+ type?: string;
63
+ confirm?: boolean;
64
+ prompt?: string;
65
+ functions?: string[];
66
+ }): this;
67
+ /**
68
+ * Returns all questions in this gather operation.
69
+ * @returns The array of GatherQuestion instances.
70
+ */
71
+ getQuestions(): GatherQuestion[];
72
+ /**
73
+ * Serializes this gather operation to a plain object for SWML output.
74
+ * @returns A dictionary representation of the gather info and its questions.
75
+ */
76
+ toDict(): Record<string, unknown>;
77
+ }
78
+ /** A single step within a context, with prompt content, criteria, function restrictions, and navigation rules. */
79
+ export declare class Step {
80
+ /** The unique name identifying this step within its context. */
81
+ name: string;
82
+ private text;
83
+ private stepCriteria;
84
+ private functions;
85
+ private validSteps;
86
+ private validContexts;
87
+ private sections;
88
+ private gatherInfo;
89
+ private _end;
90
+ private skipUserTurn;
91
+ private _skipToNextStep;
92
+ private resetSystemPrompt;
93
+ private resetUserPrompt;
94
+ private resetConsolidate;
95
+ private resetFullReset;
96
+ /**
97
+ * Creates a new Step.
98
+ * @param name - The unique step name.
99
+ */
100
+ constructor(name: string);
101
+ /**
102
+ * Sets raw text content for this step, mutually exclusive with POM sections.
103
+ * @param text - The raw prompt text.
104
+ * @returns This step for chaining.
105
+ */
106
+ setText(text: string): this;
107
+ /**
108
+ * Adds a POM section with a body, mutually exclusive with raw text.
109
+ * @param title - The section heading.
110
+ * @param body - The section body text.
111
+ * @returns This step for chaining.
112
+ */
113
+ addSection(title: string, body: string): this;
114
+ /**
115
+ * Adds a POM section with bullet points, mutually exclusive with raw text.
116
+ * @param title - The section heading.
117
+ * @param bullets - The list of bullet point strings.
118
+ * @returns This step for chaining.
119
+ */
120
+ addBullets(title: string, bullets: string[]): this;
121
+ /**
122
+ * Sets the criteria that must be met before this step is considered complete.
123
+ * @param criteria - A description of the completion criteria.
124
+ * @returns This step for chaining.
125
+ */
126
+ setStepCriteria(criteria: string): this;
127
+ /**
128
+ * Restricts which SWAIG functions are available during this step.
129
+ * @param functions - A function name, list of names, or "*" for all.
130
+ * @returns This step for chaining.
131
+ */
132
+ setFunctions(functions: string | string[]): this;
133
+ /**
134
+ * Sets which steps the AI may navigate to from this step.
135
+ * @param steps - List of allowed step names.
136
+ * @returns This step for chaining.
137
+ */
138
+ setValidSteps(steps: string[]): this;
139
+ /**
140
+ * Sets which contexts the AI may navigate to from this step.
141
+ * @param contexts - List of allowed context names.
142
+ * @returns This step for chaining.
143
+ */
144
+ setValidContexts(contexts: string[]): this;
145
+ /**
146
+ * Marks this step as an end step, terminating the conversation when reached.
147
+ * @param end - Whether this is an end step.
148
+ * @returns This step for chaining.
149
+ */
150
+ setEnd(end: boolean): this;
151
+ /**
152
+ * Sets whether to skip waiting for user input when entering this step.
153
+ * @param skip - Whether to skip the user turn.
154
+ * @returns This step for chaining.
155
+ */
156
+ setSkipUserTurn(skip: boolean): this;
157
+ /**
158
+ * Sets whether to automatically advance to the next step after this one completes.
159
+ * @param skip - Whether to skip to the next step.
160
+ * @returns This step for chaining.
161
+ */
162
+ setSkipToNextStep(skip: boolean): this;
163
+ /**
164
+ * Initializes a gather info operation on this step for collecting structured data.
165
+ * @param opts - Optional output key, completion action, and prompt configuration.
166
+ * @returns This step for chaining.
167
+ */
168
+ setGatherInfo(opts?: {
169
+ outputKey?: string;
170
+ completionAction?: string;
171
+ prompt?: string;
172
+ }): this;
173
+ /**
174
+ * Adds a question to this step's gather info operation.
175
+ * @param opts - Question configuration including key, question text, and optional type/confirm/prompt/functions.
176
+ * @returns This step for chaining.
177
+ */
178
+ addGatherQuestion(opts: {
179
+ key: string;
180
+ question: string;
181
+ type?: string;
182
+ confirm?: boolean;
183
+ prompt?: string;
184
+ functions?: string[];
185
+ }): this;
186
+ /**
187
+ * Removes all POM sections and raw text from this step.
188
+ * @returns This step for chaining.
189
+ */
190
+ clearSections(): this;
191
+ /**
192
+ * Sets the system prompt to use when resetting context at this step.
193
+ * @param systemPrompt - The replacement system prompt text.
194
+ * @returns This step for chaining.
195
+ */
196
+ setResetSystemPrompt(systemPrompt: string): this;
197
+ /**
198
+ * Sets the user prompt to use when resetting context at this step.
199
+ * @param userPrompt - The replacement user prompt text.
200
+ * @returns This step for chaining.
201
+ */
202
+ setResetUserPrompt(userPrompt: string): this;
203
+ /**
204
+ * Sets whether to consolidate conversation history when resetting at this step.
205
+ * @param consolidate - Whether to consolidate.
206
+ * @returns This step for chaining.
207
+ */
208
+ setResetConsolidate(consolidate: boolean): this;
209
+ /**
210
+ * Sets whether to perform a full conversation reset at this step.
211
+ * @param fullReset - Whether to fully reset.
212
+ * @returns This step for chaining.
213
+ */
214
+ setResetFullReset(fullReset: boolean): this;
215
+ private renderText;
216
+ /**
217
+ * Serializes this step to a plain object for SWML output.
218
+ * @returns A dictionary representation of this step.
219
+ */
220
+ toDict(): Record<string, unknown>;
221
+ }
222
+ /** A named context containing ordered steps, prompt configuration, and navigation rules. */
223
+ export declare class Context {
224
+ /** The unique name identifying this context. */
225
+ name: string;
226
+ private steps;
227
+ private stepOrder;
228
+ private _validContexts;
229
+ private _validSteps;
230
+ private _postPrompt;
231
+ private _systemPrompt;
232
+ private systemPromptSections;
233
+ private _consolidate;
234
+ private _fullReset;
235
+ private _userPrompt;
236
+ private _isolated;
237
+ private promptText;
238
+ private promptSections;
239
+ private _enterFillers;
240
+ private _exitFillers;
241
+ /**
242
+ * Creates a new Context.
243
+ * @param name - The unique context name.
244
+ */
245
+ constructor(name: string);
246
+ /**
247
+ * Adds a new step to this context.
248
+ * @param name - The unique step name within this context.
249
+ * @param opts - Optional shorthand for task text, bullets, criteria, functions, and valid steps.
250
+ * @returns The newly created Step for further configuration.
251
+ */
252
+ addStep(name: string, opts?: {
253
+ task?: string;
254
+ bullets?: string[];
255
+ criteria?: string;
256
+ functions?: string | string[];
257
+ validSteps?: string[];
258
+ }): Step;
259
+ /**
260
+ * Returns a step by name.
261
+ * @param name - The step name to retrieve.
262
+ * @returns The matching Step, or undefined if not found.
263
+ */
264
+ getStep(name: string): Step | undefined;
265
+ /**
266
+ * Removes a step from this context by name.
267
+ * @param name - The step name to remove.
268
+ * @returns This context for chaining.
269
+ */
270
+ removeStep(name: string): this;
271
+ /**
272
+ * Moves a step to a new position in the step order.
273
+ * @param name - The step name to move.
274
+ * @param position - The zero-based index to insert at.
275
+ * @returns This context for chaining.
276
+ */
277
+ moveStep(name: string, position: number): this;
278
+ /**
279
+ * Sets which contexts the AI may navigate to from this context.
280
+ * @param contexts - List of allowed context names.
281
+ * @returns This context for chaining.
282
+ */
283
+ setValidContexts(contexts: string[]): this;
284
+ /**
285
+ * Sets which steps the AI may navigate to from this context.
286
+ * @param steps - List of allowed step names.
287
+ * @returns This context for chaining.
288
+ */
289
+ setValidSteps(steps: string[]): this;
290
+ /**
291
+ * Sets the post-prompt text for this context.
292
+ * @param postPrompt - The post-prompt string.
293
+ * @returns This context for chaining.
294
+ */
295
+ setPostPrompt(postPrompt: string): this;
296
+ /**
297
+ * Sets raw system prompt text, mutually exclusive with system POM sections.
298
+ * @param systemPrompt - The system prompt string.
299
+ * @returns This context for chaining.
300
+ */
301
+ setSystemPrompt(systemPrompt: string): this;
302
+ /**
303
+ * Sets whether to consolidate conversation history when entering this context.
304
+ * @param consolidate - Whether to consolidate.
305
+ * @returns This context for chaining.
306
+ */
307
+ setConsolidate(consolidate: boolean): this;
308
+ /**
309
+ * Sets whether to fully reset conversation history when entering this context.
310
+ * @param fullReset - Whether to fully reset.
311
+ * @returns This context for chaining.
312
+ */
313
+ setFullReset(fullReset: boolean): this;
314
+ /**
315
+ * Sets the user prompt text for this context.
316
+ * @param userPrompt - The user prompt string.
317
+ * @returns This context for chaining.
318
+ */
319
+ setUserPrompt(userPrompt: string): this;
320
+ /**
321
+ * Sets whether this context is isolated from other contexts' conversation history.
322
+ * @param isolated - Whether to isolate.
323
+ * @returns This context for chaining.
324
+ */
325
+ setIsolated(isolated: boolean): this;
326
+ /**
327
+ * Adds a POM section to the system prompt, mutually exclusive with raw system prompt text.
328
+ * @param title - The section heading.
329
+ * @param body - The section body text.
330
+ * @returns This context for chaining.
331
+ */
332
+ addSystemSection(title: string, body: string): this;
333
+ /**
334
+ * Adds a POM section with bullets to the system prompt, mutually exclusive with raw system prompt text.
335
+ * @param title - The section heading.
336
+ * @param bullets - The list of bullet point strings.
337
+ * @returns This context for chaining.
338
+ */
339
+ addSystemBullets(title: string, bullets: string[]): this;
340
+ /**
341
+ * Sets raw prompt text for this context, mutually exclusive with POM prompt sections.
342
+ * @param prompt - The prompt string.
343
+ * @returns This context for chaining.
344
+ */
345
+ setPrompt(prompt: string): this;
346
+ /**
347
+ * Adds a POM section with a body to the context prompt, mutually exclusive with raw prompt text.
348
+ * @param title - The section heading.
349
+ * @param body - The section body text.
350
+ * @returns This context for chaining.
351
+ */
352
+ addSection(title: string, body: string): this;
353
+ /**
354
+ * Adds a POM section with bullets to the context prompt, mutually exclusive with raw prompt text.
355
+ * @param title - The section heading.
356
+ * @param bullets - The list of bullet point strings.
357
+ * @returns This context for chaining.
358
+ */
359
+ addBullets(title: string, bullets: string[]): this;
360
+ /**
361
+ * Sets filler phrases spoken when entering this context, keyed by language code.
362
+ * @param fillers - Map of language codes to arrays of filler phrases.
363
+ * @returns This context for chaining.
364
+ */
365
+ setEnterFillers(fillers: Record<string, string[]>): this;
366
+ /**
367
+ * Sets filler phrases spoken when exiting this context, keyed by language code.
368
+ * @param fillers - Map of language codes to arrays of filler phrases.
369
+ * @returns This context for chaining.
370
+ */
371
+ setExitFillers(fillers: Record<string, string[]>): this;
372
+ /**
373
+ * Adds enter filler phrases for a specific language.
374
+ * @param languageCode - The language code (e.g., "en-US").
375
+ * @param fillers - Array of filler phrases.
376
+ * @returns This context for chaining.
377
+ */
378
+ addEnterFiller(languageCode: string, fillers: string[]): this;
379
+ /**
380
+ * Adds exit filler phrases for a specific language.
381
+ * @param languageCode - The language code (e.g., "en-US").
382
+ * @param fillers - Array of filler phrases.
383
+ * @returns This context for chaining.
384
+ */
385
+ addExitFiller(languageCode: string, fillers: string[]): this;
386
+ /** @internal */
387
+ getSteps(): Map<string, Step>;
388
+ /** @internal */
389
+ getValidContexts(): string[] | null;
390
+ private renderPrompt;
391
+ private renderSystemPrompt;
392
+ private renderSections;
393
+ /**
394
+ * Serializes this context and all its steps to a plain object for SWML output.
395
+ * @returns A dictionary representation of this context.
396
+ */
397
+ toDict(): Record<string, unknown>;
398
+ }
399
+ /** Builds and validates a collection of named contexts for multi-step AI workflows. */
400
+ export declare class ContextBuilder {
401
+ private contexts;
402
+ private contextOrder;
403
+ /**
404
+ * Adds a new named context to the builder.
405
+ * @param name - The unique context name.
406
+ * @returns The newly created Context for further configuration.
407
+ */
408
+ addContext(name: string): Context;
409
+ /**
410
+ * Returns a context by name.
411
+ * @param name - The context name to retrieve.
412
+ * @returns The matching Context, or undefined if not found.
413
+ */
414
+ getContext(name: string): Context | undefined;
415
+ /**
416
+ * Validates that all contexts have steps, naming constraints are met, and cross-context references are valid.
417
+ * @throws Error if validation fails.
418
+ */
419
+ validate(): void;
420
+ /**
421
+ * Validates and serializes all contexts to a plain object for SWML output.
422
+ * @returns A dictionary mapping context names to their serialized representations.
423
+ */
424
+ toDict(): Record<string, unknown>;
425
+ }
426
+ /**
427
+ * Creates a standalone Context instance without a ContextBuilder.
428
+ * @param name - The context name (defaults to "default").
429
+ * @returns A new Context instance.
430
+ */
431
+ export declare function createSimpleContext(name?: string): Context;