@cortexkit/opencode-magic-context 0.33.1 → 0.34.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.
- package/README.md +20 -3
- package/dist/config/agent-disable.d.ts +22 -0
- package/dist/config/agent-disable.d.ts.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/migrate-experimental.d.ts +2 -1
- package/dist/config/migrate-experimental.d.ts.map +1 -1
- package/dist/config/project-security.d.ts +9 -0
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +90 -17
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/config/transform-mode.d.ts +2 -0
- package/dist/config/transform-mode.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-n48c783v.js → conflict-warning-hook-fvpfvt0w.js} +1 -1
- package/dist/{derive-budgets-e9j09sjr.js → derive-budgets-9crp0cvd.js} +1 -1
- package/dist/features/builtin-commands/commands.d.ts +1 -1
- package/dist/features/builtin-commands/commands.d.ts.map +1 -1
- package/dist/features/magic-context/compaction-marker.d.ts +57 -0
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/classify.d.ts +1 -0
- package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/map-memories.d.ts +1 -0
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/refresh-primers.d.ts +1 -0
- package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +2 -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 +4 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts +19 -1
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +28 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +7 -1
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts +1 -0
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/fail-closed-block.d.ts +10 -0
- package/dist/features/magic-context/fail-closed-block.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/storage-git-commits.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts +7 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
- package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
- package/dist/features/magic-context/memory/project-identity.d.ts +2 -6
- package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts +23 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/mural/compress-cues.d.ts +1 -0
- package/dist/features/magic-context/mural/compress-cues.d.ts.map +1 -1
- package/dist/features/magic-context/mural/render-mural.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts +8 -1
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/scheduler.d.ts.map +1 -1
- package/dist/features/magic-context/schema-fence-probe.d.ts +28 -0
- package/dist/features/magic-context/schema-fence-probe.d.ts.map +1 -0
- package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts +37 -2
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +38 -4
- 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.d.ts +2 -2
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
- package/dist/hooks/magic-context/boundary-execution.d.ts +1 -1
- package/dist/hooks/magic-context/boundary-execution.d.ts.map +1 -1
- package/dist/hooks/magic-context/cache-busting-signals.d.ts +1 -0
- package/dist/hooks/magic-context/cache-busting-signals.d.ts.map +1 -1
- package/dist/hooks/magic-context/child-session-spawn.d.ts +26 -0
- package/dist/hooks/magic-context/child-session-spawn.d.ts.map +1 -0
- package/dist/hooks/magic-context/command-handler.d.ts +3 -0
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-off-transition.d.ts +96 -0
- package/dist/hooks/magic-context/compaction-off-transition.d.ts.map +1 -0
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts +2 -0
- package/dist/hooks/magic-context/compartment-runner-historian.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-mapping.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +12 -5
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/ctx-reduce-availability.d.ts +47 -1
- package/dist/hooks/magic-context/ctx-reduce-availability.d.ts.map +1 -1
- package/dist/hooks/magic-context/emergency-drop.d.ts +2 -2
- package/dist/hooks/magic-context/event-handler.d.ts +7 -0
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts +13 -21
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/execute-status.d.ts +5 -1
- package/dist/hooks/magic-context/execute-status.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +2 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts +1 -0
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +14 -6
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +10 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/live-session-state.d.ts +3 -0
- package/dist/hooks/magic-context/live-session-state.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +3 -0
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/send-session-notification.d.ts +20 -1
- package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +3 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +31 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +29 -2
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-56yjaeb2.js → index-2y0ybv5x.js} +11 -1
- package/dist/{index-ey1bc14z.js → index-b563sga5.js} +7 -264
- package/dist/{index-y1c9tcm3.js → index-cn960ffd.js} +101 -20
- package/dist/{index-xyaekybw.js → index-dtas91s5.js} +6 -4
- package/dist/index-fcyvznch.js +279 -0
- package/dist/{index-63dq2g4d.js → index-ry8rh8cv.js} +138 -24
- package/dist/{index-c2gahrks.js → index-x8spt5wy.js} +1682 -893
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1677 -723
- package/dist/plugin/dream-timer.d.ts +4 -2
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +12 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts +10 -0
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts +3 -7
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/plugin/tool-registry.d.ts +8 -0
- package/dist/plugin/tool-registry.d.ts.map +1 -1
- package/dist/{recomp-orchestrator-2yb2hfh2.js → recomp-orchestrator-k72ejkkh.js} +6 -4
- package/dist/send-session-notification-6njqewzk.js +20 -0
- package/dist/shared/conflict-detector.d.ts +38 -1
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/conflict-fixer.d.ts +18 -1
- package/dist/shared/conflict-fixer.d.ts.map +1 -1
- package/dist/shared/context-limit-provenance.d.ts +3 -0
- package/dist/shared/context-limit-provenance.d.ts.map +1 -0
- package/dist/shared/escalation-bands.d.ts +9 -0
- package/dist/shared/escalation-bands.d.ts.map +1 -0
- package/dist/shared/format-threshold.d.ts +1 -1
- package/dist/shared/models-dev-cache.d.ts +29 -3
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/shared/rpc-server.d.ts.map +1 -1
- package/dist/shared/rpc-types.d.ts +51 -1
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/shared/rpc-utils.d.ts +19 -0
- package/dist/shared/rpc-utils.d.ts.map +1 -1
- package/dist/shared/storage-permissions.d.ts +5 -0
- package/dist/shared/storage-permissions.d.ts.map +1 -0
- package/dist/shared/tui-runtime-specifiers.d.ts +20 -0
- package/dist/shared/tui-runtime-specifiers.d.ts.map +1 -0
- package/dist/{storage-meta-session-td6bwtky.js → storage-meta-session-xt41zbw4.js} +2 -1
- package/dist/{task-config-5nx3qfz8.js → task-config-gbp7r23g.js} +1 -1
- package/dist/tui/compaction-off.d.ts +13 -0
- package/dist/tui/compaction-off.d.ts.map +1 -0
- package/dist/tui/data/context-db.d.ts.map +1 -1
- package/dist/tui-compiled/compaction-off.d.ts +13 -0
- package/dist/tui-compiled/compaction-off.d.ts.map +1 -0
- package/dist/tui-compiled/data/context-db.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/agents/dreamer.ts +68 -0
- package/src/agents/hidden-agent-registrations.ts +331 -0
- package/src/agents/historian.ts +3 -0
- package/src/agents/language-directive.test.ts +138 -0
- package/src/agents/language-directive.ts +121 -0
- package/src/agents/magic-context-prompt.language.test.ts +35 -0
- package/src/agents/magic-context-prompt.test.ts +292 -0
- package/src/agents/magic-context-prompt.ts +182 -0
- package/src/agents/permissions.test.ts +252 -0
- package/src/agents/permissions.ts +186 -0
- package/src/agents/sidekick.ts +1 -0
- package/src/agents/smart-note-compiler.ts +1 -0
- package/src/config/agent-disable.ts +106 -0
- package/src/config/compaction-accessor-guard.test.ts +82 -0
- package/src/config/compaction-backcompat.test.ts +52 -0
- package/src/config/index.test.ts +936 -0
- package/src/config/index.ts +601 -0
- package/src/config/migrate-config-location.test.ts +332 -0
- package/src/config/migrate-config-location.ts +635 -0
- package/src/config/migrate-dreamer-v2.test.ts +287 -0
- package/src/config/migrate-dreamer-v2.ts +336 -0
- package/src/config/migrate-experimental.test.ts +41 -0
- package/src/config/migrate-experimental.ts +185 -0
- package/src/config/project-security.test.ts +388 -0
- package/src/config/project-security.ts +611 -0
- package/src/config/prune-config-leaf.test.ts +78 -0
- package/src/config/prune-config-leaf.ts +68 -0
- package/src/config/removed-config-keys.test.ts +116 -0
- package/src/config/schema/agent-overrides.ts +45 -0
- package/src/config/schema/magic-context.test.ts +359 -0
- package/src/config/schema/magic-context.ts +991 -0
- package/src/config/transform-mode.test.ts +62 -0
- package/src/config/transform-mode.ts +34 -0
- package/src/config/variable.test.ts +323 -0
- package/src/config/variable.ts +192 -0
- package/src/features/magic-context/defaults.ts +1 -0
- package/src/features/magic-context/dreamer/cron.ts +243 -0
- package/src/features/magic-context/dreamer/task-registry.ts +151 -0
- package/src/shared/conflict-detector.test.ts +121 -0
- package/src/shared/conflict-detector.ts +50 -3
- package/src/shared/conflict-fixer.test.ts +309 -0
- package/src/shared/conflict-fixer.ts +82 -5
- package/src/shared/context-limit-provenance.ts +6 -0
- package/src/shared/escalation-bands.test.ts +23 -0
- package/src/shared/escalation-bands.ts +18 -0
- package/src/shared/format-threshold.ts +1 -1
- package/src/shared/models-dev-cache.test.ts +171 -0
- package/src/shared/models-dev-cache.ts +195 -38
- package/src/shared/rpc-server.ts +27 -18
- package/src/shared/rpc-types.ts +55 -1
- package/src/shared/rpc-utils.test.ts +157 -0
- package/src/shared/rpc-utils.ts +137 -0
- package/src/shared/storage-permissions.ts +20 -0
- package/src/shared/tui-runtime-specifiers.ts +32 -0
- package/src/tui/compaction-off.test.ts +56 -0
- package/src/tui/compaction-off.ts +29 -0
- package/src/tui/data/context-db.ts +6 -0
- package/src/tui/index.tsx +113 -65
- package/src/tui/slots/sidebar-content.tsx +189 -91
- package/src/tui/tui-compiled-runtime-imports.test.ts +151 -0
- package/src/tui-compiled/compaction-off.ts +29 -0
- package/src/tui-compiled/data/context-db.ts +6 -0
- package/src/tui-compiled/index.tsx +558 -455
- package/src/tui-compiled/slots/sidebar-content.tsx +334 -169
- package/dist/send-session-notification-tghq9gnh.js +0 -11
- /package/dist/{index-v7fmc1s2.js → index-ygcng9t8.js} +0 -0
|
@@ -9,11 +9,46 @@ import {
|
|
|
9
9
|
// src/shared/models-dev-cache.ts
|
|
10
10
|
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { join } from "node:path";
|
|
12
|
+
|
|
13
|
+
// src/shared/harness-provider-map.ts
|
|
14
|
+
var PI_TO_CANONICAL_PROVIDER = {
|
|
15
|
+
"openai-codex": "openai",
|
|
16
|
+
"google-antigravity": "google"
|
|
17
|
+
};
|
|
18
|
+
function remapProviderPrefix(ref, map) {
|
|
19
|
+
if (typeof ref !== "string")
|
|
20
|
+
return ref;
|
|
21
|
+
const slash = ref.indexOf("/");
|
|
22
|
+
if (slash <= 0)
|
|
23
|
+
return ref;
|
|
24
|
+
const provider = ref.slice(0, slash);
|
|
25
|
+
const mapped = map[provider];
|
|
26
|
+
return mapped ? `${mapped}${ref.slice(slash)}` : ref;
|
|
27
|
+
}
|
|
28
|
+
function piModelRefToCanonical(ref) {
|
|
29
|
+
return remapProviderPrefix(ref, PI_TO_CANONICAL_PROVIDER);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/shared/storage-permissions.ts
|
|
33
|
+
var enforcePrivateStoragePermissions = true;
|
|
34
|
+
function setStoragePrivatePermissionEnforcement(enforce) {
|
|
35
|
+
enforcePrivateStoragePermissions = enforce;
|
|
36
|
+
}
|
|
37
|
+
function shouldEnforcePrivateStoragePermissions() {
|
|
38
|
+
return enforcePrivateStoragePermissions;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/shared/models-dev-cache.ts
|
|
12
42
|
var MIN_SANE_LIMIT = 20000;
|
|
13
43
|
var MAX_SANE_LIMIT = 3000000;
|
|
14
44
|
function isSaneLimit(limit) {
|
|
15
45
|
return typeof limit === "number" && limit >= MIN_SANE_LIMIT && limit <= MAX_SANE_LIMIT;
|
|
16
46
|
}
|
|
47
|
+
var SEPARATE_OUTPUT_QUOTA_PROVIDERS = new Set(["google", "google-antigravity"]);
|
|
48
|
+
var MIN_PLAUSIBLE_CONTEXT_LIMIT = 1024;
|
|
49
|
+
var OUTPUT_RESERVE_CAP_RATIO = 0.25;
|
|
50
|
+
var outputReserveConfig;
|
|
51
|
+
var reserveClampLogSeen = new Set;
|
|
17
52
|
var apiCache = null;
|
|
18
53
|
var apiLoadedAt = 0;
|
|
19
54
|
var persistSeedLoaded = false;
|
|
@@ -30,12 +65,16 @@ function loadPersistedApiCacheOnce() {
|
|
|
30
65
|
const map = new Map;
|
|
31
66
|
for (const [key, persisted] of Object.entries(obj)) {
|
|
32
67
|
const limit = typeof persisted === "number" ? persisted : persisted.limit;
|
|
68
|
+
const contextLimit = typeof persisted === "number" ? undefined : persisted.contextLimit;
|
|
33
69
|
const inputLimit = typeof persisted === "number" ? undefined : persisted.inputLimit;
|
|
70
|
+
const outputLimit = typeof persisted === "number" ? undefined : persisted.outputLimit;
|
|
34
71
|
const vision = typeof persisted === "number" ? false : persisted.vision === true;
|
|
35
|
-
if (isSaneLimit(limit)) {
|
|
72
|
+
if (isSaneLimit(contextLimit) || isSaneLimit(limit)) {
|
|
36
73
|
map.set(key, {
|
|
37
|
-
limit,
|
|
74
|
+
limit: isSaneLimit(limit) ? limit : undefined,
|
|
75
|
+
contextLimit: isSaneLimit(contextLimit) ? contextLimit : undefined,
|
|
38
76
|
inputLimit: isSaneLimit(inputLimit) ? inputLimit : undefined,
|
|
77
|
+
outputLimit: isFinitePositive(outputLimit) ? outputLimit : undefined,
|
|
39
78
|
vision
|
|
40
79
|
});
|
|
41
80
|
}
|
|
@@ -54,7 +93,9 @@ function persistApiCache() {
|
|
|
54
93
|
if (isSaneLimit(value.limit)) {
|
|
55
94
|
obj[key] = {
|
|
56
95
|
limit: value.limit,
|
|
96
|
+
contextLimit: isSaneLimit(value.contextLimit) ? value.contextLimit : undefined,
|
|
57
97
|
inputLimit: isSaneLimit(value.inputLimit) ? value.inputLimit : undefined,
|
|
98
|
+
outputLimit: isFinitePositive(value.outputLimit) ? value.outputLimit : undefined,
|
|
58
99
|
vision: value.vision === true
|
|
59
100
|
};
|
|
60
101
|
}
|
|
@@ -64,30 +105,95 @@ function persistApiCache() {
|
|
|
64
105
|
mkdirSync(dir, { recursive: true });
|
|
65
106
|
const target = persistFilePath();
|
|
66
107
|
const tmp = `${target}.${process.pid}.tmp`;
|
|
67
|
-
|
|
108
|
+
if (shouldEnforcePrivateStoragePermissions()) {
|
|
109
|
+
writeFileSync(tmp, JSON.stringify(obj), { encoding: "utf-8", mode: 384 });
|
|
110
|
+
} else {
|
|
111
|
+
writeFileSync(tmp, JSON.stringify(obj), { encoding: "utf-8" });
|
|
112
|
+
}
|
|
68
113
|
renameSync(tmp, target);
|
|
69
114
|
} catch {}
|
|
70
115
|
}
|
|
71
|
-
function
|
|
116
|
+
function isFinitePositive(value) {
|
|
117
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
118
|
+
}
|
|
119
|
+
function modelKeyLookupOrder(providerID, modelID) {
|
|
120
|
+
const full = `${providerID}/${modelID}`;
|
|
121
|
+
const canonicalFull = piModelRefToCanonical(full);
|
|
122
|
+
const candidates = [full, canonicalFull, modelID];
|
|
123
|
+
const colon = modelID.lastIndexOf(":");
|
|
124
|
+
if (colon > 0) {
|
|
125
|
+
const bareModel = modelID.slice(0, colon);
|
|
126
|
+
const providerBare = `${providerID}/${bareModel}`;
|
|
127
|
+
candidates.push(providerBare, piModelRefToCanonical(providerBare), bareModel);
|
|
128
|
+
}
|
|
129
|
+
return [...new Set(candidates)];
|
|
130
|
+
}
|
|
131
|
+
function configuredOutputReserve(config, providerID, modelID) {
|
|
132
|
+
if (typeof config === "number")
|
|
133
|
+
return Number.isFinite(config) && config >= 0 ? config : undefined;
|
|
134
|
+
if (!config)
|
|
135
|
+
return;
|
|
136
|
+
for (const candidate of modelKeyLookupOrder(providerID, modelID)) {
|
|
137
|
+
const value = config[candidate];
|
|
138
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0)
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
return Number.isFinite(config.default) && config.default >= 0 ? config.default : undefined;
|
|
142
|
+
}
|
|
143
|
+
function logReserveClampOnce(key, message) {
|
|
144
|
+
if (reserveClampLogSeen.has(key))
|
|
145
|
+
return;
|
|
146
|
+
reserveClampLogSeen.add(key);
|
|
147
|
+
sessionLog("global", `models-dev-cache: ${message}`);
|
|
148
|
+
}
|
|
149
|
+
function setOutputReserveConfig(config) {
|
|
150
|
+
outputReserveConfig = config;
|
|
151
|
+
}
|
|
152
|
+
function resolveLimit(limit, providerID, modelID, reserveConfig = outputReserveConfig) {
|
|
72
153
|
if (!limit)
|
|
73
154
|
return;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
return
|
|
78
|
-
|
|
155
|
+
const context = isFinitePositive(limit.context) ? limit.context : undefined;
|
|
156
|
+
const input = isFinitePositive(limit.input) ? limit.input : undefined;
|
|
157
|
+
if (input !== undefined && (context === undefined || input < context))
|
|
158
|
+
return input;
|
|
159
|
+
if (context === undefined)
|
|
160
|
+
return;
|
|
161
|
+
const configuredReserve = configuredOutputReserve(reserveConfig, providerID, modelID);
|
|
162
|
+
let reserve;
|
|
163
|
+
if (configuredReserve !== undefined) {
|
|
164
|
+
reserve = configuredReserve;
|
|
165
|
+
} else if (SEPARATE_OUTPUT_QUOTA_PROVIDERS.has(providerID)) {
|
|
166
|
+
reserve = 0;
|
|
167
|
+
} else {
|
|
168
|
+
const output = isFinitePositive(limit.output) ? limit.output : 0;
|
|
169
|
+
const cap = context * OUTPUT_RESERVE_CAP_RATIO;
|
|
170
|
+
reserve = Math.min(output, cap);
|
|
171
|
+
if (output > cap) {
|
|
172
|
+
logReserveClampOnce(`cap|${providerID}/${modelID}|${context}|${output}`, `output reserve capped at 25% for ${providerID}/${modelID}: ${output} → ${cap}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const floor = Math.max(MIN_PLAUSIBLE_CONTEXT_LIMIT, context * 0.5);
|
|
176
|
+
const maxReserve = Math.max(0, context - floor);
|
|
177
|
+
if (reserve > maxReserve) {
|
|
178
|
+
logReserveClampOnce(`floor|${providerID}/${modelID}|${context}|${reserve}`, `output reserve clamped for ${providerID}/${modelID}: ${reserve} → ${maxReserve} (usable floor ${floor})`);
|
|
179
|
+
reserve = maxReserve;
|
|
180
|
+
}
|
|
181
|
+
return Math.floor(context - reserve);
|
|
79
182
|
}
|
|
80
183
|
function setCachedModelMetadata(cache, key, model) {
|
|
81
|
-
const
|
|
184
|
+
const contextLimit = model?.limit?.context;
|
|
82
185
|
const inputLimit = model?.limit?.input;
|
|
83
|
-
|
|
186
|
+
const outputLimit = model?.limit?.output;
|
|
187
|
+
const rawLimit = isSaneLimit(contextLimit) ? contextLimit : isSaneLimit(inputLimit) ? inputLimit : undefined;
|
|
188
|
+
if (rawLimit === undefined)
|
|
84
189
|
return;
|
|
85
|
-
}
|
|
86
190
|
const values = [model?.capabilities, model?.modalities, model?.input, model?.attachment];
|
|
87
191
|
const vision = values.some((value2) => JSON.stringify(value2 ?? "").toLowerCase().includes("image") || JSON.stringify(value2 ?? "").toLowerCase().includes("vision"));
|
|
88
192
|
const value = {
|
|
89
|
-
limit,
|
|
193
|
+
limit: rawLimit,
|
|
194
|
+
contextLimit: isSaneLimit(contextLimit) ? contextLimit : undefined,
|
|
90
195
|
inputLimit: isSaneLimit(inputLimit) ? inputLimit : undefined,
|
|
196
|
+
outputLimit: isFinitePositive(outputLimit) ? outputLimit : undefined,
|
|
91
197
|
vision
|
|
92
198
|
};
|
|
93
199
|
cache.set(key, value);
|
|
@@ -152,10 +258,21 @@ async function refreshModelLimitsOnce(client) {
|
|
|
152
258
|
return false;
|
|
153
259
|
}
|
|
154
260
|
}
|
|
155
|
-
function getSdkContextLimit(providerID, modelID) {
|
|
261
|
+
function getSdkContextLimit(providerID, modelID, detectedContextLimit, options) {
|
|
156
262
|
loadPersistedApiCacheOnce();
|
|
157
|
-
const
|
|
158
|
-
|
|
263
|
+
const metadata = lookupMetadataWithTagFallback(apiCache, providerID, modelID);
|
|
264
|
+
if (!metadata)
|
|
265
|
+
return;
|
|
266
|
+
const rawContext = metadata.contextLimit ?? metadata.limit;
|
|
267
|
+
const promptOnlyDetected = options?.detectedLimitProvenance === "prompt_only" && isFinitePositive(detectedContextLimit) ? detectedContextLimit : undefined;
|
|
268
|
+
const context = promptOnlyDetected === undefined && isFinitePositive(detectedContextLimit) && isFinitePositive(rawContext) ? Math.min(rawContext, detectedContextLimit) : promptOnlyDetected === undefined && isFinitePositive(detectedContextLimit) ? detectedContextLimit : rawContext;
|
|
269
|
+
const inputCandidates = [metadata.inputLimit, promptOnlyDetected].filter(isFinitePositive);
|
|
270
|
+
const input = inputCandidates.length > 0 ? Math.min(...inputCandidates) : undefined;
|
|
271
|
+
return resolveLimit({
|
|
272
|
+
context,
|
|
273
|
+
input,
|
|
274
|
+
output: metadata.outputLimit
|
|
275
|
+
}, providerID, modelID, options?.reservation === "none" ? 0 : undefined);
|
|
159
276
|
}
|
|
160
277
|
function modelSupportsVision(providerID, modelID) {
|
|
161
278
|
loadPersistedApiCacheOnce();
|
|
@@ -167,18 +284,15 @@ function modelSupportsVision(providerID, modelID) {
|
|
|
167
284
|
const colon = modelID.lastIndexOf(":");
|
|
168
285
|
return colon > 0 ? apiCache.get(`${providerID}/${modelID.slice(0, colon)}`)?.vision === true : false;
|
|
169
286
|
}
|
|
170
|
-
function
|
|
287
|
+
function lookupMetadataWithTagFallback(cache, providerID, modelID) {
|
|
171
288
|
if (!cache)
|
|
172
289
|
return;
|
|
173
|
-
const exact = cache.get(`${providerID}/${modelID}`)
|
|
174
|
-
if (
|
|
290
|
+
const exact = cache.get(`${providerID}/${modelID}`);
|
|
291
|
+
if (exact)
|
|
175
292
|
return exact;
|
|
176
293
|
const colonIdx = modelID.lastIndexOf(":");
|
|
177
294
|
if (colonIdx > 0) {
|
|
178
|
-
|
|
179
|
-
const fallback = cache.get(`${providerID}/${baseModel}`)?.limit;
|
|
180
|
-
if (typeof fallback === "number")
|
|
181
|
-
return fallback;
|
|
295
|
+
return cache.get(`${providerID}/${modelID.slice(0, colonIdx)}`);
|
|
182
296
|
}
|
|
183
297
|
return;
|
|
184
298
|
}
|
|
@@ -224,4 +338,4 @@ function resolveHistorianContextLimit(historianModelOverride) {
|
|
|
224
338
|
return DEFAULT_HISTORIAN_CONTEXT_FALLBACK;
|
|
225
339
|
}
|
|
226
340
|
|
|
227
|
-
export { isSaneLimit, refreshModelLimitsFromApi, refreshModelLimitsAfterAuthOnce, getSdkContextLimit, modelSupportsVision, deriveTriggerBudget, deriveHistorianChunkTokens, resolveHistorianContextLimit };
|
|
341
|
+
export { piModelRefToCanonical, setStoragePrivatePermissionEnforcement, shouldEnforcePrivateStoragePermissions, isSaneLimit, setOutputReserveConfig, refreshModelLimitsFromApi, refreshModelLimitsAfterAuthOnce, getSdkContextLimit, modelSupportsVision, deriveTriggerBudget, deriveHistorianChunkTokens, resolveHistorianContextLimit };
|