ds-harness-remote 0.4.10 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/dist/client-runtime.d.ts +10 -1
- package/dist/client-runtime.d.ts.map +1 -1
- package/dist/client-runtime.js +47 -22
- package/dist/client-runtime.js.map +1 -1
- package/dist/client.github.js +1 -1
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/codex/peer-bridge.d.ts.map +1 -1
- package/dist/codex/peer-bridge.js +3 -4
- package/dist/codex/peer-bridge.js.map +1 -1
- package/dist/codex/virtual-harness.d.ts +12 -3
- package/dist/codex/virtual-harness.d.ts.map +1 -1
- package/dist/codex/virtual-harness.js +155 -37
- package/dist/codex/virtual-harness.js.map +1 -1
- package/dist/control-route.d.ts +22 -0
- package/dist/control-route.d.ts.map +1 -1
- package/dist/control-route.js +120 -0
- package/dist/control-route.js.map +1 -1
- package/dist/control-runtime.d.ts +2 -1
- package/dist/control-runtime.d.ts.map +1 -1
- package/dist/control-runtime.js +3 -5
- package/dist/control-runtime.js.map +1 -1
- package/dist/harness-api-bridge.d.ts.map +1 -1
- package/dist/harness-api-bridge.js +3 -3
- package/dist/harness-api-bridge.js.map +1 -1
- package/dist/harness-remote-bridge.d.ts.map +1 -1
- package/dist/harness-remote-bridge.js +3 -4
- package/dist/harness-remote-bridge.js.map +1 -1
- package/dist/harness-version.d.ts +7 -0
- package/dist/harness-version.d.ts.map +1 -1
- package/dist/harness-version.js +16 -0
- package/dist/harness-version.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +738 -219
- package/dist/index.js.map +4 -4
- package/dist/remote-api-proxy.d.ts.map +1 -1
- package/dist/remote-api-proxy.js +34 -1
- package/dist/remote-api-proxy.js.map +1 -1
- package/dist/remote-typert-gateway.d.ts +3 -1
- package/dist/remote-typert-gateway.d.ts.map +1 -1
- package/dist/remote-typert-gateway.js +16 -5
- package/dist/remote-typert-gateway.js.map +1 -1
- package/dist/service.d.ts +1 -0
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +8 -4
- package/dist/service.js.map +1 -1
- package/dist/session-format-compat.d.ts +3 -0
- package/dist/session-format-compat.d.ts.map +1 -0
- package/dist/session-format-compat.js +183 -0
- package/dist/session-format-compat.js.map +1 -0
- package/dist/tui-command.js +5 -3
- package/dist/tui-command.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dsh-plugin.json +1 -1
- package/package.json +21 -21
|
@@ -2,6 +2,7 @@ import type { ApiProxy } from '@deepseek-ai/dsh-host-apiproxy/api';
|
|
|
2
2
|
import { CodexRemoteClient } from '@dsh-remote/client-core';
|
|
3
3
|
import type { RemoteTypertGatewayTarget, TypertGatewayRequest, TypertRpcResult } from '../typert-gateway-contract.js';
|
|
4
4
|
import type { CodexPermissionSnapshot } from '@dsh-remote/protocol';
|
|
5
|
+
import type { HarnessSessionGeneration } from '../harness-version.js';
|
|
5
6
|
type JsonRecord = Record<string, unknown>;
|
|
6
7
|
export interface CodexVirtualWorkspaceView {
|
|
7
8
|
workspaceId: string;
|
|
@@ -33,6 +34,10 @@ interface NativeEvent {
|
|
|
33
34
|
op: 'replace';
|
|
34
35
|
start: number;
|
|
35
36
|
end: number;
|
|
37
|
+
} | {
|
|
38
|
+
op: 'replace';
|
|
39
|
+
startSeq: number;
|
|
40
|
+
endSeq: number;
|
|
36
41
|
};
|
|
37
42
|
}
|
|
38
43
|
export interface CodexNativeHistory {
|
|
@@ -41,6 +46,7 @@ export interface CodexNativeHistory {
|
|
|
41
46
|
id: string;
|
|
42
47
|
createdAt: number;
|
|
43
48
|
cwd?: string;
|
|
49
|
+
isSeeded?: boolean;
|
|
44
50
|
};
|
|
45
51
|
entries: Array<{
|
|
46
52
|
type: 'event';
|
|
@@ -73,6 +79,7 @@ export declare function discoverCodexVirtualWorkspaces(client: CodexClientLike,
|
|
|
73
79
|
export declare class CodexVirtualHarness implements RemoteTypertGatewayTarget {
|
|
74
80
|
private readonly client;
|
|
75
81
|
private readonly host;
|
|
82
|
+
private readonly sessionGeneration;
|
|
76
83
|
readonly api: ApiProxy;
|
|
77
84
|
private catalog?;
|
|
78
85
|
private readonly workspaceStreams;
|
|
@@ -97,11 +104,11 @@ export declare class CodexVirtualHarness implements RemoteTypertGatewayTarget {
|
|
|
97
104
|
constructor(client: CodexClientLike, host: {
|
|
98
105
|
deviceId: string;
|
|
99
106
|
name: string;
|
|
100
|
-
});
|
|
107
|
+
}, sessionGeneration?: HarnessSessionGeneration);
|
|
101
108
|
static remote(core: ConstructorParameters<typeof CodexRemoteClient>[0], host: {
|
|
102
109
|
deviceId: string;
|
|
103
110
|
name: string;
|
|
104
|
-
}): CodexVirtualHarness;
|
|
111
|
+
}, sessionGeneration?: HarnessSessionGeneration): CodexVirtualHarness;
|
|
105
112
|
workspaces(signal?: AbortSignal): Promise<CodexVirtualWorkspaceView[]>;
|
|
106
113
|
selectWorkspace(workspaceId: string, signal?: AbortSignal): Promise<CodexVirtualWorkspaceView>;
|
|
107
114
|
preferredSessionId(signal?: AbortSignal): Promise<string | undefined>;
|
|
@@ -138,6 +145,8 @@ export declare class CodexVirtualHarness implements RemoteTypertGatewayTarget {
|
|
|
138
145
|
private closeItemStreamBlocks;
|
|
139
146
|
private closeAllStreamBlocks;
|
|
140
147
|
private finishStream;
|
|
148
|
+
private pushAssistantChunk;
|
|
149
|
+
private endAssistantAttempt;
|
|
141
150
|
private ensureToolStarted;
|
|
142
151
|
private emitToolResult;
|
|
143
152
|
private pushToolResult;
|
|
@@ -176,7 +185,7 @@ export declare class CodexVirtualHarness implements RemoteTypertGatewayTarget {
|
|
|
176
185
|
private broadcastRcMux;
|
|
177
186
|
private broadcastRcHost;
|
|
178
187
|
}
|
|
179
|
-
export declare function projectCodexNativeHistory(thread: JsonRecord, sessionId: string): CodexNativeHistory;
|
|
188
|
+
export declare function projectCodexNativeHistory(thread: JsonRecord, sessionId: string, sessionGeneration?: HarnessSessionGeneration): CodexNativeHistory;
|
|
180
189
|
export declare function paginateCodexNativeHistory(history: CodexNativeHistory, request: {
|
|
181
190
|
beforeSeq?: number;
|
|
182
191
|
throughSeq?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-harness.d.ts","sourceRoot":"","sources":["../../src/codex/virtual-harness.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAA2B,MAAM,oCAAoC,CAAA;AAC3F,OAAO,EACL,iBAAiB,EAIlB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EAChB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,KAAK,EAAyB,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"virtual-harness.d.ts","sourceRoot":"","sources":["../../src/codex/virtual-harness.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAA2B,MAAM,oCAAoC,CAAA;AAC3F,OAAO,EACL,iBAAiB,EAIlB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EAChB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,KAAK,EAAyB,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAC1F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAoBrE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,wBA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,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,YAAY;YAiBN,iBAAiB;YAgBjB,eAAe;YASf,eAAe;YAIf,mBAAmB;IASjC,OAAO,CAAC,iBAAiB;YAMX,YAAY;YAeZ,aAAa;YAwBb,cAAc;YAQd,aAAa;YAsCb,WAAW;YAgBX,MAAM;YAoCN,UAAU;YAiBV,uBAAuB;YAQvB,MAAM;YAQN,aAAa;YAWb,WAAW;IAUzB,OAAO,CAAC,YAAY;YAKN,WAAW;YAOX,eAAe;IAuC7B,OAAO,CAAC,kBAAkB;YAMZ,cAAc;YAiCd,cAAc;IAuD5B,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,kCAAkC;YAM5B,2BAA2B;IAKzC,OAAO,CAAC,wBAAwB;IAShC,OAAO,CAAC,cAAc;YAkEP,KAAK;YAgBL,MAAM;IAWrB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,eAAe;CAIxB;AA2JD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,MAAM,EACjB,iBAAiB,GAAE,wBAAmC,GACrD,kBAAkB,CAqFpB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GACzE,sBAAsB,CAwBxB"}
|
|
@@ -32,6 +32,7 @@ export async function discoverCodexVirtualWorkspaces(client, signal) {
|
|
|
32
32
|
export class CodexVirtualHarness {
|
|
33
33
|
client;
|
|
34
34
|
host;
|
|
35
|
+
sessionGeneration;
|
|
35
36
|
api;
|
|
36
37
|
catalog;
|
|
37
38
|
workspaceStreams = new Set();
|
|
@@ -53,13 +54,14 @@ export class CodexVirtualHarness {
|
|
|
53
54
|
commandSeq = 0;
|
|
54
55
|
selectedWorkspaceId;
|
|
55
56
|
closed = false;
|
|
56
|
-
constructor(client, host) {
|
|
57
|
+
constructor(client, host, sessionGeneration = 'legacy') {
|
|
57
58
|
this.client = client;
|
|
58
59
|
this.host = host;
|
|
60
|
+
this.sessionGeneration = sessionGeneration;
|
|
59
61
|
this.api = this.createApiProxy();
|
|
60
62
|
}
|
|
61
|
-
static remote(core, host) {
|
|
62
|
-
return new CodexVirtualHarness(new CodexRemoteClient(core), host);
|
|
63
|
+
static remote(core, host, sessionGeneration = 'legacy') {
|
|
64
|
+
return new CodexVirtualHarness(new CodexRemoteClient(core), host, sessionGeneration);
|
|
63
65
|
}
|
|
64
66
|
async workspaces(signal) {
|
|
65
67
|
return (await this.refreshCatalog(signal)).workspaces;
|
|
@@ -456,6 +458,7 @@ export class CodexVirtualHarness {
|
|
|
456
458
|
streamedBlocks: new Map(),
|
|
457
459
|
nextBlockIndex: 0,
|
|
458
460
|
streamActive: false,
|
|
461
|
+
assistantStreamRevision: 0,
|
|
459
462
|
liveItems: new Map(),
|
|
460
463
|
liveToolOutput: new Map(),
|
|
461
464
|
liveToolResultSeq: new Map(),
|
|
@@ -480,6 +483,7 @@ export class CodexVirtualHarness {
|
|
|
480
483
|
imageLimits: codexImageLimitsProjection(),
|
|
481
484
|
},
|
|
482
485
|
},
|
|
486
|
+
...(this.sessionGeneration === 'v3' ? { assistantStream: { revision: 0 } } : {}),
|
|
483
487
|
});
|
|
484
488
|
try {
|
|
485
489
|
const stream = await this.client.subscribe(threadId, frame => this.acceptCodexFrame(follow, frame), signal, () => this.closeFollowAfterRemoteStreamClosed(follow));
|
|
@@ -514,6 +518,7 @@ export class CodexVirtualHarness {
|
|
|
514
518
|
}
|
|
515
519
|
if (frame.method === 'turn/started') {
|
|
516
520
|
const turn = record(params.turn);
|
|
521
|
+
this.endAssistantAttempt(follow, { kind: 'abandoned' });
|
|
517
522
|
this.resetLiveTurn(follow);
|
|
518
523
|
follow.turn += 1;
|
|
519
524
|
follow.activeTurnId = string(turn.id);
|
|
@@ -650,6 +655,7 @@ export class CodexVirtualHarness {
|
|
|
650
655
|
this.closeAllStreamBlocks(follow);
|
|
651
656
|
if (follow.streamActive)
|
|
652
657
|
this.finishStream(follow);
|
|
658
|
+
this.endAssistantAttempt(follow, { kind: 'abandoned' });
|
|
653
659
|
this.pushEvent(follow, 'step/end', { turn: follow.turn, step: 1 });
|
|
654
660
|
follow.stepOpen = false;
|
|
655
661
|
}
|
|
@@ -695,13 +701,24 @@ export class CodexVirtualHarness {
|
|
|
695
701
|
if (type === 'agentMessage' && follow.streamActive && follow.streamedBlocks.size === 0)
|
|
696
702
|
this.finishStream(follow);
|
|
697
703
|
const supplementalImages = type === 'agentMessage' ? follow.pendingToolImages : [];
|
|
704
|
+
let assistantMessageSeq;
|
|
698
705
|
for (const event of itemEvents(item, follow.turn, 1, follow.requestId, this.modelSelection(follow.sessionId), follow.sessionId, supplementalImages)) {
|
|
699
706
|
if (event.type === 'tool/call' && follow.startedItems.has(itemId))
|
|
700
707
|
continue;
|
|
701
708
|
if (event.type === 'tool/result')
|
|
702
709
|
this.pushToolResult(follow, itemId, event);
|
|
703
|
-
else
|
|
704
|
-
this.pushEvent(follow, event.type, event.data, event.view);
|
|
710
|
+
else {
|
|
711
|
+
const seq = this.pushEvent(follow, event.type, event.data, event.view);
|
|
712
|
+
if (event.type === 'assistant/message')
|
|
713
|
+
assistantMessageSeq = seq;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
if (type === 'agentMessage' && assistantMessageSeq !== undefined) {
|
|
717
|
+
this.endAssistantAttempt(follow, {
|
|
718
|
+
kind: 'committed',
|
|
719
|
+
eventType: 'assistant/message',
|
|
720
|
+
seq: assistantMessageSeq,
|
|
721
|
+
});
|
|
705
722
|
}
|
|
706
723
|
if (type === 'agentMessage' && supplementalImages.length > 0)
|
|
707
724
|
follow.pendingToolImages = [];
|
|
@@ -719,24 +736,25 @@ export class CodexVirtualHarness {
|
|
|
719
736
|
type,
|
|
720
737
|
seq,
|
|
721
738
|
time: Date.now(),
|
|
722
|
-
data,
|
|
739
|
+
data: adaptEventData(type, type === 'assistant/message' && this.sessionGeneration === 'v3' && follow.assistantAttempt !== undefined
|
|
740
|
+
? { ...record(data), stream: follow.assistantAttempt.stream }
|
|
741
|
+
: data, this.sessionGeneration),
|
|
723
742
|
...(isSurfaceEvent(type)
|
|
724
743
|
? placement === undefined
|
|
725
744
|
? { surfaceOp: 'append' }
|
|
726
745
|
: {
|
|
727
|
-
surfaceOp:
|
|
746
|
+
surfaceOp: this.sessionGeneration === 'v3'
|
|
747
|
+
? { op: 'replace', startSeq: placement.replaceSeq, endSeq: placement.replaceSeq }
|
|
748
|
+
: { op: 'replace', start: placement.replaceSeq, end: placement.replaceSeq },
|
|
728
749
|
sourceEventSeqs: [placement.replaceSeq],
|
|
729
750
|
}
|
|
730
751
|
: {}),
|
|
731
752
|
};
|
|
732
753
|
this.cacheImageBlocks(follow.sessionId, event.data);
|
|
733
754
|
if (!follow.rcOnly) {
|
|
734
|
-
const alphaEvent = typeof event.surfaceOp === 'object'
|
|
735
|
-
? { ...event, surfaceOp: 'replace' }
|
|
736
|
-
: event;
|
|
737
755
|
follow.queue.push({
|
|
738
756
|
type: 'event',
|
|
739
|
-
event
|
|
757
|
+
event,
|
|
740
758
|
...(view === undefined ? {} : { view }),
|
|
741
759
|
});
|
|
742
760
|
}
|
|
@@ -765,52 +783,100 @@ export class CodexVirtualHarness {
|
|
|
765
783
|
const block = { itemId, index: follow.nextBlockIndex++, kind, text: '' };
|
|
766
784
|
follow.streamedBlocks.set(key, block);
|
|
767
785
|
follow.streamActive = true;
|
|
768
|
-
this.
|
|
769
|
-
turn: follow.turn,
|
|
770
|
-
step: 1,
|
|
771
|
-
chunk: { type: 'block-start', index: block.index, blockType: kind },
|
|
772
|
-
});
|
|
786
|
+
this.pushAssistantChunk(follow, { type: 'block-start', index: block.index, blockType: kind });
|
|
773
787
|
return block;
|
|
774
788
|
}
|
|
775
789
|
appendStreamDelta(follow, key, itemId, kind, delta) {
|
|
776
790
|
const block = this.ensureStreamBlock(follow, key, itemId, kind);
|
|
777
791
|
block.text = appendBoundedText(block.text, delta);
|
|
778
|
-
this.
|
|
779
|
-
|
|
780
|
-
step: 1,
|
|
781
|
-
chunk: { type: kind === 'reasoning' ? 'reasoning-delta' : 'text-delta', index: block.index, text: delta },
|
|
792
|
+
this.pushAssistantChunk(follow, {
|
|
793
|
+
type: kind === 'reasoning' ? 'reasoning-delta' : 'text-delta', index: block.index, text: delta,
|
|
782
794
|
});
|
|
783
795
|
}
|
|
784
796
|
closeItemStreamBlocks(follow, itemId, fallback) {
|
|
785
797
|
const matches = [...follow.streamedBlocks].filter(([, block]) => block.itemId === itemId);
|
|
786
798
|
for (const [key, block] of matches) {
|
|
787
799
|
const text = block.text || fallback || '';
|
|
788
|
-
this.
|
|
789
|
-
|
|
790
|
-
step: 1,
|
|
791
|
-
chunk: { type: 'block-end', index: block.index, block: { type: block.kind, text } },
|
|
800
|
+
this.pushAssistantChunk(follow, {
|
|
801
|
+
type: 'block-end', index: block.index, block: { type: block.kind, text },
|
|
792
802
|
});
|
|
793
803
|
follow.streamedBlocks.delete(key);
|
|
794
804
|
}
|
|
795
805
|
}
|
|
796
806
|
closeAllStreamBlocks(follow) {
|
|
797
807
|
for (const block of follow.streamedBlocks.values()) {
|
|
798
|
-
this.
|
|
799
|
-
|
|
800
|
-
step: 1,
|
|
801
|
-
chunk: { type: 'block-end', index: block.index, block: { type: block.kind, text: block.text } },
|
|
808
|
+
this.pushAssistantChunk(follow, {
|
|
809
|
+
type: 'block-end', index: block.index, block: { type: block.kind, text: block.text },
|
|
802
810
|
});
|
|
803
811
|
}
|
|
804
812
|
follow.streamedBlocks.clear();
|
|
805
813
|
}
|
|
806
814
|
finishStream(follow) {
|
|
807
|
-
this.
|
|
808
|
-
turn: follow.turn,
|
|
809
|
-
step: 1,
|
|
810
|
-
chunk: { type: 'finish', reason: { kind: 'stop' } },
|
|
811
|
-
});
|
|
815
|
+
this.pushAssistantChunk(follow, { type: 'finish', reason: { kind: 'stop' } });
|
|
812
816
|
follow.streamActive = false;
|
|
813
817
|
}
|
|
818
|
+
pushAssistantChunk(follow, chunk) {
|
|
819
|
+
if (this.sessionGeneration !== 'v3' || follow.rcOnly === true) {
|
|
820
|
+
this.pushEvent(follow, 'assistant/chunk', { turn: follow.turn, step: 1, chunk });
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
let attempt = follow.assistantAttempt;
|
|
824
|
+
if (attempt === undefined) {
|
|
825
|
+
attempt = {
|
|
826
|
+
attemptId: `codex-attempt:${follow.activeTurnId ?? follow.turn}:${follow.nextSeq}`,
|
|
827
|
+
startedAfterSeq: follow.nextSeq - 1,
|
|
828
|
+
nextIndex: 0,
|
|
829
|
+
stream: [],
|
|
830
|
+
};
|
|
831
|
+
follow.assistantAttempt = attempt;
|
|
832
|
+
follow.assistantStreamRevision += 1;
|
|
833
|
+
follow.queue.push({
|
|
834
|
+
type: 'assistant-stream',
|
|
835
|
+
frame: {
|
|
836
|
+
type: 'start',
|
|
837
|
+
attemptId: attempt.attemptId,
|
|
838
|
+
revision: follow.assistantStreamRevision,
|
|
839
|
+
startedAfterSeq: attempt.startedAfterSeq,
|
|
840
|
+
turn: follow.turn,
|
|
841
|
+
step: 1,
|
|
842
|
+
},
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
const time = Date.now();
|
|
846
|
+
const index = attempt.nextIndex++;
|
|
847
|
+
attempt.stream.push({ time, chunk });
|
|
848
|
+
follow.assistantStreamRevision += 1;
|
|
849
|
+
follow.queue.push({
|
|
850
|
+
type: 'assistant-stream',
|
|
851
|
+
frame: {
|
|
852
|
+
type: 'chunk',
|
|
853
|
+
attemptId: attempt.attemptId,
|
|
854
|
+
revision: follow.assistantStreamRevision,
|
|
855
|
+
index,
|
|
856
|
+
time,
|
|
857
|
+
chunk,
|
|
858
|
+
},
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
endAssistantAttempt(follow, outcome) {
|
|
862
|
+
const attempt = follow.assistantAttempt;
|
|
863
|
+
if (attempt === undefined)
|
|
864
|
+
return;
|
|
865
|
+
follow.assistantAttempt = undefined;
|
|
866
|
+
follow.assistantStreamRevision += 1;
|
|
867
|
+
if (this.sessionGeneration === 'v3' && follow.rcOnly !== true) {
|
|
868
|
+
follow.queue.push({
|
|
869
|
+
type: 'assistant-stream',
|
|
870
|
+
frame: {
|
|
871
|
+
type: 'end',
|
|
872
|
+
attemptId: attempt.attemptId,
|
|
873
|
+
revision: follow.assistantStreamRevision,
|
|
874
|
+
index: attempt.nextIndex,
|
|
875
|
+
outcome,
|
|
876
|
+
},
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
}
|
|
814
880
|
ensureToolStarted(follow, item) {
|
|
815
881
|
const itemId = string(item.id);
|
|
816
882
|
if (itemId === undefined)
|
|
@@ -844,6 +910,7 @@ export class CodexVirtualHarness {
|
|
|
844
910
|
follow.streamedBlocks.clear();
|
|
845
911
|
follow.nextBlockIndex = 0;
|
|
846
912
|
follow.streamActive = false;
|
|
913
|
+
follow.assistantAttempt = undefined;
|
|
847
914
|
follow.liveItems.clear();
|
|
848
915
|
follow.liveToolOutput.clear();
|
|
849
916
|
follow.liveToolResultSeq.clear();
|
|
@@ -1148,12 +1215,13 @@ export class CodexVirtualHarness {
|
|
|
1148
1215
|
const thread = record(result.thread);
|
|
1149
1216
|
if (string(thread.id) !== threadId)
|
|
1150
1217
|
throw new Error('CodeX returned an invalid Thread history.');
|
|
1151
|
-
value = paginateCodexNativeHistory(projectCodexNativeHistory(thread, `codex:${threadId}
|
|
1218
|
+
value = paginateCodexNativeHistory(projectCodexNativeHistory(thread, `codex:${threadId}`, this.sessionGeneration), {
|
|
1152
1219
|
beforeSeq: page.beforeSeq,
|
|
1153
1220
|
throughSeq: page.throughSeq,
|
|
1154
1221
|
maxMessages: page.maxMessages,
|
|
1155
1222
|
});
|
|
1156
1223
|
}
|
|
1224
|
+
value = adaptCodexHistoryPage(value, this.sessionGeneration);
|
|
1157
1225
|
if (!isCodexNativeHistoryPage(value, `codex:${threadId}`)) {
|
|
1158
1226
|
throw new Error('CodeX Remote returned an invalid paginated History.');
|
|
1159
1227
|
}
|
|
@@ -1230,6 +1298,7 @@ export class CodexVirtualHarness {
|
|
|
1230
1298
|
streamedBlocks: new Map(),
|
|
1231
1299
|
nextBlockIndex: 0,
|
|
1232
1300
|
streamActive: false,
|
|
1301
|
+
assistantStreamRevision: 0,
|
|
1233
1302
|
liveItems: new Map(),
|
|
1234
1303
|
liveToolOutput: new Map(),
|
|
1235
1304
|
liveToolResultSeq: new Map(),
|
|
@@ -1539,7 +1608,7 @@ async function loadModelDirectory(client, signal) {
|
|
|
1539
1608
|
models,
|
|
1540
1609
|
};
|
|
1541
1610
|
}
|
|
1542
|
-
export function projectCodexNativeHistory(thread, sessionId) {
|
|
1611
|
+
export function projectCodexNativeHistory(thread, sessionId, sessionGeneration = 'legacy') {
|
|
1543
1612
|
const entries = [];
|
|
1544
1613
|
let seq = 0;
|
|
1545
1614
|
let turnNumber = 0;
|
|
@@ -1552,7 +1621,7 @@ export function projectCodexNativeHistory(thread, sessionId) {
|
|
|
1552
1621
|
type,
|
|
1553
1622
|
seq: eventSeq,
|
|
1554
1623
|
time,
|
|
1555
|
-
data,
|
|
1624
|
+
data: adaptEventData(type, data, sessionGeneration),
|
|
1556
1625
|
...(sourceEventSeqs === undefined ? {} : { sourceEventSeqs }),
|
|
1557
1626
|
...(isSurfaceEvent(type) ? { surfaceOp: 'append' } : {}),
|
|
1558
1627
|
},
|
|
@@ -1596,10 +1665,11 @@ export function projectCodexNativeHistory(thread, sessionId) {
|
|
|
1596
1665
|
const projected = projectCodexThread(thread);
|
|
1597
1666
|
return {
|
|
1598
1667
|
header: {
|
|
1599
|
-
version: 1,
|
|
1668
|
+
version: sessionGeneration === 'v3' ? 3 : 1,
|
|
1600
1669
|
id: sessionId,
|
|
1601
1670
|
createdAt: projected?.createdAt ?? Date.now(),
|
|
1602
1671
|
...(projected?.cwd === undefined ? {} : { cwd: projected.cwd }),
|
|
1672
|
+
...(sessionGeneration === 'v3' ? { isSeeded: false } : {}),
|
|
1603
1673
|
},
|
|
1604
1674
|
entries,
|
|
1605
1675
|
lastSeq: seq - 1,
|
|
@@ -1633,6 +1703,54 @@ export function paginateCodexNativeHistory(history, request) {
|
|
|
1633
1703
|
...(history.activeTurnId === undefined ? {} : { activeTurnId: history.activeTurnId }),
|
|
1634
1704
|
};
|
|
1635
1705
|
}
|
|
1706
|
+
function adaptEventData(type, data, sessionGeneration) {
|
|
1707
|
+
if (sessionGeneration !== 'v3' || type !== 'assistant/message')
|
|
1708
|
+
return data;
|
|
1709
|
+
const value = record(data);
|
|
1710
|
+
return Array.isArray(value.stream) ? value : { ...value, stream: [] };
|
|
1711
|
+
}
|
|
1712
|
+
function adaptCodexHistoryPage(value, sessionGeneration) {
|
|
1713
|
+
if (sessionGeneration !== 'v3')
|
|
1714
|
+
return value;
|
|
1715
|
+
const page = record(value);
|
|
1716
|
+
const sourceHeader = record(page.header);
|
|
1717
|
+
const { seedLength: _seedLength, ...header } = sourceHeader;
|
|
1718
|
+
const records = Array.isArray(page.records)
|
|
1719
|
+
? page.records.map(raw => {
|
|
1720
|
+
const entry = record(raw);
|
|
1721
|
+
const sourceEvent = record(entry.event);
|
|
1722
|
+
const sourceSurfaceOp = record(sourceEvent.surfaceOp);
|
|
1723
|
+
const surfaceOp = sourceEvent.surfaceOp === 'append'
|
|
1724
|
+
? 'append'
|
|
1725
|
+
: sourceSurfaceOp.op === 'replace'
|
|
1726
|
+
&& integer(sourceSurfaceOp.startSeq) !== undefined
|
|
1727
|
+
&& integer(sourceSurfaceOp.endSeq) !== undefined
|
|
1728
|
+
? sourceSurfaceOp
|
|
1729
|
+
: sourceSurfaceOp.op === 'replace'
|
|
1730
|
+
&& integer(sourceSurfaceOp.start) !== undefined
|
|
1731
|
+
&& integer(sourceSurfaceOp.end) !== undefined
|
|
1732
|
+
? {
|
|
1733
|
+
op: 'replace',
|
|
1734
|
+
startSeq: sourceSurfaceOp.start,
|
|
1735
|
+
endSeq: sourceSurfaceOp.end,
|
|
1736
|
+
}
|
|
1737
|
+
: sourceEvent.surfaceOp;
|
|
1738
|
+
return {
|
|
1739
|
+
...entry,
|
|
1740
|
+
event: {
|
|
1741
|
+
...sourceEvent,
|
|
1742
|
+
data: adaptEventData(string(sourceEvent.type) ?? '', sourceEvent.data, sessionGeneration),
|
|
1743
|
+
...(surfaceOp === undefined ? {} : { surfaceOp }),
|
|
1744
|
+
},
|
|
1745
|
+
};
|
|
1746
|
+
})
|
|
1747
|
+
: page.records;
|
|
1748
|
+
return {
|
|
1749
|
+
...page,
|
|
1750
|
+
header: { ...header, version: 3, isSeeded: sourceHeader.isSeeded === true },
|
|
1751
|
+
records,
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1636
1754
|
function itemEvents(item, turn, step, requestId, selection = modelSelection(), sessionId = CODEX_SESSION_PREFIX, supplementalImages = []) {
|
|
1637
1755
|
const type = string(item.type);
|
|
1638
1756
|
const id = string(item.id) ?? `${turn}:${step}:${hashString(JSON.stringify(item))}`;
|