@ariaflowagents/core 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 (134) hide show
  1. package/README.md +39 -0
  2. package/dist/agents/Agent.d.ts +15 -0
  3. package/dist/agents/Agent.d.ts.map +1 -0
  4. package/dist/agents/Agent.js +33 -0
  5. package/dist/agents/Agent.js.map +1 -0
  6. package/dist/agents/CompositeAgent.d.ts +24 -0
  7. package/dist/agents/CompositeAgent.d.ts.map +1 -0
  8. package/dist/agents/CompositeAgent.js +59 -0
  9. package/dist/agents/CompositeAgent.js.map +1 -0
  10. package/dist/agents/FlowAgent.d.ts +11 -0
  11. package/dist/agents/FlowAgent.d.ts.map +1 -0
  12. package/dist/agents/FlowAgent.js +44 -0
  13. package/dist/agents/FlowAgent.js.map +1 -0
  14. package/dist/agents/LLMAgent.d.ts +11 -0
  15. package/dist/agents/LLMAgent.d.ts.map +1 -0
  16. package/dist/agents/LLMAgent.js +52 -0
  17. package/dist/agents/LLMAgent.js.map +1 -0
  18. package/dist/agents/TriageAgent.d.ts +11 -0
  19. package/dist/agents/TriageAgent.d.ts.map +1 -0
  20. package/dist/agents/TriageAgent.js +89 -0
  21. package/dist/agents/TriageAgent.js.map +1 -0
  22. package/dist/agents/index.d.ts +7 -0
  23. package/dist/agents/index.d.ts.map +1 -0
  24. package/dist/agents/index.js +6 -0
  25. package/dist/agents/index.js.map +1 -0
  26. package/dist/flows/AgentFlowManager.d.ts +154 -0
  27. package/dist/flows/AgentFlowManager.d.ts.map +1 -0
  28. package/dist/flows/AgentFlowManager.js +272 -0
  29. package/dist/flows/AgentFlowManager.js.map +1 -0
  30. package/dist/flows/FlowGraph.d.ts +23 -0
  31. package/dist/flows/FlowGraph.d.ts.map +1 -0
  32. package/dist/flows/FlowGraph.js +57 -0
  33. package/dist/flows/FlowGraph.js.map +1 -0
  34. package/dist/flows/FlowManager.d.ts +36 -0
  35. package/dist/flows/FlowManager.d.ts.map +1 -0
  36. package/dist/flows/FlowManager.js +256 -0
  37. package/dist/flows/FlowManager.js.map +1 -0
  38. package/dist/flows/FlowNode.d.ts +8 -0
  39. package/dist/flows/FlowNode.d.ts.map +1 -0
  40. package/dist/flows/FlowNode.js +12 -0
  41. package/dist/flows/FlowNode.js.map +1 -0
  42. package/dist/flows/index.d.ts +8 -0
  43. package/dist/flows/index.d.ts.map +1 -0
  44. package/dist/flows/index.js +6 -0
  45. package/dist/flows/index.js.map +1 -0
  46. package/dist/flows/transitions.d.ts +9 -0
  47. package/dist/flows/transitions.d.ts.map +1 -0
  48. package/dist/flows/transitions.js +15 -0
  49. package/dist/flows/transitions.js.map +1 -0
  50. package/dist/guards/StopConditions.d.ts +14 -0
  51. package/dist/guards/StopConditions.d.ts.map +1 -0
  52. package/dist/guards/StopConditions.js +161 -0
  53. package/dist/guards/StopConditions.js.map +1 -0
  54. package/dist/guards/ToolEnforcer.d.ts +11 -0
  55. package/dist/guards/ToolEnforcer.d.ts.map +1 -0
  56. package/dist/guards/ToolEnforcer.js +40 -0
  57. package/dist/guards/ToolEnforcer.js.map +1 -0
  58. package/dist/guards/index.d.ts +4 -0
  59. package/dist/guards/index.d.ts.map +1 -0
  60. package/dist/guards/index.js +4 -0
  61. package/dist/guards/index.js.map +1 -0
  62. package/dist/guards/rules.d.ts +8 -0
  63. package/dist/guards/rules.d.ts.map +1 -0
  64. package/dist/guards/rules.js +128 -0
  65. package/dist/guards/rules.js.map +1 -0
  66. package/dist/hooks/HookRunner.d.ts +30 -0
  67. package/dist/hooks/HookRunner.d.ts.map +1 -0
  68. package/dist/hooks/HookRunner.js +85 -0
  69. package/dist/hooks/HookRunner.js.map +1 -0
  70. package/dist/hooks/builtin/logging.d.ts +6 -0
  71. package/dist/hooks/builtin/logging.d.ts.map +1 -0
  72. package/dist/hooks/builtin/logging.js +99 -0
  73. package/dist/hooks/builtin/logging.js.map +1 -0
  74. package/dist/hooks/builtin/metrics.d.ts +38 -0
  75. package/dist/hooks/builtin/metrics.d.ts.map +1 -0
  76. package/dist/hooks/builtin/metrics.js +111 -0
  77. package/dist/hooks/builtin/metrics.js.map +1 -0
  78. package/dist/hooks/index.d.ts +5 -0
  79. package/dist/hooks/index.d.ts.map +1 -0
  80. package/dist/hooks/index.js +4 -0
  81. package/dist/hooks/index.js.map +1 -0
  82. package/dist/index.d.ts +30 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +23 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/runtime/InjectionQueue.d.ts +46 -0
  87. package/dist/runtime/InjectionQueue.d.ts.map +1 -0
  88. package/dist/runtime/InjectionQueue.js +128 -0
  89. package/dist/runtime/InjectionQueue.js.map +1 -0
  90. package/dist/runtime/Runtime.d.ts +24 -0
  91. package/dist/runtime/Runtime.d.ts.map +1 -0
  92. package/dist/runtime/Runtime.js +277 -0
  93. package/dist/runtime/Runtime.js.map +1 -0
  94. package/dist/runtime/WorkingMemory.d.ts +12 -0
  95. package/dist/runtime/WorkingMemory.d.ts.map +1 -0
  96. package/dist/runtime/WorkingMemory.js +29 -0
  97. package/dist/runtime/WorkingMemory.js.map +1 -0
  98. package/dist/runtime/index.d.ts +4 -0
  99. package/dist/runtime/index.d.ts.map +1 -0
  100. package/dist/runtime/index.js +4 -0
  101. package/dist/runtime/index.js.map +1 -0
  102. package/dist/session/SessionManager.d.ts +20 -0
  103. package/dist/session/SessionManager.d.ts.map +1 -0
  104. package/dist/session/SessionManager.js +134 -0
  105. package/dist/session/SessionManager.js.map +1 -0
  106. package/dist/session/SessionStore.d.ts +9 -0
  107. package/dist/session/SessionStore.d.ts.map +1 -0
  108. package/dist/session/SessionStore.js +2 -0
  109. package/dist/session/SessionStore.js.map +1 -0
  110. package/dist/session/index.d.ts +4 -0
  111. package/dist/session/index.d.ts.map +1 -0
  112. package/dist/session/index.js +3 -0
  113. package/dist/session/index.js.map +1 -0
  114. package/dist/session/stores/MemoryStore.d.ts +11 -0
  115. package/dist/session/stores/MemoryStore.d.ts.map +1 -0
  116. package/dist/session/stores/MemoryStore.js +34 -0
  117. package/dist/session/stores/MemoryStore.js.map +1 -0
  118. package/dist/tools/Tool.d.ts +10 -0
  119. package/dist/tools/Tool.d.ts.map +1 -0
  120. package/dist/tools/Tool.js +2 -0
  121. package/dist/tools/Tool.js.map +1 -0
  122. package/dist/tools/handoff.d.ts +25 -0
  123. package/dist/tools/handoff.d.ts.map +1 -0
  124. package/dist/tools/handoff.js +51 -0
  125. package/dist/tools/handoff.js.map +1 -0
  126. package/dist/tools/index.d.ts +4 -0
  127. package/dist/tools/index.d.ts.map +1 -0
  128. package/dist/tools/index.js +2 -0
  129. package/dist/tools/index.js.map +1 -0
  130. package/dist/types/index.d.ts +325 -0
  131. package/dist/types/index.d.ts.map +1 -0
  132. package/dist/types/index.js +2 -0
  133. package/dist/types/index.js.map +1 -0
  134. package/package.json +71 -0
@@ -0,0 +1,272 @@
1
+ import { streamText, generateText } from 'ai';
2
+ import { createFlowTransition, isFlowTransition } from './transitions.js';
3
+ export var ContextStrategy;
4
+ (function (ContextStrategy) {
5
+ ContextStrategy["APPEND"] = "append";
6
+ ContextStrategy["RESET"] = "reset";
7
+ ContextStrategy["RESET_WITH_SUMMARY"] = "reset_with_summary";
8
+ })(ContextStrategy || (ContextStrategy = {}));
9
+ export function createCollectorTool(description, schema, nextNode) {
10
+ return {
11
+ description,
12
+ parameters: schema,
13
+ execute: async (data) => {
14
+ return createFlowTransition(nextNode, data);
15
+ },
16
+ };
17
+ }
18
+ export class AgentFlowManager {
19
+ nodes = new Map();
20
+ currentNode = null;
21
+ context;
22
+ config;
23
+ initialized = false;
24
+ constructor(config, sessionId, userId) {
25
+ this.config = config;
26
+ for (const node of config.nodes) {
27
+ this.nodes.set(node.name, node);
28
+ }
29
+ this.context = {
30
+ state: {},
31
+ currentNode: config.initialNode,
32
+ messages: [],
33
+ collectedData: {},
34
+ nodeHistory: [],
35
+ nodeTurnCounts: {},
36
+ sessionId,
37
+ userId,
38
+ ended: false,
39
+ };
40
+ }
41
+ async initialize() {
42
+ const parts = [];
43
+ await this.config.hooks?.onFlowStart?.(this.context);
44
+ const transitionParts = await this.transitionTo(this.config.initialNode);
45
+ parts.push(...transitionParts);
46
+ this.initialized = true;
47
+ if (this.currentNode?.autoRespond !== false) {
48
+ const responseParts = [];
49
+ for await (const part of this.generateNodeResponse()) {
50
+ responseParts.push(part);
51
+ }
52
+ parts.push(...responseParts);
53
+ }
54
+ return parts;
55
+ }
56
+ async *process(userInput) {
57
+ if (!this.initialized) {
58
+ throw new Error('Flow not initialized. Call initialize() first.');
59
+ }
60
+ if (this.context.ended) {
61
+ yield { type: 'error', error: 'Flow has ended' };
62
+ return;
63
+ }
64
+ if (!this.currentNode) {
65
+ yield { type: 'error', error: 'No current node' };
66
+ return;
67
+ }
68
+ try {
69
+ this.context.messages.push({ role: 'user', content: userInput });
70
+ const nodeName = this.currentNode.name;
71
+ this.context.nodeTurnCounts[nodeName] = (this.context.nodeTurnCounts[nodeName] ?? 0) + 1;
72
+ if (this.currentNode.maxTurns && this.context.nodeTurnCounts[nodeName] > this.currentNode.maxTurns) {
73
+ yield { type: 'error', error: `Max turns exceeded for node "${nodeName}"` };
74
+ return;
75
+ }
76
+ yield* this.runInference();
77
+ yield { type: 'done' };
78
+ }
79
+ catch (error) {
80
+ await this.config.hooks?.onError?.(this.context, error);
81
+ yield { type: 'error', error: error.message };
82
+ }
83
+ }
84
+ async forceTransition(nodeName, data) {
85
+ return this.transitionTo(nodeName, data);
86
+ }
87
+ async endFlow(reason = 'completed') {
88
+ if (this.context.ended) {
89
+ return;
90
+ }
91
+ this.context.ended = true;
92
+ this.context.endReason = reason;
93
+ if (this.currentNode?.postActions) {
94
+ await this.runActions(this.currentNode.postActions);
95
+ }
96
+ await this.config.hooks?.onFlowEnd?.(this.context, reason);
97
+ }
98
+ get state() { return this.context.state; }
99
+ get collectedData() { return this.context.collectedData; }
100
+ get currentNodeName() { return this.context.currentNode; }
101
+ get nodeHistory() { return this.context.nodeHistory; }
102
+ get hasEnded() { return this.context.ended; }
103
+ get fullContext() { return { ...this.context }; }
104
+ async transitionTo(nodeName, data) {
105
+ const parts = [];
106
+ const node = this.nodes.get(nodeName);
107
+ if (!node) {
108
+ throw new Error(`Node "${nodeName}" not found`);
109
+ }
110
+ const previousNode = this.currentNode;
111
+ const previousNodeName = previousNode?.name;
112
+ if (previousNode) {
113
+ await this.runActions(previousNode.postActions ?? []);
114
+ await this.config.hooks?.onNodeExit?.(this.context, previousNode);
115
+ parts.push({ type: 'node-exit', nodeName: previousNode.name });
116
+ }
117
+ this.currentNode = node;
118
+ this.context.currentNode = nodeName;
119
+ this.context.nodeHistory.push(nodeName);
120
+ if (data) {
121
+ Object.assign(this.context.collectedData, data);
122
+ }
123
+ await this.applyContextStrategy(node);
124
+ await this.config.hooks?.onNodeEnter?.(this.context, node);
125
+ parts.push({ type: 'node-enter', nodeName: node.name });
126
+ await this.runActions(node.preActions ?? []);
127
+ if (previousNodeName) {
128
+ await this.config.hooks?.onTransition?.(this.context, previousNodeName, nodeName, data);
129
+ parts.push({ type: 'transition', from: previousNodeName, to: nodeName, data });
130
+ }
131
+ return parts;
132
+ }
133
+ async *generateNodeResponse() {
134
+ if (!this.currentNode)
135
+ return;
136
+ yield* this.runInference();
137
+ }
138
+ async *runInference() {
139
+ if (!this.currentNode)
140
+ return;
141
+ const node = this.currentNode;
142
+ const systemPrompt = this.buildSystemPrompt(node);
143
+ const tools = {
144
+ ...this.config.globalTools,
145
+ ...node.tools,
146
+ };
147
+ await this.config.hooks?.onBeforeInference?.(this.context, node);
148
+ const streamConfig = {
149
+ model: this.config.model,
150
+ system: systemPrompt,
151
+ tools,
152
+ };
153
+ if (this.context.messages.length === 0) {
154
+ streamConfig.prompt = 'Generate the greeting for this conversation.';
155
+ }
156
+ else {
157
+ streamConfig.messages = this.context.messages;
158
+ }
159
+ const result = streamText(streamConfig);
160
+ let responseText = '';
161
+ let pendingTransition = null;
162
+ for await (const chunk of result.fullStream) {
163
+ if (chunk.type === 'text-delta') {
164
+ responseText += chunk.text;
165
+ yield { type: 'text-delta', text: chunk.text };
166
+ }
167
+ if (chunk.type === 'tool-call') {
168
+ const args = 'args' in chunk ? chunk.args : chunk.input;
169
+ yield { type: 'tool-call', toolName: chunk.toolName, args };
170
+ }
171
+ if (chunk.type === 'tool-result') {
172
+ const toolResult = 'result' in chunk ? chunk.result : chunk.output;
173
+ if (isFlowTransition(toolResult)) {
174
+ pendingTransition = toolResult;
175
+ }
176
+ yield { type: 'tool-result', toolName: chunk.toolName, result: toolResult };
177
+ }
178
+ }
179
+ const response = await result.response;
180
+ this.context.messages.push(...response.messages);
181
+ await this.config.hooks?.onAfterInference?.(this.context, node, responseText);
182
+ if (pendingTransition) {
183
+ const transitionParts = await this.transitionTo(pendingTransition.targetNode, pendingTransition.data);
184
+ for (const part of transitionParts) {
185
+ yield part;
186
+ }
187
+ if (this.currentNode && this.currentNode.autoRespond !== false) {
188
+ yield* this.generateNodeResponse();
189
+ }
190
+ }
191
+ if (node.postActions?.some(action => action.type === 'end')) {
192
+ await this.endFlow('post-action');
193
+ yield { type: 'flow-end', reason: 'post-action' };
194
+ }
195
+ }
196
+ buildSystemPrompt(node) {
197
+ const rolePrompt = node.rolePrompt ?? this.config.defaultRolePrompt ?? '';
198
+ const dataKeys = Object.keys(this.context.collectedData);
199
+ const stateContext = dataKeys.length > 0
200
+ ? `\n\n## Collected Information\n${JSON.stringify(this.context.collectedData, null, 2)}`
201
+ : '';
202
+ const historyContext = this.context.nodeHistory.length > 1
203
+ ? `\n\n## Progress\n${this.context.nodeHistory.slice(0, -1).join(' -> ')} -> **${node.name}**`
204
+ : '';
205
+ return `${rolePrompt}\n\n## Current Task\n${node.taskPrompt}${stateContext}${historyContext}\n\n## Instructions\n- Focus ONLY on the current task\n- Use the available tools to progress the conversation\n- Do not attempt tasks outside your current scope`;
206
+ }
207
+ async applyContextStrategy(node) {
208
+ const strategyConfig = node.contextStrategy
209
+ ?? this.config.defaultContextStrategy
210
+ ?? { strategy: ContextStrategy.APPEND };
211
+ switch (strategyConfig.strategy) {
212
+ case ContextStrategy.RESET:
213
+ this.context.messages = [];
214
+ break;
215
+ case ContextStrategy.RESET_WITH_SUMMARY:
216
+ if (this.context.messages.length > 0) {
217
+ const summary = await this.generateSummary(strategyConfig);
218
+ this.context.messages = [
219
+ { role: 'system', content: `Previous conversation summary: ${summary}` },
220
+ ];
221
+ }
222
+ break;
223
+ case ContextStrategy.APPEND:
224
+ default:
225
+ break;
226
+ }
227
+ }
228
+ async generateSummary(config) {
229
+ const prompt = config.summaryPrompt
230
+ ?? 'Summarize the key points from this conversation in 2-3 sentences.';
231
+ const result = await generateText({
232
+ model: this.config.model,
233
+ system: prompt,
234
+ messages: this.context.messages,
235
+ });
236
+ return result.text;
237
+ }
238
+ async runActions(actions) {
239
+ for (const action of actions) {
240
+ switch (action.type) {
241
+ case 'say':
242
+ console.log(`[FLOW SAY] ${action.text}`);
243
+ break;
244
+ case 'end':
245
+ await this.endFlow(action.message ?? 'action-triggered');
246
+ break;
247
+ case 'function':
248
+ await action.handler(this.context);
249
+ break;
250
+ case 'delay':
251
+ await new Promise(resolve => setTimeout(resolve, action.ms));
252
+ break;
253
+ case 'emit':
254
+ console.log(`[FLOW EVENT] ${action.event}`, action.data);
255
+ break;
256
+ default:
257
+ break;
258
+ }
259
+ }
260
+ }
261
+ static create(config, sessionId, userId) {
262
+ return new AgentFlowManager(config, sessionId, userId);
263
+ }
264
+ static restore(config, savedContext) {
265
+ const manager = new AgentFlowManager(config, savedContext.sessionId, savedContext.userId);
266
+ manager.context = { ...savedContext };
267
+ manager.currentNode = manager.nodes.get(savedContext.currentNode) ?? null;
268
+ manager.initialized = true;
269
+ return manager;
270
+ }
271
+ }
272
+ //# sourceMappingURL=AgentFlowManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentFlowManager.js","sourceRoot":"","sources":["../../src/flows/AgentFlowManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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 +1,23 @@
1
+ import type { ContextStrategy, FlowConfig, FlowNodeConfig, FlowTransitionConfig } from '../types/index.js';
2
+ import { FlowNode } from './FlowNode.js';
3
+ export declare class FlowGraph {
4
+ private nodes;
5
+ private transitions;
6
+ private defaultRolePrompt?;
7
+ private contextStrategy?;
8
+ addNode(node: FlowNode): this;
9
+ addTransition(from: string, to: string, config?: Omit<FlowTransitionConfig, 'from' | 'to'>): this;
10
+ setDefaultRolePrompt(prompt: string): this;
11
+ setContextStrategy(strategy: ContextStrategy): this;
12
+ toConfig(): FlowConfig;
13
+ static create(): FlowGraphBuilder;
14
+ }
15
+ export declare class FlowGraphBuilder {
16
+ private graph;
17
+ node(id: string, config: Omit<FlowNodeConfig, 'id'>): this;
18
+ transition(from: string, to: string, config?: Omit<FlowTransitionConfig, 'from' | 'to'>): this;
19
+ defaultRolePrompt(prompt: string): this;
20
+ contextStrategy(strategy: ContextStrategy): this;
21
+ build(): FlowConfig;
22
+ }
23
+ //# sourceMappingURL=FlowGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FlowGraph.d.ts","sourceRoot":"","sources":["../../src/flows/FlowGraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC3G,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAA+B;IAC5C,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,iBAAiB,CAAC,CAAS;IACnC,OAAO,CAAC,eAAe,CAAC,CAAkB;IAE1C,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAK7B,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,GAAE,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAM,GAAG,IAAI;IAKrG,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK1C,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAKnD,QAAQ,IAAI,UAAU;IAStB,MAAM,CAAC,MAAM,IAAI,gBAAgB;CAGlC;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,KAAK,CAAmB;IAEhC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,IAAI;IAK1D,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,GAAE,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAM,GAAG,IAAI;IAKlG,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKvC,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAKhD,KAAK,IAAI,UAAU;CAGpB"}
@@ -0,0 +1,57 @@
1
+ import { FlowNode } from './FlowNode.js';
2
+ export class FlowGraph {
3
+ nodes = new Map();
4
+ transitions = [];
5
+ defaultRolePrompt;
6
+ contextStrategy;
7
+ addNode(node) {
8
+ this.nodes.set(node.id, node);
9
+ return this;
10
+ }
11
+ addTransition(from, to, config = {}) {
12
+ this.transitions.push({ from, to, ...config });
13
+ return this;
14
+ }
15
+ setDefaultRolePrompt(prompt) {
16
+ this.defaultRolePrompt = prompt;
17
+ return this;
18
+ }
19
+ setContextStrategy(strategy) {
20
+ this.contextStrategy = strategy;
21
+ return this;
22
+ }
23
+ toConfig() {
24
+ return {
25
+ nodes: Array.from(this.nodes.values()).map(node => node.toConfig()),
26
+ transitions: this.transitions,
27
+ defaultRolePrompt: this.defaultRolePrompt,
28
+ contextStrategy: this.contextStrategy,
29
+ };
30
+ }
31
+ static create() {
32
+ return new FlowGraphBuilder();
33
+ }
34
+ }
35
+ export class FlowGraphBuilder {
36
+ graph = new FlowGraph();
37
+ node(id, config) {
38
+ this.graph.addNode(new FlowNode({ id, ...config }));
39
+ return this;
40
+ }
41
+ transition(from, to, config = {}) {
42
+ this.graph.addTransition(from, to, config);
43
+ return this;
44
+ }
45
+ defaultRolePrompt(prompt) {
46
+ this.graph.setDefaultRolePrompt(prompt);
47
+ return this;
48
+ }
49
+ contextStrategy(strategy) {
50
+ this.graph.setContextStrategy(strategy);
51
+ return this;
52
+ }
53
+ build() {
54
+ return this.graph.toConfig();
55
+ }
56
+ }
57
+ //# sourceMappingURL=FlowGraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FlowGraph.js","sourceRoot":"","sources":["../../src/flows/FlowGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,OAAO,SAAS;IACZ,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IACpC,WAAW,GAA2B,EAAE,CAAC;IACzC,iBAAiB,CAAU;IAC3B,eAAe,CAAmB;IAE1C,OAAO,CAAC,IAAc;QACpB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CAAC,IAAY,EAAE,EAAU,EAAE,SAAoD,EAAE;QAC5F,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oBAAoB,CAAC,MAAc;QACjC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kBAAkB,CAAC,QAAyB;QAC1C,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnE,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,eAAe,EAAE,IAAI,CAAC,eAAe;SACtC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,gBAAgB,EAAE,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,gBAAgB;IACnB,KAAK,GAAG,IAAI,SAAS,EAAE,CAAC;IAEhC,IAAI,CAAC,EAAU,EAAE,MAAkC;QACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU,CAAC,IAAY,EAAE,EAAU,EAAE,SAAoD,EAAE;QACzF,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,MAAc;QAC9B,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,eAAe,CAAC,QAAyB;QACvC,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ import { type LanguageModel, type ModelMessage } from 'ai';
2
+ import type { AgentStreamPart, FlowConfig } from '../types/index.js';
3
+ export interface FlowManagerConfig {
4
+ flow: FlowConfig;
5
+ initialNode: string;
6
+ model: LanguageModel;
7
+ defaultRolePrompt?: string;
8
+ contextMessages?: ModelMessage[];
9
+ sessionMessages?: ModelMessage[];
10
+ }
11
+ export declare class FlowManager {
12
+ private config;
13
+ private nodes;
14
+ private transitions;
15
+ private context;
16
+ private currentNodeConfig;
17
+ private initialized;
18
+ private pendingEvents;
19
+ private flowEnded;
20
+ private sessionMessages?;
21
+ constructor(config: FlowManagerConfig);
22
+ initialize(): AsyncGenerator<AgentStreamPart>;
23
+ process(userInput: string): AsyncGenerator<AgentStreamPart>;
24
+ transitionTo(nodeId: string, data?: Record<string, unknown>): Promise<void>;
25
+ transitionToGenerator(nodeId: string, data?: Record<string, unknown>): AsyncGenerator<AgentStreamPart>;
26
+ get collectedData(): Record<string, unknown>;
27
+ get currentNode(): string | undefined;
28
+ private runInference;
29
+ private buildSystemPrompt;
30
+ private applyContextStrategy;
31
+ private generateSummary;
32
+ private appendMessage;
33
+ private runActions;
34
+ private evaluateTransitions;
35
+ }
36
+ //# sourceMappingURL=FlowManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FlowManager.d.ts","sourceRoot":"","sources":["../../src/flows/FlowManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,aAAa,EAAE,KAAK,YAAY,EAAgB,MAAM,IAAI,CAAC;AACnG,OAAO,KAAK,EACV,eAAe,EAGf,UAAU,EAIX,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,aAAa,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,YAAY,EAAE,CAAC;IACjC,eAAe,CAAC,EAAE,YAAY,EAAE,CAAC;CAClC;AAID,qBAAa,WAAW;IAUV,OAAO,CAAC,MAAM;IAT1B,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,WAA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