@ariaflowagents/core 0.7.0 → 0.8.1

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 (228) hide show
  1. package/README.md +90 -1
  2. package/dist/agents/Agent.d.ts +188 -9
  3. package/dist/agents/Agent.d.ts.map +1 -1
  4. package/dist/agents/Agent.js +246 -24
  5. package/dist/agents/Agent.js.map +1 -1
  6. package/dist/agents/CompositeAgent.d.ts +4 -3
  7. package/dist/agents/CompositeAgent.d.ts.map +1 -1
  8. package/dist/agents/CompositeAgent.js +19 -9
  9. package/dist/agents/CompositeAgent.js.map +1 -1
  10. package/dist/agents/FlowAgent.d.ts +3 -2
  11. package/dist/agents/FlowAgent.d.ts.map +1 -1
  12. package/dist/agents/FlowAgent.js +16 -6
  13. package/dist/agents/FlowAgent.js.map +1 -1
  14. package/dist/agents/TriageAgent.d.ts +8 -2
  15. package/dist/agents/TriageAgent.d.ts.map +1 -1
  16. package/dist/agents/TriageAgent.js +39 -6
  17. package/dist/agents/TriageAgent.js.map +1 -1
  18. package/dist/agents/index.d.ts +1 -1
  19. package/dist/agents/index.d.ts.map +1 -1
  20. package/dist/agents/index.js +0 -1
  21. package/dist/agents/index.js.map +1 -1
  22. package/dist/flows/FlowManager.d.ts +8 -0
  23. package/dist/flows/FlowManager.d.ts.map +1 -1
  24. package/dist/flows/FlowManager.js +38 -4
  25. package/dist/flows/FlowManager.js.map +1 -1
  26. package/dist/flows/template.d.ts +2 -2
  27. package/dist/flows/template.d.ts.map +1 -1
  28. package/dist/flows/template.js +13 -0
  29. package/dist/flows/template.js.map +1 -1
  30. package/dist/foundation/AgentDefinition.d.ts +18 -0
  31. package/dist/foundation/AgentDefinition.d.ts.map +1 -0
  32. package/dist/foundation/AgentDefinition.js +2 -0
  33. package/dist/foundation/AgentDefinition.js.map +1 -0
  34. package/dist/foundation/AgentStateController.d.ts +26 -0
  35. package/dist/foundation/AgentStateController.d.ts.map +1 -0
  36. package/dist/foundation/AgentStateController.js +2 -0
  37. package/dist/foundation/AgentStateController.js.map +1 -0
  38. package/dist/foundation/ConversationEventLog.d.ts +72 -0
  39. package/dist/foundation/ConversationEventLog.d.ts.map +1 -0
  40. package/dist/foundation/ConversationEventLog.js +2 -0
  41. package/dist/foundation/ConversationEventLog.js.map +1 -0
  42. package/dist/foundation/ConversationState.d.ts +31 -0
  43. package/dist/foundation/ConversationState.d.ts.map +1 -0
  44. package/dist/foundation/ConversationState.js +2 -0
  45. package/dist/foundation/ConversationState.js.map +1 -0
  46. package/dist/foundation/DefaultAgentStateController.d.ts +24 -0
  47. package/dist/foundation/DefaultAgentStateController.d.ts.map +1 -0
  48. package/dist/foundation/DefaultAgentStateController.js +49 -0
  49. package/dist/foundation/DefaultAgentStateController.js.map +1 -0
  50. package/dist/foundation/DefaultConversationEventLog.d.ts +28 -0
  51. package/dist/foundation/DefaultConversationEventLog.d.ts.map +1 -0
  52. package/dist/foundation/DefaultConversationEventLog.js +195 -0
  53. package/dist/foundation/DefaultConversationEventLog.js.map +1 -0
  54. package/dist/foundation/DefaultConversationState.d.ts +34 -0
  55. package/dist/foundation/DefaultConversationState.d.ts.map +1 -0
  56. package/dist/foundation/DefaultConversationState.js +100 -0
  57. package/dist/foundation/DefaultConversationState.js.map +1 -0
  58. package/dist/foundation/DefaultToolExecutor.d.ts +58 -0
  59. package/dist/foundation/DefaultToolExecutor.d.ts.map +1 -0
  60. package/dist/foundation/DefaultToolExecutor.js +128 -0
  61. package/dist/foundation/DefaultToolExecutor.js.map +1 -0
  62. package/dist/foundation/ToolExecutor.d.ts +44 -0
  63. package/dist/foundation/ToolExecutor.d.ts.map +1 -0
  64. package/dist/foundation/ToolExecutor.js +2 -0
  65. package/dist/foundation/ToolExecutor.js.map +1 -0
  66. package/dist/foundation/createFoundation.d.ts +33 -0
  67. package/dist/foundation/createFoundation.d.ts.map +1 -0
  68. package/dist/foundation/createFoundation.js +34 -0
  69. package/dist/foundation/createFoundation.js.map +1 -0
  70. package/dist/foundation/index.d.ts +15 -0
  71. package/dist/foundation/index.d.ts.map +1 -0
  72. package/dist/foundation/index.js +8 -0
  73. package/dist/foundation/index.js.map +1 -0
  74. package/dist/hooks/HookRunner.d.ts +2 -0
  75. package/dist/hooks/HookRunner.d.ts.map +1 -1
  76. package/dist/hooks/HookRunner.js +4 -0
  77. package/dist/hooks/HookRunner.js.map +1 -1
  78. package/dist/index.d.ts +13 -2
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +9 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/memory/MemoryService.d.ts +40 -0
  83. package/dist/memory/MemoryService.d.ts.map +1 -0
  84. package/dist/memory/MemoryService.js +2 -0
  85. package/dist/memory/MemoryService.js.map +1 -0
  86. package/dist/memory/index.d.ts +5 -0
  87. package/dist/memory/index.d.ts.map +1 -0
  88. package/dist/memory/index.js +3 -0
  89. package/dist/memory/index.js.map +1 -0
  90. package/dist/memory/preloadMemory.d.ts +17 -0
  91. package/dist/memory/preloadMemory.d.ts.map +1 -0
  92. package/dist/memory/preloadMemory.js +62 -0
  93. package/dist/memory/preloadMemory.js.map +1 -0
  94. package/dist/memory/stores/InMemoryMemoryService.d.ts +20 -0
  95. package/dist/memory/stores/InMemoryMemoryService.d.ts.map +1 -0
  96. package/dist/memory/stores/InMemoryMemoryService.js +92 -0
  97. package/dist/memory/stores/InMemoryMemoryService.js.map +1 -0
  98. package/dist/memory/types.d.ts +49 -0
  99. package/dist/memory/types.d.ts.map +1 -0
  100. package/dist/memory/types.js +8 -0
  101. package/dist/memory/types.js.map +1 -0
  102. package/dist/prompts/AgentPrompt.d.ts +110 -0
  103. package/dist/prompts/AgentPrompt.d.ts.map +1 -0
  104. package/dist/prompts/AgentPrompt.js +373 -0
  105. package/dist/prompts/AgentPrompt.js.map +1 -0
  106. package/dist/prompts/PromptAssembly.d.ts +119 -0
  107. package/dist/prompts/PromptAssembly.d.ts.map +1 -0
  108. package/dist/prompts/PromptAssembly.js +150 -0
  109. package/dist/prompts/PromptAssembly.js.map +1 -0
  110. package/dist/prompts/PromptBuilder.d.ts +22 -3
  111. package/dist/prompts/PromptBuilder.d.ts.map +1 -1
  112. package/dist/prompts/PromptBuilder.js +242 -13
  113. package/dist/prompts/PromptBuilder.js.map +1 -1
  114. package/dist/prompts/PromptRenderer.d.ts +43 -0
  115. package/dist/prompts/PromptRenderer.d.ts.map +1 -0
  116. package/dist/prompts/PromptRenderer.js +114 -0
  117. package/dist/prompts/PromptRenderer.js.map +1 -0
  118. package/dist/prompts/brandVoice.d.ts +10 -0
  119. package/dist/prompts/brandVoice.d.ts.map +1 -0
  120. package/dist/prompts/brandVoice.js +87 -0
  121. package/dist/prompts/brandVoice.js.map +1 -0
  122. package/dist/prompts/index.d.ts +11 -4
  123. package/dist/prompts/index.d.ts.map +1 -1
  124. package/dist/prompts/index.js +7 -2
  125. package/dist/prompts/index.js.map +1 -1
  126. package/dist/prompts/security.d.ts +5 -0
  127. package/dist/prompts/security.d.ts.map +1 -0
  128. package/dist/prompts/security.js +52 -0
  129. package/dist/prompts/security.js.map +1 -0
  130. package/dist/prompts/types.d.ts +65 -1
  131. package/dist/prompts/types.d.ts.map +1 -1
  132. package/dist/prompts/types.js +26 -0
  133. package/dist/prompts/types.js.map +1 -1
  134. package/dist/runtime/ContextBudget.d.ts +57 -0
  135. package/dist/runtime/ContextBudget.d.ts.map +1 -0
  136. package/dist/runtime/ContextBudget.js +103 -0
  137. package/dist/runtime/ContextBudget.js.map +1 -0
  138. package/dist/runtime/ContextManager.d.ts +8 -5
  139. package/dist/runtime/ContextManager.d.ts.map +1 -1
  140. package/dist/runtime/ContextManager.js +47 -14
  141. package/dist/runtime/ContextManager.js.map +1 -1
  142. package/dist/runtime/FlowExecutor.d.ts +16 -11
  143. package/dist/runtime/FlowExecutor.d.ts.map +1 -1
  144. package/dist/runtime/FlowExecutor.js +32 -138
  145. package/dist/runtime/FlowExecutor.js.map +1 -1
  146. package/dist/runtime/Runtime.d.ts +31 -78
  147. package/dist/runtime/Runtime.d.ts.map +1 -1
  148. package/dist/runtime/Runtime.js +225 -1406
  149. package/dist/runtime/Runtime.js.map +1 -1
  150. package/dist/runtime/SessionCache.d.ts +16 -0
  151. package/dist/runtime/SessionCache.d.ts.map +1 -0
  152. package/dist/runtime/SessionCache.js +49 -0
  153. package/dist/runtime/SessionCache.js.map +1 -0
  154. package/dist/runtime/SessionMutex.d.ts +37 -0
  155. package/dist/runtime/SessionMutex.d.ts.map +1 -0
  156. package/dist/runtime/SessionMutex.js +59 -0
  157. package/dist/runtime/SessionMutex.js.map +1 -0
  158. package/dist/runtime/StreamEmitter.d.ts +34 -0
  159. package/dist/runtime/StreamEmitter.d.ts.map +1 -0
  160. package/dist/runtime/StreamEmitter.js +91 -0
  161. package/dist/runtime/StreamEmitter.js.map +1 -0
  162. package/dist/runtime/handoffFilters.d.ts +60 -0
  163. package/dist/runtime/handoffFilters.d.ts.map +1 -0
  164. package/dist/runtime/handoffFilters.js +95 -0
  165. package/dist/runtime/handoffFilters.js.map +1 -0
  166. package/dist/runtime/pipeline/AgentExecuteStage.d.ts +22 -0
  167. package/dist/runtime/pipeline/AgentExecuteStage.d.ts.map +1 -0
  168. package/dist/runtime/pipeline/AgentExecuteStage.js +889 -0
  169. package/dist/runtime/pipeline/AgentExecuteStage.js.map +1 -0
  170. package/dist/runtime/pipeline/ContextAssembleStage.d.ts +26 -0
  171. package/dist/runtime/pipeline/ContextAssembleStage.d.ts.map +1 -0
  172. package/dist/runtime/pipeline/ContextAssembleStage.js +253 -0
  173. package/dist/runtime/pipeline/ContextAssembleStage.js.map +1 -0
  174. package/dist/runtime/pipeline/ContextGatherStage.d.ts +21 -0
  175. package/dist/runtime/pipeline/ContextGatherStage.d.ts.map +1 -0
  176. package/dist/runtime/pipeline/ContextGatherStage.js +161 -0
  177. package/dist/runtime/pipeline/ContextGatherStage.js.map +1 -0
  178. package/dist/runtime/pipeline/IntakeStage.d.ts +25 -0
  179. package/dist/runtime/pipeline/IntakeStage.d.ts.map +1 -0
  180. package/dist/runtime/pipeline/IntakeStage.js +126 -0
  181. package/dist/runtime/pipeline/IntakeStage.js.map +1 -0
  182. package/dist/runtime/pipeline/PostStreamStage.d.ts +26 -0
  183. package/dist/runtime/pipeline/PostStreamStage.d.ts.map +1 -0
  184. package/dist/runtime/pipeline/PostStreamStage.js +129 -0
  185. package/dist/runtime/pipeline/PostStreamStage.js.map +1 -0
  186. package/dist/runtime/pipeline/TurnPipeline.d.ts +54 -0
  187. package/dist/runtime/pipeline/TurnPipeline.d.ts.map +1 -0
  188. package/dist/runtime/pipeline/TurnPipeline.js +15 -0
  189. package/dist/runtime/pipeline/TurnPipeline.js.map +1 -0
  190. package/dist/runtime/pipeline/TurnServices.d.ts +48 -0
  191. package/dist/runtime/pipeline/TurnServices.d.ts.map +1 -0
  192. package/dist/runtime/pipeline/TurnServices.js +2 -0
  193. package/dist/runtime/pipeline/TurnServices.js.map +1 -0
  194. package/dist/runtime/pipeline/agentTypeGuards.d.ts +4 -0
  195. package/dist/runtime/pipeline/agentTypeGuards.d.ts.map +1 -0
  196. package/dist/runtime/pipeline/agentTypeGuards.js +7 -0
  197. package/dist/runtime/pipeline/agentTypeGuards.js.map +1 -0
  198. package/dist/runtime/pipeline/index.d.ts +11 -0
  199. package/dist/runtime/pipeline/index.d.ts.map +1 -0
  200. package/dist/runtime/pipeline/index.js +13 -0
  201. package/dist/runtime/pipeline/index.js.map +1 -0
  202. package/dist/runtime/pipeline/outputProcessing.d.ts +23 -0
  203. package/dist/runtime/pipeline/outputProcessing.d.ts.map +1 -0
  204. package/dist/runtime/pipeline/outputProcessing.js +63 -0
  205. package/dist/runtime/pipeline/outputProcessing.js.map +1 -0
  206. package/dist/runtime/pipeline/sessionUtils.d.ts +12 -0
  207. package/dist/runtime/pipeline/sessionUtils.d.ts.map +1 -0
  208. package/dist/runtime/pipeline/sessionUtils.js +73 -0
  209. package/dist/runtime/pipeline/sessionUtils.js.map +1 -0
  210. package/dist/tools/Tool.d.ts +7 -0
  211. package/dist/tools/Tool.d.ts.map +1 -1
  212. package/dist/tools/Tool.js +12 -3
  213. package/dist/tools/Tool.js.map +1 -1
  214. package/dist/tools/memory.d.ts +26 -0
  215. package/dist/tools/memory.d.ts.map +1 -0
  216. package/dist/tools/memory.js +51 -0
  217. package/dist/tools/memory.js.map +1 -0
  218. package/dist/types/index.d.ts +177 -6
  219. package/dist/types/index.d.ts.map +1 -1
  220. package/dist/types/index.js.map +1 -1
  221. package/guides/AGENTS.md +173 -0
  222. package/guides/README.md +12 -0
  223. package/guides/TOOLS.md +93 -27
  224. package/package.json +12 -4
  225. package/dist/agents/LLMAgent.d.ts +0 -11
  226. package/dist/agents/LLMAgent.d.ts.map +0 -1
  227. package/dist/agents/LLMAgent.js +0 -31
  228. package/dist/agents/LLMAgent.js.map +0 -1
@@ -0,0 +1,373 @@
1
+ /**
2
+ * AgentPrompt — Developer-facing class for structured prompt assembly.
3
+ *
4
+ * Provides a chainable API for composing agent prompts with automatic
5
+ * security sandwiching, priority-based ordering, and XML-tagged rendering.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const prompt = new AgentPrompt()
10
+ * .role('You are a helpful customer support agent.')
11
+ * .instructions('Help customers with billing and account issues.')
12
+ * .guardrails('Never share internal pricing or discount formulas.')
13
+ * .knowledge(async () => fetchKnowledgeBase())
14
+ * .tools(myToolSet);
15
+ *
16
+ * const systemPrompt = await prompt.render();
17
+ * ```
18
+ *
19
+ * @module
20
+ */
21
+ import { getSecurityCore, SECURITY_REMINDER } from './security.js';
22
+ import { PromptAssembly } from './PromptAssembly.js';
23
+ import { renderSections } from './PromptRenderer.js';
24
+ // ============================================
25
+ // AgentPrompt
26
+ // ============================================
27
+ /**
28
+ * Developer-facing prompt builder with a chainable API.
29
+ *
30
+ * Internally creates a {@link PromptAssembly}, injects security core (priority 0)
31
+ * and security reminder (priority 1000), then freezes security bands.
32
+ *
33
+ * All chainable methods accept either a static string or an async function
34
+ * that resolves to a string.
35
+ */
36
+ export class AgentPrompt {
37
+ _assembly;
38
+ renderOptions;
39
+ constructor(config = {}) {
40
+ const { policy = 'minimal', xmlTags = true, maxTokens, disableSecurity = false, } = config;
41
+ this._assembly = new PromptAssembly();
42
+ this.renderOptions = {
43
+ useXmlTags: xmlTags,
44
+ maxTokens,
45
+ validateSecurity: !disableSecurity,
46
+ };
47
+ if (!disableSecurity) {
48
+ this._assembly.addSection({
49
+ type: 'security_core',
50
+ content: getSecurityCore(policy),
51
+ priority: 0,
52
+ shrinkable: false,
53
+ tag: 'security_core',
54
+ source: 'security',
55
+ });
56
+ this._assembly.addSection({
57
+ type: 'security_reminder',
58
+ content: SECURITY_REMINDER,
59
+ priority: 1000,
60
+ shrinkable: false,
61
+ tag: 'security_reminder',
62
+ source: 'security',
63
+ });
64
+ this._assembly.freeze();
65
+ }
66
+ }
67
+ // ============================================
68
+ // Chainable section methods
69
+ // ============================================
70
+ /**
71
+ * Sets the agent's role description. Priority 10, non-shrinkable.
72
+ */
73
+ role(content) {
74
+ this._assembly.addSection({
75
+ type: 'role',
76
+ content,
77
+ priority: 10,
78
+ shrinkable: false,
79
+ tag: 'role',
80
+ source: 'developer',
81
+ });
82
+ return this;
83
+ }
84
+ /**
85
+ * Sets the agent's instructions. Priority 15, non-shrinkable.
86
+ */
87
+ instructions(content) {
88
+ this._assembly.addSection({
89
+ type: 'instructions',
90
+ content,
91
+ priority: 15,
92
+ shrinkable: false,
93
+ tag: 'instructions',
94
+ source: 'developer',
95
+ });
96
+ return this;
97
+ }
98
+ /**
99
+ * Sets guardrail rules. Priority 20, non-shrinkable.
100
+ */
101
+ guardrails(content) {
102
+ this._assembly.addSection({
103
+ type: 'guardrails',
104
+ content,
105
+ priority: 20,
106
+ shrinkable: false,
107
+ tag: 'guardrails',
108
+ source: 'developer',
109
+ });
110
+ return this;
111
+ }
112
+ /**
113
+ * Sets voice/personality description. Priority 25, shrinkable.
114
+ */
115
+ voice(content) {
116
+ this._assembly.addSection({
117
+ type: 'voice',
118
+ content,
119
+ priority: 25,
120
+ shrinkable: true,
121
+ tag: 'voice',
122
+ source: 'developer',
123
+ });
124
+ return this;
125
+ }
126
+ /**
127
+ * Injects knowledge context. Priority 30, shrinkable.
128
+ */
129
+ knowledge(content) {
130
+ this._assembly.addSection({
131
+ type: 'knowledge',
132
+ content,
133
+ priority: 30,
134
+ shrinkable: true,
135
+ tag: 'knowledge',
136
+ source: 'developer',
137
+ });
138
+ return this;
139
+ }
140
+ /**
141
+ * Sets business/domain rules. Priority 35, shrinkable.
142
+ */
143
+ rules(content) {
144
+ this._assembly.addSection({
145
+ type: 'rules',
146
+ content,
147
+ priority: 35,
148
+ shrinkable: true,
149
+ tag: 'rules',
150
+ source: 'developer',
151
+ });
152
+ return this;
153
+ }
154
+ /**
155
+ * Adds a glossary of domain terms. Priority 38, shrinkable.
156
+ * Terms are auto-formatted into a structured list.
157
+ */
158
+ glossary(terms) {
159
+ const content = formatGlossary(terms);
160
+ this._assembly.addSection({
161
+ type: 'glossary',
162
+ content,
163
+ priority: 38,
164
+ shrinkable: true,
165
+ tag: 'glossary',
166
+ source: 'developer',
167
+ });
168
+ return this;
169
+ }
170
+ /**
171
+ * Generates tool descriptions from a ToolSet. Priority 40, shrinkable.
172
+ */
173
+ tools(toolSet) {
174
+ const content = formatToolDescriptions(toolSet);
175
+ this._assembly.addSection({
176
+ type: 'tools',
177
+ content,
178
+ priority: 40,
179
+ shrinkable: true,
180
+ tag: 'tools',
181
+ source: 'developer',
182
+ });
183
+ return this;
184
+ }
185
+ /**
186
+ * Sets voice/TTS output rules. Priority 45, shrinkable.
187
+ * Uses the same formatting logic as PromptTemplateBuilder.formatVoiceRules.
188
+ */
189
+ voiceRules(config) {
190
+ const content = formatVoiceRules(config);
191
+ this._assembly.addSection({
192
+ type: 'voice_rules',
193
+ content,
194
+ priority: 45,
195
+ shrinkable: true,
196
+ tag: 'voice_rules',
197
+ source: 'developer',
198
+ });
199
+ return this;
200
+ }
201
+ /**
202
+ * Adds example interactions or few-shot prompts. Priority 50, shrinkable.
203
+ */
204
+ examples(content) {
205
+ this._assembly.addSection({
206
+ type: 'examples',
207
+ content,
208
+ priority: 50,
209
+ shrinkable: true,
210
+ tag: 'examples',
211
+ source: 'developer',
212
+ });
213
+ return this;
214
+ }
215
+ /**
216
+ * Adds an arbitrary named section. Defaults to priority 60, shrinkable.
217
+ */
218
+ section(type, content, priority = 60) {
219
+ this._assembly.addSection({
220
+ type,
221
+ content,
222
+ priority,
223
+ shrinkable: true,
224
+ tag: type,
225
+ source: 'developer',
226
+ });
227
+ return this;
228
+ }
229
+ // ============================================
230
+ // Render & Debug
231
+ // ============================================
232
+ /**
233
+ * Resolves all sections and renders the prompt to a string.
234
+ */
235
+ async render() {
236
+ const resolved = await this._assembly.resolve();
237
+ return renderSections(resolved, this.renderOptions);
238
+ }
239
+ /**
240
+ * Returns debug information about the assembly's current state.
241
+ */
242
+ async debug() {
243
+ return this._assembly.debug();
244
+ }
245
+ /**
246
+ * Exposes the underlying PromptAssembly for runtime injection.
247
+ */
248
+ get assembly() {
249
+ return this._assembly;
250
+ }
251
+ }
252
+ // ============================================
253
+ // Formatters (internal)
254
+ // ============================================
255
+ /** Formats glossary terms into a readable list. */
256
+ function formatGlossary(terms) {
257
+ if (terms.length === 0)
258
+ return '';
259
+ const lines = ['## Domain Glossary', ''];
260
+ lines.push('The following terms have specific meanings in this context:');
261
+ lines.push('');
262
+ for (const term of terms) {
263
+ lines.push(`### ${term.name}`);
264
+ lines.push(`**Description:** ${term.description}`);
265
+ if (term.synonyms && term.synonyms.length > 0) {
266
+ lines.push(`**Synonyms:** ${term.synonyms.join(', ')}`);
267
+ }
268
+ lines.push('');
269
+ }
270
+ return lines.join('\n');
271
+ }
272
+ /** Formats a ToolSet into readable tool descriptions. */
273
+ function formatToolDescriptions(toolSet) {
274
+ const entries = Object.entries(toolSet);
275
+ if (entries.length === 0)
276
+ return '';
277
+ const descriptions = entries.map(([name, tool]) => {
278
+ const desc = 'description' in tool ? String(tool.description) : '';
279
+ return `### ${name}\n${desc}`;
280
+ });
281
+ return `## Available Tools\n\n${descriptions.join('\n\n')}`;
282
+ }
283
+ /**
284
+ * Formats voice rules configuration into a structured text block.
285
+ * Logic ported from PromptTemplateBuilder.formatVoiceRules.
286
+ */
287
+ function formatVoiceRules(cfg) {
288
+ const rules = [];
289
+ rules.push('Your responses will be converted to speech. Follow these rules for natural TTS output:');
290
+ rules.push('## Formatting');
291
+ rules.push('1. **Punctuation**: Use proper punctuation at the end of every sentence.');
292
+ rules.push('2. **No special characters**: Avoid emojis, markdown formatting, or special unicode characters.');
293
+ rules.push('3. **No quotation marks**: Avoid unless explicitly quoting someone.\n');
294
+ rules.push('## Numbers & Dates');
295
+ if (cfg.formatDates === 'MM/DD/YYYY') {
296
+ rules.push('- **Dates**: Write as MM/DD/YYYY (e.g., "04/20/2023" not "April 20th").');
297
+ }
298
+ else if (cfg.formatDates === 'speakable') {
299
+ rules.push('- **Dates**: Speak in natural form (e.g., "April twentieth, twenty twenty-three").');
300
+ }
301
+ if (cfg.formatTimes === '12h') {
302
+ rules.push('- **Times**: Use 12-hour format with space before AM/PM (e.g., "7:00 PM" not "7:00PM").');
303
+ }
304
+ if (cfg.useSpellTags) {
305
+ rules.push('\n## Identifiers (Spelling)');
306
+ rules.push('- Wrap identifiers in <spell> tags:');
307
+ rules.push(' - Order numbers: "<spell>A1B2C3</spell>"');
308
+ rules.push(' - Phone numbers: "<spell>555-123-4567</spell>"');
309
+ rules.push(' - Confirmation codes: "<spell>XYZ789</spell>"');
310
+ rules.push(' - Email addresses: "<spell>user@example.com</spell>"');
311
+ }
312
+ else {
313
+ rules.push('\n## Identifiers');
314
+ rules.push('- Spell out identifiers digit by digit: "A one B two C three"');
315
+ rules.push('- Phone numbers: "five five five, one two three, four five six seven"');
316
+ rules.push('- Email addresses: "user at example dot com"');
317
+ }
318
+ if (cfg.urlFormat === 'dot') {
319
+ rules.push('\n## URLs & Emails');
320
+ rules.push('- Say "dot" instead of ".": "example dot com"');
321
+ rules.push('- Say "at" instead of "@": "user at example dot com"');
322
+ }
323
+ rules.push('\n## Pauses & Breaks');
324
+ if (cfg.useBreakTags) {
325
+ rules.push('- Use <break time="Xs"/> for pauses: "Let me check.<break time="1s"/>Okay..."');
326
+ rules.push('- Shorter breaks (200-500ms) between list items.');
327
+ }
328
+ else {
329
+ rules.push('- Use natural pauses with punctuation and dashes.');
330
+ rules.push('- Use "\u2014" (em dash) for longer pauses in speech.');
331
+ }
332
+ if (cfg.useSpeedTags) {
333
+ rules.push('\n## Speaking Pace');
334
+ rules.push('- Use <speed ratio="0.8"/> for slow, clear explanations.');
335
+ rules.push('- Use <speed ratio="1.2"/> for quick summaries.');
336
+ rules.push('- Normal speed is ratio 1.0.');
337
+ }
338
+ if (cfg.useEmotionTags) {
339
+ rules.push('\n## Emotional Expression');
340
+ rules.push('- Use <emotion value="..."/> for tone: neutral, excited, sympathetic, curious, etc.');
341
+ rules.push('- Emotions: happy, excited, content, sad, scared, curious, sympathetic, calm.');
342
+ rules.push('- Match emotion to content - do not use conflicting tones.');
343
+ }
344
+ if (cfg.useLaughterTags) {
345
+ rules.push('\n## Nonverbal Sounds');
346
+ rules.push('- Use [laughter] to indicate laughing: "That is funny! [laughter]"');
347
+ rules.push('- Use sparingly for natural effect.');
348
+ }
349
+ if (cfg.verbalizeCurrency) {
350
+ rules.push('\n## Currency');
351
+ rules.push('- Say "five dollars" not "$5"');
352
+ rules.push('- Say "five ninety-nine" not "$5.99"');
353
+ }
354
+ if (cfg.verbalizeSymbols) {
355
+ rules.push('\n## Symbols');
356
+ rules.push('- Say "percent" not "%"');
357
+ rules.push('- Say "dollar" not "$"');
358
+ rules.push('- Say "equals" not "="');
359
+ }
360
+ if (cfg.customPronunciations) {
361
+ rules.push('\n## Custom Pronunciations');
362
+ for (const [word, pronunciation] of Object.entries(cfg.customPronunciations)) {
363
+ rules.push(`- "${word}" should be pronounced: "${pronunciation}"`);
364
+ }
365
+ }
366
+ rules.push('\n## Speaking Style');
367
+ rules.push('- Be concise and conversational.');
368
+ rules.push("- Use contractions (I'm, you're, we'll).");
369
+ rules.push('- Avoid abbreviations: say "versus" not "vs.", "for example" not "e.g."');
370
+ rules.push('- For lists, use natural connectors: "first, second, third" not bullet points.');
371
+ return rules.filter((r) => r.trim()).join('\n');
372
+ }
373
+ //# sourceMappingURL=AgentPrompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentPrompt.js","sourceRoot":"","sources":["../../src/prompts/AgentPrompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAqBrD,+CAA+C;AAC/C,cAAc;AACd,+CAA+C;AAE/C;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAW;IACL,SAAS,CAAiB;IAC1B,aAAa,CAAgB;IAE9C,YAAY,SAA4B,EAAE;QACxC,MAAM,EACJ,MAAM,GAAG,SAAS,EAClB,OAAO,GAAG,IAAI,EACd,SAAS,EACT,eAAe,GAAG,KAAK,GACxB,GAAG,MAAM,CAAC;QAEX,IAAI,CAAC,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG;YACnB,UAAU,EAAE,OAAO;YACnB,SAAS;YACT,gBAAgB,EAAE,CAAC,eAAe;SACnC,CAAC;QAEF,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;gBACxB,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC;gBAChC,QAAQ,EAAE,CAAC;gBACX,UAAU,EAAE,KAAK;gBACjB,GAAG,EAAE,eAAe;gBACpB,MAAM,EAAE,UAAU;aACnB,CAAC,CAAC;YAE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C,qBAAqB,CAAC,CAAC;IAClC,KAAK,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IAC/C,KAAK,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;IACvD,KAAK,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;IACtF,KAAK,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;IAE7F,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * PromptAssembly — Structured intermediate representation for prompt sections.
3
+ *
4
+ * Sections are stored in a Map keyed by type (except 'custom' which uses an array).
5
+ * Security-band sections (priority 0-9 or 1000+) are frozen after `freeze()` is called.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Configuration for a single prompt section.
11
+ * Content can be a static string or an async function for deferred resolution.
12
+ */
13
+ export interface PromptSectionConfig {
14
+ /** Section type identifier. */
15
+ type: string;
16
+ /** Static content string or async function that resolves to content. */
17
+ content: string | (() => Promise<string>);
18
+ /** Sort priority. Lower numbers appear first. */
19
+ priority: number;
20
+ /** Whether this section can be trimmed under token pressure. Defaults to true. */
21
+ shrinkable?: boolean;
22
+ /** XML tag name used when rendering. Defaults to the type value. */
23
+ tag?: string;
24
+ /** Origin of this section for debugging/auditing. */
25
+ source?: 'developer' | 'runtime' | 'flow' | 'security';
26
+ }
27
+ /**
28
+ * A fully resolved section with content materialized and metadata computed.
29
+ */
30
+ export interface ResolvedSection {
31
+ /** Section type identifier. */
32
+ type: string;
33
+ /** Resolved content string. */
34
+ content: string;
35
+ /** Sort priority. */
36
+ priority: number;
37
+ /** Whether this section can be trimmed under token pressure. */
38
+ shrinkable: boolean;
39
+ /** XML tag name. */
40
+ tag: string;
41
+ /** Origin of this section. */
42
+ source: string;
43
+ /** Whether this section is in a frozen security band. */
44
+ frozen: boolean;
45
+ /** Estimated token count of the content. */
46
+ estimatedTokens: number;
47
+ }
48
+ /**
49
+ * Debug information about the assembly's current state.
50
+ */
51
+ export interface AssemblyDebugInfo {
52
+ /** Per-section metadata. */
53
+ sections: Array<{
54
+ type: string;
55
+ priority: number;
56
+ tokens: number;
57
+ source: string;
58
+ shrinkable: boolean;
59
+ frozen: boolean;
60
+ }>;
61
+ /** Total estimated tokens across all sections. */
62
+ totalTokens: number;
63
+ }
64
+ /**
65
+ * Thrown when an attempt is made to modify a frozen security-band section.
66
+ */
67
+ export declare class PromptSecurityViolationError extends Error {
68
+ constructor(message: string);
69
+ }
70
+ /**
71
+ * PromptAssembly is the structured intermediate representation for prompt construction.
72
+ *
73
+ * Sections are stored in a Map keyed by type. The special type `'custom'` is stored
74
+ * in a separate array to allow multiple custom sections.
75
+ *
76
+ * After `freeze()` is called, sections in security bands (priority 0-9 or 1000+)
77
+ * cannot be added, replaced, or removed.
78
+ */
79
+ export declare class PromptAssembly {
80
+ private readonly sections;
81
+ private readonly customSections;
82
+ private frozen;
83
+ /**
84
+ * Adds or replaces a section. Custom-type sections are always appended.
85
+ *
86
+ * @throws {PromptSecurityViolationError} If the assembly is frozen and the
87
+ * section's priority falls within a security band (0-9 or 1000+).
88
+ */
89
+ addSection(config: PromptSectionConfig): this;
90
+ /**
91
+ * Sugar for `addSection` with `source: 'runtime'`.
92
+ */
93
+ inject(type: string, content: string | (() => Promise<string>), options?: Partial<Omit<PromptSectionConfig, 'type' | 'content' | 'source'>>): this;
94
+ /**
95
+ * Freezes the assembly, preventing modification of security-band sections.
96
+ */
97
+ freeze(): this;
98
+ /**
99
+ * Resolves all sections — materializing async content functions — and
100
+ * returns them sorted by priority (ascending). Empty sections are filtered out.
101
+ */
102
+ resolve(): Promise<ResolvedSection[]>;
103
+ /**
104
+ * Returns the raw section config for a given type, or `undefined` if not present.
105
+ */
106
+ sectionByType(type: string): PromptSectionConfig | undefined;
107
+ /**
108
+ * Returns true if a section of the given type exists.
109
+ */
110
+ hasSection(type: string): boolean;
111
+ /**
112
+ * Returns debug information about the assembly's current state.
113
+ * Resolves async content to compute accurate token estimates.
114
+ */
115
+ debug(): Promise<AssemblyDebugInfo>;
116
+ /** Number of sections (including custom sections). */
117
+ get size(): number;
118
+ }
119
+ //# sourceMappingURL=PromptAssembly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromptAssembly.d.ts","sourceRoot":"","sources":["../../src/prompts/PromptAssembly.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;CACxD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,UAAU,EAAE,OAAO,CAAC;IACpB,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,MAAM,EAAE,OAAO,CAAC;IAChB,4CAA4C;IAC5C,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,QAAQ,EAAE,KAAK,C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sections are stored in a Map keyed by type (except 'custom' which uses an array).
5
+ * Security-band sections (priority 0-9 or 1000+) are frozen after `freeze()` is called.
6
+ *
7
+ * @module
8
+ */
9
+ import { estimateTokenCount } from '../runtime/ContextBudget.js';
10
+ // ============================================
11
+ // Error
12
+ // ============================================
13
+ /**
14
+ * Thrown when an attempt is made to modify a frozen security-band section.
15
+ */
16
+ export class PromptSecurityViolationError extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'PromptSecurityViolationError';
20
+ }
21
+ }
22
+ // ============================================
23
+ // Helpers
24
+ // ============================================
25
+ /** Returns true if the priority falls within a frozen security band. */
26
+ function isSecurityBand(priority) {
27
+ return priority <= 9 || priority >= 1000;
28
+ }
29
+ // ============================================
30
+ // PromptAssembly
31
+ // ============================================
32
+ /**
33
+ * PromptAssembly is the structured intermediate representation for prompt construction.
34
+ *
35
+ * Sections are stored in a Map keyed by type. The special type `'custom'` is stored
36
+ * in a separate array to allow multiple custom sections.
37
+ *
38
+ * After `freeze()` is called, sections in security bands (priority 0-9 or 1000+)
39
+ * cannot be added, replaced, or removed.
40
+ */
41
+ export class PromptAssembly {
42
+ sections = new Map();
43
+ customSections = [];
44
+ frozen = false;
45
+ /**
46
+ * Adds or replaces a section. Custom-type sections are always appended.
47
+ *
48
+ * @throws {PromptSecurityViolationError} If the assembly is frozen and the
49
+ * section's priority falls within a security band (0-9 or 1000+).
50
+ */
51
+ addSection(config) {
52
+ if (this.frozen && isSecurityBand(config.priority)) {
53
+ throw new PromptSecurityViolationError(`Cannot modify section "${config.type}" at priority ${config.priority}: ` +
54
+ 'security-band sections are frozen.');
55
+ }
56
+ if (config.type === 'custom') {
57
+ this.customSections.push(config);
58
+ }
59
+ else {
60
+ this.sections.set(config.type, config);
61
+ }
62
+ return this;
63
+ }
64
+ /**
65
+ * Sugar for `addSection` with `source: 'runtime'`.
66
+ */
67
+ inject(type, content, options) {
68
+ return this.addSection({
69
+ type,
70
+ content,
71
+ priority: options?.priority ?? 60,
72
+ shrinkable: options?.shrinkable,
73
+ tag: options?.tag,
74
+ source: 'runtime',
75
+ });
76
+ }
77
+ /**
78
+ * Freezes the assembly, preventing modification of security-band sections.
79
+ */
80
+ freeze() {
81
+ this.frozen = true;
82
+ return this;
83
+ }
84
+ /**
85
+ * Resolves all sections — materializing async content functions — and
86
+ * returns them sorted by priority (ascending). Empty sections are filtered out.
87
+ */
88
+ async resolve() {
89
+ const allConfigs = [
90
+ ...this.sections.values(),
91
+ ...this.customSections,
92
+ ];
93
+ const resolved = [];
94
+ for (const config of allConfigs) {
95
+ const content = typeof config.content === 'function'
96
+ ? await config.content()
97
+ : config.content;
98
+ if (!content || content.trim().length === 0)
99
+ continue;
100
+ resolved.push({
101
+ type: config.type,
102
+ content,
103
+ priority: config.priority,
104
+ shrinkable: config.shrinkable ?? true,
105
+ tag: config.tag ?? config.type,
106
+ source: config.source ?? 'developer',
107
+ frozen: this.frozen && isSecurityBand(config.priority),
108
+ estimatedTokens: estimateTokenCount(content),
109
+ });
110
+ }
111
+ resolved.sort((a, b) => a.priority - b.priority);
112
+ return resolved;
113
+ }
114
+ /**
115
+ * Returns the raw section config for a given type, or `undefined` if not present.
116
+ */
117
+ sectionByType(type) {
118
+ return this.sections.get(type);
119
+ }
120
+ /**
121
+ * Returns true if a section of the given type exists.
122
+ */
123
+ hasSection(type) {
124
+ if (type === 'custom')
125
+ return this.customSections.length > 0;
126
+ return this.sections.has(type);
127
+ }
128
+ /**
129
+ * Returns debug information about the assembly's current state.
130
+ * Resolves async content to compute accurate token estimates.
131
+ */
132
+ async debug() {
133
+ const resolved = await this.resolve();
134
+ const sectionInfos = resolved.map((s) => ({
135
+ type: s.type,
136
+ priority: s.priority,
137
+ tokens: s.estimatedTokens,
138
+ source: s.source,
139
+ shrinkable: s.shrinkable,
140
+ frozen: s.frozen,
141
+ }));
142
+ const totalTokens = sectionInfos.reduce((sum, s) => sum + s.tokens, 0);
143
+ return { sections: sectionInfos, totalTokens };
144
+ }
145
+ /** Number of sections (including custom sections). */
146
+ get size() {
147
+ return this.sections.size + this.customSections.length;
148
+ }
149
+ }
150
+ //# sourceMappingURL=PromptAssembly.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromptAssembly.js","sourceRoot":"","sources":["../../src/prompts/PromptAssembly.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAgEjE,+CAA+C;AAC/C,QAAQ;AACR,+CAA+C;AAE/C;;GAEG;AACH,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IACrD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AAED,+CAA+C;AAC/C,UAAU;AACV,+CAA+C;AAE/C,wEAAwE;AACxE,SAAS,cAAc,CAAC,QAAgB;IACtC,OAAO,QAAQ,IAAI,CAAC,IAAI,QAAQ,IAAI,IAAI,CAAC;AAC3C,CAAC;AAED,+CAA+C;AAC/C,iBAAiB;AACjB,+CAA+C;AAE/C;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAc;IACR,QAAQ,GAAqC,IAAI,GAAG,EAAE,CAAC;IACvD,cAAc,GAA0B,EAAE,CAAC;IACpD,MAAM,GAAG,KAAK,CAAC;IAEvB;;;;;OAKG;IACH,UAAU,CAAC,MAA2B;QACpC,IAAI,IAAI,CAAC,MAAM,IAAI,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,4BAA4B,CACpC,0BAA0B,MAAM,CAAC,IAAI,iBAAiB,MAAM,CAAC,QAAQ,IAAI;gBACvE,oCAAoC,CACvC,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;aAAM,C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