@howaboua/pi-codex-conversion 1.5.8-dev.35.57ee19e → 1.5.8
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/package.json
CHANGED
|
@@ -71,19 +71,6 @@ export type NativeReplayPayloadRewriteResult =
|
|
|
71
71
|
| NativeReplayPayloadRewrite
|
|
72
72
|
| NativeReplayPayloadRewriteFailure;
|
|
73
73
|
|
|
74
|
-
type ReplayMessageSet = {
|
|
75
|
-
messages: AgentMessage[];
|
|
76
|
-
input: ResponsesInputItem[];
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
type ReplayMatch = {
|
|
80
|
-
originalPiReplayInput: ResponsesInputItem[];
|
|
81
|
-
preCompactionKept: ReplayMessageSet;
|
|
82
|
-
postCompactionTail: ReplayMessageSet;
|
|
83
|
-
actualPostCompactionTail: ResponsesInputItem[];
|
|
84
|
-
extraPostCompactionTail: ResponsesInputItem[];
|
|
85
|
-
};
|
|
86
|
-
|
|
87
74
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
88
75
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
89
76
|
}
|
|
@@ -372,66 +359,6 @@ function createReplaySlice(
|
|
|
372
359
|
};
|
|
373
360
|
}
|
|
374
361
|
|
|
375
|
-
function createReplayMessageSet<TApi extends Api>(model: Model<TApi>, messages: AgentMessage[]): ReplayMessageSet {
|
|
376
|
-
return {
|
|
377
|
-
messages,
|
|
378
|
-
input: serializeMessagesToResponsesInput(model, messages),
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function createReplayVariants<TApi extends Api>(args: {
|
|
383
|
-
model: Model<TApi>;
|
|
384
|
-
entries: readonly SessionEntry[];
|
|
385
|
-
}): ReplayMessageSet[] {
|
|
386
|
-
const contextMessages = collectReplayMessages(args.entries);
|
|
387
|
-
const piMessages = collectPiReplayMessages(args.entries);
|
|
388
|
-
const contextSet = createReplayMessageSet(args.model, contextMessages);
|
|
389
|
-
if (areEquivalentValues(contextMessages, piMessages)) return [contextSet];
|
|
390
|
-
return [contextSet, createReplayMessageSet(args.model, piMessages)];
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function findReplayMatch<TApi extends Api>(args: {
|
|
394
|
-
model: Model<TApi>;
|
|
395
|
-
payloadInput: readonly unknown[];
|
|
396
|
-
freshPreamble: FreshAuthoritativePreamble;
|
|
397
|
-
compactionSummaryMessage: AgentMessage;
|
|
398
|
-
preCompactionEntries: readonly SessionEntry[];
|
|
399
|
-
postCompactionEntries: readonly SessionEntry[];
|
|
400
|
-
}): ReplayMatch | undefined {
|
|
401
|
-
const compactionSummaryInput = serializeMessagesToResponsesInput(args.model, [args.compactionSummaryMessage]);
|
|
402
|
-
const preCompactionVariants = createReplayVariants({ model: args.model, entries: args.preCompactionEntries });
|
|
403
|
-
const postCompactionVariants = createReplayVariants({ model: args.model, entries: args.postCompactionEntries });
|
|
404
|
-
|
|
405
|
-
for (const preCompactionKept of preCompactionVariants) {
|
|
406
|
-
for (const postCompactionTail of postCompactionVariants) {
|
|
407
|
-
const expectedBeforeTrailing: ResponsesInputItem[] = [
|
|
408
|
-
...args.freshPreamble.leadingInput,
|
|
409
|
-
...compactionSummaryInput,
|
|
410
|
-
...preCompactionKept.input,
|
|
411
|
-
...postCompactionTail.input,
|
|
412
|
-
];
|
|
413
|
-
const originalPiReplayInput: ResponsesInputItem[] = [...expectedBeforeTrailing, ...args.freshPreamble.trailingInput];
|
|
414
|
-
const tailEndIndex = args.payloadInput.length - args.freshPreamble.trailingInput.length;
|
|
415
|
-
const prefixMatches = areEquivalentValues(args.payloadInput.slice(0, expectedBeforeTrailing.length), expectedBeforeTrailing);
|
|
416
|
-
const trailingMatches = areEquivalentValues(args.payloadInput.slice(tailEndIndex), args.freshPreamble.trailingInput);
|
|
417
|
-
|
|
418
|
-
if (prefixMatches && trailingMatches && tailEndIndex >= expectedBeforeTrailing.length) {
|
|
419
|
-
const actualPostCompactionTail = cloneResponsesInputSlice(
|
|
420
|
-
args.payloadInput.slice(
|
|
421
|
-
args.freshPreamble.leadingInput.length + compactionSummaryInput.length + preCompactionKept.input.length,
|
|
422
|
-
tailEndIndex,
|
|
423
|
-
),
|
|
424
|
-
);
|
|
425
|
-
const extraPostCompactionTail = cloneResponsesInputSlice(args.payloadInput.slice(expectedBeforeTrailing.length, tailEndIndex));
|
|
426
|
-
if (!actualPostCompactionTail || !extraPostCompactionTail) return undefined;
|
|
427
|
-
return { originalPiReplayInput, preCompactionKept, postCompactionTail, actualPostCompactionTail, extraPostCompactionTail };
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
return undefined;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
362
|
function findEntryIndexByIdBeforeBoundary(
|
|
436
363
|
entries: readonly SessionEntry[],
|
|
437
364
|
entryId: string,
|
|
@@ -526,27 +453,23 @@ function buildNativeReplaySegmentsInternal<TApi extends Api>(args: {
|
|
|
526
453
|
|
|
527
454
|
const preCompactionEntries = args.branchEntries.slice(firstKeptEntryIndex, boundaryIndex);
|
|
528
455
|
const postCompactionEntries = args.branchEntries.slice(boundaryIndex + 1);
|
|
456
|
+
const preCompactionKeptMessages = collectPiReplayMessages(preCompactionEntries);
|
|
457
|
+
const postCompactionTailMessages = collectPiReplayMessages(postCompactionEntries);
|
|
529
458
|
const contextPostCompactionTailMessages = collectReplayMessages(postCompactionEntries);
|
|
530
459
|
const compactionSummaryMessage = createCompactionSummaryAgentMessage(args.compactionEntry);
|
|
531
|
-
const
|
|
532
|
-
model: args.model,
|
|
533
|
-
payloadInput: args.payload.input,
|
|
534
|
-
freshPreamble,
|
|
460
|
+
const serializedPiHistoryInput = serializeMessagesToResponsesInput(args.model, [
|
|
535
461
|
compactionSummaryMessage,
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
...freshPreamble.trailingInput,
|
|
548
|
-
];
|
|
549
|
-
const parity = compareResponsesInputParity(args.payload.input, expectedInput);
|
|
462
|
+
...preCompactionKeptMessages,
|
|
463
|
+
...postCompactionTailMessages,
|
|
464
|
+
]);
|
|
465
|
+
const originalPiReplayInput: ResponsesInputItem[] = [
|
|
466
|
+
...freshPreamble.leadingInput,
|
|
467
|
+
...serializedPiHistoryInput,
|
|
468
|
+
...freshPreamble.trailingInput,
|
|
469
|
+
];
|
|
470
|
+
|
|
471
|
+
if (!areEquivalentValues(args.payload.input, originalPiReplayInput)) {
|
|
472
|
+
const parity = compareResponsesInputParity(args.payload.input, originalPiReplayInput);
|
|
550
473
|
return {
|
|
551
474
|
ok: false,
|
|
552
475
|
reason: "expected-pi-replay-mismatch",
|
|
@@ -561,7 +484,7 @@ function buildNativeReplaySegmentsInternal<TApi extends Api>(args: {
|
|
|
561
484
|
const freshPreambleCount = freshPreamble.leadingInput.length;
|
|
562
485
|
const trailingPreambleCount = freshPreamble.trailingInput.length;
|
|
563
486
|
const compactionSummaryCount = serializeMessagesToResponsesInput(args.model, [compactionSummaryMessage]).length;
|
|
564
|
-
const preCompactionKeptCount =
|
|
487
|
+
const preCompactionKeptCount = serializeMessagesToResponsesInput(args.model, preCompactionKeptMessages).length;
|
|
565
488
|
const tailStartIndex = freshPreambleCount + compactionSummaryCount + preCompactionKeptCount;
|
|
566
489
|
const tailEndIndex = args.payload.input.length - trailingPreambleCount;
|
|
567
490
|
const actualCompactionSummary = cloneResponsesInputSlice(
|
|
@@ -573,11 +496,8 @@ function buildNativeReplaySegmentsInternal<TApi extends Api>(args: {
|
|
|
573
496
|
freshPreambleCount + compactionSummaryCount + preCompactionKeptCount,
|
|
574
497
|
),
|
|
575
498
|
);
|
|
576
|
-
const actualPostCompactionTail =
|
|
577
|
-
const contextPostCompactionTail =
|
|
578
|
-
...serializeMessagesToResponsesInput(args.model, contextPostCompactionTailMessages),
|
|
579
|
-
...replayMatch.extraPostCompactionTail,
|
|
580
|
-
];
|
|
499
|
+
const actualPostCompactionTail = cloneResponsesInputSlice(args.payload.input.slice(tailStartIndex, tailEndIndex));
|
|
500
|
+
const contextPostCompactionTail = serializeMessagesToResponsesInput(args.model, contextPostCompactionTailMessages);
|
|
581
501
|
if (!actualCompactionSummary || !actualPreCompactionKeptWindow || !actualPostCompactionTail) {
|
|
582
502
|
return {
|
|
583
503
|
ok: false,
|
|
@@ -587,7 +507,7 @@ function buildNativeReplaySegmentsInternal<TApi extends Api>(args: {
|
|
|
587
507
|
|
|
588
508
|
const preCompactionKeptWindow = createReplaySlice(
|
|
589
509
|
preCompactionEntries,
|
|
590
|
-
|
|
510
|
+
preCompactionKeptMessages,
|
|
591
511
|
actualPreCompactionKeptWindow,
|
|
592
512
|
);
|
|
593
513
|
const postCompactionTail = createReplaySlice(
|
|
@@ -608,7 +528,7 @@ function buildNativeReplaySegmentsInternal<TApi extends Api>(args: {
|
|
|
608
528
|
preCompactionKeptWindow,
|
|
609
529
|
compactedWindow,
|
|
610
530
|
postCompactionTail,
|
|
611
|
-
originalPiReplayInput
|
|
531
|
+
originalPiReplayInput,
|
|
612
532
|
replayInput: [
|
|
613
533
|
...freshPreamble.leadingInput,
|
|
614
534
|
...compactedWindow,
|
|
Binary file
|
|
Binary file
|