@vibefield/puppeteer-adapter-claude 0.3.4 → 0.4.0
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/detection.d.ts +28 -3
- package/dist/detection.d.ts.map +1 -1
- package/dist/detection.js +107 -20
- package/dist/detection.js.map +1 -1
- package/dist/driver.d.ts +25 -4
- package/dist/driver.d.ts.map +1 -1
- package/dist/driver.js +162 -119
- package/dist/driver.js.map +1 -1
- package/dist/generated/forwarder-source.d.ts +6 -0
- package/dist/generated/forwarder-source.d.ts.map +1 -0
- package/dist/generated/forwarder-source.js +8 -0
- package/dist/generated/forwarder-source.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/launch/config-root.d.ts +24 -0
- package/dist/launch/config-root.d.ts.map +1 -0
- package/dist/launch/config-root.js +24 -0
- package/dist/launch/config-root.js.map +1 -0
- package/dist/launch/forwarder.d.ts +25 -0
- package/dist/launch/forwarder.d.ts.map +1 -0
- package/dist/launch/forwarder.js +112 -0
- package/dist/launch/forwarder.js.map +1 -0
- package/dist/launch/prepare.d.ts +28 -6
- package/dist/launch/prepare.d.ts.map +1 -1
- package/dist/launch/prepare.js +75 -84
- package/dist/launch/prepare.js.map +1 -1
- package/dist/launch/settings.d.ts +12 -8
- package/dist/launch/settings.d.ts.map +1 -1
- package/dist/launch/settings.js +12 -22
- package/dist/launch/settings.js.map +1 -1
- package/dist/normalization/pipeline.d.ts +34 -8
- package/dist/normalization/pipeline.d.ts.map +1 -1
- package/dist/normalization/pipeline.js +131 -50
- package/dist/normalization/pipeline.js.map +1 -1
- package/dist/normalization/types.d.ts +21 -0
- package/dist/normalization/types.d.ts.map +1 -1
- package/dist/observation/bounded-json.d.ts +54 -0
- package/dist/observation/bounded-json.d.ts.map +1 -0
- package/dist/observation/bounded-json.js +511 -0
- package/dist/observation/bounded-json.js.map +1 -0
- package/dist/observation/hook-bridge.d.ts +25 -6
- package/dist/observation/hook-bridge.d.ts.map +1 -1
- package/dist/observation/hook-bridge.js +43 -30
- package/dist/observation/hook-bridge.js.map +1 -1
- package/dist/observation/session-selection.d.ts +59 -0
- package/dist/observation/session-selection.d.ts.map +1 -0
- package/dist/observation/session-selection.js +144 -0
- package/dist/observation/session-selection.js.map +1 -0
- package/dist/observation/status-channel.d.ts +0 -6
- package/dist/observation/status-channel.d.ts.map +1 -1
- package/dist/observation/status-channel.js +0 -54
- package/dist/observation/status-channel.js.map +1 -1
- package/dist/observation/transcript/conversation.d.ts +123 -2
- package/dist/observation/transcript/conversation.d.ts.map +1 -1
- package/dist/observation/transcript/conversation.js +390 -56
- package/dist/observation/transcript/conversation.js.map +1 -1
- package/dist/observation/transcript/provider.d.ts.map +1 -1
- package/dist/observation/transcript/provider.js +35 -24
- package/dist/observation/transcript/provider.js.map +1 -1
- package/dist/observation/transcript/services/jsonl-reader.d.ts +7 -1
- package/dist/observation/transcript/services/jsonl-reader.d.ts.map +1 -1
- package/dist/observation/transcript/services/jsonl-reader.js +26 -16
- package/dist/observation/transcript/services/jsonl-reader.js.map +1 -1
- package/dist/observation/transcript/wire.d.ts +26 -2
- package/dist/observation/transcript/wire.d.ts.map +1 -1
- package/dist/observation/transcript/wire.js +52 -9
- package/dist/observation/transcript/wire.js.map +1 -1
- package/dist/services/account-usage.d.ts +26 -19
- package/dist/services/account-usage.d.ts.map +1 -1
- package/dist/services/account-usage.js +25 -43
- package/dist/services/account-usage.js.map +1 -1
- package/dist/services/profiles.d.ts.map +1 -1
- package/dist/services/profiles.js +10 -4
- package/dist/services/profiles.js.map +1 -1
- package/dist/services/prompt.js +1 -1
- package/dist/services/prompt.js.map +1 -1
- package/package.json +11 -6
|
@@ -1,7 +1,129 @@
|
|
|
1
1
|
import type { SemanticObservationEvent } from '../semantic-provider.js';
|
|
2
2
|
import { type ClaudeTranscriptRecord } from './wire.js';
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Extract root assistant messages for live observation without synthesizing historical turns: every row given, walked
|
|
5
|
+
* in causal order from no turn ({@link stepAssistantWalk}). Over a whole transcript this is the unbounded walk, whose
|
|
6
|
+
* turns {@link ClaudeTranscriptProjection} gives every row its window holds. A uuid written again keeps its first row's
|
|
7
|
+
* turn and children, and gives its message its last row's text.
|
|
8
|
+
*/
|
|
4
9
|
export declare function projectClaudeTranscriptAssistants(records: readonly ClaudeTranscriptRecord[]): ReadonlyMap<string, SemanticObservationEvent>;
|
|
10
|
+
/** What changed between two reads of one transcript reader: the rows evicted at its head and appended at its tail. */
|
|
11
|
+
export interface ClaudeTranscriptDelta {
|
|
12
|
+
readonly evicted: readonly ClaudeTranscriptRecord[];
|
|
13
|
+
readonly appended: readonly ClaudeTranscriptRecord[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The assistant projection of one session's transcript window, kept between reads. For every row the window holds, a
|
|
17
|
+
* message's turn is the one the unbounded walk gives it ({@link projectClaudeTranscriptAssistants} over every row the
|
|
18
|
+
* session has written), whichever rows the window still holds. The walk replays the unbounded walk's order with what
|
|
19
|
+
* the window has lost:
|
|
20
|
+
* - The seed. The walk starts in the running turn the unbounded walk is in after the departed rows it passes before
|
|
21
|
+
* every row the walk still holds or keeps: the last prompt passed among them in walk order, not in eviction order.
|
|
22
|
+
* - The departed skeleton. A departed row the unbounded walk may still pass after a held row or a row still to come
|
|
23
|
+
* (it waits on a parent the window holds, or one that has not arrived, or follows such a row) keeps its ids, its file
|
|
24
|
+
* order and whether it opens a turn, never its text, and is walked at its causal place. Once it is first in walk
|
|
25
|
+
* order and nothing can re-place it (its parent has been passed, or it has none), it joins the seed.
|
|
26
|
+
* - A uuid written again moves nothing ({@link stepAssistantWalk}), so a row written again whose first row has left
|
|
27
|
+
* the window adopts none of that row's children and takes its turn.
|
|
28
|
+
* So a departure re-keys no message: an eviction moves rows into the skeleton or the seed and walks nothing.
|
|
29
|
+
*
|
|
30
|
+
* The reader only appends at its tail and evicts at its head, so a read extends the walk by the rows it appended
|
|
31
|
+
* instead of walking again: an appended row whose parent the walk has passed, or has not seen, is causally last
|
|
32
|
+
* (min-index order pops it only when nothing else is ready, and it has no children), so the walk continues from its
|
|
33
|
+
* end. The full walk ({@link ClaudeTranscriptProjection.reproject}) runs at a read with no delta, when an appended row
|
|
34
|
+
* is the parent of a row the walk holds or keeps without its parent (a parent flushed after its child re-orders the
|
|
35
|
+
* walk), and while the last full walk left a cycle, whose rows it orders after every other row, so no appended row is
|
|
36
|
+
* last.
|
|
37
|
+
*
|
|
38
|
+
* Stated limits, each counted in appended rows against the window's own length (`patience`, the rows a read holds):
|
|
39
|
+
* - a departed row waiting on a parent that has not arrived joins the seed once `patience` rows have been appended
|
|
40
|
+
* since it left, so a parent later than that is walked as a new row and re-places nothing;
|
|
41
|
+
* - the seed remembers a uuid it passed for `patience` appended rows after the last row carrying it joined, so a row
|
|
42
|
+
* written again later than that is walked as a first row: a prompt opens its turn again, and rows naming the uuid
|
|
43
|
+
* hang from it;
|
|
44
|
+
* - a read with no delta whose window shares no row (by uuid) with the previous window starts unseeded.
|
|
45
|
+
* The skeleton and the uuids the seed remembers hold ids only, never text, and stay bounded by the window: a departed
|
|
46
|
+
* row stays walked only while a row before it in walk order is held or waits, and a wait ends within `patience`.
|
|
47
|
+
*/
|
|
48
|
+
export declare class ClaudeTranscriptProjection {
|
|
49
|
+
private readonly nativeSessionId;
|
|
50
|
+
/** The running turn after the rows that joined the seed: the departed rows walked before every row still walked. */
|
|
51
|
+
private seed;
|
|
52
|
+
/** The rows still walked, in walk order from `head`: the window's session rows and the departed skeleton. */
|
|
53
|
+
private walked;
|
|
54
|
+
private head;
|
|
55
|
+
/** The window's session rows, in file order, and their walk rows. */
|
|
56
|
+
private readonly held;
|
|
57
|
+
/** The turn each uuid's first pass took: every walked row's, and the seed's while it remembers them. */
|
|
58
|
+
private readonly turns;
|
|
59
|
+
/** The uuids the seed remembers, by the appended-row count at which their last row joined it, oldest first. */
|
|
60
|
+
private readonly seeded;
|
|
61
|
+
/** How many walked rows carry each uuid. */
|
|
62
|
+
private readonly uuids;
|
|
63
|
+
/** Walked rows whose parent the walk has neither passed nor holds, by the parent's uuid: it re-orders them. */
|
|
64
|
+
private readonly orphans;
|
|
65
|
+
/** The turn the walk is in at its causal end. */
|
|
66
|
+
private turnId;
|
|
67
|
+
/** The last full walk left a cycle remainder. */
|
|
68
|
+
private hasCycle;
|
|
69
|
+
/** Rows appended since the first read: the clock a departed row's patience runs on. */
|
|
70
|
+
private appendedRows;
|
|
71
|
+
/** Walk rows made so far: the next one's place in file order. */
|
|
72
|
+
private serials;
|
|
73
|
+
private readonly replies;
|
|
74
|
+
constructor(nativeSessionId: string);
|
|
75
|
+
/** The rows of this session: a row that does not repeat its session id belongs to it. */
|
|
76
|
+
sessionRows(records: readonly ClaudeTranscriptRecord[]): ClaudeTranscriptRecord[];
|
|
77
|
+
/**
|
|
78
|
+
* Takes one read of the window and returns the messages whose turn or text it changed. `delta` is what changed since
|
|
79
|
+
* the previous read; without one the window is walked whole.
|
|
80
|
+
*/
|
|
81
|
+
apply(records: readonly ClaudeTranscriptRecord[], delta: ClaudeTranscriptDelta | undefined): SemanticObservationEvent[];
|
|
82
|
+
/**
|
|
83
|
+
* The full walk: the departed skeleton in file order, then the window's session rows, walked in causal order from the
|
|
84
|
+
* seed. It walks every row it still walks anew; the uuids the seed remembers stay passed.
|
|
85
|
+
*/
|
|
86
|
+
reproject(records: readonly ClaudeTranscriptRecord[]): SemanticObservationEvent[];
|
|
87
|
+
/**
|
|
88
|
+
* A read with no delta: the first read, or a reader that read the file again (new record objects). The rows the old
|
|
89
|
+
* window held that the new one lacks (by uuid, a uuid's earliest rows first) leave first, in file order, so the walk
|
|
90
|
+
* keeps what they gave; a window that shares no row with the old one starts unseeded.
|
|
91
|
+
*/
|
|
92
|
+
private restart;
|
|
93
|
+
private inSession;
|
|
94
|
+
/** A walk row for a record the window now holds, next in file order. */
|
|
95
|
+
private rowOf;
|
|
96
|
+
/** A row the window now holds, walked next: counted by its uuid, and waiting on its parent when the walk lacks it. */
|
|
97
|
+
private hold;
|
|
98
|
+
/** Whether the walk has passed a uuid, or holds or keeps a row carrying it. */
|
|
99
|
+
private present;
|
|
100
|
+
/** Records a walked row whose parent the walk has neither passed nor holds: the parent's arrival re-orders it. */
|
|
101
|
+
private orphanIfAbsent;
|
|
102
|
+
private unorphan;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the appended rows extend the walk, each causally last: none is the parent of a row the walk holds or keeps
|
|
105
|
+
* without its parent, or of an earlier row of the same append, and the last full walk left no cycle. A uuid the walk
|
|
106
|
+
* has passed, written again, re-places nothing: its children stay with its first row.
|
|
107
|
+
*/
|
|
108
|
+
private extendsWalk;
|
|
109
|
+
/**
|
|
110
|
+
* A row the window evicted stays walked as the skeleton's, its ids only, until it joins the seed; its message counts
|
|
111
|
+
* one row fewer, and is forgotten once no window row carries its key.
|
|
112
|
+
*/
|
|
113
|
+
private depart;
|
|
114
|
+
/**
|
|
115
|
+
* Moves the walk's departed head into the seed while nothing can re-place it: a departed row first in walk order
|
|
116
|
+
* whose parent the walk has passed (or that has none), or that has waited `patience` appended rows since it left for
|
|
117
|
+
* a parent that has not arrived. Then forgets the uuids the seed has remembered for `patience` appended rows, unless
|
|
118
|
+
* a walked row still carries one.
|
|
119
|
+
*/
|
|
120
|
+
private joinSeed;
|
|
121
|
+
/**
|
|
122
|
+
* Records the walked messages and returns those whose turn or text changed. An extending walk adds its rows to a
|
|
123
|
+
* key's count; a full walk counts every row the window holds.
|
|
124
|
+
*/
|
|
125
|
+
private settle;
|
|
126
|
+
}
|
|
5
127
|
/**
|
|
6
128
|
* What the transcript shows still open at its end: the root turn the agent is in, and the tools it requested in that
|
|
7
129
|
* turn whose results it has not written. An attach reads it once (the re-attach study, §3.3), so a Claude that was
|
|
@@ -19,5 +141,4 @@ export declare function projectClaudeTranscriptAssistants(records: readonly Clau
|
|
|
19
141
|
* open one would show a working agent that is not, so the rules lean closed.
|
|
20
142
|
*/
|
|
21
143
|
export declare function projectClaudeTranscriptOpenWork(records: readonly ClaudeTranscriptRecord[]): SemanticObservationEvent[];
|
|
22
|
-
export declare function claudeTranscriptConversationFingerprint(value: SemanticObservationEvent): string;
|
|
23
144
|
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../src/observation/transcript/conversation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../src/observation/transcript/conversation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAKL,KAAK,sBAAsB,EAC5B,MAAM,WAAW,CAAC;AAkRnB;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,SAAS,sBAAsB,EAAE,GACzC,WAAW,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAM/C;AAED,sHAAsH;AACtH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,SAAS,sBAAsB,EAAE,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,SAAS,sBAAsB,EAAE,CAAC;CACtD;AAgBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,qBAAa,0BAA0B;IA0BzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAzB5C,oHAAoH;IACpH,OAAO,CAAC,IAAI,CAAqB;IACjC,6GAA6G;IAC7G,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,IAAI,CAAK;IACjB,qEAAqE;IACrE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA8C;IACnE,wGAAwG;IACxG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyC;IAC/D,+GAA+G;IAC/G,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IACpD,4CAA4C;IAC5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;IACnD,+GAA+G;IAC/G,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,iDAAiD;IACjD,OAAO,CAAC,MAAM,CAAqB;IACnC,iDAAiD;IACjD,OAAO,CAAC,QAAQ,CAAS;IACzB,uFAAuF;IACvF,OAAO,CAAC,YAAY,CAAK;IACzB,iEAAiE;IACjE,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;gBAE5B,eAAe,EAAE,MAAM;IAEpD,yFAAyF;IACzF,WAAW,CAAC,OAAO,EAAE,SAAS,sBAAsB,EAAE,GAAG,sBAAsB,EAAE;IAIjF;;;OAGG;IACH,KAAK,CACH,OAAO,EAAE,SAAS,sBAAsB,EAAE,EAC1C,KAAK,EAAE,qBAAqB,GAAG,SAAS,GACvC,wBAAwB,EAAE;IAkB7B;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,SAAS,sBAAsB,EAAE,GAAG,wBAAwB,EAAE;IAwBjF;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAwBf,OAAO,CAAC,SAAS;IAIjB,wEAAwE;IACxE,OAAO,CAAC,KAAK;IAKb,sHAAsH;IACtH,OAAO,CAAC,IAAI;IAQZ,+EAA+E;IAC/E,OAAO,CAAC,OAAO;IAIf,kHAAkH;IAClH,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,QAAQ;IAKhB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAgBnB;;;OAGG;IACH,OAAO,CAAC,MAAM;IAad;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;IAyBhB;;;OAGG;IACH,OAAO,CAAC,MAAM;CAWf;AASD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,SAAS,sBAAsB,EAAE,GACzC,wBAAwB,EAAE,CAuC5B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { claudeQuestionRequestId, normalizeClaudeQuestionRequested, parseClaudeStructuredQuestions, } from '../../normalization/interaction.js';
|
|
2
2
|
import { normalizeClaudeToolRequested } from '../../normalization/tool.js';
|
|
3
|
-
import { safeTranscriptEvidence, transcriptContent,
|
|
3
|
+
import { safeTranscriptEvidence, transcriptContent, transcriptRecordId, transcriptText, } from './wire.js';
|
|
4
4
|
/**
|
|
5
5
|
* The native `turnOrigin` values of a turn a person started: a typed TUI prompt (`human`) or a
|
|
6
6
|
* print-mode / Agent SDK prompt (`sdk`). 2.1.308's own user-started test accepts exactly these;
|
|
@@ -49,12 +49,8 @@ function stripSyntheticUserPreamble(value) {
|
|
|
49
49
|
* once the first row carrying the field arrived.
|
|
50
50
|
*/
|
|
51
51
|
function opensUserTurn(record) {
|
|
52
|
-
if (transcriptContent(record).some((
|
|
53
|
-
const block = transcriptObject(value);
|
|
54
|
-
return block?.type === 'tool_result';
|
|
55
|
-
})) {
|
|
52
|
+
if (transcriptContent(record).some((block) => block.type === 'tool_result'))
|
|
56
53
|
return false;
|
|
57
|
-
}
|
|
58
54
|
if (record.isCompactSummary)
|
|
59
55
|
return false;
|
|
60
56
|
if (record.turnOrigin !== undefined)
|
|
@@ -71,10 +67,7 @@ function observation(event, source, options = {}) {
|
|
|
71
67
|
nativeEvent: safeTranscriptEvidence(source),
|
|
72
68
|
};
|
|
73
69
|
}
|
|
74
|
-
function assistant(record, turnId) {
|
|
75
|
-
const text = transcriptText(record);
|
|
76
|
-
if (!text)
|
|
77
|
-
return undefined;
|
|
70
|
+
function assistant(record, text, turnId) {
|
|
78
71
|
const event = {
|
|
79
72
|
type: 'conversation:assistant-message',
|
|
80
73
|
messageId: transcriptRecordId(record),
|
|
@@ -89,9 +82,12 @@ function assistant(record, turnId) {
|
|
|
89
82
|
* Claude's transcript is a parent-linked graph. Its append workers can flush
|
|
90
83
|
* rows out of physical order during process teardown, so line order alone is
|
|
91
84
|
* not a trustworthy conversation order. Walk each row's known ancestry first
|
|
92
|
-
* while retaining file order for unrelated rows and malformed cycles
|
|
85
|
+
* while retaining file order for unrelated rows and malformed cycles; `cyclic`
|
|
86
|
+
* says a cycle's rows were ordered after every other row. A uuid written more
|
|
87
|
+
* than once adopts children at its first row only, and a uuid `passed` names
|
|
88
|
+
* was walked before these rows, so a row naming it is ready at once.
|
|
93
89
|
*/
|
|
94
|
-
function causalOrder(records) {
|
|
90
|
+
function causalOrder(records, passed = () => false) {
|
|
95
91
|
const firstIndexByUuid = new Map();
|
|
96
92
|
for (const [index, record] of records.entries()) {
|
|
97
93
|
if (record.uuid !== undefined && !firstIndexByUuid.has(record.uuid))
|
|
@@ -100,7 +96,8 @@ function causalOrder(records) {
|
|
|
100
96
|
const children = Array.from({ length: records.length }, () => []);
|
|
101
97
|
const indegree = new Uint8Array(records.length);
|
|
102
98
|
for (const [index, record] of records.entries()) {
|
|
103
|
-
const
|
|
99
|
+
const parent = record.parentUuid;
|
|
100
|
+
const parentIndex = parent === undefined || passed(parent) ? undefined : firstIndexByUuid.get(parent);
|
|
104
101
|
if (parentIndex === undefined || parentIndex === index)
|
|
105
102
|
continue;
|
|
106
103
|
children[parentIndex].push(index);
|
|
@@ -159,52 +156,393 @@ function causalOrder(records) {
|
|
|
159
156
|
}
|
|
160
157
|
// A corrupt cycle has no valid causal order. Retain its physical order so
|
|
161
158
|
// one malformed branch cannot hide otherwise parseable conversation rows.
|
|
159
|
+
let cyclic = false;
|
|
162
160
|
for (const [index, record] of records.entries()) {
|
|
163
|
-
if (emitted[index]
|
|
164
|
-
|
|
161
|
+
if (emitted[index] !== 0)
|
|
162
|
+
continue;
|
|
163
|
+
ordered.push(record);
|
|
164
|
+
cyclic = true;
|
|
165
165
|
}
|
|
166
|
-
return ordered;
|
|
166
|
+
return { ordered, cyclic };
|
|
167
|
+
}
|
|
168
|
+
function walkRow(record, serial) {
|
|
169
|
+
return {
|
|
170
|
+
uuid: record.uuid,
|
|
171
|
+
parentUuid: record.parentUuid,
|
|
172
|
+
serial,
|
|
173
|
+
id: transcriptRecordId(record),
|
|
174
|
+
opens: !record.isSidechain && record.type === 'user' && opensUserTurn(record),
|
|
175
|
+
record,
|
|
176
|
+
departedAt: undefined,
|
|
177
|
+
first: true,
|
|
178
|
+
after: undefined,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** Records a walked reply under its key: the key's last row wins, as in a full walk, and every row is counted. */
|
|
182
|
+
function collect(replies, reply) {
|
|
183
|
+
if (reply)
|
|
184
|
+
replies.set(reply.key, { ...reply, rows: (replies.get(reply.key)?.rows ?? 0) + 1 });
|
|
185
|
+
}
|
|
186
|
+
/** The reply a row is, when it is one: a root (non-sidechain) assistant row with text. */
|
|
187
|
+
function projectedReply(record) {
|
|
188
|
+
// The row type decides: 2.1.308's `api-request-blob` bookkeeping rows echo a user or assistant
|
|
189
|
+
// message and are neither a prompt nor a reply.
|
|
190
|
+
if (record.isSidechain || record.type !== 'assistant')
|
|
191
|
+
return undefined;
|
|
192
|
+
const text = transcriptText(record);
|
|
193
|
+
return text ? { key: transcriptRecordId(record), text } : undefined;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* One row of the assistant walk, the one rule the full walk and the projection's extending walk share. A person's
|
|
197
|
+
* prompt opens its turn, and every other row is in the running turn: the last prompt passed. A uuid the walk has passed
|
|
198
|
+
* moves nothing when it is passed again: it opens no turn, adopts no children ({@link causalOrder} links them to its
|
|
199
|
+
* first row) and keeps its first pass's turn, while a reply written again still gives its key its text. So a row's
|
|
200
|
+
* turn depends only on the rows before it in causal order, never on which of them the window still holds.
|
|
201
|
+
*/
|
|
202
|
+
function stepAssistantWalk(walk, row) {
|
|
203
|
+
row.first = row.uuid === undefined || !walk.turns.has(row.uuid);
|
|
204
|
+
if (row.first && row.opens)
|
|
205
|
+
walk.turnId = row.id;
|
|
206
|
+
const turnId = row.first || row.uuid === undefined ? walk.turnId : walk.turns.get(row.uuid);
|
|
207
|
+
if (row.first && row.uuid !== undefined)
|
|
208
|
+
walk.turns.set(row.uuid, turnId);
|
|
209
|
+
row.after = walk.turnId;
|
|
210
|
+
const { record } = row;
|
|
211
|
+
const reply = record === undefined ? undefined : projectedReply(record);
|
|
212
|
+
if (record === undefined || reply === undefined)
|
|
213
|
+
return undefined;
|
|
214
|
+
return { ...reply, projected: assistant(record, reply.text, turnId) };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The full walk of `rows` (given in file order) in causal order, from the walk's running turn. A uuid already in the
|
|
218
|
+
* walk's turns was passed before these rows: a row naming it is ready at once, and a row carrying it moves nothing.
|
|
219
|
+
*/
|
|
220
|
+
function walkAssistants(rows, walk) {
|
|
221
|
+
const { ordered, cyclic } = causalOrder(rows, (uuid) => walk.turns.has(uuid));
|
|
222
|
+
const replies = new Map();
|
|
223
|
+
for (const row of ordered)
|
|
224
|
+
collect(replies, stepAssistantWalk(walk, row));
|
|
225
|
+
return { ordered, replies, cyclic };
|
|
167
226
|
}
|
|
168
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* Extract root assistant messages for live observation without synthesizing historical turns: every row given, walked
|
|
229
|
+
* in causal order from no turn ({@link stepAssistantWalk}). Over a whole transcript this is the unbounded walk, whose
|
|
230
|
+
* turns {@link ClaudeTranscriptProjection} gives every row its window holds. A uuid written again keeps its first row's
|
|
231
|
+
* turn and children, and gives its message its last row's text.
|
|
232
|
+
*/
|
|
169
233
|
export function projectClaudeTranscriptAssistants(records) {
|
|
234
|
+
const rows = records.map((record, serial) => walkRow(record, serial));
|
|
235
|
+
const { replies } = walkAssistants(rows, { turnId: undefined, turns: new Map() });
|
|
170
236
|
const assistants = new Map();
|
|
171
|
-
|
|
172
|
-
for (const record of causalOrder(records)) {
|
|
173
|
-
if (record.isSidechain)
|
|
174
|
-
continue;
|
|
175
|
-
// The row type decides, never `message.role`: 2.1.308's `api-request-blob` bookkeeping rows
|
|
176
|
-
// carry a user or assistant role and are neither a prompt nor a reply.
|
|
177
|
-
if (record.type === 'user') {
|
|
178
|
-
if (opensUserTurn(record))
|
|
179
|
-
turnId = transcriptRecordId(record);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (record.type !== 'assistant')
|
|
183
|
-
continue;
|
|
184
|
-
const projected = assistant(record, turnId);
|
|
185
|
-
if (!projected)
|
|
186
|
-
continue;
|
|
187
|
-
const key = transcriptRecordId(record);
|
|
237
|
+
for (const [key, { projected }] of replies)
|
|
188
238
|
assistants.set(key, projected);
|
|
189
|
-
}
|
|
190
239
|
return assistants;
|
|
191
240
|
}
|
|
192
|
-
/**
|
|
193
|
-
function
|
|
194
|
-
const
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
241
|
+
/** Moves a key's count by one, forgetting the key at zero. */
|
|
242
|
+
function count(counts, key, by) {
|
|
243
|
+
const next = (counts.get(key) ?? 0) + by;
|
|
244
|
+
if (next > 0)
|
|
245
|
+
counts.set(key, next);
|
|
246
|
+
else
|
|
247
|
+
counts.delete(key);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The assistant projection of one session's transcript window, kept between reads. For every row the window holds, a
|
|
251
|
+
* message's turn is the one the unbounded walk gives it ({@link projectClaudeTranscriptAssistants} over every row the
|
|
252
|
+
* session has written), whichever rows the window still holds. The walk replays the unbounded walk's order with what
|
|
253
|
+
* the window has lost:
|
|
254
|
+
* - The seed. The walk starts in the running turn the unbounded walk is in after the departed rows it passes before
|
|
255
|
+
* every row the walk still holds or keeps: the last prompt passed among them in walk order, not in eviction order.
|
|
256
|
+
* - The departed skeleton. A departed row the unbounded walk may still pass after a held row or a row still to come
|
|
257
|
+
* (it waits on a parent the window holds, or one that has not arrived, or follows such a row) keeps its ids, its file
|
|
258
|
+
* order and whether it opens a turn, never its text, and is walked at its causal place. Once it is first in walk
|
|
259
|
+
* order and nothing can re-place it (its parent has been passed, or it has none), it joins the seed.
|
|
260
|
+
* - A uuid written again moves nothing ({@link stepAssistantWalk}), so a row written again whose first row has left
|
|
261
|
+
* the window adopts none of that row's children and takes its turn.
|
|
262
|
+
* So a departure re-keys no message: an eviction moves rows into the skeleton or the seed and walks nothing.
|
|
263
|
+
*
|
|
264
|
+
* The reader only appends at its tail and evicts at its head, so a read extends the walk by the rows it appended
|
|
265
|
+
* instead of walking again: an appended row whose parent the walk has passed, or has not seen, is causally last
|
|
266
|
+
* (min-index order pops it only when nothing else is ready, and it has no children), so the walk continues from its
|
|
267
|
+
* end. The full walk ({@link ClaudeTranscriptProjection.reproject}) runs at a read with no delta, when an appended row
|
|
268
|
+
* is the parent of a row the walk holds or keeps without its parent (a parent flushed after its child re-orders the
|
|
269
|
+
* walk), and while the last full walk left a cycle, whose rows it orders after every other row, so no appended row is
|
|
270
|
+
* last.
|
|
271
|
+
*
|
|
272
|
+
* Stated limits, each counted in appended rows against the window's own length (`patience`, the rows a read holds):
|
|
273
|
+
* - a departed row waiting on a parent that has not arrived joins the seed once `patience` rows have been appended
|
|
274
|
+
* since it left, so a parent later than that is walked as a new row and re-places nothing;
|
|
275
|
+
* - the seed remembers a uuid it passed for `patience` appended rows after the last row carrying it joined, so a row
|
|
276
|
+
* written again later than that is walked as a first row: a prompt opens its turn again, and rows naming the uuid
|
|
277
|
+
* hang from it;
|
|
278
|
+
* - a read with no delta whose window shares no row (by uuid) with the previous window starts unseeded.
|
|
279
|
+
* The skeleton and the uuids the seed remembers hold ids only, never text, and stay bounded by the window: a departed
|
|
280
|
+
* row stays walked only while a row before it in walk order is held or waits, and a wait ends within `patience`.
|
|
281
|
+
*/
|
|
282
|
+
export class ClaudeTranscriptProjection {
|
|
283
|
+
nativeSessionId;
|
|
284
|
+
/** The running turn after the rows that joined the seed: the departed rows walked before every row still walked. */
|
|
285
|
+
seed;
|
|
286
|
+
/** The rows still walked, in walk order from `head`: the window's session rows and the departed skeleton. */
|
|
287
|
+
walked = [];
|
|
288
|
+
head = 0;
|
|
289
|
+
/** The window's session rows, in file order, and their walk rows. */
|
|
290
|
+
held = new Map();
|
|
291
|
+
/** The turn each uuid's first pass took: every walked row's, and the seed's while it remembers them. */
|
|
292
|
+
turns = new Map();
|
|
293
|
+
/** The uuids the seed remembers, by the appended-row count at which their last row joined it, oldest first. */
|
|
294
|
+
seeded = new Map();
|
|
295
|
+
/** How many walked rows carry each uuid. */
|
|
296
|
+
uuids = new Map();
|
|
297
|
+
/** Walked rows whose parent the walk has neither passed nor holds, by the parent's uuid: it re-orders them. */
|
|
298
|
+
orphans = new Map();
|
|
299
|
+
/** The turn the walk is in at its causal end. */
|
|
300
|
+
turnId;
|
|
301
|
+
/** The last full walk left a cycle remainder. */
|
|
302
|
+
hasCycle = false;
|
|
303
|
+
/** Rows appended since the first read: the clock a departed row's patience runs on. */
|
|
304
|
+
appendedRows = 0;
|
|
305
|
+
/** Walk rows made so far: the next one's place in file order. */
|
|
306
|
+
serials = 0;
|
|
307
|
+
replies = new Map();
|
|
308
|
+
constructor(nativeSessionId) {
|
|
309
|
+
this.nativeSessionId = nativeSessionId;
|
|
310
|
+
}
|
|
311
|
+
/** The rows of this session: a row that does not repeat its session id belongs to it. */
|
|
312
|
+
sessionRows(records) {
|
|
313
|
+
return records.filter((record) => this.inSession(record));
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Takes one read of the window and returns the messages whose turn or text it changed. `delta` is what changed since
|
|
317
|
+
* the previous read; without one the window is walked whole.
|
|
318
|
+
*/
|
|
319
|
+
apply(records, delta) {
|
|
320
|
+
if (delta === undefined)
|
|
321
|
+
return this.restart(records);
|
|
322
|
+
this.appendedRows += delta.appended.length;
|
|
323
|
+
for (const record of delta.evicted)
|
|
324
|
+
this.depart(record);
|
|
325
|
+
this.joinSeed(records.length);
|
|
326
|
+
if (!this.extendsWalk(delta.appended))
|
|
327
|
+
return this.reproject(records);
|
|
328
|
+
const walk = { turnId: this.turnId, turns: this.turns };
|
|
329
|
+
const walked = new Map();
|
|
330
|
+
for (const record of delta.appended) {
|
|
331
|
+
if (!this.inSession(record))
|
|
332
|
+
continue;
|
|
333
|
+
const row = this.hold(record);
|
|
334
|
+
this.walked.push(row);
|
|
335
|
+
collect(walked, stepAssistantWalk(walk, row));
|
|
336
|
+
}
|
|
337
|
+
this.turnId = walk.turnId;
|
|
338
|
+
return this.settle(walked, true);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* The full walk: the departed skeleton in file order, then the window's session rows, walked in causal order from the
|
|
342
|
+
* seed. It walks every row it still walks anew; the uuids the seed remembers stay passed.
|
|
343
|
+
*/
|
|
344
|
+
reproject(records) {
|
|
345
|
+
const walked = this.walked.slice(this.head);
|
|
346
|
+
for (const row of walked)
|
|
347
|
+
if (row.first && row.uuid !== undefined)
|
|
348
|
+
this.turns.delete(row.uuid);
|
|
349
|
+
const skeleton = walked.filter((row) => row.departedAt !== undefined).sort((a, b) => a.serial - b.serial);
|
|
350
|
+
const rows = [...skeleton, ...this.sessionRows(records).map((record) => this.rowOf(record))];
|
|
351
|
+
this.held.clear();
|
|
352
|
+
this.uuids.clear();
|
|
353
|
+
this.orphans.clear();
|
|
354
|
+
for (const row of rows) {
|
|
355
|
+
if (row.record !== undefined)
|
|
356
|
+
this.held.set(row.record, row);
|
|
357
|
+
if (row.uuid !== undefined)
|
|
358
|
+
count(this.uuids, row.uuid, 1);
|
|
359
|
+
}
|
|
360
|
+
for (const row of rows)
|
|
361
|
+
this.orphanIfAbsent(row);
|
|
362
|
+
const walk = { turnId: this.seed, turns: this.turns };
|
|
363
|
+
const { ordered, replies, cyclic } = walkAssistants(rows, walk);
|
|
364
|
+
this.walked = ordered;
|
|
365
|
+
this.head = 0;
|
|
366
|
+
this.turnId = walk.turnId;
|
|
367
|
+
this.hasCycle = cyclic;
|
|
368
|
+
const changed = this.settle(replies, false);
|
|
369
|
+
for (const key of this.replies.keys())
|
|
370
|
+
if (!replies.has(key))
|
|
371
|
+
this.replies.delete(key);
|
|
372
|
+
return changed;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* A read with no delta: the first read, or a reader that read the file again (new record objects). The rows the old
|
|
376
|
+
* window held that the new one lacks (by uuid, a uuid's earliest rows first) leave first, in file order, so the walk
|
|
377
|
+
* keeps what they gave; a window that shares no row with the old one starts unseeded.
|
|
378
|
+
*/
|
|
379
|
+
restart(records) {
|
|
380
|
+
const carried = new Map();
|
|
381
|
+
for (const record of this.sessionRows(records))
|
|
382
|
+
if (record.uuid !== undefined)
|
|
383
|
+
count(carried, record.uuid, 1);
|
|
384
|
+
const old = [...this.held.keys()];
|
|
385
|
+
if (old.some(({ uuid }) => uuid !== undefined && carried.has(uuid))) {
|
|
386
|
+
const unmatched = new Map();
|
|
387
|
+
for (const { uuid } of old)
|
|
388
|
+
if (uuid !== undefined)
|
|
389
|
+
count(unmatched, uuid, 1);
|
|
390
|
+
for (const record of old) {
|
|
391
|
+
const { uuid } = record;
|
|
392
|
+
if (uuid !== undefined && (unmatched.get(uuid) ?? 0) <= (carried.get(uuid) ?? 0))
|
|
393
|
+
continue;
|
|
394
|
+
if (uuid !== undefined)
|
|
395
|
+
count(unmatched, uuid, -1);
|
|
396
|
+
this.depart(record);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
this.seed = undefined;
|
|
401
|
+
this.walked = [];
|
|
402
|
+
this.head = 0;
|
|
403
|
+
this.turns.clear();
|
|
404
|
+
this.seeded.clear();
|
|
405
|
+
}
|
|
406
|
+
this.joinSeed(records.length);
|
|
407
|
+
return this.reproject(records);
|
|
408
|
+
}
|
|
409
|
+
inSession(record) {
|
|
410
|
+
return !record.sessionId || record.sessionId === this.nativeSessionId;
|
|
411
|
+
}
|
|
412
|
+
/** A walk row for a record the window now holds, next in file order. */
|
|
413
|
+
rowOf(record) {
|
|
414
|
+
this.serials += 1;
|
|
415
|
+
return walkRow(record, this.serials);
|
|
416
|
+
}
|
|
417
|
+
/** A row the window now holds, walked next: counted by its uuid, and waiting on its parent when the walk lacks it. */
|
|
418
|
+
hold(record) {
|
|
419
|
+
const row = this.rowOf(record);
|
|
420
|
+
this.held.set(record, row);
|
|
421
|
+
if (row.uuid !== undefined)
|
|
422
|
+
count(this.uuids, row.uuid, 1);
|
|
423
|
+
this.orphanIfAbsent(row);
|
|
424
|
+
return row;
|
|
425
|
+
}
|
|
426
|
+
/** Whether the walk has passed a uuid, or holds or keeps a row carrying it. */
|
|
427
|
+
present(uuid) {
|
|
428
|
+
return this.uuids.has(uuid) || this.turns.has(uuid);
|
|
429
|
+
}
|
|
430
|
+
/** Records a walked row whose parent the walk has neither passed nor holds: the parent's arrival re-orders it. */
|
|
431
|
+
orphanIfAbsent(row) {
|
|
432
|
+
const parent = row.parentUuid;
|
|
433
|
+
if (parent === undefined || this.present(parent))
|
|
434
|
+
return;
|
|
435
|
+
const waiting = this.orphans.get(parent);
|
|
436
|
+
if (waiting)
|
|
437
|
+
waiting.add(row);
|
|
438
|
+
else
|
|
439
|
+
this.orphans.set(parent, new Set([row]));
|
|
440
|
+
}
|
|
441
|
+
unorphan(parent, row) {
|
|
442
|
+
const waiting = this.orphans.get(parent);
|
|
443
|
+
if (waiting?.delete(row) && waiting.size === 0)
|
|
444
|
+
this.orphans.delete(parent);
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Whether the appended rows extend the walk, each causally last: none is the parent of a row the walk holds or keeps
|
|
448
|
+
* without its parent, or of an earlier row of the same append, and the last full walk left no cycle. A uuid the walk
|
|
449
|
+
* has passed, written again, re-places nothing: its children stay with its first row.
|
|
450
|
+
*/
|
|
451
|
+
extendsWalk(appended) {
|
|
452
|
+
if (this.hasCycle)
|
|
453
|
+
return false;
|
|
454
|
+
const arriving = new Set();
|
|
455
|
+
const awaited = new Set();
|
|
456
|
+
for (const record of appended) {
|
|
457
|
+
if (!this.inSession(record))
|
|
458
|
+
continue;
|
|
459
|
+
if (record.uuid !== undefined) {
|
|
460
|
+
if (this.orphans.has(record.uuid) || awaited.has(record.uuid))
|
|
461
|
+
return false;
|
|
462
|
+
arriving.add(record.uuid);
|
|
463
|
+
}
|
|
464
|
+
const parent = record.parentUuid;
|
|
465
|
+
if (parent !== undefined && !this.present(parent) && !arriving.has(parent))
|
|
466
|
+
awaited.add(parent);
|
|
467
|
+
}
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* A row the window evicted stays walked as the skeleton's, its ids only, until it joins the seed; its message counts
|
|
472
|
+
* one row fewer, and is forgotten once no window row carries its key.
|
|
473
|
+
*/
|
|
474
|
+
depart(record) {
|
|
475
|
+
const row = this.held.get(record);
|
|
476
|
+
if (row === undefined)
|
|
477
|
+
return;
|
|
478
|
+
this.held.delete(record);
|
|
479
|
+
row.record = undefined;
|
|
480
|
+
row.departedAt = this.appendedRows;
|
|
481
|
+
const reply = projectedReply(record);
|
|
482
|
+
const known = reply === undefined ? undefined : this.replies.get(reply.key);
|
|
483
|
+
if (reply === undefined || known === undefined)
|
|
484
|
+
return;
|
|
485
|
+
if (known.rows > 1)
|
|
486
|
+
this.replies.set(reply.key, { ...known, rows: known.rows - 1 });
|
|
487
|
+
else
|
|
488
|
+
this.replies.delete(reply.key);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Moves the walk's departed head into the seed while nothing can re-place it: a departed row first in walk order
|
|
492
|
+
* whose parent the walk has passed (or that has none), or that has waited `patience` appended rows since it left for
|
|
493
|
+
* a parent that has not arrived. Then forgets the uuids the seed has remembered for `patience` appended rows, unless
|
|
494
|
+
* a walked row still carries one.
|
|
495
|
+
*/
|
|
496
|
+
joinSeed(patience) {
|
|
497
|
+
while (this.head < this.walked.length) {
|
|
498
|
+
const row = this.walked[this.head];
|
|
499
|
+
if (row.departedAt === undefined)
|
|
500
|
+
break;
|
|
501
|
+
const waits = row.parentUuid !== undefined && !this.turns.has(row.parentUuid);
|
|
502
|
+
if (waits && this.appendedRows - row.departedAt < patience)
|
|
503
|
+
break;
|
|
504
|
+
this.head += 1;
|
|
505
|
+
this.seed = row.after;
|
|
506
|
+
if (row.parentUuid !== undefined)
|
|
507
|
+
this.unorphan(row.parentUuid, row);
|
|
508
|
+
if (row.uuid === undefined)
|
|
509
|
+
continue;
|
|
510
|
+
count(this.uuids, row.uuid, -1);
|
|
511
|
+
this.seeded.delete(row.uuid);
|
|
512
|
+
this.seeded.set(row.uuid, this.appendedRows);
|
|
513
|
+
}
|
|
514
|
+
if (this.head * 2 > this.walked.length) {
|
|
515
|
+
this.walked = this.walked.slice(this.head);
|
|
516
|
+
this.head = 0;
|
|
517
|
+
}
|
|
518
|
+
for (const [uuid, at] of this.seeded) {
|
|
519
|
+
if (this.appendedRows - at < patience)
|
|
520
|
+
break;
|
|
521
|
+
this.seeded.delete(uuid);
|
|
522
|
+
if (!this.uuids.has(uuid))
|
|
523
|
+
this.turns.delete(uuid);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Records the walked messages and returns those whose turn or text changed. An extending walk adds its rows to a
|
|
528
|
+
* key's count; a full walk counts every row the window holds.
|
|
529
|
+
*/
|
|
530
|
+
settle(walked, extending) {
|
|
531
|
+
const changed = [];
|
|
532
|
+
for (const [key, reply] of walked) {
|
|
533
|
+
const known = this.replies.get(key);
|
|
534
|
+
const { turnId } = reply.projected;
|
|
535
|
+
if (known === undefined || known.turnId !== turnId || known.text !== reply.text)
|
|
536
|
+
changed.push(reply.projected);
|
|
537
|
+
const rows = extending && known !== undefined ? known.rows + reply.rows : reply.rows;
|
|
538
|
+
this.replies.set(key, { turnId, text: reply.text, rows });
|
|
539
|
+
}
|
|
540
|
+
return changed;
|
|
541
|
+
}
|
|
200
542
|
}
|
|
201
543
|
/** The tool calls a `user` row answers: the ids its `tool_result` blocks name. */
|
|
202
544
|
function answeredToolIds(record) {
|
|
203
|
-
return transcriptContent(record).flatMap((
|
|
204
|
-
const block = transcriptObject(value);
|
|
205
|
-
const id = block?.type === 'tool_result' ? transcriptString(block.tool_use_id) : undefined;
|
|
206
|
-
return id ? [id] : [];
|
|
207
|
-
});
|
|
545
|
+
return transcriptContent(record).flatMap((block) => block.type === 'tool_result' && block.tool_use_id !== undefined ? [block.tool_use_id] : []);
|
|
208
546
|
}
|
|
209
547
|
/**
|
|
210
548
|
* What the transcript shows still open at its end: the root turn the agent is in, and the tools it requested in that
|
|
@@ -226,7 +564,7 @@ export function projectClaudeTranscriptOpenWork(records) {
|
|
|
226
564
|
let prompt;
|
|
227
565
|
let owed = false;
|
|
228
566
|
const tools = new Map();
|
|
229
|
-
for (const record of causalOrder(records)) {
|
|
567
|
+
for (const record of causalOrder(records).ordered) {
|
|
230
568
|
if (record.isSidechain)
|
|
231
569
|
continue;
|
|
232
570
|
if (record.type === 'user') {
|
|
@@ -248,10 +586,9 @@ export function projectClaudeTranscriptOpenWork(records) {
|
|
|
248
586
|
}
|
|
249
587
|
if (record.type !== 'assistant')
|
|
250
588
|
continue;
|
|
251
|
-
for (const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
tools.set(tool.id, { record, name: tool.name, input: tool.input });
|
|
589
|
+
for (const block of transcriptContent(record)) {
|
|
590
|
+
if (block.type === 'tool_use')
|
|
591
|
+
tools.set(block.id, { record, name: block.name, input: block.input });
|
|
255
592
|
}
|
|
256
593
|
owed = false;
|
|
257
594
|
}
|
|
@@ -269,7 +606,4 @@ export function projectClaudeTranscriptOpenWork(records) {
|
|
|
269
606
|
}
|
|
270
607
|
return open;
|
|
271
608
|
}
|
|
272
|
-
export function claudeTranscriptConversationFingerprint(value) {
|
|
273
|
-
return JSON.stringify([value.turnId ?? null, value.event]);
|
|
274
|
-
}
|
|
275
609
|
//# sourceMappingURL=conversation.js.map
|