@ariaflowagents/core 0.6.3 → 0.7.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.
- package/README.md +58 -5
- package/dist/agents/Agent.d.ts +1 -0
- package/dist/agents/Agent.d.ts.map +1 -1
- package/dist/agents/Agent.js +10 -1
- package/dist/agents/Agent.js.map +1 -1
- package/dist/agents/CompositeAgent.d.ts +8 -12
- package/dist/agents/CompositeAgent.d.ts.map +1 -1
- package/dist/agents/CompositeAgent.js +30 -16
- package/dist/agents/CompositeAgent.js.map +1 -1
- package/dist/agents/FlowAgent.js +2 -2
- package/dist/agents/FlowAgent.js.map +1 -1
- package/dist/agents/LLMAgent.d.ts.map +1 -1
- package/dist/agents/LLMAgent.js +4 -25
- package/dist/agents/LLMAgent.js.map +1 -1
- package/dist/agents/TriageAgent.d.ts.map +1 -1
- package/dist/agents/TriageAgent.js +8 -29
- package/dist/agents/TriageAgent.js.map +1 -1
- package/dist/callbacks/httpCallback.d.ts +1 -0
- package/dist/callbacks/httpCallback.d.ts.map +1 -1
- package/dist/callbacks/httpCallback.js +20 -6
- package/dist/callbacks/httpCallback.js.map +1 -1
- package/dist/callbacks/streamCallback.d.ts +26 -0
- package/dist/callbacks/streamCallback.d.ts.map +1 -0
- package/dist/callbacks/streamCallback.js +281 -0
- package/dist/callbacks/streamCallback.js.map +1 -0
- package/dist/flows/FlowManager.d.ts +19 -4
- package/dist/flows/FlowManager.d.ts.map +1 -1
- package/dist/flows/FlowManager.js +355 -131
- package/dist/flows/FlowManager.js.map +1 -1
- package/dist/flows/extraction.d.ts +17 -0
- package/dist/flows/extraction.d.ts.map +1 -0
- package/dist/flows/extraction.js +56 -0
- package/dist/flows/extraction.js.map +1 -0
- package/dist/flows/index.d.ts +1 -2
- package/dist/flows/index.d.ts.map +1 -1
- package/dist/flows/index.js +1 -1
- package/dist/flows/index.js.map +1 -1
- package/dist/flows/validation.d.ts +7 -0
- package/dist/flows/validation.d.ts.map +1 -0
- package/dist/flows/validation.js +42 -0
- package/dist/flows/validation.js.map +1 -0
- package/dist/hooks/builtin/metrics.d.ts +4 -34
- package/dist/hooks/builtin/metrics.d.ts.map +1 -1
- package/dist/hooks/builtin/metrics.js +3 -65
- package/dist/hooks/builtin/metrics.js.map +1 -1
- package/dist/hooks/helpers.d.ts +8 -47
- package/dist/hooks/helpers.d.ts.map +1 -1
- package/dist/hooks/helpers.js +38 -104
- package/dist/hooks/helpers.js.map +1 -1
- package/dist/hooks/index.d.ts +4 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/processors/ProcessorRunner.d.ts.map +1 -1
- package/dist/processors/ProcessorRunner.js +13 -0
- package/dist/processors/ProcessorRunner.js.map +1 -1
- package/dist/prompts/PromptBuilder.d.ts.map +1 -1
- package/dist/prompts/PromptBuilder.js +1 -0
- package/dist/prompts/PromptBuilder.js.map +1 -1
- package/dist/prompts/types.d.ts +2 -1
- package/dist/prompts/types.d.ts.map +1 -1
- package/dist/prompts/types.js +29 -7
- package/dist/prompts/types.js.map +1 -1
- package/dist/runtime/ContextManager.d.ts +1 -1
- package/dist/runtime/ContextManager.d.ts.map +1 -1
- package/dist/runtime/ContextManager.js +141 -20
- package/dist/runtime/ContextManager.js.map +1 -1
- package/dist/runtime/ExtractionEngine.d.ts +34 -0
- package/dist/runtime/ExtractionEngine.d.ts.map +1 -0
- package/dist/runtime/ExtractionEngine.js +155 -0
- package/dist/runtime/ExtractionEngine.js.map +1 -0
- package/dist/runtime/FlowExecutor.d.ts +51 -0
- package/dist/runtime/FlowExecutor.d.ts.map +1 -0
- package/dist/runtime/FlowExecutor.js +523 -0
- package/dist/runtime/FlowExecutor.js.map +1 -0
- package/dist/runtime/InjectionQueue.d.ts +8 -1
- package/dist/runtime/InjectionQueue.d.ts.map +1 -1
- package/dist/runtime/InjectionQueue.js +33 -0
- package/dist/runtime/InjectionQueue.js.map +1 -1
- package/dist/runtime/Runtime.d.ts +32 -2
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +513 -612
- package/dist/runtime/Runtime.js.map +1 -1
- package/dist/runtime/SessionEventManager.d.ts +17 -0
- package/dist/runtime/SessionEventManager.d.ts.map +1 -0
- package/dist/runtime/SessionEventManager.js +149 -0
- package/dist/runtime/SessionEventManager.js.map +1 -0
- package/dist/runtime/SuggestionManager.d.ts +7 -0
- package/dist/runtime/SuggestionManager.d.ts.map +1 -0
- package/dist/runtime/SuggestionManager.js +50 -0
- package/dist/runtime/SuggestionManager.js.map +1 -0
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/services/MetricsService.d.ts +55 -0
- package/dist/services/MetricsService.d.ts.map +1 -0
- package/dist/services/MetricsService.js +86 -0
- package/dist/services/MetricsService.js.map +1 -0
- package/dist/services/TracingService.d.ts +13 -0
- package/dist/services/TracingService.d.ts.map +1 -0
- package/dist/services/TracingService.js +62 -0
- package/dist/services/TracingService.js.map +1 -0
- package/dist/session/stores/MemoryStore.js +1 -1
- package/dist/session/stores/MemoryStore.js.map +1 -1
- package/dist/tools/Tool.d.ts +25 -3
- package/dist/tools/Tool.d.ts.map +1 -1
- package/dist/tools/Tool.js.map +1 -1
- package/dist/tools/errorHandling.d.ts +1 -1
- package/dist/tools/errorHandling.d.ts.map +1 -1
- package/dist/tools/errorHandling.js +27 -20
- package/dist/tools/errorHandling.js.map +1 -1
- package/dist/tools/http.d.ts.map +1 -1
- package/dist/tools/http.js +53 -17
- package/dist/tools/http.js.map +1 -1
- package/dist/types/index.d.ts +179 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/telemetry.d.ts +52 -0
- package/dist/types/telemetry.d.ts.map +1 -0
- package/dist/types/telemetry.js +2 -0
- package/dist/types/telemetry.js.map +1 -0
- package/dist/utils/aiStream.d.ts +7 -0
- package/dist/utils/aiStream.d.ts.map +1 -0
- package/dist/utils/aiStream.js +41 -0
- package/dist/utils/aiStream.js.map +1 -0
- package/dist/utils/chrono.d.ts +3 -46
- package/dist/utils/chrono.d.ts.map +1 -1
- package/dist/utils/chrono.js.map +1 -1
- package/dist/utils/isRecord.d.ts +2 -0
- package/dist/utils/isRecord.d.ts.map +1 -0
- package/dist/utils/isRecord.js +4 -0
- package/dist/utils/isRecord.js.map +1 -0
- package/dist/utils/messageNormalization.d.ts +3 -0
- package/dist/utils/messageNormalization.d.ts.map +1 -0
- package/dist/utils/messageNormalization.js +121 -0
- package/dist/utils/messageNormalization.js.map +1 -0
- package/dist/utils/streamChunk.d.ts +5 -0
- package/dist/utils/streamChunk.d.ts.map +1 -0
- package/dist/utils/streamChunk.js +50 -0
- package/dist/utils/streamChunk.js.map +1 -0
- package/guides/EXAMPLE_VERIFICATION.md +53 -0
- package/guides/FLOWS.md +29 -0
- package/guides/GETTING_STARTED.md +14 -1
- package/guides/README.md +3 -1
- package/guides/RUNTIME.md +75 -0
- package/guides/TOOLS.md +6 -0
- package/package.json +2 -2
- package/dist/flows/AgentFlowManager.d.ts +0 -161
- package/dist/flows/AgentFlowManager.d.ts.map +0 -1
- package/dist/flows/AgentFlowManager.js +0 -448
- package/dist/flows/AgentFlowManager.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageNormalization.d.ts","sourceRoot":"","sources":["../../src/utils/messageNormalization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAmHvC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI,CAgChF"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return value !== null && typeof value === 'object';
|
|
3
|
+
}
|
|
4
|
+
function getTextFromParts(parts) {
|
|
5
|
+
return parts
|
|
6
|
+
.map(part => {
|
|
7
|
+
if (!isRecord(part) || part.type !== 'text') {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
return typeof part.text === 'string' ? part.text : '';
|
|
11
|
+
})
|
|
12
|
+
.join('')
|
|
13
|
+
.trim();
|
|
14
|
+
}
|
|
15
|
+
function normalizeToolParts(parts) {
|
|
16
|
+
const normalized = [];
|
|
17
|
+
for (const part of parts) {
|
|
18
|
+
if (!isRecord(part) || typeof part.type !== 'string') {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (part.type === 'tool-result') {
|
|
22
|
+
if (typeof part.toolCallId === 'string' &&
|
|
23
|
+
typeof part.toolName === 'string' &&
|
|
24
|
+
'output' in part) {
|
|
25
|
+
normalized.push({
|
|
26
|
+
type: 'tool-result',
|
|
27
|
+
toolCallId: part.toolCallId,
|
|
28
|
+
toolName: part.toolName,
|
|
29
|
+
output: part.output,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (part.type === 'tool-approval-response') {
|
|
35
|
+
if (typeof part.approvalId === 'string' && typeof part.approved === 'boolean') {
|
|
36
|
+
normalized.push({
|
|
37
|
+
type: 'tool-approval-response',
|
|
38
|
+
approvalId: part.approvalId,
|
|
39
|
+
approved: part.approved,
|
|
40
|
+
...(typeof part.reason === 'string' ? { reason: part.reason } : {}),
|
|
41
|
+
...(typeof part.providerExecuted === 'boolean'
|
|
42
|
+
? { providerExecuted: part.providerExecuted }
|
|
43
|
+
: {}),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return normalized;
|
|
49
|
+
}
|
|
50
|
+
function normalizeAssistantParts(parts) {
|
|
51
|
+
const normalized = [];
|
|
52
|
+
for (const part of parts) {
|
|
53
|
+
if (!isRecord(part) || typeof part.type !== 'string') {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (part.type === 'text') {
|
|
57
|
+
if (typeof part.text === 'string') {
|
|
58
|
+
normalized.push({ type: 'text', text: part.text });
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (part.type === 'tool-call') {
|
|
63
|
+
if (typeof part.toolCallId === 'string' &&
|
|
64
|
+
typeof part.toolName === 'string' &&
|
|
65
|
+
'input' in part) {
|
|
66
|
+
normalized.push({
|
|
67
|
+
type: 'tool-call',
|
|
68
|
+
toolCallId: part.toolCallId,
|
|
69
|
+
toolName: part.toolName,
|
|
70
|
+
input: part.input,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (part.type === 'tool-result') {
|
|
76
|
+
if (typeof part.toolCallId === 'string' &&
|
|
77
|
+
typeof part.toolName === 'string' &&
|
|
78
|
+
'output' in part) {
|
|
79
|
+
normalized.push({
|
|
80
|
+
type: 'tool-result',
|
|
81
|
+
toolCallId: part.toolCallId,
|
|
82
|
+
toolName: part.toolName,
|
|
83
|
+
output: part.output,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (part.type === 'reasoning' && typeof part.text === 'string') {
|
|
89
|
+
normalized.push({ type: 'reasoning', text: part.text });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return normalized;
|
|
93
|
+
}
|
|
94
|
+
export function normalizeModelMessage(message) {
|
|
95
|
+
const role = message.role;
|
|
96
|
+
const content = message.content;
|
|
97
|
+
if (typeof content === 'string') {
|
|
98
|
+
return message;
|
|
99
|
+
}
|
|
100
|
+
if (!Array.isArray(content)) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (role === 'tool') {
|
|
104
|
+
const toolParts = normalizeToolParts(content);
|
|
105
|
+
if (toolParts.length === 0) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return { role: 'tool', content: toolParts };
|
|
109
|
+
}
|
|
110
|
+
if (role === 'assistant') {
|
|
111
|
+
const assistantParts = normalizeAssistantParts(content);
|
|
112
|
+
if (assistantParts.length > 0) {
|
|
113
|
+
return { role: 'assistant', content: assistantParts };
|
|
114
|
+
}
|
|
115
|
+
const text = getTextFromParts(content);
|
|
116
|
+
return text.length > 0 ? { role, content: text } : null;
|
|
117
|
+
}
|
|
118
|
+
const text = getTextFromParts(content);
|
|
119
|
+
return text.length > 0 ? { role, content: text } : null;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=messageNormalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageNormalization.js","sourceRoot":"","sources":["../../src/utils/messageNormalization.ts"],"names":[],"mappings":"AAEA,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAgB;IACxC,OAAO,KAAK;SACT,GAAG,CAAC,IAAI,CAAC,EAAE;QACV,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC5C,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACxD,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC;SACR,IAAI,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAgB;IAC1C,MAAM,UAAU,GAAmC,EAAE,CAAC;IAEtD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAA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AE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAmB,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5E,CAAC;IAED,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAmB,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getChunkArgs(chunk: unknown): unknown;
|
|
2
|
+
export declare function getChunkResult(chunk: unknown): unknown;
|
|
3
|
+
export declare function getChunkToolCallId(chunk: unknown): string | undefined;
|
|
4
|
+
export declare function getChunkErrorMessage(chunk: unknown): string;
|
|
5
|
+
//# sourceMappingURL=streamChunk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamChunk.d.ts","sourceRoot":"","sources":["../../src/utils/streamChunk.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAYpD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAYtD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAMrE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAe3D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export function getChunkArgs(chunk) {
|
|
2
|
+
if (!chunk || typeof chunk !== 'object') {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
const record = chunk;
|
|
6
|
+
if ('args' in record) {
|
|
7
|
+
return record.args;
|
|
8
|
+
}
|
|
9
|
+
if ('input' in record) {
|
|
10
|
+
return record.input;
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
export function getChunkResult(chunk) {
|
|
15
|
+
if (!chunk || typeof chunk !== 'object') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const record = chunk;
|
|
19
|
+
if ('result' in record) {
|
|
20
|
+
return record.result;
|
|
21
|
+
}
|
|
22
|
+
if ('output' in record) {
|
|
23
|
+
return record.output;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
export function getChunkToolCallId(chunk) {
|
|
28
|
+
if (!chunk || typeof chunk !== 'object') {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const value = chunk.toolCallId;
|
|
32
|
+
return typeof value === 'string' ? value : undefined;
|
|
33
|
+
}
|
|
34
|
+
export function getChunkErrorMessage(chunk) {
|
|
35
|
+
if (!chunk || typeof chunk !== 'object') {
|
|
36
|
+
return 'Tool execution error';
|
|
37
|
+
}
|
|
38
|
+
const value = chunk.error;
|
|
39
|
+
if (typeof value === 'string') {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
if (value && typeof value === 'object' && 'message' in value) {
|
|
43
|
+
const msg = value.message;
|
|
44
|
+
if (typeof msg === 'string') {
|
|
45
|
+
return msg;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return 'Tool execution error';
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=streamChunk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamChunk.js","sourceRoot":"","sources":["../../src/utils/streamChunk.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QACrB,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IACD,IAAI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AAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Example Verification
|
|
2
|
+
|
|
3
|
+
Last run: **February 15, 2026 (UTC)**
|
|
4
|
+
|
|
5
|
+
## Scope
|
|
6
|
+
|
|
7
|
+
This verification was run after runtime policy-profile changes to check for regressions.
|
|
8
|
+
|
|
9
|
+
Covered suites:
|
|
10
|
+
|
|
11
|
+
1. `packages/ariaflow-core/examples/agents` (Line parity set)
|
|
12
|
+
2. `packages/ariaflow-core/examples/flows` (Pipecat parity set)
|
|
13
|
+
3. Extended package examples (`ariaflow-config`, `ariaflow-builder`, `ariaflow-tools`, `ariaflow-redis-store`)
|
|
14
|
+
|
|
15
|
+
## Results
|
|
16
|
+
|
|
17
|
+
### Core parity examples (highest signal)
|
|
18
|
+
|
|
19
|
+
- Run artifact: `reports/example-runs/20260215T141412Z`
|
|
20
|
+
- Result: **19/19 pass**, **0 fail**, **0 timeout**, **0 skipped**
|
|
21
|
+
|
|
22
|
+
Interpretation:
|
|
23
|
+
|
|
24
|
+
- Core parity examples did not regress after the runtime changes.
|
|
25
|
+
|
|
26
|
+
### Extended package examples
|
|
27
|
+
|
|
28
|
+
- Run artifact: `reports/example-runs/20260215T141412Z/extended2`
|
|
29
|
+
- Result: **17 pass**, **3 fail**, **1 timeout**, **2 skipped**
|
|
30
|
+
|
|
31
|
+
Non-pass items:
|
|
32
|
+
|
|
33
|
+
1. `packages/ariaflow-builder/examples/basic-pack/run.ts` -> `FAIL(1)`
|
|
34
|
+
- Cause: no `run.ts` exists in that folder (pack/template folder, not standalone runner).
|
|
35
|
+
2. `packages/ariaflow-builder/examples/http-callback-demo/run.ts` -> `FAIL(1)`
|
|
36
|
+
- Cause: missing `dotenv` dependency in that example environment.
|
|
37
|
+
3. `packages/ariaflow-config/examples/packs/run-pack.ts` -> `FAIL(2)`
|
|
38
|
+
- Cause: invocation without required CLI argument (`<starterName>`).
|
|
39
|
+
4. `packages/ariaflow-builder/examples/hospital-support-pack/run.ts` -> `TIMEOUT`
|
|
40
|
+
- Cause: long multi-demo integration run exceeded local timeout budget.
|
|
41
|
+
5. `packages/ariaflow-redis-store/examples/local-redis/test.ts` -> `SKIPPED`
|
|
42
|
+
6. `packages/ariaflow-redis-store/examples/local-redis/multi-turn.ts` -> `SKIPPED`
|
|
43
|
+
- Cause: local Redis was not started.
|
|
44
|
+
|
|
45
|
+
## Verdict
|
|
46
|
+
|
|
47
|
+
- **No core runtime regression detected** in the parity suites that matter most for Aria behavior.
|
|
48
|
+
- Remaining non-pass cases are example runner prerequisites/invocation issues, not evidence of runtime breakage.
|
|
49
|
+
|
|
50
|
+
## Recommended test tiers
|
|
51
|
+
|
|
52
|
+
1. **Smoke (CI default)**: core parity examples + core tests.
|
|
53
|
+
2. **Integration (manual/nightly)**: long demos, Redis-dependent examples, callback/network examples.
|
package/guides/FLOWS.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Flows provide structured, multi-step conversations using nodes and tool-driven transitions.
|
|
4
4
|
|
|
5
|
+
Legacy note: `AgentFlowManager` has been renamed to `FlowManager`. New flows should generally use `FlowAgent` orchestrated by the `Runtime`.
|
|
6
|
+
|
|
5
7
|
## Flow Agents
|
|
6
8
|
|
|
7
9
|
A `FlowAgent` wraps a `FlowConfig` and is orchestrated by the `Runtime`.
|
|
@@ -9,6 +11,8 @@ A `FlowAgent` wraps a `FlowConfig` and is orchestrated by the `Runtime`.
|
|
|
9
11
|
Key features:
|
|
10
12
|
- Node-based steps (`id`, `prompt`, `tools`)
|
|
11
13
|
- Tool-driven transitions via `createFlowTransition()`
|
|
14
|
+
- Implicit transition tools for `transitions[].on` edges (explicit tools override on name collisions)
|
|
15
|
+
- Contract-aware transitions (`contract.toolOnly`, `contract.requiresUserTurn`)
|
|
12
16
|
- Context strategies (`append`, `reset`, `reset_with_summary`)
|
|
13
17
|
- Hybrid mode to answer off-topic questions
|
|
14
18
|
|
|
@@ -50,6 +54,19 @@ const bookingFlow = {
|
|
|
50
54
|
prompt: 'Thanks. Confirm the booking?',
|
|
51
55
|
},
|
|
52
56
|
],
|
|
57
|
+
transitions: [
|
|
58
|
+
{
|
|
59
|
+
from: 'greeting',
|
|
60
|
+
to: 'collect_time',
|
|
61
|
+
on: 'to_collect_time',
|
|
62
|
+
contract: {
|
|
63
|
+
label: 'Move after date capture',
|
|
64
|
+
conditionText: 'User has provided a valid date.',
|
|
65
|
+
toolOnly: true,
|
|
66
|
+
requiresUserTurn: true,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
53
70
|
};
|
|
54
71
|
```
|
|
55
72
|
|
|
@@ -72,8 +89,20 @@ const bookingAgent: FlowAgentConfig = {
|
|
|
72
89
|
## Transition Tips
|
|
73
90
|
|
|
74
91
|
- Always return `createFlowTransition(targetId, data)` from tools that move the flow.
|
|
92
|
+
- If a transition has `on: 'to_next'`, `FlowManager` auto-exposes a `to_next` tool for that node.
|
|
93
|
+
- Use explicit tools when you need custom transition payload logic; explicit tool names override implicit transition tools.
|
|
75
94
|
- Use `createFlowUpdate(data, text, keys)` when you want to stay on the same node.
|
|
95
|
+
- Flow actions support `deferUntil: 'turn-end'` for deterministic post-response side effects.
|
|
96
|
+
- Use `contract.toolOnly: true` when a transition must come from a tool/event signal (not condition-only auto-transition).
|
|
97
|
+
- Use `contract.requiresUserTurn: true` to prevent autonomous chain transitions without a user turn.
|
|
98
|
+
|
|
99
|
+
## Prompt Composition
|
|
100
|
+
|
|
101
|
+
- Flow-level/global prompt is combined with node prompt by default.
|
|
102
|
+
- Set `addGlobalPrompt: false` on a node to suppress global prompt injection for that node (useful for short closing nodes).
|
|
103
|
+
- Optional `nodeType` (`start`, `agent`, `end`, `global`) improves validation/tooling consistency.
|
|
76
104
|
|
|
77
105
|
## Context Strategies
|
|
78
106
|
|
|
79
107
|
Use `contextStrategy: 'reset'` to keep each node clean, or `reset_with_summary` for long flows.
|
|
108
|
+
For `reset_with_summary`, you can set `summaryTimeoutMs` at flow or node level to prevent stalled turns.
|
|
@@ -18,7 +18,12 @@ npm install @ariaflowagents/core ai zod @ai-sdk/openai
|
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import 'dotenv/config';
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
Runtime,
|
|
23
|
+
type AgentConfig,
|
|
24
|
+
createDateParser,
|
|
25
|
+
createFileStreamSink,
|
|
26
|
+
} from '@ariaflowagents/core';
|
|
22
27
|
import { openai } from '@ai-sdk/openai';
|
|
23
28
|
|
|
24
29
|
const dateParser = createDateParser();
|
|
@@ -38,6 +43,14 @@ const runtime = new Runtime({
|
|
|
38
43
|
agents: [support],
|
|
39
44
|
defaultAgentId: 'support',
|
|
40
45
|
defaultModel: openai('gpt-4o-mini') as any,
|
|
46
|
+
// Optional: non-blocking persistence sink with message-level defaults
|
|
47
|
+
streamCallback: {
|
|
48
|
+
sinks: [createFileStreamSink({ directory: './transcripts' })],
|
|
49
|
+
eventMode: 'message',
|
|
50
|
+
emitToolEvents: true,
|
|
51
|
+
emitTextDeltas: false,
|
|
52
|
+
emitFinalText: true,
|
|
53
|
+
},
|
|
41
54
|
});
|
|
42
55
|
|
|
43
56
|
for await (const part of runtime.stream({ input: 'Hello there' })) {
|
package/guides/README.md
CHANGED
|
@@ -9,8 +9,10 @@ Practical guides for the AriaFlow core runtime and agent primitives.
|
|
|
9
9
|
- **[Flows](./FLOWS.md)** - Flow agents and structured conversations
|
|
10
10
|
- **[Tools](./TOOLS.md)** - Tool design, execution, and AI SDK integration
|
|
11
11
|
- **[Guardrails](./GUARDRAILS.md)** - Stop conditions, enforcement rules, processors, redaction
|
|
12
|
+
- **[Example Verification](./EXAMPLE_VERIFICATION.md)** - Latest example sweep results and known prerequisites
|
|
12
13
|
|
|
13
14
|
## Examples
|
|
14
15
|
|
|
15
16
|
- `examples/` for runnable demos
|
|
16
|
-
- `examples/
|
|
17
|
+
- `examples/flows/` for Pipecat flow parity examples
|
|
18
|
+
- `examples/agents/` for Line example parity agents and integrations
|
package/guides/RUNTIME.md
CHANGED
|
@@ -18,16 +18,90 @@ Common types:
|
|
|
18
18
|
- `tool-call`, `tool-result`, `tool-error`
|
|
19
19
|
- `handoff`
|
|
20
20
|
- `node-enter`, `flow-transition`, `flow-end`
|
|
21
|
+
- `custom` (flow/runtime emitted app events)
|
|
21
22
|
- `agent-start`, `agent-end`
|
|
22
23
|
- `turn-end`, `done`, `error`
|
|
23
24
|
|
|
24
25
|
Internal events can expose operational details. Treat them as privileged data.
|
|
25
26
|
|
|
27
|
+
## Stream Callback (Persistence Defaults)
|
|
28
|
+
|
|
29
|
+
Use `streamCallback` when sending runtime events to file/webhook/DB/queue sinks.
|
|
30
|
+
|
|
31
|
+
Default behavior is message-oriented:
|
|
32
|
+
- emits: `input`, `done`, `error`, `tripwire`, `tool-call`, `tool-result`, `tool-error`, `flow-transition`, `handoff`
|
|
33
|
+
- does not emit `text-delta` tokens unless enabled
|
|
34
|
+
- attaches final assistant text as `fullText` on terminal events
|
|
35
|
+
- if no sink is configured, adapter is a no-op
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createFunctionStreamSink } from '@ariaflowagents/core';
|
|
39
|
+
|
|
40
|
+
const runtime = new Runtime({
|
|
41
|
+
agents,
|
|
42
|
+
defaultAgentId: 'triage',
|
|
43
|
+
streamCallback: {
|
|
44
|
+
sinks: [createFunctionStreamSink(async payload => writeToDb(payload))],
|
|
45
|
+
eventMode: 'message',
|
|
46
|
+
emitToolEvents: true,
|
|
47
|
+
emitTransitionEvents: true,
|
|
48
|
+
emitTextDeltas: false,
|
|
49
|
+
emitFinalText: true,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To include token deltas:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
streamCallback: {
|
|
58
|
+
sinks: [...],
|
|
59
|
+
eventMode: 'all',
|
|
60
|
+
emitTextDeltas: true,
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
26
64
|
## Session Semantics
|
|
27
65
|
|
|
28
66
|
- Sessions are keyed by `sessionId` and persisted via a `SessionStore`.
|
|
29
67
|
- The runtime tracks `activeAgentId`, `currentAgent`, and `handoffHistory`.
|
|
68
|
+
- Flow agents snapshot structured progress into `session.workingMemory.flowStateByAgent[agentId]`
|
|
69
|
+
so other agents can see latest `currentNode` and `collectedData` after handoffs.
|
|
70
|
+
- Runtime stores replay-oriented turn events in `session.workingMemory.runtimeEventLog`
|
|
71
|
+
(`user`, `assistant_final`, `tool_call`, `tool_result`, `tool_error`, `transition`).
|
|
30
72
|
- `contextManager` can compact history before each turn.
|
|
73
|
+
- `contextManager.beforeTurn(...)` can be synchronous or asynchronous.
|
|
74
|
+
|
|
75
|
+
## Prompt Memory Hygiene
|
|
76
|
+
|
|
77
|
+
To prevent internal runtime state from leaking into the model's context window:
|
|
78
|
+
- **Filtering**: Keys like `runtimeEventLog` are automatically redacted from the prompt.
|
|
79
|
+
- **Allowlisting**: Individual agents can specify `promptMemoryAllowlist: string[]` to restrict which piece of working memory they can "see".
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const agent = {
|
|
83
|
+
id: 'billing',
|
|
84
|
+
promptMemoryAllowlist: ['invoice_status', 'billing_address']
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Durability Hardening
|
|
89
|
+
|
|
90
|
+
Runtime checkpoints session state automatically on critical events:
|
|
91
|
+
- `tool-result`
|
|
92
|
+
- `tool-error`
|
|
93
|
+
- `flow-transition`
|
|
94
|
+
- handoff state updates (after `activeAgentId`/`currentAgent` mutation)
|
|
95
|
+
|
|
96
|
+
For external side effects, tools receive a stable `idempotencyKey` in
|
|
97
|
+
`options.experimental_context` so downstream systems can de-duplicate writes.
|
|
98
|
+
|
|
99
|
+
## Fail-Closed Operations
|
|
100
|
+
|
|
101
|
+
Critical tool failures block the "success" path. If a tool fails:
|
|
102
|
+
1. The assistant's generated response is suppressed.
|
|
103
|
+
2. A `failure-recovery` event is emitted.
|
|
104
|
+
3. The turn ends with an error status to prevent inconsistent state.
|
|
31
105
|
|
|
32
106
|
## Routing & Handoffs
|
|
33
107
|
|
|
@@ -86,3 +160,4 @@ const runtime = new Runtime({
|
|
|
86
160
|
## Abort & Interrupt
|
|
87
161
|
|
|
88
162
|
`Runtime.abortSession(sessionId)` cancels an in-flight turn and emits `interrupted`.
|
|
163
|
+
`Runtime.stream({ abortSignal })` also propagates cancellation into model/tool calls.
|
package/guides/TOOLS.md
CHANGED
|
@@ -41,10 +41,16 @@ AI SDK passes `ToolExecutionOptions` into `execute`:
|
|
|
41
41
|
- `experimental_context`
|
|
42
42
|
|
|
43
43
|
AriaFlow preserves these options so advanced tools can use them directly.
|
|
44
|
+
Runtime also injects:
|
|
45
|
+
- `experimental_context.idempotencyKey` (stable per session/step/toolCall)
|
|
46
|
+
- `experimental_context.sessionId`
|
|
47
|
+
- `experimental_context.agentId`
|
|
44
48
|
|
|
45
49
|
```ts
|
|
46
50
|
execute: async (input, { abortSignal, toolCallId, experimental_context }) => {
|
|
47
51
|
// Use abortSignal to cancel I/O
|
|
52
|
+
// Use idempotencyKey for external writes
|
|
53
|
+
const idempotencyKey = experimental_context?.idempotencyKey;
|
|
48
54
|
return fetch(url, { signal: abortSignal });
|
|
49
55
|
}
|
|
50
56
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ariaflowagents/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A framework for structured conversational AI agents",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -76,6 +76,6 @@
|
|
|
76
76
|
"test": "npm run build && node --test test/*.test.js"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@ariaflowagents/config": "^0.
|
|
79
|
+
"@ariaflowagents/config": "^0.7.0"
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { type ToolSet, type ModelMessage } from 'ai';
|
|
2
|
-
import type { LanguageModel } from 'ai';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { type FlowTransitionSignal } from './transitions.js';
|
|
5
|
-
import type { SessionStore } from '../session/index.js';
|
|
6
|
-
export declare enum ContextStrategy {
|
|
7
|
-
APPEND = "append",
|
|
8
|
-
RESET = "reset",
|
|
9
|
-
RESET_WITH_SUMMARY = "reset_with_summary"
|
|
10
|
-
}
|
|
11
|
-
export interface ContextStrategyConfig {
|
|
12
|
-
strategy: ContextStrategy;
|
|
13
|
-
summaryPrompt?: string;
|
|
14
|
-
summaryMaxTokens?: number;
|
|
15
|
-
}
|
|
16
|
-
export type FlowAction = {
|
|
17
|
-
type: 'say';
|
|
18
|
-
text: string;
|
|
19
|
-
} | {
|
|
20
|
-
type: 'end';
|
|
21
|
-
message?: string;
|
|
22
|
-
} | {
|
|
23
|
-
type: 'function';
|
|
24
|
-
handler: FlowActionHandler;
|
|
25
|
-
} | {
|
|
26
|
-
type: 'delay';
|
|
27
|
-
ms: number;
|
|
28
|
-
} | {
|
|
29
|
-
type: 'emit';
|
|
30
|
-
event: string;
|
|
31
|
-
data?: unknown;
|
|
32
|
-
};
|
|
33
|
-
export type FlowActionHandler = (context: FlowContext) => Promise<void>;
|
|
34
|
-
export interface FlowNodeConfig {
|
|
35
|
-
name: string;
|
|
36
|
-
description?: string;
|
|
37
|
-
rolePrompt?: string;
|
|
38
|
-
taskPrompt: string;
|
|
39
|
-
tools?: ToolSet | ((context: FlowContext) => ToolSet);
|
|
40
|
-
preActions?: FlowAction[];
|
|
41
|
-
postActions?: FlowAction[];
|
|
42
|
-
contextStrategy?: ContextStrategyConfig;
|
|
43
|
-
autoRespond?: boolean;
|
|
44
|
-
maxTurns?: number;
|
|
45
|
-
maxSteps?: number;
|
|
46
|
-
}
|
|
47
|
-
export interface FlowContext {
|
|
48
|
-
state: Record<string, unknown>;
|
|
49
|
-
currentNode: string;
|
|
50
|
-
messages: ModelMessage[];
|
|
51
|
-
collectedData: Record<string, unknown>;
|
|
52
|
-
nodeHistory: string[];
|
|
53
|
-
nodeTurnCounts: Record<string, number>;
|
|
54
|
-
sessionId: string;
|
|
55
|
-
userId?: string;
|
|
56
|
-
ended: boolean;
|
|
57
|
-
endReason?: string;
|
|
58
|
-
}
|
|
59
|
-
export interface FlowManagerConfig {
|
|
60
|
-
nodes: FlowNodeConfig[];
|
|
61
|
-
initialNode: string;
|
|
62
|
-
globalTools?: ToolSet;
|
|
63
|
-
defaultRolePrompt?: string;
|
|
64
|
-
defaultContextStrategy?: ContextStrategyConfig;
|
|
65
|
-
model: LanguageModel;
|
|
66
|
-
hooks?: FlowHooks;
|
|
67
|
-
}
|
|
68
|
-
export interface FlowHooks {
|
|
69
|
-
onFlowStart?: (context: FlowContext) => Promise<void>;
|
|
70
|
-
onFlowEnd?: (context: FlowContext, reason: string) => Promise<void>;
|
|
71
|
-
onNodeEnter?: (context: FlowContext, node: FlowNodeConfig) => Promise<void>;
|
|
72
|
-
onNodeExit?: (context: FlowContext, node: FlowNodeConfig) => Promise<void>;
|
|
73
|
-
onBeforeInference?: (context: FlowContext, node: FlowNodeConfig) => Promise<void>;
|
|
74
|
-
onAfterInference?: (context: FlowContext, node: FlowNodeConfig, response: string) => Promise<void>;
|
|
75
|
-
onTransition?: (context: FlowContext, from: string, to: string, data?: Record<string, unknown>) => Promise<void>;
|
|
76
|
-
onError?: (context: FlowContext, error: Error) => Promise<void>;
|
|
77
|
-
}
|
|
78
|
-
export type FlowStreamPart = {
|
|
79
|
-
type: 'text-delta';
|
|
80
|
-
text: string;
|
|
81
|
-
} | {
|
|
82
|
-
type: 'tool-call';
|
|
83
|
-
toolName: string;
|
|
84
|
-
args: unknown;
|
|
85
|
-
} | {
|
|
86
|
-
type: 'tool-result';
|
|
87
|
-
toolName: string;
|
|
88
|
-
result: unknown;
|
|
89
|
-
} | {
|
|
90
|
-
type: 'transition';
|
|
91
|
-
from: string;
|
|
92
|
-
to: string;
|
|
93
|
-
data?: Record<string, unknown>;
|
|
94
|
-
} | {
|
|
95
|
-
type: 'node-enter';
|
|
96
|
-
nodeName: string;
|
|
97
|
-
} | {
|
|
98
|
-
type: 'node-exit';
|
|
99
|
-
nodeName: string;
|
|
100
|
-
} | {
|
|
101
|
-
type: 'action';
|
|
102
|
-
actionType: string;
|
|
103
|
-
data?: unknown;
|
|
104
|
-
} | {
|
|
105
|
-
type: 'flow-end';
|
|
106
|
-
reason: string;
|
|
107
|
-
} | {
|
|
108
|
-
type: 'error';
|
|
109
|
-
error: string;
|
|
110
|
-
} | {
|
|
111
|
-
type: 'done';
|
|
112
|
-
};
|
|
113
|
-
export declare function createCollectorTool<T extends z.ZodRawShape>(description: string, schema: z.ZodObject<T>, nextNode: string): {
|
|
114
|
-
description: string;
|
|
115
|
-
parameters: z.ZodObject<T, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<T> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
116
|
-
execute: (data: z.infer<z.ZodObject<T>>) => Promise<FlowTransitionSignal>;
|
|
117
|
-
};
|
|
118
|
-
export declare class AgentFlowManager {
|
|
119
|
-
private nodes;
|
|
120
|
-
private currentNode;
|
|
121
|
-
private context;
|
|
122
|
-
private config;
|
|
123
|
-
private initialized;
|
|
124
|
-
private sessionStore?;
|
|
125
|
-
private agentId;
|
|
126
|
-
constructor(config: FlowManagerConfig, sessionId: string, userId?: string, sessionStore?: SessionStore, agentId?: string);
|
|
127
|
-
private saveState;
|
|
128
|
-
private loadState;
|
|
129
|
-
initialize(): Promise<FlowStreamPart[]>;
|
|
130
|
-
process(userInput: string): AsyncGenerator<FlowStreamPart>;
|
|
131
|
-
forceTransition(nodeName: string, data?: Record<string, unknown>): Promise<FlowStreamPart[]>;
|
|
132
|
-
endFlow(reason?: string): Promise<void>;
|
|
133
|
-
get state(): Record<string, unknown>;
|
|
134
|
-
get collectedData(): Record<string, unknown>;
|
|
135
|
-
get currentNodeName(): string;
|
|
136
|
-
get nodeHistory(): string[];
|
|
137
|
-
get hasEnded(): boolean;
|
|
138
|
-
get fullContext(): {
|
|
139
|
-
state: Record<string, unknown>;
|
|
140
|
-
currentNode: string;
|
|
141
|
-
messages: ModelMessage[];
|
|
142
|
-
collectedData: Record<string, unknown>;
|
|
143
|
-
nodeHistory: string[];
|
|
144
|
-
nodeTurnCounts: Record<string, number>;
|
|
145
|
-
sessionId: string;
|
|
146
|
-
userId?: string;
|
|
147
|
-
ended: boolean;
|
|
148
|
-
endReason?: string;
|
|
149
|
-
};
|
|
150
|
-
private transitionTo;
|
|
151
|
-
private generateNodeResponse;
|
|
152
|
-
private runInference;
|
|
153
|
-
private buildSystemPrompt;
|
|
154
|
-
private applyContextStrategy;
|
|
155
|
-
private generateSummary;
|
|
156
|
-
private runActions;
|
|
157
|
-
private normalizeMessage;
|
|
158
|
-
static create(config: FlowManagerConfig, sessionId: string, userId?: string): AgentFlowManager;
|
|
159
|
-
static restore(config: FlowManagerConfig, savedContext: FlowContext): AgentFlowManager;
|
|
160
|
-
}
|
|
161
|
-
//# sourceMappingURL=AgentFlowManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgentFlowManager.d.ts","sourceRoot":"","sources":["../../src/flows/AgentFlowManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,IAAI,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,CAAC,EA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