pi-fabric 0.92.19 → 0.92.21
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/dist/agents.js +3 -3
- package/dist/chunks/chunk-EDL4JDW7.js +184 -0
- package/dist/chunks/chunk-EDL4JDW7.js.map +7 -0
- package/dist/chunks/{chunk-3KOK4CPR.js → chunk-EFHCXJTV.js} +2 -2
- package/dist/chunks/{chunk-4U5NR5VF.js → chunk-KI4VAMHK.js} +8 -8
- package/dist/chunks/{chunk-NIUOPHLB.js → chunk-MAP2LVSM.js} +123 -123
- package/dist/chunks/chunk-MAP2LVSM.js.map +7 -0
- package/dist/chunks/{chunk-VHEO26TE.js → chunk-NSTQH46Z.js} +5 -5
- package/dist/chunks/{chunk-TPLMVELH.js → chunk-VYXFSUWU.js} +4 -4
- package/dist/chunks/{chunk-DW5MTOJP.js → chunk-XFSRHUZH.js} +5 -5
- package/dist/chunks/{chunk-OP2KTYQB.js → chunk-ZMIJ6AT4.js} +4 -4
- package/dist/core/action-registry.js +2 -2
- package/dist/fabric-runtime-state.js +16 -15
- package/dist/fabric-runtime-state.js.map +2 -2
- package/dist/index.js +13 -10
- package/dist/index.js.map +2 -2
- package/dist/jev/browser.js +2 -2
- package/dist/jev/observation.js +2 -2
- package/dist/jev.js +5 -5
- package/dist/memory/file-worker.d.ts +15 -0
- package/dist/memory/file-worker.d.ts.map +1 -0
- package/dist/memory/file-worker.js +44 -0
- package/dist/memory/file-worker.js.map +7 -0
- package/dist/memory/worker-provider.d.ts +24 -0
- package/dist/memory/worker-provider.d.ts.map +1 -0
- package/dist/memory/worker-provider.js +18 -0
- package/dist/memory/worker-provider.js.map +7 -0
- package/dist/prewalk/arm.d.ts.map +1 -1
- package/dist/providers/jev-provider.js +4 -4
- package/dist/residency/host.js +4 -4
- package/dist/residency/pi-entry.js +4 -4
- package/dist/runtime/typescript-kernel.js +6 -6
- package/dist/runtime-state-builtins.d.ts.map +1 -1
- package/docs/agents.md +1 -1
- package/docs/configuration.md +1 -1
- package/docs/memory-recall.md +21 -0
- package/package.json +2 -1
- package/dist/chunks/chunk-NIUOPHLB.js.map +0 -7
- /package/dist/chunks/{chunk-3KOK4CPR.js.map → chunk-EFHCXJTV.js.map} +0 -0
- /package/dist/chunks/{chunk-4U5NR5VF.js.map → chunk-KI4VAMHK.js.map} +0 -0
- /package/dist/chunks/{chunk-VHEO26TE.js.map → chunk-NSTQH46Z.js.map} +0 -0
- /package/dist/chunks/{chunk-TPLMVELH.js.map → chunk-VYXFSUWU.js.map} +0 -0
- /package/dist/chunks/{chunk-DW5MTOJP.js.map → chunk-XFSRHUZH.js.map} +0 -0
- /package/dist/chunks/{chunk-OP2KTYQB.js.map → chunk-ZMIJ6AT4.js.map} +0 -0
package/dist/agents.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
validateAgentResult
|
|
3
|
-
} from "./chunks/chunk-3QECYQGA.js";
|
|
4
1
|
import {
|
|
5
2
|
AGENTS_ACTION_DESCRIPTORS,
|
|
6
3
|
normalizeAgentRunRequest
|
|
7
4
|
} from "./chunks/chunk-2PZWDVJB.js";
|
|
5
|
+
import {
|
|
6
|
+
validateAgentResult
|
|
7
|
+
} from "./chunks/chunk-3QECYQGA.js";
|
|
8
8
|
import {
|
|
9
9
|
actionArgNormalizer
|
|
10
10
|
} from "./chunks/chunk-NQOEHX62.js";
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MemoryProvider
|
|
3
|
+
} from "./chunk-UQ4LTUH4.js";
|
|
4
|
+
|
|
5
|
+
// src/memory/worker-provider.ts
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { Worker } from "node:worker_threads";
|
|
8
|
+
var MAX_PENDING_REQUESTS = 64;
|
|
9
|
+
var IDLE_TIMEOUT_MS = 3e4;
|
|
10
|
+
var sameBranch = (left, right) => left.leafId === right.leafId && left.entries.length === right.entries.length && left.entries.every((entry, index) => entry.id === right.entries[index].id);
|
|
11
|
+
var WorkerMemoryProvider = class extends MemoryProvider {
|
|
12
|
+
constructor(workerContext, workerUrl = new URL("../memory/file-worker.js", import.meta.url)) {
|
|
13
|
+
super(workerContext);
|
|
14
|
+
this.workerContext = workerContext;
|
|
15
|
+
this.workerUrl = workerUrl;
|
|
16
|
+
}
|
|
17
|
+
worker;
|
|
18
|
+
active;
|
|
19
|
+
pending = [];
|
|
20
|
+
idleTimer;
|
|
21
|
+
stopping;
|
|
22
|
+
closed = false;
|
|
23
|
+
nextId = 0;
|
|
24
|
+
async invoke(action, args, invocation) {
|
|
25
|
+
invocation.signal?.throwIfAborted();
|
|
26
|
+
if (this.closed) throw new Error("Memory provider is closed");
|
|
27
|
+
if (typeof args.source === "string" && args.source.length > 0 || !["recall", "expand", "sessions"].includes(action)) {
|
|
28
|
+
return super.invoke(action, args, invocation);
|
|
29
|
+
}
|
|
30
|
+
if (this.pending.length + (this.active ? 1 : 0) >= MAX_PENDING_REQUESTS) {
|
|
31
|
+
throw new Error(`Memory request queue is full (${MAX_PENDING_REQUESTS} requests); await outstanding calls`);
|
|
32
|
+
}
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const request = {
|
|
35
|
+
id: ++this.nextId,
|
|
36
|
+
action,
|
|
37
|
+
args,
|
|
38
|
+
invocation,
|
|
39
|
+
resolve,
|
|
40
|
+
reject,
|
|
41
|
+
abort: () => {
|
|
42
|
+
if (this.active === request) {
|
|
43
|
+
this.active = void 0;
|
|
44
|
+
void this.retire();
|
|
45
|
+
} else {
|
|
46
|
+
const index = this.pending.indexOf(request);
|
|
47
|
+
if (index >= 0) this.pending.splice(index, 1);
|
|
48
|
+
}
|
|
49
|
+
this.finish(request, false, invocation.signal?.reason ?? new Error("Memory request aborted"));
|
|
50
|
+
this.pump();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
invocation.signal?.addEventListener("abort", request.abort, { once: true });
|
|
54
|
+
this.pending.push(request);
|
|
55
|
+
this.pump();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
snapshot(request) {
|
|
59
|
+
const context = this.workerContext;
|
|
60
|
+
if (request.args.branches === "all" || !context.sessionFile || !context.getLiveBranch) return void 0;
|
|
61
|
+
const selector = request.action === "expand" ? request.args.session : request.args.scope;
|
|
62
|
+
const target = typeof selector === "string" && selector.trim().startsWith("session:") ? selector.trim().slice("session:".length).trim() : request.action === "expand" && typeof selector === "string" ? selector.trim() : void 0;
|
|
63
|
+
if (target !== void 0 && target !== context.sessionId && target !== path.basename(context.sessionFile, ".jsonl") && path.resolve(target) !== path.resolve(context.sessionFile)) return void 0;
|
|
64
|
+
const branch = context.getLiveBranch();
|
|
65
|
+
return {
|
|
66
|
+
leafId: branch.leafId,
|
|
67
|
+
entries: branch.entries.map((entry) => {
|
|
68
|
+
const id = entry !== null && typeof entry === "object" ? entry.id : void 0;
|
|
69
|
+
return typeof id === "string" ? { id } : {};
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
start() {
|
|
74
|
+
const { agentDir, cwd, config, sessionId, sessionFile } = this.workerContext;
|
|
75
|
+
const worker = new Worker(this.workerUrl, {
|
|
76
|
+
workerData: { agentDir, cwd, config, sessionId, sessionFile },
|
|
77
|
+
// Eval/stdin-only flags are invalid when Node starts this compiled module file.
|
|
78
|
+
execArgv: process.execArgv.filter((value, index, args) => value !== "--input-type" && args[index - 1] !== "--input-type" && !value.startsWith("--input-type="))
|
|
79
|
+
});
|
|
80
|
+
this.worker = worker;
|
|
81
|
+
worker.on("message", (message) => {
|
|
82
|
+
const request = this.active;
|
|
83
|
+
if (this.worker !== worker || !request || message?.id !== request.id) return;
|
|
84
|
+
try {
|
|
85
|
+
if (message.type === "progress") {
|
|
86
|
+
request.invocation.update(message.text);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (message.type === "error") {
|
|
90
|
+
const error = new Error(message.message);
|
|
91
|
+
error.name = message.name;
|
|
92
|
+
this.active = void 0;
|
|
93
|
+
this.finish(request, false, error);
|
|
94
|
+
} else if (message.type === "result") {
|
|
95
|
+
const branch = this.snapshot(request);
|
|
96
|
+
if (request.branch && (!branch || !sameBranch(request.branch, branch))) {
|
|
97
|
+
throw new Error("Session branch changed during memory retrieval; retry the request");
|
|
98
|
+
}
|
|
99
|
+
this.active = void 0;
|
|
100
|
+
this.finish(request, true, message.value);
|
|
101
|
+
} else {
|
|
102
|
+
throw new Error("Invalid memory worker response");
|
|
103
|
+
}
|
|
104
|
+
this.pump();
|
|
105
|
+
} catch (error) {
|
|
106
|
+
this.failWorker(worker, error);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
worker.once("error", (error) => this.failWorker(worker, error));
|
|
110
|
+
worker.once("exit", (code) => this.failWorker(worker, new Error(`Memory worker exited before completing its request (code ${code})`)));
|
|
111
|
+
return worker;
|
|
112
|
+
}
|
|
113
|
+
finish(request, success, value) {
|
|
114
|
+
request.invocation.signal?.removeEventListener("abort", request.abort);
|
|
115
|
+
if (success) request.resolve(value);
|
|
116
|
+
else request.reject(value);
|
|
117
|
+
}
|
|
118
|
+
failWorker(worker, error) {
|
|
119
|
+
if (this.worker !== worker) return;
|
|
120
|
+
const request = this.active;
|
|
121
|
+
this.active = void 0;
|
|
122
|
+
void this.retire();
|
|
123
|
+
if (request) this.finish(request, false, error);
|
|
124
|
+
}
|
|
125
|
+
pump() {
|
|
126
|
+
if (this.closed || this.active || this.stopping) return;
|
|
127
|
+
const request = this.pending.shift();
|
|
128
|
+
if (!request) {
|
|
129
|
+
this.worker?.unref();
|
|
130
|
+
if (this.worker && !this.idleTimer) {
|
|
131
|
+
this.idleTimer = setTimeout(() => {
|
|
132
|
+
void this.retire();
|
|
133
|
+
}, IDLE_TIMEOUT_MS);
|
|
134
|
+
this.idleTimer.unref();
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (this.idleTimer) clearTimeout(this.idleTimer);
|
|
139
|
+
this.idleTimer = void 0;
|
|
140
|
+
this.active = request;
|
|
141
|
+
try {
|
|
142
|
+
request.invocation.signal?.throwIfAborted();
|
|
143
|
+
request.branch = this.snapshot(request);
|
|
144
|
+
const worker = this.worker ?? this.start();
|
|
145
|
+
worker.ref();
|
|
146
|
+
worker.postMessage({ id: request.id, action: request.action, args: request.args, branch: request.branch });
|
|
147
|
+
} catch (error) {
|
|
148
|
+
this.active = void 0;
|
|
149
|
+
void this.retire();
|
|
150
|
+
this.finish(request, false, error);
|
|
151
|
+
this.pump();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
retire() {
|
|
155
|
+
if (this.idleTimer) clearTimeout(this.idleTimer);
|
|
156
|
+
this.idleTimer = void 0;
|
|
157
|
+
const worker = this.worker;
|
|
158
|
+
this.worker = void 0;
|
|
159
|
+
if (!worker) return this.stopping ?? Promise.resolve();
|
|
160
|
+
const stopping = worker.terminate().then(() => {
|
|
161
|
+
}, () => {
|
|
162
|
+
});
|
|
163
|
+
this.stopping = stopping;
|
|
164
|
+
void stopping.then(() => {
|
|
165
|
+
if (this.stopping === stopping) this.stopping = void 0;
|
|
166
|
+
this.pump();
|
|
167
|
+
});
|
|
168
|
+
return stopping;
|
|
169
|
+
}
|
|
170
|
+
async close() {
|
|
171
|
+
this.closed = true;
|
|
172
|
+
const active = this.active;
|
|
173
|
+
this.active = void 0;
|
|
174
|
+
const requests = this.pending.splice(0);
|
|
175
|
+
if (active) requests.unshift(active);
|
|
176
|
+
for (const request of requests) this.finish(request, false, new Error("Memory provider is closed"));
|
|
177
|
+
await this.retire();
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export {
|
|
182
|
+
WorkerMemoryProvider
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=chunk-EDL4JDW7.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/memory/worker-provider.ts"],
|
|
4
|
+
"sourcesContent": ["import path from \"node:path\";\nimport { Worker } from \"node:worker_threads\";\nimport type { FabricInvocationContext } from \"../protocol.js\";\nimport { MemoryProvider, type MemoryProviderContext } from \"../providers/memory-provider.js\";\nimport type { LiveSessionBranch } from \"./lineage.js\";\nimport type { MemoryWorkerReply } from \"./file-worker.js\";\n\nconst MAX_PENDING_REQUESTS = 64;\nconst IDLE_TIMEOUT_MS = 30_000;\n\ninterface Request {\n id: number;\n action: string;\n args: Record<string, unknown>;\n invocation: FabricInvocationContext;\n branch?: LiveSessionBranch | undefined;\n abort(): void;\n resolve(value: unknown): void;\n reject(error: unknown): void;\n}\n\nconst sameBranch = (left: LiveSessionBranch, right: LiveSessionBranch): boolean =>\n left.leafId === right.leafId && left.entries.length === right.entries.length &&\n left.entries.every((entry, index) =>\n (entry as { id?: string }).id === (right.entries[index] as { id?: string }).id);\n\n/** Pi-facing file memory: one lazy worker, bounded FIFO, no transcript work on the UI thread. */\nexport class WorkerMemoryProvider extends MemoryProvider {\n private worker: Worker | undefined;\n private active: Request | undefined;\n private readonly pending: Request[] = [];\n private idleTimer: NodeJS.Timeout | undefined;\n private stopping: Promise<void> | undefined;\n private closed = false;\n private nextId = 0;\n\n constructor(\n private readonly workerContext: MemoryProviderContext,\n private readonly workerUrl = new URL(\"../memory/file-worker.js\", import.meta.url),\n ) {\n super(workerContext);\n }\n\n override async invoke(action: string, args: Record<string, unknown>, invocation: FabricInvocationContext): Promise<unknown> {\n invocation.signal?.throwIfAborted();\n if (this.closed) throw new Error(\"Memory provider is closed\");\n // Authorized host adapters contain callbacks and must stay in their owning host.\n if ((typeof args.source === \"string\" && args.source.length > 0) ||\n ![\"recall\", \"expand\", \"sessions\"].includes(action)) {\n return super.invoke(action, args, invocation);\n }\n if (this.pending.length + (this.active ? 1 : 0) >= MAX_PENDING_REQUESTS) {\n throw new Error(`Memory request queue is full (${MAX_PENDING_REQUESTS} requests); await outstanding calls`);\n }\n return new Promise((resolve, reject) => {\n const request: Request = {\n id: ++this.nextId, action, args, invocation, resolve, reject,\n abort: () => {\n if (this.active === request) {\n this.active = undefined;\n void this.retire();\n } else {\n const index = this.pending.indexOf(request);\n if (index >= 0) this.pending.splice(index, 1);\n }\n this.finish(request, false, invocation.signal?.reason ?? new Error(\"Memory request aborted\"));\n this.pump();\n },\n };\n invocation.signal?.addEventListener(\"abort\", request.abort, { once: true });\n this.pending.push(request);\n this.pump();\n });\n }\n\n private snapshot(request: Request): LiveSessionBranch | undefined {\n const context = this.workerContext;\n if (request.args.branches === \"all\" || !context.sessionFile || !context.getLiveBranch) return undefined;\n const selector = request.action === \"expand\" ? request.args.session : request.args.scope;\n const target = typeof selector === \"string\" && selector.trim().startsWith(\"session:\")\n ? selector.trim().slice(\"session:\".length).trim()\n : request.action === \"expand\" && typeof selector === \"string\" ? selector.trim() : undefined;\n if (target !== undefined && target !== context.sessionId &&\n target !== path.basename(context.sessionFile, \".jsonl\") &&\n path.resolve(target) !== path.resolve(context.sessionFile)) return undefined;\n const branch = context.getLiveBranch();\n // Lineage needs IDs only. Never clone tool output, images, or the full transcript to the worker.\n return {\n leafId: branch.leafId,\n entries: branch.entries.map(entry => {\n const id = entry !== null && typeof entry === \"object\" ? (entry as { id?: unknown }).id : undefined;\n return typeof id === \"string\" ? { id } : {};\n }),\n };\n }\n\n private start(): Worker {\n const { agentDir, cwd, config, sessionId, sessionFile } = this.workerContext;\n const worker = new Worker(this.workerUrl, {\n workerData: { agentDir, cwd, config, sessionId, sessionFile },\n // Eval/stdin-only flags are invalid when Node starts this compiled module file.\n execArgv: process.execArgv.filter((value, index, args) =>\n value !== \"--input-type\" && args[index - 1] !== \"--input-type\" && !value.startsWith(\"--input-type=\")),\n });\n this.worker = worker;\n worker.on(\"message\", (message: MemoryWorkerReply) => {\n const request = this.active;\n if (this.worker !== worker || !request || message?.id !== request.id) return;\n try {\n if (message.type === \"progress\") {\n request.invocation.update(message.text);\n return;\n }\n if (message.type === \"error\") {\n const error = new Error(message.message);\n error.name = message.name;\n this.active = undefined;\n this.finish(request, false, error);\n } else if (message.type === \"result\") {\n const branch = this.snapshot(request);\n if (request.branch && (!branch || !sameBranch(request.branch, branch))) {\n throw new Error(\"Session branch changed during memory retrieval; retry the request\");\n }\n this.active = undefined;\n this.finish(request, true, message.value);\n } else {\n throw new Error(\"Invalid memory worker response\");\n }\n this.pump();\n } catch (error) {\n this.failWorker(worker, error);\n }\n });\n worker.once(\"error\", error => this.failWorker(worker, error));\n worker.once(\"exit\", code => this.failWorker(worker, new Error(`Memory worker exited before completing its request (code ${code})`)));\n return worker;\n }\n\n private finish(request: Request, success: boolean, value: unknown): void {\n request.invocation.signal?.removeEventListener(\"abort\", request.abort);\n if (success) request.resolve(value);\n else request.reject(value);\n }\n\n private failWorker(worker: Worker, error: unknown): void {\n if (this.worker !== worker) return;\n const request = this.active;\n this.active = undefined;\n void this.retire();\n if (request) this.finish(request, false, error);\n }\n\n private pump(): void {\n if (this.closed || this.active || this.stopping) return;\n const request = this.pending.shift();\n if (!request) {\n this.worker?.unref();\n if (this.worker && !this.idleTimer) {\n this.idleTimer = setTimeout(() => { void this.retire(); }, IDLE_TIMEOUT_MS);\n this.idleTimer.unref();\n }\n return;\n }\n if (this.idleTimer) clearTimeout(this.idleTimer);\n this.idleTimer = undefined;\n this.active = request;\n try {\n request.invocation.signal?.throwIfAborted();\n request.branch = this.snapshot(request);\n const worker = this.worker ?? this.start();\n worker.ref();\n worker.postMessage({ id: request.id, action: request.action, args: request.args, branch: request.branch });\n } catch (error) {\n this.active = undefined;\n void this.retire();\n this.finish(request, false, error);\n this.pump();\n }\n }\n\n private retire(): Promise<void> {\n if (this.idleTimer) clearTimeout(this.idleTimer);\n this.idleTimer = undefined;\n const worker = this.worker;\n this.worker = undefined;\n if (!worker) return this.stopping ?? Promise.resolve();\n const stopping = worker.terminate().then(() => {}, () => {});\n this.stopping = stopping;\n void stopping.then(() => {\n if (this.stopping === stopping) this.stopping = undefined;\n this.pump();\n });\n return stopping;\n }\n\n async close(): Promise<void> {\n this.closed = true;\n const active = this.active;\n this.active = undefined;\n const requests = this.pending.splice(0);\n if (active) requests.unshift(active);\n for (const request of requests) this.finish(request, false, new Error(\"Memory provider is closed\"));\n await this.retire();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,OAAO,UAAU;AACjB,SAAS,cAAc;AAMvB,IAAM,uBAAuB;AAC7B,IAAM,kBAAkB;AAaxB,IAAM,aAAa,CAAC,MAAyB,UAC3C,KAAK,WAAW,MAAM,UAAU,KAAK,QAAQ,WAAW,MAAM,QAAQ,UACtE,KAAK,QAAQ,MAAM,CAAC,OAAO,UACxB,MAA0B,OAAQ,MAAM,QAAQ,KAAK,EAAsB,EAAE;AAG3E,IAAM,uBAAN,cAAmC,eAAe;AAAA,EASvD,YACmB,eACA,YAAY,IAAI,IAAI,4BAA4B,YAAY,GAAG,GAChF;AACA,UAAM,aAAa;AAHF;AACA;AAAA,EAGnB;AAAA,EAbQ;AAAA,EACA;AAAA,EACS,UAAqB,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,SAAS;AAAA,EASjB,MAAe,OAAO,QAAgB,MAA+B,YAAuD;AAC1H,eAAW,QAAQ,eAAe;AAClC,QAAI,KAAK,OAAQ,OAAM,IAAI,MAAM,2BAA2B;AAE5D,QAAK,OAAO,KAAK,WAAW,YAAY,KAAK,OAAO,SAAS,KACzD,CAAC,CAAC,UAAU,UAAU,UAAU,EAAE,SAAS,MAAM,GAAG;AACtD,aAAO,MAAM,OAAO,QAAQ,MAAM,UAAU;AAAA,IAC9C;AACA,QAAI,KAAK,QAAQ,UAAU,KAAK,SAAS,IAAI,MAAM,sBAAsB;AACvE,YAAM,IAAI,MAAM,iCAAiC,oBAAoB,qCAAqC;AAAA,IAC5G;AACA,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,YAAM,UAAmB;AAAA,QACvB,IAAI,EAAE,KAAK;AAAA,QAAQ;AAAA,QAAQ;AAA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AQ,OAAO,CAAC;AAAA,IAC3G,SAAS,OAAO;AACd,WAAK,SAAS;AACd,WAAK,KAAK,OAAO;AACjB,WAAK,OAAO,SAAS,OAAO,KAAK;AACjC,WAAK,KAAK;AAAA,IACZ;AAAA,EACF;AAAA,EAEQ,SAAwB;AAC9B,QAAI,KAAK,UAAW,cAAa,KAAK,SAAS;AAC/C,SAAK,YAAY;AACjB,UAAM,SAAS,KAAK;AACpB,SAAK,SAAS;AACd,QAAI,CAAC,OAAQ,QAAO,KAAK,YAAY,QAAQ,QAAQ;AACrD,UAAM,WAAW,OAAO,UAAU,EAAE,KAAK,MAAM;AAAA,IAAC,GAAG,MAAM;AAAA,IAAC,CAAC;AAC3D,SAAK,WAAW;AAChB,SAAK,SAAS,KAAK,MAAM;AACvB,UAAI,KAAK,aAAa,SAAU,MAAK,WAAW;AAChD,WAAK,KAAK;AAAA,IACZ,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAuB;AAC3B,SAAK,SAAS;AACd,UAAM,SAAS,KAAK;AACpB,SAAK,SAAS;AACd,UAAM,WAAW,KAAK,QAAQ,OAAO,CAAC;AACtC,QAAI,OAAQ,UAAS,QAAQ,MAAM;AACnC,eAAW,WAAW,SAAU,MAAK,OAAO,SAAS,OAAO,IAAI,MAAM,2BAA2B,CAAC;AAClG,UAAM,KAAK,OAAO;AAAA,EACpB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
agentParticipantRecords,
|
|
10
10
|
loadModelUsage,
|
|
11
11
|
useBudgetLedger
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-KI4VAMHK.js";
|
|
13
13
|
import {
|
|
14
14
|
RESIDENT_HOST_FORMAT,
|
|
15
15
|
residentDeliveryPrefix,
|
|
@@ -689,4 +689,4 @@ if (isMain) {
|
|
|
689
689
|
export {
|
|
690
690
|
runResidentHostFromConfigPath
|
|
691
691
|
};
|
|
692
|
-
//# sourceMappingURL=chunk-
|
|
692
|
+
//# sourceMappingURL=chunk-EFHCXJTV.js.map
|
|
@@ -6,15 +6,15 @@ import {
|
|
|
6
6
|
spawnDetached,
|
|
7
7
|
workerCommand
|
|
8
8
|
} from "./chunk-X7G62ZGH.js";
|
|
9
|
+
import {
|
|
10
|
+
mapVedaTools,
|
|
11
|
+
normalizeVedaModel
|
|
12
|
+
} from "./chunk-VPPIJRNZ.js";
|
|
9
13
|
import {
|
|
10
14
|
discoverClaudeModels,
|
|
11
15
|
mapClaudeTools,
|
|
12
16
|
normalizeClaudeModel
|
|
13
17
|
} from "./chunk-PM5I335G.js";
|
|
14
|
-
import {
|
|
15
|
-
mapVedaTools,
|
|
16
|
-
normalizeVedaModel
|
|
17
|
-
} from "./chunk-VPPIJRNZ.js";
|
|
18
18
|
import {
|
|
19
19
|
peerLabelPrefix,
|
|
20
20
|
writeHandoffSession
|
|
@@ -22,15 +22,15 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
resolveAgentDir
|
|
24
24
|
} from "./chunk-PXAICAUT.js";
|
|
25
|
+
import {
|
|
26
|
+
readJsonlPage
|
|
27
|
+
} from "./chunk-CGPK5WHX.js";
|
|
25
28
|
import {
|
|
26
29
|
DEFAULT_FABRIC_CONFIG,
|
|
27
30
|
MAX_AGENT_TIMEOUT_MS,
|
|
28
31
|
MIN_AGENT_TIMEOUT_MS,
|
|
29
32
|
quarantineDamagedFile
|
|
30
33
|
} from "./chunk-YQFAHWGE.js";
|
|
31
|
-
import {
|
|
32
|
-
readJsonlPage
|
|
33
|
-
} from "./chunk-CGPK5WHX.js";
|
|
34
34
|
import {
|
|
35
35
|
writeFileAtomic,
|
|
36
36
|
writeJsonAtomic
|
|
@@ -6870,4 +6870,4 @@ export {
|
|
|
6870
6870
|
agentParticipantRecords,
|
|
6871
6871
|
actorParticipantRecord
|
|
6872
6872
|
};
|
|
6873
|
-
//# sourceMappingURL=chunk-
|
|
6873
|
+
//# sourceMappingURL=chunk-KI4VAMHK.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-J2HV2URQ.js";
|
|
5
5
|
import {
|
|
6
6
|
NESTED_TOOL_CALL_ID_PREFIX
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NSTQH46Z.js";
|
|
8
8
|
import {
|
|
9
9
|
THINKING_DIGEST_CUSTOM_TYPE,
|
|
10
10
|
buildThinkingDigest,
|
|
@@ -157,8 +157,121 @@ var CapturedToolCatalog = class {
|
|
|
157
157
|
}
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
-
// src/
|
|
160
|
+
// src/main-agent.ts
|
|
161
161
|
import { randomUUID } from "node:crypto";
|
|
162
|
+
var MAIN_AGENT_ALIAS = "main";
|
|
163
|
+
var resolveFabricIdentity = (sessionId, environment = process.env) => {
|
|
164
|
+
const actorId = environment.PI_FABRIC_ACTOR_ID?.trim();
|
|
165
|
+
const parentAgentId = environment.PI_FABRIC_PARENT_RUN?.trim();
|
|
166
|
+
const identity = actorId ? {
|
|
167
|
+
id: actorId,
|
|
168
|
+
name: environment.PI_FABRIC_ACTOR_NAME?.trim() || actorId.slice(0, 8),
|
|
169
|
+
kind: "actor",
|
|
170
|
+
sessionId
|
|
171
|
+
} : parentAgentId ? {
|
|
172
|
+
id: parentAgentId,
|
|
173
|
+
name: environment.PI_FABRIC_AGENT_NAME?.trim() || parentAgentId.slice(0, 8),
|
|
174
|
+
kind: "agent",
|
|
175
|
+
sessionId
|
|
176
|
+
} : { id: `session:${sessionId}`, name: "main", kind: "main", sessionId };
|
|
177
|
+
const inheritedMainAgentId = environment.PI_FABRIC_MAIN_AGENT_ID?.trim();
|
|
178
|
+
return {
|
|
179
|
+
identity,
|
|
180
|
+
mainAgentId: inheritedMainAgentId || (identity.kind === "main" ? identity.id : `session:${sessionId}`)
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
var escapeXmlText = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
184
|
+
var serializableData = (value) => {
|
|
185
|
+
try {
|
|
186
|
+
const serialized = JSON.stringify(value);
|
|
187
|
+
return serialized === void 0 ? void 0 : JSON.parse(serialized);
|
|
188
|
+
} catch {
|
|
189
|
+
return { fabricUnserializable: true };
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var MainAgentController = class {
|
|
193
|
+
constructor(pi, id, local, cwd, sessionId) {
|
|
194
|
+
this.pi = pi;
|
|
195
|
+
this.id = id;
|
|
196
|
+
this.local = local;
|
|
197
|
+
this.cwd = cwd;
|
|
198
|
+
this.sessionId = sessionId;
|
|
199
|
+
}
|
|
200
|
+
startedAt = Date.now();
|
|
201
|
+
matches(id) {
|
|
202
|
+
const target = id.trim();
|
|
203
|
+
return target === MAIN_AGENT_ALIAS || target === this.id;
|
|
204
|
+
}
|
|
205
|
+
info(context) {
|
|
206
|
+
const model = this.local && context?.model ? `${context.model.provider}/${context.model.id}` : void 0;
|
|
207
|
+
const thinking = this.local ? this.pi.getThinkingLevel() : void 0;
|
|
208
|
+
return {
|
|
209
|
+
id: this.id,
|
|
210
|
+
name: "Main",
|
|
211
|
+
kind: "main",
|
|
212
|
+
status: this.local ? context?.isIdle() === false ? "running" : "idle" : "remote",
|
|
213
|
+
runner: "pi",
|
|
214
|
+
transport: "host",
|
|
215
|
+
...this.local ? { cwd: this.cwd, startedAt: this.startedAt } : {},
|
|
216
|
+
...this.sessionId ? { sessionId: this.sessionId } : {},
|
|
217
|
+
...model ? { model } : {},
|
|
218
|
+
...thinking ? { thinking } : {},
|
|
219
|
+
updatedAt: Date.now(),
|
|
220
|
+
pendingMessages: this.local ? context?.hasPendingMessages() ?? false : false,
|
|
221
|
+
local: this.local
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
async switchModel(target, context) {
|
|
225
|
+
if (!this.local) {
|
|
226
|
+
return { ok: false, error: `Main agent ${this.id} is owned by another Fabric process` };
|
|
227
|
+
}
|
|
228
|
+
const key = `${target.provider}/${target.id}`;
|
|
229
|
+
const model = context.modelRegistry.find(target.provider, target.id);
|
|
230
|
+
if (!model) return { ok: false, error: `Model is not available: ${key}` };
|
|
231
|
+
const switched = await this.pi.setModel(model);
|
|
232
|
+
if (!switched) return { ok: false, error: `No authentication configured for model: ${key}` };
|
|
233
|
+
return { ok: true };
|
|
234
|
+
}
|
|
235
|
+
deliverUser(message, delivery) {
|
|
236
|
+
if (!this.local) throw new Error(`Main agent ${this.id} is owned by another Fabric process`);
|
|
237
|
+
const text = message.trim();
|
|
238
|
+
if (!text) throw new Error("Main agent message must not be empty");
|
|
239
|
+
const messageId = randomUUID();
|
|
240
|
+
this.pi.sendUserMessage(text, { deliverAs: delivery });
|
|
241
|
+
return { queued: true, messageId, routed: "main" };
|
|
242
|
+
}
|
|
243
|
+
deliverAgent(request) {
|
|
244
|
+
if (!this.local) throw new Error(`Main agent ${this.id} is owned by another Fabric process`);
|
|
245
|
+
const message = request.message.trim();
|
|
246
|
+
if (!message) throw new Error("Main agent message must not be empty");
|
|
247
|
+
const messageId = randomUUID();
|
|
248
|
+
const data = request.data === void 0 ? void 0 : serializableData(request.data);
|
|
249
|
+
this.pi.sendMessage(
|
|
250
|
+
{
|
|
251
|
+
customType: "pi-fabric-agent-message",
|
|
252
|
+
content: [
|
|
253
|
+
`<fabric-agent-message from_name=${JSON.stringify(request.from.name)} from_id=${JSON.stringify(request.from.id)} from_kind=${JSON.stringify(request.from.kind)}>`,
|
|
254
|
+
escapeXmlText(message),
|
|
255
|
+
data === void 0 ? void 0 : `<data>${escapeXmlText(JSON.stringify(data))}</data>`,
|
|
256
|
+
"</fabric-agent-message>"
|
|
257
|
+
].filter((line) => Boolean(line)).join("\n"),
|
|
258
|
+
display: true,
|
|
259
|
+
details: {
|
|
260
|
+
id: messageId,
|
|
261
|
+
from: structuredClone(request.from),
|
|
262
|
+
delivery: request.delivery,
|
|
263
|
+
triggerTurn: request.triggerTurn ?? true,
|
|
264
|
+
...data === void 0 ? {} : { data }
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
{ deliverAs: request.delivery, triggerTurn: request.triggerTurn ?? true }
|
|
268
|
+
);
|
|
269
|
+
return { queued: true, messageId, routed: "main" };
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/prewalk/handoff.ts
|
|
274
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
162
275
|
|
|
163
276
|
// src/agents/handoff-completion.ts
|
|
164
277
|
var HANDOFF_COMPLETION_MESSAGE_TYPE = "pi-fabric-handoff-complete";
|
|
@@ -324,7 +437,7 @@ var claimFabricFsDriftHandoff = (controller, execution, sessionId, drift, result
|
|
|
324
437
|
};
|
|
325
438
|
var buildPrewalkPending = (claim, resultFormat) => {
|
|
326
439
|
const inPlace = claim.arm.mode === "in-place";
|
|
327
|
-
const nestedToolCallId = `${NESTED_TOOL_CALL_ID_PREFIX}prewalk_${
|
|
440
|
+
const nestedToolCallId = `${NESTED_TOOL_CALL_ID_PREFIX}prewalk_${randomUUID2()}`;
|
|
328
441
|
const args = {
|
|
329
442
|
model: claim.arm.model,
|
|
330
443
|
name: inPlace ? "In-place Prewalk" : "Prewalk trajectory executor",
|
|
@@ -386,7 +499,7 @@ var runInPlacePrewalk = async (controller, extension, pending, context) => {
|
|
|
386
499
|
const returnModel = context.model;
|
|
387
500
|
if (!returnModel) throw new Error("Prewalk cannot determine Main return model");
|
|
388
501
|
const returnModelKey = `${returnModel.provider}/${returnModel.id}`;
|
|
389
|
-
const continuationId =
|
|
502
|
+
const continuationId = randomUUID2();
|
|
390
503
|
const switched = await extension.setModel(model);
|
|
391
504
|
if (!switched) {
|
|
392
505
|
throw new Error(`No authentication configured for prewalk model: ${modelKey}`);
|
|
@@ -735,7 +848,7 @@ var expandSkillDirMarkersForRead = (content, args, cwd) => {
|
|
|
735
848
|
};
|
|
736
849
|
|
|
737
850
|
// src/activity/store.ts
|
|
738
|
-
import { randomUUID as
|
|
851
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
739
852
|
var MAX_RUNS = 24;
|
|
740
853
|
var MAX_CALLS = 1e3;
|
|
741
854
|
var MAX_ITEMS = 1e3;
|
|
@@ -1033,7 +1146,7 @@ var FabricActivityStore = class {
|
|
|
1033
1146
|
if (!message) throw new Error("Workflow activity event message must not be empty");
|
|
1034
1147
|
const data = boundedData(input.data);
|
|
1035
1148
|
run.events.push({
|
|
1036
|
-
id:
|
|
1149
|
+
id: randomUUID3(),
|
|
1037
1150
|
message,
|
|
1038
1151
|
level: input.level ?? "info",
|
|
1039
1152
|
createdAt: Date.now(),
|
|
@@ -1842,121 +1955,10 @@ var PrewalkDriftTracker = class {
|
|
|
1842
1955
|
}
|
|
1843
1956
|
};
|
|
1844
1957
|
|
|
1845
|
-
// src/main-agent.ts
|
|
1846
|
-
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
1847
|
-
var MAIN_AGENT_ALIAS = "main";
|
|
1848
|
-
var resolveFabricIdentity = (sessionId, environment = process.env) => {
|
|
1849
|
-
const actorId = environment.PI_FABRIC_ACTOR_ID?.trim();
|
|
1850
|
-
const parentAgentId = environment.PI_FABRIC_PARENT_RUN?.trim();
|
|
1851
|
-
const identity = actorId ? {
|
|
1852
|
-
id: actorId,
|
|
1853
|
-
name: environment.PI_FABRIC_ACTOR_NAME?.trim() || actorId.slice(0, 8),
|
|
1854
|
-
kind: "actor",
|
|
1855
|
-
sessionId
|
|
1856
|
-
} : parentAgentId ? {
|
|
1857
|
-
id: parentAgentId,
|
|
1858
|
-
name: environment.PI_FABRIC_AGENT_NAME?.trim() || parentAgentId.slice(0, 8),
|
|
1859
|
-
kind: "agent",
|
|
1860
|
-
sessionId
|
|
1861
|
-
} : { id: `session:${sessionId}`, name: "main", kind: "main", sessionId };
|
|
1862
|
-
const inheritedMainAgentId = environment.PI_FABRIC_MAIN_AGENT_ID?.trim();
|
|
1863
|
-
return {
|
|
1864
|
-
identity,
|
|
1865
|
-
mainAgentId: inheritedMainAgentId || (identity.kind === "main" ? identity.id : `session:${sessionId}`)
|
|
1866
|
-
};
|
|
1867
|
-
};
|
|
1868
|
-
var escapeXmlText = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
1869
|
-
var serializableData = (value) => {
|
|
1870
|
-
try {
|
|
1871
|
-
const serialized = JSON.stringify(value);
|
|
1872
|
-
return serialized === void 0 ? void 0 : JSON.parse(serialized);
|
|
1873
|
-
} catch {
|
|
1874
|
-
return { fabricUnserializable: true };
|
|
1875
|
-
}
|
|
1876
|
-
};
|
|
1877
|
-
var MainAgentController = class {
|
|
1878
|
-
constructor(pi, id, local, cwd, sessionId) {
|
|
1879
|
-
this.pi = pi;
|
|
1880
|
-
this.id = id;
|
|
1881
|
-
this.local = local;
|
|
1882
|
-
this.cwd = cwd;
|
|
1883
|
-
this.sessionId = sessionId;
|
|
1884
|
-
}
|
|
1885
|
-
startedAt = Date.now();
|
|
1886
|
-
matches(id) {
|
|
1887
|
-
const target = id.trim();
|
|
1888
|
-
return target === MAIN_AGENT_ALIAS || target === this.id;
|
|
1889
|
-
}
|
|
1890
|
-
info(context) {
|
|
1891
|
-
const model = this.local && context?.model ? `${context.model.provider}/${context.model.id}` : void 0;
|
|
1892
|
-
const thinking = this.local ? this.pi.getThinkingLevel() : void 0;
|
|
1893
|
-
return {
|
|
1894
|
-
id: this.id,
|
|
1895
|
-
name: "Main",
|
|
1896
|
-
kind: "main",
|
|
1897
|
-
status: this.local ? context?.isIdle() === false ? "running" : "idle" : "remote",
|
|
1898
|
-
runner: "pi",
|
|
1899
|
-
transport: "host",
|
|
1900
|
-
...this.local ? { cwd: this.cwd, startedAt: this.startedAt } : {},
|
|
1901
|
-
...this.sessionId ? { sessionId: this.sessionId } : {},
|
|
1902
|
-
...model ? { model } : {},
|
|
1903
|
-
...thinking ? { thinking } : {},
|
|
1904
|
-
updatedAt: Date.now(),
|
|
1905
|
-
pendingMessages: this.local ? context?.hasPendingMessages() ?? false : false,
|
|
1906
|
-
local: this.local
|
|
1907
|
-
};
|
|
1908
|
-
}
|
|
1909
|
-
async switchModel(target, context) {
|
|
1910
|
-
if (!this.local) {
|
|
1911
|
-
return { ok: false, error: `Main agent ${this.id} is owned by another Fabric process` };
|
|
1912
|
-
}
|
|
1913
|
-
const key = `${target.provider}/${target.id}`;
|
|
1914
|
-
const model = context.modelRegistry.find(target.provider, target.id);
|
|
1915
|
-
if (!model) return { ok: false, error: `Model is not available: ${key}` };
|
|
1916
|
-
const switched = await this.pi.setModel(model);
|
|
1917
|
-
if (!switched) return { ok: false, error: `No authentication configured for model: ${key}` };
|
|
1918
|
-
return { ok: true };
|
|
1919
|
-
}
|
|
1920
|
-
deliverUser(message, delivery) {
|
|
1921
|
-
if (!this.local) throw new Error(`Main agent ${this.id} is owned by another Fabric process`);
|
|
1922
|
-
const text = message.trim();
|
|
1923
|
-
if (!text) throw new Error("Main agent message must not be empty");
|
|
1924
|
-
const messageId = randomUUID3();
|
|
1925
|
-
this.pi.sendUserMessage(text, { deliverAs: delivery });
|
|
1926
|
-
return { queued: true, messageId, routed: "main" };
|
|
1927
|
-
}
|
|
1928
|
-
deliverAgent(request) {
|
|
1929
|
-
if (!this.local) throw new Error(`Main agent ${this.id} is owned by another Fabric process`);
|
|
1930
|
-
const message = request.message.trim();
|
|
1931
|
-
if (!message) throw new Error("Main agent message must not be empty");
|
|
1932
|
-
const messageId = randomUUID3();
|
|
1933
|
-
const data = request.data === void 0 ? void 0 : serializableData(request.data);
|
|
1934
|
-
this.pi.sendMessage(
|
|
1935
|
-
{
|
|
1936
|
-
customType: "pi-fabric-agent-message",
|
|
1937
|
-
content: [
|
|
1938
|
-
`<fabric-agent-message from_name=${JSON.stringify(request.from.name)} from_id=${JSON.stringify(request.from.id)} from_kind=${JSON.stringify(request.from.kind)}>`,
|
|
1939
|
-
escapeXmlText(message),
|
|
1940
|
-
data === void 0 ? void 0 : `<data>${escapeXmlText(JSON.stringify(data))}</data>`,
|
|
1941
|
-
"</fabric-agent-message>"
|
|
1942
|
-
].filter((line) => Boolean(line)).join("\n"),
|
|
1943
|
-
display: true,
|
|
1944
|
-
details: {
|
|
1945
|
-
id: messageId,
|
|
1946
|
-
from: structuredClone(request.from),
|
|
1947
|
-
delivery: request.delivery,
|
|
1948
|
-
triggerTurn: request.triggerTurn ?? true,
|
|
1949
|
-
...data === void 0 ? {} : { data }
|
|
1950
|
-
}
|
|
1951
|
-
},
|
|
1952
|
-
{ deliverAs: request.delivery, triggerTurn: request.triggerTurn ?? true }
|
|
1953
|
-
);
|
|
1954
|
-
return { queued: true, messageId, routed: "main" };
|
|
1955
|
-
}
|
|
1956
|
-
};
|
|
1957
|
-
|
|
1958
1958
|
export {
|
|
1959
1959
|
CapturedToolCatalog,
|
|
1960
|
+
resolveFabricIdentity,
|
|
1961
|
+
MainAgentController,
|
|
1960
1962
|
HANDOFF_COMPLETION_MESSAGE_TYPE,
|
|
1961
1963
|
PREWALK_ARMED_MESSAGE_TYPE,
|
|
1962
1964
|
filterPrewalkContinuationMessages,
|
|
@@ -1977,8 +1979,6 @@ export {
|
|
|
1977
1979
|
FabricProviderComponentManifest,
|
|
1978
1980
|
createProviderComponent,
|
|
1979
1981
|
PrewalkController,
|
|
1980
|
-
PrewalkDriftTracker
|
|
1981
|
-
resolveFabricIdentity,
|
|
1982
|
-
MainAgentController
|
|
1982
|
+
PrewalkDriftTracker
|
|
1983
1983
|
};
|
|
1984
|
-
//# sourceMappingURL=chunk-
|
|
1984
|
+
//# sourceMappingURL=chunk-MAP2LVSM.js.map
|