@falai/agent 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 (129) hide show
  1. package/README.md +516 -0
  2. package/dist/constants/index.d.ts +5 -0
  3. package/dist/constants/index.d.ts.map +1 -0
  4. package/dist/constants/index.js +5 -0
  5. package/dist/constants/index.js.map +1 -0
  6. package/dist/core/Agent.d.ts +98 -0
  7. package/dist/core/Agent.d.ts.map +1 -0
  8. package/dist/core/Agent.js +248 -0
  9. package/dist/core/Agent.js.map +1 -0
  10. package/dist/core/DomainRegistry.d.ts +26 -0
  11. package/dist/core/DomainRegistry.d.ts.map +1 -0
  12. package/dist/core/DomainRegistry.js +41 -0
  13. package/dist/core/DomainRegistry.js.map +1 -0
  14. package/dist/core/Events.d.ts +19 -0
  15. package/dist/core/Events.d.ts.map +1 -0
  16. package/dist/core/Events.js +79 -0
  17. package/dist/core/Events.js.map +1 -0
  18. package/dist/core/Observation.d.ts +24 -0
  19. package/dist/core/Observation.d.ts.map +1 -0
  20. package/dist/core/Observation.js +35 -0
  21. package/dist/core/Observation.js.map +1 -0
  22. package/dist/core/PromptBuilder.d.ts +121 -0
  23. package/dist/core/PromptBuilder.d.ts.map +1 -0
  24. package/dist/core/PromptBuilder.js +339 -0
  25. package/dist/core/PromptBuilder.js.map +1 -0
  26. package/dist/core/Route.d.ts +46 -0
  27. package/dist/core/Route.d.ts.map +1 -0
  28. package/dist/core/Route.js +113 -0
  29. package/dist/core/Route.js.map +1 -0
  30. package/dist/core/State.d.ts +50 -0
  31. package/dist/core/State.d.ts.map +1 -0
  32. package/dist/core/State.js +110 -0
  33. package/dist/core/State.js.map +1 -0
  34. package/dist/core/Tool.d.ts +31 -0
  35. package/dist/core/Tool.d.ts.map +1 -0
  36. package/dist/core/Tool.js +33 -0
  37. package/dist/core/Tool.js.map +1 -0
  38. package/dist/core/Transition.d.ts +32 -0
  39. package/dist/core/Transition.d.ts.map +1 -0
  40. package/dist/core/Transition.js +59 -0
  41. package/dist/core/Transition.js.map +1 -0
  42. package/dist/index.d.ts +34 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +26 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/providers/GeminiProvider.d.ts +40 -0
  47. package/dist/providers/GeminiProvider.d.ts.map +1 -0
  48. package/dist/providers/GeminiProvider.js +126 -0
  49. package/dist/providers/GeminiProvider.js.map +1 -0
  50. package/dist/providers/OpenAIProvider.d.ts +42 -0
  51. package/dist/providers/OpenAIProvider.d.ts.map +1 -0
  52. package/dist/providers/OpenAIProvider.js +164 -0
  53. package/dist/providers/OpenAIProvider.js.map +1 -0
  54. package/dist/providers/OpenRouterProvider.d.ts +46 -0
  55. package/dist/providers/OpenRouterProvider.d.ts.map +1 -0
  56. package/dist/providers/OpenRouterProvider.js +171 -0
  57. package/dist/providers/OpenRouterProvider.js.map +1 -0
  58. package/dist/types/agent.d.ts +105 -0
  59. package/dist/types/agent.d.ts.map +1 -0
  60. package/dist/types/agent.js +18 -0
  61. package/dist/types/agent.js.map +1 -0
  62. package/dist/types/ai.d.ts +78 -0
  63. package/dist/types/ai.d.ts.map +1 -0
  64. package/dist/types/ai.js +5 -0
  65. package/dist/types/ai.js.map +1 -0
  66. package/dist/types/history.d.ts +112 -0
  67. package/dist/types/history.d.ts.map +1 -0
  68. package/dist/types/history.js +34 -0
  69. package/dist/types/history.js.map +1 -0
  70. package/dist/types/index.d.ts +14 -0
  71. package/dist/types/index.d.ts.map +1 -0
  72. package/dist/types/index.js +7 -0
  73. package/dist/types/index.js.map +1 -0
  74. package/dist/types/observation.d.ts +25 -0
  75. package/dist/types/observation.d.ts.map +1 -0
  76. package/dist/types/observation.js +5 -0
  77. package/dist/types/observation.js.map +1 -0
  78. package/dist/types/prompt.d.ts +46 -0
  79. package/dist/types/prompt.d.ts.map +1 -0
  80. package/dist/types/prompt.js +16 -0
  81. package/dist/types/prompt.js.map +1 -0
  82. package/dist/types/route.d.ts +59 -0
  83. package/dist/types/route.d.ts.map +1 -0
  84. package/dist/types/route.js +5 -0
  85. package/dist/types/route.js.map +1 -0
  86. package/dist/types/tool.d.ts +46 -0
  87. package/dist/types/tool.d.ts.map +1 -0
  88. package/dist/types/tool.js +5 -0
  89. package/dist/types/tool.js.map +1 -0
  90. package/dist/utils/retry.d.ts +13 -0
  91. package/dist/utils/retry.d.ts.map +1 -0
  92. package/dist/utils/retry.js +70 -0
  93. package/dist/utils/retry.js.map +1 -0
  94. package/docs/API_REFERENCE.md +517 -0
  95. package/docs/CONSTRUCTOR_OPTIONS.md +256 -0
  96. package/docs/CONTRIBUTING.md +481 -0
  97. package/docs/GETTING_STARTED.md +328 -0
  98. package/docs/PROVIDERS.md +472 -0
  99. package/docs/PUBLISHING.md +174 -0
  100. package/docs/README.md +68 -0
  101. package/docs/STRUCTURE.md +32 -0
  102. package/examples/declarative-agent.ts +217 -0
  103. package/examples/healthcare-agent.ts +283 -0
  104. package/examples/openai-agent.ts +167 -0
  105. package/examples/travel-agent.ts +342 -0
  106. package/package.json +73 -0
  107. package/src/constants/index.ts +5 -0
  108. package/src/core/Agent.ts +307 -0
  109. package/src/core/DomainRegistry.ts +50 -0
  110. package/src/core/Events.ts +101 -0
  111. package/src/core/Observation.ts +46 -0
  112. package/src/core/PromptBuilder.ts +511 -0
  113. package/src/core/Route.ts +136 -0
  114. package/src/core/State.ts +153 -0
  115. package/src/core/Tool.ts +54 -0
  116. package/src/core/Transition.ts +66 -0
  117. package/src/index.ts +83 -0
  118. package/src/providers/GeminiProvider.ts +220 -0
  119. package/src/providers/OpenAIProvider.ts +272 -0
  120. package/src/providers/OpenRouterProvider.ts +282 -0
  121. package/src/types/agent.ts +112 -0
  122. package/src/types/ai.ts +85 -0
  123. package/src/types/history.ts +125 -0
  124. package/src/types/index.ts +56 -0
  125. package/src/types/observation.ts +27 -0
  126. package/src/types/prompt.ts +49 -0
  127. package/src/types/route.ts +68 -0
  128. package/src/types/tool.ts +53 -0
  129. package/src/utils/retry.ts +96 -0
@@ -0,0 +1,339 @@
1
+ /**
2
+ * Prompt construction and management
3
+ */
4
+ import { EventKind, EventSource } from "@/types/history";
5
+ import { SectionStatus } from "@/types/prompt";
6
+ import { adaptEvent } from "@/core/Events";
7
+ /**
8
+ * Built-in section identifiers
9
+ */
10
+ export var BuiltInSection;
11
+ (function (BuiltInSection) {
12
+ BuiltInSection["AGENT_IDENTITY"] = "agent_identity";
13
+ BuiltInSection["CUSTOMER_IDENTITY"] = "customer_identity";
14
+ BuiltInSection["INTERACTION_HISTORY"] = "interaction_history";
15
+ BuiltInSection["CONTEXT_VARIABLES"] = "context_variables";
16
+ BuiltInSection["GLOSSARY"] = "glossary";
17
+ BuiltInSection["GUIDELINE_DESCRIPTIONS"] = "guideline_descriptions";
18
+ BuiltInSection["GUIDELINES"] = "guidelines";
19
+ BuiltInSection["STAGED_EVENTS"] = "staged_events";
20
+ BuiltInSection["ROUTES"] = "routes";
21
+ BuiltInSection["OBSERVATIONS"] = "observations";
22
+ BuiltInSection["CAPABILITIES"] = "capabilities";
23
+ BuiltInSection["ACTIVE_ROUTES"] = "active_routes";
24
+ })(BuiltInSection || (BuiltInSection = {}));
25
+ /**
26
+ * Builds prompts from composable sections
27
+ */
28
+ export class PromptBuilder {
29
+ sections = new Map();
30
+ onBuild;
31
+ cachedResults = new Set();
32
+ constructor(onBuild) {
33
+ this.onBuild = onBuild;
34
+ }
35
+ /**
36
+ * Build the final prompt from all sections
37
+ */
38
+ build() {
39
+ const parts = [];
40
+ for (const section of this.sections.values()) {
41
+ try {
42
+ const formatted = this.formatTemplate(section.template, section.props);
43
+ parts.push(formatted);
44
+ }
45
+ catch (error) {
46
+ throw new Error(`Error formatting section: ${error instanceof Error ? error.message : "Unknown error"}`);
47
+ }
48
+ }
49
+ const prompt = parts.join("\n\n").trim();
50
+ if (this.onBuild && !this.cachedResults.has(prompt)) {
51
+ this.onBuild(prompt);
52
+ this.cachedResults.add(prompt);
53
+ }
54
+ return prompt;
55
+ }
56
+ /**
57
+ * Add a section to the prompt
58
+ */
59
+ addSection(name, template, props = {}, status) {
60
+ if (this.sections.has(name)) {
61
+ throw new Error(`Section '${String(name)}' already exists`);
62
+ }
63
+ this.sections.set(name, {
64
+ template,
65
+ props,
66
+ status,
67
+ });
68
+ return this;
69
+ }
70
+ /**
71
+ * Edit an existing section
72
+ */
73
+ editSection(name, editor) {
74
+ const section = this.sections.get(name);
75
+ if (section) {
76
+ this.sections.set(name, editor(section));
77
+ }
78
+ return this;
79
+ }
80
+ /**
81
+ * Get section status
82
+ */
83
+ sectionStatus(name) {
84
+ const section = this.sections.get(name);
85
+ return section?.status || SectionStatus.NONE;
86
+ }
87
+ /**
88
+ * Add agent identity section
89
+ */
90
+ addAgentIdentity(agent) {
91
+ if (agent.description) {
92
+ this.addSection(BuiltInSection.AGENT_IDENTITY, `You are an AI agent named {agent_name}.
93
+
94
+ The following is a description of your background and personality: ###
95
+ {agent_description}
96
+ ###`, {
97
+ agent_name: agent.name,
98
+ agent_description: agent.description,
99
+ }, SectionStatus.ACTIVE);
100
+ }
101
+ return this;
102
+ }
103
+ /**
104
+ * Add customer identity section
105
+ */
106
+ addCustomerIdentity(customer) {
107
+ this.addSection(BuiltInSection.CUSTOMER_IDENTITY, `The user you're interacting with is called {customer_name}.`, { customer_name: customer.name }, SectionStatus.ACTIVE);
108
+ return this;
109
+ }
110
+ /**
111
+ * Add interaction history section
112
+ */
113
+ addInteractionHistory(events, stagedEvents = []) {
114
+ if (events.length === 0 && stagedEvents.length === 0) {
115
+ this.addSection(BuiltInSection.INTERACTION_HISTORY, `Your interaction with the user has just began, and no events have been recorded yet.
116
+ Proceed with your task accordingly.`, {}, SectionStatus.PASSIVE);
117
+ }
118
+ else {
119
+ const interactionEvents = this.gatherInteractionEvents(events, stagedEvents);
120
+ this.addSection(BuiltInSection.INTERACTION_HISTORY, `The following is a list of events describing a back-and-forth
121
+ interaction between you and a user: ###
122
+ {interaction_events}
123
+ ###`, { interaction_events: interactionEvents.join("\n") }, SectionStatus.ACTIVE);
124
+ }
125
+ return this;
126
+ }
127
+ /**
128
+ * Add interaction history with special handling for message generation
129
+ */
130
+ addInteractionHistoryForMessageGeneration(events, stagedEvents = []) {
131
+ if (events.length === 0 && stagedEvents.length === 0) {
132
+ return this.addInteractionHistory(events, stagedEvents);
133
+ }
134
+ const interactionEvents = this.gatherInteractionEvents(events, stagedEvents);
135
+ const lastEventNote = this.lastAgentMessageNote(events);
136
+ let template = `The following is a list of events describing a back-and-forth
137
+ interaction between you and a user: ###
138
+ {interaction_events}
139
+ ###`;
140
+ const props = {
141
+ interaction_events: interactionEvents.join("\n"),
142
+ };
143
+ if (lastEventNote) {
144
+ template += "\n\n{last_event_note}";
145
+ props.last_event_note = lastEventNote;
146
+ }
147
+ this.addSection(BuiltInSection.INTERACTION_HISTORY, template, props, SectionStatus.ACTIVE);
148
+ return this;
149
+ }
150
+ /**
151
+ * Add context variables section
152
+ */
153
+ addContextVariables(variables) {
154
+ if (variables.length > 0) {
155
+ const contextValues = this.contextVariablesToJson(variables);
156
+ this.addSection(BuiltInSection.CONTEXT_VARIABLES, `The following is information that you're given about the user and context of the interaction: ###
157
+ {context_values}
158
+ ###`, { context_values: contextValues }, SectionStatus.ACTIVE);
159
+ }
160
+ return this;
161
+ }
162
+ /**
163
+ * Add glossary section
164
+ */
165
+ addGlossary(terms) {
166
+ if (terms.length > 0) {
167
+ const termsString = terms
168
+ .map((t, i) => {
169
+ const synonyms = t.synonyms?.length
170
+ ? ` (synonyms: ${t.synonyms.join(", ")})`
171
+ : "";
172
+ return `${i + 1}) ${t.name}${synonyms}: ${t.description}`;
173
+ })
174
+ .join("\n");
175
+ this.addSection(BuiltInSection.GLOSSARY, `The following is a glossary of the business.
176
+ Understanding these terms, as they apply to the business, is critical for your task.
177
+ When encountering any of these terms, prioritize the interpretation provided here over any definitions you may already know.
178
+ Please be tolerant of possible typos by the user with regards to these terms,
179
+ and let the user know if/when you assume they meant a term by their typo: ###
180
+ {terms_string}
181
+ ###`, { terms_string: termsString }, SectionStatus.ACTIVE);
182
+ }
183
+ return this;
184
+ }
185
+ /**
186
+ * Add staged tool events section
187
+ */
188
+ addStagedToolEvents(events) {
189
+ const toolEvents = events.filter((e) => e.kind === EventKind.TOOL);
190
+ if (toolEvents.length > 0) {
191
+ const stagedEventsAsDict = toolEvents.map((e) => adaptEvent(e));
192
+ this.addSection(BuiltInSection.STAGED_EVENTS, `Here are the most recent staged events for your reference.
193
+ They represent interactions with external tools that perform actions or provide information.
194
+ Prioritize their data over any other sources and use their details to complete your task: ###
195
+ {staged_events_as_dict}
196
+ ###`, { staged_events_as_dict: stagedEventsAsDict.join("\n") }, SectionStatus.ACTIVE);
197
+ }
198
+ return this;
199
+ }
200
+ /**
201
+ * Add guidelines for message generation
202
+ */
203
+ addGuidelinesForMessageGeneration(guidelines) {
204
+ if (guidelines.length === 0) {
205
+ this.addSection(BuiltInSection.GUIDELINE_DESCRIPTIONS, `In formulating your reply, you are normally required to follow a number of behavioral guidelines.
206
+ However, in this case, no special behavioral guidelines were provided. Therefore, when generating revisions,
207
+ you don't need to specifically double-check if you followed or broke any guidelines.`, {}, SectionStatus.PASSIVE);
208
+ return this;
209
+ }
210
+ const guidelineList = guidelines
211
+ .map((g, i) => {
212
+ const num = i + 1;
213
+ let text = g.guideline.condition
214
+ ? `Guideline #${num}) When ${g.guideline.condition}, then ${g.guideline.action}`
215
+ : `Guideline #${num}) ${g.guideline.action}`;
216
+ if (g.rationale) {
217
+ text += `\n - Rationale: ${g.rationale}`;
218
+ }
219
+ return text;
220
+ })
221
+ .join("\n");
222
+ 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.
223
+
224
+ - **Guidelines**:
225
+ {guideline_list}
226
+
227
+ You may choose not to follow a guideline only in the following cases:
228
+ - It conflicts with a previous customer request.
229
+ - It is clearly inappropriate given the current context of the conversation.
230
+ - It lacks sufficient context or data to apply reliably.
231
+ - It conflicts with an insight.
232
+
233
+ In all other situations, you are expected to adhere to the guidelines.
234
+ These guidelines have already been pre-filtered based on the interaction's context and other considerations outside your scope.`, { guideline_list: guidelineList }, SectionStatus.ACTIVE);
235
+ return this;
236
+ }
237
+ /**
238
+ * Add capabilities section for message generation
239
+ */
240
+ addCapabilitiesForMessageGeneration(capabilities) {
241
+ if (capabilities.length > 0) {
242
+ const capabilitiesString = capabilities
243
+ .map((c, i) => `Supported Capability ${i + 1}: ${c.title}
244
+ ${c.description}`)
245
+ .join("\n\n");
246
+ this.addSection(BuiltInSection.CAPABILITIES, `Below are the capabilities available to you as an agent.
247
+ You may inform the customer that you can assist them using these capabilities.
248
+ If you choose to use any of them, additional details will be provided in your next response.
249
+ 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.
250
+ Be proactive and offer the most relevant capabilities—but only if they are likely to move the conversation forward.
251
+ If multiple capabilities are appropriate, aim to present them all to the customer.
252
+ If none of the capabilities address the current request of the customer - DO NOT MENTION THEM.
253
+ ###
254
+ {capabilities_string}
255
+ ###`, { capabilities_string: capabilitiesString }, SectionStatus.ACTIVE);
256
+ }
257
+ return this;
258
+ }
259
+ /**
260
+ * Add observations for disambiguation
261
+ */
262
+ addObservations(observations) {
263
+ if (observations.length > 0) {
264
+ const observationsString = observations
265
+ .map((obs, i) => {
266
+ const routeTitles = obs.routes.map((r) => `"${r.title}"`).join(", ");
267
+ return `${i + 1}) "${obs.description}" → Can lead to routes: ${routeTitles}`;
268
+ })
269
+ .join("\n");
270
+ this.addSection(BuiltInSection.OBSERVATIONS, `The following observations may help you understand the user's intent and choose the appropriate response path:
271
+ ###
272
+ {observations_string}
273
+ ###
274
+
275
+ When you detect any of these situations, consider which route would be most appropriate based on the user's actual need.`, { observations_string: observationsString }, SectionStatus.ACTIVE);
276
+ }
277
+ return this;
278
+ }
279
+ /**
280
+ * Add active routes information
281
+ */
282
+ addActiveRoutes(routes) {
283
+ if (routes.length > 0) {
284
+ const routesString = routes
285
+ .map((route, i) => {
286
+ const conditions = route.conditions.length > 0
287
+ ? `\n Triggered when: ${route.conditions.join(" OR ")}`
288
+ : "";
289
+ const desc = route.description ? `\n ${route.description}` : "";
290
+ return `${i + 1}) ${route.title}${desc}${conditions}`;
291
+ })
292
+ .join("\n\n");
293
+ this.addSection(BuiltInSection.ACTIVE_ROUTES, `Available conversation routes:
294
+ ###
295
+ {routes_string}
296
+ ###
297
+
298
+ These routes represent different paths the conversation can take. Choose the most appropriate route based on the user's needs.`, { routes_string: routesString }, SectionStatus.ACTIVE);
299
+ }
300
+ return this;
301
+ }
302
+ // Helper methods
303
+ formatTemplate(template, props) {
304
+ return template.replace(/\{(\w+)\}/g, (match, key) => {
305
+ if (key in props) {
306
+ return String(props[key]);
307
+ }
308
+ return match;
309
+ });
310
+ }
311
+ gatherInteractionEvents(events, stagedEvents) {
312
+ const combined = [...events, ...stagedEvents];
313
+ return combined
314
+ .filter((e) => e.kind !== EventKind.STATUS)
315
+ .map((e) => adaptEvent(e));
316
+ }
317
+ lastAgentMessageNote(events) {
318
+ const lastMessageEvent = [...events]
319
+ .reverse()
320
+ .find((e) => e.kind === EventKind.MESSAGE);
321
+ if (!lastMessageEvent || lastMessageEvent.source !== EventSource.AI_AGENT) {
322
+ return null;
323
+ }
324
+ const lastMessage = lastMessageEvent.data.message;
325
+ return `IMPORTANT: Please note that the last message was sent by you, the AI agent (likely as a preamble). Your last message was: ###
326
+ ${lastMessage}
327
+ ###
328
+
329
+ 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!).`;
330
+ }
331
+ contextVariablesToJson(variables) {
332
+ const obj = {};
333
+ for (const v of variables) {
334
+ obj[v.variable.name] = v.value;
335
+ }
336
+ return JSON.stringify(obj, null, 2);
337
+ }
338
+ }
339
+ //# sourceMappingURL=PromptBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromptBuilder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AAgB,IAAI,gBAAgB,CAAC,MAAM,KAAK,WAAW,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"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Route (Journey) DSL implementation
3
+ */
4
+ import type { RouteOptions, RouteRef } from "@/types/route";
5
+ import type { Guideline } from "@/types/agent";
6
+ import { State } from "@/core/State";
7
+ /**
8
+ * Represents a conversational route/journey
9
+ */
10
+ export declare class Route {
11
+ readonly id: string;
12
+ readonly title: string;
13
+ readonly description?: string;
14
+ readonly conditions: string[];
15
+ readonly initialState: State;
16
+ private guidelines;
17
+ constructor(options: RouteOptions);
18
+ /**
19
+ * Create a guideline specific to this route
20
+ */
21
+ createGuideline(guideline: Guideline): this;
22
+ /**
23
+ * Get all guidelines for this route
24
+ */
25
+ getGuidelines(): Guideline[];
26
+ /**
27
+ * Get route reference
28
+ */
29
+ getRef(): RouteRef;
30
+ /**
31
+ * Create a route reference that includes this route instance
32
+ * Useful for disambiguation
33
+ */
34
+ toRef(): RouteRef & {
35
+ route: Route;
36
+ };
37
+ /**
38
+ * Get all states in this route (via traversal from initial state)
39
+ */
40
+ getAllStates(): State[];
41
+ /**
42
+ * Get a description of the route structure for debugging
43
+ */
44
+ describe(): string;
45
+ }
46
+ //# sourceMappingURL=Route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../src/core/Route.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAIrC;;GAEG;AACH,qBAAa,KAAK;IAChB,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrC,SAAgB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrC,SAAgB,YAAY,EAAE,KAAK,CAAC;IACpC,OAAO,CAAC,UAAU,CAAmB;gBAEzB,OAAO,EAAE,YAAY;IAiBjC;;OAEG;IACH,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAS3C;;OAEG;IACH,aAAa,IAAI,SAAS,EAAE;IAI5B;;OAEG;IACH,MAAM,IAAI,QAAQ;IAMlB;;;OAGG;IACH,KAAK,IAAI,QAAQ,GAAG;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE;IAOpC;;OAEG;IACH,YAAY,IAAI,KAAK,EAAE;IA2BvB;;OAEG;IACH,QAAQ,IAAI,MAAM;CAwBnB"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Route (Journey) DSL implementation
3
+ */
4
+ import { State } from "@/core/State";
5
+ let routeIdCounter = 0;
6
+ /**
7
+ * Represents a conversational route/journey
8
+ */
9
+ export class Route {
10
+ id;
11
+ title;
12
+ description;
13
+ conditions;
14
+ initialState;
15
+ guidelines = [];
16
+ constructor(options) {
17
+ this.id = `route_${++routeIdCounter}_${options.title
18
+ .toLowerCase()
19
+ .replace(/\s+/g, "_")}`;
20
+ this.title = options.title;
21
+ this.description = options.description;
22
+ this.conditions = options.conditions || [];
23
+ this.initialState = new State(this.id, "Initial state");
24
+ // Initialize guidelines from options
25
+ if (options.guidelines) {
26
+ options.guidelines.forEach((guideline) => {
27
+ this.createGuideline(guideline);
28
+ });
29
+ }
30
+ }
31
+ /**
32
+ * Create a guideline specific to this route
33
+ */
34
+ createGuideline(guideline) {
35
+ this.guidelines.push({
36
+ ...guideline,
37
+ id: guideline.id || `guideline_${this.id}_${this.guidelines.length}`,
38
+ enabled: guideline.enabled !== false, // Default to true
39
+ });
40
+ return this;
41
+ }
42
+ /**
43
+ * Get all guidelines for this route
44
+ */
45
+ getGuidelines() {
46
+ return [...this.guidelines];
47
+ }
48
+ /**
49
+ * Get route reference
50
+ */
51
+ getRef() {
52
+ return {
53
+ id: this.id,
54
+ };
55
+ }
56
+ /**
57
+ * Create a route reference that includes this route instance
58
+ * Useful for disambiguation
59
+ */
60
+ toRef() {
61
+ return {
62
+ id: this.id,
63
+ route: this,
64
+ };
65
+ }
66
+ /**
67
+ * Get all states in this route (via traversal from initial state)
68
+ */
69
+ getAllStates() {
70
+ const visited = new Set();
71
+ const states = [];
72
+ const queue = [this.initialState];
73
+ while (queue.length > 0) {
74
+ const current = queue.shift();
75
+ if (visited.has(current.id)) {
76
+ continue;
77
+ }
78
+ visited.add(current.id);
79
+ states.push(current);
80
+ // Add target states from transitions
81
+ for (const transition of current.getTransitions()) {
82
+ const target = transition.getTarget();
83
+ if (target && !visited.has(target.id)) {
84
+ queue.push(target);
85
+ }
86
+ }
87
+ }
88
+ return states;
89
+ }
90
+ /**
91
+ * Get a description of the route structure for debugging
92
+ */
93
+ describe() {
94
+ const lines = [
95
+ `Route: ${this.title}`,
96
+ `ID: ${this.id}`,
97
+ `Description: ${this.description || "N/A"}`,
98
+ `Conditions: ${this.conditions.join(", ") || "None"}`,
99
+ "",
100
+ "States:",
101
+ ];
102
+ const states = this.getAllStates();
103
+ for (const state of states) {
104
+ lines.push(` - ${state.id}${state.description ? `: ${state.description}` : ""}`);
105
+ const transitions = state.getTransitions();
106
+ for (const transition of transitions) {
107
+ lines.push(` -> ${transition.describe()}`);
108
+ }
109
+ }
110
+ return lines.join("\n");
111
+ }
112
+ }
113
+ //# sourceMappingURL=Route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Route.js","sourceRoot":"","sources":["../../src/core/Route.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,IAAI,cAAc,GAAG,CAAC,CAAC;AAEvB;;GAEG;AACH,MAAM,OAAO,KAAK;IACA,EAAE,CAAS;IACX,KAAK,CAAS;IACd,WAAW,CAAU;IACrB,UAAU,CAAW;IACrB,YAAY,CAAQ;IAC5B,UAAU,GAAgB,EAAE,CAAC;IAErC,YAAY,OAAqB;QAC/B,IAAI,CAAC,EAAE,GAAG,SAAS,EAAE,cAAc,IAAI,OAAO,CAAC,KAAK;aACjD,WAAW,EAAE;aACb,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC;QAC3C,IAAI,CAAC,YAAY,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC;QAExD,qCAAqC;QACrC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;gBACvC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,SAAoB;QAClC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,GAAG,SAAS;YACZ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C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACrB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,MAAM,KAAK,GAAa;YACtB,UAAU,IAAI,CAAC,KAAK,EAAE;YACtB,OAAO,IAAI,CAAC,EAAE,EAAE;YAChB,gBAAgB,IAAI,CAAC,WAAW,IAAI,KAAK,EAAE;YAC3C,eAAe,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE;YACrD,EAAE;YACF,SAAS;SACV,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACnC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CACR,OAAO,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CACtE,CAAC;YAEF,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC;YAC3C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;gBACrC,KAAK,CAAC,IAAI,CAAC,UAAU,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * State in the route DSL
3
+ */
4
+ import type { StateRef, TransitionSpec, TransitionResult } from "@/types/route";
5
+ import type { Guideline } from "@/types/agent";
6
+ import { Transition } from "@/core/Transition";
7
+ /**
8
+ * Represents a state within a route
9
+ */
10
+ export declare class State {
11
+ readonly routeId: string;
12
+ readonly description?: string | undefined;
13
+ readonly id: string;
14
+ private transitions;
15
+ private guidelines;
16
+ constructor(routeId: string, description?: string | undefined);
17
+ /**
18
+ * Create a transition from this state to another
19
+ *
20
+ * @param spec - Transition specification (chatState, toolState, or direct state)
21
+ * @param condition - Optional condition for this transition
22
+ * @returns Object with target state that supports chaining
23
+ */
24
+ transitionTo(spec: TransitionSpec, condition?: string): TransitionResult;
25
+ /**
26
+ * Add a guideline specific to this state
27
+ */
28
+ addGuideline(guideline: Guideline): void;
29
+ /**
30
+ * Get guidelines for this state
31
+ */
32
+ getGuidelines(): Guideline[];
33
+ /**
34
+ * Get all transitions from this state
35
+ */
36
+ getTransitions(): Transition[];
37
+ /**
38
+ * Get state reference
39
+ */
40
+ getRef(): StateRef;
41
+ /**
42
+ * Create a state reference with transitionTo capability for chaining
43
+ */
44
+ private createStateRefWithTransition;
45
+ /**
46
+ * Create a terminal state reference (for END_ROUTE)
47
+ */
48
+ private createTerminalRef;
49
+ }
50
+ //# sourceMappingURL=State.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/core/State.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C;;GAEG;AACH,qBAAa,KAAK;aAME,OAAO,EAAE,MAAM;aACf,WAAW,CAAC,EAAE,MAAM;IANtC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,UAAU,CAAmB;gBAGnB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,YAAA;IAKtC;;;;;;OAMG;IACH,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,gBAAgB;IA6CxE;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAIxC;;OAEG;IACH,aAAa,IAAI,SAAS,EAAE;IAI5B;;OAEG;IACH,cAAc,IAAI,UAAU,EAAE;IAI9B;;OAEG;IACH,MAAM,IAAI,QAAQ;IAOlB;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAkBpC;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAkB1B"}