@cortexkit/pi-magic-context 0.49.23 → 0.49.24
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 +4 -4
- package/dist/chunk-embedding-write-worker.js +4 -4
- package/dist/{compartment-chunk-embedding-y01m95c2.js → compartment-chunk-embedding-g9a977b8.js} +3 -3
- package/dist/{embedding-backfill-2vh6m3bg.js → embedding-backfill-qxzjy5v2.js} +5 -5
- package/dist/{index-w1twp2kp.js → index-00c5a49f.js} +1 -1
- package/dist/{index-dbgg6hsf.js → index-3jde7hdr.js} +2 -2
- package/dist/{index-579m1751.js → index-8a2wvrda.js} +1 -1
- package/dist/{index-at6py2k3.js → index-8hmqdav2.js} +5 -1
- package/dist/{index-gqjxy2p7.js → index-byh4rfe7.js} +77 -5
- package/dist/{index-st4gwt64.js → index-faz8bw8b.js} +1 -1
- package/dist/{index-2bx7ge3x.js → index-fbrxezw0.js} +32 -32
- package/dist/{index-wgmhk91m.js → index-hf01gtz7.js} +3 -3
- package/dist/{index-pe5gz5c4.js → index-nxq2srg9.js} +1 -1
- package/dist/{index-ftvm2acc.js → index-rk8xef10.js} +4 -4
- package/dist/{index-vx6f7wff.js → index-wb2t932e.js} +1 -1
- package/dist/{index-5j6vwg4z.js → index-ygzh9xdg.js} +32 -22
- package/dist/index.js +515 -146
- package/dist/{message-fts-rowid-map-59y476bk.js → message-fts-rowid-map-1tb3qjtc.js} +2 -2
- package/dist/{message-index-bounded-4ngt600v.js → message-index-bounded-hjat9176.js} +5 -5
- package/dist/{message-index-3snxf11x.js → message-index-esykp965.js} +5 -5
- package/dist/migration-worker.js +3 -3
- package/dist/{project-embedding-registry-hfyzs654.js → project-embedding-registry-9e82qsb6.js} +4 -4
- package/dist/raw-ordinal-warmup-worker.js +6 -6
- package/dist/{read-session-chunk-5dmc77q2.js → read-session-chunk-tzvv1kph.js} +2 -2
- package/dist/{read-session-raw-yxv2fv34.js → read-session-raw-napqv76k.js} +3 -1
- package/dist/{search-archive-3daj5ttc.js → search-archive-enx1vd9n.js} +3 -3
- package/dist/{search-jhfh3tsj.js → search-n3yqng95.js} +8 -8
- package/dist/subagent-entry.js +11 -11
- package/dist/tag-snapshot-worker-pi.js +4 -4
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -251,7 +251,7 @@ import {
|
|
|
251
251
|
registerTodoStateLifecycle,
|
|
252
252
|
syncCtxMemoryToolEnabled,
|
|
253
253
|
registerMagicContextTools
|
|
254
|
-
} from "./index-
|
|
254
|
+
} from "./index-fbrxezw0.js";
|
|
255
255
|
import"./index-4knyh1kt.js";
|
|
256
256
|
import {
|
|
257
257
|
canonicalModelIdentity,
|
|
@@ -292,7 +292,7 @@ import {
|
|
|
292
292
|
openCurrentDatabase,
|
|
293
293
|
openDatabaseAsync,
|
|
294
294
|
closeDatabase
|
|
295
|
-
} from "./index-
|
|
295
|
+
} from "./index-3jde7hdr.js";
|
|
296
296
|
import {
|
|
297
297
|
pruneMissingProjectIdentities,
|
|
298
298
|
setHomeProjectPermission,
|
|
@@ -408,6 +408,7 @@ import {
|
|
|
408
408
|
setSessionWorkMetrics,
|
|
409
409
|
getSessionWorkMetrics,
|
|
410
410
|
resolveEpochFloorForPass,
|
|
411
|
+
askAnswerLines,
|
|
411
412
|
retreatPastHostUnservedRows,
|
|
412
413
|
completedToolArcCrossesBoundary,
|
|
413
414
|
estimateTrueRawMessageTokens,
|
|
@@ -465,7 +466,7 @@ import {
|
|
|
465
466
|
getRawSessionTagKeysThrough2,
|
|
466
467
|
getLegacyProtectedTailStartOrdinal2,
|
|
467
468
|
readSessionChunk2
|
|
468
|
-
} from "./index-
|
|
469
|
+
} from "./index-byh4rfe7.js";
|
|
469
470
|
import {
|
|
470
471
|
UNKNOWN_FIT_RATIO,
|
|
471
472
|
hasMeasuredDecisionCalibration,
|
|
@@ -616,7 +617,7 @@ import {
|
|
|
616
617
|
indexSingleMessage2,
|
|
617
618
|
indexMessagesAfterOrdinal2,
|
|
618
619
|
sweepOrphanedOpenCodeMessageIndexesCooperatively2
|
|
619
|
-
} from "./index-
|
|
620
|
+
} from "./index-hf01gtz7.js";
|
|
620
621
|
import {
|
|
621
622
|
resolveOpenCodeDbPath,
|
|
622
623
|
assertOpenCodeStoreGeneration,
|
|
@@ -632,11 +633,11 @@ import {
|
|
|
632
633
|
import {
|
|
633
634
|
runSessionWarmupWorker,
|
|
634
635
|
RAW_SUMMARY_TEXT_MAX_CHARS2
|
|
635
|
-
} from "./index-
|
|
636
|
+
} from "./index-8hmqdav2.js";
|
|
636
637
|
import {
|
|
637
638
|
formatSynapseLaneDescriptor
|
|
638
639
|
} from "./index-gwxaz0z5.js";
|
|
639
|
-
import"./index-
|
|
640
|
+
import"./index-8a2wvrda.js";
|
|
640
641
|
import {
|
|
641
642
|
buildCanonicalChunkTextFromFts2,
|
|
642
643
|
buildCompartmentSummaryFallbackText2,
|
|
@@ -646,7 +647,7 @@ import {
|
|
|
646
647
|
replaceCompartmentChunkEmbeddings2,
|
|
647
648
|
deleteChunkEmbedBackoffForSession2,
|
|
648
649
|
chunkWindowSourceKey2
|
|
649
|
-
} from "./index-
|
|
650
|
+
} from "./index-wb2t932e.js";
|
|
650
651
|
import {
|
|
651
652
|
recordSessionProjectIdentity,
|
|
652
653
|
GIT_SWEEP_LEASE_RENEWAL_MS,
|
|
@@ -681,7 +682,7 @@ import {
|
|
|
681
682
|
embedSessionCompartmentChunks2,
|
|
682
683
|
getEmbeddingCoverageStatus2,
|
|
683
684
|
getAutoEmbeddingSessionCoverage2
|
|
684
|
-
} from "./index-
|
|
685
|
+
} from "./index-00c5a49f.js";
|
|
685
686
|
import {
|
|
686
687
|
rememberV1HiddenRun
|
|
687
688
|
} from "./index-6x556c2q.js";
|
|
@@ -746,7 +747,7 @@ import {
|
|
|
746
747
|
normalizeVerificationFiles,
|
|
747
748
|
indexCommitsForProject,
|
|
748
749
|
embedUnembeddedCommits
|
|
749
|
-
} from "./index-
|
|
750
|
+
} from "./index-rk8xef10.js";
|
|
750
751
|
import {
|
|
751
752
|
setEmbeddingSessionBusy2,
|
|
752
753
|
isEmbeddingHostBusy2
|
|
@@ -782,7 +783,7 @@ import {
|
|
|
782
783
|
} from "./index-wqpjhx1p.js";
|
|
783
784
|
import {
|
|
784
785
|
cosineSimilarity
|
|
785
|
-
} from "./index-
|
|
786
|
+
} from "./index-nxq2srg9.js";
|
|
786
787
|
import"./index-6wdwv3a6.js";
|
|
787
788
|
import {
|
|
788
789
|
DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS,
|
|
@@ -810,10 +811,10 @@ import {
|
|
|
810
811
|
drainPiTagSnapshotSession,
|
|
811
812
|
assertPiTagSnapshotReady,
|
|
812
813
|
ensurePiTagSnapshotReady
|
|
813
|
-
} from "./index-
|
|
814
|
+
} from "./index-ygzh9xdg.js";
|
|
814
815
|
import"./index-jn44h81p.js";
|
|
815
816
|
import"./index-1cvyaw9a.js";
|
|
816
|
-
import"./index-
|
|
817
|
+
import"./index-faz8bw8b.js";
|
|
817
818
|
import {
|
|
818
819
|
__toESM
|
|
819
820
|
} from "./index-22jkk6wg.js";
|
|
@@ -3555,7 +3556,7 @@ function startHostStallProfilerSwitch() {
|
|
|
3555
3556
|
// package.json
|
|
3556
3557
|
var package_default = {
|
|
3557
3558
|
name: "@cortexkit/pi-magic-context",
|
|
3558
|
-
version: "0.49.
|
|
3559
|
+
version: "0.49.24",
|
|
3559
3560
|
type: "module",
|
|
3560
3561
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
3561
3562
|
main: "dist/index.js",
|
|
@@ -3587,8 +3588,8 @@ var package_default = {
|
|
|
3587
3588
|
build: "bun ../../scripts/check-bun.mjs && tsc -p ../retina-local-fs/tsconfig.build.json && bun ../../scripts/clean-dist-chunks.mjs dist index.js subagent-entry.js historian-calibration-extension.js embedding-worker-process.js raw-ordinal-warmup-worker.js tag-snapshot-worker-pi.js transformers-web.js transformers-node-wasm.js && bun build ../plugin/src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/transformers-web.js --target browser --format esm --external onnxruntime-web && bun ../plugin/scripts/build-transformers-node-wasm.ts dist && bun build src/index.ts src/tag-snapshot-worker-pi.ts src/subagent-entry.ts src/historian-calibration-extension.ts ../plugin/src/features/magic-context/memory/embedding-worker.ts ../plugin/src/features/magic-context/memory/embedding-worker-process.ts ../plugin/src/features/magic-context/migration-worker.ts ../plugin/src/hooks/magic-context/auto-search-worker.ts ../plugin/src/hooks/magic-context/raw-ordinal-warmup-worker.ts ../plugin/src/features/magic-context/compaction-marker-candidates-worker.ts ../plugin/src/features/magic-context/chunk-embedding-write-worker.ts --outdir dist --entry-naming '[name].[ext]' --target node --format esm --splitting --external @earendil-works/pi-coding-agent --external @oh-my-pi/pi-coding-agent --external @earendil-works/pi-tui --external onnxruntime-node --external onnxruntime-web --external sharp --external bun:ffi --external node:sqlite",
|
|
3588
3589
|
"build:e2e-argv": `bun ../../scripts/clean-dist-chunks.mjs ../../tests/docker/.generated subagent-runner-e2e.mjs && bun build src/subagent-runner.ts --outdir ../../tests/docker/.generated --entry-naming 'subagent-runner-e2e.mjs' --splitting --target node --format esm --external node:sqlite && node --input-type=module -e 'const { __test } = await import("../../tests/docker/.generated/subagent-runner-e2e.mjs"); if (typeof __test.buildArgs !== "function" || typeof __test.resolvePiInvocation !== "function") throw new Error("argv renderer exports missing"); console.log("Node argv renderer: 2 exports loaded")'`,
|
|
3589
3590
|
typecheck: "tsc -p ../retina-local-fs/tsconfig.build.json && tsc --noEmit",
|
|
3590
|
-
test: "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel=4 --timeout 30000",
|
|
3591
|
-
"test:serial": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel=1 --timeout 30000",
|
|
3591
|
+
test: "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && MC_SLOW_TESTS=0 BUN_JSC_useOMGJIT=0 bun test --parallel=4 --timeout 30000",
|
|
3592
|
+
"test:serial": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && MC_SLOW_TESTS=0 BUN_JSC_useOMGJIT=0 bun test --parallel=1 --timeout 30000",
|
|
3592
3593
|
lint: "bun ../../scripts/check-bun.mjs && biome check src",
|
|
3593
3594
|
"lint:fix": "biome check --write src",
|
|
3594
3595
|
format: "biome format --write src",
|
|
@@ -3626,6 +3627,7 @@ var package_default = {
|
|
|
3626
3627
|
"omp-pi-ai-1811": "npm:@oh-my-pi/pi-ai@18.11.3",
|
|
3627
3628
|
"omp-pi-ai-1812": "npm:@oh-my-pi/pi-ai@18.12.3",
|
|
3628
3629
|
"omp-pi-ai-18126": "npm:@oh-my-pi/pi-ai@18.12.6",
|
|
3630
|
+
"omp-pi-ai-1813": "npm:@oh-my-pi/pi-ai@18.13.0",
|
|
3629
3631
|
"pi-agent-core-087": "npm:@earendil-works/pi-agent-core@0.87.1",
|
|
3630
3632
|
"pi-ai-086": "npm:@earendil-works/pi-ai@0.86.0",
|
|
3631
3633
|
"pi-ai-087": "npm:@earendil-works/pi-ai@0.87.1",
|
|
@@ -15544,7 +15546,10 @@ function orientationRenderer(capTokens) {
|
|
|
15544
15546
|
sawMessage = true;
|
|
15545
15547
|
const out = [];
|
|
15546
15548
|
if (msg.role === "user" && hasMeaningfulUserText2(msg.parts)) {
|
|
15547
|
-
const
|
|
15549
|
+
const rawTexts = extractTexts2(msg.parts);
|
|
15550
|
+
const parts = rawTexts.map((t) => cleanUserText2(t)).map(normalizeText).filter((t) => t.length > 0);
|
|
15551
|
+
parts.push(...rawTexts.flatMap((t) => askAnswerLines(t)).map(normalizeText));
|
|
15552
|
+
const text = parts.filter((t) => t.length > 0).join(" / ");
|
|
15548
15553
|
if (text)
|
|
15549
15554
|
out.push(`U: ${text}`);
|
|
15550
15555
|
}
|
|
@@ -26029,6 +26034,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
26029
26034
|
priorBoundaryOrdinal: ctx.priorBoundaryOrdinal,
|
|
26030
26035
|
migrationFloorActive: ctx.migrationFloorActive,
|
|
26031
26036
|
emergencyTailScale: ctx.emergencyTailScale,
|
|
26037
|
+
liftLivePromptFloor: ctx.liftLivePromptFloor === true ? true : undefined,
|
|
26032
26038
|
providerShapeVersion: ctx.providerShapeVersion,
|
|
26033
26039
|
cacheNamespace: ctx.cacheNamespace,
|
|
26034
26040
|
createdAt,
|
|
@@ -30006,7 +30012,7 @@ async function runPiHistorian(deps) {
|
|
|
30006
30012
|
}) : { ok: true };
|
|
30007
30013
|
if (!validation.ok && validation.reason === "stale_snapshot" && refreshBoundarySnapshot) {
|
|
30008
30014
|
try {
|
|
30009
|
-
const refreshed = refreshBoundarySnapshot();
|
|
30015
|
+
const refreshed = refreshBoundarySnapshot(boundarySnapshot);
|
|
30010
30016
|
if (hasRunnableCompartmentWindow(refreshed)) {
|
|
30011
30017
|
sessionLog2(sessionId, `historian: refreshed stale protected-tail snapshot at run time (was: ${validation.detail ?? "stale"}) — eligible head ${refreshed.offset}-${refreshed.eligibleEndOrdinal - 1}`);
|
|
30012
30018
|
boundarySnapshot = refreshed;
|
|
@@ -32384,6 +32390,7 @@ async function sendStatusNotification(_client, sessionId, text, params) {
|
|
|
32384
32390
|
var inconsistentProducerWindows = new Set;
|
|
32385
32391
|
var HISTORIAN_ALERT_COOLDOWN_MS2 = 60 * 1000;
|
|
32386
32392
|
var lastHistorianAlertBySession2 = new Map;
|
|
32393
|
+
var loggedStoredValidationFailures = new Map;
|
|
32387
32394
|
var STORED_COMPARTMENT_FAILURE_BACKOFF_MS = 30 * 60 * 1000;
|
|
32388
32395
|
|
|
32389
32396
|
// ../plugin/src/hooks/magic-context/compartment-runner-recomp.ts
|
|
@@ -35530,19 +35537,103 @@ function isOmpUnmanagedCaptureRequest(payload) {
|
|
|
35530
35537
|
// src/pi-dispatch-chain.ts
|
|
35531
35538
|
import { isDeepStrictEqual } from "node:util";
|
|
35532
35539
|
|
|
35533
|
-
// src/pi-dispatch-
|
|
35540
|
+
// src/pi-dispatch-omp-user.ts
|
|
35541
|
+
var PI_OMP_STEERING_TEMPLATE = `<system-notice>
|
|
35542
|
+
User interjection during work: priority; supersedes conflicting prior instructions. Re-read; ensure current work reflects user intent.
|
|
35543
|
+
</system-notice>
|
|
35544
|
+
{{message}}
|
|
35545
|
+
`;
|
|
35534
35546
|
function object(value) {
|
|
35535
35547
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
35536
35548
|
}
|
|
35549
|
+
function renderSteering(text) {
|
|
35550
|
+
const lines = PI_OMP_STEERING_TEMPLATE.replace("{{message}}", () => text).split(`
|
|
35551
|
+
`);
|
|
35552
|
+
const result = [];
|
|
35553
|
+
let code = false;
|
|
35554
|
+
for (let index = 0;index < lines.length; index++) {
|
|
35555
|
+
let line = lines[index].trimEnd();
|
|
35556
|
+
let indent = 0;
|
|
35557
|
+
while (line.charCodeAt(indent) === 32 || line.charCodeAt(indent) === 9)
|
|
35558
|
+
indent++;
|
|
35559
|
+
if (line.charCodeAt(indent) >= 128)
|
|
35560
|
+
indent = line.length - line.trimStart().length;
|
|
35561
|
+
const start = line.slice(indent);
|
|
35562
|
+
if (start.startsWith("```") || start.startsWith("~~~")) {
|
|
35563
|
+
code = !code;
|
|
35564
|
+
result.push(line);
|
|
35565
|
+
continue;
|
|
35566
|
+
}
|
|
35567
|
+
if (code) {
|
|
35568
|
+
result.push(line);
|
|
35569
|
+
continue;
|
|
35570
|
+
}
|
|
35571
|
+
if (/^\|[-:\s|]+\|$/.test(start)) {
|
|
35572
|
+
const cells = start.split("|").filter((cell) => cell.trim());
|
|
35573
|
+
line = line.slice(0, line.length - start.length) + "|" + cells.map((cell) => {
|
|
35574
|
+
const value = cell.trim();
|
|
35575
|
+
return `${value.startsWith(":") ? ":" : ""}---${value.endsWith(":") ? ":" : ""}`;
|
|
35576
|
+
}).join("|") + "|";
|
|
35577
|
+
} else if (/^\|.*\|$/.test(start)) {
|
|
35578
|
+
line = line.slice(0, line.length - start.length) + start.split("|").map((cell) => cell.trim()).join("|");
|
|
35579
|
+
}
|
|
35580
|
+
if (!line.trim()) {
|
|
35581
|
+
const next = lines[index + 1];
|
|
35582
|
+
if (next === undefined || !next.trim()) {
|
|
35583
|
+
while (result.at(-1) === "")
|
|
35584
|
+
result.pop();
|
|
35585
|
+
while (index + 1 < lines.length && !lines[index + 1].trim())
|
|
35586
|
+
index++;
|
|
35587
|
+
continue;
|
|
35588
|
+
}
|
|
35589
|
+
if (!result.length || result.at(-1) === "")
|
|
35590
|
+
continue;
|
|
35591
|
+
}
|
|
35592
|
+
if (/^<\/[a-z_-]+>$/.test(start)) {
|
|
35593
|
+
while (result.at(-1) === "")
|
|
35594
|
+
result.pop();
|
|
35595
|
+
}
|
|
35596
|
+
result.push(line);
|
|
35597
|
+
}
|
|
35598
|
+
while (result.at(-1) === "")
|
|
35599
|
+
result.pop();
|
|
35600
|
+
return result.join(`
|
|
35601
|
+
`);
|
|
35602
|
+
}
|
|
35603
|
+
function piOmpUserHistory(message) {
|
|
35604
|
+
if (message.role !== "user" || message.steering !== true)
|
|
35605
|
+
return message;
|
|
35606
|
+
const content = message.content;
|
|
35607
|
+
const text = typeof content === "string" ? content : Array.isArray(content) ? content.filter((part) => object(part)?.type === "text").map((part) => object(part)?.text).join(`
|
|
35608
|
+
`) : "";
|
|
35609
|
+
if (!text.length)
|
|
35610
|
+
return message;
|
|
35611
|
+
const { steering: _steering, ...rest } = message;
|
|
35612
|
+
const wrapped = renderSteering(text);
|
|
35613
|
+
return {
|
|
35614
|
+
...rest,
|
|
35615
|
+
content: typeof content === "string" ? wrapped : [
|
|
35616
|
+
{ type: "text", text: wrapped },
|
|
35617
|
+
...Array.isArray(content) ? content.filter((part) => object(part)?.type === "image") : []
|
|
35618
|
+
]
|
|
35619
|
+
};
|
|
35620
|
+
}
|
|
35621
|
+
|
|
35622
|
+
// src/pi-dispatch-agent-history.ts
|
|
35623
|
+
function object2(value) {
|
|
35624
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
35625
|
+
}
|
|
35537
35626
|
var DEVELOPER_ORIGIN = Symbol("custom developer history");
|
|
35538
35627
|
function piIsDeveloperHistory(message) {
|
|
35539
35628
|
return message.role === "developer" || Reflect.get(message, DEVELOPER_ORIGIN) === true;
|
|
35540
35629
|
}
|
|
35541
35630
|
function piAgentHistory(messages, api) {
|
|
35542
35631
|
return messages.flatMap((value) => {
|
|
35543
|
-
const message =
|
|
35632
|
+
const message = object2(value);
|
|
35544
35633
|
if (!message)
|
|
35545
35634
|
return [value];
|
|
35635
|
+
if (message.role === "user")
|
|
35636
|
+
return [piOmpUserHistory(message)];
|
|
35546
35637
|
if (message.role === "compactionSummary") {
|
|
35547
35638
|
return [
|
|
35548
35639
|
{
|
|
@@ -35565,7 +35656,7 @@ function piAgentHistory(messages, api) {
|
|
|
35565
35656
|
const content = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content;
|
|
35566
35657
|
const userInvoked = message.role === "custom" && message.attribution === "user";
|
|
35567
35658
|
if (userInvoked && message.customType === "collab-prompt") {
|
|
35568
|
-
const text = content.filter((part) =>
|
|
35659
|
+
const text = content.filter((part) => object2(part)?.type === "text").map((part) => object2(part)?.text).join(`
|
|
35569
35660
|
`);
|
|
35570
35661
|
return [
|
|
35571
35662
|
{
|
|
@@ -35576,20 +35667,20 @@ function piAgentHistory(messages, api) {
|
|
|
35576
35667
|
type: "text",
|
|
35577
35668
|
text: text.length ? "User interjection envelope" : ""
|
|
35578
35669
|
},
|
|
35579
|
-
...content.filter((part) =>
|
|
35670
|
+
...content.filter((part) => object2(part)?.type === "image")
|
|
35580
35671
|
]
|
|
35581
35672
|
}
|
|
35582
35673
|
];
|
|
35583
35674
|
}
|
|
35584
35675
|
if (userInvoked && message.customType === "skill-prompt")
|
|
35585
35676
|
return [{ ...message, role: "user", content }];
|
|
35586
|
-
const images = content.filter((part) =>
|
|
35677
|
+
const images = content.filter((part) => object2(part)?.type === "image");
|
|
35587
35678
|
const developerRole = api === "ollama-chat" && message.attribution !== "user" ? "developer" : "user";
|
|
35588
35679
|
if (!images.length)
|
|
35589
35680
|
return [
|
|
35590
35681
|
{ ...message, role: developerRole, content, [DEVELOPER_ORIGIN]: true }
|
|
35591
35682
|
];
|
|
35592
|
-
const texts = content.filter((part) =>
|
|
35683
|
+
const texts = content.filter((part) => object2(part)?.type === "text");
|
|
35593
35684
|
return [
|
|
35594
35685
|
...texts.length ? [
|
|
35595
35686
|
{
|
|
@@ -35682,20 +35773,20 @@ function piToolCallWireId(id, model, source) {
|
|
|
35682
35773
|
}
|
|
35683
35774
|
|
|
35684
35775
|
// src/pi-dispatch-chain-tail.ts
|
|
35685
|
-
function
|
|
35776
|
+
function object3(value) {
|
|
35686
35777
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
35687
35778
|
}
|
|
35688
35779
|
var OMITTED_IMAGE = "[image omitted: model does not support vision]";
|
|
35689
35780
|
function piEncodeChainTail(messages, assistant, responseItems, model) {
|
|
35690
|
-
const harmony =
|
|
35781
|
+
const harmony = object3(model.identity)?.class === "gpt-oss";
|
|
35691
35782
|
const text = (value) => {
|
|
35692
35783
|
const wellFormed = value.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "�");
|
|
35693
35784
|
return harmony ? wellFormed.replace(/<\|(start|end|message|channel|constrain|return|call)\|>/g, "<\\|$1\\|>") : wellFormed;
|
|
35694
35785
|
};
|
|
35695
35786
|
const supportsImages = model.input?.includes("image") === true;
|
|
35696
35787
|
const image = (block) => {
|
|
35697
|
-
const detail = block.detail === "original" &&
|
|
35698
|
-
const file =
|
|
35788
|
+
const detail = block.detail === "original" && object3(model.compat)?.supportsImageDetailOriginal !== true ? "auto" : block.detail ?? "auto";
|
|
35789
|
+
const file = object3(block.providerFile);
|
|
35699
35790
|
if (file?.provider === "openai" && typeof file.id === "string" && file.id)
|
|
35700
35791
|
return { type: "input_image", detail, file_id: file.id };
|
|
35701
35792
|
if (typeof block.url !== "string" && (typeof block.mimeType !== "string" || typeof block.data !== "string"))
|
|
@@ -35708,14 +35799,15 @@ function piEncodeChainTail(messages, assistant, responseItems, model) {
|
|
|
35708
35799
|
};
|
|
35709
35800
|
const items = [];
|
|
35710
35801
|
for (const value of messages) {
|
|
35711
|
-
let message =
|
|
35802
|
+
let message = object3(value);
|
|
35712
35803
|
if (!message || message.providerPayload !== undefined)
|
|
35713
35804
|
return;
|
|
35805
|
+
message = piOmpUserHistory(message);
|
|
35714
35806
|
if (message.role === "custom" || message.role === "hookMessage") {
|
|
35715
35807
|
if (typeof message.customType !== "string" || message.attribution === "user")
|
|
35716
35808
|
return;
|
|
35717
35809
|
const converted = piAgentHistory([message], model.api);
|
|
35718
|
-
const developer =
|
|
35810
|
+
const developer = object3(converted[0]);
|
|
35719
35811
|
if (converted.length !== 1 || !developer || !piIsDeveloperHistory(developer))
|
|
35720
35812
|
return;
|
|
35721
35813
|
message = {
|
|
@@ -35733,7 +35825,7 @@ function piEncodeChainTail(messages, assistant, responseItems, model) {
|
|
|
35733
35825
|
const images = [];
|
|
35734
35826
|
const ordered = [];
|
|
35735
35827
|
for (const value of content) {
|
|
35736
|
-
const block =
|
|
35828
|
+
const block = object3(value);
|
|
35737
35829
|
if (block?.type === "text" && typeof block.text === "string") {
|
|
35738
35830
|
texts.push(block.text);
|
|
35739
35831
|
if (!user || block.text.trim())
|
|
@@ -35761,7 +35853,7 @@ function piEncodeChainTail(messages, assistant, responseItems, model) {
|
|
|
35761
35853
|
if (typeof message.toolCallId !== "string" || message.providerMetadata !== undefined)
|
|
35762
35854
|
return;
|
|
35763
35855
|
const id = piToolCallWireId(message.toolCallId, model, assistant);
|
|
35764
|
-
const call = responseItems.map(
|
|
35856
|
+
const call = responseItems.map(object3).find((item) => item?.call_id === id);
|
|
35765
35857
|
if (!id || call?.type !== "function_call" && call?.type !== "custom_tool_call")
|
|
35766
35858
|
return;
|
|
35767
35859
|
const joined = texts.join(`
|
|
@@ -35778,28 +35870,47 @@ ${OMITTED_IMAGE}` : OMITTED_IMAGE : joined);
|
|
|
35778
35870
|
}
|
|
35779
35871
|
|
|
35780
35872
|
// src/pi-dispatch-chain.ts
|
|
35781
|
-
function
|
|
35873
|
+
function object4(value) {
|
|
35782
35874
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
35783
35875
|
}
|
|
35784
35876
|
function piChainCapableApi(api) {
|
|
35785
35877
|
return api === "openai-codex-responses" || api === "openai-responses" || api === "azure-openai-responses";
|
|
35786
35878
|
}
|
|
35879
|
+
function injectedHeadIndex(messages) {
|
|
35880
|
+
let index = 0;
|
|
35881
|
+
while (object4(messages[index])?.role === "system")
|
|
35882
|
+
index++;
|
|
35883
|
+
const m0 = object4(messages[index]);
|
|
35884
|
+
const m1 = object4(messages[index + 1]);
|
|
35885
|
+
const syntheticUser = (message) => message?.role === "user" && Object.keys(message).every((key) => ["role", "content", "timestamp"].includes(key));
|
|
35886
|
+
if (!syntheticUser(m0) || !syntheticUser(m1))
|
|
35887
|
+
return -1;
|
|
35888
|
+
const m0Content = m0?.content;
|
|
35889
|
+
const m1Content = m1?.content;
|
|
35890
|
+
if (!Array.isArray(m0Content) || !Array.isArray(m1Content))
|
|
35891
|
+
return -1;
|
|
35892
|
+
const m0Text = object4(m0Content[0]);
|
|
35893
|
+
const m1Text = object4(m1Content[0]);
|
|
35894
|
+
return m0Content.length >= 1 && m0Content.length <= 2 && (m0Content.length === 1 || object4(m0Content[1])?.type === "image") && m1Content.length === 1 && m0Text?.type === "text" && typeof m0Text.text === "string" && /^(<project-docs>|<user-profile>|<covered-system-messages>|<session-history>)/.test(m0Text.text) && m0Text.text.includes("</session-history>") && m1Text?.type === "text" && typeof m1Text.text === "string" && /^(<session-history-since>|<knowledge-updates>)/.test(m1Text.text) ? index : -1;
|
|
35895
|
+
}
|
|
35787
35896
|
function piPreparedHistory(messages, model) {
|
|
35788
35897
|
const snapshots = [];
|
|
35789
35898
|
const responseIds = [];
|
|
35790
|
-
|
|
35791
|
-
|
|
35899
|
+
const head = injectedHeadIndex(messages);
|
|
35900
|
+
for (const [index, message] of messages.entries()) {
|
|
35901
|
+
const source = object4(message);
|
|
35902
|
+
const identity = head >= 0 && (index === head || index === head + 1) ? Object.fromEntries(Object.entries(source ?? {}).filter(([key]) => key !== "timestamp")) : message;
|
|
35903
|
+
const fields = lkgContentFields(identity);
|
|
35792
35904
|
if (!fields)
|
|
35793
35905
|
return;
|
|
35794
35906
|
snapshots.push({ id: "", fields });
|
|
35795
|
-
const source = object3(message);
|
|
35796
35907
|
responseIds.push(source?.role === "assistant" && typeof source.responseId === "string" && source.responseId.length > 0 ? source.responseId : undefined);
|
|
35797
35908
|
}
|
|
35798
35909
|
const prepared = { snapshots, responseIds };
|
|
35799
35910
|
let index = responseIds.length - 1;
|
|
35800
35911
|
while (index >= 0 && responseIds[index] === undefined)
|
|
35801
35912
|
index--;
|
|
35802
|
-
const assistant =
|
|
35913
|
+
const assistant = object4(messages[index]);
|
|
35803
35914
|
const response = piChainResponse(assistant);
|
|
35804
35915
|
if (model && assistant && response) {
|
|
35805
35916
|
const delta = piEncodeChainTail(messages.slice(index + 1), assistant, response.responseItems, model);
|
|
@@ -35809,7 +35920,7 @@ function piPreparedHistory(messages, model) {
|
|
|
35809
35920
|
return prepared;
|
|
35810
35921
|
}
|
|
35811
35922
|
function piChainedRequest(payload) {
|
|
35812
|
-
const body =
|
|
35923
|
+
const body = object4(payload);
|
|
35813
35924
|
if (!body || body.previous_response_id === undefined)
|
|
35814
35925
|
return;
|
|
35815
35926
|
const id = body.previous_response_id;
|
|
@@ -35818,14 +35929,14 @@ function piChainedRequest(payload) {
|
|
|
35818
35929
|
return { previousResponseId: id, delta: body.input };
|
|
35819
35930
|
}
|
|
35820
35931
|
function piChainResponse(message) {
|
|
35821
|
-
const source =
|
|
35932
|
+
const source = object4(message);
|
|
35822
35933
|
if (source?.role !== "assistant")
|
|
35823
35934
|
return;
|
|
35824
35935
|
if (source.stopReason !== "stop" && source.stopReason !== "toolUse")
|
|
35825
35936
|
return;
|
|
35826
35937
|
if (typeof source.responseId !== "string" || !source.responseId)
|
|
35827
35938
|
return;
|
|
35828
|
-
const payload =
|
|
35939
|
+
const payload = object4(source.providerPayload);
|
|
35829
35940
|
if (payload?.type !== "openaiResponsesHistory" || payload.dt !== true || !Array.isArray(payload.items))
|
|
35830
35941
|
return;
|
|
35831
35942
|
return {
|
|
@@ -36019,6 +36130,121 @@ function piHasManagedSignature(payload, signature) {
|
|
|
36019
36130
|
function piOmitsTruncatedAssistant(message) {
|
|
36020
36131
|
return (message.stopReason === "length" || message.stopReason === "error" || message.stopReason === "aborted") && Array.isArray(message.content) && !message.content.some((block) => block?.type === "text" || block?.type === "toolCall");
|
|
36021
36132
|
}
|
|
36133
|
+
function object5(value) {
|
|
36134
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
36135
|
+
}
|
|
36136
|
+
function nonblank(value) {
|
|
36137
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
36138
|
+
}
|
|
36139
|
+
function wellFormed(text) {
|
|
36140
|
+
return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "�");
|
|
36141
|
+
}
|
|
36142
|
+
function piAnthropicAssistantReplay(message, model, host) {
|
|
36143
|
+
if (model?.api !== "anthropic-messages" || !Array.isArray(message.content))
|
|
36144
|
+
return "kept";
|
|
36145
|
+
const sameModel = message.provider === model.provider && message.api === model.api && message.model === model.id;
|
|
36146
|
+
let thinking = false;
|
|
36147
|
+
let fallback = false;
|
|
36148
|
+
for (const value of message.content) {
|
|
36149
|
+
const block = object5(value);
|
|
36150
|
+
if (!block)
|
|
36151
|
+
return "kept";
|
|
36152
|
+
if (block.type === "toolCall")
|
|
36153
|
+
return "kept";
|
|
36154
|
+
if (block.type === "text") {
|
|
36155
|
+
if (typeof block.text !== "string" || block.text.trim())
|
|
36156
|
+
return "kept";
|
|
36157
|
+
continue;
|
|
36158
|
+
}
|
|
36159
|
+
if (block.type === "thinking") {
|
|
36160
|
+
if (host === "pi") {
|
|
36161
|
+
if (block.redacted === true) {
|
|
36162
|
+
if (sameModel)
|
|
36163
|
+
return "kept";
|
|
36164
|
+
continue;
|
|
36165
|
+
}
|
|
36166
|
+
if (typeof block.thinking !== "string")
|
|
36167
|
+
return "kept";
|
|
36168
|
+
if (nonblank(block.thinking))
|
|
36169
|
+
return "kept";
|
|
36170
|
+
if (sameModel && nonblank(block.thinkingSignature))
|
|
36171
|
+
return "kept";
|
|
36172
|
+
continue;
|
|
36173
|
+
}
|
|
36174
|
+
if (typeof block.thinking !== "string")
|
|
36175
|
+
return "kept";
|
|
36176
|
+
if (message.api !== model.api) {
|
|
36177
|
+
if (nonblank(block.thinking))
|
|
36178
|
+
return "kept";
|
|
36179
|
+
continue;
|
|
36180
|
+
}
|
|
36181
|
+
if (message.provider !== model.provider && (nonblank(block.thinking) || nonblank(block.thinkingSignature)))
|
|
36182
|
+
return "kept";
|
|
36183
|
+
if (nonblank(block.thinking) || nonblank(block.thinkingSignature))
|
|
36184
|
+
thinking = true;
|
|
36185
|
+
continue;
|
|
36186
|
+
}
|
|
36187
|
+
if (host === "omp" && block.type === "redactedThinking") {
|
|
36188
|
+
if (typeof block.data !== "string")
|
|
36189
|
+
return "kept";
|
|
36190
|
+
if (message.api !== model.api)
|
|
36191
|
+
continue;
|
|
36192
|
+
if (message.provider !== model.provider && nonblank(block.data))
|
|
36193
|
+
return "kept";
|
|
36194
|
+
if (nonblank(block.data))
|
|
36195
|
+
thinking = true;
|
|
36196
|
+
continue;
|
|
36197
|
+
}
|
|
36198
|
+
if (host === "omp" && block.type === "anthropicServerTool") {
|
|
36199
|
+
if (message.api === "anthropic-messages" && message.provider === model.provider)
|
|
36200
|
+
return "kept";
|
|
36201
|
+
continue;
|
|
36202
|
+
}
|
|
36203
|
+
if (host === "omp" && block.type === "fallback")
|
|
36204
|
+
fallback = true;
|
|
36205
|
+
}
|
|
36206
|
+
if (thinking)
|
|
36207
|
+
return "optional";
|
|
36208
|
+
return fallback ? "kept" : "dropped";
|
|
36209
|
+
}
|
|
36210
|
+
function piAnthropicOptionalThinking(message) {
|
|
36211
|
+
const signatures = [];
|
|
36212
|
+
const redacted = [];
|
|
36213
|
+
const texts = [];
|
|
36214
|
+
let fallback = false;
|
|
36215
|
+
for (const value of Array.isArray(message.content) ? message.content : []) {
|
|
36216
|
+
const block = object5(value);
|
|
36217
|
+
if (block?.type === "thinking") {
|
|
36218
|
+
if (nonblank(block.thinkingSignature))
|
|
36219
|
+
signatures.push(block.thinkingSignature);
|
|
36220
|
+
if (nonblank(block.thinking))
|
|
36221
|
+
texts.push(wellFormed(block.thinking).trim());
|
|
36222
|
+
} else if (block?.type === "redactedThinking" && nonblank(block.data))
|
|
36223
|
+
redacted.push(block.data);
|
|
36224
|
+
else if (block?.type === "fallback")
|
|
36225
|
+
fallback = true;
|
|
36226
|
+
}
|
|
36227
|
+
return { signatures, redacted, texts, fallback };
|
|
36228
|
+
}
|
|
36229
|
+
var THINKING_PRESENCE_PLACEHOLDER = "(no reasoning was returned for this turn)";
|
|
36230
|
+
function piExplainsOptionalAssistant(thinking, content) {
|
|
36231
|
+
const fromThinking = (text) => typeof text === "string" && thinking.texts.some((prepared) => text.includes(prepared));
|
|
36232
|
+
return Array.isArray(content) && content.length > 0 && content.every((value) => {
|
|
36233
|
+
const block = object5(value);
|
|
36234
|
+
if (block?.type === "thinking") {
|
|
36235
|
+
if (nonblank(block.signature))
|
|
36236
|
+
return thinking.signatures.includes(block.signature);
|
|
36237
|
+
return block.thinking === THINKING_PRESENCE_PLACEHOLDER || fromThinking(block.thinking);
|
|
36238
|
+
}
|
|
36239
|
+
if (block?.type === "redacted_thinking")
|
|
36240
|
+
return typeof block.data === "string" && thinking.redacted.includes(block.data);
|
|
36241
|
+
if (block?.type === "text")
|
|
36242
|
+
return fromThinking(block.text);
|
|
36243
|
+
if (block?.type === "fallback")
|
|
36244
|
+
return thinking.fallback;
|
|
36245
|
+
return false;
|
|
36246
|
+
});
|
|
36247
|
+
}
|
|
36022
36248
|
|
|
36023
36249
|
// src/pi-dispatch-tool-pairing.ts
|
|
36024
36250
|
var RESPONSES_APIS = new Set([
|
|
@@ -36026,7 +36252,7 @@ var RESPONSES_APIS = new Set([
|
|
|
36026
36252
|
"openai-codex-responses",
|
|
36027
36253
|
"azure-openai-responses"
|
|
36028
36254
|
]);
|
|
36029
|
-
function
|
|
36255
|
+
function object6(value) {
|
|
36030
36256
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
36031
36257
|
}
|
|
36032
36258
|
function piResponsesCallComponent(id) {
|
|
@@ -36037,12 +36263,12 @@ function piToolCallPairing(messages) {
|
|
|
36037
36263
|
const responsesComponents = new Set;
|
|
36038
36264
|
const opaqueCompositeIds = new Set;
|
|
36039
36265
|
for (const value of messages) {
|
|
36040
|
-
const message =
|
|
36266
|
+
const message = object6(value);
|
|
36041
36267
|
if (message?.role !== "assistant" || !Array.isArray(message.content))
|
|
36042
36268
|
continue;
|
|
36043
36269
|
const responses = RESPONSES_APIS.has(String(message.api));
|
|
36044
36270
|
for (const part of message.content) {
|
|
36045
|
-
const block =
|
|
36271
|
+
const block = object6(part);
|
|
36046
36272
|
if (block?.type !== "toolCall" || typeof block.id !== "string")
|
|
36047
36273
|
continue;
|
|
36048
36274
|
if (responses)
|
|
@@ -36063,7 +36289,7 @@ function piToolCallPairing(messages) {
|
|
|
36063
36289
|
// src/pi-dispatch-chat-history.ts
|
|
36064
36290
|
var MAX_EXACT_UNITS = 32 * 1024 * 1024;
|
|
36065
36291
|
var IMAGE_CAPTION = "Attached image(s) from tool result:";
|
|
36066
|
-
function
|
|
36292
|
+
function object7(value) {
|
|
36067
36293
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
36068
36294
|
}
|
|
36069
36295
|
function omitsAssistant(message, model, compat) {
|
|
@@ -36073,7 +36299,7 @@ function omitsAssistant(message, model, compat) {
|
|
|
36073
36299
|
return true;
|
|
36074
36300
|
let thinking = false;
|
|
36075
36301
|
for (const value of message.content) {
|
|
36076
|
-
const block =
|
|
36302
|
+
const block = object7(value);
|
|
36077
36303
|
if (!block)
|
|
36078
36304
|
return false;
|
|
36079
36305
|
if (block.type === "text") {
|
|
@@ -36095,15 +36321,15 @@ function omitsAssistant(message, model, compat) {
|
|
|
36095
36321
|
function piChatHistoryPlan(messages, model) {
|
|
36096
36322
|
if (model?.api !== "openai-completions")
|
|
36097
36323
|
return;
|
|
36098
|
-
const compat =
|
|
36324
|
+
const compat = object7(model.compat) ?? {};
|
|
36099
36325
|
const pairingId = piToolCallPairing(messages);
|
|
36100
36326
|
const calls = new Set;
|
|
36101
36327
|
for (const value of messages) {
|
|
36102
|
-
const message =
|
|
36328
|
+
const message = object7(value);
|
|
36103
36329
|
if (message?.role !== "assistant" || !Array.isArray(message.content))
|
|
36104
36330
|
continue;
|
|
36105
36331
|
for (const value of message.content) {
|
|
36106
|
-
const block =
|
|
36332
|
+
const block = object7(value);
|
|
36107
36333
|
if (block?.type === "toolCall" && typeof block.id === "string")
|
|
36108
36334
|
calls.add(pairingId(block.id));
|
|
36109
36335
|
}
|
|
@@ -36112,7 +36338,7 @@ function piChatHistoryPlan(messages, model) {
|
|
|
36112
36338
|
let pending = new Set;
|
|
36113
36339
|
let exactUnits = 0;
|
|
36114
36340
|
for (let index = 0;index < messages.length; index++) {
|
|
36115
|
-
const message =
|
|
36341
|
+
const message = object7(messages[index]);
|
|
36116
36342
|
if (!message)
|
|
36117
36343
|
return;
|
|
36118
36344
|
if ((message.role === "bashExecution" || message.role === "pythonExecution") && message.excludeFromContext === true)
|
|
@@ -36124,7 +36350,7 @@ function piChatHistoryPlan(messages, model) {
|
|
|
36124
36350
|
continue;
|
|
36125
36351
|
if (Array.isArray(message.content))
|
|
36126
36352
|
for (const value of message.content) {
|
|
36127
|
-
const block =
|
|
36353
|
+
const block = object7(value);
|
|
36128
36354
|
if (block?.type === "toolCall" && typeof block.id === "string")
|
|
36129
36355
|
pending.add(pairingId(block.id));
|
|
36130
36356
|
}
|
|
@@ -36136,7 +36362,7 @@ function piChatHistoryPlan(messages, model) {
|
|
|
36136
36362
|
return;
|
|
36137
36363
|
const parts = [];
|
|
36138
36364
|
for (const value of message.content) {
|
|
36139
|
-
const part =
|
|
36365
|
+
const part = object7(value);
|
|
36140
36366
|
if (part?.type === "text" && typeof part.text === "string" && part.text.trim())
|
|
36141
36367
|
parts.push(part.text);
|
|
36142
36368
|
}
|
|
@@ -36169,14 +36395,14 @@ ${parts.join(`
|
|
|
36169
36395
|
};
|
|
36170
36396
|
const vision = model.input?.includes("image") === true && compat.stripImageInput !== true;
|
|
36171
36397
|
for (const step of transformed) {
|
|
36172
|
-
const message = step.kind === "source" ?
|
|
36398
|
+
const message = step.kind === "source" ? object7(messages[step.index]) : undefined;
|
|
36173
36399
|
if (message?.role !== "toolResult")
|
|
36174
36400
|
flushImages();
|
|
36175
36401
|
steps.push(step);
|
|
36176
36402
|
if (message?.role !== "toolResult" || !vision || !Array.isArray(message.content))
|
|
36177
36403
|
continue;
|
|
36178
36404
|
for (const value of message.content) {
|
|
36179
|
-
const block =
|
|
36405
|
+
const block = object7(value);
|
|
36180
36406
|
if (block?.type !== "image")
|
|
36181
36407
|
continue;
|
|
36182
36408
|
if (compat.requiresAssistantAfterToolResult === true)
|
|
@@ -36200,12 +36426,12 @@ ${parts.join(`
|
|
|
36200
36426
|
function piMatchesChatImages(content, urls) {
|
|
36201
36427
|
if (!Array.isArray(content) || content.length !== urls.length + 1)
|
|
36202
36428
|
return false;
|
|
36203
|
-
const caption =
|
|
36429
|
+
const caption = object7(content[0]);
|
|
36204
36430
|
if (caption?.type !== "text" || caption.text !== IMAGE_CAPTION || Object.keys(caption).length !== 2)
|
|
36205
36431
|
return false;
|
|
36206
36432
|
for (let i = 0;i < urls.length; i++) {
|
|
36207
|
-
const block =
|
|
36208
|
-
const image =
|
|
36433
|
+
const block = object7(content[i + 1]);
|
|
36434
|
+
const image = object7(block?.image_url);
|
|
36209
36435
|
if (block?.type !== "image_url" || Object.keys(block).length !== 2 || !image || Object.keys(image).length !== 1 || image.url !== urls[i])
|
|
36210
36436
|
return false;
|
|
36211
36437
|
}
|
|
@@ -36213,22 +36439,22 @@ function piMatchesChatImages(content, urls) {
|
|
|
36213
36439
|
}
|
|
36214
36440
|
|
|
36215
36441
|
// src/pi-dispatch-image-budget.ts
|
|
36216
|
-
function
|
|
36442
|
+
function object8(value) {
|
|
36217
36443
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
36218
36444
|
}
|
|
36219
36445
|
function piImageBudgetPlan(model) {
|
|
36220
|
-
if (!model?.input?.includes("image") ||
|
|
36446
|
+
if (!model?.input?.includes("image") || object8(model.compat)?.stripImageInput === true)
|
|
36221
36447
|
return;
|
|
36222
36448
|
return {
|
|
36223
36449
|
count: 0,
|
|
36224
36450
|
api: model.api,
|
|
36225
36451
|
rows: new Map,
|
|
36226
|
-
hoistToolImages: model.api?.startsWith("google-") === true &&
|
|
36452
|
+
hoistToolImages: model.api?.startsWith("google-") === true && object8(model.compat)?.multimodalFunctionResponse !== true || model.api === "bedrock-converse-stream" && model.requiresToolResultImageHoisting === true,
|
|
36227
36453
|
hoistErrorImages: model.api === "anthropic-messages" || model.api === "bedrock-converse-stream"
|
|
36228
36454
|
};
|
|
36229
36455
|
}
|
|
36230
36456
|
function inputImage(block, api) {
|
|
36231
|
-
const file =
|
|
36457
|
+
const file = object8(block.providerFile);
|
|
36232
36458
|
if (api === "ollama-chat")
|
|
36233
36459
|
return { kind: "bytes", value: String(block.data ?? "") };
|
|
36234
36460
|
if ((api?.endsWith("responses") && file?.provider === "openai" || api === "anthropic-messages" && file?.provider === "anthropic") && typeof file?.id === "string")
|
|
@@ -36248,7 +36474,7 @@ function piRecordImages(plan, row, source) {
|
|
|
36248
36474
|
return;
|
|
36249
36475
|
const images = [];
|
|
36250
36476
|
for (const value of source.content) {
|
|
36251
|
-
const block =
|
|
36477
|
+
const block = object8(value);
|
|
36252
36478
|
if (block?.type === "image")
|
|
36253
36479
|
images.push(inputImage(block, plan.api));
|
|
36254
36480
|
}
|
|
@@ -36274,20 +36500,20 @@ function piWireImages(content, ollamaImages) {
|
|
|
36274
36500
|
return [];
|
|
36275
36501
|
const images = [];
|
|
36276
36502
|
for (const value of content) {
|
|
36277
|
-
const block =
|
|
36503
|
+
const block = object8(value);
|
|
36278
36504
|
if (!block)
|
|
36279
36505
|
continue;
|
|
36280
|
-
const source =
|
|
36281
|
-
const inline =
|
|
36282
|
-
const file =
|
|
36283
|
-
const bedrock =
|
|
36506
|
+
const source = object8(block.source);
|
|
36507
|
+
const inline = object8(block.inlineData);
|
|
36508
|
+
const file = object8(block.fileData);
|
|
36509
|
+
const bedrock = object8(block.image);
|
|
36284
36510
|
if (block.type === "image_url" || block.type === "input_image") {
|
|
36285
36511
|
if (typeof block.file_id === "string")
|
|
36286
36512
|
images.push({ kind: "file", value: block.file_id });
|
|
36287
36513
|
else
|
|
36288
36514
|
images.push({
|
|
36289
36515
|
kind: "url",
|
|
36290
|
-
value: String(typeof block.image_url === "string" ? block.image_url :
|
|
36516
|
+
value: String(typeof block.image_url === "string" ? block.image_url : object8(block.image_url)?.url)
|
|
36291
36517
|
});
|
|
36292
36518
|
} else if (block.type === "image") {
|
|
36293
36519
|
if (source?.type === "file")
|
|
@@ -36311,7 +36537,7 @@ function piWireImages(content, ollamaImages) {
|
|
|
36311
36537
|
else if (bedrock)
|
|
36312
36538
|
images.push({
|
|
36313
36539
|
kind: "data",
|
|
36314
|
-
value: String(
|
|
36540
|
+
value: String(object8(bedrock.source)?.bytes),
|
|
36315
36541
|
mime: `image/${bedrock.format}`
|
|
36316
36542
|
});
|
|
36317
36543
|
}
|
|
@@ -36333,11 +36559,11 @@ function piMatchesImages(actual, expected) {
|
|
|
36333
36559
|
return true;
|
|
36334
36560
|
}
|
|
36335
36561
|
function piWireImageCount(payload) {
|
|
36336
|
-
const body =
|
|
36562
|
+
const body = object8(payload);
|
|
36337
36563
|
const visit = (value) => {
|
|
36338
36564
|
if (Array.isArray(value))
|
|
36339
36565
|
return value.reduce((n, item) => n + visit(item), 0);
|
|
36340
|
-
const block =
|
|
36566
|
+
const block = object8(value);
|
|
36341
36567
|
if (!block)
|
|
36342
36568
|
return 0;
|
|
36343
36569
|
if (["image", "image_url", "input_image"].includes(String(block.type)) || block.inlineData || block.fileData || block.image)
|
|
@@ -36351,15 +36577,15 @@ function piWireImageCount(payload) {
|
|
|
36351
36577
|
block.response
|
|
36352
36578
|
].reduce((n, item) => n + visit(item), Array.isArray(block.images) ? block.images.length : 0);
|
|
36353
36579
|
};
|
|
36354
|
-
return visit(body?.messages ?? body?.input ?? body?.contents ??
|
|
36580
|
+
return visit(body?.messages ?? body?.input ?? body?.contents ?? object8(body?.request)?.contents);
|
|
36355
36581
|
}
|
|
36356
36582
|
|
|
36357
36583
|
// src/pi-dispatch-responses-history.ts
|
|
36358
36584
|
var MAX_TEXT_UNITS = 32 * 1024 * 1024;
|
|
36359
|
-
function
|
|
36585
|
+
function object9(value) {
|
|
36360
36586
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
36361
36587
|
}
|
|
36362
|
-
function
|
|
36588
|
+
function wellFormed2(text) {
|
|
36363
36589
|
return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "�");
|
|
36364
36590
|
}
|
|
36365
36591
|
function textIdentity2(text, phase) {
|
|
@@ -36371,7 +36597,7 @@ function textIdentity2(text, phase) {
|
|
|
36371
36597
|
function signaturePhase(block) {
|
|
36372
36598
|
try {
|
|
36373
36599
|
if (typeof block.textSignature === "string") {
|
|
36374
|
-
const signature =
|
|
36600
|
+
const signature = object9(JSON.parse(block.textSignature));
|
|
36375
36601
|
if (signature?.v === 1 && typeof signature.id === "string")
|
|
36376
36602
|
return signature.phase;
|
|
36377
36603
|
}
|
|
@@ -36382,30 +36608,30 @@ function demotedThinking(text, model) {
|
|
|
36382
36608
|
const id = model.id?.toLowerCase() ?? "";
|
|
36383
36609
|
if (/^(?:[^/]+\/)?muse-spark-1\.3(?:-|$)/u.test(id))
|
|
36384
36610
|
return `<thinking>
|
|
36385
|
-
${
|
|
36611
|
+
${wellFormed2(text)}
|
|
36386
36612
|
</thinking>`;
|
|
36387
36613
|
if (/^(?:[^/]+\/)?(?:gpt-|o[134](?:-|$)|chatgpt-|codex-)/u.test(id))
|
|
36388
36614
|
return `<think>
|
|
36389
|
-
${
|
|
36615
|
+
${wellFormed2(text)}
|
|
36390
36616
|
</think>`;
|
|
36391
36617
|
return;
|
|
36392
36618
|
}
|
|
36393
36619
|
function coldReplayable(items) {
|
|
36394
36620
|
let reasoning = false;
|
|
36395
36621
|
for (const value of items) {
|
|
36396
|
-
const item =
|
|
36622
|
+
const item = object9(value);
|
|
36397
36623
|
if (typeof item?.encrypted_content === "string")
|
|
36398
36624
|
return false;
|
|
36399
36625
|
if (item?.type !== "reasoning")
|
|
36400
36626
|
continue;
|
|
36401
|
-
if (!Array.isArray(item.content) || !item.content.some((part) =>
|
|
36627
|
+
if (!Array.isArray(item.content) || !item.content.some((part) => object9(part)?.type === "reasoning_text"))
|
|
36402
36628
|
return false;
|
|
36403
36629
|
reasoning = true;
|
|
36404
36630
|
}
|
|
36405
36631
|
return reasoning;
|
|
36406
36632
|
}
|
|
36407
36633
|
function piResponsesAssistantTexts(value, model, host, alternatives) {
|
|
36408
|
-
const message =
|
|
36634
|
+
const message = object9(value);
|
|
36409
36635
|
if (!message || !Array.isArray(message.content))
|
|
36410
36636
|
return;
|
|
36411
36637
|
if (piOmitsTruncatedAssistant(message))
|
|
@@ -36415,7 +36641,7 @@ function piResponsesAssistantTexts(value, model, host, alternatives) {
|
|
|
36415
36641
|
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;
|
|
36416
36642
|
let units = 0;
|
|
36417
36643
|
for (const value of message.content) {
|
|
36418
|
-
const block =
|
|
36644
|
+
const block = object9(value);
|
|
36419
36645
|
if (block?.type === "toolCall")
|
|
36420
36646
|
continue;
|
|
36421
36647
|
if (block?.type === "thinking") {
|
|
@@ -36425,7 +36651,7 @@ function piResponsesAssistantTexts(value, model, host, alternatives) {
|
|
|
36425
36651
|
return;
|
|
36426
36652
|
if (!block.thinking.trim())
|
|
36427
36653
|
continue;
|
|
36428
|
-
const compat =
|
|
36654
|
+
const compat = object9(model.compat);
|
|
36429
36655
|
if (block.summary === false && (compat?.requiresReasoningContentForToolCalls === true || compat?.requiresReasoningContentForAllAssistantTurns === true))
|
|
36430
36656
|
return;
|
|
36431
36657
|
const text = demotedThinking(block.thinking, model);
|
|
@@ -36442,10 +36668,10 @@ function piResponsesAssistantTexts(value, model, host, alternatives) {
|
|
|
36442
36668
|
units += block.text.length;
|
|
36443
36669
|
if (units > MAX_TEXT_UNITS)
|
|
36444
36670
|
return;
|
|
36445
|
-
texts.push(textIdentity2(
|
|
36671
|
+
texts.push(textIdentity2(wellFormed2(block.text), sameModel ? signaturePhase(block) : undefined));
|
|
36446
36672
|
blocks.push(block);
|
|
36447
36673
|
}
|
|
36448
|
-
const payload =
|
|
36674
|
+
const payload = object9(message.providerPayload);
|
|
36449
36675
|
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))
|
|
36450
36676
|
return texts;
|
|
36451
36677
|
const replay = [];
|
|
@@ -36459,7 +36685,7 @@ function piResponsesAssistantTexts(value, model, host, alternatives) {
|
|
|
36459
36685
|
let unsigned = false;
|
|
36460
36686
|
let rewrittenText = false;
|
|
36461
36687
|
for (const value of payload.items) {
|
|
36462
|
-
const item =
|
|
36688
|
+
const item = object9(value);
|
|
36463
36689
|
if (item?.type === "reasoning")
|
|
36464
36690
|
continue;
|
|
36465
36691
|
if (item?.type === "function_call" || item?.type === "custom_tool_call") {
|
|
@@ -36470,14 +36696,14 @@ function piResponsesAssistantTexts(value, model, host, alternatives) {
|
|
|
36470
36696
|
return texts;
|
|
36471
36697
|
const itemTexts = [];
|
|
36472
36698
|
for (const value of item.content) {
|
|
36473
|
-
const part =
|
|
36699
|
+
const part = object9(value);
|
|
36474
36700
|
const block = blocks[bound];
|
|
36475
36701
|
if (!block || part?.type !== "output_text" || typeof part.text !== "string")
|
|
36476
36702
|
return texts;
|
|
36477
36703
|
let signature;
|
|
36478
36704
|
try {
|
|
36479
36705
|
if (typeof block.textSignature === "string")
|
|
36480
|
-
signature =
|
|
36706
|
+
signature = object9(JSON.parse(block.textSignature));
|
|
36481
36707
|
} catch {
|
|
36482
36708
|
return texts;
|
|
36483
36709
|
}
|
|
@@ -36496,7 +36722,7 @@ function piResponsesAssistantTexts(value, model, host, alternatives) {
|
|
|
36496
36722
|
continue;
|
|
36497
36723
|
output = true;
|
|
36498
36724
|
for (const text of itemTexts)
|
|
36499
|
-
replay.push(textIdentity2(
|
|
36725
|
+
replay.push(textIdentity2(wellFormed2(text), item.phase));
|
|
36500
36726
|
}
|
|
36501
36727
|
if (!output || bound !== blocks.length || unsigned && !rewrittenText)
|
|
36502
36728
|
return texts;
|
|
@@ -36516,7 +36742,7 @@ function piResponsesWireTexts(value, phase) {
|
|
|
36516
36742
|
const texts = [];
|
|
36517
36743
|
let units = 0;
|
|
36518
36744
|
for (const partValue of value) {
|
|
36519
|
-
const part =
|
|
36745
|
+
const part = object9(partValue);
|
|
36520
36746
|
if (part?.type !== "output_text" || typeof part.text !== "string")
|
|
36521
36747
|
return;
|
|
36522
36748
|
units += part.text.length;
|
|
@@ -36530,6 +36756,14 @@ function piResponsesWireTexts(value, phase) {
|
|
|
36530
36756
|
// src/pi-dispatch-structure.ts
|
|
36531
36757
|
var MAX_MESSAGES = 1e5;
|
|
36532
36758
|
var ORPHAN_NOTE = Symbol("prepared orphan tool result");
|
|
36759
|
+
var ANTHROPIC_CONTINUE_PAD_TEXT = "Continue.";
|
|
36760
|
+
var ANTHROPIC_CONTINUE_PAD_APIS = new Set(["anthropic-messages"]);
|
|
36761
|
+
function piModelsAnthropicContinuePad(api, host) {
|
|
36762
|
+
return host === "omp" && api !== undefined && ANTHROPIC_CONTINUE_PAD_APIS.has(api);
|
|
36763
|
+
}
|
|
36764
|
+
function isAnthropicContinuePadRow(row) {
|
|
36765
|
+
return row.role === "user" && row.wireContent === ANTHROPIC_CONTINUE_PAD_TEXT;
|
|
36766
|
+
}
|
|
36533
36767
|
var TRANSFORM_MESSAGES_APIS = new Set([
|
|
36534
36768
|
"openai-completions",
|
|
36535
36769
|
"openai-responses",
|
|
@@ -36546,11 +36780,11 @@ var TRANSFORM_MESSAGES_APIS = new Set([
|
|
|
36546
36780
|
"devin-agent",
|
|
36547
36781
|
"apple-foundation-models"
|
|
36548
36782
|
]);
|
|
36549
|
-
function
|
|
36783
|
+
function object10(value) {
|
|
36550
36784
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
36551
36785
|
}
|
|
36552
36786
|
function messageStructure(value) {
|
|
36553
|
-
const message =
|
|
36787
|
+
const message = object10(value);
|
|
36554
36788
|
if (!message)
|
|
36555
36789
|
return;
|
|
36556
36790
|
const role = [
|
|
@@ -36579,7 +36813,7 @@ function messageStructure(value) {
|
|
|
36579
36813
|
}
|
|
36580
36814
|
if (role === "assistant" && Array.isArray(message.content)) {
|
|
36581
36815
|
for (const value of message.content) {
|
|
36582
|
-
const block =
|
|
36816
|
+
const block = object10(value);
|
|
36583
36817
|
if (block?.type !== "toolCall" && block?.type !== "tool_use")
|
|
36584
36818
|
continue;
|
|
36585
36819
|
if (typeof block.id !== "string")
|
|
@@ -36595,7 +36829,7 @@ function windowCalls(message) {
|
|
|
36595
36829
|
if (!Array.isArray(message.content))
|
|
36596
36830
|
return [];
|
|
36597
36831
|
return message.content.flatMap((value) => {
|
|
36598
|
-
const block =
|
|
36832
|
+
const block = object10(value);
|
|
36599
36833
|
return block?.type === "toolCall" && typeof block.id === "string" ? [
|
|
36600
36834
|
{
|
|
36601
36835
|
id: block.id,
|
|
@@ -36605,7 +36839,7 @@ function windowCalls(message) {
|
|
|
36605
36839
|
});
|
|
36606
36840
|
}
|
|
36607
36841
|
function duplicateSuffix(model) {
|
|
36608
|
-
const compat =
|
|
36842
|
+
const compat = object10(model?.compat);
|
|
36609
36843
|
if (model?.api === "openai-completions") {
|
|
36610
36844
|
if (compat?.requiresMistralToolIds === true)
|
|
36611
36845
|
return { prefix: "dup", max: 9 };
|
|
@@ -36622,7 +36856,7 @@ function appendDuplicateSuffix(id, suffix, max) {
|
|
|
36622
36856
|
}
|
|
36623
36857
|
function projectMissingToolResults(messages, model, host = "omp") {
|
|
36624
36858
|
const input = messages.filter((value) => {
|
|
36625
|
-
const message =
|
|
36859
|
+
const message = object10(value);
|
|
36626
36860
|
return !((message?.role === "bashExecution" || message?.role === "pythonExecution") && message.excludeFromContext === true);
|
|
36627
36861
|
});
|
|
36628
36862
|
if (host === "pi")
|
|
@@ -36637,7 +36871,7 @@ function projectMissingToolResults(messages, model, host = "omp") {
|
|
|
36637
36871
|
const realResults = new Map;
|
|
36638
36872
|
const validToolUseIds = new Set;
|
|
36639
36873
|
const deduplicated = input.map((value, index) => {
|
|
36640
|
-
const message =
|
|
36874
|
+
const message = object10(value);
|
|
36641
36875
|
if (message?.role === "toolResult" && typeof message.toolCallId === "string") {
|
|
36642
36876
|
let key = pairingId(message.toolCallId);
|
|
36643
36877
|
let output = value;
|
|
@@ -36664,7 +36898,7 @@ function projectMissingToolResults(messages, model, host = "omp") {
|
|
|
36664
36898
|
const touched = new Set;
|
|
36665
36899
|
let changed = false;
|
|
36666
36900
|
const content = message.content.map((part) => {
|
|
36667
|
-
const block =
|
|
36901
|
+
const block = object10(part);
|
|
36668
36902
|
if (block?.type !== "toolCall" || typeof block.id !== "string")
|
|
36669
36903
|
return part;
|
|
36670
36904
|
const key = pairingId(block.id);
|
|
@@ -36743,7 +36977,7 @@ function projectMissingToolResults(messages, model, host = "omp") {
|
|
|
36743
36977
|
};
|
|
36744
36978
|
for (let index = 0;index < deduplicated.length; index++) {
|
|
36745
36979
|
const value = deduplicated[index];
|
|
36746
|
-
const message =
|
|
36980
|
+
const message = object10(value);
|
|
36747
36981
|
if (message?.role === "assistant") {
|
|
36748
36982
|
flush(message.timestamp);
|
|
36749
36983
|
if (piOmitsTruncatedAssistant(message))
|
|
@@ -36784,7 +37018,7 @@ function projectMissingToolResults(messages, model, host = "omp") {
|
|
|
36784
37018
|
if (pending.some((call) => !answered.has(pairingId(call.id))) || aborted.size > 0)
|
|
36785
37019
|
continue;
|
|
36786
37020
|
const parts = message.content.flatMap((value) => {
|
|
36787
|
-
const part =
|
|
37021
|
+
const part = object10(value);
|
|
36788
37022
|
return part?.type === "text" && typeof part.text === "string" && part.text.trim() ? [part.text] : [];
|
|
36789
37023
|
});
|
|
36790
37024
|
if (!parts.length)
|
|
@@ -36812,11 +37046,11 @@ function projectUnmodeledToolResults(messages) {
|
|
|
36812
37046
|
return pipe > 0 ? id.slice(0, pipe) : id;
|
|
36813
37047
|
};
|
|
36814
37048
|
for (const value of messages) {
|
|
36815
|
-
const message =
|
|
37049
|
+
const message = object10(value);
|
|
36816
37050
|
if (message?.role !== "assistant" || !Array.isArray(message.content))
|
|
36817
37051
|
continue;
|
|
36818
37052
|
for (const value of message.content) {
|
|
36819
|
-
const block =
|
|
37053
|
+
const block = object10(value);
|
|
36820
37054
|
if (block?.type !== "toolCall" || typeof block.id !== "string")
|
|
36821
37055
|
continue;
|
|
36822
37056
|
if ([
|
|
@@ -36832,7 +37066,7 @@ function projectUnmodeledToolResults(messages) {
|
|
|
36832
37066
|
const pairingId = (id) => !opaqueIds.has(id) && responsesComponents.has(component(id)) ? component(id) : id;
|
|
36833
37067
|
const lastResult = new Map;
|
|
36834
37068
|
messages.forEach((value, index) => {
|
|
36835
|
-
const message =
|
|
37069
|
+
const message = object10(value);
|
|
36836
37070
|
if (message?.role === "toolResult" && typeof message.toolCallId === "string")
|
|
36837
37071
|
lastResult.set(pairingId(message.toolCallId), index);
|
|
36838
37072
|
});
|
|
@@ -36863,7 +37097,7 @@ function projectUnmodeledToolResults(messages) {
|
|
|
36863
37097
|
};
|
|
36864
37098
|
for (let index = 0;index < messages.length; index++) {
|
|
36865
37099
|
const value = messages[index];
|
|
36866
|
-
const message =
|
|
37100
|
+
const message = object10(value);
|
|
36867
37101
|
if ((message?.role === "bashExecution" || message?.role === "pythonExecution") && message.excludeFromContext === true)
|
|
36868
37102
|
continue;
|
|
36869
37103
|
if (message?.role !== "toolResult")
|
|
@@ -36905,7 +37139,7 @@ function projectPiToolResults(messages) {
|
|
|
36905
37139
|
held.length = 0;
|
|
36906
37140
|
};
|
|
36907
37141
|
for (const value of messages) {
|
|
36908
|
-
const message =
|
|
37142
|
+
const message = object10(value);
|
|
36909
37143
|
const role = message?.role;
|
|
36910
37144
|
if (role === "assistant") {
|
|
36911
37145
|
close(message?.timestamp);
|
|
@@ -36936,7 +37170,7 @@ function projectPiToolResults(messages) {
|
|
|
36936
37170
|
function preparePiDispatch(messages, model, omp) {
|
|
36937
37171
|
let output = messages;
|
|
36938
37172
|
const structure = buildPiPreparedStructure(messages, model, omp ? (index, source) => {
|
|
36939
|
-
if (
|
|
37173
|
+
if (object10(source.providerPayload)?.type !== "openaiResponsesHistory")
|
|
36940
37174
|
return;
|
|
36941
37175
|
if (output === messages)
|
|
36942
37176
|
output = messages.slice();
|
|
@@ -36949,7 +37183,7 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
36949
37183
|
if (!messages.length || messages.length > MAX_MESSAGES)
|
|
36950
37184
|
return;
|
|
36951
37185
|
for (let index = 0;index < messages.length; index++) {
|
|
36952
|
-
const source =
|
|
37186
|
+
const source = object10(messages[index]);
|
|
36953
37187
|
if (source?.role === "user" || source?.role === "compactionSummary")
|
|
36954
37188
|
prepareUser?.(index, source);
|
|
36955
37189
|
}
|
|
@@ -36965,7 +37199,7 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
36965
37199
|
let valid = true;
|
|
36966
37200
|
for (let index = 0;index < projectedMessages.length; index++) {
|
|
36967
37201
|
const message = projectedMessages[index];
|
|
36968
|
-
const source =
|
|
37202
|
+
const source = object10(message);
|
|
36969
37203
|
if (rows.length === 0 && (source?.role === "system" || source?.role === "developer"))
|
|
36970
37204
|
continue;
|
|
36971
37205
|
if ((source?.role === "bashExecution" || source?.role === "pythonExecution") && source.excludeFromContext === true)
|
|
@@ -36989,10 +37223,17 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
36989
37223
|
"azure-openai-responses",
|
|
36990
37224
|
"openai-codex-responses"
|
|
36991
37225
|
].includes(model?.api ?? "") && (source?.role === "user" || source?.role === "developer") && (typeof source.content === "string" ? !source.content.trim() : Array.isArray(source.content) && !source.content.some((value) => {
|
|
36992
|
-
const block =
|
|
37226
|
+
const block = object10(value);
|
|
36993
37227
|
return block?.type === "image" || block?.type === "text" && typeof block.text === "string" && block.text.trim();
|
|
36994
37228
|
})))
|
|
36995
37229
|
continue;
|
|
37230
|
+
if (source?.role === "assistant") {
|
|
37231
|
+
const replay = piAnthropicAssistantReplay(source, model, host);
|
|
37232
|
+
if (replay === "dropped")
|
|
37233
|
+
continue;
|
|
37234
|
+
if (replay === "optional")
|
|
37235
|
+
row.optionalThinking = piAnthropicOptionalThinking(source);
|
|
37236
|
+
}
|
|
36996
37237
|
row.calls.forEach((id, index) => {
|
|
36997
37238
|
toolNames.set(id, row.callNames?.[index] ?? "");
|
|
36998
37239
|
if (model?.api) {
|
|
@@ -37019,26 +37260,46 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
37019
37260
|
}
|
|
37020
37261
|
if (!valid)
|
|
37021
37262
|
return;
|
|
37263
|
+
const baseRows = [...rows];
|
|
37264
|
+
const promotable = new Map;
|
|
37022
37265
|
const positionedRows = [...byIndex];
|
|
37023
37266
|
for (let position = positionedRows.length - 1;position >= 0; position--) {
|
|
37024
37267
|
const [index, row] = positionedRows[position];
|
|
37025
|
-
const source =
|
|
37268
|
+
const source = object10(projectedMessages[index]);
|
|
37026
37269
|
if (!source)
|
|
37027
37270
|
return;
|
|
37028
37271
|
const content = source.content;
|
|
37029
37272
|
const parts = typeof content === "string" ? [{ type: "text", text: content }] : content;
|
|
37030
|
-
const textOnly = Array.isArray(parts) && parts.every((part) =>
|
|
37273
|
+
const textOnly = Array.isArray(parts) && parts.every((part) => object10(part)?.type === "text" && typeof object10(part)?.text === "string");
|
|
37274
|
+
const systemTexts = () => {
|
|
37275
|
+
const texts = parts.map((part) => part.text);
|
|
37276
|
+
return model?.api === "anthropic-messages" ? texts.filter((text) => text.trim()).map((text) => new TextDecoder().decode(new TextEncoder().encode(text))) : texts;
|
|
37277
|
+
};
|
|
37031
37278
|
if (piIsDeveloperHistory(source) && source.attribution !== "user") {
|
|
37032
37279
|
const previous = rows[position - 1];
|
|
37033
37280
|
const next = rows[position + 1];
|
|
37034
|
-
|
|
37281
|
+
const anthropicPromotable = model?.api === "anthropic-messages" && object10(model.compat)?.supportsMidConversationSystem === true && textOnly;
|
|
37282
|
+
if (anthropicPromotable)
|
|
37283
|
+
promotable.set(row, systemTexts());
|
|
37284
|
+
if (model?.api === "ollama-chat" || anthropicPromotable && (previous?.role === "user" || previous?.role === "toolResult") && (!next || next.role === "assistant"))
|
|
37035
37285
|
row.role = "system";
|
|
37036
37286
|
}
|
|
37037
37287
|
if (row.role === "system") {
|
|
37038
37288
|
if (!textOnly)
|
|
37039
37289
|
return;
|
|
37040
|
-
|
|
37041
|
-
|
|
37290
|
+
row.systemText = systemTexts();
|
|
37291
|
+
}
|
|
37292
|
+
}
|
|
37293
|
+
const modelsContinuePad = piModelsAnthropicContinuePad(model?.api, host);
|
|
37294
|
+
if (modelsContinuePad) {
|
|
37295
|
+
for (let position = rows.length - 1;position > 0; position--) {
|
|
37296
|
+
if (rows[position]?.role === "assistant" && rows[position - 1]?.role === "assistant")
|
|
37297
|
+
rows.splice(position, 0, {
|
|
37298
|
+
role: "user",
|
|
37299
|
+
calls: [],
|
|
37300
|
+
results: [],
|
|
37301
|
+
exactText: ANTHROPIC_CONTINUE_PAD_TEXT
|
|
37302
|
+
});
|
|
37042
37303
|
}
|
|
37043
37304
|
}
|
|
37044
37305
|
const responsesApi = responsesLane(model?.api);
|
|
@@ -37116,8 +37377,10 @@ function buildPiPreparedStructure(messages, model, prepareUser, host = "omp") {
|
|
|
37116
37377
|
...responsesMessages ? { responsesMessages } : {},
|
|
37117
37378
|
...responsesMessages && unsignedAlternatives ? { responsesAlternatives: [fallbackMessages, coldMessages] } : {},
|
|
37118
37379
|
...model?.api ? { api: model.api } : {},
|
|
37380
|
+
...modelsContinuePad ? { anthropicContinuePad: true } : {},
|
|
37381
|
+
...modelsContinuePad && baseRows.some((row) => row.optionalThinking) ? { anthropicOptional: { rows: baseRows, promotable } } : {},
|
|
37119
37382
|
...model?.api?.startsWith("google-") ? {
|
|
37120
|
-
googleFunctionIds:
|
|
37383
|
+
googleFunctionIds: object10(model.compat)?.supportsFunctionPartId === true
|
|
37121
37384
|
} : {}
|
|
37122
37385
|
};
|
|
37123
37386
|
}
|
|
@@ -37129,7 +37392,7 @@ function responsesLane(api) {
|
|
|
37129
37392
|
].includes(api ?? "");
|
|
37130
37393
|
}
|
|
37131
37394
|
function payloadStructure(payload, ollama = false, responsesItems = false, imageProjection = false) {
|
|
37132
|
-
const body =
|
|
37395
|
+
const body = object10(payload);
|
|
37133
37396
|
if (!body)
|
|
37134
37397
|
return;
|
|
37135
37398
|
const google = piGoogleConversation(payload);
|
|
@@ -37144,11 +37407,13 @@ function payloadStructure(payload, ollama = false, responsesItems = false, image
|
|
|
37144
37407
|
return;
|
|
37145
37408
|
const rows = [];
|
|
37146
37409
|
for (const value of messages) {
|
|
37147
|
-
const message =
|
|
37410
|
+
const message = object10(value);
|
|
37148
37411
|
if (!message)
|
|
37149
37412
|
return;
|
|
37150
37413
|
if (rows.length === 0 && (message.role === "system" || message.role === "developer"))
|
|
37151
37414
|
continue;
|
|
37415
|
+
if (message.role === "system" && Array.isArray(message.content) && message.content.every((block) => ["tool_addition", "tool_removal"].includes(String(object10(block)?.type))))
|
|
37416
|
+
continue;
|
|
37152
37417
|
if (responses && message.type === "reasoning")
|
|
37153
37418
|
continue;
|
|
37154
37419
|
if (responses && ["function_call", "custom_tool_call", "computer_call"].includes(String(message.type))) {
|
|
@@ -37204,7 +37469,7 @@ function payloadStructure(payload, ollama = false, responsesItems = false, image
|
|
|
37204
37469
|
continue;
|
|
37205
37470
|
}
|
|
37206
37471
|
if (message.role === "user" && Array.isArray(message.content)) {
|
|
37207
|
-
const results = message.content.filter((block) =>
|
|
37472
|
+
const results = message.content.filter((block) => object10(block)?.type === "tool_result" || bedrock && object10(block)?.toolResult);
|
|
37208
37473
|
if (results.length) {
|
|
37209
37474
|
for (const block of results) {
|
|
37210
37475
|
const id = bedrock ? block.toolResult?.toolUseId : block.tool_use_id;
|
|
@@ -37251,11 +37516,11 @@ function payloadStructure(payload, ollama = false, responsesItems = false, image
|
|
|
37251
37516
|
}
|
|
37252
37517
|
if (Array.isArray(message.tool_calls)) {
|
|
37253
37518
|
for (const call of message.tool_calls) {
|
|
37254
|
-
const source =
|
|
37519
|
+
const source = object10(call);
|
|
37255
37520
|
if (!source)
|
|
37256
37521
|
return;
|
|
37257
37522
|
if (source.id === undefined && ollama) {
|
|
37258
|
-
const fn =
|
|
37523
|
+
const fn = object10(source.function);
|
|
37259
37524
|
if (typeof fn?.name !== "string")
|
|
37260
37525
|
return;
|
|
37261
37526
|
row.calls.push("");
|
|
@@ -37291,7 +37556,7 @@ function googleStructure(contents, imageProjection = false) {
|
|
|
37291
37556
|
return;
|
|
37292
37557
|
const rows = [];
|
|
37293
37558
|
for (const value of contents) {
|
|
37294
|
-
const message =
|
|
37559
|
+
const message = object10(value);
|
|
37295
37560
|
if (!message || !Array.isArray(message.parts))
|
|
37296
37561
|
return;
|
|
37297
37562
|
if (message.role !== "user" && message.role !== "model")
|
|
@@ -37306,11 +37571,11 @@ function googleStructure(contents, imageProjection = false) {
|
|
|
37306
37571
|
};
|
|
37307
37572
|
const results = [];
|
|
37308
37573
|
for (const value of message.parts) {
|
|
37309
|
-
const part =
|
|
37574
|
+
const part = object10(value);
|
|
37310
37575
|
if (!part)
|
|
37311
37576
|
return;
|
|
37312
37577
|
if (part.functionCall) {
|
|
37313
|
-
const call =
|
|
37578
|
+
const call = object10(part.functionCall);
|
|
37314
37579
|
if (row.role !== "assistant" || typeof call?.name !== "string" || call.id !== undefined && typeof call.id !== "string")
|
|
37315
37580
|
return;
|
|
37316
37581
|
row.calls.push(call.id ?? "");
|
|
@@ -37318,7 +37583,7 @@ function googleStructure(contents, imageProjection = false) {
|
|
|
37318
37583
|
row.callNames.push(call.name);
|
|
37319
37584
|
}
|
|
37320
37585
|
if (part.functionResponse) {
|
|
37321
|
-
const result =
|
|
37586
|
+
const result = object10(part.functionResponse);
|
|
37322
37587
|
if (row.role !== "user" || typeof result?.name !== "string" || result.id !== undefined && typeof result.id !== "string")
|
|
37323
37588
|
return;
|
|
37324
37589
|
results.push({
|
|
@@ -37352,11 +37617,11 @@ function matchesUserText(content, text, api, responses, googleOrBedrock) {
|
|
|
37352
37617
|
if (responses || googleOrBedrock) {
|
|
37353
37618
|
if (!Array.isArray(content) || content.length !== 1)
|
|
37354
37619
|
return false;
|
|
37355
|
-
const block =
|
|
37620
|
+
const block = object10(content[0]);
|
|
37356
37621
|
return !!block && block.text === text && (responses ? block.type === "input_text" : Object.keys(block).length === 1);
|
|
37357
37622
|
}
|
|
37358
37623
|
if ((api === "anthropic-messages" || api === "factory-droid-agent") && Array.isArray(content)) {
|
|
37359
|
-
const block = content.length === 1 ?
|
|
37624
|
+
const block = content.length === 1 ? object10(content[0]) : undefined;
|
|
37360
37625
|
return block?.type === "text" && block.text === text;
|
|
37361
37626
|
}
|
|
37362
37627
|
return content === text;
|
|
@@ -37409,6 +37674,79 @@ function trimPreparedImageRows(rows, budget, drops) {
|
|
|
37409
37674
|
flush();
|
|
37410
37675
|
return projected;
|
|
37411
37676
|
}
|
|
37677
|
+
function countAnthropicOptionalAlignments(plan, base, wire, compare) {
|
|
37678
|
+
const pad = {
|
|
37679
|
+
role: "user",
|
|
37680
|
+
calls: [],
|
|
37681
|
+
results: [],
|
|
37682
|
+
exactText: ANTHROPIC_CONTINUE_PAD_TEXT
|
|
37683
|
+
};
|
|
37684
|
+
const role = (index) => plan.promotable.has(base[index]) ? "user" : base[index].role;
|
|
37685
|
+
const final = (index, previous, next) => {
|
|
37686
|
+
const row = base[index];
|
|
37687
|
+
const systemText = plan.promotable.get(row);
|
|
37688
|
+
if (!systemText)
|
|
37689
|
+
return row;
|
|
37690
|
+
const promoted = (previous === "user" || previous === "toolResult") && (next === undefined || next === "assistant");
|
|
37691
|
+
return promoted ? { ...row, role: "system", systemText } : { ...row, role: "user", systemText: undefined };
|
|
37692
|
+
};
|
|
37693
|
+
const matches = (expected, at) => at < wire.length && compare(expected, wire[at]) === undefined;
|
|
37694
|
+
const states = new Map;
|
|
37695
|
+
const add = (index, previous, at, count) => {
|
|
37696
|
+
let bucket = states.get(index);
|
|
37697
|
+
if (!bucket) {
|
|
37698
|
+
bucket = new Map;
|
|
37699
|
+
states.set(index, bucket);
|
|
37700
|
+
}
|
|
37701
|
+
const key = `${previous ?? ""}|${at}`;
|
|
37702
|
+
bucket.set(key, Math.min(2, (bucket.get(key) ?? 0) + count));
|
|
37703
|
+
};
|
|
37704
|
+
let complete = 0;
|
|
37705
|
+
const advance = (current, previous, at, count) => {
|
|
37706
|
+
const place = (next) => {
|
|
37707
|
+
if (current < 0)
|
|
37708
|
+
return at;
|
|
37709
|
+
const nextRole = next === undefined ? undefined : role(next);
|
|
37710
|
+
if (!matches(final(current, previous, nextRole), at))
|
|
37711
|
+
return;
|
|
37712
|
+
let after = at + 1;
|
|
37713
|
+
if (role(current) === "assistant" && nextRole === "assistant") {
|
|
37714
|
+
if (!matches(pad, after))
|
|
37715
|
+
return;
|
|
37716
|
+
after++;
|
|
37717
|
+
}
|
|
37718
|
+
return after;
|
|
37719
|
+
};
|
|
37720
|
+
for (let next = current + 1;next < base.length; next++) {
|
|
37721
|
+
const after = place(next);
|
|
37722
|
+
if (after !== undefined)
|
|
37723
|
+
add(next, current < 0 ? undefined : role(current), after, count);
|
|
37724
|
+
if (!base[next].optionalThinking)
|
|
37725
|
+
return;
|
|
37726
|
+
}
|
|
37727
|
+
if (current < 0) {
|
|
37728
|
+
if (wire.length === 0)
|
|
37729
|
+
complete = Math.min(2, complete + count);
|
|
37730
|
+
return;
|
|
37731
|
+
}
|
|
37732
|
+
const after = place(undefined);
|
|
37733
|
+
if (after === wire.length || after === wire.length - 1 && role(current) === "assistant" && isAnthropicContinuePadRow(wire[after]))
|
|
37734
|
+
complete = Math.min(2, complete + count);
|
|
37735
|
+
};
|
|
37736
|
+
advance(-1, undefined, 0, 1);
|
|
37737
|
+
for (let index = 0;index < base.length && complete < 2; index++) {
|
|
37738
|
+
const bucket = states.get(index);
|
|
37739
|
+
if (!bucket)
|
|
37740
|
+
continue;
|
|
37741
|
+
states.delete(index);
|
|
37742
|
+
for (const [key, count] of bucket) {
|
|
37743
|
+
const split = key.lastIndexOf("|");
|
|
37744
|
+
const previous = key.slice(0, split) || undefined;
|
|
37745
|
+
advance(index, previous, Number(key.slice(split + 1)), count);
|
|
37746
|
+
}
|
|
37747
|
+
}
|
|
37748
|
+
return complete;
|
|
37749
|
+
}
|
|
37412
37750
|
function piPreparedStructureMismatch(payload, prepared, onImageTrim) {
|
|
37413
37751
|
let stage = "image count";
|
|
37414
37752
|
let row = 0;
|
|
@@ -37424,7 +37762,7 @@ function piPreparedStructureMismatch(payload, prepared, onImageTrim) {
|
|
|
37424
37762
|
return "comparison=image count";
|
|
37425
37763
|
const imageProjection = trimmed > 0;
|
|
37426
37764
|
stage = "wire rows";
|
|
37427
|
-
const body =
|
|
37765
|
+
const body = object10(payload);
|
|
37428
37766
|
const ollama = prepared?.api === "ollama-chat" && !!body && Array.isArray(body.messages) && body.input === undefined && body.system === undefined && body.inferenceConfig === undefined;
|
|
37429
37767
|
const responses = body?.messages === undefined && Array.isArray(body?.input);
|
|
37430
37768
|
rows = payloadStructure(payload, ollama, responses && !!prepared?.responsesMessages, imageProjection);
|
|
@@ -37435,6 +37773,7 @@ function piPreparedStructureMismatch(payload, prepared, onImageTrim) {
|
|
|
37435
37773
|
const actual = rows;
|
|
37436
37774
|
expectedRows = [prepared.responsesMessages, ...prepared.responsesAlternatives].find((candidate) => candidate?.length === actual.length && candidate.every((expected, index) => JSON.stringify(expected.responseTexts) === JSON.stringify(actual[index].responseTexts))) ?? expectedRows;
|
|
37437
37775
|
}
|
|
37776
|
+
const optionalPlan = expectedRows === prepared?.messages ? prepared?.anthropicOptional : undefined;
|
|
37438
37777
|
if (expectedRows && imageProjection && imageBudget)
|
|
37439
37778
|
expectedRows = trimPreparedImageRows(expectedRows, imageBudget, trimmed);
|
|
37440
37779
|
if (!rows || !expectedRows)
|
|
@@ -37444,43 +37783,71 @@ function piPreparedStructureMismatch(payload, prepared, onImageTrim) {
|
|
|
37444
37783
|
stage = "row comparison";
|
|
37445
37784
|
const google = !!piGoogleConversation(payload);
|
|
37446
37785
|
const anthropic = google || body.inferenceConfig !== undefined || prepared?.api === "anthropic-messages" || !prepared?.api && body.max_tokens !== undefined && Array.isArray(body.system);
|
|
37447
|
-
|
|
37448
|
-
row = i;
|
|
37449
|
-
const expected = expectedRows[i];
|
|
37450
|
-
const actual = rows[i];
|
|
37786
|
+
const compareRow = (expected, actual) => {
|
|
37451
37787
|
if (actual.role !== expected.role)
|
|
37452
|
-
return
|
|
37788
|
+
return "role";
|
|
37453
37789
|
if (expected.systemText !== undefined) {
|
|
37454
37790
|
const texts = expected.systemText;
|
|
37455
37791
|
const content = actual.wireContent;
|
|
37456
|
-
const actualTexts = typeof content === "string" ? [content] : Array.isArray(content) && content.every((part) =>
|
|
37792
|
+
const actualTexts = typeof content === "string" ? [content] : Array.isArray(content) && content.every((part) => object10(part)?.type === "text" && typeof object10(part)?.text === "string") ? content.map((part) => part.text) : undefined;
|
|
37457
37793
|
if (!actualTexts || (typeof content === "string" ? content !== texts.join(`
|
|
37458
37794
|
`) : JSON.stringify(actualTexts) !== JSON.stringify(texts)))
|
|
37459
|
-
return
|
|
37795
|
+
return "content";
|
|
37460
37796
|
}
|
|
37461
37797
|
if (imageProjection && !piMatchesImages(actual.images ?? [], expected.images ?? []))
|
|
37462
|
-
return
|
|
37798
|
+
return "content";
|
|
37463
37799
|
if (expected.responseTexts !== undefined && (expected.responseTexts.length !== actual.responseTexts?.length || expected.responseTexts.some((text, index) => text !== actual.responseTexts?.[index])))
|
|
37464
|
-
return
|
|
37800
|
+
return "content";
|
|
37465
37801
|
if (expected.exactText !== undefined || expected.exactImages !== undefined) {
|
|
37466
37802
|
if (actual.wireRole !== "user")
|
|
37467
|
-
return
|
|
37803
|
+
return "role";
|
|
37468
37804
|
if (expected.exactText !== undefined && !matchesUserText(actual.wireContent, expected.exactText, prepared?.api, responses, google || body.inferenceConfig !== undefined) || expected.exactImages !== undefined && !piMatchesChatImages(actual.wireContent, expected.exactImages))
|
|
37469
|
-
return
|
|
37805
|
+
return "content";
|
|
37470
37806
|
}
|
|
37471
37807
|
if (actual.calls.length !== expected.calls.length || actual.results.length !== expected.results.length)
|
|
37472
|
-
return
|
|
37808
|
+
return "count";
|
|
37473
37809
|
if (actual.timestamp !== undefined && actual.timestamp !== expected.timestamp)
|
|
37474
|
-
return
|
|
37810
|
+
return "timestamp";
|
|
37475
37811
|
for (let j = 0;j < actual.calls.length; j++)
|
|
37476
37812
|
if (google && actual.calls[j] === "" && prepared?.googleFunctionIds !== true || ollama && actual.idlessCalls?.[j] === true ? !expected.callNames?.[j] || actual.callNames?.[j] !== expected.callNames[j] : google && prepared?.googleFunctionIds === false || actual.calls[j] !== (expected.wireCalls ? expected.wireCalls[j] : wireId(expected.calls[j], anthropic, responses)))
|
|
37477
|
-
return
|
|
37813
|
+
return google && actual.calls[j] === "" || ollama && actual.idlessCalls?.[j] === true ? "name" : "call id";
|
|
37478
37814
|
for (let j = 0;j < actual.results.length; j++)
|
|
37479
37815
|
if (google && actual.results[j] === "" && prepared?.googleFunctionIds !== true || ollama && actual.idlessResults?.[j] === true ? !expected.resultNames?.[j] || actual.resultNames?.[j] !== expected.resultNames[j] : google && prepared?.googleFunctionIds === false || actual.results[j] !== (expected.wireResults ? expected.wireResults[j] : wireId(expected.results[j], anthropic, responses)))
|
|
37480
|
-
return
|
|
37816
|
+
return google && actual.results[j] === "" || ollama && actual.idlessResults?.[j] === true ? "name" : "result id";
|
|
37817
|
+
if (expected.optionalThinking && !piExplainsOptionalAssistant(expected.optionalThinking, actual.wireContent))
|
|
37818
|
+
return "content";
|
|
37819
|
+
return;
|
|
37820
|
+
};
|
|
37821
|
+
if (optionalPlan) {
|
|
37822
|
+
stage = "optional assistants";
|
|
37823
|
+
const alignments = countAnthropicOptionalAlignments(optionalPlan, imageProjection && imageBudget ? trimPreparedImageRows(optionalPlan.rows, imageBudget, trimmed) : optionalPlan.rows, rows, compareRow);
|
|
37824
|
+
if (alignments > 1)
|
|
37825
|
+
return structureDetail(0, expectedRows, rows, "alignment");
|
|
37826
|
+
if (alignments === 1) {
|
|
37827
|
+
if (imageProjection && imageBudget)
|
|
37828
|
+
onImageTrim?.({
|
|
37829
|
+
planned: imageBudget.count,
|
|
37830
|
+
actual: actualImages,
|
|
37831
|
+
trimmed
|
|
37832
|
+
});
|
|
37833
|
+
return;
|
|
37834
|
+
}
|
|
37835
|
+
stage = "row comparison";
|
|
37481
37836
|
}
|
|
37482
|
-
|
|
37483
|
-
|
|
37837
|
+
for (let i = 0;i < Math.min(rows.length, expectedRows.length); i++) {
|
|
37838
|
+
row = i;
|
|
37839
|
+
const comparison = compareRow(expectedRows[i], rows[i]);
|
|
37840
|
+
if (comparison)
|
|
37841
|
+
return structureDetail(i, expectedRows, rows, comparison);
|
|
37842
|
+
}
|
|
37843
|
+
if (rows.length !== expectedRows.length) {
|
|
37844
|
+
const lastActual = rows[rows.length - 1];
|
|
37845
|
+
const allowsTrailingPad = prepared?.anthropicContinuePad === true && expectedRows.length > 0 && expectedRows[expectedRows.length - 1]?.role === "assistant" && rows.length === expectedRows.length + 1 && !!lastActual && isAnthropicContinuePadRow(lastActual);
|
|
37846
|
+
if (!allowsTrailingPad)
|
|
37847
|
+
return structureDetail(Math.min(rows.length, expectedRows.length), expectedRows, rows, "count");
|
|
37848
|
+
}
|
|
37849
|
+
if (optionalPlan)
|
|
37850
|
+
return structureDetail(0, expectedRows, rows, "alignment");
|
|
37484
37851
|
if (imageProjection && imageBudget)
|
|
37485
37852
|
onImageTrim?.({
|
|
37486
37853
|
planned: imageBudget.count,
|
|
@@ -46095,7 +46462,7 @@ function maybeFireHistorian(args) {
|
|
|
46095
46462
|
return;
|
|
46096
46463
|
}
|
|
46097
46464
|
const unregister = setRawMessageProvider2(sessionId, provider);
|
|
46098
|
-
const resolvePiBoundarySnapshot = (emergencyTailScale) => resolveProtectedTailBoundary(resolveBoundaryContext({
|
|
46465
|
+
const resolvePiBoundarySnapshot = (emergencyTailScale, liftLivePromptFloor = false) => resolveProtectedTailBoundary(resolveBoundaryContext({
|
|
46099
46466
|
db,
|
|
46100
46467
|
sessionId,
|
|
46101
46468
|
mode: "pi-trigger",
|
|
@@ -46105,12 +46472,14 @@ function maybeFireHistorian(args) {
|
|
|
46105
46472
|
usageSource: "live",
|
|
46106
46473
|
providerShapeVersion: "pi-folded-v1",
|
|
46107
46474
|
cacheNamespace: `pi:${sessionId}`,
|
|
46108
|
-
emergencyTailScale
|
|
46475
|
+
emergencyTailScale,
|
|
46476
|
+
liftLivePromptFloor
|
|
46109
46477
|
}));
|
|
46110
|
-
const resolveRunnablePiBoundarySnapshot = () => {
|
|
46111
|
-
|
|
46478
|
+
const resolveRunnablePiBoundarySnapshot = (stale) => {
|
|
46479
|
+
const liftLivePromptFloor = stale?.liftLivePromptFloor === true;
|
|
46480
|
+
let snapshot = ensureRunnablePiBoundaryForTests(resolvePiBoundarySnapshot(undefined, liftLivePromptFloor));
|
|
46112
46481
|
if (!hasRunnableCompartmentWindow(snapshot) && usage.percentage >= historianForceMaterializationPercentage) {
|
|
46113
|
-
snapshot = ensureRunnablePiBoundaryForTests(resolvePiBoundarySnapshot(usage.percentage >= 95 ? 0.25 : 0.5));
|
|
46482
|
+
snapshot = ensureRunnablePiBoundaryForTests(resolvePiBoundarySnapshot(usage.percentage >= 95 ? 0.25 : 0.5, liftLivePromptFloor));
|
|
46114
46483
|
}
|
|
46115
46484
|
return snapshot;
|
|
46116
46485
|
};
|