@relayflows/sdk 2.0.26 → 2.0.27
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/cloud-transcript-codex.d.ts +42 -0
- package/dist/cloud-transcript-codex.d.ts.map +1 -0
- package/dist/cloud-transcript-codex.js +411 -0
- package/dist/cloud-transcript-codex.js.map +1 -0
- package/dist/cloud-transcript-types.d.ts +161 -0
- package/dist/cloud-transcript-types.d.ts.map +1 -0
- package/dist/cloud-transcript-types.js +47 -0
- package/dist/cloud-transcript-types.js.map +1 -0
- package/dist/cloud-transcript.d.ts +2 -78
- package/dist/cloud-transcript.d.ts.map +1 -1
- package/dist/cloud-transcript.js +36 -38
- package/dist/cloud-transcript.js.map +1 -1
- package/package.json +2 -2
- package/src/cloud-transcript-codex.ts +429 -0
- package/src/cloud-transcript-types.ts +214 -0
- package/src/cloud-transcript.ts +44 -136
package/src/cloud-transcript.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// Rendering an agent step's transcript JSONL for a terminal.
|
|
2
2
|
//
|
|
3
|
-
// The frames are what the harness wrote
|
|
4
|
-
// by the `relayflow.attempt` markers the v2
|
|
5
|
-
// assembles one log out of several attempts.
|
|
6
|
-
// the one Cloud's dashboard renderer
|
|
7
|
-
// `packages/web/lib/workflows/agent-transcript.ts`) -- the
|
|
8
|
-
// CLI and the dashboard agree about what a run did. The
|
|
9
|
-
// shared: this package cannot import from the Cloud app,
|
|
10
|
-
// be deployed in step with a dashboard would be worse
|
|
3
|
+
// The frames are what the harness wrote -- Claude Code's `stream-json`, or
|
|
4
|
+
// `codex exec --json` -- wrapped by the `relayflow.attempt` markers the v2
|
|
5
|
+
// executor interleaves when it assembles one log out of several attempts.
|
|
6
|
+
// The Claude frame vocabulary read here is the one Cloud's dashboard renderer
|
|
7
|
+
// reads (cloud#3847, `packages/web/lib/workflows/agent-transcript.ts`) -- the
|
|
8
|
+
// same shapes, so the CLI and the dashboard agree about what a run did. The
|
|
9
|
+
// implementation is not shared: this package cannot import from the Cloud app,
|
|
10
|
+
// and a CLI that had to be deployed in step with a dashboard would be worse
|
|
11
|
+
// than one that does not. The Codex vocabulary lives in
|
|
12
|
+
// `cloud-transcript-codex.ts`; dispatch is per frame, not per provider, so a
|
|
13
|
+
// log that mixes them stays honest rather than being forced into a guess.
|
|
11
14
|
//
|
|
12
15
|
// Two rules the shapes do not give you:
|
|
13
16
|
//
|
|
@@ -19,98 +22,21 @@
|
|
|
19
22
|
// the redactor `flows status` uses. Transcript text is whatever the agent
|
|
20
23
|
// printed, including anything it read out of its own environment.
|
|
21
24
|
|
|
25
|
+
import {
|
|
26
|
+
CODEX_FRAME_TYPES, codexFrame, indexCodexItems, renderCodexEntry, type CodexState,
|
|
27
|
+
} from './cloud-transcript-codex.js';
|
|
28
|
+
import {
|
|
29
|
+
TARGET_MAX_CHARS, isRecord, num, oneLine, safe, separator, str, thousands,
|
|
30
|
+
type ParsedTranscript, type TranscriptEntry,
|
|
31
|
+
} from './cloud-transcript-types.js';
|
|
22
32
|
import { redact } from './redact.js';
|
|
23
33
|
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface TranscriptAttemptOmitted {
|
|
32
|
-
kind: 'attempt_omitted';
|
|
33
|
-
attempt: number | null;
|
|
34
|
-
bytes: number | null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface TranscriptInit {
|
|
38
|
-
kind: 'init';
|
|
39
|
-
model: string | null;
|
|
40
|
-
version: string | null;
|
|
41
|
-
permission_mode: string | null;
|
|
42
|
-
tools: number | null;
|
|
43
|
-
mcp_servers: number | null;
|
|
44
|
-
session_id: string | null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface TranscriptMessage {
|
|
48
|
-
kind: 'message';
|
|
49
|
-
role: 'assistant' | 'user';
|
|
50
|
-
text: string;
|
|
51
|
-
/** A frame carrying `parent_tool_use_id`: a subagent's turn, not the main one. */
|
|
52
|
-
nested: boolean;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface TranscriptThinking {
|
|
56
|
-
kind: 'thinking';
|
|
57
|
-
/** The count only. A thinking block's text and signature never reach the page. */
|
|
58
|
-
chars: number;
|
|
59
|
-
nested: boolean;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface TranscriptTool {
|
|
63
|
-
kind: 'tool';
|
|
64
|
-
name: string;
|
|
65
|
-
/** What the call was aimed at: a path, a command, a pattern. Null when the input had no string. */
|
|
66
|
-
target: string | null;
|
|
67
|
-
/** Null when no `tool_result` answered it -- not the same fact as a zero-byte result. */
|
|
68
|
-
result_chars: number | null;
|
|
69
|
-
is_error: boolean;
|
|
70
|
-
nested: boolean;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface TranscriptResult {
|
|
74
|
-
kind: 'result';
|
|
75
|
-
is_error: boolean;
|
|
76
|
-
subtype: string | null;
|
|
77
|
-
duration_ms: number | null;
|
|
78
|
-
num_turns: number | null;
|
|
79
|
-
total_cost_usd: number | null;
|
|
80
|
-
tokens_in: number | null;
|
|
81
|
-
tokens_out: number | null;
|
|
82
|
-
cache_read: number | null;
|
|
83
|
-
cache_creation: number | null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface TranscriptUnknown {
|
|
87
|
-
kind: 'unknown';
|
|
88
|
-
type: string;
|
|
89
|
-
chars: number;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface TranscriptUnparsed {
|
|
93
|
-
kind: 'unparsed';
|
|
94
|
-
text: string;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export type TranscriptEntry =
|
|
98
|
-
| TranscriptAttempt | TranscriptAttemptOmitted | TranscriptInit | TranscriptMessage
|
|
99
|
-
| TranscriptThinking | TranscriptTool | TranscriptResult | TranscriptUnknown | TranscriptUnparsed;
|
|
100
|
-
|
|
101
|
-
export interface ParsedTranscript {
|
|
102
|
-
entries: TranscriptEntry[];
|
|
103
|
-
/** How many attempts said their head was cut to fit the log cap. */
|
|
104
|
-
truncated_attempts: number;
|
|
105
|
-
/** How many attempts were dropped whole to fit the log cap. */
|
|
106
|
-
omitted_attempts: number;
|
|
107
|
-
/**
|
|
108
|
-
* False when the log carried no frame this vocabulary knows -- a v1
|
|
109
|
-
* plain-terminal sandbox log, say. The caller prints it raw rather than
|
|
110
|
-
* claiming an empty transcript.
|
|
111
|
-
*/
|
|
112
|
-
stream_json: boolean;
|
|
113
|
-
}
|
|
34
|
+
export type {
|
|
35
|
+
ParsedTranscript, TranscriptEntry, TranscriptAttempt, TranscriptAttemptOmitted, TranscriptError,
|
|
36
|
+
TranscriptFileChange, TranscriptInit, TranscriptMessage, TranscriptResult, TranscriptThinking,
|
|
37
|
+
TranscriptThread, TranscriptTool, TranscriptToolCodex, TranscriptTurn, TranscriptUnknown,
|
|
38
|
+
TranscriptUnparsed,
|
|
39
|
+
} from './cloud-transcript-types.js';
|
|
114
40
|
|
|
115
41
|
/**
|
|
116
42
|
* Which input field names a tool call. Order matters: the first present
|
|
@@ -122,26 +48,6 @@ const TARGET_KEYS = [
|
|
|
122
48
|
'prompt', 'description', 'subagent_type',
|
|
123
49
|
] as const;
|
|
124
50
|
|
|
125
|
-
const TARGET_MAX_CHARS = 160;
|
|
126
|
-
|
|
127
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
128
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function str(value: unknown): string | null {
|
|
132
|
-
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function num(value: unknown): number | null {
|
|
136
|
-
return typeof value === 'number' && Number.isFinite(value) ? value : null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Collapse to one line and bound it; a tool input can be a whole file body. */
|
|
140
|
-
function oneLine(text: string, limit = TARGET_MAX_CHARS): string {
|
|
141
|
-
const flat = text.replace(/\s+/gu, ' ').trim();
|
|
142
|
-
return flat.length <= limit ? flat : `${flat.slice(0, limit)}…`;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
51
|
/**
|
|
146
52
|
* `clean` runs before `oneLine`, not after, and the order is load-bearing.
|
|
147
53
|
*
|
|
@@ -154,12 +60,12 @@ function toolTarget(input: unknown, clean: (text: string) => string): string | n
|
|
|
154
60
|
if (!isRecord(input)) return null;
|
|
155
61
|
for (const key of TARGET_KEYS) {
|
|
156
62
|
const value = str(input[key]);
|
|
157
|
-
if (value !== null) return oneLine(clean(value));
|
|
63
|
+
if (value !== null) return oneLine(clean(value), TARGET_MAX_CHARS);
|
|
158
64
|
}
|
|
159
65
|
// An unfamiliar tool still shows something rather than nothing.
|
|
160
66
|
for (const value of Object.values(input)) {
|
|
161
67
|
const text = str(value);
|
|
162
|
-
if (text !== null) return oneLine(clean(text));
|
|
68
|
+
if (text !== null) return oneLine(clean(text), TARGET_MAX_CHARS);
|
|
163
69
|
}
|
|
164
70
|
return null;
|
|
165
71
|
}
|
|
@@ -219,13 +125,15 @@ export function parseAgentTranscript(content: string, env: NodeJS.ProcessEnv = p
|
|
|
219
125
|
}
|
|
220
126
|
}
|
|
221
127
|
const results = indexToolResults(frames);
|
|
128
|
+
const codexIndex = indexCodexItems(raw);
|
|
129
|
+
const codexState: CodexState = { seq: 0 };
|
|
222
130
|
const entries: TranscriptEntry[] = [];
|
|
223
131
|
let truncatedAttempts = 0;
|
|
224
132
|
let omittedAttempts = 0;
|
|
225
133
|
let streamJson = false;
|
|
226
134
|
const clean = (text: string): string => redact(text, env);
|
|
227
135
|
|
|
228
|
-
for (const { frame, line } of raw) {
|
|
136
|
+
for (const [index, { frame, line }] of raw.entries()) {
|
|
229
137
|
if (frame === undefined || !isRecord(frame)) {
|
|
230
138
|
entries.push({ kind: 'unparsed', text: clean(line) });
|
|
231
139
|
continue;
|
|
@@ -233,6 +141,8 @@ export function parseAgentTranscript(content: string, env: NodeJS.ProcessEnv = p
|
|
|
233
141
|
const type = str(frame['type']);
|
|
234
142
|
if (type === 'relayflow.attempt') {
|
|
235
143
|
streamJson = true;
|
|
144
|
+
// Calls are numbered within an attempt, so a second attempt starts over.
|
|
145
|
+
codexState.seq = 0;
|
|
236
146
|
const truncated = frame['truncated'] === true;
|
|
237
147
|
if (truncated) truncatedAttempts += 1;
|
|
238
148
|
entries.push({ kind: 'attempt', attempt: num(frame['attempt']), bytes: num(frame['bytes']), truncated });
|
|
@@ -240,10 +150,16 @@ export function parseAgentTranscript(content: string, env: NodeJS.ProcessEnv = p
|
|
|
240
150
|
}
|
|
241
151
|
if (type === 'relayflow.attempt.omitted') {
|
|
242
152
|
streamJson = true;
|
|
153
|
+
codexState.seq = 0;
|
|
243
154
|
omittedAttempts += 1;
|
|
244
155
|
entries.push({ kind: 'attempt_omitted', attempt: num(frame['attempt']), bytes: num(frame['bytes']) });
|
|
245
156
|
continue;
|
|
246
157
|
}
|
|
158
|
+
if (type !== null && CODEX_FRAME_TYPES.has(type)) {
|
|
159
|
+
streamJson = true;
|
|
160
|
+
entries.push(...(codexFrame(frame, type, index, codexIndex, codexState, clean, line) ?? []));
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
247
163
|
if (type === 'system' && frame['subtype'] === 'init') {
|
|
248
164
|
streamJson = true;
|
|
249
165
|
const tools = frame['tools'];
|
|
@@ -327,28 +243,14 @@ export function parseAgentTranscript(content: string, env: NodeJS.ProcessEnv = p
|
|
|
327
243
|
return { entries, truncated_attempts: truncatedAttempts, omitted_attempts: omittedAttempts, stream_json: streamJson };
|
|
328
244
|
}
|
|
329
245
|
|
|
330
|
-
function thousands(value: number): string {
|
|
331
|
-
return String(value).replace(/\B(?=(\d{3})+(?!\d))/gu, ',');
|
|
332
|
-
}
|
|
333
|
-
|
|
334
246
|
function seconds(ms: number): string {
|
|
335
247
|
return ms < 1000 ? `${ms}ms` : `${(ms / 1000).toFixed(1)}s`;
|
|
336
248
|
}
|
|
337
249
|
|
|
338
|
-
/** Terminal control characters never reach the page, wherever the text came from. */
|
|
339
|
-
function safe(text: string): string {
|
|
340
|
-
return text.replace(/[\u0000-\u0009\u000B-\u001F\u007F-\u009F]/gu, '?');
|
|
341
|
-
}
|
|
342
|
-
|
|
343
250
|
function dollars(value: number): string {
|
|
344
251
|
return `$${value.toFixed(6).replace(/0+$/u, '').replace(/\.$/u, '')}`;
|
|
345
252
|
}
|
|
346
253
|
|
|
347
|
-
/** One rule with a label, the way an attempt boundary reads. */
|
|
348
|
-
function separator(label: string): string {
|
|
349
|
-
return `── ${label} ${'─'.repeat(Math.max(2, 68 - label.length))}`;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
254
|
/**
|
|
353
255
|
* Render a parsed transcript as terminal lines.
|
|
354
256
|
*
|
|
@@ -359,6 +261,11 @@ function separator(label: string): string {
|
|
|
359
261
|
export function renderAgentTranscript(parsed: ParsedTranscript): string[] {
|
|
360
262
|
const lines: string[] = [];
|
|
361
263
|
for (const entry of parsed.entries) {
|
|
264
|
+
// A Codex tool call carries its exit code, its status and its result size
|
|
265
|
+
// on one line, which the Claude shape below has no room for; everything
|
|
266
|
+
// the Codex vocabulary owns is rendered there.
|
|
267
|
+
const codex = renderCodexEntry(entry);
|
|
268
|
+
if (codex !== undefined) { lines.push(...codex); continue; }
|
|
362
269
|
switch (entry.kind) {
|
|
363
270
|
case 'attempt': {
|
|
364
271
|
const size = entry.bytes === null ? '' : ` · ${thousands(entry.bytes)} bytes`;
|
|
@@ -380,7 +287,8 @@ export function renderAgentTranscript(parsed: ParsedTranscript): string[] {
|
|
|
380
287
|
break;
|
|
381
288
|
}
|
|
382
289
|
case 'message': {
|
|
383
|
-
const
|
|
290
|
+
const state = entry.complete === false ? ' (incomplete)' : '';
|
|
291
|
+
const who = `${entry.role}${entry.nested ? ' (subagent)' : ''}${state}`;
|
|
384
292
|
const body = entry.text.split('\n');
|
|
385
293
|
lines.push(`${who}:`);
|
|
386
294
|
for (const line of body) lines.push(` ${safe(line)}`);
|