@memberjunction/ai-agents 5.48.0 → 5.49.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 +14 -0
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +5 -0
- package/dist/AgentRunner.js.map +1 -1
- package/dist/ConversationCompactionManager.d.ts +198 -0
- package/dist/ConversationCompactionManager.d.ts.map +1 -0
- package/dist/ConversationCompactionManager.js +384 -0
- package/dist/ConversationCompactionManager.js.map +1 -0
- package/dist/ConversationToolManager.d.ts +154 -0
- package/dist/ConversationToolManager.d.ts.map +1 -0
- package/dist/ConversationToolManager.js +336 -0
- package/dist/ConversationToolManager.js.map +1 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts +8 -0
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +1 -0
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +10 -1
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +23 -34
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +75 -2
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +314 -4
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +869 -92
- package/dist/base-agent.js.map +1 -1
- package/dist/conversation-history-format.d.ts +19 -0
- package/dist/conversation-history-format.d.ts.map +1 -0
- package/dist/conversation-history-format.js +40 -0
- package/dist/conversation-history-format.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/prior-turn-tool-result-cache.d.ts +71 -0
- package/dist/prior-turn-tool-result-cache.d.ts.map +1 -0
- package/dist/prior-turn-tool-result-cache.js +85 -0
- package/dist/prior-turn-tool-result-cache.js.map +1 -0
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +7 -3
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts +41 -0
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +69 -0
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-session-runner.d.ts +72 -1
- package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
- package/dist/realtime/realtime-session-runner.js +215 -13
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-tool-broker.d.ts +7 -2
- package/dist/realtime/realtime-tool-broker.d.ts.map +1 -1
- package/dist/realtime/realtime-tool-broker.js +13 -10
- package/dist/realtime/realtime-tool-broker.js.map +1 -1
- package/dist/tool-result-format.d.ts +78 -0
- package/dist/tool-result-format.d.ts.map +1 -0
- package/dist/tool-result-format.js +46 -0
- package/dist/tool-result-format.js.map +1 -0
- package/package.json +18 -18
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Conversation-history retrieval tools (RLM-style addressable paging).
|
|
3
|
+
*
|
|
4
|
+
* The cross-turn summary (see ConversationCompactionManager) is deliberately lossy — a
|
|
5
|
+
* compact handle over history that has left the context window. These tools are the
|
|
6
|
+
* other half of the design (plans/agent-conversation-compaction.md §5): the full
|
|
7
|
+
* history stays in an addressable external store (ConversationDetail rows keyed by the
|
|
8
|
+
* persisted per-conversation `Sequence`), and the agent pages exact slices back in on
|
|
9
|
+
* demand instead of trusting the summary. Zero turn cost — calls ride the
|
|
10
|
+
* `conversationToolCalls` inline response field, mirroring `artifactToolCalls`.
|
|
11
|
+
*
|
|
12
|
+
* All reads are served from `ConversationEngine`'s per-conversation cache (one query on
|
|
13
|
+
* a cold miss, in-memory afterward).
|
|
14
|
+
*
|
|
15
|
+
* @module @memberjunction/ai-agents
|
|
16
|
+
*/
|
|
17
|
+
import { ConversationEngine } from '@memberjunction/core-entities';
|
|
18
|
+
import { FormatSequencedHistoryLine } from './conversation-history-format.js';
|
|
19
|
+
/**
|
|
20
|
+
* The conversation-tool name vocabulary — single source of truth. The LLM is taught these
|
|
21
|
+
* exact strings (GetToolDocumentation + the loop-agent system template's response-type
|
|
22
|
+
* union), the dispatch switch matches them, and framework guidance messages enumerate them.
|
|
23
|
+
* Add/rename tools HERE; everything else derives from this array.
|
|
24
|
+
*/
|
|
25
|
+
export const ConversationToolNames = ['getMessageBySequence', 'getMessagesByRange', 'searchConversation', 'summarizeRange'];
|
|
26
|
+
/** Hard cap on messages returned by getMessagesByRange. */
|
|
27
|
+
const MAX_RANGE_MESSAGES = 50;
|
|
28
|
+
/** Hard cap on the span a single summarizeRange sub-call may cover. */
|
|
29
|
+
const MAX_SUMMARIZE_RANGE_MESSAGES = 500;
|
|
30
|
+
/** Character budget for the rendered slice fed to the summarizeRange sub-call. */
|
|
31
|
+
const MAX_SUMMARIZE_INPUT_CHARS = 100_000;
|
|
32
|
+
/** Total character budget for a range result — beyond it, messages are dropped with a note. */
|
|
33
|
+
const MAX_RANGE_TOTAL_CHARS = 32_000;
|
|
34
|
+
/** searchConversation result caps. */
|
|
35
|
+
const DEFAULT_SEARCH_RESULTS = 20;
|
|
36
|
+
const MAX_SEARCH_RESULTS = 50;
|
|
37
|
+
/** Snippet length around a search match. */
|
|
38
|
+
const SNIPPET_CHARS = 300;
|
|
39
|
+
/**
|
|
40
|
+
* Max characters for a searchConversation regex pattern. The pattern is model-authored
|
|
41
|
+
* (and thus prompt-injection-steerable) — a length cap is the first line of ReDoS
|
|
42
|
+
* surface control before it ever reaches `new RegExp`.
|
|
43
|
+
*/
|
|
44
|
+
const MAX_SEARCH_PATTERN_CHARS = 256;
|
|
45
|
+
/**
|
|
46
|
+
* Per-message haystack cap for REGEX matching: patterns run against at most this many
|
|
47
|
+
* characters of a message body (keyword search stays uncapped — indexOf is linear-safe).
|
|
48
|
+
* Bounds the per-call work a pathological pattern can do against one huge message.
|
|
49
|
+
*/
|
|
50
|
+
const MAX_SEARCH_HAYSTACK_CHARS = 20_000;
|
|
51
|
+
/**
|
|
52
|
+
* Total wall-clock budget for one search scan. Checked between messages — it cannot
|
|
53
|
+
* interrupt a single pathological `match()` call (that would need RE2 or a worker
|
|
54
|
+
* thread, both disproportionate here); together with the pattern/haystack caps it
|
|
55
|
+
* bounds the blast radius to "one slow call, contained per-call".
|
|
56
|
+
*/
|
|
57
|
+
const MAX_SEARCH_SCAN_MS = 2_000;
|
|
58
|
+
/**
|
|
59
|
+
* Max conversationToolCalls executed per LLM response. Each call is a run step (and
|
|
60
|
+
* summarizeRange is a full LLM sub-call) — an unbounded Promise.all would let a single
|
|
61
|
+
* response fan out arbitrary work/cost. Excess calls are reported back to the model as
|
|
62
|
+
* skipped so it can re-request them next turn. Consumed by BaseAgent's executor.
|
|
63
|
+
*/
|
|
64
|
+
export const MAX_CONVERSATION_TOOL_CALLS_PER_TURN = 8;
|
|
65
|
+
/**
|
|
66
|
+
* Per-run manager for conversation-history retrieval tools. Initialized with the run's
|
|
67
|
+
* conversationId (the availability gate — no conversation, no tools) and serving all
|
|
68
|
+
* reads from the ConversationEngine cache.
|
|
69
|
+
*/
|
|
70
|
+
export class ConversationToolManager {
|
|
71
|
+
constructor() {
|
|
72
|
+
this.conversationId = null;
|
|
73
|
+
this.contextUser = null;
|
|
74
|
+
this.summaryHost = null;
|
|
75
|
+
}
|
|
76
|
+
/** Arms the manager for a run. Pass null conversationId to disable (programmatic runs). */
|
|
77
|
+
Initialize(conversationId, contextUser) {
|
|
78
|
+
this.conversationId = conversationId;
|
|
79
|
+
this.contextUser = contextUser;
|
|
80
|
+
}
|
|
81
|
+
/** Wires the recursive-sub-call seam (BaseAgent owns prompt execution). */
|
|
82
|
+
SetSummaryHost(host) {
|
|
83
|
+
this.summaryHost = host;
|
|
84
|
+
}
|
|
85
|
+
/** Disarms the manager (per-run reset). */
|
|
86
|
+
Clear() {
|
|
87
|
+
this.conversationId = null;
|
|
88
|
+
this.contextUser = null;
|
|
89
|
+
this.summaryHost = null;
|
|
90
|
+
}
|
|
91
|
+
/** True when the run has a conversation to page against. */
|
|
92
|
+
get IsAvailable() {
|
|
93
|
+
return !!this.conversationId && !!this.contextUser;
|
|
94
|
+
}
|
|
95
|
+
/** Executes one tool call with timing + full error containment. */
|
|
96
|
+
async ExecuteSingleToolCall(call) {
|
|
97
|
+
const start = Date.now();
|
|
98
|
+
try {
|
|
99
|
+
const { data, promptRunId } = await this.dispatch(call);
|
|
100
|
+
return { tool: call.tool, input: call.input, result: { success: true, data }, durationMs: Date.now() - start, promptRunId };
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
104
|
+
return { tool: call.tool, input: call.input, result: { success: false, errorMessage }, durationMs: Date.now() - start };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Markdown tool documentation injected into the system prompt (the
|
|
109
|
+
* `{{ _CONVERSATION_TOOLS }}` template block), rendered only when the run has a
|
|
110
|
+
* conversation.
|
|
111
|
+
*/
|
|
112
|
+
GetToolDocumentation() {
|
|
113
|
+
return [
|
|
114
|
+
'## Conversation History Tools',
|
|
115
|
+
'Older parts of this conversation may have been replaced by a summary. The FULL history remains stored, addressable by the `[seq N]` sequence numbers the summary references. Page exact messages back in with `conversationToolCalls` in your response — results arrive as a conversation message on your next turn. Prefer paging in exact messages over trusting the summary for precise wording, identifiers, numbers, or decisions.',
|
|
116
|
+
'',
|
|
117
|
+
'| tool | input | returns |',
|
|
118
|
+
'|---|---|---|',
|
|
119
|
+
'| `getMessageBySequence` | `{ "sequence": 42 }` | the exact message at that sequence |',
|
|
120
|
+
`| \`getMessagesByRange\` | \`{ "startSequence": 10, "endSequence": 20 }\` | the messages in the inclusive range (max ${MAX_RANGE_MESSAGES}) |`,
|
|
121
|
+
`| \`searchConversation\` | \`{ "query": "text or regex", "isRegex"?: true, "role"?: "User"\\|"AI", "startSequence"?, "endSequence"?, "maxResults"? }\` | matching hits as \`{sequence, role, agent, snippet}\` (default ${DEFAULT_SEARCH_RESULTS}) — then page the hits you need |`,
|
|
122
|
+
`| \`summarizeRange\` | \`{ "startSequence": 1, "endSequence": 120, "lens": "what the summary should focus on" }\` | a focused summary of the range through YOUR lens (max ${MAX_SUMMARIZE_RANGE_MESSAGES} messages) — use when a range is too big to page in raw |`,
|
|
123
|
+
'',
|
|
124
|
+
'',
|
|
125
|
+
`Max ${MAX_CONVERSATION_TOOL_CALLS_PER_TURN} tool calls per response — excess calls are skipped and reported back; re-request them on your next turn.`,
|
|
126
|
+
'',
|
|
127
|
+
'Example: `"conversationToolCalls": [{ "tool": "searchConversation", "input": { "query": "budget approval" } }]`'
|
|
128
|
+
].join('\n');
|
|
129
|
+
}
|
|
130
|
+
/** Routes a call to its tool implementation. */
|
|
131
|
+
async dispatch(call) {
|
|
132
|
+
const details = await this.loadOrderedDetails();
|
|
133
|
+
switch (call.tool) {
|
|
134
|
+
case 'getMessageBySequence':
|
|
135
|
+
return { data: this.getMessageBySequence(details, call.input) };
|
|
136
|
+
case 'getMessagesByRange':
|
|
137
|
+
return { data: this.getMessagesByRange(details, call.input) };
|
|
138
|
+
case 'searchConversation':
|
|
139
|
+
return { data: this.searchConversation(details, call.input) };
|
|
140
|
+
case 'summarizeRange':
|
|
141
|
+
return this.summarizeRange(details, call.input);
|
|
142
|
+
default:
|
|
143
|
+
throw new Error(`Unknown conversation tool '${call.tool}'`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The recursive sub-call (RLM pattern): renders the requested slice and hands it to
|
|
148
|
+
* the host's summary prompt with the caller's lens. The agent is not limited to the
|
|
149
|
+
* one baseline summary's framing — any window can be re-summarized however the
|
|
150
|
+
* current task needs, on a cheap sub-call model.
|
|
151
|
+
*/
|
|
152
|
+
async summarizeRange(details, input) {
|
|
153
|
+
if (!this.summaryHost) {
|
|
154
|
+
throw new Error('summarizeRange is unavailable: no summary host is wired for this run');
|
|
155
|
+
}
|
|
156
|
+
const { startSequence, endSequence } = input;
|
|
157
|
+
if (typeof startSequence !== 'number' || typeof endSequence !== 'number' || startSequence > endSequence) {
|
|
158
|
+
throw new Error(`summarizeRange requires numeric 'startSequence' <= 'endSequence'`);
|
|
159
|
+
}
|
|
160
|
+
if (!input.lens || input.lens.trim().length === 0) {
|
|
161
|
+
throw new Error(`summarizeRange requires a 'lens' describing what the summary should focus on`);
|
|
162
|
+
}
|
|
163
|
+
if (endSequence - startSequence + 1 > MAX_SUMMARIZE_RANGE_MESSAGES) {
|
|
164
|
+
throw new Error(`Range spans ${endSequence - startSequence + 1} messages — max ${MAX_SUMMARIZE_RANGE_MESSAGES} per summarizeRange call`);
|
|
165
|
+
}
|
|
166
|
+
const inRange = details.filter(d => d.Sequence >= startSequence && d.Sequence <= endSequence);
|
|
167
|
+
if (inRange.length === 0) {
|
|
168
|
+
throw new Error(`No messages found in sequence range ${startSequence}..${endSequence}`);
|
|
169
|
+
}
|
|
170
|
+
const rangeText = this.renderRangeForSummary(inRange);
|
|
171
|
+
const summary = await this.summaryHost.RunSummaryPrompt(rangeText, input.lens.trim());
|
|
172
|
+
return {
|
|
173
|
+
data: {
|
|
174
|
+
lens: input.lens.trim(),
|
|
175
|
+
startSequence,
|
|
176
|
+
endSequence,
|
|
177
|
+
messageCount: inRange.length,
|
|
178
|
+
summary: summary.text
|
|
179
|
+
},
|
|
180
|
+
promptRunId: summary.promptRunId
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** `[seq N] Role: text` rendering (shared shape) with a total input budget for the sub-call model. */
|
|
184
|
+
renderRangeForSummary(details) {
|
|
185
|
+
const lines = [];
|
|
186
|
+
let usedChars = 0;
|
|
187
|
+
for (const detail of details) {
|
|
188
|
+
const line = FormatSequencedHistoryLine(detail.Sequence, detail.Role, detail.Message || '');
|
|
189
|
+
usedChars += line.length;
|
|
190
|
+
if (usedChars > MAX_SUMMARIZE_INPUT_CHARS && lines.length > 0) {
|
|
191
|
+
lines.push(`[input capped at ~${MAX_SUMMARIZE_INPUT_CHARS.toLocaleString('en-US')} characters — messages from sequence ${detail.Sequence} onward omitted; summarize a narrower range to cover them]`);
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
lines.push(line);
|
|
195
|
+
}
|
|
196
|
+
return lines.join('\n');
|
|
197
|
+
}
|
|
198
|
+
/** Full conversation history, ordered by Sequence, from the engine cache. */
|
|
199
|
+
async loadOrderedDetails() {
|
|
200
|
+
if (!this.conversationId || !this.contextUser) {
|
|
201
|
+
throw new Error('Conversation tools are unavailable: no conversation is associated with this run');
|
|
202
|
+
}
|
|
203
|
+
const cache = await ConversationEngine.Instance.LoadConversationDetails(this.conversationId, this.contextUser);
|
|
204
|
+
return [...cache.Details].sort((a, b) => a.Sequence - b.Sequence);
|
|
205
|
+
}
|
|
206
|
+
getMessageBySequence(details, input) {
|
|
207
|
+
if (typeof input.sequence !== 'number') {
|
|
208
|
+
throw new Error(`getMessageBySequence requires a numeric 'sequence' input`);
|
|
209
|
+
}
|
|
210
|
+
const detail = details.find(d => d.Sequence === input.sequence);
|
|
211
|
+
if (!detail) {
|
|
212
|
+
throw new Error(`No message found at sequence ${input.sequence} (valid range: 1..${details.length > 0 ? details[details.length - 1].Sequence : 0})`);
|
|
213
|
+
}
|
|
214
|
+
return this.toToolMessage(detail);
|
|
215
|
+
}
|
|
216
|
+
getMessagesByRange(details, input) {
|
|
217
|
+
const { startSequence, endSequence } = input;
|
|
218
|
+
if (typeof startSequence !== 'number' || typeof endSequence !== 'number' || startSequence > endSequence) {
|
|
219
|
+
throw new Error(`getMessagesByRange requires numeric 'startSequence' <= 'endSequence'`);
|
|
220
|
+
}
|
|
221
|
+
if (endSequence - startSequence + 1 > MAX_RANGE_MESSAGES) {
|
|
222
|
+
throw new Error(`Range spans ${endSequence - startSequence + 1} messages — max ${MAX_RANGE_MESSAGES} per call. Narrow the range or make multiple calls.`);
|
|
223
|
+
}
|
|
224
|
+
const inRange = details.filter(d => d.Sequence >= startSequence && d.Sequence <= endSequence);
|
|
225
|
+
// Enforce the total-character budget so one range call can't blow the context.
|
|
226
|
+
const messages = [];
|
|
227
|
+
let usedChars = 0;
|
|
228
|
+
for (const detail of inRange) {
|
|
229
|
+
const message = this.toToolMessage(detail);
|
|
230
|
+
usedChars += message.message.length;
|
|
231
|
+
if (usedChars > MAX_RANGE_TOTAL_CHARS && messages.length > 0) {
|
|
232
|
+
return {
|
|
233
|
+
messages,
|
|
234
|
+
truncated: `Result capped at ~${MAX_RANGE_TOTAL_CHARS.toLocaleString('en-US')} characters — ${inRange.length - messages.length} message(s) from sequence ${message.sequence} onward omitted. Request a narrower range to read them.`
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
messages.push(message);
|
|
238
|
+
}
|
|
239
|
+
return { messages };
|
|
240
|
+
}
|
|
241
|
+
searchConversation(details, input) {
|
|
242
|
+
if (!input.query || input.query.trim().length === 0) {
|
|
243
|
+
throw new Error(`searchConversation requires a non-empty 'query'`);
|
|
244
|
+
}
|
|
245
|
+
const maxResults = Math.min(input.maxResults || DEFAULT_SEARCH_RESULTS, MAX_SEARCH_RESULTS);
|
|
246
|
+
const matchType = input.isRegex ? 'regex' : 'keyword';
|
|
247
|
+
const regex = this.compileSearchRegex(input.query, input.isRegex);
|
|
248
|
+
const needle = input.query.toLowerCase();
|
|
249
|
+
const hits = [];
|
|
250
|
+
let totalMatches = 0;
|
|
251
|
+
let anyHaystackCapped = false;
|
|
252
|
+
let warning;
|
|
253
|
+
const deadline = Date.now() + MAX_SEARCH_SCAN_MS;
|
|
254
|
+
for (const detail of details) {
|
|
255
|
+
// Wall-clock budget checked between messages — bounds the total scan a
|
|
256
|
+
// model-authored pattern can consume on the event loop (see the
|
|
257
|
+
// MAX_SEARCH_SCAN_MS doc for what this deliberately cannot bound).
|
|
258
|
+
if (Date.now() > deadline) {
|
|
259
|
+
warning = `Search stopped after ${MAX_SEARCH_SCAN_MS}ms — results are partial (stopped before sequence ${detail.Sequence}). Narrow the sequence range or simplify the pattern.`;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
if (!this.passesSearchFilters(detail, input))
|
|
263
|
+
continue;
|
|
264
|
+
const text = detail.Message || '';
|
|
265
|
+
// Regex mode matches a capped slice of long messages (keyword indexOf is
|
|
266
|
+
// linear-safe and stays uncapped); snippets still render from full text.
|
|
267
|
+
let haystack = text;
|
|
268
|
+
if (regex && text.length > MAX_SEARCH_HAYSTACK_CHARS) {
|
|
269
|
+
haystack = text.slice(0, MAX_SEARCH_HAYSTACK_CHARS);
|
|
270
|
+
anyHaystackCapped = true;
|
|
271
|
+
}
|
|
272
|
+
// `??` (not the usual `||` fallback) — a match at index 0 is a valid hit
|
|
273
|
+
const matchIndex = regex ? (haystack.match(regex)?.index ?? -1) : text.toLowerCase().indexOf(needle);
|
|
274
|
+
if (matchIndex < 0)
|
|
275
|
+
continue;
|
|
276
|
+
totalMatches++;
|
|
277
|
+
if (hits.length < maxResults) {
|
|
278
|
+
hits.push({
|
|
279
|
+
sequence: detail.Sequence,
|
|
280
|
+
role: detail.Role || '',
|
|
281
|
+
agent: detail.Agent || null,
|
|
282
|
+
snippet: this.buildSnippet(text, matchIndex),
|
|
283
|
+
matchType
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (anyHaystackCapped && !warning) {
|
|
288
|
+
warning = `Regex matching was limited to the first ${MAX_SEARCH_HAYSTACK_CHARS.toLocaleString('en-US')} characters of long messages — a match deeper in such a message would not be found. Page the message in by sequence to inspect it fully.`;
|
|
289
|
+
}
|
|
290
|
+
return warning ? { hits, totalMatches, warning } : { hits, totalMatches };
|
|
291
|
+
}
|
|
292
|
+
/** Compiles the query as a case-insensitive regex in regex mode; null in keyword mode. */
|
|
293
|
+
compileSearchRegex(query, isRegex) {
|
|
294
|
+
if (!isRegex) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
if (query.length > MAX_SEARCH_PATTERN_CHARS) {
|
|
298
|
+
throw new Error(`Regex pattern is ${query.length} characters — max ${MAX_SEARCH_PATTERN_CHARS}. Use a shorter pattern or keyword search.`);
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
return new RegExp(query, 'i');
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
throw new Error(`Invalid regular expression '${query}': ${error instanceof Error ? error.message : error}`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/** Role and sequence-range filters applied to every candidate message in a search. */
|
|
308
|
+
passesSearchFilters(detail, input) {
|
|
309
|
+
const roleFilter = input.role?.toLowerCase();
|
|
310
|
+
if (roleFilter && (detail.Role || '').toLowerCase() !== roleFilter)
|
|
311
|
+
return false;
|
|
312
|
+
if (typeof input.startSequence === 'number' && detail.Sequence < input.startSequence)
|
|
313
|
+
return false;
|
|
314
|
+
if (typeof input.endSequence === 'number' && detail.Sequence > input.endSequence)
|
|
315
|
+
return false;
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
/** A ~300-char window centered on the match, with ellipses at cut edges. */
|
|
319
|
+
buildSnippet(text, matchIndex) {
|
|
320
|
+
const half = Math.floor(SNIPPET_CHARS / 2);
|
|
321
|
+
const start = Math.max(0, matchIndex - half);
|
|
322
|
+
const end = Math.min(text.length, start + SNIPPET_CHARS);
|
|
323
|
+
const prefix = start > 0 ? '…' : '';
|
|
324
|
+
const suffix = end < text.length ? '…' : '';
|
|
325
|
+
return `${prefix}${text.slice(start, end)}${suffix}`;
|
|
326
|
+
}
|
|
327
|
+
toToolMessage(detail) {
|
|
328
|
+
return {
|
|
329
|
+
sequence: detail.Sequence,
|
|
330
|
+
role: detail.Role || '',
|
|
331
|
+
agent: detail.Agent || null,
|
|
332
|
+
message: detail.Message || ''
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=ConversationToolManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConversationToolManager.js","sourceRoot":"","sources":["../src/ConversationToolManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,kBAAkB,EAA8B,MAAM,+BAA+B,CAAC;AAC/F,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,sBAAsB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gBAAgB,CAAU,CAAC;AA8ErI,2DAA2D;AAC3D,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,uEAAuE;AACvE,MAAM,4BAA4B,GAAG,GAAG,CAAC;AACzC,kFAAkF;AAClF,MAAM,yBAAyB,GAAG,OAAO,CAAC;AAC1C,+FAA+F;AAC/F,MAAM,qBAAqB,GAAG,MAAM,CAAC;AACrC,sCAAsC;AACtC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,4CAA4C;AAC5C,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B;;;;GAIG;AACH,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,MAAM,CAAC;AACzC;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,CAAC;AAEtD;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAApC;QACY,mBAAc,GAAkB,IAAI,CAAC;QACrC,gBAAW,GAAoB,IAAI,CAAC;QACpC,gBAAW,GAAuC,IAAI,CAAC;IAsRnE,CAAC;IApRG,2FAA2F;IACpF,UAAU,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,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC;IACzD,CAAC;IAEO,aAAa,CAAC,MAAkC;QACpD,OAAO;YACH,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;YACvB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI;YAC3B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;SAChC,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -243,6 +243,14 @@ export interface LoopAgentTypePromptParams {
|
|
|
243
243
|
* @default true
|
|
244
244
|
*/
|
|
245
245
|
includeArtifactToolsDocs?: boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Include conversation-history retrieval tool documentation in the prompt (the
|
|
248
|
+
* `_CONVERSATION_TOOLS` block). Only emitted when the run has a conversationId —
|
|
249
|
+
* these tools page exact pre-summary messages back in by their persisted Sequence
|
|
250
|
+
* handles. Disable for agents that should never dig into conversation history.
|
|
251
|
+
* @default true
|
|
252
|
+
*/
|
|
253
|
+
includeConversationToolsDocs?: boolean;
|
|
246
254
|
/**
|
|
247
255
|
* Include tool-pipeline documentation in the prompt (the `_PIPELINE_TOOLS` block).
|
|
248
256
|
* Only emitted when at least one pipeline source — an Action or artifact tool — is available.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-agent-prompt-params.d.ts","sourceRoot":"","sources":["../../src/agent-types/loop-agent-prompt-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,0BAA0B;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAEl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CAAC;CAC/B;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,yBAAyB,
|
|
1
|
+
{"version":3,"file":"loop-agent-prompt-params.d.ts","sourceRoot":"","sources":["../../src/agent-types/loop-agent-prompt-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,0BAA0B;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,eAAO,MAAM,qCAAqC,EAAE,QAAQ,CAAC,0BAA0B,CAStF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,WAAW,yBAAyB;IAGtC;;;;;;;;;OASG;IACH,6BAA6B,CAAC,EAAE,0BAA0B,CAAC;IAE3D;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;OAOG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC;;;;;OAKG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;;;;OAMG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;;;;;OAMG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;IAEvC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAI9B;;;;;;;OAOG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,yBAAyB,CAiBhF,CAAC"}
|
|
@@ -50,6 +50,7 @@ export const DEFAULT_LOOP_AGENT_PROMPT_PARAMS = {
|
|
|
50
50
|
includeScratchpadDocs: true,
|
|
51
51
|
scratchpadMaxTasks: 50,
|
|
52
52
|
includeArtifactToolsDocs: true,
|
|
53
|
+
includeConversationToolsDocs: true,
|
|
53
54
|
includePipelineDocs: true,
|
|
54
55
|
maxSubAgentsInPrompt: -1,
|
|
55
56
|
maxActionsInPrompt: -1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-agent-prompt-params.js","sourceRoot":"","sources":["../../src/agent-types/loop-agent-prompt-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AA+EH;;;GAGG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAyC;IACvF,OAAO,EAAE,IAAI;IACb,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,IAAI;IAChB,iBAAiB,EAAE,IAAI;IACvB,QAAQ,EAAE,IAAI;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"loop-agent-prompt-params.js","sourceRoot":"","sources":["../../src/agent-types/loop-agent-prompt-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AA+EH;;;GAGG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAyC;IACvF,OAAO,EAAE,IAAI;IACb,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,IAAI;IAChB,iBAAiB,EAAE,IAAI;IACvB,QAAQ,EAAE,IAAI;CACjB,CAAC;AAgNF;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAwC;IACjF,6BAA6B,EAAE,EAAE,GAAG,qCAAqC,EAAE;IAC3E,kBAAkB,EAAE,IAAI;IACxB,gBAAgB,EAAE,IAAI;IACtB,uBAAuB,EAAE,IAAI;IAC7B,kBAAkB,EAAE,IAAI;IACxB,2BAA2B,EAAE,IAAI;IACjC,uBAAuB,EAAE,IAAI;IAC7B,sBAAsB,EAAE,IAAI;IAC5B,uBAAuB,EAAE,IAAI;IAC7B,qBAAqB,EAAE,IAAI;IAC3B,kBAAkB,EAAE,EAAE;IACtB,wBAAwB,EAAE,IAAI;IAC9B,4BAA4B,EAAE,IAAI;IAClC,mBAAmB,EAAE,IAAI;IACzB,oBAAoB,EAAE,CAAC,CAAC;IACxB,kBAAkB,EAAE,CAAC,CAAC;CACzB,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AgentPayloadChangeRequest, ForEachOperation, WhileOperation, AgentResponseForm, ActionableCommand, AutomaticCommand, AgentScratchpad, AgentPipelineRequest } from "@memberjunction/ai-core-plus";
|
|
2
2
|
import { ArtifactToolCall } from "../ArtifactToolManager.js";
|
|
3
|
+
import { ConversationToolCall } from "../ConversationToolManager.js";
|
|
3
4
|
import { MemoryWriteRequest } from "../MemoryWriteManager.js";
|
|
4
|
-
export type { ForEachOperation, WhileOperation, ArtifactToolCall, MemoryWriteRequest };
|
|
5
|
+
export type { ForEachOperation, WhileOperation, ArtifactToolCall, ConversationToolCall, MemoryWriteRequest };
|
|
5
6
|
/**
|
|
6
7
|
* Response structure for Loop Agent Type
|
|
7
8
|
*/
|
|
@@ -50,6 +51,14 @@ export interface LoopAgentResponse<P = any> {
|
|
|
50
51
|
* injected into the next turn's prompt via _ARTIFACT_TOOL_RESULTS.
|
|
51
52
|
*/
|
|
52
53
|
artifactToolCalls?: ArtifactToolCall[];
|
|
54
|
+
/**
|
|
55
|
+
* Conversation-history retrieval tool invocations — page exact pre-summary
|
|
56
|
+
* messages back into context by their persisted `Sequence` handles, or search
|
|
57
|
+
* the full stored history. Processed inline on the same turn as other response
|
|
58
|
+
* fields (zero turn cost); results are injected as a conversation message on
|
|
59
|
+
* the next turn. Only honored when the run has a conversationId.
|
|
60
|
+
*/
|
|
61
|
+
conversationToolCalls?: ConversationToolCall[];
|
|
53
62
|
/**
|
|
54
63
|
* Durable memory writes — record facts/preferences that persist across
|
|
55
64
|
* runs. Processed inline on the same turn as other response fields (zero
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-agent-response-type.d.ts","sourceRoot":"","sources":["../../src/agent-types/loop-agent-response-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAC1M,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG3D,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,kB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E,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACjC,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,WAAW,CAAC,EAAE,MAAM,CAAC;SACxB,CAAC,CAAC;QAEH;;WAEG;QACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;QAE3B;;WAEG;QACH,KAAK,CAAC,EAAE,cAAc,CAAC;QAEvB;;;;;WAKG;QACH,MAAM,CAAC,EAAE,KAAK,CAAC;YACX,IAAI,EAAE,MAAM,CAAC;YACb;;;;eAIG;YACH,MAAM,CAAC,EAAE,MAAM,CAAC;SACnB,CAAC,CAAC;QAEH;;;;WAIG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-agent-response-type.js","sourceRoot":"","sources":["../../src/agent-types/loop-agent-response-type.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"loop-agent-response-type.js","sourceRoot":"","sources":["../../src/agent-types/loop-agent-response-type.ts"],"names":[],"mappings":";AAwNA,oEAAoE;AACpE,sDAAsD"}
|
|
@@ -12,42 +12,31 @@
|
|
|
12
12
|
import { BaseAgentType } from './base-agent-type.js';
|
|
13
13
|
import { AIPromptRunResult, BaseAgentNextStep, AIPromptParams, ExecuteAgentParams, AgentConfiguration, AgentAction } from '@memberjunction/ai-core-plus';
|
|
14
14
|
import { MJAIPromptEntityExtended } from '@memberjunction/ai-core-plus';
|
|
15
|
-
/**
|
|
16
|
-
* Implementation of the Loop Agent Type pattern.
|
|
17
|
-
*
|
|
18
|
-
* This agent type enables iterative execution where the agent continues
|
|
19
|
-
* processing until a task is marked complete. It supports:
|
|
20
|
-
* - Task completion detection
|
|
21
|
-
* - Sub-agent delegation
|
|
22
|
-
* - Action execution
|
|
23
|
-
* - Progress tracking
|
|
24
|
-
* - Error handling
|
|
25
|
-
* - Result accumulation across iterations
|
|
26
|
-
*
|
|
27
|
-
* @class LoopAgentType
|
|
28
|
-
* @extends BaseAgentType
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* // The agent will execute in a loop until taskComplete is true
|
|
33
|
-
* const loopAgent = new LoopAgentType();
|
|
34
|
-
* const nextStep = await loopAgent.DetermineNextStep(promptResult);
|
|
35
|
-
*
|
|
36
|
-
* switch (nextStep.step) {
|
|
37
|
-
* case 'success':
|
|
38
|
-
* console.log('Task completed:', nextStep.payload);
|
|
39
|
-
* break;
|
|
40
|
-
* case 'sub-agent':
|
|
41
|
-
* console.log('Delegating to:', nextStep.subAgentName);
|
|
42
|
-
* break;
|
|
43
|
-
* case 'action':
|
|
44
|
-
* console.log('Executing action:', nextStep.actionName);
|
|
45
|
-
* break;
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
15
|
export declare class LoopAgentType extends BaseAgentType {
|
|
50
16
|
private _evaluator;
|
|
17
|
+
/**
|
|
18
|
+
* Consecutive inline-read-tool pre-emptions forced so far. Per-run safe: a fresh
|
|
19
|
+
* LoopAgentType instance is created for each agent run (ClassFactory.CreateInstance
|
|
20
|
+
* in BaseAgentType.GetAgentTypeInstance). Reset whenever a response arrives without
|
|
21
|
+
* the terminal-step-plus-read-tools combination.
|
|
22
|
+
*/
|
|
23
|
+
private consecutiveReadToolPreemptions;
|
|
24
|
+
/**
|
|
25
|
+
* Handles the terminal-step-plus-inline-read-tools combination. Inline READ tools
|
|
26
|
+
* (artifact/conversation) are yield/await: results arrive on the NEXT turn, so a
|
|
27
|
+
* terminal step in the same response would orphan them — the tools execute and inject
|
|
28
|
+
* their results, but the run ends and the user gets "one moment…" and silence. Mirrors
|
|
29
|
+
* the Pipeline/client-tools pre-emption: force one more (non-terminal) turn so the LLM
|
|
30
|
+
* responds after reading the results. taskComplete + clientTools is excluded — the
|
|
31
|
+
* ClientTools path already re-enters the loop and consumes the injected results.
|
|
32
|
+
* memoryWrites/scratchpad are fire-and-forget writes and never trigger pre-emption.
|
|
33
|
+
*
|
|
34
|
+
* @returns The forced Retry step, or null when no pre-emption applies — including when
|
|
35
|
+
* the consecutive cap is reached (the caller then honors the terminal step; pre-emption
|
|
36
|
+
* retries are exempt from the unproductive-retry limit, so without the ceiling the
|
|
37
|
+
* combination could extend a run indefinitely).
|
|
38
|
+
*/
|
|
39
|
+
private buildReadToolPreemptionStep;
|
|
51
40
|
InitializeAgentTypeState<ATS = any, P = any>(params: ExecuteAgentParams<any, P>): Promise<ATS>;
|
|
52
41
|
/**
|
|
53
42
|
* Determines the next step based on the structured response from the AI model.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loop-agent-type.d.ts","sourceRoot":"","sources":["../../src/agent-types/loop-agent-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,WAAW,EAA6B,MAAM,8BAA8B,CAAC;AAEpL,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"loop-agent-type.d.ts","sourceRoot":"","sources":["../../src/agent-types/loop-agent-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,WAAW,EAA6B,MAAM,8BAA8B,CAAC;AAEpL,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AA+CxE,qBACa,aAAc,SAAQ,aAAa;IAC5C,OAAO,CAAC,UAAU,CAAiC;IAEnD;;;;;OAKG;IACH,O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