@caupulican/pi-adaptative 0.93.18 → 0.93.19
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/CHANGELOG.md +17 -0
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +22 -12
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +21 -0
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +149 -26
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +1 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-agent-control.d.ts +2 -0
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control.js.map +1 -1
- package/dist/core/foreground-lifecycle-adapter.d.ts +27 -0
- package/dist/core/foreground-lifecycle-adapter.d.ts.map +1 -0
- package/dist/core/foreground-lifecycle-adapter.js +61 -0
- package/dist/core/foreground-lifecycle-adapter.js.map +1 -0
- package/dist/core/foreground-lifecycle-controller.d.ts +48 -0
- package/dist/core/foreground-lifecycle-controller.d.ts.map +1 -0
- package/dist/core/foreground-lifecycle-controller.js +404 -0
- package/dist/core/foreground-lifecycle-controller.js.map +1 -0
- package/dist/core/foreground-recovery-controller.d.ts +3 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
- package/dist/core/foreground-recovery-controller.js +15 -1
- package/dist/core/foreground-recovery-controller.js.map +1 -1
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +9 -2
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/keybindings.d.ts +2 -2
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -2
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/memory/memory-manager.d.ts +22 -0
- package/dist/core/memory/memory-manager.d.ts.map +1 -1
- package/dist/core/memory/memory-manager.js +108 -49
- package/dist/core/memory/memory-manager.js.map +1 -1
- package/dist/core/model-router/session-buffer.d.ts +10 -2
- package/dist/core/model-router/session-buffer.d.ts.map +1 -1
- package/dist/core/model-router/session-buffer.js +35 -9
- package/dist/core/model-router/session-buffer.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +20 -2
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +70 -17
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/provider-request-runtime-controller.d.ts +12 -1
- package/dist/core/provider-request-runtime-controller.d.ts.map +1 -1
- package/dist/core/provider-request-runtime-controller.js +45 -2
- package/dist/core/provider-request-runtime-controller.js.map +1 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +4 -2
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +1 -3
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +10 -20
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts +3 -0
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +25 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/transcript-overlay.d.ts +13 -0
- package/dist/modes/interactive/components/transcript-overlay.d.ts.map +1 -0
- package/dist/modes/interactive/components/transcript-overlay.js +35 -0
- package/dist/modes/interactive/components/transcript-overlay.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +7 -4
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +2 -1
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +9 -7
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +70 -99
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/runtime-status-controller.d.ts +40 -0
- package/dist/modes/interactive/runtime-status-controller.d.ts.map +1 -0
- package/dist/modes/interactive/runtime-status-controller.js +147 -0
- package/dist/modes/interactive/runtime-status-controller.js.map +1 -0
- package/dist/modes/interactive/runtime-status.d.ts +15 -0
- package/dist/modes/interactive/runtime-status.d.ts.map +1 -0
- package/dist/modes/interactive/runtime-status.js +18 -0
- package/dist/modes/interactive/runtime-status.js.map +1 -0
- package/docs/json.md +1 -1
- package/docs/keybindings.md +2 -1
- package/docs/session-format.md +59 -4
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -5,13 +5,35 @@ import type { MemoryLifecycleContext, MemoryProvider } from "./memory-provider.t
|
|
|
5
5
|
export interface MemoryPrefetchOptions {
|
|
6
6
|
externalEgressPolicy?: MemoryEgressPolicy;
|
|
7
7
|
}
|
|
8
|
+
export interface MemoryManagerOptions {
|
|
9
|
+
/** Maximum time a provider lifecycle call may keep the session waiting. */
|
|
10
|
+
lifecycleTimeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export type MemoryLifecycleOperation = "isAvailable" | "initialize" | "prefetch" | "syncTurn" | "onPreCompress" | "onSessionEnd" | "shutdown";
|
|
13
|
+
export interface MemoryLifecycleDiagnostic {
|
|
14
|
+
provider: string;
|
|
15
|
+
operation: MemoryLifecycleOperation;
|
|
16
|
+
status: "timeout" | "error" | "abandoned";
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
8
19
|
export declare class MemoryManager {
|
|
20
|
+
/** Provider identities remain fenced while late timed-out operations are still pending, without retaining them strongly. */
|
|
21
|
+
private static readonly ABANDONED_PROVIDERS;
|
|
9
22
|
private readonly providers;
|
|
10
23
|
private readonly activeProviders;
|
|
11
24
|
private readonly registeredToolNames;
|
|
12
25
|
private ctx?;
|
|
13
26
|
private systemPromptBlockCache?;
|
|
27
|
+
private readonly lifecycleTimeoutMs;
|
|
28
|
+
private readonly lifecycleDiagnostics;
|
|
14
29
|
private static readonly RESERVED_CORE_TOOL_NAMES;
|
|
30
|
+
constructor(options?: MemoryManagerOptions);
|
|
31
|
+
/** Bounded, source-labelled diagnostics for lifecycle failures; no provider payloads are retained. */
|
|
32
|
+
getLifecycleDiagnostics(): MemoryLifecycleDiagnostic[];
|
|
33
|
+
private recordLifecycleDiagnostic;
|
|
34
|
+
private abandonProvider;
|
|
35
|
+
private releaseAbandonedProvider;
|
|
36
|
+
private invokeProvider;
|
|
15
37
|
registerProvider(p: MemoryProvider): void;
|
|
16
38
|
initializeAll(sessionId: string, ctx: MemoryLifecycleContext): Promise<void>;
|
|
17
39
|
buildSystemPromptBlock(budget?: MemoryPromptBudget): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-manager.d.ts","sourceRoot":"","sources":["../../../src/core/memory/memory-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,KAAK,E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,CAAC,IAAI,CAAC,CAUxC;IAEM,kBAAkB,IAAI,cAAc,EAAE,CAa5C;IAEM,iBAAiB,IAAI,MAAM,EAAE,CAgBnC;IAEM,KAAK,IAAI,IAAI,CAOnB;CACD"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_EXTERNAL_MEMORY_EGRESS_POLICY, hasSecretLikeMemoryText, } from "../context/memory-provider-contract.js";
|
|
2
2
|
import { wrapUntrustedText } from "../security/untrusted-boundary.js";
|
|
3
|
+
const DEFAULT_LIFECYCLE_TIMEOUT_MS = 8_000;
|
|
4
|
+
const MAX_LIFECYCLE_DIAGNOSTICS = 32;
|
|
3
5
|
export class MemoryManager {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.activeProviders = new Set();
|
|
7
|
-
this.registeredToolNames = new Set();
|
|
8
|
-
}
|
|
6
|
+
/** Provider identities remain fenced while late timed-out operations are still pending, without retaining them strongly. */
|
|
7
|
+
static { this.ABANDONED_PROVIDERS = new WeakMap(); }
|
|
9
8
|
// Core reserved tool names to prevent hijacking or schema corruption.
|
|
10
9
|
static { this.RESERVED_CORE_TOOL_NAMES = new Set([
|
|
11
10
|
"read",
|
|
@@ -21,6 +20,86 @@ export class MemoryManager {
|
|
|
21
20
|
"skill_search",
|
|
22
21
|
"skill_open",
|
|
23
22
|
]); }
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
this.providers = [];
|
|
25
|
+
this.activeProviders = new Set();
|
|
26
|
+
this.registeredToolNames = new Set();
|
|
27
|
+
this.lifecycleDiagnostics = [];
|
|
28
|
+
const timeout = options.lifecycleTimeoutMs ?? DEFAULT_LIFECYCLE_TIMEOUT_MS;
|
|
29
|
+
if (!Number.isFinite(timeout) || timeout <= 0) {
|
|
30
|
+
throw new Error("Memory lifecycle timeout must be a finite positive number.");
|
|
31
|
+
}
|
|
32
|
+
this.lifecycleTimeoutMs = timeout;
|
|
33
|
+
}
|
|
34
|
+
/** Bounded, source-labelled diagnostics for lifecycle failures; no provider payloads are retained. */
|
|
35
|
+
getLifecycleDiagnostics() {
|
|
36
|
+
return this.lifecycleDiagnostics.map((diagnostic) => ({ ...diagnostic }));
|
|
37
|
+
}
|
|
38
|
+
recordLifecycleDiagnostic(diagnostic) {
|
|
39
|
+
if (this.lifecycleDiagnostics.length >= MAX_LIFECYCLE_DIAGNOSTICS) {
|
|
40
|
+
this.lifecycleDiagnostics.shift();
|
|
41
|
+
}
|
|
42
|
+
this.lifecycleDiagnostics.push(diagnostic);
|
|
43
|
+
console.error(`Memory provider ${diagnostic.provider} ${diagnostic.operation} ${diagnostic.status}: ${diagnostic.message}`);
|
|
44
|
+
}
|
|
45
|
+
abandonProvider(provider) {
|
|
46
|
+
// A timed-out Promise cannot be cancelled. Removing the provider prevents a late completion
|
|
47
|
+
// from racing a later hook and makes abandonment the one mandatory recovery path.
|
|
48
|
+
this.activeProviders.delete(provider.name);
|
|
49
|
+
const state = MemoryManager.ABANDONED_PROVIDERS.get(provider) ?? { pendingOperations: 0 };
|
|
50
|
+
state.pendingOperations += 1;
|
|
51
|
+
MemoryManager.ABANDONED_PROVIDERS.set(provider, state);
|
|
52
|
+
}
|
|
53
|
+
releaseAbandonedProvider(provider) {
|
|
54
|
+
const state = MemoryManager.ABANDONED_PROVIDERS.get(provider);
|
|
55
|
+
if (state === undefined)
|
|
56
|
+
return;
|
|
57
|
+
state.pendingOperations -= 1;
|
|
58
|
+
if (state.pendingOperations <= 0)
|
|
59
|
+
MemoryManager.ABANDONED_PROVIDERS.delete(provider);
|
|
60
|
+
}
|
|
61
|
+
async invokeProvider(provider, operation, callback) {
|
|
62
|
+
let timeout;
|
|
63
|
+
let timedOut = false;
|
|
64
|
+
const operationPromise = Promise.resolve()
|
|
65
|
+
.then(callback)
|
|
66
|
+
.then((value) => ({ status: "ok", value }))
|
|
67
|
+
.catch((error) => ({ status: "error", error }))
|
|
68
|
+
.finally(() => {
|
|
69
|
+
if (timedOut)
|
|
70
|
+
this.releaseAbandonedProvider(provider);
|
|
71
|
+
});
|
|
72
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
73
|
+
timeout = setTimeout(() => {
|
|
74
|
+
timedOut = true;
|
|
75
|
+
this.abandonProvider(provider);
|
|
76
|
+
this.recordLifecycleDiagnostic({
|
|
77
|
+
provider: provider.name,
|
|
78
|
+
operation,
|
|
79
|
+
status: "timeout",
|
|
80
|
+
message: `exceeded ${this.lifecycleTimeoutMs}ms`,
|
|
81
|
+
});
|
|
82
|
+
resolve({ status: "timeout" });
|
|
83
|
+
}, this.lifecycleTimeoutMs);
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
const result = await Promise.race([operationPromise, timeoutPromise]);
|
|
87
|
+
if (result.status === "error") {
|
|
88
|
+
this.recordLifecycleDiagnostic({
|
|
89
|
+
provider: provider.name,
|
|
90
|
+
operation,
|
|
91
|
+
status: "error",
|
|
92
|
+
message: result.error instanceof Error ? result.error.name : typeof result.error,
|
|
93
|
+
});
|
|
94
|
+
return { status: "error", error: result.error };
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
if (timeout !== undefined)
|
|
100
|
+
clearTimeout(timeout);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
24
103
|
registerProvider(p) {
|
|
25
104
|
if (this.providers.some((prov) => prov.name === p.name)) {
|
|
26
105
|
throw new Error(`Memory provider ${p.name} is already registered.`);
|
|
@@ -52,17 +131,21 @@ export class MemoryManager {
|
|
|
52
131
|
this.activeProviders.clear();
|
|
53
132
|
this.systemPromptBlockCache = undefined;
|
|
54
133
|
for (const p of this.providers) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
catch (err) {
|
|
64
|
-
console.error(`Memory provider ${p.name} failed to initialize and was deactivated:`, err);
|
|
134
|
+
if (MemoryManager.ABANDONED_PROVIDERS.has(p)) {
|
|
135
|
+
this.recordLifecycleDiagnostic({
|
|
136
|
+
provider: p.name,
|
|
137
|
+
operation: "initialize",
|
|
138
|
+
status: "abandoned",
|
|
139
|
+
message: "provider identity was abandoned by an earlier manager generation",
|
|
140
|
+
});
|
|
141
|
+
continue;
|
|
65
142
|
}
|
|
143
|
+
const availability = await this.invokeProvider(p, "isAvailable", () => p.isAvailable());
|
|
144
|
+
if (availability.status !== "ok" || !availability.value)
|
|
145
|
+
continue;
|
|
146
|
+
const initialized = await this.invokeProvider(p, "initialize", () => p.initialize(sessionId, ctx));
|
|
147
|
+
if (initialized.status === "ok")
|
|
148
|
+
this.activeProviders.add(p.name);
|
|
66
149
|
}
|
|
67
150
|
}
|
|
68
151
|
buildSystemPromptBlock(budget) {
|
|
@@ -119,14 +202,9 @@ export class MemoryManager {
|
|
|
119
202
|
continue;
|
|
120
203
|
}
|
|
121
204
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
results.push(wrapUntrustedText(text, `memory:${p.name}`));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
console.error(`Memory provider ${p.name} failed during prefetch:`, err);
|
|
205
|
+
const result = await this.invokeProvider(p, "prefetch", () => p.prefetch(query));
|
|
206
|
+
if (result.status === "ok" && result.value) {
|
|
207
|
+
results.push(wrapUntrustedText(result.value, `memory:${p.name}`));
|
|
130
208
|
}
|
|
131
209
|
}
|
|
132
210
|
return results.join("\n\n");
|
|
@@ -139,12 +217,7 @@ export class MemoryManager {
|
|
|
139
217
|
if (!this.activeProviders.has(p.name) || !p.syncTurn) {
|
|
140
218
|
continue;
|
|
141
219
|
}
|
|
142
|
-
|
|
143
|
-
await p.syncTurn(user, assistant);
|
|
144
|
-
}
|
|
145
|
-
catch (err) {
|
|
146
|
-
console.error(`Memory provider ${p.name} failed during syncTurn:`, err);
|
|
147
|
-
}
|
|
220
|
+
await this.invokeProvider(p, "syncTurn", () => p.syncTurn(user, assistant));
|
|
148
221
|
}
|
|
149
222
|
}
|
|
150
223
|
async onPreCompress() {
|
|
@@ -153,14 +226,9 @@ export class MemoryManager {
|
|
|
153
226
|
if (!this.activeProviders.has(p.name) || !p.onPreCompress) {
|
|
154
227
|
continue;
|
|
155
228
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
insights.push(insight);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
catch (err) {
|
|
163
|
-
console.error(`Memory provider ${p.name} failed during onPreCompress:`, err);
|
|
229
|
+
const result = await this.invokeProvider(p, "onPreCompress", () => p.onPreCompress());
|
|
230
|
+
if (result.status === "ok" && result.value) {
|
|
231
|
+
insights.push(result.value);
|
|
164
232
|
}
|
|
165
233
|
}
|
|
166
234
|
return insights.join("\n\n");
|
|
@@ -173,12 +241,7 @@ export class MemoryManager {
|
|
|
173
241
|
if (!this.activeProviders.has(p.name) || !p.onSessionEnd) {
|
|
174
242
|
continue;
|
|
175
243
|
}
|
|
176
|
-
|
|
177
|
-
await p.onSessionEnd();
|
|
178
|
-
}
|
|
179
|
-
catch (err) {
|
|
180
|
-
console.error(`Memory provider ${p.name} failed during onSessionEnd:`, err);
|
|
181
|
-
}
|
|
244
|
+
await this.invokeProvider(p, "onSessionEnd", () => p.onSessionEnd());
|
|
182
245
|
}
|
|
183
246
|
}
|
|
184
247
|
async shutdownAll() {
|
|
@@ -188,12 +251,7 @@ export class MemoryManager {
|
|
|
188
251
|
if (!this.activeProviders.has(p.name)) {
|
|
189
252
|
continue;
|
|
190
253
|
}
|
|
191
|
-
|
|
192
|
-
await p.shutdown();
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
console.error(`Memory provider ${p.name} failed to shutdown cleanly:`, err);
|
|
196
|
-
}
|
|
254
|
+
await this.invokeProvider(p, "shutdown", () => p.shutdown());
|
|
197
255
|
}
|
|
198
256
|
this.activeProviders.clear();
|
|
199
257
|
}
|
|
@@ -236,6 +294,7 @@ export class MemoryManager {
|
|
|
236
294
|
this.registeredToolNames.clear();
|
|
237
295
|
this.systemPromptBlockCache = undefined;
|
|
238
296
|
this.ctx = undefined;
|
|
297
|
+
this.lifecycleDiagnostics.length = 0;
|
|
239
298
|
}
|
|
240
299
|
}
|
|
241
300
|
//# sourceMappingURL=memory-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-manager.js","sourceRoot":"","sources":["../../../src/core/memory/memory-manager.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qCAAqC,EACrC,uBAAuB,GAEvB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAOtE,MAAM,OAAO,aAAa;IAA1B;QACkB,cAAS,GAAqB,EAAE,CAAC;QACjC,oBAAe,GAAgB,IAAI,GAAG,EAAE,CAAC;QACzC,wBAAmB,GAAgB,IAAI,GAAG,EAAE,CAAC;IA4P/D,CAAC;IAxPA,sEAAsE;aAC9C,6BAAwB,GAAG,IAAI,GAAG,CAAC;QAC1D,MAAM;QACN,OAAO;QACP,MAAM;QACN,MAAM;QACN,IAAI;QACJ,MAAM;QACN,QAAQ;QACR,UAAU;QACV,UAAU;QACV,aAAa;QACb,cAAc;QACd,YAAY;KACZ,CAAC,AAb8C,CAa7C;IAEI,gBAAgB,CAAC,CAAiB;QACxC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,IAAI,yBAAyB,CAAC,CAAC;QACrE,CAAC;QAED,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;YAC1B,IAAI,KAAK,GAAqB,EAAE,CAAC;YACjC,IAAI,CAAC;gBACJ,KAAK,GAAG,CAAC,CAAC,kBAAkB,EAAE,IAAI,EAAE,CAAC;YAC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CAAC,CAAC,CAAC,CAAC;gBAChB,CAAC;YACF,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;YAC9E,CAAC;QACF,CAAC;QACD,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;IACrB,CAAC;IAEM,KAAK;QACX,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC;QACjC,IAAI,CAAC,sBAAsB,GAAG,SAAS,CAAC;QACxC,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;IACtB,CAAC;CACD","sourcesContent":["import type { MemoryPromptBudget } from \"../context/memory-prompt-budget.ts\";\nimport {\n\tDEFAULT_EXTERNAL_MEMORY_EGRESS_POLICY,\n\thasSecretLikeMemoryText,\n\ttype MemoryEgressPolicy,\n} from \"../context/memory-provider-contract.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { wrapUntrustedText } from \"../security/untrusted-boundary.ts\";\nimport type { MemoryLifecycleContext, MemoryProvider } from \"./memory-provider.ts\";\n\nexport interface MemoryPrefetchOptions {\n\texternalEgressPolicy?: MemoryEgressPolicy;\n}\n\nexport class MemoryManager {\n\tprivate readonly providers: MemoryProvider[] = [];\n\tprivate readonly activeProviders: Set<string> = new Set();\n\tprivate readonly registeredToolNames: Set<string> = new Set();\n\tprivate ctx?: MemoryLifecycleContext;\n\tprivate systemPromptBlockCache?: { key: string; text: string };\n\n\t// Core reserved tool names to prevent hijacking or schema corruption.\n\tprivate static readonly RESERVED_CORE_TOOL_NAMES = new Set([\n\t\t\"read\",\n\t\t\"write\",\n\t\t\"grep\",\n\t\t\"find\",\n\t\t\"ls\",\n\t\t\"bash\",\n\t\t\"python\",\n\t\t\"ask_user\",\n\t\t\"skillify\",\n\t\t\"skill_audit\",\n\t\t\"skill_search\",\n\t\t\"skill_open\",\n\t]);\n\n\tpublic registerProvider(p: MemoryProvider): void {\n\t\tif (this.providers.some((prov) => prov.name === p.name)) {\n\t\t\tthrow new Error(`Memory provider ${p.name} is already registered.`);\n\t\t}\n\n\t\tif (p.getToolDefinitions) {\n\t\t\tlet tools: ToolDefinition[] = [];\n\t\t\ttry {\n\t\t\t\ttools = p.getToolDefinitions() ?? [];\n\t\t\t} catch (err) {\n\t\t\t\tthrow new Error(`Failed to get tool definitions from provider ${p.name}: ${String(err)}`);\n\t\t\t}\n\n\t\t\tfor (const tool of tools) {\n\t\t\t\tif (MemoryManager.RESERVED_CORE_TOOL_NAMES.has(tool.name)) {\n\t\t\t\t\tthrow new Error(`Memory provider ${p.name} tried to register reserved core tool: ${tool.name}`);\n\t\t\t\t}\n\t\t\t\tif (this.registeredToolNames.has(tool.name)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Memory provider tool name collision: ${tool.name} is already registered. First-registration-wins.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const tool of tools) {\n\t\t\t\tthis.registeredToolNames.add(tool.name);\n\t\t\t}\n\t\t}\n\n\t\tthis.providers.push(p);\n\t}\n\n\tpublic async initializeAll(sessionId: string, ctx: MemoryLifecycleContext): Promise<void> {\n\t\tthis.ctx = ctx;\n\t\tthis.activeProviders.clear();\n\t\tthis.systemPromptBlockCache = undefined;\n\n\t\tfor (const p of this.providers) {\n\t\t\ttry {\n\t\t\t\tconst available = await p.isAvailable();\n\t\t\t\tif (!available) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tawait p.initialize(sessionId, ctx);\n\t\t\t\tthis.activeProviders.add(p.name);\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Memory provider ${p.name} failed to initialize and was deactivated:`, err);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic buildSystemPromptBlock(budget?: MemoryPromptBudget): string {\n\t\tconst key =\n\t\t\tbudget === undefined\n\t\t\t\t? \"none\"\n\t\t\t\t: `${budget.enabled}:${budget.compact}:${budget.maxLines}:${budget.maxEstimatedTokens}:${budget.maxChars}`;\n\t\tif (this.systemPromptBlockCache !== undefined && this.systemPromptBlockCache.key === key) {\n\t\t\treturn this.systemPromptBlockCache.text;\n\t\t}\n\n\t\tconst text = this._composeSystemPromptBlock(budget);\n\t\tthis.systemPromptBlockCache = { key, text };\n\t\treturn text;\n\t}\n\n\t/**\n\t * Compose the memory block freshly from the providers, BYPASSING the frozen cache used by the\n\t * system prompt. Used by end-of-loop reflection so its confront-before-write sees the live memory\n\t * (including writes made earlier in the same session) without churning the prefix-cache-stable\n\t * system prompt block.\n\t */\n\tpublic buildSystemPromptBlockFresh(budget?: MemoryPromptBudget): string {\n\t\treturn this._composeSystemPromptBlock(budget);\n\t}\n\n\tprivate _composeSystemPromptBlock(budget?: MemoryPromptBudget): string {\n\t\tconst blocks: string[] = [];\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.systemPromptBlock) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst block = p.systemPromptBlock(budget);\n\t\t\t\tif (block) {\n\t\t\t\t\tblocks.push(block);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Memory provider ${p.name} failed to generate system prompt block:`, err);\n\t\t\t}\n\t\t}\n\t\treturn blocks.join(\"\\n\\n\");\n\t}\n\n\tpublic async prefetch(query: string, options: MemoryPrefetchOptions = {}): Promise<string> {\n\t\tconst results: string[] = [];\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.prefetch) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (p.egress !== \"local\") {\n\t\t\t\tconst policy = options.externalEgressPolicy ?? DEFAULT_EXTERNAL_MEMORY_EGRESS_POLICY;\n\t\t\t\tif (\n\t\t\t\t\t!policy.enabled ||\n\t\t\t\t\t!policy.allowExternalEgress ||\n\t\t\t\t\t!policy.allowQueryText ||\n\t\t\t\t\tquery.length > policy.maxOutboundChars ||\n\t\t\t\t\t(policy.redactSecretLikeText && hasSecretLikeMemoryText(query))\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst text = await p.prefetch(query);\n\t\t\t\tif (text) {\n\t\t\t\t\tresults.push(wrapUntrustedText(text, `memory:${p.name}`));\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Memory provider ${p.name} failed during prefetch:`, err);\n\t\t\t}\n\t\t}\n\t\treturn results.join(\"\\n\\n\");\n\t}\n\n\tpublic async syncTurn(user: string, assistant: string): Promise<void> {\n\t\tif (this.ctx?.isChildSession) {\n\t\t\treturn; // Write-gated: skip writes in child sessions\n\t\t}\n\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.syncTurn) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait p.syncTurn(user, assistant);\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Memory provider ${p.name} failed during syncTurn:`, err);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async onPreCompress(): Promise<string> {\n\t\tconst insights: string[] = [];\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.onPreCompress) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst insight = await p.onPreCompress();\n\t\t\t\tif (insight) {\n\t\t\t\t\tinsights.push(insight);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Memory provider ${p.name} failed during onPreCompress:`, err);\n\t\t\t}\n\t\t}\n\t\treturn insights.join(\"\\n\\n\");\n\t}\n\n\tpublic async onSessionEnd(): Promise<void> {\n\t\tif (this.ctx?.isChildSession) {\n\t\t\treturn; // Write-gated: skip writes in child sessions\n\t\t}\n\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.onSessionEnd) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait p.onSessionEnd();\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Memory provider ${p.name} failed during onSessionEnd:`, err);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async shutdownAll(): Promise<void> {\n\t\t// Shutdown in reverse registration order\n\t\tconst reversed = [...this.providers].reverse();\n\t\tfor (const p of reversed) {\n\t\t\tif (!this.activeProviders.has(p.name)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait p.shutdown();\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Memory provider ${p.name} failed to shutdown cleanly:`, err);\n\t\t\t}\n\t\t}\n\t\tthis.activeProviders.clear();\n\t}\n\n\tpublic getToolDefinitions(): ToolDefinition[] {\n\t\tconst tools: ToolDefinition[] = [];\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.getToolDefinitions) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\ttools.push(...p.getToolDefinitions());\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Failed to get tool definitions from provider ${p.name}:`, err);\n\t\t\t}\n\t\t}\n\t\treturn tools;\n\t}\n\n\tpublic getContextMarkers(): string[] {\n\t\tconst markers = new Set<string>();\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.getContextMarkers) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst list = p.getContextMarkers() ?? [];\n\t\t\t\tfor (const m of list) {\n\t\t\t\t\tmarkers.add(m);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Failed to get context markers from provider ${p.name}:`, err);\n\t\t\t}\n\t\t}\n\t\treturn [...markers];\n\t}\n\n\tpublic reset(): void {\n\t\tthis.providers.length = 0;\n\t\tthis.activeProviders.clear();\n\t\tthis.registeredToolNames.clear();\n\t\tthis.systemPromptBlockCache = undefined;\n\t\tthis.ctx = undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"memory-manager.js","sourceRoot":"","sources":["../../../src/core/memory/memory-manager.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qCAAqC,EACrC,uBAAuB,GAEvB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AA4BtE,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAC3C,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAWrC,MAAM,OAAO,aAAa;IACzB,4HAA4H;aACpG,wBAAmB,GAAG,IAAI,OAAO,EAA0C,AAAxD,CAAyD;IASpG,sEAAsE;aAC9C,6BAAwB,GAAG,IAAI,GAAG,CAAC;QAC1D,MAAM;QACN,OAAO;QACP,MAAM;QACN,MAAM;QACN,IAAI;QACJ,MAAM;QACN,QAAQ;QACR,UAAU;QACV,UAAU;QACV,aAAa;QACb,cAAc;QACd,YAAY;KACZ,CAAC,AAb8C,CAa7C;IAEH,YAAY,OAAO,GAAyB,EAAE;QAxB7B,cAAS,GAAqB,EAAE,CAAC;QACjC,oBAAe,GAAgB,IAAI,GAAG,EAAE,CAAC;QACzC,wBAAmB,GAAgB,IAAI,GAAG,EAAE,CAAC;QAI7C,yBAAoB,GAAgC,EAAE,CAAC;QAmBvE,MAAM,OAAO,GAAG,OAAO,CAAC,kBAAkB,IAAI,4BAA4B,CAAC;QAC3E,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAC/E,CAAC;QACD,IAAI,CAAC,kBAAkB,GAAG,OAAO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KAAK;QACX,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QAC1B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC;QACjC,IAAI,CAAC,sBAAsB,GAAG,SAAS,CAAC;QACxC,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QACrB,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IACtC,CAAC;CACD","sourcesContent":["import type { MemoryPromptBudget } from \"../context/memory-prompt-budget.ts\";\nimport {\n\tDEFAULT_EXTERNAL_MEMORY_EGRESS_POLICY,\n\thasSecretLikeMemoryText,\n\ttype MemoryEgressPolicy,\n} from \"../context/memory-provider-contract.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { wrapUntrustedText } from \"../security/untrusted-boundary.ts\";\nimport type { MemoryLifecycleContext, MemoryProvider } from \"./memory-provider.ts\";\n\nexport interface MemoryPrefetchOptions {\n\texternalEgressPolicy?: MemoryEgressPolicy;\n}\n\nexport interface MemoryManagerOptions {\n\t/** Maximum time a provider lifecycle call may keep the session waiting. */\n\tlifecycleTimeoutMs?: number;\n}\n\nexport type MemoryLifecycleOperation =\n\t| \"isAvailable\"\n\t| \"initialize\"\n\t| \"prefetch\"\n\t| \"syncTurn\"\n\t| \"onPreCompress\"\n\t| \"onSessionEnd\"\n\t| \"shutdown\";\n\nexport interface MemoryLifecycleDiagnostic {\n\tprovider: string;\n\toperation: MemoryLifecycleOperation;\n\tstatus: \"timeout\" | \"error\" | \"abandoned\";\n\tmessage: string;\n}\n\nconst DEFAULT_LIFECYCLE_TIMEOUT_MS = 8_000;\nconst MAX_LIFECYCLE_DIAGNOSTICS = 32;\n\ntype ProviderOperationResult<T> =\n\t| { status: \"ok\"; value: T }\n\t| { status: \"timeout\" }\n\t| { status: \"error\"; error: unknown };\n\ninterface AbandonedProviderState {\n\tpendingOperations: number;\n}\n\nexport class MemoryManager {\n\t/** Provider identities remain fenced while late timed-out operations are still pending, without retaining them strongly. */\n\tprivate static readonly ABANDONED_PROVIDERS = new WeakMap<MemoryProvider, AbandonedProviderState>();\n\tprivate readonly providers: MemoryProvider[] = [];\n\tprivate readonly activeProviders: Set<string> = new Set();\n\tprivate readonly registeredToolNames: Set<string> = new Set();\n\tprivate ctx?: MemoryLifecycleContext;\n\tprivate systemPromptBlockCache?: { key: string; text: string };\n\tprivate readonly lifecycleTimeoutMs: number;\n\tprivate readonly lifecycleDiagnostics: MemoryLifecycleDiagnostic[] = [];\n\n\t// Core reserved tool names to prevent hijacking or schema corruption.\n\tprivate static readonly RESERVED_CORE_TOOL_NAMES = new Set([\n\t\t\"read\",\n\t\t\"write\",\n\t\t\"grep\",\n\t\t\"find\",\n\t\t\"ls\",\n\t\t\"bash\",\n\t\t\"python\",\n\t\t\"ask_user\",\n\t\t\"skillify\",\n\t\t\"skill_audit\",\n\t\t\"skill_search\",\n\t\t\"skill_open\",\n\t]);\n\n\tconstructor(options: MemoryManagerOptions = {}) {\n\t\tconst timeout = options.lifecycleTimeoutMs ?? DEFAULT_LIFECYCLE_TIMEOUT_MS;\n\t\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\t\tthrow new Error(\"Memory lifecycle timeout must be a finite positive number.\");\n\t\t}\n\t\tthis.lifecycleTimeoutMs = timeout;\n\t}\n\n\t/** Bounded, source-labelled diagnostics for lifecycle failures; no provider payloads are retained. */\n\tpublic getLifecycleDiagnostics(): MemoryLifecycleDiagnostic[] {\n\t\treturn this.lifecycleDiagnostics.map((diagnostic) => ({ ...diagnostic }));\n\t}\n\n\tprivate recordLifecycleDiagnostic(diagnostic: MemoryLifecycleDiagnostic): void {\n\t\tif (this.lifecycleDiagnostics.length >= MAX_LIFECYCLE_DIAGNOSTICS) {\n\t\t\tthis.lifecycleDiagnostics.shift();\n\t\t}\n\t\tthis.lifecycleDiagnostics.push(diagnostic);\n\t\tconsole.error(\n\t\t\t`Memory provider ${diagnostic.provider} ${diagnostic.operation} ${diagnostic.status}: ${diagnostic.message}`,\n\t\t);\n\t}\n\n\tprivate abandonProvider(provider: MemoryProvider): void {\n\t\t// A timed-out Promise cannot be cancelled. Removing the provider prevents a late completion\n\t\t// from racing a later hook and makes abandonment the one mandatory recovery path.\n\t\tthis.activeProviders.delete(provider.name);\n\t\tconst state = MemoryManager.ABANDONED_PROVIDERS.get(provider) ?? { pendingOperations: 0 };\n\t\tstate.pendingOperations += 1;\n\t\tMemoryManager.ABANDONED_PROVIDERS.set(provider, state);\n\t}\n\n\tprivate releaseAbandonedProvider(provider: MemoryProvider): void {\n\t\tconst state = MemoryManager.ABANDONED_PROVIDERS.get(provider);\n\t\tif (state === undefined) return;\n\t\tstate.pendingOperations -= 1;\n\t\tif (state.pendingOperations <= 0) MemoryManager.ABANDONED_PROVIDERS.delete(provider);\n\t}\n\n\tprivate async invokeProvider<T>(\n\t\tprovider: MemoryProvider,\n\t\toperation: MemoryLifecycleOperation,\n\t\tcallback: () => T | Promise<T>,\n\t): Promise<ProviderOperationResult<T>> {\n\t\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\t\tlet timedOut = false;\n\t\tconst operationPromise = Promise.resolve()\n\t\t\t.then(callback)\n\t\t\t.then((value): ProviderOperationResult<T> => ({ status: \"ok\", value }))\n\t\t\t.catch((error): ProviderOperationResult<T> => ({ status: \"error\", error }))\n\t\t\t.finally(() => {\n\t\t\t\tif (timedOut) this.releaseAbandonedProvider(provider);\n\t\t\t});\n\t\tconst timeoutPromise = new Promise<ProviderOperationResult<T>>((resolve) => {\n\t\t\ttimeout = setTimeout(() => {\n\t\t\t\ttimedOut = true;\n\t\t\t\tthis.abandonProvider(provider);\n\t\t\t\tthis.recordLifecycleDiagnostic({\n\t\t\t\t\tprovider: provider.name,\n\t\t\t\t\toperation,\n\t\t\t\t\tstatus: \"timeout\",\n\t\t\t\t\tmessage: `exceeded ${this.lifecycleTimeoutMs}ms`,\n\t\t\t\t});\n\t\t\t\tresolve({ status: \"timeout\" });\n\t\t\t}, this.lifecycleTimeoutMs);\n\t\t});\n\t\ttry {\n\t\t\tconst result = await Promise.race([operationPromise, timeoutPromise]);\n\t\t\tif (result.status === \"error\") {\n\t\t\t\tthis.recordLifecycleDiagnostic({\n\t\t\t\t\tprovider: provider.name,\n\t\t\t\t\toperation,\n\t\t\t\t\tstatus: \"error\",\n\t\t\t\t\tmessage: result.error instanceof Error ? result.error.name : typeof result.error,\n\t\t\t\t});\n\t\t\t\treturn { status: \"error\", error: result.error };\n\t\t\t}\n\t\t\treturn result;\n\t\t} finally {\n\t\t\tif (timeout !== undefined) clearTimeout(timeout);\n\t\t}\n\t}\n\n\tpublic registerProvider(p: MemoryProvider): void {\n\t\tif (this.providers.some((prov) => prov.name === p.name)) {\n\t\t\tthrow new Error(`Memory provider ${p.name} is already registered.`);\n\t\t}\n\n\t\tif (p.getToolDefinitions) {\n\t\t\tlet tools: ToolDefinition[] = [];\n\t\t\ttry {\n\t\t\t\ttools = p.getToolDefinitions() ?? [];\n\t\t\t} catch (err) {\n\t\t\t\tthrow new Error(`Failed to get tool definitions from provider ${p.name}: ${String(err)}`);\n\t\t\t}\n\n\t\t\tfor (const tool of tools) {\n\t\t\t\tif (MemoryManager.RESERVED_CORE_TOOL_NAMES.has(tool.name)) {\n\t\t\t\t\tthrow new Error(`Memory provider ${p.name} tried to register reserved core tool: ${tool.name}`);\n\t\t\t\t}\n\t\t\t\tif (this.registeredToolNames.has(tool.name)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Memory provider tool name collision: ${tool.name} is already registered. First-registration-wins.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const tool of tools) {\n\t\t\t\tthis.registeredToolNames.add(tool.name);\n\t\t\t}\n\t\t}\n\n\t\tthis.providers.push(p);\n\t}\n\n\tpublic async initializeAll(sessionId: string, ctx: MemoryLifecycleContext): Promise<void> {\n\t\tthis.ctx = ctx;\n\t\tthis.activeProviders.clear();\n\t\tthis.systemPromptBlockCache = undefined;\n\n\t\tfor (const p of this.providers) {\n\t\t\tif (MemoryManager.ABANDONED_PROVIDERS.has(p)) {\n\t\t\t\tthis.recordLifecycleDiagnostic({\n\t\t\t\t\tprovider: p.name,\n\t\t\t\t\toperation: \"initialize\",\n\t\t\t\t\tstatus: \"abandoned\",\n\t\t\t\t\tmessage: \"provider identity was abandoned by an earlier manager generation\",\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst availability = await this.invokeProvider(p, \"isAvailable\", () => p.isAvailable());\n\t\t\tif (availability.status !== \"ok\" || !availability.value) continue;\n\n\t\t\tconst initialized = await this.invokeProvider(p, \"initialize\", () => p.initialize(sessionId, ctx));\n\t\t\tif (initialized.status === \"ok\") this.activeProviders.add(p.name);\n\t\t}\n\t}\n\n\tpublic buildSystemPromptBlock(budget?: MemoryPromptBudget): string {\n\t\tconst key =\n\t\t\tbudget === undefined\n\t\t\t\t? \"none\"\n\t\t\t\t: `${budget.enabled}:${budget.compact}:${budget.maxLines}:${budget.maxEstimatedTokens}:${budget.maxChars}`;\n\t\tif (this.systemPromptBlockCache !== undefined && this.systemPromptBlockCache.key === key) {\n\t\t\treturn this.systemPromptBlockCache.text;\n\t\t}\n\n\t\tconst text = this._composeSystemPromptBlock(budget);\n\t\tthis.systemPromptBlockCache = { key, text };\n\t\treturn text;\n\t}\n\n\t/**\n\t * Compose the memory block freshly from the providers, BYPASSING the frozen cache used by the\n\t * system prompt. Used by end-of-loop reflection so its confront-before-write sees the live memory\n\t * (including writes made earlier in the same session) without churning the prefix-cache-stable\n\t * system prompt block.\n\t */\n\tpublic buildSystemPromptBlockFresh(budget?: MemoryPromptBudget): string {\n\t\treturn this._composeSystemPromptBlock(budget);\n\t}\n\n\tprivate _composeSystemPromptBlock(budget?: MemoryPromptBudget): string {\n\t\tconst blocks: string[] = [];\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.systemPromptBlock) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst block = p.systemPromptBlock(budget);\n\t\t\t\tif (block) {\n\t\t\t\t\tblocks.push(block);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Memory provider ${p.name} failed to generate system prompt block:`, err);\n\t\t\t}\n\t\t}\n\t\treturn blocks.join(\"\\n\\n\");\n\t}\n\n\tpublic async prefetch(query: string, options: MemoryPrefetchOptions = {}): Promise<string> {\n\t\tconst results: string[] = [];\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.prefetch) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (p.egress !== \"local\") {\n\t\t\t\tconst policy = options.externalEgressPolicy ?? DEFAULT_EXTERNAL_MEMORY_EGRESS_POLICY;\n\t\t\t\tif (\n\t\t\t\t\t!policy.enabled ||\n\t\t\t\t\t!policy.allowExternalEgress ||\n\t\t\t\t\t!policy.allowQueryText ||\n\t\t\t\t\tquery.length > policy.maxOutboundChars ||\n\t\t\t\t\t(policy.redactSecretLikeText && hasSecretLikeMemoryText(query))\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst result = await this.invokeProvider(p, \"prefetch\", () => p.prefetch!(query));\n\t\t\tif (result.status === \"ok\" && result.value) {\n\t\t\t\tresults.push(wrapUntrustedText(result.value, `memory:${p.name}`));\n\t\t\t}\n\t\t}\n\t\treturn results.join(\"\\n\\n\");\n\t}\n\n\tpublic async syncTurn(user: string, assistant: string): Promise<void> {\n\t\tif (this.ctx?.isChildSession) {\n\t\t\treturn; // Write-gated: skip writes in child sessions\n\t\t}\n\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.syncTurn) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tawait this.invokeProvider(p, \"syncTurn\", () => p.syncTurn!(user, assistant));\n\t\t}\n\t}\n\n\tpublic async onPreCompress(): Promise<string> {\n\t\tconst insights: string[] = [];\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.onPreCompress) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = await this.invokeProvider(p, \"onPreCompress\", () => p.onPreCompress!());\n\t\t\tif (result.status === \"ok\" && result.value) {\n\t\t\t\tinsights.push(result.value);\n\t\t\t}\n\t\t}\n\t\treturn insights.join(\"\\n\\n\");\n\t}\n\n\tpublic async onSessionEnd(): Promise<void> {\n\t\tif (this.ctx?.isChildSession) {\n\t\t\treturn; // Write-gated: skip writes in child sessions\n\t\t}\n\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.onSessionEnd) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tawait this.invokeProvider(p, \"onSessionEnd\", () => p.onSessionEnd!());\n\t\t}\n\t}\n\n\tpublic async shutdownAll(): Promise<void> {\n\t\t// Shutdown in reverse registration order\n\t\tconst reversed = [...this.providers].reverse();\n\t\tfor (const p of reversed) {\n\t\t\tif (!this.activeProviders.has(p.name)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tawait this.invokeProvider(p, \"shutdown\", () => p.shutdown());\n\t\t}\n\t\tthis.activeProviders.clear();\n\t}\n\n\tpublic getToolDefinitions(): ToolDefinition[] {\n\t\tconst tools: ToolDefinition[] = [];\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.getToolDefinitions) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\ttools.push(...p.getToolDefinitions());\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Failed to get tool definitions from provider ${p.name}:`, err);\n\t\t\t}\n\t\t}\n\t\treturn tools;\n\t}\n\n\tpublic getContextMarkers(): string[] {\n\t\tconst markers = new Set<string>();\n\t\tfor (const p of this.providers) {\n\t\t\tif (!this.activeProviders.has(p.name) || !p.getContextMarkers) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst list = p.getContextMarkers() ?? [];\n\t\t\t\tfor (const m of list) {\n\t\t\t\t\tmarkers.add(m);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tconsole.error(`Failed to get context markers from provider ${p.name}:`, err);\n\t\t\t}\n\t\t}\n\t\treturn [...markers];\n\t}\n\n\tpublic reset(): void {\n\t\tthis.providers.length = 0;\n\t\tthis.activeProviders.clear();\n\t\tthis.registeredToolNames.clear();\n\t\tthis.systemPromptBlockCache = undefined;\n\t\tthis.ctx = undefined;\n\t\tthis.lifecycleDiagnostics.length = 0;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentMessage } from "@caupulican/pi-agent-core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Message } from "@caupulican/pi-ai";
|
|
3
3
|
export type ModelRouterBufferedSessionMessage = {
|
|
4
4
|
kind: "message";
|
|
5
5
|
message: Message;
|
|
@@ -11,11 +11,19 @@ export type ModelRouterBufferedSessionMessage = {
|
|
|
11
11
|
};
|
|
12
12
|
export type ModelRouterSessionBuffer = {
|
|
13
13
|
messages: ModelRouterBufferedSessionMessage[];
|
|
14
|
+
/** True after the complete routed turn has been durably committed. */
|
|
15
|
+
committed: boolean;
|
|
16
|
+
/** True after the prompt prefix was durably committed before provider transport. */
|
|
17
|
+
prefixCommitted: boolean;
|
|
18
|
+
/** Number of AgentMessages (including custom messages) in the committed prefix, retained for live-suffix repair. */
|
|
19
|
+
prefixMessageCount: number;
|
|
14
20
|
};
|
|
15
21
|
export declare function createModelRouterSessionBuffer(): ModelRouterSessionBuffer;
|
|
16
22
|
export declare function bufferModelRouterSessionMessage(buffer: ModelRouterSessionBuffer, message: Message): void;
|
|
17
23
|
export declare function bufferModelRouterSessionCustomMessage(buffer: ModelRouterSessionBuffer, message: Extract<AgentMessage, {
|
|
18
24
|
role: "custom";
|
|
19
25
|
}>): void;
|
|
20
|
-
export declare function flushModelRouterSessionBuffer(buffer: ModelRouterSessionBuffer,
|
|
26
|
+
export declare function flushModelRouterSessionBuffer(buffer: ModelRouterSessionBuffer, appendBatch: (entries: readonly ModelRouterBufferedSessionMessage[]) => readonly string[]): Map<AgentMessage, string>;
|
|
27
|
+
/** Commit only the prompt prefix before provider transport; later assistant/tool messages remain buffered. */
|
|
28
|
+
export declare function flushModelRouterSessionBufferPrefix(buffer: ModelRouterSessionBuffer, appendBatch: (entries: readonly ModelRouterBufferedSessionMessage[]) => readonly string[]): Map<AgentMessage, string>;
|
|
21
29
|
//# sourceMappingURL=session-buffer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-buffer.d.ts","sourceRoot":"","sources":["../../../src/core/model-router/session-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"session-buffer.d.ts","sourceRoot":"","sources":["../../../src/core/model-router/session-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,MAAM,iCAAiC,GAC1C;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAChB,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC;CAClD,CAAC;AAEL,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,EAAE,iCAAiC,EAAE,CAAC;IAC9C,sEAAsE;IACtE,SAAS,EAAE,OAAO,CAAC;IACnB,oFAAoF;IACpF,eAAe,EAAE,OAAO,CAAC;IACzB,oHAAoH;IACpH,kBAAkB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,wBAAgB,8BAA8B,IAAI,wBAAwB,CAEzE;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,wBAAwB,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAExG;AAED,wBAAgB,qCAAqC,CACpD,MAAM,EAAE,wBAAwB,EAChC,OAAO,EAAE,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,GAChD,IAAI,CAEN;AAED,wBAAgB,6BAA6B,CAC5C,MAAM,EAAE,wBAAwB,EAChC,WAAW,EAAE,CAAC,OAAO,EAAE,SAAS,iCAAiC,EAAE,KAAK,SAAS,MAAM,EAAE,GACvF,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAO3B;AAED,8GAA8G;AAC9G,wBAAgB,mCAAmC,CAClD,MAAM,EAAE,wBAAwB,EAChC,WAAW,EAAE,CAAC,OAAO,EAAE,SAAS,iCAAiC,EAAE,KAAK,SAAS,MAAM,EAAE,GACvF,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,CAQ3B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function createModelRouterSessionBuffer() {
|
|
2
|
-
return { messages: [] };
|
|
2
|
+
return { messages: [], committed: false, prefixCommitted: false, prefixMessageCount: 0 };
|
|
3
3
|
}
|
|
4
4
|
export function bufferModelRouterSessionMessage(buffer, message) {
|
|
5
5
|
buffer.messages.push({ kind: "message", message });
|
|
@@ -7,14 +7,40 @@ export function bufferModelRouterSessionMessage(buffer, message) {
|
|
|
7
7
|
export function bufferModelRouterSessionCustomMessage(buffer, message) {
|
|
8
8
|
buffer.messages.push({ kind: "custom", message });
|
|
9
9
|
}
|
|
10
|
-
export function flushModelRouterSessionBuffer(buffer,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
export function flushModelRouterSessionBuffer(buffer, appendBatch) {
|
|
11
|
+
if (buffer.committed)
|
|
12
|
+
return new Map();
|
|
13
|
+
const entryIds = appendBufferedMessages(buffer.messages, appendBatch);
|
|
14
|
+
buffer.messages = [];
|
|
15
|
+
buffer.committed = true;
|
|
16
|
+
buffer.prefixCommitted = true;
|
|
17
|
+
return entryIds;
|
|
18
|
+
}
|
|
19
|
+
/** Commit only the prompt prefix before provider transport; later assistant/tool messages remain buffered. */
|
|
20
|
+
export function flushModelRouterSessionBufferPrefix(buffer, appendBatch) {
|
|
21
|
+
if (buffer.prefixCommitted)
|
|
22
|
+
return new Map();
|
|
23
|
+
const entries = buffer.messages;
|
|
24
|
+
const entryIds = appendBufferedMessages(entries, appendBatch);
|
|
25
|
+
buffer.messages = [];
|
|
26
|
+
buffer.prefixCommitted = true;
|
|
27
|
+
buffer.prefixMessageCount = entries.length;
|
|
28
|
+
return entryIds;
|
|
29
|
+
}
|
|
30
|
+
function appendBufferedMessages(entries, appendBatch) {
|
|
31
|
+
if (entries.length === 0)
|
|
32
|
+
return new Map();
|
|
33
|
+
const ids = appendBatch(entries);
|
|
34
|
+
if (ids.length !== entries.length) {
|
|
35
|
+
throw new Error("Session message batch returned an unexpected entry count.");
|
|
36
|
+
}
|
|
37
|
+
const entryIds = new Map();
|
|
38
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
39
|
+
const id = ids[index];
|
|
40
|
+
if (typeof id !== "string")
|
|
41
|
+
throw new Error("Session message batch returned an invalid entry id.");
|
|
42
|
+
entryIds.set(entries[index].message, id);
|
|
18
43
|
}
|
|
44
|
+
return entryIds;
|
|
19
45
|
}
|
|
20
46
|
//# sourceMappingURL=session-buffer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-buffer.js","sourceRoot":"","sources":["../../../src/core/model-router/session-buffer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session-buffer.js","sourceRoot":"","sources":["../../../src/core/model-router/session-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AAM,CAAC,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAC3C,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,SAAS,sBAAsB,CAC9B,OAAqD,EACrD,WAAyF;IAEzF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,GAAG,EAAE,CAAC;IAC3C,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,GAAG,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;IACjD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACxD,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;QACtB,IAAI,OAAO,EAAE,KAAK,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACnG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["import type { AgentMessage } from \"@caupulican/pi-agent-core\";\nimport type { Message } from \"@caupulican/pi-ai\";\n\nexport type ModelRouterBufferedSessionMessage =\n\t| {\n\t\t\tkind: \"message\";\n\t\t\tmessage: Message;\n\t }\n\t| {\n\t\t\tkind: \"custom\";\n\t\t\tmessage: Extract<AgentMessage, { role: \"custom\" }>;\n\t };\n\nexport type ModelRouterSessionBuffer = {\n\tmessages: ModelRouterBufferedSessionMessage[];\n\t/** True after the complete routed turn has been durably committed. */\n\tcommitted: boolean;\n\t/** True after the prompt prefix was durably committed before provider transport. */\n\tprefixCommitted: boolean;\n\t/** Number of AgentMessages (including custom messages) in the committed prefix, retained for live-suffix repair. */\n\tprefixMessageCount: number;\n};\n\nexport function createModelRouterSessionBuffer(): ModelRouterSessionBuffer {\n\treturn { messages: [], committed: false, prefixCommitted: false, prefixMessageCount: 0 };\n}\n\nexport function bufferModelRouterSessionMessage(buffer: ModelRouterSessionBuffer, message: Message): void {\n\tbuffer.messages.push({ kind: \"message\", message });\n}\n\nexport function bufferModelRouterSessionCustomMessage(\n\tbuffer: ModelRouterSessionBuffer,\n\tmessage: Extract<AgentMessage, { role: \"custom\" }>,\n): void {\n\tbuffer.messages.push({ kind: \"custom\", message });\n}\n\nexport function flushModelRouterSessionBuffer(\n\tbuffer: ModelRouterSessionBuffer,\n\tappendBatch: (entries: readonly ModelRouterBufferedSessionMessage[]) => readonly string[],\n): Map<AgentMessage, string> {\n\tif (buffer.committed) return new Map();\n\tconst entryIds = appendBufferedMessages(buffer.messages, appendBatch);\n\tbuffer.messages = [];\n\tbuffer.committed = true;\n\tbuffer.prefixCommitted = true;\n\treturn entryIds;\n}\n\n/** Commit only the prompt prefix before provider transport; later assistant/tool messages remain buffered. */\nexport function flushModelRouterSessionBufferPrefix(\n\tbuffer: ModelRouterSessionBuffer,\n\tappendBatch: (entries: readonly ModelRouterBufferedSessionMessage[]) => readonly string[],\n): Map<AgentMessage, string> {\n\tif (buffer.prefixCommitted) return new Map();\n\tconst entries = buffer.messages;\n\tconst entryIds = appendBufferedMessages(entries, appendBatch);\n\tbuffer.messages = [];\n\tbuffer.prefixCommitted = true;\n\tbuffer.prefixMessageCount = entries.length;\n\treturn entryIds;\n}\n\nfunction appendBufferedMessages(\n\tentries: readonly ModelRouterBufferedSessionMessage[],\n\tappendBatch: (entries: readonly ModelRouterBufferedSessionMessage[]) => readonly string[],\n): Map<AgentMessage, string> {\n\tif (entries.length === 0) return new Map();\n\tconst ids = appendBatch(entries);\n\tif (ids.length !== entries.length) {\n\t\tthrow new Error(\"Session message batch returned an unexpected entry count.\");\n\t}\n\tconst entryIds = new Map<AgentMessage, string>();\n\tfor (let index = 0; index < entries.length; index += 1) {\n\t\tconst id = ids[index];\n\t\tif (typeof id !== \"string\") throw new Error(\"Session message batch returned an invalid entry id.\");\n\t\tentryIds.set(entries[index]!.message, id);\n\t}\n\treturn entryIds;\n}\n"]}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* ModelRouterControllerDeps.getToolProbeVerdict}).
|
|
32
32
|
*/
|
|
33
33
|
import type { Agent, AgentMessage } from "@caupulican/pi-agent-core";
|
|
34
|
-
import type { SessionManager } from "@caupulican/pi-agent-core/node";
|
|
34
|
+
import type { SessionManager, SessionMessageBatchEntry } from "@caupulican/pi-agent-core/node";
|
|
35
35
|
import type { Api, Model, Usage } from "@caupulican/pi-ai";
|
|
36
36
|
import type { AgentSessionEvent, IsolatedCompletionOptions, IsolatedCompletionResult } from "./agent-session-contracts.ts";
|
|
37
37
|
import type { RouteDecision } from "./autonomy/contracts.ts";
|
|
@@ -52,6 +52,8 @@ export interface ModelRouterControllerDeps {
|
|
|
52
52
|
getSettingsManager(): SettingsManager;
|
|
53
53
|
/** Session log: routed-turn message buffering/persistence, decision persistence, recent-decision status. */
|
|
54
54
|
getSessionManager(): SessionManager;
|
|
55
|
+
/** Canonical host-owned mixed message batch persistence; one validated publication for lifecycle linking. */
|
|
56
|
+
appendSessionMessageBatch(batch: readonly SessionMessageBatchEntry[]): string[];
|
|
55
57
|
/** Resolves configured route/judge/executor model patterns against configured auth. */
|
|
56
58
|
getModelRegistry(): ModelRegistry;
|
|
57
59
|
/** Session-scoped provider/model quota exhaustion guard. */
|
|
@@ -66,6 +68,8 @@ export interface ModelRouterControllerDeps {
|
|
|
66
68
|
getBaseSystemPrompt(): string;
|
|
67
69
|
/** The session-owned foreground drive loop; the routed path delegates every turn here. */
|
|
68
70
|
runAgentPrompt(messages: AgentMessage | AgentMessage[]): Promise<void>;
|
|
71
|
+
/** Continue from canonical history after a committed cheap-route escalation. */
|
|
72
|
+
runAgentContinuation(): Promise<void>;
|
|
69
73
|
/** Rebuilds the system prompt for a filtered tool surface (routed-model capability shedding). */
|
|
70
74
|
buildSystemPromptForToolNames(toolNames: string[]): string;
|
|
71
75
|
/** Re-resolves the restored model against the registry after a routed turn (provider override safety). */
|
|
@@ -142,6 +146,20 @@ export declare class ModelRouterController {
|
|
|
142
146
|
* Returns true when the message was buffered, so the host skips its own persistence.
|
|
143
147
|
*/
|
|
144
148
|
captureSessionMessage(message: AgentMessage): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Commit a cheap routed turn's buffered messages in their original source order.
|
|
151
|
+
*
|
|
152
|
+
* The lifecycle adapter uses this at the tool reservation boundary: once the assistant
|
|
153
|
+
* message is durable, later tool-result messages must go through the normal message-end
|
|
154
|
+
* path and an escalation may continue from canonical history instead of splicing it away.
|
|
155
|
+
* The buffer is marked committed only after every append succeeds; a failed append therefore
|
|
156
|
+
* rejects the reservation and the tool body is never entered.
|
|
157
|
+
*/
|
|
158
|
+
commitSessionBuffer(): Map<AgentMessage, string>;
|
|
159
|
+
/** Commit only the prompt prefix before a provider request; keep the assistant/tool suffix buffered. */
|
|
160
|
+
commitSessionBufferPrefix(): Map<AgentMessage, string>;
|
|
161
|
+
/** Whether a cheap routed turn has crossed its durable tool-boundary commit. */
|
|
162
|
+
isSessionBufferCommitted(): boolean;
|
|
145
163
|
private _isModelAvailableAndAuthed;
|
|
146
164
|
private _evaluateModelFitness;
|
|
147
165
|
private _formatFitnessFailure;
|
|
@@ -172,6 +190,6 @@ export declare class ModelRouterController {
|
|
|
172
190
|
} | undefined>;
|
|
173
191
|
private _resolveModelRouterTurnModel;
|
|
174
192
|
getStatus(formatLabel?: (label: string) => string): string;
|
|
175
|
-
runRoutedTurn(messages: AgentMessage | AgentMessage[], routedModel: Model<Api> | undefined, routeDecision: RouteDecision | undefined, persistDecision?: boolean): Promise<void>;
|
|
193
|
+
runRoutedTurn(messages: AgentMessage | AgentMessage[], routedModel: Model<Api> | undefined, routeDecision: RouteDecision | undefined, persistDecision?: boolean, continueFromCanonicalHistory?: boolean): Promise<void>;
|
|
176
194
|
}
|
|
177
195
|
//# sourceMappingURL=model-router-controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-router-controller.d.ts","sourceRoot":"","sources":["../../src/core/model-router-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAiB,MAAM,2BAA2B,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"model-router-controller.d.ts","sourceRoot":"","sources":["../../src/core/model-router-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAiB,MAAM,2BAA2B,CAAC;AACpF,OAAO,KAAK,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/F,OAAO,KAAK,EAAE,GAAG,EAAW,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,KAAK,EACX,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAkC,KAAK,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAI7G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAmBzD,OAAO,EAIN,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAE9B,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAI7D,wGAAwG;AAC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