@cortexkit/pi-magic-context 0.40.0 → 0.40.1
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.
|
@@ -14085,8 +14085,6 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
14085
14085
|
updated_at INTEGER NOT NULL,
|
|
14086
14086
|
harness TEXT NOT NULL DEFAULT 'opencode'
|
|
14087
14087
|
);
|
|
14088
|
-
CREATE INDEX IF NOT EXISTS idx_message_history_index_orphan_sweep
|
|
14089
|
-
ON message_history_index(harness, session_id, updated_at);
|
|
14090
14088
|
|
|
14091
14089
|
CREATE TABLE IF NOT EXISTS message_history_source (
|
|
14092
14090
|
session_id TEXT NOT NULL,
|
|
@@ -14673,6 +14671,10 @@ CREATE INDEX IF NOT EXISTS idx_dream_queue_pending ON dream_queue(started_at, en
|
|
|
14673
14671
|
ensureColumn(db, "recomp_compartments", "harness", "TEXT NOT NULL DEFAULT 'opencode'");
|
|
14674
14672
|
ensureColumn(db, "recomp_facts", "harness", "TEXT NOT NULL DEFAULT 'opencode'");
|
|
14675
14673
|
ensureColumn(db, "message_history_index", "harness", "TEXT NOT NULL DEFAULT 'opencode'");
|
|
14674
|
+
db.exec(`
|
|
14675
|
+
CREATE INDEX IF NOT EXISTS idx_message_history_index_orphan_sweep
|
|
14676
|
+
ON message_history_index(harness, session_id, updated_at);
|
|
14677
|
+
`);
|
|
14676
14678
|
ensureColumn(db, "workspaces", "share_categories", `TEXT NOT NULL DEFAULT '["CONSTRAINTS"]'`);
|
|
14677
14679
|
}
|
|
14678
14680
|
var CHANNEL2_CLAIM_TTL_MS = 10 * 60000;
|
|
@@ -42708,33 +42710,123 @@ function startLockHeartbeat(lockPath) {
|
|
|
42708
42710
|
timer.unref?.();
|
|
42709
42711
|
return () => clearInterval(timer);
|
|
42710
42712
|
}
|
|
42711
|
-
|
|
42712
|
-
|
|
42713
|
+
var localEmbeddingRuntimeMode = "native";
|
|
42714
|
+
var wasmRuntimeInjected = false;
|
|
42715
|
+
var isElectronForRuntime = () => typeof process !== "undefined" && Boolean(process.versions?.electron);
|
|
42716
|
+
var importWasmOrtForRuntime = async () => {
|
|
42717
|
+
const ortWebSpec = `onnxruntime-${"web"}`;
|
|
42718
|
+
return await import(ortWebSpec);
|
|
42719
|
+
};
|
|
42720
|
+
var importTransformersForRuntime = async () => {
|
|
42721
|
+
const transformersSpec = "@huggingface/transformers";
|
|
42722
|
+
return await import(transformersSpec);
|
|
42723
|
+
};
|
|
42724
|
+
var importTransformersWasmFallbackForRuntime = async () => {
|
|
42725
|
+
const { createRequire: createRequireFn } = await import("node:module");
|
|
42726
|
+
const requireFn = createRequireFn(import.meta.url);
|
|
42727
|
+
const nodeEntry = requireFn.resolve("@huggingface/transformers");
|
|
42728
|
+
const webEntry = pathToFileURL2(join9(dirname7(nodeEntry), "transformers.web.js")).href;
|
|
42729
|
+
return await import(webEntry);
|
|
42730
|
+
};
|
|
42731
|
+
var modelCacheDirForRuntime = () => join9(getMagicContextStorageDir(), "models");
|
|
42732
|
+
var logForRuntime = log;
|
|
42733
|
+
var injectWasmOrtForRuntime = injectWasmOrt;
|
|
42734
|
+
async function ensureWasmOrtInjected() {
|
|
42735
|
+
if (wasmRuntimeInjected)
|
|
42736
|
+
return true;
|
|
42737
|
+
if (!await injectWasmOrtForRuntime())
|
|
42713
42738
|
return false;
|
|
42714
|
-
|
|
42739
|
+
wasmRuntimeInjected = true;
|
|
42740
|
+
return true;
|
|
42741
|
+
}
|
|
42742
|
+
async function injectWasmOrt() {
|
|
42743
|
+
if (wasmRuntimeInjected)
|
|
42744
|
+
return true;
|
|
42715
42745
|
try {
|
|
42716
|
-
const
|
|
42717
|
-
const ortWeb = await import(ortWebSpec);
|
|
42746
|
+
const ortWeb = await importWasmOrtForRuntime();
|
|
42718
42747
|
try {
|
|
42719
42748
|
const { createRequire: createRequireFn } = await import("node:module");
|
|
42720
42749
|
const requireFn = createRequireFn(import.meta.url);
|
|
42721
42750
|
const mainEntry = requireFn.resolve("onnxruntime-web");
|
|
42722
42751
|
const distDir = dirname7(mainEntry);
|
|
42723
|
-
const wasmPathsPrefix = `${pathToFileURL2(distDir).href}/`;
|
|
42724
42752
|
if (ortWeb.env?.wasm) {
|
|
42725
|
-
ortWeb.env.wasm.wasmPaths =
|
|
42753
|
+
ortWeb.env.wasm.wasmPaths = `${pathToFileURL2(distDir).href}/`;
|
|
42726
42754
|
}
|
|
42727
42755
|
} catch (pathError) {
|
|
42728
42756
|
log("[magic-context] could not resolve local onnxruntime-web/dist, falling back to default WASM paths:", pathError instanceof Error ? pathError.message : String(pathError));
|
|
42729
42757
|
}
|
|
42730
42758
|
globalThis[Symbol.for("onnxruntime")] = ortWeb;
|
|
42731
|
-
|
|
42759
|
+
wasmRuntimeInjected = true;
|
|
42732
42760
|
return true;
|
|
42733
42761
|
} catch (error51) {
|
|
42734
|
-
log("[magic-context] failed to inject onnxruntime-web
|
|
42762
|
+
log("[magic-context] failed to inject onnxruntime-web:", error51 instanceof Error ? error51.message : String(error51));
|
|
42735
42763
|
return false;
|
|
42736
42764
|
}
|
|
42737
42765
|
}
|
|
42766
|
+
function likelyMuslHint() {
|
|
42767
|
+
if (process.platform !== "linux" || typeof process.report?.getReport !== "function")
|
|
42768
|
+
return "";
|
|
42769
|
+
try {
|
|
42770
|
+
const report = process.report.getReport();
|
|
42771
|
+
return typeof report.header?.glibcVersionRuntime === "string" ? "" : " Linux process report has no glibc runtime version (musl likely).";
|
|
42772
|
+
} catch {
|
|
42773
|
+
return "";
|
|
42774
|
+
}
|
|
42775
|
+
}
|
|
42776
|
+
function localEmbeddingRuntimeIsDisabled() {
|
|
42777
|
+
return localEmbeddingRuntimeMode === "disabled";
|
|
42778
|
+
}
|
|
42779
|
+
function disableLocalEmbeddingsAfterRuntimeFailure(detail) {
|
|
42780
|
+
localEmbeddingRuntimeMode = "disabled";
|
|
42781
|
+
logForRuntime(`[magic-context] local embeddings are disabled because both the onnxruntime-node native binding and the onnxruntime-web (WASM) fallback failed to load. Native failure: ${detail}. Run \`npx @cortexkit/magic-context@latest doctor\` for repair guidance (use \`doctor --force\` to reinstall cached plugin packages), or configure an \`openai-compatible\` embedding HTTP endpoint. Existing memories are unaffected.`);
|
|
42782
|
+
}
|
|
42783
|
+
async function loadTransformersForLocalEmbedding() {
|
|
42784
|
+
if (localEmbeddingRuntimeMode === "disabled") {
|
|
42785
|
+
throw new Error("local embedding runtime is disabled");
|
|
42786
|
+
}
|
|
42787
|
+
if (localEmbeddingRuntimeMode === "wasm") {
|
|
42788
|
+
if (!await ensureWasmOrtInjected()) {
|
|
42789
|
+
disableLocalEmbeddingsAfterRuntimeFailure("the previously selected WASM runtime is unavailable");
|
|
42790
|
+
throw new Error("onnxruntime-web failed to load");
|
|
42791
|
+
}
|
|
42792
|
+
try {
|
|
42793
|
+
return { module: await importTransformersWasmFallbackForRuntime(), usesWasm: true };
|
|
42794
|
+
} catch (wasmError) {
|
|
42795
|
+
disableLocalEmbeddingsAfterRuntimeFailure("the previously selected WASM runtime failed to load");
|
|
42796
|
+
throw wasmError;
|
|
42797
|
+
}
|
|
42798
|
+
}
|
|
42799
|
+
const electron = isElectronForRuntime();
|
|
42800
|
+
if (electron) {
|
|
42801
|
+
const wasInjected = wasmRuntimeInjected;
|
|
42802
|
+
if (await ensureWasmOrtInjected()) {
|
|
42803
|
+
if (!wasInjected) {
|
|
42804
|
+
logForRuntime("[magic-context] Electron detected — using onnxruntime-web (WASM) for embeddings (bypasses onnxruntime-node native load)");
|
|
42805
|
+
}
|
|
42806
|
+
return { module: await importTransformersForRuntime(), usesWasm: true };
|
|
42807
|
+
}
|
|
42808
|
+
}
|
|
42809
|
+
try {
|
|
42810
|
+
return { module: await importTransformersForRuntime(), usesWasm: false };
|
|
42811
|
+
} catch (nativeError) {
|
|
42812
|
+
if (!isNativeRuntimeMissingError(nativeError) || electron) {
|
|
42813
|
+
throw nativeError;
|
|
42814
|
+
}
|
|
42815
|
+
if (!await ensureWasmOrtInjected()) {
|
|
42816
|
+
disableLocalEmbeddingsAfterRuntimeFailure(nativeError instanceof Error ? nativeError.message : String(nativeError));
|
|
42817
|
+
throw nativeError;
|
|
42818
|
+
}
|
|
42819
|
+
localEmbeddingRuntimeMode = "wasm";
|
|
42820
|
+
try {
|
|
42821
|
+
const module = await importTransformersWasmFallbackForRuntime();
|
|
42822
|
+
logForRuntime("[magic-context] onnxruntime-node failed to load; using onnxruntime-web (WASM) for local embeddings. WASM inference is slower than native; a remote `openai-compatible` provider may be faster." + likelyMuslHint());
|
|
42823
|
+
return { module, usesWasm: true };
|
|
42824
|
+
} catch (wasmError) {
|
|
42825
|
+
disableLocalEmbeddingsAfterRuntimeFailure(nativeError instanceof Error ? nativeError.message : String(nativeError));
|
|
42826
|
+
throw wasmError;
|
|
42827
|
+
}
|
|
42828
|
+
}
|
|
42829
|
+
}
|
|
42738
42830
|
var DEFAULT_LOCAL_DTYPE = "fp32";
|
|
42739
42831
|
async function withQuietConsole(fn) {
|
|
42740
42832
|
const origWarn = console.warn;
|
|
@@ -42752,7 +42844,6 @@ async function withQuietConsole(fn) {
|
|
|
42752
42844
|
console.error = origError;
|
|
42753
42845
|
}
|
|
42754
42846
|
}
|
|
42755
|
-
var nativeRuntimeMissing = false;
|
|
42756
42847
|
function isNativeRuntimeMissingError(error51) {
|
|
42757
42848
|
const message = error51 instanceof Error ? error51.message : String(error51 ?? "");
|
|
42758
42849
|
const lower = message.toLowerCase();
|
|
@@ -42836,7 +42927,7 @@ class LocalEmbeddingProvider {
|
|
|
42836
42927
|
if (this.pipeline) {
|
|
42837
42928
|
return true;
|
|
42838
42929
|
}
|
|
42839
|
-
if (
|
|
42930
|
+
if (localEmbeddingRuntimeMode === "disabled") {
|
|
42840
42931
|
return false;
|
|
42841
42932
|
}
|
|
42842
42933
|
if (this.initPromise) {
|
|
@@ -42848,15 +42939,13 @@ class LocalEmbeddingProvider {
|
|
|
42848
42939
|
if (this.disposing) {
|
|
42849
42940
|
return;
|
|
42850
42941
|
}
|
|
42851
|
-
const
|
|
42852
|
-
const transformersSpec = "@huggingface/transformers";
|
|
42853
|
-
const transformersModule = await import(transformersSpec);
|
|
42942
|
+
const { module: transformersModule, usesWasm } = await loadTransformersForLocalEmbedding();
|
|
42854
42943
|
const env = transformersModule.env;
|
|
42855
42944
|
const LogLevel = transformersModule.LogLevel;
|
|
42856
42945
|
if (LogLevel && "ERROR" in LogLevel) {
|
|
42857
42946
|
env.logLevel = LogLevel.ERROR;
|
|
42858
42947
|
}
|
|
42859
|
-
const modelCacheDir =
|
|
42948
|
+
const modelCacheDir = modelCacheDirForRuntime();
|
|
42860
42949
|
try {
|
|
42861
42950
|
if (shouldEnforcePrivateStoragePermissions()) {
|
|
42862
42951
|
mkdirSync4(modelCacheDir, { recursive: true, mode: 448 });
|
|
@@ -42883,7 +42972,7 @@ class LocalEmbeddingProvider {
|
|
|
42883
42972
|
try {
|
|
42884
42973
|
const pipeline = await withQuietConsole(() => createPipeline("feature-extraction", this.model, {
|
|
42885
42974
|
dtype: this.dtype,
|
|
42886
|
-
...
|
|
42975
|
+
...usesWasm ? { device: "auto" } : {}
|
|
42887
42976
|
}));
|
|
42888
42977
|
if (this.disposing) {
|
|
42889
42978
|
await pipeline.dispose?.();
|
|
@@ -42915,10 +43004,9 @@ class LocalEmbeddingProvider {
|
|
|
42915
43004
|
await releaseLock();
|
|
42916
43005
|
}
|
|
42917
43006
|
} catch (error51) {
|
|
42918
|
-
if (isNativeRuntimeMissingError(error51)) {
|
|
42919
|
-
|
|
42920
|
-
|
|
42921
|
-
} else {
|
|
43007
|
+
if (!localEmbeddingRuntimeIsDisabled() && isNativeRuntimeMissingError(error51)) {
|
|
43008
|
+
disableLocalEmbeddingsAfterRuntimeFailure(error51 instanceof Error ? error51.message : String(error51));
|
|
43009
|
+
} else if (!localEmbeddingRuntimeIsDisabled()) {
|
|
42922
43010
|
log("[magic-context] embedding model failed to load:", error51);
|
|
42923
43011
|
}
|
|
42924
43012
|
this.pipeline = null;
|
package/dist/index.js
CHANGED
|
@@ -403,7 +403,7 @@ import {
|
|
|
403
403
|
withMigrationLanguageDirective,
|
|
404
404
|
withRawMessageProvider,
|
|
405
405
|
withRawSessionMessageCache
|
|
406
|
-
} from "./index-
|
|
406
|
+
} from "./index-fre7qcqg.js";
|
|
407
407
|
import {
|
|
408
408
|
pushNotification
|
|
409
409
|
} from "./index-hw34xmzk.js";
|
|
@@ -28349,7 +28349,7 @@ ${c.content}
|
|
|
28349
28349
|
// package.json
|
|
28350
28350
|
var package_default = {
|
|
28351
28351
|
name: "@cortexkit/pi-magic-context",
|
|
28352
|
-
version: "0.40.
|
|
28352
|
+
version: "0.40.1",
|
|
28353
28353
|
type: "module",
|
|
28354
28354
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
28355
28355
|
main: "dist/index.js",
|
package/dist/subagent-entry.js
CHANGED
package/package.json
CHANGED