@falai/agent 0.4.1 → 0.5.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 (285) hide show
  1. package/README.md +21 -74
  2. package/dist/cjs/core/Agent.d.ts +22 -29
  3. package/dist/cjs/core/Agent.d.ts.map +1 -1
  4. package/dist/cjs/core/Agent.js +464 -291
  5. package/dist/cjs/core/Agent.js.map +1 -1
  6. package/dist/cjs/core/Events.d.ts +10 -1
  7. package/dist/cjs/core/Events.d.ts.map +1 -1
  8. package/dist/cjs/core/Events.js +3 -2
  9. package/dist/cjs/core/Events.js.map +1 -1
  10. package/dist/cjs/core/PersistenceManager.d.ts +19 -0
  11. package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
  12. package/dist/cjs/core/PersistenceManager.js +55 -0
  13. package/dist/cjs/core/PersistenceManager.js.map +1 -1
  14. package/dist/cjs/core/PromptComposer.d.ts +24 -0
  15. package/dist/cjs/core/PromptComposer.d.ts.map +1 -0
  16. package/dist/cjs/core/PromptComposer.js +127 -0
  17. package/dist/cjs/core/PromptComposer.js.map +1 -0
  18. package/dist/cjs/core/ResponseEngine.d.ts +19 -0
  19. package/dist/cjs/core/ResponseEngine.d.ts.map +1 -0
  20. package/dist/cjs/core/ResponseEngine.js +51 -0
  21. package/dist/cjs/core/ResponseEngine.js.map +1 -0
  22. package/dist/cjs/core/Route.d.ts +18 -12
  23. package/dist/cjs/core/Route.d.ts.map +1 -1
  24. package/dist/cjs/core/Route.js +15 -9
  25. package/dist/cjs/core/Route.js.map +1 -1
  26. package/dist/cjs/core/RoutingEngine.d.ts +38 -0
  27. package/dist/cjs/core/RoutingEngine.d.ts.map +1 -0
  28. package/dist/cjs/core/RoutingEngine.js +110 -0
  29. package/dist/cjs/core/RoutingEngine.js.map +1 -0
  30. package/dist/cjs/core/State.d.ts +15 -4
  31. package/dist/cjs/core/State.d.ts.map +1 -1
  32. package/dist/cjs/core/State.js +21 -2
  33. package/dist/cjs/core/State.js.map +1 -1
  34. package/dist/cjs/core/ToolExecutor.d.ts +29 -0
  35. package/dist/cjs/core/ToolExecutor.d.ts.map +1 -0
  36. package/dist/cjs/core/ToolExecutor.js +73 -0
  37. package/dist/cjs/core/ToolExecutor.js.map +1 -0
  38. package/dist/cjs/core/Transition.d.ts +5 -5
  39. package/dist/cjs/core/Transition.d.ts.map +1 -1
  40. package/dist/cjs/core/Transition.js.map +1 -1
  41. package/dist/cjs/index.d.ts +6 -8
  42. package/dist/cjs/index.d.ts.map +1 -1
  43. package/dist/cjs/index.js +8 -10
  44. package/dist/cjs/index.js.map +1 -1
  45. package/dist/cjs/providers/AnthropicProvider.d.ts.map +1 -1
  46. package/dist/cjs/providers/AnthropicProvider.js +10 -13
  47. package/dist/cjs/providers/AnthropicProvider.js.map +1 -1
  48. package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
  49. package/dist/cjs/providers/GeminiProvider.js +12 -8
  50. package/dist/cjs/providers/GeminiProvider.js.map +1 -1
  51. package/dist/cjs/providers/OpenAIProvider.d.ts.map +1 -1
  52. package/dist/cjs/providers/OpenAIProvider.js +10 -53
  53. package/dist/cjs/providers/OpenAIProvider.js.map +1 -1
  54. package/dist/cjs/providers/OpenRouterProvider.d.ts.map +1 -1
  55. package/dist/cjs/providers/OpenRouterProvider.js +10 -53
  56. package/dist/cjs/providers/OpenRouterProvider.js.map +1 -1
  57. package/dist/cjs/types/agent.d.ts +13 -12
  58. package/dist/cjs/types/agent.d.ts.map +1 -1
  59. package/dist/cjs/types/ai.d.ts +8 -2
  60. package/dist/cjs/types/ai.d.ts.map +1 -1
  61. package/dist/cjs/types/history.d.ts +8 -0
  62. package/dist/cjs/types/history.d.ts.map +1 -1
  63. package/dist/cjs/types/index.d.ts +0 -3
  64. package/dist/cjs/types/index.d.ts.map +1 -1
  65. package/dist/cjs/types/index.js +1 -3
  66. package/dist/cjs/types/index.js.map +1 -1
  67. package/dist/cjs/types/route.d.ts +39 -4
  68. package/dist/cjs/types/route.d.ts.map +1 -1
  69. package/dist/cjs/types/routing.d.ts +16 -0
  70. package/dist/cjs/types/routing.d.ts.map +1 -0
  71. package/dist/cjs/types/routing.js +3 -0
  72. package/dist/cjs/types/routing.js.map +1 -0
  73. package/dist/cjs/types/schema.d.ts +22 -0
  74. package/dist/cjs/types/schema.d.ts.map +1 -0
  75. package/dist/cjs/types/schema.js +3 -0
  76. package/dist/cjs/types/schema.js.map +1 -0
  77. package/dist/cjs/types/session.d.ts +77 -0
  78. package/dist/cjs/types/session.d.ts.map +1 -0
  79. package/dist/cjs/types/session.js +146 -0
  80. package/dist/cjs/types/session.js.map +1 -0
  81. package/dist/cjs/types/tool.d.ts +11 -5
  82. package/dist/cjs/types/tool.d.ts.map +1 -1
  83. package/dist/cjs/utils/id.d.ts +0 -5
  84. package/dist/cjs/utils/id.d.ts.map +1 -1
  85. package/dist/cjs/utils/id.js +0 -10
  86. package/dist/cjs/utils/id.js.map +1 -1
  87. package/dist/cjs/utils/schema.d.ts +17 -0
  88. package/dist/cjs/utils/schema.d.ts.map +1 -0
  89. package/dist/cjs/utils/schema.js +32 -0
  90. package/dist/cjs/utils/schema.js.map +1 -0
  91. package/dist/core/Agent.d.ts +22 -29
  92. package/dist/core/Agent.d.ts.map +1 -1
  93. package/dist/core/Agent.js +464 -291
  94. package/dist/core/Agent.js.map +1 -1
  95. package/dist/core/Events.d.ts +10 -1
  96. package/dist/core/Events.d.ts.map +1 -1
  97. package/dist/core/Events.js +3 -2
  98. package/dist/core/Events.js.map +1 -1
  99. package/dist/core/PersistenceManager.d.ts +19 -0
  100. package/dist/core/PersistenceManager.d.ts.map +1 -1
  101. package/dist/core/PersistenceManager.js +55 -0
  102. package/dist/core/PersistenceManager.js.map +1 -1
  103. package/dist/core/PromptComposer.d.ts +24 -0
  104. package/dist/core/PromptComposer.d.ts.map +1 -0
  105. package/dist/core/PromptComposer.js +123 -0
  106. package/dist/core/PromptComposer.js.map +1 -0
  107. package/dist/core/ResponseEngine.d.ts +19 -0
  108. package/dist/core/ResponseEngine.d.ts.map +1 -0
  109. package/dist/core/ResponseEngine.js +47 -0
  110. package/dist/core/ResponseEngine.js.map +1 -0
  111. package/dist/core/Route.d.ts +18 -12
  112. package/dist/core/Route.d.ts.map +1 -1
  113. package/dist/core/Route.js +15 -9
  114. package/dist/core/Route.js.map +1 -1
  115. package/dist/core/RoutingEngine.d.ts +38 -0
  116. package/dist/core/RoutingEngine.d.ts.map +1 -0
  117. package/dist/core/RoutingEngine.js +106 -0
  118. package/dist/core/RoutingEngine.js.map +1 -0
  119. package/dist/core/State.d.ts +15 -4
  120. package/dist/core/State.d.ts.map +1 -1
  121. package/dist/core/State.js +21 -2
  122. package/dist/core/State.js.map +1 -1
  123. package/dist/core/ToolExecutor.d.ts +29 -0
  124. package/dist/core/ToolExecutor.d.ts.map +1 -0
  125. package/dist/core/ToolExecutor.js +69 -0
  126. package/dist/core/ToolExecutor.js.map +1 -0
  127. package/dist/core/Transition.d.ts +5 -5
  128. package/dist/core/Transition.d.ts.map +1 -1
  129. package/dist/core/Transition.js.map +1 -1
  130. package/dist/index.d.ts +6 -8
  131. package/dist/index.d.ts.map +1 -1
  132. package/dist/index.js +3 -5
  133. package/dist/index.js.map +1 -1
  134. package/dist/providers/AnthropicProvider.d.ts.map +1 -1
  135. package/dist/providers/AnthropicProvider.js +10 -13
  136. package/dist/providers/AnthropicProvider.js.map +1 -1
  137. package/dist/providers/GeminiProvider.d.ts.map +1 -1
  138. package/dist/providers/GeminiProvider.js +12 -8
  139. package/dist/providers/GeminiProvider.js.map +1 -1
  140. package/dist/providers/OpenAIProvider.d.ts.map +1 -1
  141. package/dist/providers/OpenAIProvider.js +10 -53
  142. package/dist/providers/OpenAIProvider.js.map +1 -1
  143. package/dist/providers/OpenRouterProvider.d.ts.map +1 -1
  144. package/dist/providers/OpenRouterProvider.js +10 -53
  145. package/dist/providers/OpenRouterProvider.js.map +1 -1
  146. package/dist/types/agent.d.ts +13 -12
  147. package/dist/types/agent.d.ts.map +1 -1
  148. package/dist/types/ai.d.ts +8 -2
  149. package/dist/types/ai.d.ts.map +1 -1
  150. package/dist/types/history.d.ts +8 -0
  151. package/dist/types/history.d.ts.map +1 -1
  152. package/dist/types/index.d.ts +0 -3
  153. package/dist/types/index.d.ts.map +1 -1
  154. package/dist/types/index.js +0 -1
  155. package/dist/types/index.js.map +1 -1
  156. package/dist/types/route.d.ts +39 -4
  157. package/dist/types/route.d.ts.map +1 -1
  158. package/dist/types/routing.d.ts +16 -0
  159. package/dist/types/routing.d.ts.map +1 -0
  160. package/dist/types/routing.js +2 -0
  161. package/dist/types/routing.js.map +1 -0
  162. package/dist/types/schema.d.ts +22 -0
  163. package/dist/types/schema.d.ts.map +1 -0
  164. package/dist/types/schema.js +2 -0
  165. package/dist/types/schema.js.map +1 -0
  166. package/dist/types/session.d.ts +77 -0
  167. package/dist/types/session.d.ts.map +1 -0
  168. package/dist/types/session.js +138 -0
  169. package/dist/types/session.js.map +1 -0
  170. package/dist/types/tool.d.ts +11 -5
  171. package/dist/types/tool.d.ts.map +1 -1
  172. package/dist/utils/id.d.ts +0 -5
  173. package/dist/utils/id.d.ts.map +1 -1
  174. package/dist/utils/id.js +0 -9
  175. package/dist/utils/id.js.map +1 -1
  176. package/dist/utils/schema.d.ts +17 -0
  177. package/dist/utils/schema.d.ts.map +1 -0
  178. package/dist/utils/schema.js +27 -0
  179. package/dist/utils/schema.js.map +1 -0
  180. package/docs/ADAPTERS.md +83 -3
  181. package/docs/API_REFERENCE.md +329 -104
  182. package/docs/ARCHITECTURE.md +284 -286
  183. package/docs/CONSTRUCTOR_OPTIONS.md +192 -135
  184. package/docs/CONTEXT_MANAGEMENT.md +311 -28
  185. package/docs/CONTRIBUTING.md +1 -1
  186. package/docs/DOMAINS.md +61 -0
  187. package/docs/GETTING_STARTED.md +177 -88
  188. package/docs/PERSISTENCE.md +170 -23
  189. package/docs/README.md +7 -10
  190. package/examples/business-onboarding.ts +21 -9
  191. package/examples/company-qna-agent.ts +508 -0
  192. package/examples/declarative-agent.ts +143 -26
  193. package/examples/domain-scoping.ts +31 -10
  194. package/examples/extracted-data-modification.ts +415 -0
  195. package/examples/healthcare-agent.ts +194 -90
  196. package/examples/openai-agent.ts +67 -25
  197. package/examples/opensearch-persistence.ts +455 -151
  198. package/examples/persistent-onboarding.ts +162 -96
  199. package/examples/prisma-persistence.ts +371 -125
  200. package/examples/redis-persistence.ts +393 -23
  201. package/examples/rules-prohibitions.ts +32 -11
  202. package/examples/streaming-agent.ts +61 -13
  203. package/examples/travel-agent.ts +266 -133
  204. package/package.json +1 -1
  205. package/src/core/Agent.ts +668 -356
  206. package/src/core/Events.ts +12 -2
  207. package/src/core/PersistenceManager.ts +81 -0
  208. package/src/core/PromptComposer.ts +143 -0
  209. package/src/core/ResponseEngine.ts +82 -0
  210. package/src/core/Route.ts +32 -17
  211. package/src/core/RoutingEngine.ts +165 -0
  212. package/src/core/State.ts +55 -15
  213. package/src/core/ToolExecutor.ts +117 -0
  214. package/src/core/Transition.ts +5 -5
  215. package/src/index.ts +12 -21
  216. package/src/providers/AnthropicProvider.ts +10 -13
  217. package/src/providers/GeminiProvider.ts +12 -8
  218. package/src/providers/OpenAIProvider.ts +10 -56
  219. package/src/providers/OpenRouterProvider.ts +10 -56
  220. package/src/types/agent.ts +16 -13
  221. package/src/types/ai.ts +6 -2
  222. package/src/types/history.ts +8 -0
  223. package/src/types/index.ts +0 -11
  224. package/src/types/route.ts +41 -5
  225. package/src/types/routing.ts +18 -0
  226. package/src/types/schema.ts +23 -0
  227. package/src/types/session.ts +219 -0
  228. package/src/types/tool.ts +29 -7
  229. package/src/utils/id.ts +0 -10
  230. package/src/utils/schema.ts +32 -0
  231. package/dist/cjs/core/ConditionEvaluator.d.ts +0 -72
  232. package/dist/cjs/core/ConditionEvaluator.d.ts.map +0 -1
  233. package/dist/cjs/core/ConditionEvaluator.js +0 -272
  234. package/dist/cjs/core/ConditionEvaluator.js.map +0 -1
  235. package/dist/cjs/core/Observation.d.ts +0 -24
  236. package/dist/cjs/core/Observation.d.ts.map +0 -1
  237. package/dist/cjs/core/Observation.js +0 -39
  238. package/dist/cjs/core/Observation.js.map +0 -1
  239. package/dist/cjs/core/PreparationEngine.d.ts +0 -116
  240. package/dist/cjs/core/PreparationEngine.d.ts.map +0 -1
  241. package/dist/cjs/core/PreparationEngine.js +0 -353
  242. package/dist/cjs/core/PreparationEngine.js.map +0 -1
  243. package/dist/cjs/core/PromptBuilder.d.ts +0 -136
  244. package/dist/cjs/core/PromptBuilder.d.ts.map +0 -1
  245. package/dist/cjs/core/PromptBuilder.js +0 -421
  246. package/dist/cjs/core/PromptBuilder.js.map +0 -1
  247. package/dist/cjs/types/observation.d.ts +0 -27
  248. package/dist/cjs/types/observation.d.ts.map +0 -1
  249. package/dist/cjs/types/observation.js +0 -6
  250. package/dist/cjs/types/observation.js.map +0 -1
  251. package/dist/cjs/types/prompt.d.ts +0 -46
  252. package/dist/cjs/types/prompt.d.ts.map +0 -1
  253. package/dist/cjs/types/prompt.js +0 -19
  254. package/dist/cjs/types/prompt.js.map +0 -1
  255. package/dist/core/ConditionEvaluator.d.ts +0 -72
  256. package/dist/core/ConditionEvaluator.d.ts.map +0 -1
  257. package/dist/core/ConditionEvaluator.js +0 -268
  258. package/dist/core/ConditionEvaluator.js.map +0 -1
  259. package/dist/core/Observation.d.ts +0 -24
  260. package/dist/core/Observation.d.ts.map +0 -1
  261. package/dist/core/Observation.js +0 -35
  262. package/dist/core/Observation.js.map +0 -1
  263. package/dist/core/PreparationEngine.d.ts +0 -116
  264. package/dist/core/PreparationEngine.d.ts.map +0 -1
  265. package/dist/core/PreparationEngine.js +0 -349
  266. package/dist/core/PreparationEngine.js.map +0 -1
  267. package/dist/core/PromptBuilder.d.ts +0 -136
  268. package/dist/core/PromptBuilder.d.ts.map +0 -1
  269. package/dist/core/PromptBuilder.js +0 -417
  270. package/dist/core/PromptBuilder.js.map +0 -1
  271. package/dist/types/observation.d.ts +0 -27
  272. package/dist/types/observation.d.ts.map +0 -1
  273. package/dist/types/observation.js +0 -5
  274. package/dist/types/observation.js.map +0 -1
  275. package/dist/types/prompt.d.ts +0 -46
  276. package/dist/types/prompt.d.ts.map +0 -1
  277. package/dist/types/prompt.js +0 -16
  278. package/dist/types/prompt.js.map +0 -1
  279. package/docs/STRUCTURE.md +0 -58
  280. package/src/core/ConditionEvaluator.ts +0 -381
  281. package/src/core/Observation.ts +0 -47
  282. package/src/core/PreparationEngine.ts +0 -561
  283. package/src/core/PromptBuilder.ts +0 -617
  284. package/src/types/observation.ts +0 -29
  285. package/src/types/prompt.ts +0 -49
@@ -1,421 +0,0 @@
1
- "use strict";
2
- /**
3
- * Prompt construction and management
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PromptBuilder = exports.BuiltInSection = void 0;
7
- const history_1 = require("../types/history");
8
- const prompt_1 = require("../types/prompt");
9
- const Events_1 = require("./Events");
10
- /**
11
- * Built-in section identifiers
12
- */
13
- var BuiltInSection;
14
- (function (BuiltInSection) {
15
- BuiltInSection["AGENT_IDENTITY"] = "agent_identity";
16
- BuiltInSection["CUSTOMER_IDENTITY"] = "customer_identity";
17
- BuiltInSection["INTERACTION_HISTORY"] = "interaction_history";
18
- BuiltInSection["CONTEXT_VARIABLES"] = "context_variables";
19
- BuiltInSection["GLOSSARY"] = "glossary";
20
- BuiltInSection["GUIDELINE_DESCRIPTIONS"] = "guideline_descriptions";
21
- BuiltInSection["GUIDELINES"] = "guidelines";
22
- BuiltInSection["STAGED_EVENTS"] = "staged_events";
23
- BuiltInSection["ROUTES"] = "routes";
24
- BuiltInSection["OBSERVATIONS"] = "observations";
25
- BuiltInSection["CAPABILITIES"] = "capabilities";
26
- BuiltInSection["ACTIVE_ROUTES"] = "active_routes";
27
- BuiltInSection["DOMAINS"] = "domains";
28
- })(BuiltInSection || (exports.BuiltInSection = BuiltInSection = {}));
29
- /**
30
- * Builds prompts from composable sections
31
- */
32
- class PromptBuilder {
33
- constructor(onBuild) {
34
- this.sections = new Map();
35
- this.cachedResults = new Set();
36
- this.onBuild = onBuild;
37
- }
38
- /**
39
- * Build the final prompt from all sections
40
- */
41
- build() {
42
- const parts = [];
43
- for (const section of this.sections.values()) {
44
- try {
45
- const formatted = this.formatTemplate(section.template, section.props);
46
- parts.push(formatted);
47
- }
48
- catch (error) {
49
- throw new Error(`Error formatting section: ${error instanceof Error ? error.message : "Unknown error"}`);
50
- }
51
- }
52
- const prompt = parts.join("\n\n").trim();
53
- if (this.onBuild && !this.cachedResults.has(prompt)) {
54
- this.onBuild(prompt);
55
- this.cachedResults.add(prompt);
56
- }
57
- return prompt;
58
- }
59
- /**
60
- * Add a section to the prompt
61
- */
62
- addSection(name, template, props = {}, status) {
63
- if (this.sections.has(name)) {
64
- throw new Error(`Section '${String(name)}' already exists`);
65
- }
66
- this.sections.set(name, {
67
- template,
68
- props,
69
- status,
70
- });
71
- return this;
72
- }
73
- /**
74
- * Edit an existing section
75
- */
76
- editSection(name, editor) {
77
- const section = this.sections.get(name);
78
- if (section) {
79
- this.sections.set(name, editor(section));
80
- }
81
- return this;
82
- }
83
- /**
84
- * Get section status
85
- */
86
- sectionStatus(name) {
87
- const section = this.sections.get(name);
88
- return section?.status || prompt_1.SectionStatus.NONE;
89
- }
90
- /**
91
- * Add agent identity section
92
- */
93
- addAgentIdentity(agent) {
94
- if (agent.description) {
95
- this.addSection(BuiltInSection.AGENT_IDENTITY, `You are an AI agent named {agent_name}.
96
-
97
- The following is a description of your background and personality: ###
98
- {agent_description}
99
- ###`, {
100
- agent_name: agent.name,
101
- agent_description: agent.description,
102
- }, prompt_1.SectionStatus.ACTIVE);
103
- }
104
- return this;
105
- }
106
- /**
107
- * Add customer identity section
108
- */
109
- addCustomerIdentity(customer) {
110
- this.addSection(BuiltInSection.CUSTOMER_IDENTITY, `The user you're interacting with is called {customer_name}.`, { customer_name: customer.name }, prompt_1.SectionStatus.ACTIVE);
111
- return this;
112
- }
113
- /**
114
- * Add interaction history section
115
- */
116
- addInteractionHistory(events, stagedEvents = []) {
117
- if (events.length === 0 && stagedEvents.length === 0) {
118
- this.addSection(BuiltInSection.INTERACTION_HISTORY, `Your interaction with the user has just began, and no events have been recorded yet.
119
- Proceed with your task accordingly.`, {}, prompt_1.SectionStatus.PASSIVE);
120
- }
121
- else {
122
- const interactionEvents = this.gatherInteractionEvents(events, stagedEvents);
123
- this.addSection(BuiltInSection.INTERACTION_HISTORY, `The following is a list of events describing a back-and-forth
124
- interaction between you and a user: ###
125
- {interaction_events}
126
- ###`, { interaction_events: interactionEvents.join("\n") }, prompt_1.SectionStatus.ACTIVE);
127
- }
128
- return this;
129
- }
130
- /**
131
- * Add interaction history with special handling for message generation
132
- */
133
- addInteractionHistoryForMessageGeneration(events, stagedEvents = []) {
134
- if (events.length === 0 && stagedEvents.length === 0) {
135
- return this.addInteractionHistory(events, stagedEvents);
136
- }
137
- const interactionEvents = this.gatherInteractionEvents(events, stagedEvents);
138
- const lastEventNote = this.lastAgentMessageNote(events);
139
- let template = `The following is a list of events describing a back-and-forth
140
- interaction between you and a user: ###
141
- {interaction_events}
142
- ###`;
143
- const props = {
144
- interaction_events: interactionEvents.join("\n"),
145
- };
146
- if (lastEventNote) {
147
- template += "\n\n{last_event_note}";
148
- props.last_event_note = lastEventNote;
149
- }
150
- this.addSection(BuiltInSection.INTERACTION_HISTORY, template, props, prompt_1.SectionStatus.ACTIVE);
151
- return this;
152
- }
153
- /**
154
- * Add context variables section
155
- */
156
- addContextVariables(variables) {
157
- if (variables.length > 0) {
158
- const contextValues = this.contextVariablesToJson(variables);
159
- this.addSection(BuiltInSection.CONTEXT_VARIABLES, `The following is information that you're given about the user and context of the interaction: ###
160
- {context_values}
161
- ###`, { context_values: contextValues }, prompt_1.SectionStatus.ACTIVE);
162
- }
163
- return this;
164
- }
165
- /**
166
- * Add glossary section
167
- */
168
- addGlossary(terms) {
169
- if (terms.length > 0) {
170
- const termsString = terms
171
- .map((t, i) => {
172
- const synonyms = t.synonyms?.length
173
- ? ` (synonyms: ${t.synonyms.join(", ")})`
174
- : "";
175
- return `${i + 1}) ${t.name}${synonyms}: ${t.description}`;
176
- })
177
- .join("\n");
178
- this.addSection(BuiltInSection.GLOSSARY, `The following is a glossary of the business.
179
- Understanding these terms, as they apply to the business, is critical for your task.
180
- When encountering any of these terms, prioritize the interpretation provided here over any definitions you may already know.
181
- Please be tolerant of possible typos by the user with regards to these terms,
182
- and let the user know if/when you assume they meant a term by their typo: ###
183
- {terms_string}
184
- ###`, { terms_string: termsString }, prompt_1.SectionStatus.ACTIVE);
185
- }
186
- return this;
187
- }
188
- /**
189
- * Add staged tool events section
190
- */
191
- addStagedToolEvents(events) {
192
- const toolEvents = events.filter((e) => e.kind === history_1.EventKind.TOOL);
193
- if (toolEvents.length > 0) {
194
- const stagedEventsAsDict = toolEvents.map((e) => (0, Events_1.adaptEvent)(e));
195
- this.addSection(BuiltInSection.STAGED_EVENTS, `Here are the most recent staged events for your reference.
196
- They represent interactions with external tools that perform actions or provide information.
197
- Prioritize their data over any other sources and use their details to complete your task: ###
198
- {staged_events_as_dict}
199
- ###`, { staged_events_as_dict: stagedEventsAsDict.join("\n") }, prompt_1.SectionStatus.ACTIVE);
200
- }
201
- return this;
202
- }
203
- /**
204
- * Add guidelines for message generation
205
- */
206
- addGuidelinesForMessageGeneration(guidelines) {
207
- if (guidelines.length === 0) {
208
- this.addSection(BuiltInSection.GUIDELINE_DESCRIPTIONS, `In formulating your reply, you are normally required to follow a number of behavioral guidelines.
209
- However, in this case, no special behavioral guidelines were provided. Therefore, when generating revisions,
210
- you don't need to specifically double-check if you followed or broke any guidelines.`, {}, prompt_1.SectionStatus.PASSIVE);
211
- return this;
212
- }
213
- const guidelineList = guidelines
214
- .map((g, i) => {
215
- const num = i + 1;
216
- let text = g.guideline.condition
217
- ? `Guideline #${num}) When ${g.guideline.condition}, then ${g.guideline.action}`
218
- : `Guideline #${num}) ${g.guideline.action}`;
219
- if (g.rationale) {
220
- text += `\n - Rationale: ${g.rationale}`;
221
- }
222
- return text;
223
- })
224
- .join("\n");
225
- this.addSection(BuiltInSection.GUIDELINE_DESCRIPTIONS, `When crafting your reply, you must follow the behavioral guidelines provided below, which have been identified as relevant to the current state of the interaction.
226
-
227
- - **Guidelines**:
228
- {guideline_list}
229
-
230
- You may choose not to follow a guideline only in the following cases:
231
- - It conflicts with a previous customer request.
232
- - It is clearly inappropriate given the current context of the conversation.
233
- - It lacks sufficient context or data to apply reliably.
234
- - It conflicts with an insight.
235
-
236
- In all other situations, you are expected to adhere to the guidelines.
237
- These guidelines have already been pre-filtered based on the interaction's context and other considerations outside your scope.`, { guideline_list: guidelineList }, prompt_1.SectionStatus.ACTIVE);
238
- return this;
239
- }
240
- /**
241
- * Add capabilities section for message generation
242
- */
243
- addCapabilitiesForMessageGeneration(capabilities) {
244
- if (capabilities.length > 0) {
245
- const capabilitiesString = capabilities
246
- .map((c, i) => `Supported Capability ${i + 1}: ${c.title}
247
- ${c.description}`)
248
- .join("\n\n");
249
- this.addSection(BuiltInSection.CAPABILITIES, `Below are the capabilities available to you as an agent.
250
- You may inform the customer that you can assist them using these capabilities.
251
- If you choose to use any of them, additional details will be provided in your next response.
252
- Always prefer adhering to guidelines, before offering capabilities - only offer capabilities if you have no other instruction that's relevant for the current stage of the interaction.
253
- Be proactive and offer the most relevant capabilities—but only if they are likely to move the conversation forward.
254
- If multiple capabilities are appropriate, aim to present them all to the customer.
255
- If none of the capabilities address the current request of the customer - DO NOT MENTION THEM.
256
- ###
257
- {capabilities_string}
258
- ###`, { capabilities_string: capabilitiesString }, prompt_1.SectionStatus.ACTIVE);
259
- }
260
- return this;
261
- }
262
- /**
263
- * Add observations for disambiguation
264
- */
265
- addObservations(observations) {
266
- if (observations.length > 0) {
267
- const observationsString = observations
268
- .map((obs, i) => {
269
- const routeTitles = obs.routes.map((r) => `"${r.title}"`).join(", ");
270
- return `${i + 1}) "${obs.description}" → Can lead to routes: ${routeTitles}`;
271
- })
272
- .join("\n");
273
- this.addSection(BuiltInSection.OBSERVATIONS, `The following observations may help you understand the user's intent and choose the appropriate response path:
274
- ###
275
- {observations_string}
276
- ###
277
-
278
- When you detect any of these situations, consider which route would be most appropriate based on the user's actual need.`, { observations_string: observationsString }, prompt_1.SectionStatus.ACTIVE);
279
- }
280
- return this;
281
- }
282
- /**
283
- * Add active routes information
284
- */
285
- addActiveRoutes(routes) {
286
- if (routes.length > 0) {
287
- const routesString = routes
288
- .map((route, i) => {
289
- const conditions = route.conditions.length > 0
290
- ? `\n Triggered when: ${route.conditions.join(" OR ")}`
291
- : "";
292
- const desc = route.description ? `\n ${route.description}` : "";
293
- let domainInfo = "";
294
- if (route.domains !== undefined) {
295
- if (route.domains.length === 0) {
296
- domainInfo = "\n Available tools: None (conversation only)";
297
- }
298
- else {
299
- domainInfo = `\n Available tools: ${route.domains.join(", ")}`;
300
- }
301
- }
302
- let rulesInfo = "";
303
- if (route.rules && route.rules.length > 0) {
304
- const rulesList = route.rules
305
- .map((r, idx) => `${idx + 1}. ${r}`)
306
- .join("; ");
307
- rulesInfo = `\n RULES: ${rulesList}`;
308
- }
309
- let prohibitionsInfo = "";
310
- if (route.prohibitions && route.prohibitions.length > 0) {
311
- const prohibitionsList = route.prohibitions
312
- .map((p, idx) => `${idx + 1}. ${p}`)
313
- .join("; ");
314
- prohibitionsInfo = `\n PROHIBITIONS: ${prohibitionsList}`;
315
- }
316
- return `${i + 1}) ${route.title}${desc}${conditions}${domainInfo}${rulesInfo}${prohibitionsInfo}`;
317
- })
318
- .join("\n\n");
319
- this.addSection(BuiltInSection.ACTIVE_ROUTES, `Available conversation routes:
320
- ###
321
- {routes_string}
322
- ###
323
-
324
- These routes represent different paths the conversation can take. Choose the most appropriate route based on the user's needs.
325
- IMPORTANT:
326
- - If a route specifies available tools, you can ONLY call tools from those domains when following that route.
327
- - If a route has RULES, you MUST follow them when you choose that route.
328
- - If a route has PROHIBITIONS, you MUST NEVER do those things when you choose that route.`, { routes_string: routesString }, prompt_1.SectionStatus.ACTIVE);
329
- }
330
- return this;
331
- }
332
- /**
333
- * Add domains (tools) information
334
- */
335
- addDomains(domains) {
336
- const domainNames = Object.keys(domains);
337
- if (domainNames.length > 0) {
338
- const domainsString = domainNames
339
- .map((name, i) => {
340
- const toolNames = Object.keys(domains[name]);
341
- const tools = toolNames.join(", ");
342
- return `${i + 1}) Domain "${name}": ${tools}`;
343
- })
344
- .join("\n");
345
- this.addSection(BuiltInSection.DOMAINS, `Available tool domains:
346
- ###
347
- {domains_string}
348
- ###
349
-
350
- These are the tool domains registered in the system. Each domain contains specific tools/methods.
351
- When calling tools, use the format: domain.toolName (e.g., "payment.processPayment").`, { domains_string: domainsString }, prompt_1.SectionStatus.ACTIVE);
352
- }
353
- return this;
354
- }
355
- /**
356
- * Add JSON response schema instructions
357
- *
358
- * NOTE: toolCalls are NOT included. Tools execute automatically based on
359
- * state transitions and guideline matching, NOT based on AI decisions.
360
- */
361
- addJsonResponseSchema() {
362
- const schema = {
363
- message: "The actual message to send to the user",
364
- route: "The title of the route you chose (or null if no specific route)",
365
- state: "The current state within the chosen route (or null if not in a route)",
366
- reasoning: "Optional: Your internal reasoning for this response",
367
- };
368
- this.addSection("json_response_format", `IMPORTANT: You must respond with valid JSON in the following format:
369
-
370
- \`\`\`json
371
- ${JSON.stringify(schema, null, 2)}
372
- \`\`\`
373
-
374
- Instructions:
375
- - "message": The actual message to send to the user (required)
376
- - "route": If you chose a specific conversation route, provide its exact title. If not in a route, use null.
377
- - "state": The current state within the chosen route. If not in a route or at initial state, use null.
378
- - "reasoning": Optional field for your internal thinking process.
379
-
380
- Your entire response must be valid JSON. Do not include any text before or after the JSON object.`, {}, prompt_1.SectionStatus.ACTIVE);
381
- return this;
382
- }
383
- // Helper methods
384
- formatTemplate(template, props) {
385
- return template.replace(/\{(\w+)\}/g, (match, key) => {
386
- if (key in props) {
387
- return String(props[key]);
388
- }
389
- return match;
390
- });
391
- }
392
- gatherInteractionEvents(events, stagedEvents) {
393
- const combined = [...events, ...stagedEvents];
394
- return combined
395
- .filter((e) => e.kind !== history_1.EventKind.STATUS)
396
- .map((e) => (0, Events_1.adaptEvent)(e));
397
- }
398
- lastAgentMessageNote(events) {
399
- const lastMessageEvent = [...events]
400
- .reverse()
401
- .find((e) => e.kind === history_1.EventKind.MESSAGE);
402
- if (!lastMessageEvent || lastMessageEvent.source !== history_1.EventSource.AI_AGENT) {
403
- return null;
404
- }
405
- const lastMessage = lastMessageEvent.data.message;
406
- return `IMPORTANT: Please note that the last message was sent by you, the AI agent (likely as a preamble). Your last message was: ###
407
- ${lastMessage}
408
- ###
409
-
410
- You must keep that in mind when responding to the user, to continue the last message naturally (without repeating anything similar in your last message - make sure you don't repeat something like this in your next message - it was already said!).`;
411
- }
412
- contextVariablesToJson(variables) {
413
- const obj = {};
414
- for (const v of variables) {
415
- obj[v.variable.name] = v.value;
416
- }
417
- return JSON.stringify(obj, null, 2);
418
- }
419
- }
420
- exports.PromptBuilder = PromptBuilder;
421
- //# sourceMappingURL=PromptBuilder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PromptBuilder.js","sourceRoot":"","sources":["../../../src/core/PromptBuilder.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,8CAA0D;AAG1D,4CAAgD;AAEhD,qCAAsC;AAEtC;;GAEG;AACH,IAAY,cAcX;AAdD,WAAY,cAAc;IACxB,mDAAiC,CAAA;IACjC,yDAAuC,CAAA;IACvC,6DAA2C,CAAA;IAC3C,yDAAuC,CAAA;IACvC,uCAAqB,CAAA;IACrB,mEAAiD,CAAA;IACjD,2CAAyB,CAAA;IACzB,iDAA+B,CAAA;IAC/B,mCAAiB,CAAA;IACjB,+CAA6B,CAAA;IAC7B,+CAA6B,CAAA;IAC7B,iDAA+B,CAAA;IAC/B,qCAAmB,CAAA;AACrB,CAAC,EAdW,cAAc,8BAAd,cAAc,QAczB;AAkBD;;GAEG;AACH,MAAa,aAAa;IAKxB,YAAY,OAAkC;QAJtC,aAAQ,GAAgD,IAAI,GA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AC,MAAM,CAAC;aAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,mBAAU,EAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC;IAEO,oBAAoB,CAAC,MAAe;QAC1C,MAAM,gBAAgB,GAAG,CAAC,GAAG,MAAM,CAAC;aACjC,OAAO,EAAE;aACT,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,mBAAS,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,KAAK,qBAAW,CAAC,QAAQ,EAAE,CAAC;YAC1E,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,WAAW,GAAI,gBAAgB,CAAC,IAAyB,CAAC,OAAO,CAAC;QACxE,OAAO;EACT,WAAW;;;uPAG0O,CAAC;IACtP,CAAC;IAEO,sBAAsB,CAAC,SAAiC;QAC9D,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;YAC1B,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;QACjC,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACtC,CAAC;CACF;AAtjBD,sCAsjBC"}
@@ -1,27 +0,0 @@
1
- /**
2
- * Observation types for disambiguation
3
- */
4
- import type { RouteRef } from "./route";
5
- /**
6
- * An observation that can disambiguate between multiple routes
7
- */
8
- export interface Observation {
9
- /** Unique identifier */
10
- id: string;
11
- /** The observation description */
12
- description: string;
13
- /** Routes this observation can disambiguate between */
14
- routes?: RouteRef[];
15
- }
16
- /**
17
- * Options for creating an observation
18
- */
19
- export interface ObservationOptions {
20
- /** Custom ID for the observation (optional - will generate deterministic ID from description if not provided) */
21
- id?: string;
22
- /** The observation description */
23
- description: string;
24
- /** Route IDs or titles to disambiguate between (can be set later with disambiguate()) */
25
- routeRefs?: string[];
26
- }
27
- //# sourceMappingURL=observation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../../../src/types/observation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,wBAAwB;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iHAAiH;IACjH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- /**
3
- * Observation types for disambiguation
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- //# sourceMappingURL=observation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"observation.js","sourceRoot":"","sources":["../../../src/types/observation.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -1,46 +0,0 @@
1
- /**
2
- * Prompt building types
3
- */
4
- /**
5
- * Status of a prompt section
6
- */
7
- export declare enum SectionStatus {
8
- /** Section has active information */
9
- ACTIVE = "active",
10
- /** Section is inactive but may have empty-state text */
11
- PASSIVE = "passive",
12
- /** Section is not included */
13
- NONE = "none"
14
- }
15
- /**
16
- * A section within a prompt
17
- */
18
- export interface PromptSection {
19
- /** Template string (may contain placeholders) */
20
- template: string;
21
- /** Properties to fill template placeholders */
22
- props: Record<string, unknown>;
23
- /** Status of this section */
24
- status?: SectionStatus;
25
- }
26
- /**
27
- * Context variable with value
28
- */
29
- export interface ContextVariable {
30
- /** Variable name */
31
- name: string;
32
- /** Variable description */
33
- description?: string;
34
- /** Variable type */
35
- type?: string;
36
- }
37
- /**
38
- * Value for a context variable
39
- */
40
- export interface ContextVariableValue {
41
- /** The variable definition */
42
- variable: ContextVariable;
43
- /** The current value */
44
- value: unknown;
45
- }
46
- //# sourceMappingURL=prompt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/types/prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,oBAAY,aAAa;IACvB,qCAAqC;IACrC,MAAM,WAAW;IACjB,wDAAwD;IACxD,OAAO,YAAY;IACnB,8BAA8B;IAC9B,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,6BAA6B;IAC7B,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,8BAA8B;IAC9B,QAAQ,EAAE,eAAe,CAAC;IAC1B,wBAAwB;IACxB,KAAK,EAAE,OAAO,CAAC;CAChB"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- /**
3
- * Prompt building types
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SectionStatus = void 0;
7
- /**
8
- * Status of a prompt section
9
- */
10
- var SectionStatus;
11
- (function (SectionStatus) {
12
- /** Section has active information */
13
- SectionStatus["ACTIVE"] = "active";
14
- /** Section is inactive but may have empty-state text */
15
- SectionStatus["PASSIVE"] = "passive";
16
- /** Section is not included */
17
- SectionStatus["NONE"] = "none";
18
- })(SectionStatus || (exports.SectionStatus = SectionStatus = {}));
19
- //# sourceMappingURL=prompt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/types/prompt.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,qCAAqC;IACrC,kCAAiB,CAAA;IACjB,wDAAwD;IACxD,oCAAmB,CAAA;IACnB,8BAA8B;IAC9B,8BAAa,CAAA;AACf,CAAC,EAPW,aAAa,6BAAb,aAAa,QAOxB"}
@@ -1,72 +0,0 @@
1
- /**
2
- * ConditionEvaluator - Handles AI-powered condition evaluation
3
- *
4
- * This class is responsible for:
5
- * - Evaluating guideline conditions
6
- * - Evaluating transition conditions
7
- * - Extracting tool arguments from context and history
8
- */
9
- import type { Event, AiProvider } from "../types/index";
10
- import type { Guideline } from "../types/agent";
11
- import type { ToolRef } from "../types/tool";
12
- /**
13
- * Result of guideline condition evaluation
14
- */
15
- export interface GuidelineEvaluationResult {
16
- matches: boolean;
17
- rationale?: string;
18
- }
19
- /**
20
- * Result of transition condition evaluation
21
- */
22
- export interface TransitionEvaluationResult {
23
- shouldFollow: boolean;
24
- rationale?: string;
25
- }
26
- /**
27
- * Result of tool argument extraction
28
- */
29
- export interface ArgumentExtractionResult {
30
- arguments: unknown[];
31
- rationale?: string;
32
- }
33
- /**
34
- * ConditionEvaluator - Evaluates conditions using AI
35
- */
36
- export declare class ConditionEvaluator<TContext = unknown> {
37
- private readonly ai;
38
- constructor(ai: AiProvider);
39
- /**
40
- * Evaluate a guideline condition against context and history
41
- */
42
- evaluateGuidelineCondition(guideline: Guideline, context: TContext, history: Event[]): Promise<GuidelineEvaluationResult>;
43
- /**
44
- * Evaluate a transition condition
45
- */
46
- evaluateTransitionCondition(condition: string, context: TContext, history: Event[]): Promise<TransitionEvaluationResult>;
47
- /**
48
- * Extract tool arguments from context and history
49
- */
50
- extractToolArguments(tool: ToolRef<TContext, unknown[], unknown>, context: TContext, history: Event[]): Promise<ArgumentExtractionResult>;
51
- /**
52
- * Simple argument extraction from context (fallback)
53
- */
54
- simpleArgumentExtraction(tool: ToolRef<TContext, unknown[], unknown>, context: TContext): unknown[];
55
- /**
56
- * Extract recent messages from history
57
- */
58
- private extractRecentMessages;
59
- /**
60
- * Parse guideline evaluation from text response (fallback)
61
- */
62
- private parseGuidelineResponse;
63
- /**
64
- * Parse transition evaluation from text response (fallback)
65
- */
66
- private parseTransitionResponse;
67
- /**
68
- * Parse argument extraction from text response (fallback)
69
- */
70
- private parseArgumentResponse;
71
- }
72
- //# sourceMappingURL=ConditionEvaluator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConditionEvaluator.d.ts","sourceRoot":"","sources":["../../src/core/ConditionEvaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAoB,MAAM,gBAAgB,CAAC;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA0BD;;GAEG;AACH,qBAAa,kBAAkB,CAAC,QAAQ,GAAG,OAAO;IACpC,OAAO,CAA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