@ariaflowagents/core 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -1
- package/dist/agents/Agent.d.ts +188 -9
- package/dist/agents/Agent.d.ts.map +1 -1
- package/dist/agents/Agent.js +246 -24
- package/dist/agents/Agent.js.map +1 -1
- package/dist/agents/CompositeAgent.d.ts +4 -3
- package/dist/agents/CompositeAgent.d.ts.map +1 -1
- package/dist/agents/CompositeAgent.js +19 -9
- package/dist/agents/CompositeAgent.js.map +1 -1
- package/dist/agents/FlowAgent.d.ts +3 -2
- package/dist/agents/FlowAgent.d.ts.map +1 -1
- package/dist/agents/FlowAgent.js +16 -6
- package/dist/agents/FlowAgent.js.map +1 -1
- package/dist/agents/TriageAgent.d.ts +8 -2
- package/dist/agents/TriageAgent.d.ts.map +1 -1
- package/dist/agents/TriageAgent.js +39 -6
- package/dist/agents/TriageAgent.js.map +1 -1
- package/dist/agents/index.d.ts +1 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +0 -1
- package/dist/agents/index.js.map +1 -1
- package/dist/flows/FlowManager.d.ts +8 -0
- package/dist/flows/FlowManager.d.ts.map +1 -1
- package/dist/flows/FlowManager.js +38 -4
- package/dist/flows/FlowManager.js.map +1 -1
- package/dist/flows/template.d.ts +2 -2
- package/dist/flows/template.d.ts.map +1 -1
- package/dist/flows/template.js +13 -0
- package/dist/flows/template.js.map +1 -1
- package/dist/foundation/AgentDefinition.d.ts +18 -0
- package/dist/foundation/AgentDefinition.d.ts.map +1 -0
- package/dist/foundation/AgentDefinition.js +2 -0
- package/dist/foundation/AgentDefinition.js.map +1 -0
- package/dist/foundation/AgentStateController.d.ts +26 -0
- package/dist/foundation/AgentStateController.d.ts.map +1 -0
- package/dist/foundation/AgentStateController.js +2 -0
- package/dist/foundation/AgentStateController.js.map +1 -0
- package/dist/foundation/ConversationEventLog.d.ts +72 -0
- package/dist/foundation/ConversationEventLog.d.ts.map +1 -0
- package/dist/foundation/ConversationEventLog.js +2 -0
- package/dist/foundation/ConversationEventLog.js.map +1 -0
- package/dist/foundation/ConversationState.d.ts +31 -0
- package/dist/foundation/ConversationState.d.ts.map +1 -0
- package/dist/foundation/ConversationState.js +2 -0
- package/dist/foundation/ConversationState.js.map +1 -0
- package/dist/foundation/DefaultAgentStateController.d.ts +24 -0
- package/dist/foundation/DefaultAgentStateController.d.ts.map +1 -0
- package/dist/foundation/DefaultAgentStateController.js +49 -0
- package/dist/foundation/DefaultAgentStateController.js.map +1 -0
- package/dist/foundation/DefaultConversationEventLog.d.ts +28 -0
- package/dist/foundation/DefaultConversationEventLog.d.ts.map +1 -0
- package/dist/foundation/DefaultConversationEventLog.js +195 -0
- package/dist/foundation/DefaultConversationEventLog.js.map +1 -0
- package/dist/foundation/DefaultConversationState.d.ts +34 -0
- package/dist/foundation/DefaultConversationState.d.ts.map +1 -0
- package/dist/foundation/DefaultConversationState.js +100 -0
- package/dist/foundation/DefaultConversationState.js.map +1 -0
- package/dist/foundation/DefaultToolExecutor.d.ts +58 -0
- package/dist/foundation/DefaultToolExecutor.d.ts.map +1 -0
- package/dist/foundation/DefaultToolExecutor.js +128 -0
- package/dist/foundation/DefaultToolExecutor.js.map +1 -0
- package/dist/foundation/ToolExecutor.d.ts +44 -0
- package/dist/foundation/ToolExecutor.d.ts.map +1 -0
- package/dist/foundation/ToolExecutor.js +2 -0
- package/dist/foundation/ToolExecutor.js.map +1 -0
- package/dist/foundation/createFoundation.d.ts +33 -0
- package/dist/foundation/createFoundation.d.ts.map +1 -0
- package/dist/foundation/createFoundation.js +34 -0
- package/dist/foundation/createFoundation.js.map +1 -0
- package/dist/foundation/index.d.ts +15 -0
- package/dist/foundation/index.d.ts.map +1 -0
- package/dist/foundation/index.js +8 -0
- package/dist/foundation/index.js.map +1 -0
- package/dist/hooks/HookRunner.d.ts +2 -0
- package/dist/hooks/HookRunner.d.ts.map +1 -1
- package/dist/hooks/HookRunner.js +4 -0
- package/dist/hooks/HookRunner.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/memory/MemoryService.d.ts +40 -0
- package/dist/memory/MemoryService.d.ts.map +1 -0
- package/dist/memory/MemoryService.js +2 -0
- package/dist/memory/MemoryService.js.map +1 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +3 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/preloadMemory.d.ts +17 -0
- package/dist/memory/preloadMemory.d.ts.map +1 -0
- package/dist/memory/preloadMemory.js +62 -0
- package/dist/memory/preloadMemory.js.map +1 -0
- package/dist/memory/stores/InMemoryMemoryService.d.ts +20 -0
- package/dist/memory/stores/InMemoryMemoryService.d.ts.map +1 -0
- package/dist/memory/stores/InMemoryMemoryService.js +92 -0
- package/dist/memory/stores/InMemoryMemoryService.js.map +1 -0
- package/dist/memory/types.d.ts +49 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +8 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/prompts/AgentPrompt.d.ts +110 -0
- package/dist/prompts/AgentPrompt.d.ts.map +1 -0
- package/dist/prompts/AgentPrompt.js +373 -0
- package/dist/prompts/AgentPrompt.js.map +1 -0
- package/dist/prompts/PromptAssembly.d.ts +119 -0
- package/dist/prompts/PromptAssembly.d.ts.map +1 -0
- package/dist/prompts/PromptAssembly.js +150 -0
- package/dist/prompts/PromptAssembly.js.map +1 -0
- package/dist/prompts/PromptBuilder.d.ts +22 -3
- package/dist/prompts/PromptBuilder.d.ts.map +1 -1
- package/dist/prompts/PromptBuilder.js +242 -13
- package/dist/prompts/PromptBuilder.js.map +1 -1
- package/dist/prompts/PromptRenderer.d.ts +43 -0
- package/dist/prompts/PromptRenderer.d.ts.map +1 -0
- package/dist/prompts/PromptRenderer.js +114 -0
- package/dist/prompts/PromptRenderer.js.map +1 -0
- package/dist/prompts/brandVoice.d.ts +10 -0
- package/dist/prompts/brandVoice.d.ts.map +1 -0
- package/dist/prompts/brandVoice.js +87 -0
- package/dist/prompts/brandVoice.js.map +1 -0
- package/dist/prompts/index.d.ts +11 -4
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +7 -2
- package/dist/prompts/index.js.map +1 -1
- package/dist/prompts/security.d.ts +5 -0
- package/dist/prompts/security.d.ts.map +1 -0
- package/dist/prompts/security.js +52 -0
- package/dist/prompts/security.js.map +1 -0
- package/dist/prompts/types.d.ts +65 -1
- package/dist/prompts/types.d.ts.map +1 -1
- package/dist/prompts/types.js +26 -0
- package/dist/prompts/types.js.map +1 -1
- package/dist/runtime/ContextBudget.d.ts +57 -0
- package/dist/runtime/ContextBudget.d.ts.map +1 -0
- package/dist/runtime/ContextBudget.js +103 -0
- package/dist/runtime/ContextBudget.js.map +1 -0
- package/dist/runtime/ContextManager.d.ts +8 -5
- package/dist/runtime/ContextManager.d.ts.map +1 -1
- package/dist/runtime/ContextManager.js +47 -14
- package/dist/runtime/ContextManager.js.map +1 -1
- package/dist/runtime/FlowExecutor.d.ts +16 -11
- package/dist/runtime/FlowExecutor.d.ts.map +1 -1
- package/dist/runtime/FlowExecutor.js +32 -138
- package/dist/runtime/FlowExecutor.js.map +1 -1
- package/dist/runtime/Runtime.d.ts +31 -78
- package/dist/runtime/Runtime.d.ts.map +1 -1
- package/dist/runtime/Runtime.js +225 -1406
- package/dist/runtime/Runtime.js.map +1 -1
- package/dist/runtime/SessionCache.d.ts +16 -0
- package/dist/runtime/SessionCache.d.ts.map +1 -0
- package/dist/runtime/SessionCache.js +49 -0
- package/dist/runtime/SessionCache.js.map +1 -0
- package/dist/runtime/SessionMutex.d.ts +37 -0
- package/dist/runtime/SessionMutex.d.ts.map +1 -0
- package/dist/runtime/SessionMutex.js +59 -0
- package/dist/runtime/SessionMutex.js.map +1 -0
- package/dist/runtime/StreamEmitter.d.ts +34 -0
- package/dist/runtime/StreamEmitter.d.ts.map +1 -0
- package/dist/runtime/StreamEmitter.js +91 -0
- package/dist/runtime/StreamEmitter.js.map +1 -0
- package/dist/runtime/handoffFilters.d.ts +60 -0
- package/dist/runtime/handoffFilters.d.ts.map +1 -0
- package/dist/runtime/handoffFilters.js +95 -0
- package/dist/runtime/handoffFilters.js.map +1 -0
- package/dist/runtime/pipeline/AgentExecuteStage.d.ts +22 -0
- package/dist/runtime/pipeline/AgentExecuteStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/AgentExecuteStage.js +889 -0
- package/dist/runtime/pipeline/AgentExecuteStage.js.map +1 -0
- package/dist/runtime/pipeline/ContextAssembleStage.d.ts +26 -0
- package/dist/runtime/pipeline/ContextAssembleStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/ContextAssembleStage.js +253 -0
- package/dist/runtime/pipeline/ContextAssembleStage.js.map +1 -0
- package/dist/runtime/pipeline/ContextGatherStage.d.ts +21 -0
- package/dist/runtime/pipeline/ContextGatherStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/ContextGatherStage.js +161 -0
- package/dist/runtime/pipeline/ContextGatherStage.js.map +1 -0
- package/dist/runtime/pipeline/IntakeStage.d.ts +25 -0
- package/dist/runtime/pipeline/IntakeStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/IntakeStage.js +126 -0
- package/dist/runtime/pipeline/IntakeStage.js.map +1 -0
- package/dist/runtime/pipeline/PostStreamStage.d.ts +26 -0
- package/dist/runtime/pipeline/PostStreamStage.d.ts.map +1 -0
- package/dist/runtime/pipeline/PostStreamStage.js +129 -0
- package/dist/runtime/pipeline/PostStreamStage.js.map +1 -0
- package/dist/runtime/pipeline/TurnPipeline.d.ts +54 -0
- package/dist/runtime/pipeline/TurnPipeline.d.ts.map +1 -0
- package/dist/runtime/pipeline/TurnPipeline.js +15 -0
- package/dist/runtime/pipeline/TurnPipeline.js.map +1 -0
- package/dist/runtime/pipeline/TurnServices.d.ts +48 -0
- package/dist/runtime/pipeline/TurnServices.d.ts.map +1 -0
- package/dist/runtime/pipeline/TurnServices.js +2 -0
- package/dist/runtime/pipeline/TurnServices.js.map +1 -0
- package/dist/runtime/pipeline/agentTypeGuards.d.ts +4 -0
- package/dist/runtime/pipeline/agentTypeGuards.d.ts.map +1 -0
- package/dist/runtime/pipeline/agentTypeGuards.js +7 -0
- package/dist/runtime/pipeline/agentTypeGuards.js.map +1 -0
- package/dist/runtime/pipeline/index.d.ts +11 -0
- package/dist/runtime/pipeline/index.d.ts.map +1 -0
- package/dist/runtime/pipeline/index.js +13 -0
- package/dist/runtime/pipeline/index.js.map +1 -0
- package/dist/runtime/pipeline/outputProcessing.d.ts +23 -0
- package/dist/runtime/pipeline/outputProcessing.d.ts.map +1 -0
- package/dist/runtime/pipeline/outputProcessing.js +63 -0
- package/dist/runtime/pipeline/outputProcessing.js.map +1 -0
- package/dist/runtime/pipeline/sessionUtils.d.ts +12 -0
- package/dist/runtime/pipeline/sessionUtils.d.ts.map +1 -0
- package/dist/runtime/pipeline/sessionUtils.js +73 -0
- package/dist/runtime/pipeline/sessionUtils.js.map +1 -0
- package/dist/tools/Tool.d.ts +7 -0
- package/dist/tools/Tool.d.ts.map +1 -1
- package/dist/tools/Tool.js +12 -3
- package/dist/tools/Tool.js.map +1 -1
- package/dist/tools/memory.d.ts +26 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +51 -0
- package/dist/tools/memory.js.map +1 -0
- package/dist/types/index.d.ts +177 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/guides/AGENTS.md +173 -0
- package/guides/README.md +12 -0
- package/guides/TOOLS.md +93 -27
- package/package.json +12 -4
- package/dist/agents/LLMAgent.d.ts +0 -11
- package/dist/agents/LLMAgent.d.ts.map +0 -1
- package/dist/agents/LLMAgent.js +0 -31
- package/dist/agents/LLMAgent.js.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Session } from '../types/index.js';
|
|
2
|
+
import type { MemoryIngestionOptions, SearchMemoryRequest, SearchMemoryResponse } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for cross-session long-term memory.
|
|
5
|
+
*
|
|
6
|
+
* MemoryService is the counterpart to SessionStore:
|
|
7
|
+
* - SessionStore manages per-session state (messages, workingMemory, agentStates)
|
|
8
|
+
* - MemoryService manages cross-session knowledge (facts, summaries, preferences)
|
|
9
|
+
*
|
|
10
|
+
* The service has two responsibilities:
|
|
11
|
+
* 1. Ingestion — converting session data into searchable memories
|
|
12
|
+
* 2. Retrieval — finding relevant memories for a given query
|
|
13
|
+
*/
|
|
14
|
+
export interface MemoryService {
|
|
15
|
+
/**
|
|
16
|
+
* Ingest a session into long-term memory.
|
|
17
|
+
*
|
|
18
|
+
* Typically called when a session ends or reaches a meaningful checkpoint.
|
|
19
|
+
* Implementations may store raw events, extract facts via LLM, or summarize.
|
|
20
|
+
* A session may be ingested multiple times (implementations must handle idempotency).
|
|
21
|
+
*
|
|
22
|
+
* @param session - The session to ingest
|
|
23
|
+
* @param options - Optional ingestion configuration
|
|
24
|
+
*/
|
|
25
|
+
addSessionToMemory(session: Session, options?: MemoryIngestionOptions): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Search long-term memory for relevant context.
|
|
28
|
+
*
|
|
29
|
+
* Returns memories scoped to a specific user within an application context.
|
|
30
|
+
* Implementations may use keyword matching, semantic search, or hybrid approaches.
|
|
31
|
+
*
|
|
32
|
+
* @param request - Search parameters (userId, query, optional filters)
|
|
33
|
+
*/
|
|
34
|
+
searchMemory(request: SearchMemoryRequest): Promise<SearchMemoryResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* Delete all memories for a user. Used for GDPR compliance / data cleanup.
|
|
37
|
+
*/
|
|
38
|
+
deleteMemories?(userId: string): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=MemoryService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryService.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEpG;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;OASG;IACH,kBAAkB,CAChB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB;;;;;;;OAOG;IACH,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAE1E;;OAEG;IACH,cAAc,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryService.js","sourceRoot":"","sources":["../../src/memory/MemoryService.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { MemoryService } from './MemoryService.js';
|
|
2
|
+
export type { MemoryEntry, SearchMemoryRequest, SearchMemoryResponse, MemoryIngestionOptions, } from './types.js';
|
|
3
|
+
export { InMemoryMemoryService } from './stores/InMemoryMemoryService.js';
|
|
4
|
+
export { preloadMemoryContext } from './preloadMemory.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Session } from '../types/index.js';
|
|
2
|
+
import type { MemoryService } from './MemoryService.js';
|
|
3
|
+
/**
|
|
4
|
+
* Preloads relevant memories into the system prompt before each LLM call.
|
|
5
|
+
*
|
|
6
|
+
* This is NOT a tool the LLM calls. It is a Runtime-level middleware that:
|
|
7
|
+
* 1. Takes the user's latest message as a search query
|
|
8
|
+
* 2. Searches long-term memory for relevant context
|
|
9
|
+
* 3. Formats matching memories as a markdown section
|
|
10
|
+
* 4. Truncates the output to fit within the allocated token budget
|
|
11
|
+
*
|
|
12
|
+
* The maxTokens parameter is mandatory. If the formatted output exceeds
|
|
13
|
+
* maxTokens, memories are dropped in lowest-relevance-first order until
|
|
14
|
+
* the output fits.
|
|
15
|
+
*/
|
|
16
|
+
export declare function preloadMemoryContext(memoryService: MemoryService, session: Session, userInput: string, maxTokens: number): Promise<string | null>;
|
|
17
|
+
//# sourceMappingURL=preloadMemory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preloadMemory.d.ts","sourceRoot":"","sources":["../../src/memory/preloadMemory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAWxD;;;;;;;;;;;;GAYG;AACH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA2CxB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token estimation function. Matches the estimator used in ContextManager.ts:
|
|
3
|
+
* Math.ceil(text.length / 4).
|
|
4
|
+
*/
|
|
5
|
+
function estimateTokenCount(text) {
|
|
6
|
+
if (!text)
|
|
7
|
+
return 0;
|
|
8
|
+
return Math.ceil(text.length / 4);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Preloads relevant memories into the system prompt before each LLM call.
|
|
12
|
+
*
|
|
13
|
+
* This is NOT a tool the LLM calls. It is a Runtime-level middleware that:
|
|
14
|
+
* 1. Takes the user's latest message as a search query
|
|
15
|
+
* 2. Searches long-term memory for relevant context
|
|
16
|
+
* 3. Formats matching memories as a markdown section
|
|
17
|
+
* 4. Truncates the output to fit within the allocated token budget
|
|
18
|
+
*
|
|
19
|
+
* The maxTokens parameter is mandatory. If the formatted output exceeds
|
|
20
|
+
* maxTokens, memories are dropped in lowest-relevance-first order until
|
|
21
|
+
* the output fits.
|
|
22
|
+
*/
|
|
23
|
+
export async function preloadMemoryContext(memoryService, session, userInput, maxTokens) {
|
|
24
|
+
if (!session.userId)
|
|
25
|
+
return null;
|
|
26
|
+
if (maxTokens <= 0)
|
|
27
|
+
return null;
|
|
28
|
+
const result = await memoryService.searchMemory({
|
|
29
|
+
userId: session.userId,
|
|
30
|
+
query: userInput,
|
|
31
|
+
limit: 10,
|
|
32
|
+
});
|
|
33
|
+
if (result.memories.length === 0)
|
|
34
|
+
return null;
|
|
35
|
+
const headerLines = [
|
|
36
|
+
'## Context from Past Conversations',
|
|
37
|
+
'',
|
|
38
|
+
'The following is from previous conversations with this user.',
|
|
39
|
+
'Use this context to provide continuity and avoid asking for information the user has already provided.',
|
|
40
|
+
'',
|
|
41
|
+
];
|
|
42
|
+
const header = headerLines.join('\n');
|
|
43
|
+
let estimatedTokens = estimateTokenCount(header);
|
|
44
|
+
const includedLines = [];
|
|
45
|
+
for (const m of result.memories) {
|
|
46
|
+
const author = m.author ? `${m.author}: ` : '';
|
|
47
|
+
const date = m.createdAt
|
|
48
|
+
? `[${m.createdAt.toISOString().split('T')[0]}] `
|
|
49
|
+
: '';
|
|
50
|
+
const line = `${date}${author}${m.content}`;
|
|
51
|
+
const lineTokens = estimateTokenCount(line);
|
|
52
|
+
if (estimatedTokens + lineTokens > maxTokens) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
includedLines.push(line);
|
|
56
|
+
estimatedTokens += lineTokens;
|
|
57
|
+
}
|
|
58
|
+
if (includedLines.length === 0)
|
|
59
|
+
return null;
|
|
60
|
+
return header + includedLines.join('\n');
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=preloadMemory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preloadMemory.js","sourceRoot":"","sources":["../../src/memory/preloadMemory.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,SAAS,kBAAkB,CAAC,IAAY;IACtC,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,CAAC;IACpB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,aAA4B,EAC5B,OAAgB,EAChB,SAAiB,EACjB,SAAiB;IAEjB,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACjC,IAAI,SAAS,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAEhC,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,YAAY,CAAC;QAC9C,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,EAAE;KACV,CAAC,CAAC;IAEH,IAAI,MAAM,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} from '../MemoryService.js';
|
|
3
|
+
import type { MemoryIngestionOptions, SearchMemoryRequest, SearchMemoryResponse } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* In-memory implementation of MemoryService for development and testing.
|
|
6
|
+
*
|
|
7
|
+
* Uses keyword-based search with term overlap scoring.
|
|
8
|
+
* All data is stored in-process and lost on restart.
|
|
9
|
+
*/
|
|
10
|
+
export declare class InMemoryMemoryService implements MemoryService {
|
|
11
|
+
/**
|
|
12
|
+
* In-memory storage indexed by userId.
|
|
13
|
+
* Each user has a map of sessionId → MemoryEntry[].
|
|
14
|
+
*/
|
|
15
|
+
private memories;
|
|
16
|
+
addSessionToMemory(session: Session, options?: MemoryIngestionOptions): Promise<void>;
|
|
17
|
+
searchMemory(request: SearchMemoryRequest): Promise<SearchMemoryResponse>;
|
|
18
|
+
deleteMemories(userId: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=InMemoryMemoryService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryMemoryService.d.ts","sourceRoot":"","sources":["../../../src/memory/stores/InMemoryMemoryService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAEV,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AA6BrB;;;;;GAKG;AACH,qBAAa,qBAAsB,YAAW,aAAa;IACzD;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAsD;IAEhE,kBAAkB,CACtB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,IAAI,CAAC;IA2BV,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA2BzE,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGpD"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts plain text from a message content field.
|
|
4
|
+
* Handles both string content and array content parts.
|
|
5
|
+
*/
|
|
6
|
+
function extractTextFromMessage(message) {
|
|
7
|
+
if (typeof message.content === 'string')
|
|
8
|
+
return message.content;
|
|
9
|
+
if (Array.isArray(message.content)) {
|
|
10
|
+
return message.content
|
|
11
|
+
.filter((part) => part.type === 'text')
|
|
12
|
+
.map((part) => part.text)
|
|
13
|
+
.join('\n');
|
|
14
|
+
}
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extracts lowercase words from text as a Set for fast lookup.
|
|
19
|
+
*/
|
|
20
|
+
function extractWordsLower(text) {
|
|
21
|
+
return new Set(text
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.split(/\s+/)
|
|
24
|
+
.filter(Boolean));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* In-memory implementation of MemoryService for development and testing.
|
|
28
|
+
*
|
|
29
|
+
* Uses keyword-based search with term overlap scoring.
|
|
30
|
+
* All data is stored in-process and lost on restart.
|
|
31
|
+
*/
|
|
32
|
+
export class InMemoryMemoryService {
|
|
33
|
+
/**
|
|
34
|
+
* In-memory storage indexed by userId.
|
|
35
|
+
* Each user has a map of sessionId → MemoryEntry[].
|
|
36
|
+
*/
|
|
37
|
+
memories = new Map();
|
|
38
|
+
async addSessionToMemory(session, options) {
|
|
39
|
+
if (!session.userId)
|
|
40
|
+
return;
|
|
41
|
+
const entries = [];
|
|
42
|
+
for (const message of session.messages) {
|
|
43
|
+
if (message.role !== 'user' && message.role !== 'assistant')
|
|
44
|
+
continue;
|
|
45
|
+
const text = extractTextFromMessage(message);
|
|
46
|
+
if (!text.trim())
|
|
47
|
+
continue;
|
|
48
|
+
entries.push({
|
|
49
|
+
id: randomUUID(),
|
|
50
|
+
sessionId: session.id,
|
|
51
|
+
userId: session.userId,
|
|
52
|
+
content: text,
|
|
53
|
+
author: message.role === 'user' ? 'user' : 'assistant',
|
|
54
|
+
metadata: options?.metadata,
|
|
55
|
+
createdAt: new Date(),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Idempotency: delete existing entries for this session before re-ingesting
|
|
59
|
+
const userMemories = this.memories.get(session.userId) ?? new Map();
|
|
60
|
+
userMemories.set(session.id, entries);
|
|
61
|
+
this.memories.set(session.userId, userMemories);
|
|
62
|
+
}
|
|
63
|
+
async searchMemory(request) {
|
|
64
|
+
const userMemories = this.memories.get(request.userId);
|
|
65
|
+
if (!userMemories)
|
|
66
|
+
return { memories: [] };
|
|
67
|
+
const queryWords = extractWordsLower(request.query);
|
|
68
|
+
if (queryWords.size === 0)
|
|
69
|
+
return { memories: [] };
|
|
70
|
+
const matches = [];
|
|
71
|
+
for (const entries of userMemories.values()) {
|
|
72
|
+
for (const entry of entries) {
|
|
73
|
+
const entryWords = extractWordsLower(entry.content);
|
|
74
|
+
let matchCount = 0;
|
|
75
|
+
for (const w of queryWords) {
|
|
76
|
+
if (entryWords.has(w))
|
|
77
|
+
matchCount++;
|
|
78
|
+
}
|
|
79
|
+
if (matchCount > 0) {
|
|
80
|
+
matches.push({ ...entry, score: matchCount / queryWords.size });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Sort by relevance score descending
|
|
85
|
+
matches.sort((a, b) => (b.score ?? 0) - (a.score ?? 0));
|
|
86
|
+
return { memories: matches.slice(0, request.limit ?? 10) };
|
|
87
|
+
}
|
|
88
|
+
async deleteMemories(userId) {
|
|
89
|
+
this.memories.delete(userId);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=InMemoryMemoryService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryMemoryService.js","sourceRoot":"","sources":["../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G,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACpD,IAAI,UAAU,GAAG,CAAC,CAAC;gBACnB,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;oBAC3B,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;wBAAE,UAAU,EAAE,CAAC;gBACtC,CAAC;gBACD,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;oBACnB,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;gBAClE,CAAC;YACH,CAAC;QACH,CAAC;QAED,qCAAqC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;QACxD,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,MAAc;QACjC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the cross-session long-term memory system.
|
|
3
|
+
*
|
|
4
|
+
* These types define the data structures used by MemoryService implementations
|
|
5
|
+
* for storing, searching, and managing cross-session knowledge.
|
|
6
|
+
*/
|
|
7
|
+
export interface MemoryEntry {
|
|
8
|
+
/** Unique identifier for this memory */
|
|
9
|
+
id: string;
|
|
10
|
+
/** The session this memory was derived from */
|
|
11
|
+
sessionId: string;
|
|
12
|
+
/** The user this memory belongs to */
|
|
13
|
+
userId: string;
|
|
14
|
+
/** The memory content (extracted fact, summary, or raw text) */
|
|
15
|
+
content: string;
|
|
16
|
+
/** Who authored the original content: 'user' | 'assistant' | agent name */
|
|
17
|
+
author?: string;
|
|
18
|
+
/** Structured metadata for filtering */
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
/** When the memory was created */
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
/** Relevance score (populated by search, not storage) */
|
|
23
|
+
score?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface SearchMemoryRequest {
|
|
26
|
+
/** Required: whose memories to search */
|
|
27
|
+
userId: string;
|
|
28
|
+
/** The search query */
|
|
29
|
+
query: string;
|
|
30
|
+
/** Max results to return (default: 10) */
|
|
31
|
+
limit?: number;
|
|
32
|
+
/** Optional metadata filters */
|
|
33
|
+
filter?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
export interface SearchMemoryResponse {
|
|
36
|
+
memories: MemoryEntry[];
|
|
37
|
+
}
|
|
38
|
+
export interface MemoryIngestionOptions {
|
|
39
|
+
/** Custom metadata to attach to all memories from this session */
|
|
40
|
+
metadata?: Record<string, unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Ingestion strategy:
|
|
43
|
+
* - 'raw': Store message content as-is (default for InMemoryMemoryService)
|
|
44
|
+
* - 'summarize': Use LLM to summarize the session before storing
|
|
45
|
+
* - 'extract': Use LLM to extract individual facts/entities
|
|
46
|
+
*/
|
|
47
|
+
strategy?: 'raw' | 'summarize' | 'extract';
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,EAAE,EAAE,MAAM,CAAC;IAEX,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAElB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IAEf,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAEhB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,kCAAkC;IAClC,SAAS,EAAE,IAAI,CAAC;IAEhB,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;IAEf,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IAEd,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,KAAK,GAAG,WAAW,GAAG,SAAS,CAAC;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentPrompt — Developer-facing class for structured prompt assembly.
|
|
3
|
+
*
|
|
4
|
+
* Provides a chainable API for composing agent prompts with automatic
|
|
5
|
+
* security sandwiching, priority-based ordering, and XML-tagged rendering.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const prompt = new AgentPrompt()
|
|
10
|
+
* .role('You are a helpful customer support agent.')
|
|
11
|
+
* .instructions('Help customers with billing and account issues.')
|
|
12
|
+
* .guardrails('Never share internal pricing or discount formulas.')
|
|
13
|
+
* .knowledge(async () => fetchKnowledgeBase())
|
|
14
|
+
* .tools(myToolSet);
|
|
15
|
+
*
|
|
16
|
+
* const systemPrompt = await prompt.render();
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import type { ToolSet } from '../tools/Tool.js';
|
|
22
|
+
import type { GlossaryTerm, VoiceRulesConfig, PolicyProfile } from './types.js';
|
|
23
|
+
import { PromptAssembly } from './PromptAssembly.js';
|
|
24
|
+
import type { AssemblyDebugInfo } from './PromptAssembly.js';
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for the AgentPrompt constructor.
|
|
27
|
+
*/
|
|
28
|
+
export interface AgentPromptConfig {
|
|
29
|
+
/** Security policy profile. Defaults to 'minimal'. */
|
|
30
|
+
policy?: PolicyProfile;
|
|
31
|
+
/** Whether to wrap sections in XML tags. Defaults to true. */
|
|
32
|
+
xmlTags?: boolean;
|
|
33
|
+
/** Maximum token budget for the rendered prompt. */
|
|
34
|
+
maxTokens?: number;
|
|
35
|
+
/** Disable automatic security core and reminder sections. Defaults to false. */
|
|
36
|
+
disableSecurity?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Developer-facing prompt builder with a chainable API.
|
|
40
|
+
*
|
|
41
|
+
* Internally creates a {@link PromptAssembly}, injects security core (priority 0)
|
|
42
|
+
* and security reminder (priority 1000), then freezes security bands.
|
|
43
|
+
*
|
|
44
|
+
* All chainable methods accept either a static string or an async function
|
|
45
|
+
* that resolves to a string.
|
|
46
|
+
*/
|
|
47
|
+
export declare class AgentPrompt {
|
|
48
|
+
private readonly _assembly;
|
|
49
|
+
private readonly renderOptions;
|
|
50
|
+
constructor(config?: AgentPromptConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Sets the agent's role description. Priority 10, non-shrinkable.
|
|
53
|
+
*/
|
|
54
|
+
role(content: string | (() => Promise<string>)): this;
|
|
55
|
+
/**
|
|
56
|
+
* Sets the agent's instructions. Priority 15, non-shrinkable.
|
|
57
|
+
*/
|
|
58
|
+
instructions(content: string | (() => Promise<string>)): this;
|
|
59
|
+
/**
|
|
60
|
+
* Sets guardrail rules. Priority 20, non-shrinkable.
|
|
61
|
+
*/
|
|
62
|
+
guardrails(content: string | (() => Promise<string>)): this;
|
|
63
|
+
/**
|
|
64
|
+
* Sets voice/personality description. Priority 25, shrinkable.
|
|
65
|
+
*/
|
|
66
|
+
voice(content: string | (() => Promise<string>)): this;
|
|
67
|
+
/**
|
|
68
|
+
* Injects knowledge context. Priority 30, shrinkable.
|
|
69
|
+
*/
|
|
70
|
+
knowledge(content: string | (() => Promise<string>)): this;
|
|
71
|
+
/**
|
|
72
|
+
* Sets business/domain rules. Priority 35, shrinkable.
|
|
73
|
+
*/
|
|
74
|
+
rules(content: string | (() => Promise<string>)): this;
|
|
75
|
+
/**
|
|
76
|
+
* Adds a glossary of domain terms. Priority 38, shrinkable.
|
|
77
|
+
* Terms are auto-formatted into a structured list.
|
|
78
|
+
*/
|
|
79
|
+
glossary(terms: GlossaryTerm[]): this;
|
|
80
|
+
/**
|
|
81
|
+
* Generates tool descriptions from a ToolSet. Priority 40, shrinkable.
|
|
82
|
+
*/
|
|
83
|
+
tools(toolSet: ToolSet): this;
|
|
84
|
+
/**
|
|
85
|
+
* Sets voice/TTS output rules. Priority 45, shrinkable.
|
|
86
|
+
* Uses the same formatting logic as PromptTemplateBuilder.formatVoiceRules.
|
|
87
|
+
*/
|
|
88
|
+
voiceRules(config: VoiceRulesConfig): this;
|
|
89
|
+
/**
|
|
90
|
+
* Adds example interactions or few-shot prompts. Priority 50, shrinkable.
|
|
91
|
+
*/
|
|
92
|
+
examples(content: string | (() => Promise<string>)): this;
|
|
93
|
+
/**
|
|
94
|
+
* Adds an arbitrary named section. Defaults to priority 60, shrinkable.
|
|
95
|
+
*/
|
|
96
|
+
section(type: string, content: string | (() => Promise<string>), priority?: number): this;
|
|
97
|
+
/**
|
|
98
|
+
* Resolves all sections and renders the prompt to a string.
|
|
99
|
+
*/
|
|
100
|
+
render(): Promise<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns debug information about the assembly's current state.
|
|
103
|
+
*/
|
|
104
|
+
debug(): Promise<AssemblyDebugInfo>;
|
|
105
|
+
/**
|
|
106
|
+
* Exposes the underlying PromptAssembly for runtime injection.
|
|
107
|
+
*/
|
|
108
|
+
get assembly(): PromptAssembly;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=AgentPrompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentPrompt.d.ts","sourceRoot":"","sources":["../../src/prompts/AgentPrompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQ7D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sDAAsD;IACtD,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAMD;;;;;;;;GAQG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAC3C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;gBAElC,MAAM,GAAE,iBAAsB;IA0C1C;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,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