@cortexkit/pi-magic-context 0.49.42 → 0.49.44
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/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{compaction-marker-candidates-8qhackvy.js → compaction-marker-candidates-17a21jfn.js} +12 -2
- package/dist/compaction-marker-candidates-worker.js +5 -2
- package/dist/{embedding-backfill-002vyexq.js → embedding-backfill-v9b8gkmp.js} +4 -4
- package/dist/embedding-worker.js +2 -2
- package/dist/{index-j0h89gxy.js → index-025nxwc9.js} +1 -1
- package/dist/{index-p8jpbrj4.js → index-2kmwjq42.js} +64 -12
- package/dist/{index-z7dktknj.js → index-9tcbabqr.js} +2 -2
- package/dist/{index-6cvt64cn.js → index-fjmghcbx.js} +137 -52
- package/dist/{index-jbkwszd5.js → index-gajhgp4k.js} +3 -3
- package/dist/{index-k0csz6pb.js → index-gg9r701n.js} +3 -3
- package/dist/{index-p9jfa33t.js → index-gtd9kaaf.js} +3 -3
- package/dist/{index-ccanzg8p.js → index-gzk7d940.js} +1 -1
- package/dist/{index-mx757f3g.js → index-j2x88zk0.js} +1 -1
- package/dist/{index-a7sj2bam.js → index-p1jxxsth.js} +1 -1
- package/dist/{index-ry84c8dr.js → index-pb0ygvpa.js} +1 -1
- package/dist/{index-2qqsnh1b.js → index-xf3ndcqd.js} +1 -1
- package/dist/{index-g2j58qpq.js → index-zttw4vew.js} +3 -3
- package/dist/index.js +353 -190
- package/dist/{message-index-bounded-39z2atfj.js → message-index-bounded-1gj1pwjy.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/{project-embedding-registry-16pj4vyf.js → project-embedding-registry-e81zewts.js} +3 -3
- package/dist/raw-ordinal-warmup-worker.js +3 -3
- package/dist/{read-session-chunk-jxq427v6.js → read-session-chunk-r9qy3jzj.js} +2 -2
- package/dist/{render-6bhqgkpq.js → render-dvmk12tf.js} +5 -5
- package/dist/{search-archive-yvdq2nfp.js → search-archive-23s9g6dx.js} +4 -4
- package/dist/{search-45wknkb6.js → search-khaxkbs1.js} +7 -7
- package/dist/subagent-entry.js +13 -13
- package/dist/tag-snapshot-worker-pi.js +1 -1
- package/dist/{v2-archive-reader-bd94n954.js → v2-archive-reader-z7qgxxp0.js} +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -150,7 +150,7 @@ import {
|
|
|
150
150
|
registerTodoStateLifecycle,
|
|
151
151
|
syncCtxMemoryToolEnabled,
|
|
152
152
|
registerMagicContextTools
|
|
153
|
-
} from "./index-
|
|
153
|
+
} from "./index-fjmghcbx.js";
|
|
154
154
|
import"./index-4knyh1kt.js";
|
|
155
155
|
import {
|
|
156
156
|
canonicalModelIdentity,
|
|
@@ -168,7 +168,7 @@ import {
|
|
|
168
168
|
DEFAULT_HISTORIAN_TIMEOUT_MS,
|
|
169
169
|
DREAM_TASK_PROMOTION_DEFAULTS,
|
|
170
170
|
LIVE_RELOAD_CONFIG_PATHS
|
|
171
|
-
} from "./index-
|
|
171
|
+
} from "./index-gzk7d940.js";
|
|
172
172
|
import {
|
|
173
173
|
FAIL_CLOSED_DOCTOR_COMMAND,
|
|
174
174
|
formatFailClosedBlockingMessage,
|
|
@@ -353,7 +353,7 @@ import {
|
|
|
353
353
|
getRawSessionTagKeysThrough2,
|
|
354
354
|
getLegacyProtectedTailStartOrdinal2,
|
|
355
355
|
readSessionChunk2
|
|
356
|
-
} from "./index-
|
|
356
|
+
} from "./index-j2x88zk0.js";
|
|
357
357
|
import {
|
|
358
358
|
UNKNOWN_FIT_RATIO,
|
|
359
359
|
hasMeasuredDecisionCalibration,
|
|
@@ -490,7 +490,7 @@ import {
|
|
|
490
490
|
openCurrentDatabase,
|
|
491
491
|
openDatabaseAsync,
|
|
492
492
|
closeDatabase
|
|
493
|
-
} from "./index-
|
|
493
|
+
} from "./index-p1jxxsth.js";
|
|
494
494
|
import {
|
|
495
495
|
LkgRecoveryFenceError,
|
|
496
496
|
clearLkgFenceProcessState,
|
|
@@ -607,7 +607,7 @@ import {
|
|
|
607
607
|
getSourceContents,
|
|
608
608
|
recordSubagentInvocation,
|
|
609
609
|
getLatestHistorianInvocationId
|
|
610
|
-
} from "./index-
|
|
610
|
+
} from "./index-gtd9kaaf.js";
|
|
611
611
|
import {
|
|
612
612
|
resolveOpenCodeDbPath,
|
|
613
613
|
assertOpenCodeStoreGeneration,
|
|
@@ -665,7 +665,7 @@ import {
|
|
|
665
665
|
clearCompressionDepthRange,
|
|
666
666
|
cleanSearchText,
|
|
667
667
|
matchedSearchSnippet
|
|
668
|
-
} from "./index-
|
|
668
|
+
} from "./index-025nxwc9.js";
|
|
669
669
|
import {
|
|
670
670
|
rememberV1HiddenRun
|
|
671
671
|
} from "./index-6x556c2q.js";
|
|
@@ -742,7 +742,7 @@ import {
|
|
|
742
742
|
} from "./index-q1yc6bs0.js";
|
|
743
743
|
import {
|
|
744
744
|
getCachedLocalEmbeddingPooling
|
|
745
|
-
} from "./index-
|
|
745
|
+
} from "./index-xf3ndcqd.js";
|
|
746
746
|
import {
|
|
747
747
|
describeShadowBackfillWriteRefusal2,
|
|
748
748
|
contentSha2562,
|
|
@@ -760,10 +760,10 @@ import {
|
|
|
760
760
|
embedSessionCompartmentChunks2,
|
|
761
761
|
getEmbeddingCoverageStatus2,
|
|
762
762
|
getAutoEmbeddingSessionCoverage2
|
|
763
|
-
} from "./index-
|
|
763
|
+
} from "./index-9tcbabqr.js";
|
|
764
764
|
import {
|
|
765
765
|
cosineSimilarity
|
|
766
|
-
} from "./index-
|
|
766
|
+
} from "./index-gajhgp4k.js";
|
|
767
767
|
import {
|
|
768
768
|
USER_FACING_FAILURES,
|
|
769
769
|
renderUserFacingFailure,
|
|
@@ -797,8 +797,8 @@ import {
|
|
|
797
797
|
scheduleClearAndReindex,
|
|
798
798
|
clearSessionTracking,
|
|
799
799
|
createAutoSearchDiagnostics
|
|
800
|
-
} from "./index-
|
|
801
|
-
import"./index-
|
|
800
|
+
} from "./index-zttw4vew.js";
|
|
801
|
+
import"./index-2kmwjq42.js";
|
|
802
802
|
import {
|
|
803
803
|
DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS,
|
|
804
804
|
buildHiddenAgentRegistrations,
|
|
@@ -828,8 +828,8 @@ import {
|
|
|
828
828
|
} from "./index-wwsfevck.js";
|
|
829
829
|
import"./index-cq71g4dk.js";
|
|
830
830
|
import"./index-1cvyaw9a.js";
|
|
831
|
-
import"./index-
|
|
832
|
-
import"./index-
|
|
831
|
+
import"./index-gg9r701n.js";
|
|
832
|
+
import"./index-pb0ygvpa.js";
|
|
833
833
|
import {
|
|
834
834
|
__toESM
|
|
835
835
|
} from "./index-22jkk6wg.js";
|
|
@@ -3584,7 +3584,7 @@ function startHostStallProfilerSwitch() {
|
|
|
3584
3584
|
// package.json
|
|
3585
3585
|
var package_default = {
|
|
3586
3586
|
name: "@cortexkit/pi-magic-context",
|
|
3587
|
-
version: "0.49.
|
|
3587
|
+
version: "0.49.44",
|
|
3588
3588
|
type: "module",
|
|
3589
3589
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
3590
3590
|
main: "dist/index.js",
|
|
@@ -3658,6 +3658,8 @@ var package_default = {
|
|
|
3658
3658
|
"omp-pi-ai-18126": "npm:@oh-my-pi/pi-ai@18.12.6",
|
|
3659
3659
|
"omp-pi-ai-1813": "npm:@oh-my-pi/pi-ai@18.13.0",
|
|
3660
3660
|
"omp-pi-ai-18132": "npm:@oh-my-pi/pi-ai@18.13.2",
|
|
3661
|
+
"omp-pi-ai-18180": "npm:@oh-my-pi/pi-ai@18.18.0",
|
|
3662
|
+
"omp-pi-ai-18181": "npm:@oh-my-pi/pi-ai@18.18.1",
|
|
3661
3663
|
"pi-agent-core-087": "npm:@earendil-works/pi-agent-core@0.87.1",
|
|
3662
3664
|
"pi-ai-086": "npm:@earendil-works/pi-ai@0.86.0",
|
|
3663
3665
|
"pi-ai-087": "npm:@earendil-works/pi-ai@0.87.1",
|
|
@@ -24195,7 +24197,7 @@ function parseCacheTtl(ttl) {
|
|
|
24195
24197
|
}
|
|
24196
24198
|
function createScheduler(config) {
|
|
24197
24199
|
return {
|
|
24198
|
-
shouldExecute(sessionMeta, contextUsage,
|
|
24200
|
+
shouldExecute(sessionMeta, contextUsage, _currentTime, sessionId, modelKey, contextLimit) {
|
|
24199
24201
|
if (contextUsage.percentage === 0 && sessionMeta.lastResponseTime === 0) {
|
|
24200
24202
|
return "defer";
|
|
24201
24203
|
}
|
|
@@ -24208,35 +24210,10 @@ function createScheduler(config) {
|
|
|
24208
24210
|
if (contextUsage.percentage >= threshold) {
|
|
24209
24211
|
return "execute";
|
|
24210
24212
|
}
|
|
24211
|
-
let ttlMs;
|
|
24212
|
-
try {
|
|
24213
|
-
ttlMs = parseCacheTtl(sessionMeta.cacheTtl);
|
|
24214
|
-
} catch (error) {
|
|
24215
|
-
if (sessionId) {
|
|
24216
|
-
sessionLog2(sessionId, `invalid cache_ttl "${sessionMeta.cacheTtl}"; falling back to default 5m`, error);
|
|
24217
|
-
} else {
|
|
24218
|
-
log2(`[magic-context] invalid cache_ttl "${sessionMeta.cacheTtl}"; falling back to default 5m`, error);
|
|
24219
|
-
}
|
|
24220
|
-
ttlMs = parseCacheTtl("5m");
|
|
24221
|
-
}
|
|
24222
|
-
const elapsedTime = currentTime - sessionMeta.lastResponseTime;
|
|
24223
|
-
if (elapsedTime > ttlMs) {
|
|
24224
|
-
return "execute";
|
|
24225
|
-
}
|
|
24226
24213
|
return "defer";
|
|
24227
24214
|
}
|
|
24228
24215
|
};
|
|
24229
24216
|
}
|
|
24230
|
-
function computeHardCacheExpired(cacheTtl, lastResponseTime, now, onInvalid) {
|
|
24231
|
-
let ttlMs;
|
|
24232
|
-
try {
|
|
24233
|
-
ttlMs = parseCacheTtl(cacheTtl);
|
|
24234
|
-
} catch (error) {
|
|
24235
|
-
onInvalid?.(error);
|
|
24236
|
-
ttlMs = 5 * 60 * 1000;
|
|
24237
|
-
}
|
|
24238
|
-
return lastResponseTime > 0 && now - lastResponseTime > ttlMs;
|
|
24239
|
-
}
|
|
24240
24217
|
|
|
24241
24218
|
// ../plugin/src/features/magic-context/tagger.ts
|
|
24242
24219
|
var TOOL_COMPOSITE_KEY_SEP = "\x00";
|
|
@@ -24993,7 +24970,6 @@ var CACHE_LOSING_FOLD_REASONS = new Set([
|
|
|
24993
24970
|
"model_change",
|
|
24994
24971
|
"system_hash",
|
|
24995
24972
|
"tool_definitions",
|
|
24996
|
-
"ttl_idle",
|
|
24997
24973
|
"host_compaction"
|
|
24998
24974
|
]);
|
|
24999
24975
|
function sameBytes(left, right) {
|
|
@@ -25367,7 +25343,7 @@ function hasReclaimRide(signals) {
|
|
|
25367
25343
|
return signals.hardFold || signals.force || signals.explicitFlush || signals.publishedHistory || signals.subagentExecute === true || signals.executeReclaim === true || signals.servedShapeRepair === true;
|
|
25368
25344
|
}
|
|
25369
25345
|
function prefixMutationPermitted(gate) {
|
|
25370
|
-
return !gate.signedThinkingHold || gate.firstRender || gate.
|
|
25346
|
+
return !gate.signedThinkingHold || gate.firstRender || gate.emergency;
|
|
25371
25347
|
}
|
|
25372
25348
|
function reclaimRidePermitted(signals, gate) {
|
|
25373
25349
|
return prefixMutationPermitted(gate) && hasReclaimRide(signals);
|
|
@@ -34357,9 +34333,6 @@ function mustMaterializePi(state, db, currentCompartmentsOverride, passSnapshot)
|
|
|
34357
34333
|
if (meta.cachedM0ProjectIdentity !== null && meta.cachedM0ProjectIdentity !== state.projectIdentity) {
|
|
34358
34334
|
return piMaterializeMismatch("project_change", "projectIdentity", meta.cachedM0ProjectIdentity, state.projectIdentity);
|
|
34359
34335
|
}
|
|
34360
|
-
if (hard.cacheExpired && hard.lastResponseTime > 0 && hard.lastResponseTime > (meta.cachedM0MaterializedAt ?? 0)) {
|
|
34361
|
-
return piMaterializeMismatch("ttl_idle", "lastResponseTimeAfterMaterialization", meta.cachedM0MaterializedAt ?? 0, hard.lastResponseTime);
|
|
34362
|
-
}
|
|
34363
34336
|
if (cached.upgradeState !== current.upgradeState) {
|
|
34364
34337
|
return piMaterializeMismatch("renderer_upgrade", "upgradeState", cached.upgradeState, current.upgradeState);
|
|
34365
34338
|
}
|
|
@@ -36734,6 +36707,151 @@ function piExpandChainedRequest(payload, chained, anchor, prepared, pass) {
|
|
|
36734
36707
|
return { payload: { ...rest, input }, input };
|
|
36735
36708
|
}
|
|
36736
36709
|
|
|
36710
|
+
// src/pi-dispatch-cursor.ts
|
|
36711
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
36712
|
+
var MAX_BYTES = 32 * 1024 * 1024;
|
|
36713
|
+
var MAX_ENTRIES = 1e5;
|
|
36714
|
+
function object5(value) {
|
|
36715
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
36716
|
+
}
|
|
36717
|
+
function piCursorConversation(payload) {
|
|
36718
|
+
const body = object5(payload);
|
|
36719
|
+
if (body?.messages !== undefined || body?.input !== undefined || body?.contents !== undefined || body?.request !== undefined)
|
|
36720
|
+
return;
|
|
36721
|
+
const state = object5(body?.conversationState);
|
|
36722
|
+
if (!state || !Array.isArray(state.rootPromptMessagesJson) || !Array.isArray(state.turns))
|
|
36723
|
+
return;
|
|
36724
|
+
let bytes = 0;
|
|
36725
|
+
let nodes = 0;
|
|
36726
|
+
const messages = [];
|
|
36727
|
+
const rootIds = [];
|
|
36728
|
+
const decode = (value, depth = 0) => {
|
|
36729
|
+
if (++nodes > MAX_ENTRIES || depth > 128)
|
|
36730
|
+
throw new Error("Cursor structure limit");
|
|
36731
|
+
if (value instanceof Uint8Array) {
|
|
36732
|
+
bytes += value.byteLength;
|
|
36733
|
+
if (bytes > MAX_BYTES)
|
|
36734
|
+
throw new Error("Cursor bytes limit");
|
|
36735
|
+
if (value.byteLength === 32)
|
|
36736
|
+
return { blobId: Buffer.from(value).toString("hex") };
|
|
36737
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(value));
|
|
36738
|
+
}
|
|
36739
|
+
if (Array.isArray(value))
|
|
36740
|
+
return value.map((entry) => decode(entry, depth + 1));
|
|
36741
|
+
const record = object5(value);
|
|
36742
|
+
if (record)
|
|
36743
|
+
return Object.fromEntries(Object.entries(record).map(([key, child]) => [
|
|
36744
|
+
key,
|
|
36745
|
+
decode(child, depth + 1)
|
|
36746
|
+
]));
|
|
36747
|
+
return value;
|
|
36748
|
+
};
|
|
36749
|
+
try {
|
|
36750
|
+
const decoded = decode(state);
|
|
36751
|
+
for (const root of decoded.rootPromptMessagesJson) {
|
|
36752
|
+
const record = object5(root);
|
|
36753
|
+
if (typeof record?.blobId === "string")
|
|
36754
|
+
rootIds.push(record.blobId);
|
|
36755
|
+
else if (record && typeof record.role === "string")
|
|
36756
|
+
messages.push(record);
|
|
36757
|
+
else
|
|
36758
|
+
return;
|
|
36759
|
+
}
|
|
36760
|
+
for (const value of decoded.turns.slice(0, 8)) {
|
|
36761
|
+
const turn = object5(value);
|
|
36762
|
+
const agent = object5(object5(turn?.turn)?.value) ?? turn;
|
|
36763
|
+
const user = object5(agent?.userMessage);
|
|
36764
|
+
if (typeof user?.text === "string")
|
|
36765
|
+
messages.push({ role: "user", content: user.text });
|
|
36766
|
+
}
|
|
36767
|
+
const action = object5(object5(body?.action)?.action);
|
|
36768
|
+
if (!action || !["userMessageAction", "resumeAction"].includes(String(action.case)))
|
|
36769
|
+
return;
|
|
36770
|
+
let active = decode(body?.action);
|
|
36771
|
+
let activeText;
|
|
36772
|
+
if (action.case === "userMessageAction") {
|
|
36773
|
+
const user = object5(object5(action.value)?.userMessage);
|
|
36774
|
+
if (!user || typeof user.text !== "string")
|
|
36775
|
+
return;
|
|
36776
|
+
messages.push({ role: "user", content: user.text });
|
|
36777
|
+
activeText = user.text;
|
|
36778
|
+
const { messageId: _messageId, ...content } = user;
|
|
36779
|
+
active = decode({
|
|
36780
|
+
action: {
|
|
36781
|
+
case: action.case,
|
|
36782
|
+
value: { ...object5(action.value), userMessage: content }
|
|
36783
|
+
}
|
|
36784
|
+
});
|
|
36785
|
+
}
|
|
36786
|
+
return {
|
|
36787
|
+
conversation: {
|
|
36788
|
+
conversationState: decoded,
|
|
36789
|
+
action: active,
|
|
36790
|
+
customSystemPrompt: body?.customSystemPrompt
|
|
36791
|
+
},
|
|
36792
|
+
messages,
|
|
36793
|
+
rootIds,
|
|
36794
|
+
activeText
|
|
36795
|
+
};
|
|
36796
|
+
} catch {
|
|
36797
|
+
return;
|
|
36798
|
+
}
|
|
36799
|
+
}
|
|
36800
|
+
function piCursorManagedRoots(messages, signature, cwd) {
|
|
36801
|
+
if (!signature)
|
|
36802
|
+
return [];
|
|
36803
|
+
const roots = new Set;
|
|
36804
|
+
const date = new Date;
|
|
36805
|
+
const day = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
36806
|
+
const reminder = cwd && `<system-reminder>
|
|
36807
|
+
Today: ${day}; current working directory: '${cwd.replace(/\\/gu, "/")}'. Do not repeat this information in your reply.
|
|
36808
|
+
</system-reminder>`;
|
|
36809
|
+
for (const value of messages.slice(0, 8)) {
|
|
36810
|
+
const source = object5(value);
|
|
36811
|
+
if (!source || !["user", "developer"].includes(String(source.role)))
|
|
36812
|
+
continue;
|
|
36813
|
+
const message = piOmpUserHistory(source);
|
|
36814
|
+
const raw = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content;
|
|
36815
|
+
if (!Array.isArray(raw))
|
|
36816
|
+
continue;
|
|
36817
|
+
const parts = [];
|
|
36818
|
+
let managed = false;
|
|
36819
|
+
for (const part of raw) {
|
|
36820
|
+
if (part?.type === "text" && typeof part.text === "string") {
|
|
36821
|
+
const text = part.text.trim();
|
|
36822
|
+
managed ||= text.slice(0, 4096).includes(signature);
|
|
36823
|
+
if (text)
|
|
36824
|
+
parts.push({ type: "text", text });
|
|
36825
|
+
} else if (part?.type === "image" && typeof part.data === "string") {
|
|
36826
|
+
parts.push({
|
|
36827
|
+
type: "image",
|
|
36828
|
+
image: `data:${part.mimeType};base64,${part.data}`,
|
|
36829
|
+
mediaType: part.mimeType
|
|
36830
|
+
});
|
|
36831
|
+
}
|
|
36832
|
+
}
|
|
36833
|
+
if (!managed)
|
|
36834
|
+
continue;
|
|
36835
|
+
const hash = (content) => {
|
|
36836
|
+
const json = JSON.stringify({ role: "user", content });
|
|
36837
|
+
if (json.length <= MAX_BYTES)
|
|
36838
|
+
roots.add(createHash14("sha256").update(json).digest("hex"));
|
|
36839
|
+
};
|
|
36840
|
+
hash(parts);
|
|
36841
|
+
if (reminder) {
|
|
36842
|
+
if (typeof message.content === "string")
|
|
36843
|
+
hash([
|
|
36844
|
+
{ type: "text", text: `${reminder}
|
|
36845
|
+
|
|
36846
|
+
${message.content}`.trim() }
|
|
36847
|
+
]);
|
|
36848
|
+
else
|
|
36849
|
+
hash([{ type: "text", text: reminder }, ...parts]);
|
|
36850
|
+
}
|
|
36851
|
+
}
|
|
36852
|
+
return [...roots];
|
|
36853
|
+
}
|
|
36854
|
+
|
|
36737
36855
|
// src/pi-dispatch-google.ts
|
|
36738
36856
|
function piGoogleConversation(payload) {
|
|
36739
36857
|
if (!payload || typeof payload !== "object")
|
|
@@ -36774,12 +36892,13 @@ function piConversationFields(payload) {
|
|
|
36774
36892
|
};
|
|
36775
36893
|
} else {
|
|
36776
36894
|
const google = piGoogleConversation(payload);
|
|
36777
|
-
|
|
36895
|
+
const cursor = google ? undefined : piCursorConversation(payload);
|
|
36896
|
+
if (!google && !cursor)
|
|
36778
36897
|
return;
|
|
36779
|
-
conversation = {
|
|
36780
|
-
contents: google
|
|
36781
|
-
systemInstruction: google
|
|
36782
|
-
configSystemInstruction: google
|
|
36898
|
+
conversation = cursor?.conversation ?? {
|
|
36899
|
+
contents: google?.contents,
|
|
36900
|
+
systemInstruction: google?.systemInstruction,
|
|
36901
|
+
configSystemInstruction: google?.config?.systemInstruction
|
|
36783
36902
|
};
|
|
36784
36903
|
}
|
|
36785
36904
|
const fields = [];
|
|
@@ -36853,15 +36972,20 @@ function piManagedSignature(messages) {
|
|
|
36853
36972
|
}
|
|
36854
36973
|
return;
|
|
36855
36974
|
}
|
|
36856
|
-
function piHasManagedSignature(payload, signature) {
|
|
36975
|
+
function piHasManagedSignature(payload, signature, cursorRoots) {
|
|
36857
36976
|
if (!signature || !payload || typeof payload !== "object")
|
|
36858
36977
|
return false;
|
|
36859
36978
|
const body = payload;
|
|
36860
36979
|
const google = piGoogleConversation(payload);
|
|
36980
|
+
const cursor = body.messages === undefined && body.input === undefined && !google ? piCursorConversation(payload) : undefined;
|
|
36981
|
+
if (cursor?.activeText?.slice(0, 4096).includes(signature))
|
|
36982
|
+
return true;
|
|
36983
|
+
if (cursorRoots?.length && cursor?.rootIds.some((id) => cursorRoots.includes(id)))
|
|
36984
|
+
return true;
|
|
36861
36985
|
const nativeText = !!google || body.inferenceConfig !== undefined;
|
|
36862
36986
|
if (typeof body.input === "string" && body.messages === undefined)
|
|
36863
36987
|
return body.input.slice(0, 4096).includes(signature);
|
|
36864
|
-
const messages = Array.isArray(body.messages) ? body.messages : Array.isArray(body.input) ? body.input : google?.contents;
|
|
36988
|
+
const messages = Array.isArray(body.messages) ? body.messages : Array.isArray(body.input) ? body.input : google?.contents ?? cursor?.messages;
|
|
36865
36989
|
if (!messages)
|
|
36866
36990
|
return false;
|
|
36867
36991
|
for (const message of messages.slice(0, 8)) {
|
|
@@ -36879,12 +37003,36 @@ function piHasManagedSignature(payload, signature) {
|
|
|
36879
37003
|
}
|
|
36880
37004
|
return false;
|
|
36881
37005
|
}
|
|
37006
|
+
function piDispatchShape(payload, api) {
|
|
37007
|
+
let keys;
|
|
37008
|
+
try {
|
|
37009
|
+
keys = payload && typeof payload === "object" ? Object.keys(payload).sort().slice(0, 12).join(",") : typeof payload;
|
|
37010
|
+
} catch {
|
|
37011
|
+
keys = "unreadable object";
|
|
37012
|
+
}
|
|
37013
|
+
return `provider API=${api ?? "unknown"} shape=${keys || "empty object"}`;
|
|
37014
|
+
}
|
|
37015
|
+
|
|
37016
|
+
// src/pi-dispatch-refused.ts
|
|
37017
|
+
function piRefusedPayload(message) {
|
|
37018
|
+
const fail = () => {
|
|
37019
|
+
throw new Error(message);
|
|
37020
|
+
};
|
|
37021
|
+
return new Proxy(Object.create(null), {
|
|
37022
|
+
get: (_target, key) => key === "then" ? undefined : fail(),
|
|
37023
|
+
ownKeys: fail,
|
|
37024
|
+
getOwnPropertyDescriptor: fail,
|
|
37025
|
+
set: fail,
|
|
37026
|
+
has: fail,
|
|
37027
|
+
getPrototypeOf: fail
|
|
37028
|
+
});
|
|
37029
|
+
}
|
|
36882
37030
|
|
|
36883
37031
|
// src/pi-dispatch-assistant-history.ts
|
|
36884
37032
|
function piOmitsTruncatedAssistant(message) {
|
|
36885
37033
|
return (message.stopReason === "length" || message.stopReason === "error" || message.stopReason === "aborted") && Array.isArray(message.content) && !message.content.some((block) => block?.type === "text" || block?.type === "toolCall");
|
|
36886
37034
|
}
|
|
36887
|
-
function
|
|
37035
|
+
function object6(value) {
|
|
36888
37036
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
36889
37037
|
}
|
|
36890
37038
|
function nonblank(value) {
|
|
@@ -36900,7 +37048,7 @@ function piAnthropicAssistantReplay(message, model, host) {
|
|
|
36900
37048
|
let thinking = false;
|
|
36901
37049
|
let fallback = false;
|
|
36902
37050
|
for (const value of message.content) {
|
|
36903
|
-
const block =
|
|
37051
|
+
const block = object6(value);
|
|
36904
37052
|
if (!block)
|
|
36905
37053
|
return "kept";
|
|
36906
37054
|
if (block.type === "toolCall")
|
|
@@ -36967,7 +37115,7 @@ function piAnthropicOptionalThinking(message) {
|
|
|
36967
37115
|
const texts = [];
|
|
36968
37116
|
let fallback = false;
|
|
36969
37117
|
for (const value of Array.isArray(message.content) ? message.content : []) {
|
|
36970
|
-
const block =
|
|
37118
|
+
const block = object6(value);
|
|
36971
37119
|
if (block?.type === "thinking") {
|
|
36972
37120
|
if (nonblank(block.thinkingSignature))
|
|
36973
37121
|
signatures.push(block.thinkingSignature);
|
|
@@ -36984,7 +37132,7 @@ var THINKING_PRESENCE_PLACEHOLDER = "(no reasoning was returned for this turn)";
|
|
|
36984
37132
|
function piExplainsOptionalAssistant(thinking, content) {
|
|
36985
37133
|
const fromThinking = (text) => typeof text === "string" && thinking.texts.some((prepared) => text.includes(prepared));
|
|
36986
37134
|
return Array.isArray(content) && content.length > 0 && content.every((value) => {
|
|
36987
|
-
const block =
|
|
37135
|
+
const block = object6(value);
|
|
36988
37136
|
if (block?.type === "thinking") {
|
|
36989
37137
|
if (nonblank(block.signature))
|
|
36990
37138
|
return thinking.signatures.includes(block.signature);
|
|
@@ -37006,7 +37154,7 @@ var RESPONSES_APIS = new Set([
|
|
|
37006
37154
|
"openai-codex-responses",
|
|
37007
37155
|
"azure-openai-responses"
|
|
37008
37156
|
]);
|
|
37009
|
-
function
|
|
37157
|
+
function object7(value) {
|
|
37010
37158
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
37011
37159
|
}
|
|
37012
37160
|
function piResponsesCallComponent(id) {
|
|
@@ -37017,12 +37165,12 @@ function piToolCallPairing(messages) {
|
|
|
37017
37165
|
const responsesComponents = new Set;
|
|
37018
37166
|
const opaqueCompositeIds = new Set;
|
|
37019
37167
|
for (const value of messages) {
|
|
37020
|
-
const message =
|
|
37168
|
+
const message = object7(value);
|
|
37021
37169
|
if (message?.role !== "assistant" || !Array.isArray(message.content))
|
|
37022
37170
|
continue;
|
|
37023
37171
|
const responses = RESPONSES_APIS.has(String(message.api));
|
|
37024
37172
|
for (const part of message.content) {
|
|
37025
|
-
const block =
|
|
37173
|
+
const block = object7(part);
|
|
37026
37174
|
if (block?.type !== "toolCall" || typeof block.id !== "string")
|
|
37027
37175
|
continue;
|
|
37028
37176
|
if (responses)
|
|
@@ -37043,7 +37191,7 @@ function piToolCallPairing(messages) {
|
|
|
37043
37191
|
// src/pi-dispatch-chat-history.ts
|
|
37044
37192
|
var MAX_EXACT_UNITS = 32 * 1024 * 1024;
|
|
37045
37193
|
var IMAGE_CAPTION = "Attached image(s) from tool result:";
|
|
37046
|
-
function
|
|
37194
|
+
function object8(value) {
|
|
37047
37195
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
37048
37196
|
}
|
|
37049
37197
|
function omitsAssistant(message, model, compat) {
|
|
@@ -37053,7 +37201,7 @@ function omitsAssistant(message, model, compat) {
|
|
|
37053
37201
|
return true;
|
|
37054
37202
|
let thinking = false;
|
|
37055
37203
|
for (const value of message.content) {
|
|
37056
|
-
const block =
|
|
37204
|
+
const block = object8(value);
|
|
37057
37205
|
if (!block)
|
|
37058
37206
|
return false;
|
|
37059
37207
|
if (block.type === "text") {
|
|
@@ -37075,15 +37223,15 @@ function omitsAssistant(message, model, compat) {
|
|
|
37075
37223
|
function piChatHistoryPlan(messages, model) {
|
|
37076
37224
|
if (model?.api !== "openai-completions")
|
|
37077
37225
|
return;
|
|
37078
|
-
const compat =
|
|
37226
|
+
const compat = object8(model.compat) ?? {};
|
|
37079
37227
|
const pairingId = piToolCallPairing(messages);
|
|
37080
37228
|
const calls = new Set;
|
|
37081
37229
|
for (const value of messages) {
|
|
37082
|
-
const message =
|
|
37230
|
+
const message = object8(value);
|
|
37083
37231
|
if (message?.role !== "assistant" || !Array.isArray(message.content))
|
|
37084
37232
|
continue;
|
|
37085
37233
|
for (const value of message.content) {
|
|
37086
|
-
const block =
|
|
37234
|
+
const block = object8(value);
|
|
37087
37235
|
if (block?.type === "toolCall" && typeof block.id === "string")
|
|
37088
37236
|
calls.add(pairingId(block.id));
|
|
37089
37237
|
}
|
|
@@ -37092,7 +37240,7 @@ function piChatHistoryPlan(messages, model) {
|
|
|
37092
37240
|
let pending = new Set;
|
|
37093
37241
|
let exactUnits = 0;
|
|
37094
37242
|
for (let index = 0;index < messages.length; index++) {
|
|
37095
|
-
const message =
|
|
37243
|
+
const message = object8(messages[index]);
|
|
37096
37244
|
if (!message)
|
|
37097
37245
|
return;
|
|
37098
37246
|
if ((message.role === "bashExecution" || message.role === "pythonExecution") && message.excludeFromContext === true)
|
|
@@ -37104,7 +37252,7 @@ function piChatHistoryPlan(messages, model) {
|
|
|
37104
37252
|
continue;
|
|
37105
37253
|
if (Array.isArray(message.content))
|
|
37106
37254
|
for (const value of message.content) {
|
|
37107
|
-
const block =
|
|
37255
|
+
const block = object8(value);
|
|
37108
37256
|
if (block?.type === "toolCall" && typeof block.id === "string")
|
|
37109
37257
|
pending.add(pairingId(block.id));
|
|
37110
37258
|
}
|
|
@@ -37116,7 +37264,7 @@ function piChatHistoryPlan(messages, model) {
|
|
|
37116
37264
|
return;
|
|
37117
37265
|
const parts = [];
|
|
37118
37266
|
for (const value of message.content) {
|
|
37119
|
-
const part =
|
|
37267
|
+
const part = object8(value);
|
|
37120
37268
|
if (part?.type === "text" && typeof part.text === "string" && part.text.trim())
|
|
37121
37269
|
parts.push(part.text);
|
|
37122
37270
|
}
|
|
@@ -37149,14 +37297,14 @@ ${parts.join(`
|
|
|
37149
37297
|
};
|
|
37150
37298
|
const vision = model.input?.includes("image") === true && compat.stripImageInput !== true;
|
|
37151
37299
|
for (const step of transformed) {
|
|
37152
|
-
const message = step.kind === "source" ?
|
|
37300
|
+
const message = step.kind === "source" ? object8(messages[step.index]) : undefined;
|
|
37153
37301
|
if (message?.role !== "toolResult")
|
|
37154
37302
|
flushImages();
|
|
37155
37303
|
steps.push(step);
|
|
37156
37304
|
if (message?.role !== "toolResult" || !vision || !Array.isArray(message.content))
|
|
37157
37305
|
continue;
|
|
37158
37306
|
for (const value of message.content) {
|
|
37159
|
-
const block =
|
|
37307
|
+
const block = object8(value);
|
|
37160
37308
|
if (block?.type !== "image")
|
|
37161
37309
|
continue;
|
|
37162
37310
|
if (compat.requiresAssistantAfterToolResult === true)
|
|
@@ -37180,12 +37328,12 @@ ${parts.join(`
|
|
|
37180
37328
|
function piMatchesChatImages(content, urls) {
|
|
37181
37329
|
if (!Array.isArray(content) || content.length !== urls.length + 1)
|
|
37182
37330
|
return false;
|
|
37183
|
-
const caption =
|
|
37331
|
+
const caption = object8(content[0]);
|
|
37184
37332
|
if (caption?.type !== "text" || caption.text !== IMAGE_CAPTION || Object.keys(caption).length !== 2)
|
|
37185
37333
|
return false;
|
|
37186
37334
|
for (let i = 0;i < urls.length; i++) {
|
|
37187
|
-
const block =
|
|
37188
|
-
const image =
|
|
37335
|
+
const block = object8(content[i + 1]);
|
|
37336
|
+
const image = object8(block?.image_url);
|
|
37189
37337
|
if (block?.type !== "image_url" || Object.keys(block).length !== 2 || !image || Object.keys(image).length !== 1 || image.url !== urls[i])
|
|
37190
37338
|
return false;
|
|
37191
37339
|
}
|
|
@@ -37193,7 +37341,7 @@ function piMatchesChatImages(content, urls) {
|
|
|
37193
37341
|
}
|
|
37194
37342
|
|
|
37195
37343
|
// src/pi-dispatch-date-reminder.ts
|
|
37196
|
-
function
|
|
37344
|
+
function object9(value) {
|
|
37197
37345
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
37198
37346
|
}
|
|
37199
37347
|
function piDateReminderText(value, cwd) {
|
|
@@ -37217,8 +37365,8 @@ function piDateReminderWireText(content, cwd) {
|
|
|
37217
37365
|
return piDateReminderText(content, cwd) ? content : undefined;
|
|
37218
37366
|
if (!Array.isArray(content) || content.length !== 1)
|
|
37219
37367
|
return;
|
|
37220
|
-
const block =
|
|
37221
|
-
const cache =
|
|
37368
|
+
const block = object9(content[0]);
|
|
37369
|
+
const cache = object9(block?.cache_control);
|
|
37222
37370
|
if (block?.type !== "text" || !cache || cache.type !== "ephemeral" || Object.keys(block).some((key) => !["type", "text", "cache_control"].includes(key)) || Object.keys(cache).some((key) => !["type", "ttl", "scope"].includes(key)) || cache.ttl !== undefined && cache.ttl !== "5m" && cache.ttl !== "1h" || cache.scope !== undefined && cache.scope !== "global")
|
|
37223
37371
|
return;
|
|
37224
37372
|
return piDateReminderText(block.text, cwd) ? block.text : undefined;
|
|
@@ -37238,15 +37386,15 @@ var PI_DATE_REMINDER_APIS = new Set([
|
|
|
37238
37386
|
function singleText(value, type) {
|
|
37239
37387
|
if (!Array.isArray(value) || value.length !== 1)
|
|
37240
37388
|
return;
|
|
37241
|
-
const part =
|
|
37389
|
+
const part = object9(value[0]);
|
|
37242
37390
|
return part && (type === undefined ? Object.keys(part).length === 1 : part.type === type && Object.keys(part).length === 2) ? part.text : undefined;
|
|
37243
37391
|
}
|
|
37244
37392
|
function piWithoutDateReminders(payload, api, cwd, developerRole, includesPreparedFirstUser) {
|
|
37245
|
-
const body =
|
|
37393
|
+
const body = object9(payload);
|
|
37246
37394
|
if (!body)
|
|
37247
37395
|
return;
|
|
37248
37396
|
const google = api.startsWith("google-");
|
|
37249
|
-
const envelope = google ?
|
|
37397
|
+
const envelope = google ? object9(body.request) ?? body : body;
|
|
37250
37398
|
const field = google ? "contents" : api.endsWith("responses") ? "input" : "messages";
|
|
37251
37399
|
const messages = envelope[field];
|
|
37252
37400
|
if (!Array.isArray(messages))
|
|
@@ -37255,7 +37403,7 @@ function piWithoutDateReminders(payload, api, cwd, developerRole, includesPrepar
|
|
|
37255
37403
|
let removed = false;
|
|
37256
37404
|
const kept = [];
|
|
37257
37405
|
for (const value of messages) {
|
|
37258
|
-
const row =
|
|
37406
|
+
const row = object9(value);
|
|
37259
37407
|
if (!row)
|
|
37260
37408
|
return;
|
|
37261
37409
|
const text = google ? singleText(row.parts) : api === "bedrock-converse-stream" ? singleText(row.content) : api.endsWith("responses") ? singleText(row.content, "input_text") ?? (api === "openai-codex-responses" ? row.content : undefined) : row.content;
|
|
@@ -37272,7 +37420,7 @@ function piWithoutDateReminders(payload, api, cwd, developerRole, includesPrepar
|
|
|
37272
37420
|
removed = true;
|
|
37273
37421
|
continue;
|
|
37274
37422
|
}
|
|
37275
|
-
if (row.role === "user" && (typeof row.content === "string" || Array.isArray(row.content) && row.content.some((part) =>
|
|
37423
|
+
if (row.role === "user" && (typeof row.content === "string" || Array.isArray(row.content) && row.content.some((part) => object9(part)?.type === "input_text" || object9(part)?.type === "text" || typeof object9(part)?.text === "string") || Array.isArray(row.parts) && row.parts.some((part) => typeof object9(part)?.text === "string")))
|
|
37276
37424
|
firstUser = true;
|
|
37277
37425
|
kept.push(value);
|
|
37278
37426
|
}
|
|
@@ -37283,22 +37431,22 @@ function piWithoutDateReminders(payload, api, cwd, developerRole, includesPrepar
|
|
|
37283
37431
|
}
|
|
37284
37432
|
|
|
37285
37433
|
// src/pi-dispatch-image-budget.ts
|
|
37286
|
-
function
|
|
37434
|
+
function object10(value) {
|
|
37287
37435
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
37288
37436
|
}
|
|
37289
37437
|
function piImageBudgetPlan(model) {
|
|
37290
|
-
if (!model?.input?.includes("image") ||
|
|
37438
|
+
if (!model?.input?.includes("image") || object10(model.compat)?.stripImageInput === true)
|
|
37291
37439
|
return;
|
|
37292
37440
|
return {
|
|
37293
37441
|
count: 0,
|
|
37294
37442
|
api: model.api,
|
|
37295
37443
|
rows: new Map,
|
|
37296
|
-
hoistToolImages: model.api?.startsWith("google-") === true &&
|
|
37444
|
+
hoistToolImages: model.api?.startsWith("google-") === true && object10(model.compat)?.multimodalFunctionResponse !== true || model.api === "bedrock-converse-stream" && model.requiresToolResultImageHoisting === true,
|
|
37297
37445
|
hoistErrorImages: model.api === "anthropic-messages" || model.api === "bedrock-converse-stream"
|
|
37298
37446
|
};
|
|
37299
37447
|
}
|
|
37300
37448
|
function inputImage(block, api) {
|
|
37301
|
-
const file =
|
|
37449
|
+
const file = object10(block.providerFile);
|
|
37302
37450
|
if (api === "ollama-chat")
|
|
37303
37451
|
return { kind: "bytes", value: String(block.data ?? "") };
|
|
37304
37452
|
if ((api?.endsWith("responses") && file?.provider === "openai" || api === "anthropic-messages" && file?.provider === "anthropic") && typeof file?.id === "string")
|
|
@@ -37318,7 +37466,7 @@ function piRecordImages(plan, row, source) {
|
|
|
37318
37466
|
return;
|
|
37319
37467
|
const images = [];
|
|
37320
37468
|
for (const value of source.content) {
|
|
37321
|
-
const block =
|
|
37469
|
+
const block = object10(value);
|
|
37322
37470
|
if (block?.type === "image")
|
|
37323
37471
|
images.push(inputImage(block, plan.api));
|
|
37324
37472
|
}
|
|
@@ -37344,20 +37492,20 @@ function piWireImages(content, ollamaImages) {
|
|
|
37344
37492
|
return [];
|
|
37345
37493
|
const images = [];
|
|
37346
37494
|
for (const value of content) {
|
|
37347
|
-
const block =
|
|
37495
|
+
const block = object10(value);
|
|
37348
37496
|
if (!block)
|
|
37349
37497
|
continue;
|
|
37350
|
-
const source =
|
|
37351
|
-
const inline =
|
|
37352
|
-
const file =
|
|
37353
|
-
const bedrock =
|
|
37498
|
+
const source = object10(block.source);
|
|
37499
|
+
const inline = object10(block.inlineData);
|
|
37500
|
+
const file = object10(block.fileData);
|
|
37501
|
+
const bedrock = object10(block.image);
|
|
37354
37502
|
if (block.type === "image_url" || block.type === "input_image") {
|
|
37355
37503
|
if (typeof block.file_id === "string")
|
|
37356
37504
|
images.push({ kind: "file", value: block.file_id });
|
|
37357
37505
|
else
|
|
37358
37506
|
images.push({
|
|
37359
37507
|
kind: "url",
|
|
37360
|
-
value: String(typeof block.image_url === "string" ? block.image_url :
|
|
37508
|
+
value: String(typeof block.image_url === "string" ? block.image_url : object10(block.image_url)?.url)
|
|
37361
37509
|
});
|
|
37362
37510
|
} else if (block.type === "image") {
|
|
37363
37511
|
if (source?.type === "file")
|
|
@@ -37381,7 +37529,7 @@ function piWireImages(content, ollamaImages) {
|
|
|
37381
37529
|
else if (bedrock)
|
|
37382
37530
|
images.push({
|
|
37383
37531
|
kind: "data",
|
|
37384
|
-
value: String(
|
|
37532
|
+
value: String(object10(bedrock.source)?.bytes),
|
|
37385
37533
|
mime: `image/${bedrock.format}`
|
|
37386
37534
|
});
|
|
37387
37535
|
}
|
|
@@ -37403,11 +37551,11 @@ function piMatchesImages(actual, expected) {
|
|
|
37403
37551
|
return true;
|
|
37404
37552
|
}
|
|
37405
37553
|
function piWireImageCount(payload) {
|
|
37406
|
-
const body =
|
|
37554
|
+
const body = object10(payload);
|
|
37407
37555
|
const visit = (value) => {
|
|
37408
37556
|
if (Array.isArray(value))
|
|
37409
37557
|
return value.reduce((n, item) => n + visit(item), 0);
|
|
37410
|
-
const block =
|
|
37558
|
+
const block = object10(value);
|
|
37411
37559
|
if (!block)
|
|
37412
37560
|
return 0;
|
|
37413
37561
|
if (["image", "image_url", "input_image"].includes(String(block.type)) || block.inlineData || block.fileData || block.image)
|
|
@@ -37421,12 +37569,12 @@ function piWireImageCount(payload) {
|
|
|
37421
37569
|
block.response
|
|
37422
37570
|
].reduce((n, item) => n + visit(item), Array.isArray(block.images) ? block.images.length : 0);
|
|
37423
37571
|
};
|
|
37424
|
-
return visit(body?.messages ?? body?.input ?? body?.contents ??
|
|
37572
|
+
return visit(body?.messages ?? body?.input ?? body?.contents ?? object10(body?.request)?.contents);
|
|
37425
37573
|
}
|
|
37426
37574
|
|
|
37427
37575
|
// src/pi-dispatch-responses-history.ts
|
|
37428
37576
|
var MAX_TEXT_UNITS = 32 * 1024 * 1024;
|
|
37429
|
-
function
|
|
37577
|
+
function object11(value) {
|
|
37430
37578
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
37431
37579
|
}
|
|
37432
37580
|
function wellFormed2(text) {
|
|
@@ -37441,7 +37589,7 @@ function textIdentity2(text, phase) {
|
|
|
37441
37589
|
function signaturePhase(block) {
|
|
37442
37590
|
try {
|
|
37443
37591
|
if (typeof block.textSignature === "string") {
|
|
37444
|
-
const signature =
|
|
37592
|
+
const signature = object11(JSON.parse(block.textSignature));
|
|
37445
37593
|
if (signature?.v === 1 && typeof signature.id === "string")
|
|
37446
37594
|
return signature.phase;
|
|
37447
37595
|
}
|
|
@@ -37463,19 +37611,19 @@ ${wellFormed2(text)}
|
|
|
37463
37611
|
function coldReplayable(items) {
|
|
37464
37612
|
let reasoning = false;
|
|
37465
37613
|
for (const value of items) {
|
|
37466
|
-
const item =
|
|
37614
|
+
const item = object11(value);
|
|
37467
37615
|
if (typeof item?.encrypted_content === "string")
|
|
37468
37616
|
return false;
|
|
37469
37617
|
if (item?.type !== "reasoning")
|
|
37470
37618
|
continue;
|
|
37471
|
-
if (!Array.isArray(item.content) || !item.content.some((part) =>
|
|
37619
|
+
if (!Array.isArray(item.content) || !item.content.some((part) => object11(part)?.type === "reasoning_text"))
|
|
37472
37620
|
return false;
|
|
37473
37621
|
reasoning = true;
|
|
37474
37622
|
}
|
|
37475
37623
|
return reasoning;
|
|
37476
37624
|
}
|
|
37477
37625
|
function piResponsesAssistantTexts(value, model, host, alternatives, frozenTagStrips) {
|
|
37478
|
-
const message =
|
|
37626
|
+
const message = object11(value);
|
|
37479
37627
|
if (!message || !Array.isArray(message.content))
|
|
37480
37628
|
return;
|
|
37481
37629
|
if (piOmitsTruncatedAssistant(message))
|
|
@@ -37485,7 +37633,7 @@ function piResponsesAssistantTexts(value, model, host, alternatives, frozenTagSt
|
|
|
37485
37633
|
const sameModel = model !== undefined && typeof model.api === "string" && typeof model.id === "string" && typeof model.provider === "string" && message.api === model.api && message.model === model.id && message.provider === model.provider;
|
|
37486
37634
|
let units = 0;
|
|
37487
37635
|
for (const value of message.content) {
|
|
37488
|
-
const block =
|
|
37636
|
+
const block = object11(value);
|
|
37489
37637
|
if (block?.type === "toolCall")
|
|
37490
37638
|
continue;
|
|
37491
37639
|
if (block?.type === "thinking") {
|
|
@@ -37495,7 +37643,7 @@ function piResponsesAssistantTexts(value, model, host, alternatives, frozenTagSt
|
|
|
37495
37643
|
return;
|
|
37496
37644
|
if (!block.thinking.trim())
|
|
37497
37645
|
continue;
|
|
37498
|
-
const compat =
|
|
37646
|
+
const compat = object11(model.compat);
|
|
37499
37647
|
if (block.summary === false && (compat?.requiresReasoningContentForToolCalls === true || compat?.requiresReasoningContentForAllAssistantTurns === true))
|
|
37500
37648
|
return;
|
|
37501
37649
|
const text = demotedThinking(block.thinking, model);
|
|
@@ -37515,13 +37663,13 @@ function piResponsesAssistantTexts(value, model, host, alternatives, frozenTagSt
|
|
|
37515
37663
|
texts.push(textIdentity2(wellFormed2(block.text), sameModel ? signaturePhase(block) : undefined));
|
|
37516
37664
|
blocks.push(block);
|
|
37517
37665
|
}
|
|
37518
|
-
const payload =
|
|
37666
|
+
const payload = object11(message.providerPayload);
|
|
37519
37667
|
if (message.api !== model?.api || typeof model?.id !== "string" || typeof model?.provider !== "string" || message.model !== model?.id || (payload?.provider ?? message.provider) !== model?.provider || payload?.type !== "openaiResponsesHistory" || payload.dt !== true || !Array.isArray(payload.items))
|
|
37520
37668
|
return texts;
|
|
37521
37669
|
if (host === "omp" && model.api === "openai-codex-responses" && texts.every((text) => !/\S/u.test(JSON.parse(text)[0])) && payload.items.every((value) => {
|
|
37522
|
-
const item =
|
|
37670
|
+
const item = object11(value);
|
|
37523
37671
|
return item?.type === "reasoning" || item?.type === "message" && item.role === "assistant" && Array.isArray(item.content) && item.content.every((value) => {
|
|
37524
|
-
const part =
|
|
37672
|
+
const part = object11(value);
|
|
37525
37673
|
return part?.type === "output_text" && typeof part.text === "string" && !/\S/u.test(part.text);
|
|
37526
37674
|
});
|
|
37527
37675
|
}))
|
|
@@ -37538,7 +37686,7 @@ function piResponsesAssistantTexts(value, model, host, alternatives, frozenTagSt
|
|
|
37538
37686
|
let rewrittenText = false;
|
|
37539
37687
|
let allUnsignedFrozen = true;
|
|
37540
37688
|
for (const value of payload.items) {
|
|
37541
|
-
const item =
|
|
37689
|
+
const item = object11(value);
|
|
37542
37690
|
if (item?.type === "reasoning")
|
|
37543
37691
|
continue;
|
|
37544
37692
|
if (item?.type === "function_call" || item?.type === "custom_tool_call") {
|
|
@@ -37549,14 +37697,14 @@ function piResponsesAssistantTexts(value, model, host, alternatives, frozenTagSt
|
|
|
37549
37697
|
return texts;
|
|
37550
37698
|
const itemTexts = [];
|
|
37551
37699
|
for (const value of item.content) {
|
|
37552
|
-
const part =
|
|
37700
|
+
const part = object11(value);
|
|
37553
37701
|
const block = blocks[bound];
|
|
37554
37702
|
if (!block || part?.type !== "output_text" || typeof part.text !== "string")
|
|
37555
37703
|
return texts;
|
|
37556
37704
|
let signature;
|
|
37557
37705
|
try {
|
|
37558
37706
|
if (typeof block.textSignature === "string")
|
|
37559
|
-
signature =
|
|
37707
|
+
signature = object11(JSON.parse(block.textSignature));
|
|
37560
37708
|
} catch {
|
|
37561
37709
|
return texts;
|
|
37562
37710
|
}
|
|
@@ -37596,7 +37744,7 @@ function piResponsesWireTexts(value, phase) {
|
|
|
37596
37744
|
const texts = [];
|
|
37597
37745
|
let units = 0;
|
|
37598
37746
|
for (const partValue of value) {
|
|
37599
|
-
const part =
|
|
37747
|
+
const part = object11(partValue);
|
|
37600
37748
|
if (part?.type !== "output_text" || typeof part.text !== "string")
|
|
37601
37749
|
return;
|
|
37602
37750
|
units += part.text.length;
|
|
@@ -37635,11 +37783,11 @@ var TRANSFORM_MESSAGES_APIS = new Set([
|
|
|
37635
37783
|
"devin-agent",
|
|
37636
37784
|
"apple-foundation-models"
|
|
37637
37785
|
]);
|
|
37638
|
-
function
|
|
37786
|
+
function object12(value) {
|
|
37639
37787
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
37640
37788
|
}
|
|
37641
37789
|
function messageStructure(value) {
|
|
37642
|
-
const message =
|
|
37790
|
+
const message = object12(value);
|
|
37643
37791
|
if (!message)
|
|
37644
37792
|
return;
|
|
37645
37793
|
const role = [
|
|
@@ -37668,7 +37816,7 @@ function messageStructure(value) {
|
|
|
37668
37816
|
}
|
|
37669
37817
|
if (role === "assistant" && Array.isArray(message.content)) {
|
|
37670
37818
|
for (const value of message.content) {
|
|
37671
|
-
const block =
|
|
37819
|
+
const block = object12(value);
|
|
37672
37820
|
if (block?.type !== "toolCall" && block?.type !== "tool_use")
|
|
37673
37821
|
continue;
|
|
37674
37822
|
if (typeof block.id !== "string")
|
|
@@ -37684,7 +37832,7 @@ function windowCalls(message) {
|
|
|
37684
37832
|
if (!Array.isArray(message.content))
|
|
37685
37833
|
return [];
|
|
37686
37834
|
return message.content.flatMap((value) => {
|
|
37687
|
-
const block =
|
|
37835
|
+
const block = object12(value);
|
|
37688
37836
|
return block?.type === "toolCall" && typeof block.id === "string" ? [
|
|
37689
37837
|
{
|
|
37690
37838
|
id: block.id,
|
|
@@ -37694,7 +37842,7 @@ function windowCalls(message) {
|
|
|
37694
37842
|
});
|
|
37695
37843
|
}
|
|
37696
37844
|
function duplicateSuffix(model) {
|
|
37697
|
-
const compat =
|
|
37845
|
+
const compat = object12(model?.compat);
|
|
37698
37846
|
if (model?.api === "openai-completions") {
|
|
37699
37847
|
if (compat?.requiresMistralToolIds === true)
|
|
37700
37848
|
return { prefix: "dup", max: 9 };
|
|
@@ -37711,7 +37859,7 @@ function appendDuplicateSuffix(id, suffix, max) {
|
|
|
37711
37859
|
}
|
|
37712
37860
|
function projectMissingToolResults(messages, model, host = "omp") {
|
|
37713
37861
|
const input = messages.filter((value) => {
|
|
37714
|
-
const message =
|
|
37862
|
+
const message = object12(value);
|
|
37715
37863
|
return !((message?.role === "bashExecution" || message?.role === "pythonExecution") && message.excludeFromContext === true);
|
|
37716
37864
|
});
|
|
37717
37865
|
if (host === "pi")
|
|
@@ -37726,7 +37874,7 @@ function projectMissingToolResults(messages, model, host = "omp") {
|
|
|
37726
37874
|
const realResults = new Map;
|
|
37727
37875
|
const validToolUseIds = new Set;
|
|
37728
37876
|
const deduplicated = input.map((value, index) => {
|
|
37729
|
-
const message =
|
|
37877
|
+
const message = object12(value);
|
|
37730
37878
|
if (message?.role === "toolResult" && typeof message.toolCallId === "string") {
|
|
37731
37879
|
let key = pairingId(message.toolCallId);
|
|
37732
37880
|
let output = value;
|
|
@@ -37753,7 +37901,7 @@ function projectMissingToolResults(messages, model, host = "omp") {
|
|
|
37753
37901
|
const touched = new Set;
|
|
37754
37902
|
let changed = false;
|
|
37755
37903
|
const content = message.content.map((part) => {
|
|
37756
|
-
const block =
|
|
37904
|
+
const block = object12(part);
|
|
37757
37905
|
if (block?.type !== "toolCall" || typeof block.id !== "string")
|
|
37758
37906
|
return part;
|
|
37759
37907
|
const key = pairingId(block.id);
|
|
@@ -37832,7 +37980,7 @@ function projectMissingToolResults(messages, model, host = "omp") {
|
|
|
37832
37980
|
};
|
|
37833
37981
|
for (let index = 0;index < deduplicated.length; index++) {
|
|
37834
37982
|
const value = deduplicated[index];
|
|
37835
|
-
const message =
|
|
37983
|
+
const message = object12(value);
|
|
37836
37984
|
if (message?.role === "assistant") {
|
|
37837
37985
|
flush(message.timestamp);
|
|
37838
37986
|
if (piOmitsTruncatedAssistant(message))
|
|
@@ -37873,7 +38021,7 @@ function projectMissingToolResults(messages, model, host = "omp") {
|
|
|
37873
38021
|
if (pending.some((call) => !answered.has(pairingId(call.id))) || aborted.size > 0)
|
|
37874
38022
|
continue;
|
|
37875
38023
|
const parts = message.content.flatMap((value) => {
|
|
37876
|
-
const part =
|
|
38024
|
+
const part = object12(value);
|
|
37877
38025
|
return part?.type === "text" && typeof part.text === "string" && part.text.trim() ? [part.text] : [];
|
|
37878
38026
|
});
|
|
37879
38027
|
if (!parts.length)
|
|
@@ -37901,11 +38049,11 @@ function projectUnmodeledToolResults(messages) {
|
|
|
37901
38049
|
return pipe > 0 ? id.slice(0, pipe) : id;
|
|
37902
38050
|
};
|
|
37903
38051
|
for (const value of messages) {
|
|
37904
|
-
const message =
|
|
38052
|
+
const message = object12(value);
|
|
37905
38053
|
if (message?.role !== "assistant" || !Array.isArray(message.content))
|
|
37906
38054
|
continue;
|
|
37907
38055
|
for (const value of message.content) {
|
|
37908
|
-
const block =
|
|
38056
|
+
const block = object12(value);
|
|
37909
38057
|
if (block?.type !== "toolCall" || typeof block.id !== "string")
|
|
37910
38058
|
continue;
|
|
37911
38059
|
if ([
|
|
@@ -37921,7 +38069,7 @@ function projectUnmodeledToolResults(messages) {
|
|
|
37921
38069
|
const pairingId = (id) => !opaqueIds.has(id) && responsesComponents.has(component(id)) ? component(id) : id;
|
|
37922
38070
|
const lastResult = new Map;
|
|
37923
38071
|
messages.forEach((value, index) => {
|
|
37924
|
-
const message =
|
|
38072
|
+
const message = object12(value);
|
|
37925
38073
|
if (message?.role === "toolResult" && typeof message.toolCallId === "string")
|
|
37926
38074
|
lastResult.set(pairingId(message.toolCallId), index);
|
|
37927
38075
|
});
|
|
@@ -37952,7 +38100,7 @@ function projectUnmodeledToolResults(messages) {
|
|
|
37952
38100
|
};
|
|
37953
38101
|
for (let index = 0;index < messages.length; index++) {
|
|
37954
38102
|
const value = messages[index];
|
|
37955
|
-
const message =
|
|
38103
|
+
const message = object12(value);
|
|
37956
38104
|
if ((message?.role === "bashExecution" || message?.role === "pythonExecution") && message.excludeFromContext === true)
|
|
37957
38105
|
continue;
|
|
37958
38106
|
if (message?.role !== "toolResult")
|
|
@@ -37994,7 +38142,7 @@ function projectPiToolResults(messages) {
|
|
|
37994
38142
|
held.length = 0;
|
|
37995
38143
|
};
|
|
37996
38144
|
for (const value of messages) {
|
|
37997
|
-
const message =
|
|
38145
|
+
const message = object12(value);
|
|
37998
38146
|
const role = message?.role;
|
|
37999
38147
|
if (role === "assistant") {
|
|
38000
38148
|
close(message?.timestamp);
|
|
@@ -38025,7 +38173,7 @@ function projectPiToolResults(messages) {
|
|
|
38025
38173
|
function preparePiDispatch(messages, model, omp, cwd) {
|
|
38026
38174
|
let output = messages;
|
|
38027
38175
|
const structure = buildPiPreparedStructure(messages, model, omp ? (index, source) => {
|
|
38028
|
-
if (
|
|
38176
|
+
if (object12(source.providerPayload)?.type !== "openaiResponsesHistory")
|
|
38029
38177
|
return;
|
|
38030
38178
|
if (output === messages)
|
|
38031
38179
|
output = messages.slice();
|
|
@@ -38041,7 +38189,7 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
38041
38189
|
if (!messages.length || messages.length > MAX_MESSAGES)
|
|
38042
38190
|
return;
|
|
38043
38191
|
for (let index = 0;index < messages.length; index++) {
|
|
38044
|
-
const source =
|
|
38192
|
+
const source = object12(messages[index]);
|
|
38045
38193
|
if (source?.role === "user" || source?.role === "compactionSummary")
|
|
38046
38194
|
prepareUser?.(index, source);
|
|
38047
38195
|
}
|
|
@@ -38058,7 +38206,7 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
38058
38206
|
let valid = true;
|
|
38059
38207
|
for (let index = 0;index < projectedMessages.length; index++) {
|
|
38060
38208
|
const message = projectedMessages[index];
|
|
38061
|
-
const source =
|
|
38209
|
+
const source = object12(message);
|
|
38062
38210
|
if (rows.length === 0 && (source?.role === "system" || source?.role === "developer"))
|
|
38063
38211
|
continue;
|
|
38064
38212
|
if ((source?.role === "bashExecution" || source?.role === "pythonExecution") && source.excludeFromContext === true)
|
|
@@ -38082,7 +38230,7 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
38082
38230
|
"azure-openai-responses",
|
|
38083
38231
|
"openai-codex-responses"
|
|
38084
38232
|
].includes(model?.api ?? "") && (source?.role === "user" || source?.role === "developer") && (typeof source.content === "string" ? !source.content.trim() : Array.isArray(source.content) && !source.content.some((value) => {
|
|
38085
|
-
const block =
|
|
38233
|
+
const block = object12(value);
|
|
38086
38234
|
return block?.type === "image" || block?.type === "text" && typeof block.text === "string" && block.text.trim();
|
|
38087
38235
|
})))
|
|
38088
38236
|
continue;
|
|
@@ -38126,12 +38274,12 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
38126
38274
|
const positionedRows = [...byIndex];
|
|
38127
38275
|
for (let position = positionedRows.length - 1;position >= 0; position--) {
|
|
38128
38276
|
const [index, row] = positionedRows[position];
|
|
38129
|
-
const source =
|
|
38277
|
+
const source = object12(projectedMessages[index]);
|
|
38130
38278
|
if (!source)
|
|
38131
38279
|
return;
|
|
38132
38280
|
const content = source.content;
|
|
38133
38281
|
const parts = typeof content === "string" ? [{ type: "text", text: content }] : content;
|
|
38134
|
-
const textOnly = Array.isArray(parts) && parts.every((part) =>
|
|
38282
|
+
const textOnly = Array.isArray(parts) && parts.every((part) => object12(part)?.type === "text" && typeof object12(part)?.text === "string");
|
|
38135
38283
|
const systemTexts = () => {
|
|
38136
38284
|
const texts = parts.map((part) => part.text);
|
|
38137
38285
|
return model?.api === "anthropic-messages" ? texts.filter((text) => text.trim()).map((text) => new TextDecoder().decode(new TextEncoder().encode(text))) : texts;
|
|
@@ -38139,7 +38287,7 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
38139
38287
|
if (piIsDeveloperHistory(source) && source.attribution !== "user") {
|
|
38140
38288
|
const previous = rows[position - 1];
|
|
38141
38289
|
const next = rows[position + 1];
|
|
38142
|
-
const anthropicPromotable = model?.api === "anthropic-messages" &&
|
|
38290
|
+
const anthropicPromotable = model?.api === "anthropic-messages" && object12(model.compat)?.supportsMidConversationSystem === true && textOnly;
|
|
38143
38291
|
if (anthropicPromotable)
|
|
38144
38292
|
promotable.set(row, systemTexts());
|
|
38145
38293
|
if (model?.api === "ollama-chat" || anthropicPromotable && (previous?.role === "user" || previous?.role === "toolResult") && (!next || next.role === "assistant"))
|
|
@@ -38193,7 +38341,7 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
38193
38341
|
continue;
|
|
38194
38342
|
}
|
|
38195
38343
|
const alternatives = {};
|
|
38196
|
-
const texts = piResponsesAssistantTexts(projectedMessages[index], model, host, alternatives,
|
|
38344
|
+
const texts = piResponsesAssistantTexts(projectedMessages[index], model, host, alternatives, object12(projectedMessages[index])?.[PI_NATIVE_TAG_STRIP_PROVENANCE]);
|
|
38197
38345
|
if (!texts) {
|
|
38198
38346
|
responsesMessages = undefined;
|
|
38199
38347
|
break;
|
|
@@ -38241,15 +38389,15 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
38241
38389
|
...modelsContinuePad ? { anthropicContinuePad: true } : {},
|
|
38242
38390
|
...modelsContinuePad && baseRows.some((row) => row.optionalThinking) ? { anthropicOptional: { rows: baseRows, promotable } } : {},
|
|
38243
38391
|
...model?.api?.startsWith("google-") ? {
|
|
38244
|
-
googleFunctionIds:
|
|
38392
|
+
googleFunctionIds: object12(model.compat)?.supportsFunctionPartId === true
|
|
38245
38393
|
} : {}
|
|
38246
38394
|
};
|
|
38247
38395
|
if (host === "omp" && PI_DATE_REMINDER_APIS.has(model?.api ?? ""))
|
|
38248
38396
|
dateReminderPlans.set(prepared, {
|
|
38249
38397
|
...modelsContinuePad ? { plan: { rows: baseRows, promotable } } : {},
|
|
38250
38398
|
firstUser: firstUserRow ? baseRows.indexOf(firstUserRow) : -1,
|
|
38251
|
-
midConversationSystem:
|
|
38252
|
-
developerRole:
|
|
38399
|
+
midConversationSystem: object12(model?.compat)?.supportsMidConversationSystem === true,
|
|
38400
|
+
developerRole: object12(model?.compat)?.supportsDeveloperRole === true
|
|
38253
38401
|
});
|
|
38254
38402
|
return prepared;
|
|
38255
38403
|
}
|
|
@@ -38261,7 +38409,7 @@ function responsesLane(api) {
|
|
|
38261
38409
|
].includes(api ?? "");
|
|
38262
38410
|
}
|
|
38263
38411
|
function payloadStructure(payload, ollama = false, responsesItems = false, imageProjection = false) {
|
|
38264
|
-
const body =
|
|
38412
|
+
const body = object12(payload);
|
|
38265
38413
|
if (!body)
|
|
38266
38414
|
return;
|
|
38267
38415
|
const google = piGoogleConversation(payload);
|
|
@@ -38276,12 +38424,12 @@ function payloadStructure(payload, ollama = false, responsesItems = false, image
|
|
|
38276
38424
|
return;
|
|
38277
38425
|
const rows = [];
|
|
38278
38426
|
for (const value of messages) {
|
|
38279
|
-
const message =
|
|
38427
|
+
const message = object12(value);
|
|
38280
38428
|
if (!message)
|
|
38281
38429
|
return;
|
|
38282
38430
|
if (rows.length === 0 && (message.role === "system" || message.role === "developer"))
|
|
38283
38431
|
continue;
|
|
38284
|
-
if (message.role === "system" && Array.isArray(message.content) && message.content.every((block) => ["tool_addition", "tool_removal"].includes(String(
|
|
38432
|
+
if (message.role === "system" && Array.isArray(message.content) && message.content.every((block) => ["tool_addition", "tool_removal"].includes(String(object12(block)?.type))))
|
|
38285
38433
|
continue;
|
|
38286
38434
|
if (responses && message.type === "reasoning")
|
|
38287
38435
|
continue;
|
|
@@ -38338,7 +38486,7 @@ function payloadStructure(payload, ollama = false, responsesItems = false, image
|
|
|
38338
38486
|
continue;
|
|
38339
38487
|
}
|
|
38340
38488
|
if (message.role === "user" && Array.isArray(message.content)) {
|
|
38341
|
-
const results = message.content.filter((block) =>
|
|
38489
|
+
const results = message.content.filter((block) => object12(block)?.type === "tool_result" || bedrock && object12(block)?.toolResult);
|
|
38342
38490
|
if (results.length) {
|
|
38343
38491
|
for (const block of results) {
|
|
38344
38492
|
const id = bedrock ? block.toolResult?.toolUseId : block.tool_use_id;
|
|
@@ -38385,11 +38533,11 @@ function payloadStructure(payload, ollama = false, responsesItems = false, image
|
|
|
38385
38533
|
}
|
|
38386
38534
|
if (Array.isArray(message.tool_calls)) {
|
|
38387
38535
|
for (const call of message.tool_calls) {
|
|
38388
|
-
const source =
|
|
38536
|
+
const source = object12(call);
|
|
38389
38537
|
if (!source)
|
|
38390
38538
|
return;
|
|
38391
38539
|
if (source.id === undefined && ollama) {
|
|
38392
|
-
const fn =
|
|
38540
|
+
const fn = object12(source.function);
|
|
38393
38541
|
if (typeof fn?.name !== "string")
|
|
38394
38542
|
return;
|
|
38395
38543
|
row.calls.push("");
|
|
@@ -38425,7 +38573,7 @@ function googleStructure(contents, imageProjection = false) {
|
|
|
38425
38573
|
return;
|
|
38426
38574
|
const rows = [];
|
|
38427
38575
|
for (const value of contents) {
|
|
38428
|
-
const message =
|
|
38576
|
+
const message = object12(value);
|
|
38429
38577
|
if (!message || !Array.isArray(message.parts))
|
|
38430
38578
|
return;
|
|
38431
38579
|
if (message.role !== "user" && message.role !== "model")
|
|
@@ -38440,11 +38588,11 @@ function googleStructure(contents, imageProjection = false) {
|
|
|
38440
38588
|
};
|
|
38441
38589
|
const results = [];
|
|
38442
38590
|
for (const value of message.parts) {
|
|
38443
|
-
const part =
|
|
38591
|
+
const part = object12(value);
|
|
38444
38592
|
if (!part)
|
|
38445
38593
|
return;
|
|
38446
38594
|
if (part.functionCall) {
|
|
38447
|
-
const call =
|
|
38595
|
+
const call = object12(part.functionCall);
|
|
38448
38596
|
if (row.role !== "assistant" || typeof call?.name !== "string" || call.id !== undefined && typeof call.id !== "string")
|
|
38449
38597
|
return;
|
|
38450
38598
|
row.calls.push(call.id ?? "");
|
|
@@ -38452,7 +38600,7 @@ function googleStructure(contents, imageProjection = false) {
|
|
|
38452
38600
|
row.callNames.push(call.name);
|
|
38453
38601
|
}
|
|
38454
38602
|
if (part.functionResponse) {
|
|
38455
|
-
const result =
|
|
38603
|
+
const result = object12(part.functionResponse);
|
|
38456
38604
|
if (row.role !== "user" || typeof result?.name !== "string" || result.id !== undefined && typeof result.id !== "string")
|
|
38457
38605
|
return;
|
|
38458
38606
|
results.push({
|
|
@@ -38486,11 +38634,11 @@ function matchesUserText(content, text, api, responses, googleOrBedrock) {
|
|
|
38486
38634
|
if (responses || googleOrBedrock) {
|
|
38487
38635
|
if (!Array.isArray(content) || content.length !== 1)
|
|
38488
38636
|
return false;
|
|
38489
|
-
const block =
|
|
38637
|
+
const block = object12(content[0]);
|
|
38490
38638
|
return !!block && block.text === text && (responses ? block.type === "input_text" : Object.keys(block).length === 1);
|
|
38491
38639
|
}
|
|
38492
38640
|
if ((api === "anthropic-messages" || api === "factory-droid-agent") && Array.isArray(content)) {
|
|
38493
|
-
const block = content.length === 1 ?
|
|
38641
|
+
const block = content.length === 1 ? object12(content[0]) : undefined;
|
|
38494
38642
|
return block?.type === "text" && block.text === text;
|
|
38495
38643
|
}
|
|
38496
38644
|
return content === text;
|
|
@@ -38624,15 +38772,15 @@ function countAnthropicOptionalAlignments(plan, base, wire, compare, reminders,
|
|
|
38624
38772
|
function piPreparedStructureMismatch(payload, prepared, onImageTrim) {
|
|
38625
38773
|
const plan = prepared && dateReminderPlans.get(prepared);
|
|
38626
38774
|
try {
|
|
38627
|
-
const body = plan ?
|
|
38775
|
+
const body = plan ? object12(payload) : undefined;
|
|
38628
38776
|
const messages = body?.messages ?? body?.input;
|
|
38629
38777
|
if (Array.isArray(messages)) {
|
|
38630
38778
|
for (const value of messages) {
|
|
38631
|
-
const message =
|
|
38779
|
+
const message = object12(value);
|
|
38632
38780
|
if (message?.role !== "system" && message?.role !== "developer")
|
|
38633
38781
|
break;
|
|
38634
38782
|
const content = message.content;
|
|
38635
|
-
const inputText = Array.isArray(content) && content.length === 1 &&
|
|
38783
|
+
const inputText = Array.isArray(content) && content.length === 1 && object12(content[0])?.type === "input_text" ? object12(content[0])?.text : undefined;
|
|
38636
38784
|
if (piDateReminderWireText(content, plan?.cwd) !== undefined || piDateReminderText(inputText, plan?.cwd))
|
|
38637
38785
|
return "comparison=role";
|
|
38638
38786
|
}
|
|
@@ -38648,7 +38796,7 @@ function piPreparedStructureMismatch(payload, prepared, onImageTrim) {
|
|
|
38648
38796
|
if (plan.firstUser < 0)
|
|
38649
38797
|
return mismatch;
|
|
38650
38798
|
const root = prepared.messages[plan.firstUser];
|
|
38651
|
-
const body =
|
|
38799
|
+
const body = object12(payload);
|
|
38652
38800
|
const routeRows = Array.isArray(body?.input) ? prepared.responsesMessages ?? prepared.messages : prepared.api === "openai-completions" ? prepared.chatMessages ?? prepared.messages : prepared.messages;
|
|
38653
38801
|
const firstUser = routeRows.indexOf(root);
|
|
38654
38802
|
if (firstUser < 0)
|
|
@@ -38659,11 +38807,11 @@ function piPreparedStructureMismatch(payload, prepared, onImageTrim) {
|
|
|
38659
38807
|
});
|
|
38660
38808
|
return filtered === undefined ? mismatch : preparedStructureMismatch(filtered, prepared, onImageTrim);
|
|
38661
38809
|
}
|
|
38662
|
-
const messages =
|
|
38810
|
+
const messages = object12(payload)?.messages;
|
|
38663
38811
|
if (!Array.isArray(messages))
|
|
38664
38812
|
return mismatch;
|
|
38665
38813
|
for (const value of messages) {
|
|
38666
|
-
const message =
|
|
38814
|
+
const message = object12(value);
|
|
38667
38815
|
if (piDateReminderWireText(message?.content, plan.cwd) !== undefined && Object.keys(message ?? {}).some((key) => !["role", "content"].includes(key)))
|
|
38668
38816
|
return mismatch;
|
|
38669
38817
|
}
|
|
@@ -38703,7 +38851,7 @@ function preparedStructureMismatch(payload, prepared, onImageTrim, reminders, re
|
|
|
38703
38851
|
return "comparison=image count";
|
|
38704
38852
|
const imageProjection = trimmed > 0;
|
|
38705
38853
|
stage = "wire rows";
|
|
38706
|
-
const body =
|
|
38854
|
+
const body = object12(payload);
|
|
38707
38855
|
const ollama = prepared?.api === "ollama-chat" && !!body && Array.isArray(body.messages) && body.input === undefined && body.system === undefined && body.inferenceConfig === undefined;
|
|
38708
38856
|
const responses = body?.messages === undefined && Array.isArray(body?.input);
|
|
38709
38857
|
rows = reminderWire ?? payloadStructure(payload, ollama, responses && !!prepared?.responsesMessages, imageProjection);
|
|
@@ -38730,7 +38878,7 @@ function preparedStructureMismatch(payload, prepared, onImageTrim, reminders, re
|
|
|
38730
38878
|
if (expected.systemText !== undefined) {
|
|
38731
38879
|
const texts = expected.systemText;
|
|
38732
38880
|
const content = actual.wireContent;
|
|
38733
|
-
const actualTexts = typeof content === "string" ? [content] : Array.isArray(content) && content.every((part) =>
|
|
38881
|
+
const actualTexts = typeof content === "string" ? [content] : Array.isArray(content) && content.every((part) => object12(part)?.type === "text" && typeof object12(part)?.text === "string") ? content.map((part) => part.text) : undefined;
|
|
38734
38882
|
if (!actualTexts || (typeof content === "string" ? content !== texts.join(`
|
|
38735
38883
|
`) : JSON.stringify(actualTexts) !== JSON.stringify(texts)))
|
|
38736
38884
|
return "content";
|
|
@@ -40137,6 +40285,7 @@ function releasePiOperationPayloads(operation) {
|
|
|
40137
40285
|
operation.dispatchFields = undefined;
|
|
40138
40286
|
operation.chainDispatchFields = undefined;
|
|
40139
40287
|
operation.managedSignature = undefined;
|
|
40288
|
+
operation.cursorRoots = undefined;
|
|
40140
40289
|
operation.preparedStructure = undefined;
|
|
40141
40290
|
operation.preparedHistory = undefined;
|
|
40142
40291
|
}
|
|
@@ -40277,10 +40426,10 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40277
40426
|
receiptMaps.add(imageTrimNotices);
|
|
40278
40427
|
const chains = new Map;
|
|
40279
40428
|
receiptMaps.add(chains);
|
|
40280
|
-
const refuse = (ctx, budget, reason, isCurrent) => {
|
|
40429
|
+
const refuse = (ctx, budget, reason, isCurrent, abort = true) => {
|
|
40281
40430
|
if (!isCurrent()) {
|
|
40282
40431
|
log2(`[magic-context][pi] DISCARDED CONTEXT RESULT ${budget.diagnostic()}`, reason);
|
|
40283
|
-
return;
|
|
40432
|
+
return RETRY_MESSAGE;
|
|
40284
40433
|
}
|
|
40285
40434
|
budget.abandoned = true;
|
|
40286
40435
|
budget.recovery = budget.recovery === "not attempted" ? "no managed result; refused" : budget.recovery;
|
|
@@ -40297,7 +40446,7 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40297
40446
|
} catch (error) {
|
|
40298
40447
|
log2("[magic-context][pi] refusal entry failed", error);
|
|
40299
40448
|
} finally {
|
|
40300
|
-
if (!budget.sideTurn)
|
|
40449
|
+
if (abort && !budget.sideTurn)
|
|
40301
40450
|
ctx.abort();
|
|
40302
40451
|
}
|
|
40303
40452
|
try {
|
|
@@ -40305,6 +40454,7 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40305
40454
|
} catch (error) {
|
|
40306
40455
|
log2("[magic-context][pi] refusal diagnostic failed", error);
|
|
40307
40456
|
}
|
|
40457
|
+
return message;
|
|
40308
40458
|
};
|
|
40309
40459
|
if (fenceEnabled) {
|
|
40310
40460
|
pi.on("agent_start", (_event, ctx) => {
|
|
@@ -40357,7 +40507,7 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40357
40507
|
cancelledOperation?.pass?.cancel();
|
|
40358
40508
|
if (cancelledOperation)
|
|
40359
40509
|
cancelledOperation.ready = false;
|
|
40360
|
-
return;
|
|
40510
|
+
return piRefusedPayload("Magic Context request cancelled before provider dispatch.");
|
|
40361
40511
|
}
|
|
40362
40512
|
if (options.compactionOff?.(ctx)) {
|
|
40363
40513
|
chains.delete(operationKey(ctx));
|
|
@@ -40369,12 +40519,19 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40369
40519
|
return;
|
|
40370
40520
|
const nonces = unsendableNonces.get(key);
|
|
40371
40521
|
if (nonces?.size) {
|
|
40372
|
-
|
|
40522
|
+
let serializedPayload;
|
|
40523
|
+
try {
|
|
40524
|
+
serializedPayload = JSON.stringify(payload);
|
|
40525
|
+
} catch {
|
|
40526
|
+
const budget = new PiContextBudget;
|
|
40527
|
+
budget.stage = "provider dispatch";
|
|
40528
|
+
return piRefusedPayload(refuse(ctx, budget, `provider payload could not be inspected; ${piDispatchShape(payload, ctx.model?.api)}`, () => true, false));
|
|
40529
|
+
}
|
|
40373
40530
|
if (serializedPayload && [...nonces].some((nonce) => serializedPayload.includes(nonce))) {
|
|
40374
40531
|
const budget = new PiContextBudget;
|
|
40375
40532
|
budget.stage = "provider dispatch";
|
|
40376
|
-
refuse(ctx, budget,
|
|
40377
|
-
return;
|
|
40533
|
+
const message = refuse(ctx, budget, `superseded context fallback is not a managed request; ${piDispatchShape(payload, ctx.model?.api)}`, () => true, false);
|
|
40534
|
+
return piRefusedPayload(message);
|
|
40378
40535
|
}
|
|
40379
40536
|
}
|
|
40380
40537
|
if (isOmpAdvisorRequest(payload))
|
|
@@ -40389,8 +40546,7 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40389
40546
|
const capture = isOmpUnmanagedCaptureRequest(payload);
|
|
40390
40547
|
const budget = (capture ? undefined : active.pass) ?? new PiContextBudget;
|
|
40391
40548
|
if (active.refused && active.pass === budget) {
|
|
40392
|
-
|
|
40393
|
-
return;
|
|
40549
|
+
return piRefusedPayload(active.refusalMessage ?? RETRY_MESSAGE);
|
|
40394
40550
|
}
|
|
40395
40551
|
let refusalOrigin;
|
|
40396
40552
|
try {
|
|
@@ -40419,13 +40575,13 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40419
40575
|
checked = expanded.payload;
|
|
40420
40576
|
chainInput = expanded.input;
|
|
40421
40577
|
}
|
|
40422
|
-
if (!piHasManagedSignature(checked, active.managedSignature))
|
|
40423
|
-
throw new Error("provider request does not match this pass's managed dispatch (missing current receipt signature)");
|
|
40578
|
+
if (!piHasManagedSignature(checked, active.managedSignature, active.cursorRoots))
|
|
40579
|
+
throw new Error(ctx.model?.api === "cursor-agent" ? "provider request does not match this pass's managed dispatch (Cursor root hash did not match and active message has no current receipt signature)" : "provider request does not match this pass's managed dispatch (missing current receipt signature)");
|
|
40424
40580
|
const fields = piConversationFields(payload);
|
|
40425
40581
|
if (!fields)
|
|
40426
40582
|
throw new Error("provider conversation identity could not be established");
|
|
40427
40583
|
const body = checked;
|
|
40428
|
-
const skipReason = active.preparedStructure ? active.preparedStructure.structuralSkipReason ?? (active.preparedStructure.api && body?.messages === undefined && Array.isArray(body?.input) && !active.preparedStructure.responsesMessages ? "provider selected Responses items without a matching history plan" : undefined) : "prepared history representation is not modeled";
|
|
40584
|
+
const skipReason = piCursorConversation(checked) ? "Cursor history blob IDs do not expose prepared turn structure" : active.preparedStructure ? active.preparedStructure.structuralSkipReason ?? (active.preparedStructure.api && body?.messages === undefined && Array.isArray(body?.input) && !active.preparedStructure.responsesMessages ? "provider selected Responses items without a matching history plan" : undefined) : "prepared history representation is not modeled";
|
|
40429
40585
|
if (chained && skipReason)
|
|
40430
40586
|
throw new Error("provider request does not match this pass's managed dispatch (chained continuation requires a modeled prepared history)");
|
|
40431
40587
|
if (skipReason && !structureWarnings.has(key)) {
|
|
@@ -40469,14 +40625,22 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40469
40625
|
if (signal ? signal.aborted : budget.isCancelled(error)) {
|
|
40470
40626
|
budget.cancel();
|
|
40471
40627
|
active.ready = false;
|
|
40472
|
-
return;
|
|
40628
|
+
return piRefusedPayload("Magic Context request cancelled before provider dispatch.");
|
|
40473
40629
|
}
|
|
40474
40630
|
active.refused = true;
|
|
40475
40631
|
budget.stage = refusalOrigin ? `provider dispatch (origin=${refusalOrigin}; context stage=${budget.stage})` : "provider dispatch";
|
|
40476
|
-
|
|
40632
|
+
const reason = new Error(`${error instanceof Error ? error.message : String(error)}; ${piDispatchShape(payload, ctx.model?.api)}`);
|
|
40633
|
+
active.refusalMessage = refuse(ctx, budget, reason, isCurrent, false);
|
|
40634
|
+
return piRefusedPayload(active.refusalMessage);
|
|
40477
40635
|
}
|
|
40478
40636
|
});
|
|
40479
40637
|
}
|
|
40638
|
+
if (!fenceEnabled) {
|
|
40639
|
+
pi.on("before_provider_request", (_event, ctx) => {
|
|
40640
|
+
const operation = operations.get(operationKey(ctx));
|
|
40641
|
+
return operation?.refused ? piRefusedPayload(operation.refusalMessage ?? RETRY_MESSAGE) : undefined;
|
|
40642
|
+
});
|
|
40643
|
+
}
|
|
40480
40644
|
pi.registerEntryRenderer?.(ENTRY_TYPE, (entry) => new Text2(entry.data?.message ?? RETRY_MESSAGE, 0, 0));
|
|
40481
40645
|
pi.on("context", async (event, ctx) => {
|
|
40482
40646
|
if (fenceEnabled && isOmpDumpContext())
|
|
@@ -40509,6 +40673,7 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40509
40673
|
active.dispatched = false;
|
|
40510
40674
|
active.ready = false;
|
|
40511
40675
|
active.refused = false;
|
|
40676
|
+
active.refusalMessage = undefined;
|
|
40512
40677
|
const { isOwned, isCurrent, assertOwner } = createPiContextOwnershipGuards(operations, key, active, budget, owner);
|
|
40513
40678
|
budget.assertOwner = assertOwner;
|
|
40514
40679
|
try {
|
|
@@ -40525,6 +40690,8 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40525
40690
|
if (prepared.messages !== result.messages)
|
|
40526
40691
|
result.messages = prepared.messages;
|
|
40527
40692
|
active.managedSignature = piManagedSignature(result.messages);
|
|
40693
|
+
if (ctx.model?.api === "cursor-agent")
|
|
40694
|
+
active.cursorRoots = piCursorManagedRoots(result.messages, active.managedSignature, ctx.cwd);
|
|
40528
40695
|
active.preparedStructure = prepared.structure;
|
|
40529
40696
|
if (fenceEnabled && !budget.sideTurn && piChainCapableApi(ctx.model?.api))
|
|
40530
40697
|
active.preparedHistory = piPreparedHistory(result.messages, ctx.model);
|
|
@@ -40576,7 +40743,7 @@ function registerPiGuardedContext(pi, handler, options = {}) {
|
|
|
40576
40743
|
throw error;
|
|
40577
40744
|
}
|
|
40578
40745
|
active.refused = true;
|
|
40579
|
-
refuse(ctx, budget, error, isOwned);
|
|
40746
|
+
active.refusalMessage = refuse(ctx, budget, error, isOwned);
|
|
40580
40747
|
return { messages: event.messages };
|
|
40581
40748
|
} finally {
|
|
40582
40749
|
if (!fenceEnabled || budget.sideTurn)
|
|
@@ -40700,7 +40867,7 @@ function createPiFallbackIndex() {
|
|
|
40700
40867
|
}
|
|
40701
40868
|
|
|
40702
40869
|
// src/pi-fit-reclaim.ts
|
|
40703
|
-
import { createHash as
|
|
40870
|
+
import { createHash as createHash15, randomUUID as randomUUID4 } from "node:crypto";
|
|
40704
40871
|
var pendingInput = new Set;
|
|
40705
40872
|
var KEY3 = "piUpperEstimateReclaim";
|
|
40706
40873
|
function piFitOverflowPossible(args) {
|
|
@@ -40736,7 +40903,7 @@ function piUpperReclaimCursor(args) {
|
|
|
40736
40903
|
sessionId: args.sessionId,
|
|
40737
40904
|
modelKey: args.modelKey,
|
|
40738
40905
|
contextWindow: args.contextWindow ?? null,
|
|
40739
|
-
head: head ?
|
|
40906
|
+
head: head ? createHash15("sha256").update(JSON.stringify([
|
|
40740
40907
|
Buffer.from(head.cachedM0Bytes ?? []).toString("base64"),
|
|
40741
40908
|
Buffer.from(head.cachedM1Bytes ?? []).toString("base64"),
|
|
40742
40909
|
head.cachedM0MuralDataUrl ?? null
|
|
@@ -40823,7 +40990,7 @@ async function waitForPiHistorianInTurn(sessionId, remainingMs, wait) {
|
|
|
40823
40990
|
}
|
|
40824
40991
|
|
|
40825
40992
|
// src/pi-lkg-fit-envelope.ts
|
|
40826
|
-
import { createHash as
|
|
40993
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
40827
40994
|
function readPiLkgFitEnvelope(ctx, pi, modelKey, frozen, wireSchema) {
|
|
40828
40995
|
try {
|
|
40829
40996
|
if (!modelKey || typeof pi.getAllTools !== "function")
|
|
@@ -40885,7 +41052,7 @@ function readPiLkgFitEnvelope(ctx, pi, modelKey, frozen, wireSchema) {
|
|
|
40885
41052
|
refusalToolDefinitionTokens,
|
|
40886
41053
|
toolDefinitionsMeasured: refusalToolDefinitionTokens !== undefined,
|
|
40887
41054
|
envelopeBytes: Buffer.byteLength(envelopeJson),
|
|
40888
|
-
envelopeSignature: activeNames ?
|
|
41055
|
+
envelopeSignature: activeNames ? createHash16("sha256").update(envelopeJson).update(JSON.stringify(activeNames)).digest("hex") : undefined,
|
|
40889
41056
|
calibration
|
|
40890
41057
|
};
|
|
40891
41058
|
} catch {
|
|
@@ -40894,13 +41061,13 @@ function readPiLkgFitEnvelope(ctx, pi, modelKey, frozen, wireSchema) {
|
|
|
40894
41061
|
}
|
|
40895
41062
|
|
|
40896
41063
|
// src/pi-message-identity.ts
|
|
40897
|
-
import { createHash as
|
|
41064
|
+
import { createHash as createHash19 } from "node:crypto";
|
|
40898
41065
|
|
|
40899
41066
|
// src/pi-tool-identity.ts
|
|
40900
|
-
import { createHash as
|
|
41067
|
+
import { createHash as createHash18 } from "node:crypto";
|
|
40901
41068
|
|
|
40902
41069
|
// src/served-array-ledger.ts
|
|
40903
|
-
import { createHash as
|
|
41070
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
40904
41071
|
import {
|
|
40905
41072
|
closeSync as closeSync2,
|
|
40906
41073
|
fstatSync,
|
|
@@ -41178,7 +41345,7 @@ function getPiLastServedArray(sessionId) {
|
|
|
41178
41345
|
return previous ? `[${previous.serializedMessages.join(",")}]` : undefined;
|
|
41179
41346
|
}
|
|
41180
41347
|
function sha256(value) {
|
|
41181
|
-
return
|
|
41348
|
+
return createHash17("sha256").update(value).digest("hex");
|
|
41182
41349
|
}
|
|
41183
41350
|
function safeSessionFileStem(sessionId) {
|
|
41184
41351
|
const readable = sessionId.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 96);
|
|
@@ -41463,7 +41630,7 @@ function readPiServedCachedArray(sessionId) {
|
|
|
41463
41630
|
const memory = getPiLastServedArray(sessionId);
|
|
41464
41631
|
const slot = memory === undefined ? getSlot(sessionId) : undefined;
|
|
41465
41632
|
const jsonPrefix = memory ?? slot?.jsonPrefix;
|
|
41466
|
-
if (jsonPrefix === undefined ||
|
|
41633
|
+
if (jsonPrefix === undefined || createHash18("sha256").update(jsonPrefix).digest("hex") !== getPiLastServedDigest(sessionId))
|
|
41467
41634
|
return;
|
|
41468
41635
|
let parsed;
|
|
41469
41636
|
try {
|
|
@@ -41487,7 +41654,7 @@ function piMessageEntryFingerprint(message) {
|
|
|
41487
41654
|
const m = message;
|
|
41488
41655
|
if (typeof m.role !== "string")
|
|
41489
41656
|
return null;
|
|
41490
|
-
const contentHash =
|
|
41657
|
+
const contentHash = createHash19("sha256").update(stableStringify(m.content)).digest("hex");
|
|
41491
41658
|
return JSON.stringify([
|
|
41492
41659
|
typeof m.responseId === "string" ? m.responseId : null,
|
|
41493
41660
|
typeof m.timestamp === "number" || typeof m.timestamp === "string" ? m.timestamp : null,
|
|
@@ -43342,8 +43509,7 @@ function processSystemPromptForCache(args) {
|
|
|
43342
43509
|
const stableCandidate = dates.stable;
|
|
43343
43510
|
const stableCandidateHash = systemPromptFingerprint(stableCandidate, args.promptSurfacePreset);
|
|
43344
43511
|
const contentOrPresetChanged = !isFirstHash && stableCandidateHash !== previousHash;
|
|
43345
|
-
const
|
|
43346
|
-
const dateMayAdvance = isCacheBusting || idleCacheExpired || contentOrPresetChanged;
|
|
43512
|
+
const dateMayAdvance = isCacheBusting || contentOrPresetChanged;
|
|
43347
43513
|
if (liveDate && !stickyDate) {
|
|
43348
43514
|
stickyDateBySession.set(sessionId, liveDate);
|
|
43349
43515
|
} else if (liveDate && stickyDate && liveDate !== stickyDate) {
|
|
@@ -47652,7 +47818,6 @@ Historian previously failed ${failureCount} time(s), so Magic Context is retryin
|
|
|
47652
47818
|
permission: {
|
|
47653
47819
|
signedThinkingHold: args.signedThinkingHeld === true,
|
|
47654
47820
|
firstRender: false,
|
|
47655
|
-
idleExpiry: false,
|
|
47656
47821
|
emergency: usage.percentage >= historianForceMaterializationPercentage
|
|
47657
47822
|
}
|
|
47658
47823
|
}, args.eligiblePendingDropTagIds, args.primaryExecute === true);
|
|
@@ -48160,12 +48325,11 @@ async function runPipeline(args) {
|
|
|
48160
48325
|
}
|
|
48161
48326
|
const routinePressureAlreadyApplied = !args.sessionMeta.isSubagent && executePressureEligible && routinePressureAppliedBySession.get(args.sessionId) === true;
|
|
48162
48327
|
let hasPendingMaterializeSignal = !protectedSignedPrefix && hasPendingMaterialization(args.sessionId);
|
|
48163
|
-
const heldIdleExpiryRebuild = protectedSignedPrefix && piHardSignals?.cacheExpired === true;
|
|
48164
48328
|
const systemPrefixChangedThisPass = !prefixPreflightContended && effectiveSystemChangedThisPass;
|
|
48165
48329
|
const rideSignals = {
|
|
48166
48330
|
executeReclaim: false,
|
|
48167
48331
|
subagentExecute: args.sessionMeta.isSubagent && args.schedulerDecision === "execute",
|
|
48168
|
-
hardFold: foldBustsServedPrefixThisPass || systemPrefixChangedThisPass || firstRenderBust ||
|
|
48332
|
+
hardFold: foldBustsServedPrefixThisPass || systemPrefixChangedThisPass || firstRenderBust || isCacheBustingPass,
|
|
48169
48333
|
force: (args.forceMaterialization === true || emergencyDropEligible) && (args.contextUsage.percentage >= 95 || getEmergencyInputSample(args.db, args.sessionId) === 0),
|
|
48170
48334
|
explicitFlush: !protectedSignedPrefix && (args.userFlushOrigin === true || hasPendingMaterializationOrigin(pendingMaterializationSessions, args.sessionId, "user_flush")),
|
|
48171
48335
|
publishedHistory: !prefixPreflightContended && publishedM1RefreshedThisPass
|
|
@@ -48173,7 +48337,6 @@ async function runPipeline(args) {
|
|
|
48173
48337
|
const ridePermissionGate = {
|
|
48174
48338
|
signedThinkingHold: protectedSignedPrefix,
|
|
48175
48339
|
firstRender: firstRenderBust,
|
|
48176
|
-
idleExpiry: heldIdleExpiryRebuild,
|
|
48177
48340
|
emergency: emergencyDropEligible
|
|
48178
48341
|
};
|
|
48179
48342
|
let prefixMutationAllowed = prefixMutationPermitted(ridePermissionGate);
|
|
@@ -48189,7 +48352,7 @@ async function runPipeline(args) {
|
|
|
48189
48352
|
onRejectedProjectOverride: (warning) => sessionLog2(args.sessionId, warning)
|
|
48190
48353
|
});
|
|
48191
48354
|
let protectionFloorResolution = resolveProtectionFloor();
|
|
48192
|
-
let shouldRunHeuristics = args.heuristics !== undefined && isCacheBustingPass && (rideSignals.publishedHistory || systemPrefixChangedThisPass || rideSignals.explicitFlush || args.forceMaterialization === true || hasPendingMaterializeSignal || deferredMaterializeEligible || foldBustsServedPrefixThisPass || firstRenderBust ||
|
|
48355
|
+
let shouldRunHeuristics = args.heuristics !== undefined && isCacheBustingPass && (rideSignals.publishedHistory || systemPrefixChangedThisPass || rideSignals.explicitFlush || args.forceMaterialization === true || hasPendingMaterializeSignal || deferredMaterializeEligible || foldBustsServedPrefixThisPass || firstRenderBust || args.recoveryRebuildReason !== undefined && isCacheBustingPass || rideSignals.subagentExecute || args.schedulerDecision === "execute" && !alreadyRanHeuristicsThisTurn);
|
|
48193
48356
|
let unavoidableCarriedIdentityRebuild = false;
|
|
48194
48357
|
if (protectedSignedPrefix && readPiIdentityRebuilds(args.db, args.sessionId).length > 0) {
|
|
48195
48358
|
args.tryReplayHeldIdentityRebuild?.();
|
|
@@ -48708,7 +48871,7 @@ async function runPipeline(args) {
|
|
|
48708
48871
|
const tHeuristic = performance.now();
|
|
48709
48872
|
const providerOverflow = args.providerOverflowRecovery === true;
|
|
48710
48873
|
const recoveryCalibration = sessionDecisionCalibration(args.db, args.sessionId);
|
|
48711
|
-
const independentMutationBeforeHeuristics = pendingOpsDidMutate || systemPrefixChangedThisPass || foldBustsServedPrefixThisPass || identityRebuild || firstRenderBust
|
|
48874
|
+
const independentMutationBeforeHeuristics = pendingOpsDidMutate || systemPrefixChangedThisPass || foldBustsServedPrefixThisPass || identityRebuild || firstRenderBust;
|
|
48712
48875
|
if (args.forceMaterialization === true && independentMutationBeforeHeuristics && getEmergencyInputSample(args.db, args.sessionId) > 0) {
|
|
48713
48876
|
clearEmergencyDropSample(args.db, args.sessionId);
|
|
48714
48877
|
}
|
|
@@ -49351,7 +49514,7 @@ async function runPipeline(args) {
|
|
|
49351
49514
|
prefixMutationAllowed,
|
|
49352
49515
|
strictThinkingKept: protectedSignedPrefix,
|
|
49353
49516
|
signedPrefixRewritten: rewritingSignedPrefix,
|
|
49354
|
-
prefixRebuildAlreadyPriced: firstRenderBust ||
|
|
49517
|
+
prefixRebuildAlreadyPriced: firstRenderBust || !!args.recoveryRebuildReason && isCacheBustingPass,
|
|
49355
49518
|
identityRebuilt: identityRebuild,
|
|
49356
49519
|
servedTagNumbers,
|
|
49357
49520
|
heuristicsExecuted,
|
|
@@ -51009,7 +51172,7 @@ function cacheRows(source, now) {
|
|
|
51009
51172
|
}
|
|
51010
51173
|
rows.push({
|
|
51011
51174
|
label: "Auto-execute",
|
|
51012
|
-
value:
|
|
51175
|
+
value: `at ≥${threshold}`,
|
|
51013
51176
|
tone: "muted"
|
|
51014
51177
|
});
|
|
51015
51178
|
return rows;
|