@cortexkit/opencode-magic-context 0.41.2 → 0.41.4
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/README.md +9 -3
- package/dist/announcement-3c1vertn.js +14 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +756 -4
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/conflict-warning-hook-ejkc9sjn.js +16 -0
- package/dist/derive-budgets-bc366cz8.js +13 -0
- package/dist/features/magic-context/compartment-lease.d.ts +6 -0
- package/dist/features/magic-context/compartment-lease.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +13 -0
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +3 -0
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +18 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +13 -14
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta.d.ts +1 -1
- package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
- package/dist/features/magic-context/storage-subagent-invocations.d.ts +3 -2
- package/dist/features/magic-context/storage-subagent-invocations.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +6 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +2 -2
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/subagent-token-capture.d.ts +2 -1
- package/dist/features/magic-context/subagent-token-capture.d.ts.map +1 -1
- package/dist/hooks/magic-context/command-handler.d.ts +5 -1
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts +6 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +4 -0
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts +2 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/derive-budgets.d.ts +1 -0
- package/dist/hooks/magic-context/derive-budgets.d.ts.map +1 -1
- package/dist/hooks/magic-context/emergency-drop.d.ts +3 -1
- package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
- package/dist/hooks/magic-context/execute-status.d.ts +7 -1
- package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts +4 -3
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts +2 -0
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +9 -5
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +6 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/issue-423-fixture.d.ts +37 -0
- package/dist/hooks/magic-context/issue-423-fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/issue-424-fixture.d.ts +11 -0
- package/dist/hooks/magic-context/issue-424-fixture.d.ts.map +1 -0
- package/dist/hooks/magic-context/module-state-sync.d.ts +2 -1
- package/dist/hooks/magic-context/module-state-sync.d.ts.map +1 -1
- package/dist/hooks/magic-context/module-transport.d.ts +11 -4
- package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
- package/dist/hooks/magic-context/module-wire.d.ts +6 -1
- package/dist/hooks/magic-context/module-wire.d.ts.map +1 -1
- package/dist/hooks/magic-context/producer-window-guard.d.ts +8 -0
- package/dist/hooks/magic-context/producer-window-guard.d.ts.map +1 -0
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +59 -0
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts +2 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts +15 -0
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts +4 -1
- package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts +2 -0
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +15 -2
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/send-session-notification.d.ts +6 -0
- package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +8 -19
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +2 -0
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +8 -3
- package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
- package/dist/hooks/magic-context/tool-drop-target.d.ts +1 -0
- package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +2 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +32 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +4 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
- package/dist/{index-j8r0ejb3.js → index-0y2mcg5y.js} +1971 -11203
- package/dist/{index-1yh8g550.js → index-22jkk6wg.js} +2 -15
- package/dist/{index-dmvy29z0.js → index-3wzdwt6p.js} +11 -15
- package/dist/{index-eq9wr75c.js → index-4avmwfp5.js} +57 -108
- package/dist/{index-d1mxrd3p.js → index-7k55qm8a.js} +17 -12
- package/dist/{index-2wchnyk6.js → index-avwt563y.js} +8 -1
- package/dist/{index-4x691bz5.js → index-dkv2dn46.js} +5 -2
- package/dist/{index-rgdqj8nj.js → index-e7vx3byk.js} +1 -1
- package/dist/{index-szf8w1p5.js → index-fmsr7v69.js} +2 -2
- package/dist/{index-y1yr57fw.js → index-fz104x1j.js} +18 -18
- package/dist/{index-d62ypazr.js → index-jdxxq8cz.js} +6 -11
- package/dist/{index-9j3tx8hy.js → index-may8skc8.js} +6 -25
- package/dist/{index-cvda5jb3.js → index-mjv9je4e.js} +23 -19
- package/dist/{index-zwjhba2r.js → index-q264erdp.js} +122 -41
- package/dist/{index-b9j85d29.js → index-raatkvw5.js} +49 -11
- package/dist/{index-9xexf8s7.js → index-rn7gafjr.js} +1 -9
- package/dist/index-sd3egckz.js +1583 -0
- package/dist/index-v6t0tg85.js +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2660 -3255
- package/dist/model-resolution-dxatzjde.js +12 -0
- package/dist/{index-dynqfgx1.js → module-asyncify-2EFITU5U-rkqjhjxd.js} +69 -8
- package/dist/plugin/boot-deadline.d.ts +47 -0
- package/dist/plugin/boot-deadline.d.ts.map +1 -0
- package/dist/plugin/conflict-warning-hook.d.ts +10 -0
- package/dist/plugin/conflict-warning-hook.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +5 -0
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/prompt-context-5y5ms8f9.js +6 -0
- package/dist/recomp-orchestrator-q98r6rga.js +19 -0
- package/dist/rpc-notifications-4amf6mf4.js +14 -0
- package/dist/{index-vnz6jvdc.js → safe-notification-target-q9z81zt3.js} +4 -3
- package/dist/send-session-notification-hdh02wy9.js +16 -0
- package/dist/shared/cache-ttl-display.d.ts +23 -0
- package/dist/shared/cache-ttl-display.d.ts.map +1 -0
- package/dist/shared/cache-ttl-seed.d.ts +10 -0
- package/dist/shared/cache-ttl-seed.d.ts.map +1 -0
- package/dist/shared/config-diagnostics.d.ts +30 -0
- package/dist/shared/config-diagnostics.d.ts.map +1 -0
- package/dist/shared/config-warning-surface.d.ts +3 -0
- package/dist/shared/config-warning-surface.d.ts.map +1 -0
- package/dist/shared/conflict-detector.d.ts +3 -1
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/data-path.d.ts +10 -9
- package/dist/shared/data-path.d.ts.map +1 -1
- package/dist/shared/harness-provider-map.d.ts +7 -0
- package/dist/shared/harness-provider-map.d.ts.map +1 -1
- package/dist/shared/harness.d.ts +3 -3
- package/dist/shared/harness.d.ts.map +1 -1
- package/dist/shared/jsonc-parser.d.ts +12 -0
- package/dist/shared/jsonc-parser.d.ts.map +1 -1
- package/dist/shared/model-resolution.d.ts +3 -3
- package/dist/shared/model-resolution.d.ts.map +1 -1
- package/dist/shared/model-suggestion-retry.d.ts +14 -10
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/pi-executable.d.ts +6 -0
- package/dist/shared/pi-executable.d.ts.map +1 -0
- package/dist/shared/prompt-surface-runtime.d.ts +2 -2
- package/dist/shared/prompt-surface-runtime.d.ts.map +1 -1
- package/dist/shared/rpc-types.d.ts +6 -0
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/shared/rpc-utils.d.ts.map +1 -1
- package/dist/shared/status-detail-text.d.ts.map +1 -1
- package/dist/shared/tag-transcript.d.ts.map +1 -1
- package/dist/shared/transcript.d.ts +2 -1
- package/dist/shared/transcript.d.ts.map +1 -1
- package/dist/storage-meta-session-dvwfw778.js +20 -0
- package/dist/task-config-hnv93r7p.js +9 -0
- package/dist/transformers-node-wasm.js +328 -328
- package/dist/transformers-web.js +72 -72
- package/dist/{transformers.node-b1wa0hgx.js → transformers.node-dpmf3wpx.js} +74 -74
- package/package.json +1 -1
- package/src/config/index.test.ts +72 -0
- package/src/config/index.ts +96 -15
- package/src/config/project-security.hostile-matrix.test.ts +78 -9
- package/src/config/project-security.ts +4 -3
- package/src/config/schema/magic-context.test.ts +64 -0
- package/src/config/schema/magic-context.ts +100 -6
- package/src/shared/cache-ttl-display.test.ts +84 -0
- package/src/shared/cache-ttl-display.ts +64 -0
- package/src/shared/cache-ttl-seed.ts +23 -0
- package/src/shared/config-diagnostics.test.ts +29 -0
- package/src/shared/config-diagnostics.ts +64 -0
- package/src/shared/config-warning-surface.ts +28 -0
- package/src/shared/conflict-detector.test.ts +24 -0
- package/src/shared/conflict-detector.ts +25 -7
- package/src/shared/data-path.ts +10 -9
- package/src/shared/harness-provider-map.test.ts +16 -0
- package/src/shared/harness-provider-map.ts +15 -0
- package/src/shared/harness.ts +3 -3
- package/src/shared/jsonc-parser.test.ts +14 -1
- package/src/shared/jsonc-parser.ts +93 -0
- package/src/shared/model-resolution.test.ts +61 -0
- package/src/shared/model-resolution.ts +14 -5
- package/src/shared/model-suggestion-retry.ts +143 -28
- package/src/shared/pi-executable.ts +20 -0
- package/src/shared/prompt-surface-runtime.ts +3 -3
- package/src/shared/rpc-types.ts +6 -0
- package/src/shared/rpc-utils.ts +2 -3
- package/src/shared/status-detail-text.test.ts +2 -1
- package/src/shared/status-detail-text.ts +5 -1
- package/src/shared/tag-transcript.ts +32 -2
- package/src/shared/transcript.ts +3 -1
- package/src/tui/index.tsx +15 -1
- package/src/tui-compiled/index.tsx +234 -222
- package/dist/announcement-3g9xg433.js +0 -18
- package/dist/conflict-warning-hook-rf17b6et.js +0 -17
- package/dist/derive-budgets-9q2d3r93.js +0 -14
- package/dist/emscripten-module-49k43zfy.js +0 -507
- package/dist/emscripten-module-ex4v0x4z.js +0 -606
- package/dist/emscripten-module-jfs3d1dq.js +0 -1536
- package/dist/emscripten-module-ss4g4spn.js +0 -4563
- package/dist/ffi-bbm9vkfa.js +0 -92
- package/dist/ffi-kb5r0x1j.js +0 -92
- package/dist/ffi-qnrt0y78.js +0 -80
- package/dist/ffi-yx2hpf4p.js +0 -80
- package/dist/index-8mtsfhyg.js +0 -146
- package/dist/index-8sseka65.js +0 -251
- package/dist/index-ss632za9.js +0 -77
- package/dist/model-resolution-6w6wzw18.js +0 -17
- package/dist/module-ES6BEMUI-1yjdz59c.js +0 -14
- package/dist/module-asyncify-2EFITU5U-fdkx4fhy.js +0 -9
- package/dist/prompt-context-29qkb28f.js +0 -7
- package/dist/recomp-orchestrator-m37p3fq6.js +0 -34
- package/dist/rpc-notifications-1ffm755w.js +0 -17
- package/dist/safe-notification-target-2a8py95v.js +0 -11
- package/dist/send-session-notification-bw7eex6w.js +0 -20
- package/dist/storage-meta-session-dse3qv6s.js +0 -23
- package/dist/task-config-gv6s04fp.js +0 -18
- /package/dist/{index-37yzyeca.js → index-3fe78beq.js} +0 -0
package/dist/transformers-web.js
CHANGED
|
@@ -4241,18 +4241,18 @@ var Environment = class {
|
|
|
4241
4241
|
}
|
|
4242
4242
|
}
|
|
4243
4243
|
};
|
|
4244
|
-
function setupGlobals(
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4244
|
+
function setupGlobals(env2) {
|
|
4245
|
+
env2.set("false", false);
|
|
4246
|
+
env2.set("true", true);
|
|
4247
|
+
env2.set("none", null);
|
|
4248
|
+
env2.set("raise_exception", (args) => {
|
|
4249
4249
|
throw new Error(args);
|
|
4250
4250
|
});
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4251
|
+
env2.set("range", range);
|
|
4252
|
+
env2.set("strftime_now", strftime_now);
|
|
4253
|
+
env2.set("True", true);
|
|
4254
|
+
env2.set("False", false);
|
|
4255
|
+
env2.set("None", null);
|
|
4256
4256
|
}
|
|
4257
4257
|
function getAttributeValue(item, attributePath) {
|
|
4258
4258
|
const parts = attributePath.split(".");
|
|
@@ -4317,8 +4317,8 @@ function compareRuntimeValues(a, b, caseSensitive = false) {
|
|
|
4317
4317
|
}
|
|
4318
4318
|
var Interpreter = class {
|
|
4319
4319
|
global;
|
|
4320
|
-
constructor(
|
|
4321
|
-
this.global =
|
|
4320
|
+
constructor(env2) {
|
|
4321
|
+
this.global = env2 ?? new Environment;
|
|
4322
4322
|
}
|
|
4323
4323
|
run(program) {
|
|
4324
4324
|
return this.evaluate(program, this.global);
|
|
@@ -5401,14 +5401,14 @@ var Template = class {
|
|
|
5401
5401
|
this.parsed = parse(tokens);
|
|
5402
5402
|
}
|
|
5403
5403
|
render(items) {
|
|
5404
|
-
const
|
|
5405
|
-
setupGlobals(
|
|
5404
|
+
const env2 = new Environment;
|
|
5405
|
+
setupGlobals(env2);
|
|
5406
5406
|
if (items) {
|
|
5407
5407
|
for (const [key, value] of Object.entries(items)) {
|
|
5408
|
-
|
|
5408
|
+
env2.set(key, value);
|
|
5409
5409
|
}
|
|
5410
5410
|
}
|
|
5411
|
-
const interpreter = new Interpreter(
|
|
5411
|
+
const interpreter = new Interpreter(env2);
|
|
5412
5412
|
const result = interpreter.run(this.parsed);
|
|
5413
5413
|
return result.value;
|
|
5414
5414
|
}
|
|
@@ -6055,8 +6055,8 @@ function getFetchHeaders(urlOrPath) {
|
|
|
6055
6055
|
const headers = new Headers;
|
|
6056
6056
|
if (isNode) {
|
|
6057
6057
|
const IS_CI = !!process.env?.TESTING_REMOTELY;
|
|
6058
|
-
const
|
|
6059
|
-
headers.set("User-Agent", `transformers.js/${
|
|
6058
|
+
const version = env3.version;
|
|
6059
|
+
headers.set("User-Agent", `transformers.js/${version}; is_ci/${IS_CI};`);
|
|
6060
6060
|
const isHFURL = isValidUrl(urlOrPath, ["http:", "https:"], ["huggingface.co", "hf.co"]);
|
|
6061
6061
|
if (isHFURL) {
|
|
6062
6062
|
const token = process.env?.HF_TOKEN ?? process.env?.HF_ACCESS_TOKEN;
|
|
@@ -6819,7 +6819,7 @@ function dynamic_time_warping(matrix) {
|
|
|
6819
6819
|
const outputShape = [output_length + 1, input_length + 1];
|
|
6820
6820
|
const cost = Array.from({ length: outputShape[0] }, () => Array(outputShape[1]).fill(Infinity));
|
|
6821
6821
|
cost[0][0] = 0;
|
|
6822
|
-
const
|
|
6822
|
+
const trace = Array.from({ length: outputShape[0] }, () => Array(outputShape[1]).fill(-1));
|
|
6823
6823
|
for (let j2 = 1;j2 < outputShape[1]; ++j2) {
|
|
6824
6824
|
for (let i2 = 1;i2 < outputShape[0]; ++i2) {
|
|
6825
6825
|
const c0 = cost[i2 - 1][j2 - 1];
|
|
@@ -6837,14 +6837,14 @@ function dynamic_time_warping(matrix) {
|
|
|
6837
6837
|
t = 2;
|
|
6838
6838
|
}
|
|
6839
6839
|
cost[i2][j2] = matrix[i2 - 1][j2 - 1] + c;
|
|
6840
|
-
|
|
6840
|
+
trace[i2][j2] = t;
|
|
6841
6841
|
}
|
|
6842
6842
|
}
|
|
6843
6843
|
for (let i2 = 0;i2 < outputShape[1]; ++i2) {
|
|
6844
|
-
|
|
6844
|
+
trace[0][i2] = 2;
|
|
6845
6845
|
}
|
|
6846
6846
|
for (let i2 = 0;i2 < outputShape[0]; ++i2) {
|
|
6847
|
-
|
|
6847
|
+
trace[i2][0] = 1;
|
|
6848
6848
|
}
|
|
6849
6849
|
let i = output_length;
|
|
6850
6850
|
let j = input_length;
|
|
@@ -6853,7 +6853,7 @@ function dynamic_time_warping(matrix) {
|
|
|
6853
6853
|
while (i > 0 || j > 0) {
|
|
6854
6854
|
text_indices.push(i - 1);
|
|
6855
6855
|
time_indices.push(j - 1);
|
|
6856
|
-
switch (
|
|
6856
|
+
switch (trace[i][j]) {
|
|
6857
6857
|
case 0:
|
|
6858
6858
|
--i;
|
|
6859
6859
|
--j;
|
|
@@ -8784,9 +8784,9 @@ function reshape(data, dimensions) {
|
|
|
8784
8784
|
}
|
|
8785
8785
|
return reshapedArray[0];
|
|
8786
8786
|
}
|
|
8787
|
-
function permute(
|
|
8788
|
-
const [permutedData, shape] = permute_data(
|
|
8789
|
-
return new Tensor22(
|
|
8787
|
+
function permute(tensor, axes) {
|
|
8788
|
+
const [permutedData, shape] = permute_data(tensor.data, tensor.dims, axes);
|
|
8789
|
+
return new Tensor22(tensor.type, permutedData, shape);
|
|
8790
8790
|
}
|
|
8791
8791
|
function interpolate(input, [out_height, out_width], mode = "bilinear", align_corners = false) {
|
|
8792
8792
|
const in_channels = input.dims.at(-3) ?? 1;
|
|
@@ -8946,8 +8946,8 @@ function cat(tensors, dim = 0) {
|
|
|
8946
8946
|
const resultType = tensors[0].type;
|
|
8947
8947
|
if (dim === 0) {
|
|
8948
8948
|
let offset = 0;
|
|
8949
|
-
for (const
|
|
8950
|
-
const tensorData =
|
|
8949
|
+
for (const tensor of tensors) {
|
|
8950
|
+
const tensorData = tensor.data;
|
|
8951
8951
|
result.set(tensorData, offset);
|
|
8952
8952
|
offset += tensorData.length;
|
|
8953
8953
|
}
|
|
@@ -9070,20 +9070,20 @@ function full(size, fill_value) {
|
|
|
9070
9070
|
}
|
|
9071
9071
|
return fullHelper(size, fill_value, dtype, typedArrayCls);
|
|
9072
9072
|
}
|
|
9073
|
-
function full_like(
|
|
9074
|
-
return full(
|
|
9073
|
+
function full_like(tensor, fill_value) {
|
|
9074
|
+
return full(tensor.dims, fill_value);
|
|
9075
9075
|
}
|
|
9076
9076
|
function ones(size) {
|
|
9077
9077
|
return fullHelper(size, 1n, "int64", BigInt64Array);
|
|
9078
9078
|
}
|
|
9079
|
-
function ones_like(
|
|
9080
|
-
return ones(
|
|
9079
|
+
function ones_like(tensor) {
|
|
9080
|
+
return ones(tensor.dims);
|
|
9081
9081
|
}
|
|
9082
9082
|
function zeros(size) {
|
|
9083
9083
|
return fullHelper(size, 0n, "int64", BigInt64Array);
|
|
9084
9084
|
}
|
|
9085
|
-
function zeros_like(
|
|
9086
|
-
return zeros(
|
|
9085
|
+
function zeros_like(tensor) {
|
|
9086
|
+
return zeros(tensor.dims);
|
|
9087
9087
|
}
|
|
9088
9088
|
function rand(size) {
|
|
9089
9089
|
const length = size.reduce((a, b) => a * b, 1);
|
|
@@ -9093,11 +9093,11 @@ function randn(size) {
|
|
|
9093
9093
|
const length = size.reduce((a, b) => a * b, 1);
|
|
9094
9094
|
return new Tensor22("float32", Float32Array.from({ length }, () => random.gauss()), size);
|
|
9095
9095
|
}
|
|
9096
|
-
function quantize_embeddings(
|
|
9097
|
-
if (
|
|
9096
|
+
function quantize_embeddings(tensor, precision) {
|
|
9097
|
+
if (tensor.dims.length !== 2) {
|
|
9098
9098
|
throw new Error("The tensor must have 2 dimensions");
|
|
9099
9099
|
}
|
|
9100
|
-
if (
|
|
9100
|
+
if (tensor.dims.at(-1) % 8 !== 0) {
|
|
9101
9101
|
throw new Error("The last dimension of the tensor must be a multiple of 8");
|
|
9102
9102
|
}
|
|
9103
9103
|
if (!["binary", "ubinary"].includes(precision)) {
|
|
@@ -9106,7 +9106,7 @@ function quantize_embeddings(tensor2, precision) {
|
|
|
9106
9106
|
const signed = precision === "binary";
|
|
9107
9107
|
const dtype = signed ? "int8" : "uint8";
|
|
9108
9108
|
const cls = signed ? Int8Array : Uint8Array;
|
|
9109
|
-
const inputData =
|
|
9109
|
+
const inputData = tensor.data;
|
|
9110
9110
|
const outputData = new cls(inputData.length / 8);
|
|
9111
9111
|
for (let i = 0;i < inputData.length; ++i) {
|
|
9112
9112
|
const bit = inputData[i] > 0 ? 1 : 0;
|
|
@@ -9117,7 +9117,7 @@ function quantize_embeddings(tensor2, precision) {
|
|
|
9117
9117
|
outputData[arrayIndex] -= 128;
|
|
9118
9118
|
}
|
|
9119
9119
|
}
|
|
9120
|
-
return new Tensor22(dtype, outputData, [
|
|
9120
|
+
return new Tensor22(dtype, outputData, [tensor.dims[0], tensor.dims[1] / 8]);
|
|
9121
9121
|
}
|
|
9122
9122
|
async function get_tokenizer_files(modelId) {
|
|
9123
9123
|
if (!modelId) {
|
|
@@ -9133,16 +9133,16 @@ async function loadTokenizer(pretrained_model_name_or_path, options) {
|
|
|
9133
9133
|
const tokenizerFiles = await get_tokenizer_files(pretrained_model_name_or_path);
|
|
9134
9134
|
return await Promise.all(tokenizerFiles.map((file) => getModelJSON(pretrained_model_name_or_path, file, true, options)));
|
|
9135
9135
|
}
|
|
9136
|
-
function prepareTensorForDecode(
|
|
9137
|
-
const dims =
|
|
9136
|
+
function prepareTensorForDecode(tensor) {
|
|
9137
|
+
const dims = tensor.dims;
|
|
9138
9138
|
switch (dims.length) {
|
|
9139
9139
|
case 1:
|
|
9140
|
-
return
|
|
9140
|
+
return tensor.tolist();
|
|
9141
9141
|
case 2:
|
|
9142
9142
|
if (dims[0] !== 1) {
|
|
9143
9143
|
throw new Error("Unable to decode tensor with `batch size !== 1`. Use `tokenizer.batch_decode(...)` for batched inputs.");
|
|
9144
9144
|
}
|
|
9145
|
-
return
|
|
9145
|
+
return tensor.tolist()[0];
|
|
9146
9146
|
default:
|
|
9147
9147
|
throw new Error(`Expected tensor to have 1-2 dimensions, got ${dims.length}.`);
|
|
9148
9148
|
}
|
|
@@ -11705,26 +11705,26 @@ var RawImage = class _RawImage {
|
|
|
11705
11705
|
return await loadImageFunction(img);
|
|
11706
11706
|
}
|
|
11707
11707
|
}
|
|
11708
|
-
static fromTensor(
|
|
11709
|
-
if (
|
|
11710
|
-
throw new Error(`Tensor should have 3 dimensions, but has ${
|
|
11708
|
+
static fromTensor(tensor, channel_format = "CHW") {
|
|
11709
|
+
if (tensor.dims.length !== 3) {
|
|
11710
|
+
throw new Error(`Tensor should have 3 dimensions, but has ${tensor.dims.length} dimensions.`);
|
|
11711
11711
|
}
|
|
11712
11712
|
if (channel_format === "CHW") {
|
|
11713
|
-
|
|
11713
|
+
tensor = tensor.transpose(1, 2, 0);
|
|
11714
11714
|
} else if (channel_format === "HWC") {} else {
|
|
11715
11715
|
throw new Error(`Unsupported channel format: ${channel_format}`);
|
|
11716
11716
|
}
|
|
11717
|
-
if (!(
|
|
11718
|
-
throw new Error(`Unsupported tensor type: ${
|
|
11717
|
+
if (!(tensor.data instanceof Uint8ClampedArray || tensor.data instanceof Uint8Array)) {
|
|
11718
|
+
throw new Error(`Unsupported tensor type: ${tensor.type}`);
|
|
11719
11719
|
}
|
|
11720
|
-
switch (
|
|
11720
|
+
switch (tensor.dims[2]) {
|
|
11721
11721
|
case 1:
|
|
11722
11722
|
case 2:
|
|
11723
11723
|
case 3:
|
|
11724
11724
|
case 4:
|
|
11725
|
-
return new _RawImage(
|
|
11725
|
+
return new _RawImage(tensor.data, tensor.dims[1], tensor.dims[0], tensor.dims[2]);
|
|
11726
11726
|
default:
|
|
11727
|
-
throw new Error(`Unsupported number of channels: ${
|
|
11727
|
+
throw new Error(`Unsupported number of channels: ${tensor.dims[2]}`);
|
|
11728
11728
|
}
|
|
11729
11729
|
}
|
|
11730
11730
|
grayscale() {
|
|
@@ -12011,13 +12011,13 @@ var RawImage = class _RawImage {
|
|
|
12011
12011
|
return await canvas.convertToBlob({ type, quality });
|
|
12012
12012
|
}
|
|
12013
12013
|
toTensor(channel_format = "CHW") {
|
|
12014
|
-
let
|
|
12014
|
+
let tensor = new Tensor22("uint8", new Uint8Array(this.data), [this.height, this.width, this.channels]);
|
|
12015
12015
|
if (channel_format === "HWC") {} else if (channel_format === "CHW") {
|
|
12016
|
-
|
|
12016
|
+
tensor = tensor.permute(2, 0, 1);
|
|
12017
12017
|
} else {
|
|
12018
12018
|
throw new Error(`Unsupported channel format: ${channel_format}`);
|
|
12019
12019
|
}
|
|
12020
|
-
return
|
|
12020
|
+
return tensor;
|
|
12021
12021
|
}
|
|
12022
12022
|
toCanvas() {
|
|
12023
12023
|
if (!apis.IS_WEB_ENV) {
|
|
@@ -15301,25 +15301,25 @@ async function sessionRun(session, inputs) {
|
|
|
15301
15301
|
const checkedInputs = validateInputs(session, inputs);
|
|
15302
15302
|
try {
|
|
15303
15303
|
const ortFeed = Object.fromEntries(Object.entries(checkedInputs).map(([k, v]) => {
|
|
15304
|
-
const
|
|
15304
|
+
const tensor = v.ort_tensor;
|
|
15305
15305
|
if (apis.IS_NODE_ENV) {
|
|
15306
|
-
if (typeof Float16Array !== "undefined" &&
|
|
15307
|
-
|
|
15306
|
+
if (typeof Float16Array !== "undefined" && tensor.cpuData instanceof Float16Array) {
|
|
15307
|
+
tensor.cpuData = new Uint16Array(tensor.cpuData.buffer);
|
|
15308
15308
|
}
|
|
15309
15309
|
}
|
|
15310
|
-
return [k,
|
|
15310
|
+
return [k, tensor];
|
|
15311
15311
|
}));
|
|
15312
15312
|
const output = await runInferenceSession(session, ortFeed);
|
|
15313
15313
|
return replaceTensors(output);
|
|
15314
15314
|
} catch (e) {
|
|
15315
|
-
const formatted = Object.fromEntries(Object.entries(checkedInputs).map(([k,
|
|
15315
|
+
const formatted = Object.fromEntries(Object.entries(checkedInputs).map(([k, tensor]) => {
|
|
15316
15316
|
const unpacked = {
|
|
15317
|
-
type:
|
|
15318
|
-
dims:
|
|
15319
|
-
location:
|
|
15317
|
+
type: tensor.type,
|
|
15318
|
+
dims: tensor.dims,
|
|
15319
|
+
location: tensor.location
|
|
15320
15320
|
};
|
|
15321
15321
|
if (unpacked.location !== "gpu-buffer") {
|
|
15322
|
-
unpacked.data =
|
|
15322
|
+
unpacked.data = tensor.data;
|
|
15323
15323
|
}
|
|
15324
15324
|
return [k, unpacked];
|
|
15325
15325
|
}));
|
|
@@ -15332,12 +15332,12 @@ function validateInputs(session, inputs) {
|
|
|
15332
15332
|
const checkedInputs = /* @__PURE__ */ Object.create(null);
|
|
15333
15333
|
const missingInputs = [];
|
|
15334
15334
|
for (const inputName of session.inputNames) {
|
|
15335
|
-
const
|
|
15336
|
-
if (!(
|
|
15335
|
+
const tensor = inputs[inputName];
|
|
15336
|
+
if (!(tensor instanceof Tensor22)) {
|
|
15337
15337
|
missingInputs.push(inputName);
|
|
15338
15338
|
continue;
|
|
15339
15339
|
}
|
|
15340
|
-
checkedInputs[inputName] = isONNXProxy() ?
|
|
15340
|
+
checkedInputs[inputName] = isONNXProxy() ? tensor.clone() : tensor;
|
|
15341
15341
|
}
|
|
15342
15342
|
if (missingInputs.length > 0) {
|
|
15343
15343
|
throw new Error(`An error occurred during model execution: "Missing the following inputs: ${missingInputs.join(", ")}.`);
|
|
@@ -16736,9 +16736,9 @@ var PreTrainedModel = class extends Callable {
|
|
|
16736
16736
|
const sequences = new Tensor22("int64", all_input_ids.flat(), [all_input_ids.length, all_input_ids[0].length]);
|
|
16737
16737
|
const past_key_values = getPastKeyValues(outputs, model_inputs.past_key_values);
|
|
16738
16738
|
const cachedTensors = new Set(Object.values(past_key_values));
|
|
16739
|
-
for (const
|
|
16740
|
-
if (
|
|
16741
|
-
|
|
16739
|
+
for (const tensor of Object.values(outputs)) {
|
|
16740
|
+
if (tensor.location === "gpu-buffer" && !cachedTensors.has(tensor)) {
|
|
16741
|
+
tensor.dispose();
|
|
16742
16742
|
}
|
|
16743
16743
|
}
|
|
16744
16744
|
const keepCacheAlive = "past_key_values" in kwargs || generation_config.return_dict_in_generate;
|
|
@@ -19595,8 +19595,8 @@ var MultiModalityCausalLM = class extends MultiModalityPreTrainedModel {
|
|
|
19595
19595
|
});
|
|
19596
19596
|
const clamped = decoded_image.add_(1).mul_(255 / 2).clamp_(0, 255).to("uint8");
|
|
19597
19597
|
const images = [];
|
|
19598
|
-
for (const
|
|
19599
|
-
const img = RawImage.fromTensor(
|
|
19598
|
+
for (const tensor of clamped) {
|
|
19599
|
+
const img = RawImage.fromTensor(tensor);
|
|
19600
19600
|
images.push(img);
|
|
19601
19601
|
}
|
|
19602
19602
|
return images;
|