@e4779/pi-fabric 0.117.2-fork.28 → 0.117.2-fork.30

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.
@@ -8,7 +8,7 @@ import {
8
8
  agentParticipantRecords,
9
9
  loadModelUsage,
10
10
  useBudgetLedger
11
- } from "./chunk-ZPPNWB64.js";
11
+ } from "./chunk-FE6NOAO7.js";
12
12
  import {
13
13
  MeshStore
14
14
  } from "./chunk-EFETPXU2.js";
@@ -815,4 +815,4 @@ export {
815
815
  residentIdleDecision,
816
816
  runResidentHostFromConfigPath
817
817
  };
818
- //# sourceMappingURL=chunk-XWWV6TKV.js.map
818
+ //# sourceMappingURL=chunk-LNASO4VT.js.map
@@ -6902,4 +6902,4 @@ export {
6902
6902
  FABRIC_MANAGED_HOST_VERSION,
6903
6903
  createFabricExtension
6904
6904
  };
6905
- //# sourceMappingURL=chunk-YKYWY722.js.map
6905
+ //# sourceMappingURL=chunk-XCEEQ5AB.js.map
@@ -0,0 +1,21 @@
1
+ /** Inserted right after the SDK's `[DONE]` guard inside the SSE consumer loop. */
2
+ export declare const openAiSseKeepaliveMarker = "\nif (!sse.data || !sse.data.trim()) continue;";
3
+ export interface OpenAiSsePatchResult {
4
+ source: string;
5
+ applied: boolean;
6
+ }
7
+ /**
8
+ * Rewrite the SDK's SSE consumer so empty or whitespace-only `data:` events
9
+ * are skipped instead of reaching `JSON.parse`. Idempotent; throws when the
10
+ * `[DONE]` guard is absent so an upstream refactor surfaces as a loud
11
+ * warning (the load hook skips patching) rather than a silent regression.
12
+ */
13
+ export declare function patchOpenAiSseStreaming(source: string): OpenAiSsePatchResult;
14
+ /**
15
+ * Whether a module URL is the OpenAI SDK's SSE decoder (`core/streaming.*`).
16
+ * Deliberately loose about the package scope (any package literally named
17
+ * `openai`) and strict about the path, so lookalikes (`not-openai/...`)
18
+ * and unrelated files (`openai/index.mjs`) stay untouched.
19
+ */
20
+ export declare function isOpenAiStreamingModuleUrl(url: string): boolean;
21
+ //# sourceMappingURL=openai-sse-patch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-sse-patch.d.ts","sourceRoot":"","sources":["../../src/durable/openai-sse-patch.ts"],"names":[],"mappings":"AAYA,kFAAkF;AAClF,eAAO,MAAM,wBAAwB,mDAAmD,CAAC;AAIzF,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAe5E;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/D"}
@@ -5,6 +5,29 @@ import { spawn } from "node:child_process";
5
5
  import module from "node:module";
6
6
  import { fileURLToPath } from "node:url";
7
7
 
8
+ // src/durable/openai-sse-patch.ts
9
+ var openAiSseKeepaliveMarker = "\nif (!sse.data || !sse.data.trim()) continue;";
10
+ var doneGuardPattern = /if\s*\(\s*sse\.data\s*===\s*(["'])\[DONE\]\1\s*\)\s*\{[^{}]*\}/;
11
+ function patchOpenAiSseStreaming(source) {
12
+ if (source.includes("!sse.data.trim()) continue;") || source.includes("!sse.data.trim())continue;")) {
13
+ return { source, applied: false };
14
+ }
15
+ const guard = doneGuardPattern.exec(source);
16
+ if (!guard) {
17
+ throw new Error(
18
+ "openai SSE keepalive patch: `[DONE]` guard not found in the streaming decoder source (upstream layout changed)"
19
+ );
20
+ }
21
+ const insertAt = guard.index + guard[0].length;
22
+ return {
23
+ source: source.slice(0, insertAt) + openAiSseKeepaliveMarker + source.slice(insertAt),
24
+ applied: true
25
+ };
26
+ }
27
+ function isOpenAiStreamingModuleUrl(url) {
28
+ return url.includes("/openai/core/streaming.");
29
+ }
30
+
8
31
  // src/durable/worker-options.ts
9
32
  import path from "node:path";
10
33
  function parseDurableWorkerOptions(argv, cwd = process.cwd()) {
@@ -97,6 +120,25 @@ try {
97
120
  return nextResolve(specifier, { ...context, parentURL: sdkEntry });
98
121
  }
99
122
  return nextResolve(specifier, context);
123
+ },
124
+ // Provider gateways in front of OpenAI-compatible endpoints (observed
125
+ // with GLM-5.2 behind ai-sbt-hub) send bare `data: \n\n` keepalives
126
+ // during long reasoning pauses; the SDK parses the empty payload and
127
+ // aborts the whole generation. Patch its streaming decoder in memory
128
+ // before it loads — no on-disk mutation.
129
+ load(url, context, nextLoad) {
130
+ const loaded = nextLoad(url, context);
131
+ if (loaded.source != null && isOpenAiStreamingModuleUrl(url)) {
132
+ try {
133
+ const text = typeof loaded.source === "string" ? loaded.source : new TextDecoder().decode(loaded.source);
134
+ const patched = patchOpenAiSseStreaming(text);
135
+ if (patched.applied) loaded.source = patched.source;
136
+ } catch (error) {
137
+ process.stderr.write(`pi-fabric worker: openai SSE keepalive patch skipped: ${error instanceof Error ? error.message : String(error)}
138
+ `);
139
+ }
140
+ }
141
+ return loaded;
100
142
  }
101
143
  });
102
144
  const { runDurableWorker } = await import("./worker-host.js");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/durable/worker.ts", "../../src/durable/worker-options.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\nimport { spawn } from \"node:child_process\";\nimport module from \"node:module\";\nimport { fileURLToPath } from \"node:url\";\nimport { parseDurableWorkerOptions } from \"./worker-options.js\";\n\ntry {\n // This process-only entry is never imported by extension registration.\n const options = parseDurableWorkerOptions(process.argv.slice(2));\n if (process.versions.bun) {\n // Bun cannot install Node's peer-resolution hooks. Keep the pinned SDK in\n // the package's required Node 24+ runtime; never inject ambient NODE_PATH.\n const child = spawn(\"node\", [fileURLToPath(import.meta.url), ...process.argv.slice(2)], { stdio: \"inherit\" });\n const code = await new Promise<number>((resolve, reject) => {\n child.once(\"error\", error => reject(new Error(`Bun-launched durable workers require Node.js 24+ on PATH: ${error.message}`, { cause: error })));\n child.once(\"exit\", (code, signal) => resolve(code ?? (signal ? 1 : 0)));\n });\n process.exitCode = code;\n } else {\n if (Number.parseInt(process.versions.node, 10) < 24) throw new Error(\"Durable Pi workers require Node.js 24+\");\n // Managed Pi installs omit host peers. A subprocess cannot use Main's virtual\n // modules, so it owns a pinned SDK under a non-peer name. Resolve all Pi peers\n // through that SDK's dependency tree (also with non-hoisting installers), not\n // an ambient checkout or another extension's SDK. This hook is process-local\n // and must be installed before importing any durable host/engine modules.\n const sdkEntry = import.meta.resolve(\"pi-fabric-worker-sdk\");\n const sdkName = \"@earendil-works/pi-coding-agent\";\n const peers = [\"@earendil-works/pi-agent-core\", \"@earendil-works/pi-ai\", \"@earendil-works/pi-tui\", \"typebox\"];\n module.registerHooks({\n resolve(specifier, context, nextResolve) {\n if (specifier === sdkName || specifier.startsWith(`${sdkName}/`)) {\n return nextResolve(`pi-fabric-worker-sdk${specifier.slice(sdkName.length)}`, { ...context, parentURL: import.meta.url });\n }\n if (peers.some(name => specifier === name || specifier.startsWith(`${name}/`))) {\n return nextResolve(specifier, { ...context, parentURL: sdkEntry });\n }\n return nextResolve(specifier, context);\n },\n });\n const { runDurableWorker } = await import(\"./worker-host.js\");\n await runDurableWorker(options);\n }\n} catch (error) {\n process.stderr.write(`Durable Pi worker failed: ${error instanceof Error ? error.stack ?? error.message : String(error)}\\n`);\n process.exitCode = 1;\n}\n", "import path from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport interface DurableWorkerOptions {\n directory: string;\n runId: string;\n sessionFile?: string;\n model?: string;\n provider?: string;\n thinking?: ThinkingLevel;\n tools?: string[];\n noTools?: \"all\";\n extensions: string[];\n noExtensions: boolean;\n appendSystemPrompt: string;\n}\n\n/** Internal worker protocol, deliberately not a second general-purpose Pi CLI. */\nexport function parseDurableWorkerOptions(argv: readonly string[], cwd = process.cwd()): DurableWorkerOptions {\n const options: DurableWorkerOptions = {\n directory: \"\", runId: \"\", extensions: [], noExtensions: false, appendSystemPrompt: \"\",\n };\n const prompts: string[] = [];\n for (let i = 0; i < argv.length; i++) {\n const flag = argv[i]!;\n if (flag === \"--no-session\") continue;\n if (flag === \"--no-extensions\") { options.noExtensions = true; continue; }\n if (flag === \"--no-tools\") { options.noTools = \"all\"; continue; }\n if (![\"--mode\", \"--durable-directory\", \"--durable-run-id\", \"--session\", \"--model\", \"--provider\", \"--thinking\", \"--tools\", \"-e\", \"--extension\", \"--append-system-prompt\"].includes(flag)) {\n throw new Error(`Unsupported durable worker option: ${flag}`);\n }\n const value = argv[++i];\n if (value === undefined || value.startsWith(\"--\")) throw new Error(`Missing value for ${flag}`);\n switch (flag) {\n case \"--mode\": if (value !== \"rpc\") throw new Error(\"The durable worker only supports RPC mode\"); break;\n case \"--durable-directory\": options.directory = path.resolve(cwd, value); break;\n case \"--durable-run-id\": options.runId = value.trim(); break;\n case \"--session\": options.sessionFile = path.resolve(cwd, value); break;\n case \"--model\": options.model = value; break;\n case \"--provider\": options.provider = value; break;\n case \"--thinking\":\n if (![\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"].includes(value)) throw new Error(`Invalid thinking level: ${value}`);\n options.thinking = value as ThinkingLevel;\n break;\n case \"--tools\": options.tools = value.split(\",\").map(tool => tool.trim()).filter(Boolean); break;\n case \"-e\": case \"--extension\": options.extensions.push(value.startsWith(\"builtin:\") ? value : path.resolve(cwd, value)); break;\n case \"--append-system-prompt\": prompts.push(value); break;\n }\n }\n if (!options.directory || !options.runId) throw new Error(\"Durable workers require --durable-directory and --durable-run-id\");\n if (options.tools && options.noTools) throw new Error(\"--tools and --no-tools are mutually exclusive\");\n options.appendSystemPrompt = prompts.join(\"\\n\\n\");\n return options;\n}\n"],
5
- "mappings": ";;;AACA,SAAS,aAAa;AACtB,OAAO,YAAY;AACnB,SAAS,qBAAqB;;;ACH9B,OAAO,UAAU;AAkBV,SAAS,0BAA0B,MAAyB,MAAM,QAAQ,IAAI,GAAyB;AAC5G,QAAM,UAAgC;AAAA,IACpC,WAAW;AAAA,IA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B,SAAS;AAC5G,WAAO,cAAc;AAAA,MACnB,QAAQ,WAAW,SAAS,aAAa;AACvC,YAAI,cAAc,WAAW,UAAU,WAAW,GAAG,OAAO,GAAG,GAAG;AAChE,iBAAO,YAAY,uBAAuB,UAAU,MAAM,QAAQ,MAAM,CAAC,IAAI,EAAE,GAAG,SAAS,WAAW,YAAY,IAAI,CAAC;AAAA,QACzH;AACA,YAAI,MAAM,KAAK,UAAQ,cAAc,QAAQ,UAAU,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG;AAC9E,iBAAO,YAAY,WAAW,EAAE,GAAG,SAAS,WAAW,SAAS,CAAC;AAAA,QACnE;AACA,eAAO,YAAY,WAAW,OAAO;AAAA,MACvC;AAAA,IACF,CAAC;AACD,UAAM,EAAE,iBAAiB,IAAI,MAAM,OAAO,kBAAkB;AAC5D,UAAM,iBAAiB,OAAO;AAAA,EAChC;AACF,SAAS,OAAO;AACd,UAAQ,OAAO,MAAM,6BAA6B,iBAAiB,QAAQ,MAAM,SAAS,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,CAAI;AAC3H,UAAQ,WAAW;AACrB;",
3
+ "sources": ["../../src/durable/worker.ts", "../../src/durable/openai-sse-patch.ts", "../../src/durable/worker-options.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\nimport { spawn } from \"node:child_process\";\nimport module from \"node:module\";\nimport { fileURLToPath } from \"node:url\";\nimport { isOpenAiStreamingModuleUrl, patchOpenAiSseStreaming } from \"./openai-sse-patch.js\";\nimport { parseDurableWorkerOptions } from \"./worker-options.js\";\n\ntry {\n // This process-only entry is never imported by extension registration.\n const options = parseDurableWorkerOptions(process.argv.slice(2));\n if (process.versions.bun) {\n // Bun cannot install Node's peer-resolution hooks. Keep the pinned SDK in\n // the package's required Node 24+ runtime; never inject ambient NODE_PATH.\n const child = spawn(\"node\", [fileURLToPath(import.meta.url), ...process.argv.slice(2)], { stdio: \"inherit\" });\n const code = await new Promise<number>((resolve, reject) => {\n child.once(\"error\", error => reject(new Error(`Bun-launched durable workers require Node.js 24+ on PATH: ${error.message}`, { cause: error })));\n child.once(\"exit\", (code, signal) => resolve(code ?? (signal ? 1 : 0)));\n });\n process.exitCode = code;\n } else {\n if (Number.parseInt(process.versions.node, 10) < 24) throw new Error(\"Durable Pi workers require Node.js 24+\");\n // Managed Pi installs omit host peers. A subprocess cannot use Main's virtual\n // modules, so it owns a pinned SDK under a non-peer name. Resolve all Pi peers\n // through that SDK's dependency tree (also with non-hoisting installers), not\n // an ambient checkout or another extension's SDK. This hook is process-local\n // and must be installed before importing any durable host/engine modules.\n const sdkEntry = import.meta.resolve(\"pi-fabric-worker-sdk\");\n const sdkName = \"@earendil-works/pi-coding-agent\";\n const peers = [\"@earendil-works/pi-agent-core\", \"@earendil-works/pi-ai\", \"@earendil-works/pi-tui\", \"typebox\"];\n module.registerHooks({\n resolve(specifier, context, nextResolve) {\n if (specifier === sdkName || specifier.startsWith(`${sdkName}/`)) {\n return nextResolve(`pi-fabric-worker-sdk${specifier.slice(sdkName.length)}`, { ...context, parentURL: import.meta.url });\n }\n if (peers.some(name => specifier === name || specifier.startsWith(`${name}/`))) {\n return nextResolve(specifier, { ...context, parentURL: sdkEntry });\n }\n return nextResolve(specifier, context);\n },\n // Provider gateways in front of OpenAI-compatible endpoints (observed\n // with GLM-5.2 behind ai-sbt-hub) send bare `data: \\n\\n` keepalives\n // during long reasoning pauses; the SDK parses the empty payload and\n // aborts the whole generation. Patch its streaming decoder in memory\n // before it loads \u2014 no on-disk mutation.\n load(url, context, nextLoad) {\n const loaded = nextLoad(url, context);\n if (loaded.source != null && isOpenAiStreamingModuleUrl(url)) {\n try {\n // The default load returns file contents as bytes, not a string.\n const text = typeof loaded.source === \"string\" ? loaded.source : new TextDecoder().decode(loaded.source);\n const patched = patchOpenAiSseStreaming(text);\n if (patched.applied) loaded.source = patched.source;\n } catch (error) {\n process.stderr.write(`pi-fabric worker: openai SSE keepalive patch skipped: ${error instanceof Error ? error.message : String(error)}\\n`);\n }\n }\n return loaded;\n },\n });\n const { runDurableWorker } = await import(\"./worker-host.js\");\n await runDurableWorker(options);\n }\n} catch (error) {\n process.stderr.write(`Durable Pi worker failed: ${error instanceof Error ? error.stack ?? error.message : String(error)}\\n`);\n process.exitCode = 1;\n}\n", "// Empty SSE keepalive tolerance for the OpenAI SDK's streaming decoder.\n//\n// Gateways in front of OpenAI-compatible endpoints (observed with GLM-5.2\n// behind ai-sbt-hub) hold the connection open during long reasoning pauses\n// with bare `data: \\n\\n` lines instead of SSE comments. The SDK's\n// `Stream.fromSSEResponse` only special-cases `[DONE]`, so an empty payload\n// reaches `JSON.parse(\"\")` and aborts the whole generation with\n// \"Error reading response: malformed server-sent event JSON.\", discarding\n// the partial output. An empty `data:` carries no payload: the consumer loop\n// skips it instead. The patch is applied in memory by the durable worker's\n// module load hook (see durable/worker.ts); nothing on disk is modified.\n\n/** Inserted right after the SDK's `[DONE]` guard inside the SSE consumer loop. */\nexport const openAiSseKeepaliveMarker = \"\\nif (!sse.data || !sse.data.trim()) continue;\";\n\nconst doneGuardPattern = /if\\s*\\(\\s*sse\\.data\\s*===\\s*([\"'])\\[DONE\\]\\1\\s*\\)\\s*\\{[^{}]*\\}/;\n\nexport interface OpenAiSsePatchResult {\n source: string;\n applied: boolean;\n}\n\n/**\n * Rewrite the SDK's SSE consumer so empty or whitespace-only `data:` events\n * are skipped instead of reaching `JSON.parse`. Idempotent; throws when the\n * `[DONE]` guard is absent so an upstream refactor surfaces as a loud\n * warning (the load hook skips patching) rather than a silent regression.\n */\nexport function patchOpenAiSseStreaming(source: string): OpenAiSsePatchResult {\n if (source.includes(\"!sse.data.trim()) continue;\") || source.includes(\"!sse.data.trim())continue;\")) {\n return { source, applied: false };\n }\n const guard = doneGuardPattern.exec(source);\n if (!guard) {\n throw new Error(\n \"openai SSE keepalive patch: `[DONE]` guard not found in the streaming decoder source (upstream layout changed)\",\n );\n }\n const insertAt = guard.index + guard[0].length;\n return {\n source: source.slice(0, insertAt) + openAiSseKeepaliveMarker + source.slice(insertAt),\n applied: true,\n };\n}\n\n/**\n * Whether a module URL is the OpenAI SDK's SSE decoder (`core/streaming.*`).\n * Deliberately loose about the package scope (any package literally named\n * `openai`) and strict about the path, so lookalikes (`not-openai/...`)\n * and unrelated files (`openai/index.mjs`) stay untouched.\n */\nexport function isOpenAiStreamingModuleUrl(url: string): boolean {\n return url.includes(\"/openai/core/streaming.\");\n}\n", "import path from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\n\nexport interface DurableWorkerOptions {\n directory: string;\n runId: string;\n sessionFile?: string;\n model?: string;\n provider?: string;\n thinking?: ThinkingLevel;\n tools?: string[];\n noTools?: \"all\";\n extensions: string[];\n noExtensions: boolean;\n appendSystemPrompt: string;\n}\n\n/** Internal worker protocol, deliberately not a second general-purpose Pi CLI. */\nexport function parseDurableWorkerOptions(argv: readonly string[], cwd = process.cwd()): DurableWorkerOptions {\n const options: DurableWorkerOptions = {\n directory: \"\", runId: \"\", extensions: [], noExtensions: false, appendSystemPrompt: \"\",\n };\n const prompts: string[] = [];\n for (let i = 0; i < argv.length; i++) {\n const flag = argv[i]!;\n if (flag === \"--no-session\") continue;\n if (flag === \"--no-extensions\") { options.noExtensions = true; continue; }\n if (flag === \"--no-tools\") { options.noTools = \"all\"; continue; }\n if (![\"--mode\", \"--durable-directory\", \"--durable-run-id\", \"--session\", \"--model\", \"--provider\", \"--thinking\", \"--tools\", \"-e\", \"--extension\", \"--append-system-prompt\"].includes(flag)) {\n throw new Error(`Unsupported durable worker option: ${flag}`);\n }\n const value = argv[++i];\n if (value === undefined || value.startsWith(\"--\")) throw new Error(`Missing value for ${flag}`);\n switch (flag) {\n case \"--mode\": if (value !== \"rpc\") throw new Error(\"The durable worker only supports RPC mode\"); break;\n case \"--durable-directory\": options.directory = path.resolve(cwd, value); break;\n case \"--durable-run-id\": options.runId = value.trim(); break;\n case \"--session\": options.sessionFile = path.resolve(cwd, value); break;\n case \"--model\": options.model = value; break;\n case \"--provider\": options.provider = value; break;\n case \"--thinking\":\n if (![\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"].includes(value)) throw new Error(`Invalid thinking level: ${value}`);\n options.thinking = value as ThinkingLevel;\n break;\n case \"--tools\": options.tools = value.split(\",\").map(tool => tool.trim()).filter(Boolean); break;\n case \"-e\": case \"--extension\": options.extensions.push(value.startsWith(\"builtin:\") ? value : path.resolve(cwd, value)); break;\n case \"--append-system-prompt\": prompts.push(value); break;\n }\n }\n if (!options.directory || !options.runId) throw new Error(\"Durable workers require --durable-directory and --durable-run-id\");\n if (options.tools && options.noTools) throw new Error(\"--tools and --no-tools are mutually exclusive\");\n options.appendSystemPrompt = prompts.join(\"\\n\\n\");\n return options;\n}\n"],
5
+ "mappings": ";;;AACA,SAAS,aAAa;AACtB,OAAO,YAAY;AACnB,SAAS,qBAAqB;;;ACUvB,IAAM,2BAA2B;AAExC,IAAM,mBAAmB;AAalB,SAAS,wBAAwB,QAAsC;AAC5E,MAAI,OAAO,SAAS,6BAA6B,KAAK,OAAO,SAAS,4BAA4B,GAAG;AACnG,WAAO,EAAE,QAAQ,SAAS,MAAM;AAAA,EAClC;AACA,QAAM,QAAQ,iBAAiB,KAAK,MAAM;AAC1C,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,WAAW,MAAM,QAAQ,MAAM,CAAC,EAAE;AACxC,SAAO;AAAA,IACL,QAAQ,OAAO,MAAM,GAAG,QAAQ,IAAI,2BAA2B,OAAO,MAAM,QAAQ;AAAA,IACpF,SAAS;AAAA,EACX;AACF;AAQO,SAAS,2BAA2B,KAAsB;AAC/D,SAAO,IAAI,SAAS,yBAAyB;AAC/C;;;ACrDA,OAAO,UAAU;AAkBV,SAAS,0BAA0B,MAAyB,MAAM,QAAQ,IAAI,GAAyB;AAC5G,QAAM,UAAgC;AAAA,IACpC,WAAW;AAAA,IAAI,OAAO;AAAA,IAAI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
  import {
2
2
  FABRIC_MANAGED_HOST_VERSION,
3
3
  createFabricExtension
4
- } from "./chunks/chunk-YKYWY722.js";
4
+ } from "./chunks/chunk-XCEEQ5AB.js";
5
5
  import "./chunks/chunk-3UGN25XS.js";
6
6
  import "./chunks/chunk-J7ZQERKA.js";
7
7
  import "./chunks/chunk-QNMQJNXE.js";
@@ -115,7 +115,7 @@ import {
115
115
  snapshotHandoffSession,
116
116
  thinkingTransferPolicy,
117
117
  withInheritedSessionPins
118
- } from "./chunks/chunk-ZPPNWB64.js";
118
+ } from "./chunks/chunk-FE6NOAO7.js";
119
119
  import {
120
120
  readTraceContext
121
121
  } from "./chunks/chunk-QRN433TI.js";
package/dist/index.js CHANGED
@@ -86,7 +86,7 @@ import {
86
86
  createFabricExtension,
87
87
  createFabricPersistedExecutionDetails,
88
88
  readFabricExecutionRenderDetails
89
- } from "./chunks/chunk-YKYWY722.js";
89
+ } from "./chunks/chunk-XCEEQ5AB.js";
90
90
  import "./chunks/chunk-3UGN25XS.js";
91
91
  import "./chunks/chunk-J7ZQERKA.js";
92
92
  import "./chunks/chunk-QNMQJNXE.js";
@@ -2,8 +2,8 @@
2
2
  import {
3
3
  residentIdleDecision,
4
4
  runResidentHostFromConfigPath
5
- } from "../chunks/chunk-XWWV6TKV.js";
6
- import "../chunks/chunk-ZPPNWB64.js";
5
+ } from "../chunks/chunk-LNASO4VT.js";
6
+ import "../chunks/chunk-FE6NOAO7.js";
7
7
  import "../chunks/chunk-QRN433TI.js";
8
8
  import "../chunks/chunk-SVDHQUTM.js";
9
9
  import "../chunks/chunk-PM5I335G.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  runResidentHostFromConfigPath
3
- } from "../chunks/chunk-XWWV6TKV.js";
4
- import "../chunks/chunk-ZPPNWB64.js";
3
+ } from "../chunks/chunk-LNASO4VT.js";
4
+ import "../chunks/chunk-FE6NOAO7.js";
5
5
  import "../chunks/chunk-QRN433TI.js";
6
6
  import "../chunks/chunk-SVDHQUTM.js";
7
7
  import "../chunks/chunk-PM5I335G.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e4779/pi-fabric",
3
- "version": "0.117.2-fork.28",
3
+ "version": "0.117.2-fork.30",
4
4
  "description": "A programmable tool and agent runtime for Pi",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",