@caupulican/pi-adaptative 0.85.4 → 0.85.8
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 +31 -0
- package/dist/bun/cli.d.ts +1 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +1 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +1 -1
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +6 -3
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -2
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +2 -2
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +2 -2
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/bash-executor.js +2 -2
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/billing-failover-controller.d.ts +2 -2
- package/dist/core/billing-failover-controller.d.ts.map +1 -1
- package/dist/core/billing-failover-controller.js +1 -1
- package/dist/core/billing-failover-controller.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +8 -2
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +73 -3
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/compaction-support.d.ts +2 -2
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +9 -1
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/artifact-retrieval.d.ts +1 -1
- package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
- package/dist/core/context/artifact-retrieval.js +1 -1
- package/dist/core/context/artifact-retrieval.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts +6 -6
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +151 -63
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-composition.js +1 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +5 -2
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/file-store-memory-provider.js +1 -1
- package/dist/core/context/file-store-memory-provider.js.map +1 -1
- package/dist/core/context/tool-output-packer.d.ts +1 -1
- package/dist/core/context/tool-output-packer.d.ts.map +1 -1
- package/dist/core/context/tool-output-packer.js +1 -1
- package/dist/core/context/tool-output-packer.js.map +1 -1
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +7 -5
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +2 -2
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +8 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js +1 -1
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +2 -2
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/cost/session-usage.d.ts +1 -1
- package/dist/core/cost/session-usage.d.ts.map +1 -1
- package/dist/core/cost/session-usage.js +1 -1
- package/dist/core/cost/session-usage.js.map +1 -1
- package/dist/core/delegation/worker-actions.js +1 -1
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +3 -2
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-conversation-store.d.ts +2 -1
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
- package/dist/core/delegation/worker-conversation-store.js +3 -2
- package/dist/core/delegation/worker-conversation-store.js.map +1 -1
- package/dist/core/extensions/builtin.d.ts +2 -2
- package/dist/core/extensions/builtin.d.ts.map +1 -1
- package/dist/core/extensions/builtin.js +2 -2
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/bundled-virtual-modules.d.ts +2 -0
- package/dist/core/extensions/bundled-virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/bundled-virtual-modules.js +129 -0
- package/dist/core/extensions/bundled-virtual-modules.js.map +1 -0
- package/dist/core/extensions/factory-runtime.d.ts +22 -0
- package/dist/core/extensions/factory-runtime.d.ts.map +1 -0
- package/dist/core/extensions/factory-runtime.js +334 -0
- package/dist/core/extensions/factory-runtime.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/lifecycle.d.ts +13 -0
- package/dist/core/extensions/lifecycle.d.ts.map +1 -0
- package/dist/core/extensions/lifecycle.js +52 -0
- package/dist/core/extensions/lifecycle.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +3 -24
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +21 -531
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts +51 -0
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/virtual-modules.js +59 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -0
- package/dist/core/foreground-recovery-controller.d.ts +2 -1
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
- package/dist/core/foreground-recovery-controller.js +3 -3
- package/dist/core/foreground-recovery-controller.js.map +1 -1
- package/dist/core/goal-loop-controller.js +1 -1
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +1 -1
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +1 -1
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +1 -1
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +1 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/memory/providers/file-store.d.ts.map +1 -1
- package/dist/core/memory/providers/file-store.js +1 -1
- package/dist/core/memory/providers/file-store.js.map +1 -1
- package/dist/core/memory/providers/user-memory-archive.js +1 -1
- package/dist/core/memory/providers/user-memory-archive.js.map +1 -1
- package/dist/core/model-registry.d.ts +2 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +4 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router-controller.js +1 -1
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.js +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +1 -1
- package/dist/core/model-tool-protocol.d.ts.map +1 -1
- package/dist/core/model-tool-protocol.js +1 -1
- package/dist/core/model-tool-protocol.js.map +1 -1
- package/dist/core/models/llamacpp-runtime.d.ts +7 -0
- package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
- package/dist/core/models/llamacpp-runtime.js +8 -3
- package/dist/core/models/llamacpp-runtime.js.map +1 -1
- package/dist/core/models/local-runtime.js +1 -1
- package/dist/core/models/local-runtime.js.map +1 -1
- package/dist/core/orchestration/model-binding.d.ts +1 -1
- package/dist/core/orchestration/model-binding.d.ts.map +1 -1
- package/dist/core/orchestration/model-binding.js +1 -1
- package/dist/core/orchestration/model-binding.js.map +1 -1
- package/dist/core/orchestration/task-profile-writer.js +1 -1
- package/dist/core/orchestration/task-profile-writer.js.map +1 -1
- package/dist/core/process-matrix/runtime.d.ts +15 -1
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +55 -34
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +4 -3
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +2 -2
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/research/model-fitness-controller.js +1 -1
- package/dist/core/research/model-fitness-controller.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +2 -2
- package/dist/core/research/research-lane-controller.d.ts.map +1 -1
- package/dist/core/research/research-lane-controller.js +1 -1
- package/dist/core/research/research-lane-controller.js.map +1 -1
- package/dist/core/resource-loader.d.ts +10 -19
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +8 -70
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +13 -3
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/scout-controller.d.ts +1 -1
- package/dist/core/scout-controller.d.ts.map +1 -1
- package/dist/core/scout-controller.js +1 -1
- package/dist/core/scout-controller.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -3
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/security/context-threat-scanner.d.ts +14 -0
- package/dist/core/security/context-threat-scanner.d.ts.map +1 -0
- package/dist/core/security/context-threat-scanner.js +71 -0
- package/dist/core/security/context-threat-scanner.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +4 -1
- package/dist/core/session-supervision-runtime.d.ts.map +1 -1
- package/dist/core/session-supervision-runtime.js +49 -11
- package/dist/core/session-supervision-runtime.js.map +1 -1
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tool-recovery-logger.js +1 -1
- package/dist/core/tool-recovery-logger.js.map +1 -1
- package/dist/core/tools/artifact-retrieve.js +1 -1
- package/dist/core/tools/artifact-retrieve.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -4
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/extensionify-runtime.d.ts +44 -0
- package/dist/core/tools/extensionify-runtime.d.ts.map +1 -0
- package/dist/core/tools/extensionify-runtime.js +115 -0
- package/dist/core/tools/extensionify-runtime.js.map +1 -0
- package/dist/core/tools/extensionify.d.ts +9 -30
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +10 -140
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/find.d.ts +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/index.d.ts +2 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +7 -43
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +1 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/render-utils.js +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/search-command-guard.d.ts +8 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -1
- package/dist/core/tools/search-command-guard.js +54 -0
- package/dist/core/tools/search-command-guard.js.map +1 -1
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +9 -4
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/tools/shell-session.d.ts.map +1 -1
- package/dist/core/tools/shell-session.js +6 -4
- package/dist/core/tools/shell-session.js.map +1 -1
- package/dist/core/tools/tool-definition-factory.d.ts +32 -0
- package/dist/core/tools/tool-definition-factory.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-factory.js +55 -0
- package/dist/core/tools/tool-definition-factory.js.map +1 -0
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +79 -32
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +24 -18
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.js +1 -1
- package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +1 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +1 -1
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/child-process.js +1 -1
- package/dist/utils/child-process.js.map +1 -1
- 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 +7 -5
|
@@ -134,6 +134,11 @@ export class PrismLlamaCppRuntime {
|
|
|
134
134
|
args.deps?.extractArchive ?? ((input, destDir, kind) => this._extractArchive(input, destDir, kind));
|
|
135
135
|
this._healthPollAttempts = args.deps?.healthPollAttempts ?? DEFAULT_HEALTH_POLL_ATTEMPTS;
|
|
136
136
|
this._healthPollIntervalMs = args.deps?.healthPollIntervalMs ?? DEFAULT_HEALTH_POLL_INTERVAL_MS;
|
|
137
|
+
this._processLifecycle = args.deps?.processLifecycle ?? {
|
|
138
|
+
track: trackDetachedChildPid,
|
|
139
|
+
untrack: untrackDetachedChildPid,
|
|
140
|
+
terminate: killProcessTree,
|
|
141
|
+
};
|
|
137
142
|
}
|
|
138
143
|
runtimeDir() {
|
|
139
144
|
return agentRuntimesDir("prism-llamacpp", this._agentDir);
|
|
@@ -383,7 +388,7 @@ export class PrismLlamaCppRuntime {
|
|
|
383
388
|
env: process.env,
|
|
384
389
|
});
|
|
385
390
|
if (child.pid)
|
|
386
|
-
|
|
391
|
+
this._processLifecycle.track(child.pid);
|
|
387
392
|
child.unref?.();
|
|
388
393
|
child.on("exit", () => {
|
|
389
394
|
if (this._child === child) {
|
|
@@ -410,8 +415,8 @@ export class PrismLlamaCppRuntime {
|
|
|
410
415
|
return { stopped: false };
|
|
411
416
|
this._child = undefined;
|
|
412
417
|
if (child.pid) {
|
|
413
|
-
|
|
414
|
-
|
|
418
|
+
this._processLifecycle.untrack(child.pid);
|
|
419
|
+
this._processLifecycle.terminate(child.pid);
|
|
415
420
|
}
|
|
416
421
|
return { stopped: true };
|
|
417
422
|
}
|
|
@@ -1 +1 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,MAAM,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;YAC7G,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU;gBAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;YAC9D,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBACjC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACZ,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,0BAA0B,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;YAC/E,CAAC;YACD,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC/C,CAAC;QACD,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC/C,CAAC;IAED,IAAI;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,KAAK;YAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;YACf,uBAAuB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnC,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED,SAAS;QACR,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport { type Dirent, mkdirSync, readdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { arch as osArch, platform as osPlatform } from \"node:os\";\nimport { dirname, join, relative } from \"node:path\";\nimport type { Readable } from \"node:stream\";\nimport { pipeline } from \"node:stream/promises\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\nimport { modelsDir as agentModelsDir, runtimesDir as agentRuntimesDir } from \"../agent-paths.ts\";\nimport {\n\tderiveHostLocalInferenceProfile,\n\ttype LocalInferenceProfile,\n\ttype LocalInferenceProfileMode,\n} from \"./local-inference-profile.ts\";\nimport { probePrismLlamaCppServer } from \"./prism-llamacpp-server-probe.ts\";\nimport {\n\textractZipArchive,\n\tfetchRuntimeDownload,\n\tinstallRuntimeArchive,\n\ttype ManagedRuntimeSpawn,\n\tremovePartialDownload,\n\trequireRuntimeStdin,\n\tresolveRuntimeLifecycleDependencies,\n\truntimeCommandAvailable,\n\ttryFileSizeBytes,\n\twriteRuntimeDownload,\n} from \"./runtime-process.ts\";\n\n/**\n * Managed runtime for Pi's curated Prism 1-bit and ternary GGUF models. Q1_0 is available in\n * upstream llama.cpp, while the selected group-128 Q2_0 artifacts and paired DSpark acceleration\n * still require Prism's validated build. This module therefore owns the pinned runtime install,\n * GGUF downloads, and llama-server lifecycle. Mirrors local-runtime.ts's OllamaRuntime: injectable\n * seams for fetch/spawn/exists, pi-owned directories under agentDir (runtimes/, models/),\n * detached+tracked child processes, onProgress as best-effort UI feedback, honest error taxonomies\n * instead of silent fallbacks.\n *\n * The fork publishes precompiled per-platform archives on GitHub Releases (no local build): pin a\n * release tag, download the matching asset, extract it, and locate the `llama-server` binary once\n * at install time (release archive layouts vary — bin/ vs build/bin/ at the top level — so this is\n * a deterministic one-time scan, not a fallback). The found relative path and backend (cpu/cuda)\n * are persisted to a manifest so later `detect()`/`serve()` calls never need to re-scan.\n */\n\n/**\n * Pinned Prism ML llama.cpp fork release — verified via\n * `GET https://api.github.com/repos/PrismML-Eng/llama.cpp/releases/tags/prism-b9594-38c66ad` on\n * 2026-07-18 (release exists, all assets referenced below are present on it). Bump here (and\n * re-verify with the same API call) when the provider ships new kernels.\n */\nexport const PRISM_LLAMACPP_PINNED_RELEASE = \"prism-b9594-38c66ad\";\n\nexport const PRISM_LLAMACPP_RELEASES_BASE_URL = \"https://github.com/PrismML-Eng/llama.cpp/releases/download\";\n\nexport interface PrismModelDescriptor {\n\trepo: string;\n\tfile: string;\n\tmmprojFile?: string;\n\tdisplayName: string;\n\tarchitecture: \"dense\";\n\truntime: \"prism-llamacpp\";\n\tfamily: \"bonsai\" | \"ternary-bonsai\";\n\tparameterScale: \"1.7B\" | \"4B\" | \"8B\" | \"27B\";\n\tweightFormat: \"q1_0\" | \"q2_0\";\n\tmatchedDrafter?: {\n\t\tkind: \"dspark\";\n\t\tfile: string;\n\t\tdraftMax: 4;\n\t\tminimumContext: 16_384;\n\t\tvalidatedBackend: \"cuda\";\n\t};\n}\n\n/** Curated 27B descriptor shared by the full local execution catalog. */\nexport const BONSAI_27B: PrismModelDescriptor = {\n\trepo: \"prism-ml/Bonsai-27B-gguf\",\n\tfile: \"Bonsai-27B-Q1_0.gguf\",\n\tmmprojFile: \"Bonsai-27B-mmproj-Q8_0.gguf\",\n\tdisplayName: \"Bonsai-27B (1-bit Q1_0 + vision)\",\n\tarchitecture: \"dense\",\n\truntime: \"prism-llamacpp\",\n\tfamily: \"bonsai\",\n\tparameterScale: \"27B\",\n\tweightFormat: \"q1_0\",\n\tmatchedDrafter: {\n\t\tkind: \"dspark\",\n\t\tfile: \"Bonsai-27B-dspark-Q4_1.gguf\",\n\t\tdraftMax: 4,\n\t\tminimumContext: 16_384,\n\t\tvalidatedBackend: \"cuda\",\n\t},\n};\n\nexport type PrismBackend = \"cpu\" | \"cuda\";\nexport type PrismAssetKind = \"tar-gz\" | \"zip\";\n\nexport interface PrismArchiveAsset {\n\tname: string;\n\tkind: PrismAssetKind;\n}\n\nexport interface PrismLlamaAsset extends PrismArchiveAsset {\n\tbackend: PrismBackend;\n\tcompanionAssets?: readonly PrismArchiveAsset[];\n}\n\n// Verbatim asset names from the pinned release (see PRISM_LLAMACPP_PINNED_RELEASE doc comment) —\n// hardcoded rather than templated from the tag because the provider's naming isn't fully\n// consistent across platforms (Windows CPU assets drop the tag/commit segment entirely; the\n// Windows CUDA asset uses a different build-number segment, \"b1\" not \"b9594\").\nconst LINUX_X64_CPU_ASSET = \"llama-prism-b9594-38c66ad-bin-ubuntu-x64.tar.gz\";\nconst LINUX_ARM64_CPU_ASSET = \"llama-prism-b9594-38c66ad-bin-ubuntu-arm64.tar.gz\";\nconst LINUX_X64_CUDA_ASSET = \"llama-prism-b9594-38c66ad-bin-linux-cuda-12.4-x64.tar.gz\";\nconst MACOS_ARM64_ASSET = \"llama-prism-b9594-38c66ad-bin-macos-arm64.tar.gz\";\nconst MACOS_X64_ASSET = \"llama-prism-b9594-38c66ad-bin-macos-x64.tar.gz\";\nconst WIN_X64_CPU_ASSET = \"llama-bin-win-cpu-x64.zip\";\nconst WIN_ARM64_CPU_ASSET = \"llama-bin-win-cpu-arm64.zip\";\nconst WIN_X64_CUDA_ASSET = \"llama-prism-b1-38c66ad-bin-win-cuda-12.4-x64.zip\";\nconst WIN_X64_CUDA_COMPANION_ASSET = \"cudart-llama-bin-win-cuda-12.4-x64.zip\";\n\n/**\n * Maps a platform/arch/GPU triple to the exact Prism llama.cpp release asset for\n * {@link PRISM_LLAMACPP_PINNED_RELEASE} — verified against the real GitHub release, not guessed.\n * CPU asset by default; CUDA 12.4 is selected for x64 Linux or Windows with an NVIDIA GPU. The\n * pinned Windows build is incomplete without its matching `cudart-*` archive, so the resolver\n * returns both as one mandatory installation plan. Pure and exported so it's independently\n * testable.\n */\nexport function resolvePrismLlamaAsset(\n\tplat: string,\n\tarchitecture: string,\n\thasNvidiaGpu: boolean,\n): PrismLlamaAsset | undefined {\n\tif (plat === \"linux\") {\n\t\tif (architecture === \"x64\") {\n\t\t\treturn hasNvidiaGpu\n\t\t\t\t? { name: LINUX_X64_CUDA_ASSET, kind: \"tar-gz\", backend: \"cuda\" }\n\t\t\t\t: { name: LINUX_X64_CPU_ASSET, kind: \"tar-gz\", backend: \"cpu\" };\n\t\t}\n\t\tif (architecture === \"arm64\") return { name: LINUX_ARM64_CPU_ASSET, kind: \"tar-gz\", backend: \"cpu\" };\n\t\treturn undefined;\n\t}\n\tif (plat === \"darwin\") {\n\t\tif (architecture === \"arm64\") return { name: MACOS_ARM64_ASSET, kind: \"tar-gz\", backend: \"cpu\" };\n\t\tif (architecture === \"x64\") return { name: MACOS_X64_ASSET, kind: \"tar-gz\", backend: \"cpu\" };\n\t\treturn undefined;\n\t}\n\tif (plat === \"win32\") {\n\t\tif (architecture === \"x64\") {\n\t\t\treturn hasNvidiaGpu\n\t\t\t\t? {\n\t\t\t\t\t\tname: WIN_X64_CUDA_ASSET,\n\t\t\t\t\t\tkind: \"zip\",\n\t\t\t\t\t\tbackend: \"cuda\",\n\t\t\t\t\t\tcompanionAssets: [{ name: WIN_X64_CUDA_COMPANION_ASSET, kind: \"zip\" }],\n\t\t\t\t\t}\n\t\t\t\t: { name: WIN_X64_CPU_ASSET, kind: \"zip\", backend: \"cpu\" };\n\t\t}\n\t\tif (architecture === \"arm64\") return { name: WIN_ARM64_CPU_ASSET, kind: \"zip\", backend: \"cpu\" };\n\t\treturn undefined;\n\t}\n\treturn undefined;\n}\n\nexport interface PrismDetectResult {\n\truntimeInstalled: boolean;\n\tbinaryPath?: string;\n\trelease?: string;\n}\n\nexport interface PrismDownloadResult {\n\tok: boolean;\n\tpath?: string;\n\tskipped?: boolean;\n\terror?: string;\n}\n\nexport type PrismServeResult = { ok: true; baseUrl: string } | { ok: false; error: string };\n\ninterface PrismInstallManifest {\n\trelease: string;\n\tbinaryRelPath: string;\n\tbackend: PrismBackend;\n}\n\ntype PrismExtractArchiveFn = (\n\tinput: Readable,\n\tdestDir: string,\n\tkind: PrismAssetKind,\n) => Promise<{ ok: boolean; error?: string }>;\n\nexport interface PrismLlamaCppDeps {\n\tfetchFn?: typeof fetch;\n\tspawnFn?: ManagedRuntimeSpawn;\n\texistsFn?: (path: string) => boolean;\n\tsleepFn?: (ms: number) => Promise<void>;\n\t/** Whether a named command exists on PATH (nvidia-smi, tar — for zip extraction on Windows). */\n\thasCommand?: (command: string) => boolean;\n\t/** Decided once at install time and persisted as `backend` — serve() reads the persisted value\n\t * so `-ngl 99` reflects what was actually installed, not the host's current GPU state. */\n\thasNvidiaGpu?: () => boolean;\n\tplatform?: () => string;\n\tarch?: () => string;\n\t/** Host capacity probes used once to derive the bounded local inference profile. */\n\ttotalMemoryBytes?: () => number;\n\tlogicalCpuCount?: () => number;\n\t/** Runs the extraction step for a downloaded archive. Injectable so installManaged's\n\t * download->extract->scan orchestration is testable without a real tar/unzip pipeline; defaults\n\t * to the real spawn-based extractor. */\n\textractArchive?: PrismExtractArchiveFn;\n\t/** Health-poll bounds for serve(); default ~120s (240 * 500ms), both overridable for tests. */\n\thealthPollAttempts?: number;\n\thealthPollIntervalMs?: number;\n}\n\nconst EXTRACTION_TIMEOUT_MS = 10 * 60_000;\nconst COMMAND_KILL_GRACE_MS = 2_000;\nconst DEFAULT_HEALTH_POLL_ATTEMPTS = 240;\nconst DEFAULT_HEALTH_POLL_INTERVAL_MS = 500;\nconst HEALTH_CHECK_TIMEOUT_MS = 2_000;\nconst HEAD_REQUEST_TIMEOUT_MS = 10_000;\n\nfunction parseContentLength(header: string | null): number | undefined {\n\tif (!header) return undefined;\n\tconst value = Number(header);\n\treturn Number.isFinite(value) && value >= 0 ? value : undefined;\n}\n\nfunction modelIdentityConflictError(servedModelIds: readonly string[]): string {\n\treturn `model-identity-conflict:${servedModelIds.join(\",\") || \"unknown\"}`;\n}\n\nexport class PrismLlamaCppRuntime {\n\tprivate readonly _agentDir: string;\n\tprivate readonly _fetch: typeof fetch;\n\tprivate readonly _spawn: ManagedRuntimeSpawn;\n\tprivate readonly _exists: (path: string) => boolean;\n\tprivate readonly _sleep: (ms: number) => Promise<void>;\n\tprivate readonly _hasCommand: (command: string) => boolean;\n\tprivate readonly _hasNvidiaGpu: () => boolean;\n\tprivate readonly _platform: () => string;\n\tprivate readonly _arch: () => string;\n\tprivate readonly _extractArchiveFn: PrismExtractArchiveFn;\n\tprivate readonly _healthPollAttempts: number;\n\tprivate readonly _healthPollIntervalMs: number;\n\tprivate readonly _profile: LocalInferenceProfile;\n\tprivate _child: Pick<ChildProcess, \"pid\" | \"kill\" | \"unref\" | \"on\"> | undefined;\n\n\tconstructor(args: {\n\t\tagentDir: string;\n\t\tprofileMode?: LocalInferenceProfileMode;\n\t\tdeps?: PrismLlamaCppDeps;\n\t}) {\n\t\tthis._agentDir = args.agentDir;\n\t\t[this._fetch, this._spawn, this._exists, this._sleep] = resolveRuntimeLifecycleDependencies(args.deps);\n\t\tthis._hasCommand = args.deps?.hasCommand ?? runtimeCommandAvailable;\n\t\tthis._hasNvidiaGpu = args.deps?.hasNvidiaGpu ?? (() => this._hasCommand(\"nvidia-smi\"));\n\t\tthis._platform = args.deps?.platform ?? osPlatform;\n\t\tthis._arch = args.deps?.arch ?? osArch;\n\t\tthis._profile = deriveHostLocalInferenceProfile(args.profileMode ?? \"balanced\", args.deps);\n\t\tthis._extractArchiveFn =\n\t\t\targs.deps?.extractArchive ?? ((input, destDir, kind) => this._extractArchive(input, destDir, kind));\n\t\tthis._healthPollAttempts = args.deps?.healthPollAttempts ?? DEFAULT_HEALTH_POLL_ATTEMPTS;\n\t\tthis._healthPollIntervalMs = args.deps?.healthPollIntervalMs ?? DEFAULT_HEALTH_POLL_INTERVAL_MS;\n\t}\n\n\truntimeDir(): string {\n\t\treturn agentRuntimesDir(\"prism-llamacpp\", this._agentDir);\n\t}\n\n\tmodelsDir(): string {\n\t\treturn agentModelsDir(\"llamacpp\", this._agentDir);\n\t}\n\n\tprivate _binaryName(): string {\n\t\treturn this._platform() === \"win32\" ? \"llama-server.exe\" : \"llama-server\";\n\t}\n\n\tprivate _manifestPath(): string {\n\t\treturn join(this.runtimeDir(), \"install.json\");\n\t}\n\n\tprivate _readManifest(): PrismInstallManifest | undefined {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(readFileSync(this._manifestPath(), \"utf8\")) as {\n\t\t\t\trelease?: unknown;\n\t\t\t\tbinaryRelPath?: unknown;\n\t\t\t\tbackend?: unknown;\n\t\t\t};\n\t\t\tif (\n\t\t\t\ttypeof parsed.release === \"string\" &&\n\t\t\t\ttypeof parsed.binaryRelPath === \"string\" &&\n\t\t\t\t(parsed.backend === \"cpu\" || parsed.backend === \"cuda\")\n\t\t\t) {\n\t\t\t\treturn { release: parsed.release, binaryRelPath: parsed.binaryRelPath, backend: parsed.backend };\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate _writeManifest(manifest: PrismInstallManifest): void {\n\t\twriteFileSync(this._manifestPath(), JSON.stringify(manifest, null, \"\\t\"));\n\t}\n\n\tasync detect(): Promise<PrismDetectResult> {\n\t\tconst manifest = this._readManifest();\n\t\tif (!manifest) return { runtimeInstalled: false };\n\t\tconst binaryPath = join(this.runtimeDir(), manifest.binaryRelPath);\n\t\tconst runtimeInstalled = this._exists(binaryPath);\n\t\treturn {\n\t\t\truntimeInstalled,\n\t\t\tbinaryPath: runtimeInstalled ? binaryPath : undefined,\n\t\t\trelease: manifest.release,\n\t\t};\n\t}\n\n\t/** One-time recursive scan for the `llama-server` binary inside a freshly extracted release\n\t * archive — layouts vary (bin/ vs build/bin/ at the top level) across platforms/backends, so\n\t * this locates it deterministically instead of assuming a fixed path, then the result is\n\t * persisted so later calls never need to re-scan. */\n\tprivate _findBinaryRelPath(root: string): string | undefined {\n\t\tconst targetName = this._binaryName();\n\t\tconst stack: string[] = [root];\n\t\twhile (stack.length > 0) {\n\t\t\tconst dir = stack.pop();\n\t\t\tif (dir === undefined) continue;\n\t\t\tlet entries: Dirent[];\n\t\t\ttry {\n\t\t\t\tentries = readdirSync(dir, { withFileTypes: true });\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const entry of entries) {\n\t\t\t\tconst full = join(dir, entry.name);\n\t\t\t\tif (entry.isDirectory()) stack.push(full);\n\t\t\t\telse if (entry.isFile() && entry.name === targetName) return relative(root, full);\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Download the pinned release asset for this host and extract it (consent-gated by the caller,\n\t * same contract as OllamaRuntime#installManaged — this method only does the mechanical\n\t * download+extract+locate and reports the outcome honestly). No compiler toolchain required:\n\t * the fork ships prebuilt binaries.\n\t */\n\tasync installManaged(onProgress?: (status: string) => void): Promise<{ ok: boolean; error?: string }> {\n\t\tconst asset = resolvePrismLlamaAsset(this._platform(), this._arch(), this._hasNvidiaGpu());\n\t\tif (!asset) return { ok: false, error: \"unsupported-platform\" };\n\n\t\tconst archives: readonly PrismArchiveAsset[] = [asset, ...(asset.companionAssets ?? [])];\n\t\tfor (const archive of archives) {\n\t\t\tconst downloadUrl = `${PRISM_LLAMACPP_RELEASES_BASE_URL}/${PRISM_LLAMACPP_PINNED_RELEASE}/${archive.name}`;\n\t\t\tconst extracted = await this._installArchive(downloadUrl, archive, onProgress);\n\t\t\tif (!extracted.ok) return extracted;\n\t\t}\n\n\t\tonProgress?.(\"Locating llama-server binary…\");\n\t\tconst destDir = this.runtimeDir();\n\t\tconst binaryRelPath = this._findBinaryRelPath(destDir);\n\t\tif (!binaryRelPath) {\n\t\t\treturn { ok: false, error: \"binary-missing: no llama-server binary found in the extracted archive\" };\n\t\t}\n\n\t\tthis._writeManifest({ release: PRISM_LLAMACPP_PINNED_RELEASE, binaryRelPath, backend: asset.backend });\n\t\tonProgress?.(\"Prism llama.cpp runtime installed.\");\n\t\treturn { ok: true };\n\t}\n\n\tprivate _installArchive(\n\t\tdownloadUrl: string,\n\t\tasset: PrismArchiveAsset,\n\t\tonProgress?: (status: string) => void,\n\t): Promise<{ ok: boolean; error?: string }> {\n\t\treturn installRuntimeArchive(\n\t\t\tthis._fetch,\n\t\t\tdownloadUrl,\n\t\t\tthis.runtimeDir(),\n\t\t\tasset,\n\t\t\tthis._extractArchiveFn,\n\t\t\tonProgress,\n\t\t);\n\t}\n\n\tprivate async _extractArchive(\n\t\tinput: Readable,\n\t\tdestDir: string,\n\t\tkind: PrismAssetKind,\n\t): Promise<{ ok: boolean; error?: string }> {\n\t\ttry {\n\t\t\treturn kind === \"zip\" ? await this._extractZip(input, destDir) : await this._extractTarGz(input, destDir);\n\t\t} catch (error) {\n\t\t\treturn { ok: false, error: `extract-fail: ${error instanceof Error ? error.message : String(error)}` };\n\t\t}\n\t}\n\n\tprivate async _extractTarGz(input: Readable, destDir: string): Promise<{ ok: boolean; error?: string }> {\n\t\tconst tarProc = spawnProcess(\"tar\", [\"-xzf\", \"-\", \"-C\", destDir], {\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tstdio: [\"pipe\", \"ignore\", \"ignore\"],\n\t\t});\n\t\tconst terminationController = new AbortController();\n\t\tconst processWait = waitForChildProcessWithTermination(tarProc, {\n\t\t\tsignal: terminationController.signal,\n\t\t\ttimeoutMs: EXTRACTION_TIMEOUT_MS,\n\t\t\tkillGraceMs: COMMAND_KILL_GRACE_MS,\n\t\t});\n\t\ttry {\n\t\t\tawait pipeline(input, requireRuntimeStdin(tarProc, \"tar\"));\n\t\t} catch (error) {\n\t\t\tterminationController.abort();\n\t\t\tawait processWait.catch(() => {});\n\t\t\tthrow error;\n\t\t}\n\t\tconst terminal = await processWait;\n\t\tif (terminal.reason === \"timeout\" || terminal.code !== 0) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror:\n\t\t\t\t\tterminal.reason === \"timeout\"\n\t\t\t\t\t\t? `extract-fail: tar extraction timed out after ${EXTRACTION_TIMEOUT_MS}ms`\n\t\t\t\t\t\t: `extract-fail: tar exited with code ${terminal.code ?? \"unknown\"}`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true };\n\t}\n\n\tprivate async _extractZip(input: Readable, destDir: string): Promise<{ ok: boolean; error?: string }> {\n\t\treturn extractZipArchive({\n\t\t\tinput,\n\t\t\tdestDir,\n\t\t\ttempPrefix: \"prism-llamacpp-download\",\n\t\t\tplatform: this._platform,\n\t\t\thasCommand: this._hasCommand,\n\t\t\ttimeoutMs: EXTRACTION_TIMEOUT_MS,\n\t\t\tkillGraceMs: COMMAND_KILL_GRACE_MS,\n\t\t});\n\t}\n\n\tprivate async _remoteContentLength(url: string): Promise<number | undefined> {\n\t\ttry {\n\t\t\tconst response = await this._fetch(url, {\n\t\t\t\tmethod: \"HEAD\",\n\t\t\t\tsignal: AbortSignal.timeout(HEAD_REQUEST_TIMEOUT_MS),\n\t\t\t});\n\t\t\treturn response.ok ? parseContentLength(response.headers.get(\"content-length\")) : undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Stream a GGUF (or mmproj) file from Hugging Face into pi's owned models dir. Skips a re-download\n\t * when the local file already matches the remote size; verifies size when the response reports\n\t * `content-length` and deletes the partial file on any failure or mismatch — never leaves a\n\t * corrupt/truncated weight file behind for a later load to silently misread.\n\t */\n\tasync downloadModel(\n\t\targs: { repo: string; file: string },\n\t\tonProgress?: (status: string) => void,\n\t): Promise<PrismDownloadResult> {\n\t\tconst destPath = join(this.modelsDir(), args.repo, args.file);\n\t\tconst url = `https://huggingface.co/${args.repo}/resolve/main/${args.file}`;\n\t\tmkdirSync(dirname(destPath), { recursive: true });\n\n\t\tif (this._exists(destPath)) {\n\t\t\tconst remoteSize = await this._remoteContentLength(url);\n\t\t\tif (remoteSize !== undefined && remoteSize === tryFileSizeBytes(destPath)) {\n\t\t\t\tonProgress?.(`${args.file} already downloaded (${remoteSize} bytes) — skipping.`);\n\t\t\t\treturn { ok: true, path: destPath, skipped: true };\n\t\t\t}\n\t\t}\n\n\t\tonProgress?.(`Downloading ${args.file} from ${args.repo}…`);\n\t\tconst download = await fetchRuntimeDownload(this._fetch, url);\n\t\tif (!download.ok) return download;\n\n\t\tconst expectedBytes = parseContentLength(download.response.headers.get(\"content-length\"));\n\t\tconst written = await writeRuntimeDownload(download.body as unknown as Readable, destPath);\n\t\tif (!written.ok) return written;\n\n\t\tconst actualBytes = tryFileSizeBytes(destPath);\n\t\tif (expectedBytes !== undefined && actualBytes !== expectedBytes) {\n\t\t\tremovePartialDownload(destPath);\n\t\t\treturn { ok: false, error: `size-mismatch: expected ${expectedBytes} bytes, got ${actualBytes ?? 0}` };\n\t\t}\n\n\t\tonProgress?.(`${args.file} downloaded (${actualBytes ?? 0} bytes).`);\n\t\treturn { ok: true, path: destPath };\n\t}\n\n\t/**\n\t * Spawn `llama-server` detached+tracked (killed on parent shutdown even if pi crashes without\n\t * calling stop()) and poll `/health` until ready. `-ngl 99` is only added when the installed\n\t * asset's persisted `backend` is `\"cuda\"`, not from the host's current GPU state.\n\t */\n\tasync serve(args: {\n\t\tmodelPath: string;\n\t\tmodelAlias: string;\n\t\tmmprojPath?: string;\n\t\tport: number;\n\t\tnumCtx: number;\n\t}): Promise<PrismServeResult> {\n\t\tconst manifest = this._readManifest();\n\t\tif (!manifest) return { ok: false, error: \"binary-missing\" };\n\t\tconst binaryPath = join(this.runtimeDir(), manifest.binaryRelPath);\n\t\tif (!this._exists(binaryPath)) return { ok: false, error: \"binary-missing\" };\n\n\t\tconst baseUrl = `http://127.0.0.1:${args.port}`;\n\t\tconst existing = await probePrismLlamaCppServer(baseUrl, args.modelAlias, this._fetch, HEALTH_CHECK_TIMEOUT_MS);\n\t\tif (existing.status === \"matching\") return { ok: true, baseUrl };\n\t\tif (existing.status === \"conflict\" && !this._child) {\n\t\t\treturn { ok: false, error: modelIdentityConflictError(existing.servedModelIds) };\n\t\t}\n\t\tif (this._child) this.stop();\n\t\tconst argv = [\n\t\t\t\"-m\",\n\t\t\targs.modelPath,\n\t\t\t\"--alias\",\n\t\t\targs.modelAlias,\n\t\t\t...(args.mmprojPath ? [\"--mmproj\", args.mmprojPath] : []),\n\t\t\t\"--host\",\n\t\t\t\"127.0.0.1\",\n\t\t\t\"--port\",\n\t\t\tString(args.port),\n\t\t\t\"-c\",\n\t\t\tString(args.numCtx),\n\t\t\t\"--cache-ram\",\n\t\t\tString(this._profile.promptCacheMiB),\n\t\t\t\"-np\",\n\t\t\tString(this._profile.parallelRequests),\n\t\t\t\"-fa\",\n\t\t\tthis._profile.flashAttention ? \"on\" : \"off\",\n\t\t\t\"-ctk\",\n\t\t\tthis._profile.kvCacheType,\n\t\t\t\"-ctv\",\n\t\t\tthis._profile.kvCacheType,\n\t\t\t\"-t\",\n\t\t\tString(this._profile.generationThreads),\n\t\t\t\"-tb\",\n\t\t\tString(this._profile.batchThreads),\n\t\t\t...(manifest.backend === \"cuda\" ? [\"-ngl\", \"99\"] : []),\n\t\t];\n\n\t\tconst child = this._spawn(binaryPath, argv, {\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tstdio: \"ignore\",\n\t\t\tenv: process.env,\n\t\t});\n\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\tchild.unref?.();\n\t\tchild.on(\"exit\", () => {\n\t\t\tif (this._child === child) {\n\t\t\t\tthis._child = undefined;\n\t\t\t}\n\t\t});\n\t\tthis._child = child;\n\n\t\tfor (let attempt = 0; attempt < this._healthPollAttempts; attempt++) {\n\t\t\tconst probe = await probePrismLlamaCppServer(baseUrl, args.modelAlias, this._fetch, HEALTH_CHECK_TIMEOUT_MS);\n\t\t\tif (probe.status === \"matching\") return { ok: true, baseUrl };\n\t\t\tif (probe.status === \"conflict\") {\n\t\t\t\tthis.stop();\n\t\t\t\treturn { ok: false, error: modelIdentityConflictError(probe.servedModelIds) };\n\t\t\t}\n\t\t\tawait this._sleep(this._healthPollIntervalMs);\n\t\t}\n\t\tthis.stop();\n\t\treturn { ok: false, error: \"health-timeout\" };\n\t}\n\n\tstop(): { stopped: boolean } {\n\t\tconst child = this._child;\n\t\tif (!child) return { stopped: false };\n\t\tthis._child = undefined;\n\t\tif (child.pid) {\n\t\t\tuntrackDetachedChildPid(child.pid);\n\t\t\tkillProcessTree(child.pid);\n\t\t}\n\t\treturn { stopped: true };\n\t}\n\n\tisRunning(): boolean {\n\t\treturn this._child !== undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"llamacpp-runtime.js","sourceRoot":"","sources":["../../../src/core/models/llamacpp-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC3F,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,QAAQ,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACvG,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,WAAW,IAAI,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjG,OAAO,EACN,+BAA+B,GAG/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EACN,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EAErB,qBAAqB,EACrB,mBAAmB,EACnB,mCAAmC,EACnC,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,qBAAqB,CAAC;AAEnE,MAAM,CAAC,MAAM,gCAAgC,GAAG,4DAA4D,CAAC;AAqB7G,yEAAyE;AACzE,MAAM,CAAC,MAAM,UAAU,GAAyB;IAC/C,IAAI,EAAE,0BA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S,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED,SAAS;QACR,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport { type Dirent, mkdirSync, readdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { arch as osArch, platform as osPlatform } from \"node:os\";\nimport { dirname, join, relative } from \"node:path\";\nimport type { Readable } from \"node:stream\";\nimport { pipeline } from \"node:stream/promises\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport { killProcessTree, trackDetachedChildPid, untrackDetachedChildPid } from \"../../utils/shell.ts\";\nimport { modelsDir as agentModelsDir, runtimesDir as agentRuntimesDir } from \"../agent-paths.ts\";\nimport {\n\tderiveHostLocalInferenceProfile,\n\ttype LocalInferenceProfile,\n\ttype LocalInferenceProfileMode,\n} from \"./local-inference-profile.ts\";\nimport { probePrismLlamaCppServer } from \"./prism-llamacpp-server-probe.ts\";\nimport {\n\textractZipArchive,\n\tfetchRuntimeDownload,\n\tinstallRuntimeArchive,\n\ttype ManagedRuntimeSpawn,\n\tremovePartialDownload,\n\trequireRuntimeStdin,\n\tresolveRuntimeLifecycleDependencies,\n\truntimeCommandAvailable,\n\ttryFileSizeBytes,\n\twriteRuntimeDownload,\n} from \"./runtime-process.ts\";\n\n/**\n * Managed runtime for Pi's curated Prism 1-bit and ternary GGUF models. Q1_0 is available in\n * upstream llama.cpp, while the selected group-128 Q2_0 artifacts and paired DSpark acceleration\n * still require Prism's validated build. This module therefore owns the pinned runtime install,\n * GGUF downloads, and llama-server lifecycle. Mirrors local-runtime.ts's OllamaRuntime: injectable\n * seams for fetch/spawn/exists, pi-owned directories under agentDir (runtimes/, models/),\n * detached+tracked child processes, onProgress as best-effort UI feedback, honest error taxonomies\n * instead of silent fallbacks.\n *\n * The fork publishes precompiled per-platform archives on GitHub Releases (no local build): pin a\n * release tag, download the matching asset, extract it, and locate the `llama-server` binary once\n * at install time (release archive layouts vary — bin/ vs build/bin/ at the top level — so this is\n * a deterministic one-time scan, not a fallback). The found relative path and backend (cpu/cuda)\n * are persisted to a manifest so later `detect()`/`serve()` calls never need to re-scan.\n */\n\n/**\n * Pinned Prism ML llama.cpp fork release — verified via\n * `GET https://api.github.com/repos/PrismML-Eng/llama.cpp/releases/tags/prism-b9594-38c66ad` on\n * 2026-07-18 (release exists, all assets referenced below are present on it). Bump here (and\n * re-verify with the same API call) when the provider ships new kernels.\n */\nexport const PRISM_LLAMACPP_PINNED_RELEASE = \"prism-b9594-38c66ad\";\n\nexport const PRISM_LLAMACPP_RELEASES_BASE_URL = \"https://github.com/PrismML-Eng/llama.cpp/releases/download\";\n\nexport interface PrismModelDescriptor {\n\trepo: string;\n\tfile: string;\n\tmmprojFile?: string;\n\tdisplayName: string;\n\tarchitecture: \"dense\";\n\truntime: \"prism-llamacpp\";\n\tfamily: \"bonsai\" | \"ternary-bonsai\";\n\tparameterScale: \"1.7B\" | \"4B\" | \"8B\" | \"27B\";\n\tweightFormat: \"q1_0\" | \"q2_0\";\n\tmatchedDrafter?: {\n\t\tkind: \"dspark\";\n\t\tfile: string;\n\t\tdraftMax: 4;\n\t\tminimumContext: 16_384;\n\t\tvalidatedBackend: \"cuda\";\n\t};\n}\n\n/** Curated 27B descriptor shared by the full local execution catalog. */\nexport const BONSAI_27B: PrismModelDescriptor = {\n\trepo: \"prism-ml/Bonsai-27B-gguf\",\n\tfile: \"Bonsai-27B-Q1_0.gguf\",\n\tmmprojFile: \"Bonsai-27B-mmproj-Q8_0.gguf\",\n\tdisplayName: \"Bonsai-27B (1-bit Q1_0 + vision)\",\n\tarchitecture: \"dense\",\n\truntime: \"prism-llamacpp\",\n\tfamily: \"bonsai\",\n\tparameterScale: \"27B\",\n\tweightFormat: \"q1_0\",\n\tmatchedDrafter: {\n\t\tkind: \"dspark\",\n\t\tfile: \"Bonsai-27B-dspark-Q4_1.gguf\",\n\t\tdraftMax: 4,\n\t\tminimumContext: 16_384,\n\t\tvalidatedBackend: \"cuda\",\n\t},\n};\n\nexport type PrismBackend = \"cpu\" | \"cuda\";\nexport type PrismAssetKind = \"tar-gz\" | \"zip\";\n\nexport interface PrismArchiveAsset {\n\tname: string;\n\tkind: PrismAssetKind;\n}\n\nexport interface PrismLlamaAsset extends PrismArchiveAsset {\n\tbackend: PrismBackend;\n\tcompanionAssets?: readonly PrismArchiveAsset[];\n}\n\n// Verbatim asset names from the pinned release (see PRISM_LLAMACPP_PINNED_RELEASE doc comment) —\n// hardcoded rather than templated from the tag because the provider's naming isn't fully\n// consistent across platforms (Windows CPU assets drop the tag/commit segment entirely; the\n// Windows CUDA asset uses a different build-number segment, \"b1\" not \"b9594\").\nconst LINUX_X64_CPU_ASSET = \"llama-prism-b9594-38c66ad-bin-ubuntu-x64.tar.gz\";\nconst LINUX_ARM64_CPU_ASSET = \"llama-prism-b9594-38c66ad-bin-ubuntu-arm64.tar.gz\";\nconst LINUX_X64_CUDA_ASSET = \"llama-prism-b9594-38c66ad-bin-linux-cuda-12.4-x64.tar.gz\";\nconst MACOS_ARM64_ASSET = \"llama-prism-b9594-38c66ad-bin-macos-arm64.tar.gz\";\nconst MACOS_X64_ASSET = \"llama-prism-b9594-38c66ad-bin-macos-x64.tar.gz\";\nconst WIN_X64_CPU_ASSET = \"llama-bin-win-cpu-x64.zip\";\nconst WIN_ARM64_CPU_ASSET = \"llama-bin-win-cpu-arm64.zip\";\nconst WIN_X64_CUDA_ASSET = \"llama-prism-b1-38c66ad-bin-win-cuda-12.4-x64.zip\";\nconst WIN_X64_CUDA_COMPANION_ASSET = \"cudart-llama-bin-win-cuda-12.4-x64.zip\";\n\n/**\n * Maps a platform/arch/GPU triple to the exact Prism llama.cpp release asset for\n * {@link PRISM_LLAMACPP_PINNED_RELEASE} — verified against the real GitHub release, not guessed.\n * CPU asset by default; CUDA 12.4 is selected for x64 Linux or Windows with an NVIDIA GPU. The\n * pinned Windows build is incomplete without its matching `cudart-*` archive, so the resolver\n * returns both as one mandatory installation plan. Pure and exported so it's independently\n * testable.\n */\nexport function resolvePrismLlamaAsset(\n\tplat: string,\n\tarchitecture: string,\n\thasNvidiaGpu: boolean,\n): PrismLlamaAsset | undefined {\n\tif (plat === \"linux\") {\n\t\tif (architecture === \"x64\") {\n\t\t\treturn hasNvidiaGpu\n\t\t\t\t? { name: LINUX_X64_CUDA_ASSET, kind: \"tar-gz\", backend: \"cuda\" }\n\t\t\t\t: { name: LINUX_X64_CPU_ASSET, kind: \"tar-gz\", backend: \"cpu\" };\n\t\t}\n\t\tif (architecture === \"arm64\") return { name: LINUX_ARM64_CPU_ASSET, kind: \"tar-gz\", backend: \"cpu\" };\n\t\treturn undefined;\n\t}\n\tif (plat === \"darwin\") {\n\t\tif (architecture === \"arm64\") return { name: MACOS_ARM64_ASSET, kind: \"tar-gz\", backend: \"cpu\" };\n\t\tif (architecture === \"x64\") return { name: MACOS_X64_ASSET, kind: \"tar-gz\", backend: \"cpu\" };\n\t\treturn undefined;\n\t}\n\tif (plat === \"win32\") {\n\t\tif (architecture === \"x64\") {\n\t\t\treturn hasNvidiaGpu\n\t\t\t\t? {\n\t\t\t\t\t\tname: WIN_X64_CUDA_ASSET,\n\t\t\t\t\t\tkind: \"zip\",\n\t\t\t\t\t\tbackend: \"cuda\",\n\t\t\t\t\t\tcompanionAssets: [{ name: WIN_X64_CUDA_COMPANION_ASSET, kind: \"zip\" }],\n\t\t\t\t\t}\n\t\t\t\t: { name: WIN_X64_CPU_ASSET, kind: \"zip\", backend: \"cpu\" };\n\t\t}\n\t\tif (architecture === \"arm64\") return { name: WIN_ARM64_CPU_ASSET, kind: \"zip\", backend: \"cpu\" };\n\t\treturn undefined;\n\t}\n\treturn undefined;\n}\n\nexport interface PrismDetectResult {\n\truntimeInstalled: boolean;\n\tbinaryPath?: string;\n\trelease?: string;\n}\n\nexport interface PrismDownloadResult {\n\tok: boolean;\n\tpath?: string;\n\tskipped?: boolean;\n\terror?: string;\n}\n\nexport type PrismServeResult = { ok: true; baseUrl: string } | { ok: false; error: string };\n\nexport interface PrismProcessLifecycle {\n\ttrack(pid: number): void;\n\tuntrack(pid: number): void;\n\tterminate(pid: number): void;\n}\n\ninterface PrismInstallManifest {\n\trelease: string;\n\tbinaryRelPath: string;\n\tbackend: PrismBackend;\n}\n\ntype PrismExtractArchiveFn = (\n\tinput: Readable,\n\tdestDir: string,\n\tkind: PrismAssetKind,\n) => Promise<{ ok: boolean; error?: string }>;\n\nexport interface PrismLlamaCppDeps {\n\tfetchFn?: typeof fetch;\n\tspawnFn?: ManagedRuntimeSpawn;\n\texistsFn?: (path: string) => boolean;\n\tsleepFn?: (ms: number) => Promise<void>;\n\t/** Whether a named command exists on PATH (nvidia-smi, tar — for zip extraction on Windows). */\n\thasCommand?: (command: string) => boolean;\n\t/** Decided once at install time and persisted as `backend` — serve() reads the persisted value\n\t * so `-ngl 99` reflects what was actually installed, not the host's current GPU state. */\n\thasNvidiaGpu?: () => boolean;\n\tplatform?: () => string;\n\tarch?: () => string;\n\t/** Host capacity probes used once to derive the bounded local inference profile. */\n\ttotalMemoryBytes?: () => number;\n\tlogicalCpuCount?: () => number;\n\t/** Runs the extraction step for a downloaded archive. Injectable so installManaged's\n\t * download->extract->scan orchestration is testable without a real tar/unzip pipeline; defaults\n\t * to the real spawn-based extractor. */\n\textractArchive?: PrismExtractArchiveFn;\n\t/** Health-poll bounds for serve(); default ~120s (240 * 500ms), both overridable for tests. */\n\thealthPollAttempts?: number;\n\thealthPollIntervalMs?: number;\n\tprocessLifecycle?: PrismProcessLifecycle;\n}\n\nconst EXTRACTION_TIMEOUT_MS = 10 * 60_000;\nconst COMMAND_KILL_GRACE_MS = 2_000;\nconst DEFAULT_HEALTH_POLL_ATTEMPTS = 240;\nconst DEFAULT_HEALTH_POLL_INTERVAL_MS = 500;\nconst HEALTH_CHECK_TIMEOUT_MS = 2_000;\nconst HEAD_REQUEST_TIMEOUT_MS = 10_000;\n\nfunction parseContentLength(header: string | null): number | undefined {\n\tif (!header) return undefined;\n\tconst value = Number(header);\n\treturn Number.isFinite(value) && value >= 0 ? value : undefined;\n}\n\nfunction modelIdentityConflictError(servedModelIds: readonly string[]): string {\n\treturn `model-identity-conflict:${servedModelIds.join(\",\") || \"unknown\"}`;\n}\n\nexport class PrismLlamaCppRuntime {\n\tprivate readonly _agentDir: string;\n\tprivate readonly _fetch: typeof fetch;\n\tprivate readonly _spawn: ManagedRuntimeSpawn;\n\tprivate readonly _exists: (path: string) => boolean;\n\tprivate readonly _sleep: (ms: number) => Promise<void>;\n\tprivate readonly _hasCommand: (command: string) => boolean;\n\tprivate readonly _hasNvidiaGpu: () => boolean;\n\tprivate readonly _platform: () => string;\n\tprivate readonly _arch: () => string;\n\tprivate readonly _extractArchiveFn: PrismExtractArchiveFn;\n\tprivate readonly _healthPollAttempts: number;\n\tprivate readonly _healthPollIntervalMs: number;\n\tprivate readonly _profile: LocalInferenceProfile;\n\tprivate readonly _processLifecycle: PrismProcessLifecycle;\n\tprivate _child: Pick<ChildProcess, \"pid\" | \"kill\" | \"unref\" | \"on\"> | undefined;\n\n\tconstructor(args: {\n\t\tagentDir: string;\n\t\tprofileMode?: LocalInferenceProfileMode;\n\t\tdeps?: PrismLlamaCppDeps;\n\t}) {\n\t\tthis._agentDir = args.agentDir;\n\t\t[this._fetch, this._spawn, this._exists, this._sleep] = resolveRuntimeLifecycleDependencies(args.deps);\n\t\tthis._hasCommand = args.deps?.hasCommand ?? runtimeCommandAvailable;\n\t\tthis._hasNvidiaGpu = args.deps?.hasNvidiaGpu ?? (() => this._hasCommand(\"nvidia-smi\"));\n\t\tthis._platform = args.deps?.platform ?? osPlatform;\n\t\tthis._arch = args.deps?.arch ?? osArch;\n\t\tthis._profile = deriveHostLocalInferenceProfile(args.profileMode ?? \"balanced\", args.deps);\n\t\tthis._extractArchiveFn =\n\t\t\targs.deps?.extractArchive ?? ((input, destDir, kind) => this._extractArchive(input, destDir, kind));\n\t\tthis._healthPollAttempts = args.deps?.healthPollAttempts ?? DEFAULT_HEALTH_POLL_ATTEMPTS;\n\t\tthis._healthPollIntervalMs = args.deps?.healthPollIntervalMs ?? DEFAULT_HEALTH_POLL_INTERVAL_MS;\n\t\tthis._processLifecycle = args.deps?.processLifecycle ?? {\n\t\t\ttrack: trackDetachedChildPid,\n\t\t\tuntrack: untrackDetachedChildPid,\n\t\t\tterminate: killProcessTree,\n\t\t};\n\t}\n\n\truntimeDir(): string {\n\t\treturn agentRuntimesDir(\"prism-llamacpp\", this._agentDir);\n\t}\n\n\tmodelsDir(): string {\n\t\treturn agentModelsDir(\"llamacpp\", this._agentDir);\n\t}\n\n\tprivate _binaryName(): string {\n\t\treturn this._platform() === \"win32\" ? \"llama-server.exe\" : \"llama-server\";\n\t}\n\n\tprivate _manifestPath(): string {\n\t\treturn join(this.runtimeDir(), \"install.json\");\n\t}\n\n\tprivate _readManifest(): PrismInstallManifest | undefined {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(readFileSync(this._manifestPath(), \"utf8\")) as {\n\t\t\t\trelease?: unknown;\n\t\t\t\tbinaryRelPath?: unknown;\n\t\t\t\tbackend?: unknown;\n\t\t\t};\n\t\t\tif (\n\t\t\t\ttypeof parsed.release === \"string\" &&\n\t\t\t\ttypeof parsed.binaryRelPath === \"string\" &&\n\t\t\t\t(parsed.backend === \"cpu\" || parsed.backend === \"cuda\")\n\t\t\t) {\n\t\t\t\treturn { release: parsed.release, binaryRelPath: parsed.binaryRelPath, backend: parsed.backend };\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\tprivate _writeManifest(manifest: PrismInstallManifest): void {\n\t\twriteFileSync(this._manifestPath(), JSON.stringify(manifest, null, \"\\t\"));\n\t}\n\n\tasync detect(): Promise<PrismDetectResult> {\n\t\tconst manifest = this._readManifest();\n\t\tif (!manifest) return { runtimeInstalled: false };\n\t\tconst binaryPath = join(this.runtimeDir(), manifest.binaryRelPath);\n\t\tconst runtimeInstalled = this._exists(binaryPath);\n\t\treturn {\n\t\t\truntimeInstalled,\n\t\t\tbinaryPath: runtimeInstalled ? binaryPath : undefined,\n\t\t\trelease: manifest.release,\n\t\t};\n\t}\n\n\t/** One-time recursive scan for the `llama-server` binary inside a freshly extracted release\n\t * archive — layouts vary (bin/ vs build/bin/ at the top level) across platforms/backends, so\n\t * this locates it deterministically instead of assuming a fixed path, then the result is\n\t * persisted so later calls never need to re-scan. */\n\tprivate _findBinaryRelPath(root: string): string | undefined {\n\t\tconst targetName = this._binaryName();\n\t\tconst stack: string[] = [root];\n\t\twhile (stack.length > 0) {\n\t\t\tconst dir = stack.pop();\n\t\t\tif (dir === undefined) continue;\n\t\t\tlet entries: Dirent[];\n\t\t\ttry {\n\t\t\t\tentries = readdirSync(dir, { withFileTypes: true });\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const entry of entries) {\n\t\t\t\tconst full = join(dir, entry.name);\n\t\t\t\tif (entry.isDirectory()) stack.push(full);\n\t\t\t\telse if (entry.isFile() && entry.name === targetName) return relative(root, full);\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Download the pinned release asset for this host and extract it (consent-gated by the caller,\n\t * same contract as OllamaRuntime#installManaged — this method only does the mechanical\n\t * download+extract+locate and reports the outcome honestly). No compiler toolchain required:\n\t * the fork ships prebuilt binaries.\n\t */\n\tasync installManaged(onProgress?: (status: string) => void): Promise<{ ok: boolean; error?: string }> {\n\t\tconst asset = resolvePrismLlamaAsset(this._platform(), this._arch(), this._hasNvidiaGpu());\n\t\tif (!asset) return { ok: false, error: \"unsupported-platform\" };\n\n\t\tconst archives: readonly PrismArchiveAsset[] = [asset, ...(asset.companionAssets ?? [])];\n\t\tfor (const archive of archives) {\n\t\t\tconst downloadUrl = `${PRISM_LLAMACPP_RELEASES_BASE_URL}/${PRISM_LLAMACPP_PINNED_RELEASE}/${archive.name}`;\n\t\t\tconst extracted = await this._installArchive(downloadUrl, archive, onProgress);\n\t\t\tif (!extracted.ok) return extracted;\n\t\t}\n\n\t\tonProgress?.(\"Locating llama-server binary…\");\n\t\tconst destDir = this.runtimeDir();\n\t\tconst binaryRelPath = this._findBinaryRelPath(destDir);\n\t\tif (!binaryRelPath) {\n\t\t\treturn { ok: false, error: \"binary-missing: no llama-server binary found in the extracted archive\" };\n\t\t}\n\n\t\tthis._writeManifest({ release: PRISM_LLAMACPP_PINNED_RELEASE, binaryRelPath, backend: asset.backend });\n\t\tonProgress?.(\"Prism llama.cpp runtime installed.\");\n\t\treturn { ok: true };\n\t}\n\n\tprivate _installArchive(\n\t\tdownloadUrl: string,\n\t\tasset: PrismArchiveAsset,\n\t\tonProgress?: (status: string) => void,\n\t): Promise<{ ok: boolean; error?: string }> {\n\t\treturn installRuntimeArchive(\n\t\t\tthis._fetch,\n\t\t\tdownloadUrl,\n\t\t\tthis.runtimeDir(),\n\t\t\tasset,\n\t\t\tthis._extractArchiveFn,\n\t\t\tonProgress,\n\t\t);\n\t}\n\n\tprivate async _extractArchive(\n\t\tinput: Readable,\n\t\tdestDir: string,\n\t\tkind: PrismAssetKind,\n\t): Promise<{ ok: boolean; error?: string }> {\n\t\ttry {\n\t\t\treturn kind === \"zip\" ? await this._extractZip(input, destDir) : await this._extractTarGz(input, destDir);\n\t\t} catch (error) {\n\t\t\treturn { ok: false, error: `extract-fail: ${error instanceof Error ? error.message : String(error)}` };\n\t\t}\n\t}\n\n\tprivate async _extractTarGz(input: Readable, destDir: string): Promise<{ ok: boolean; error?: string }> {\n\t\tconst tarProc = spawnProcess(\"tar\", [\"-xzf\", \"-\", \"-C\", destDir], {\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tstdio: [\"pipe\", \"ignore\", \"ignore\"],\n\t\t});\n\t\tconst terminationController = new AbortController();\n\t\tconst processWait = waitForChildProcessWithTermination(tarProc, {\n\t\t\tsignal: terminationController.signal,\n\t\t\ttimeoutMs: EXTRACTION_TIMEOUT_MS,\n\t\t\tkillGraceMs: COMMAND_KILL_GRACE_MS,\n\t\t});\n\t\ttry {\n\t\t\tawait pipeline(input, requireRuntimeStdin(tarProc, \"tar\"));\n\t\t} catch (error) {\n\t\t\tterminationController.abort();\n\t\t\tawait processWait.catch(() => {});\n\t\t\tthrow error;\n\t\t}\n\t\tconst terminal = await processWait;\n\t\tif (terminal.reason === \"timeout\" || terminal.code !== 0) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terror:\n\t\t\t\t\tterminal.reason === \"timeout\"\n\t\t\t\t\t\t? `extract-fail: tar extraction timed out after ${EXTRACTION_TIMEOUT_MS}ms`\n\t\t\t\t\t\t: `extract-fail: tar exited with code ${terminal.code ?? \"unknown\"}`,\n\t\t\t};\n\t\t}\n\t\treturn { ok: true };\n\t}\n\n\tprivate async _extractZip(input: Readable, destDir: string): Promise<{ ok: boolean; error?: string }> {\n\t\treturn extractZipArchive({\n\t\t\tinput,\n\t\t\tdestDir,\n\t\t\ttempPrefix: \"prism-llamacpp-download\",\n\t\t\tplatform: this._platform,\n\t\t\thasCommand: this._hasCommand,\n\t\t\ttimeoutMs: EXTRACTION_TIMEOUT_MS,\n\t\t\tkillGraceMs: COMMAND_KILL_GRACE_MS,\n\t\t});\n\t}\n\n\tprivate async _remoteContentLength(url: string): Promise<number | undefined> {\n\t\ttry {\n\t\t\tconst response = await this._fetch(url, {\n\t\t\t\tmethod: \"HEAD\",\n\t\t\t\tsignal: AbortSignal.timeout(HEAD_REQUEST_TIMEOUT_MS),\n\t\t\t});\n\t\t\treturn response.ok ? parseContentLength(response.headers.get(\"content-length\")) : undefined;\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Stream a GGUF (or mmproj) file from Hugging Face into pi's owned models dir. Skips a re-download\n\t * when the local file already matches the remote size; verifies size when the response reports\n\t * `content-length` and deletes the partial file on any failure or mismatch — never leaves a\n\t * corrupt/truncated weight file behind for a later load to silently misread.\n\t */\n\tasync downloadModel(\n\t\targs: { repo: string; file: string },\n\t\tonProgress?: (status: string) => void,\n\t): Promise<PrismDownloadResult> {\n\t\tconst destPath = join(this.modelsDir(), args.repo, args.file);\n\t\tconst url = `https://huggingface.co/${args.repo}/resolve/main/${args.file}`;\n\t\tmkdirSync(dirname(destPath), { recursive: true });\n\n\t\tif (this._exists(destPath)) {\n\t\t\tconst remoteSize = await this._remoteContentLength(url);\n\t\t\tif (remoteSize !== undefined && remoteSize === tryFileSizeBytes(destPath)) {\n\t\t\t\tonProgress?.(`${args.file} already downloaded (${remoteSize} bytes) — skipping.`);\n\t\t\t\treturn { ok: true, path: destPath, skipped: true };\n\t\t\t}\n\t\t}\n\n\t\tonProgress?.(`Downloading ${args.file} from ${args.repo}…`);\n\t\tconst download = await fetchRuntimeDownload(this._fetch, url);\n\t\tif (!download.ok) return download;\n\n\t\tconst expectedBytes = parseContentLength(download.response.headers.get(\"content-length\"));\n\t\tconst written = await writeRuntimeDownload(download.body as unknown as Readable, destPath);\n\t\tif (!written.ok) return written;\n\n\t\tconst actualBytes = tryFileSizeBytes(destPath);\n\t\tif (expectedBytes !== undefined && actualBytes !== expectedBytes) {\n\t\t\tremovePartialDownload(destPath);\n\t\t\treturn { ok: false, error: `size-mismatch: expected ${expectedBytes} bytes, got ${actualBytes ?? 0}` };\n\t\t}\n\n\t\tonProgress?.(`${args.file} downloaded (${actualBytes ?? 0} bytes).`);\n\t\treturn { ok: true, path: destPath };\n\t}\n\n\t/**\n\t * Spawn `llama-server` detached+tracked (killed on parent shutdown even if pi crashes without\n\t * calling stop()) and poll `/health` until ready. `-ngl 99` is only added when the installed\n\t * asset's persisted `backend` is `\"cuda\"`, not from the host's current GPU state.\n\t */\n\tasync serve(args: {\n\t\tmodelPath: string;\n\t\tmodelAlias: string;\n\t\tmmprojPath?: string;\n\t\tport: number;\n\t\tnumCtx: number;\n\t}): Promise<PrismServeResult> {\n\t\tconst manifest = this._readManifest();\n\t\tif (!manifest) return { ok: false, error: \"binary-missing\" };\n\t\tconst binaryPath = join(this.runtimeDir(), manifest.binaryRelPath);\n\t\tif (!this._exists(binaryPath)) return { ok: false, error: \"binary-missing\" };\n\n\t\tconst baseUrl = `http://127.0.0.1:${args.port}`;\n\t\tconst existing = await probePrismLlamaCppServer(baseUrl, args.modelAlias, this._fetch, HEALTH_CHECK_TIMEOUT_MS);\n\t\tif (existing.status === \"matching\") return { ok: true, baseUrl };\n\t\tif (existing.status === \"conflict\" && !this._child) {\n\t\t\treturn { ok: false, error: modelIdentityConflictError(existing.servedModelIds) };\n\t\t}\n\t\tif (this._child) this.stop();\n\t\tconst argv = [\n\t\t\t\"-m\",\n\t\t\targs.modelPath,\n\t\t\t\"--alias\",\n\t\t\targs.modelAlias,\n\t\t\t...(args.mmprojPath ? [\"--mmproj\", args.mmprojPath] : []),\n\t\t\t\"--host\",\n\t\t\t\"127.0.0.1\",\n\t\t\t\"--port\",\n\t\t\tString(args.port),\n\t\t\t\"-c\",\n\t\t\tString(args.numCtx),\n\t\t\t\"--cache-ram\",\n\t\t\tString(this._profile.promptCacheMiB),\n\t\t\t\"-np\",\n\t\t\tString(this._profile.parallelRequests),\n\t\t\t\"-fa\",\n\t\t\tthis._profile.flashAttention ? \"on\" : \"off\",\n\t\t\t\"-ctk\",\n\t\t\tthis._profile.kvCacheType,\n\t\t\t\"-ctv\",\n\t\t\tthis._profile.kvCacheType,\n\t\t\t\"-t\",\n\t\t\tString(this._profile.generationThreads),\n\t\t\t\"-tb\",\n\t\t\tString(this._profile.batchThreads),\n\t\t\t...(manifest.backend === \"cuda\" ? [\"-ngl\", \"99\"] : []),\n\t\t];\n\n\t\tconst child = this._spawn(binaryPath, argv, {\n\t\t\tdetached: process.platform !== \"win32\",\n\t\t\tstdio: \"ignore\",\n\t\t\tenv: process.env,\n\t\t});\n\t\tif (child.pid) this._processLifecycle.track(child.pid);\n\t\tchild.unref?.();\n\t\tchild.on(\"exit\", () => {\n\t\t\tif (this._child === child) {\n\t\t\t\tthis._child = undefined;\n\t\t\t}\n\t\t});\n\t\tthis._child = child;\n\n\t\tfor (let attempt = 0; attempt < this._healthPollAttempts; attempt++) {\n\t\t\tconst probe = await probePrismLlamaCppServer(baseUrl, args.modelAlias, this._fetch, HEALTH_CHECK_TIMEOUT_MS);\n\t\t\tif (probe.status === \"matching\") return { ok: true, baseUrl };\n\t\t\tif (probe.status === \"conflict\") {\n\t\t\t\tthis.stop();\n\t\t\t\treturn { ok: false, error: modelIdentityConflictError(probe.servedModelIds) };\n\t\t\t}\n\t\t\tawait this._sleep(this._healthPollIntervalMs);\n\t\t}\n\t\tthis.stop();\n\t\treturn { ok: false, error: \"health-timeout\" };\n\t}\n\n\tstop(): { stopped: boolean } {\n\t\tconst child = this._child;\n\t\tif (!child) return { stopped: false };\n\t\tthis._child = undefined;\n\t\tif (child.pid) {\n\t\t\tthis._processLifecycle.untrack(child.pid);\n\t\t\tthis._processLifecycle.terminate(child.pid);\n\t\t}\n\t\treturn { stopped: true };\n\t}\n\n\tisRunning(): boolean {\n\t\treturn this._child !== undefined;\n\t}\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import { homedir, arch as osArch, platform as osPlatform } from "node:os";
|
|
|
3
3
|
import { delimiter, dirname, join, relative } from "node:path";
|
|
4
4
|
import { pipeline } from "node:stream/promises";
|
|
5
5
|
import * as nodeZlib from "node:zlib";
|
|
6
|
-
import { StreamingLineDecoder } from "@caupulican/pi-ai";
|
|
6
|
+
import { StreamingLineDecoder } from "@caupulican/pi-ai/streaming-lines";
|
|
7
7
|
import { getBundledResourcesDir } from "../../config.js";
|
|
8
8
|
import { spawnProcess, waitForChildProcessWithTermination, } from "../../utils/child-process.js";
|
|
9
9
|
import { modelsDir as agentModelsDir, runtimesDir as agentRuntimesDir } from "../agent-paths.js";
|