@farero-ai/ui 0.0.0-stage → 0.4.1

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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +150 -2
  3. package/dist/activity/orrery.d.ts +6 -0
  4. package/dist/activity/orrery.js +1 -0
  5. package/dist/activity.css +2 -0
  6. package/dist/activity.d.ts +10 -0
  7. package/dist/activity.js +1 -0
  8. package/dist/chunks/ActivityGlyph-tlf4hwl8.d.ts +44 -0
  9. package/dist/chunks/DataTable-GR4HPUOJ.js +1 -0
  10. package/dist/chunks/IsolatedPreview-HJ6B36KF.js +1 -0
  11. package/dist/chunks/MathEquation-7ZVYQFEK.js +1 -0
  12. package/dist/chunks/chunk-3I4YBQX6.js +1 -0
  13. package/dist/chunks/chunk-5SBKMKFB.js +1 -0
  14. package/dist/chunks/chunk-756GM57N.js +1 -0
  15. package/dist/chunks/chunk-CMWS5PI4.js +2 -0
  16. package/dist/chunks/chunk-CXEEHWHD.js +3 -0
  17. package/dist/chunks/chunk-E7KN7CHM.js +5 -0
  18. package/dist/chunks/chunk-FW2QVWXL.js +1 -0
  19. package/dist/chunks/chunk-HGN4GN2E.js +1 -0
  20. package/dist/chunks/chunk-ITKN2ASJ.js +1 -0
  21. package/dist/chunks/chunk-LHMFMBHY.js +2 -0
  22. package/dist/chunks/chunk-LNOXROHT.js +1 -0
  23. package/dist/chunks/chunk-ONVWTQLU.js +1 -0
  24. package/dist/chunks/chunk-RR7BB4EQ.js +2 -0
  25. package/dist/chunks/chunk-RWFARXSG.js +1 -0
  26. package/dist/chunks/chunk-S3DX6DGB.js +1 -0
  27. package/dist/chunks/chunk-T3JXEXIJ.js +1 -0
  28. package/dist/chunks/chunk-UNO25KYE.js +1 -0
  29. package/dist/chunks/chunk-WMKRKKIS.js +1 -0
  30. package/dist/chunks/chunk-WQZ3EUKA.js +1 -0
  31. package/dist/chunks/chunk-YPRVAH5G.js +1 -0
  32. package/dist/chunks/chunk-Z3Z6LSG4.js +2 -0
  33. package/dist/chunks/chunk-ZVJQ5X63.js +2 -0
  34. package/dist/chunks/d2-S4ICDZEQ.js +1 -0
  35. package/dist/chunks/download-K6ZKYCHG.js +1 -0
  36. package/dist/chunks/mermaid-CQ4QMBLA.js +7 -0
  37. package/dist/chunks/readonly-components-1cDZu8D0.d.ts +26 -0
  38. package/dist/cn.d.ts +5 -0
  39. package/dist/cn.js +1 -0
  40. package/dist/code.d.ts +44 -0
  41. package/dist/code.js +1 -0
  42. package/dist/commands.d.ts +159 -0
  43. package/dist/commands.js +1 -0
  44. package/dist/controls.d.ts +233 -0
  45. package/dist/controls.js +1 -0
  46. package/dist/diagram.d.ts +83 -0
  47. package/dist/diagram.js +1 -0
  48. package/dist/fence.d.ts +41 -0
  49. package/dist/fence.js +1 -0
  50. package/dist/icons.d.ts +18 -0
  51. package/dist/icons.js +1 -0
  52. package/dist/markdown.d.ts +133 -0
  53. package/dist/markdown.js +1 -0
  54. package/dist/styles.css +2 -0
  55. package/dist/table.d.ts +41 -0
  56. package/dist/table.js +1 -0
  57. package/dist/theme.d.ts +4 -0
  58. package/dist/theme.js +1 -0
  59. package/dist/transcript.d.ts +849 -0
  60. package/dist/transcript.js +17 -0
  61. package/package.json +91 -4
@@ -0,0 +1,849 @@
1
+ import * as react from 'react';
2
+ import { FC, ReactNode, SyntheticEvent, ComponentProps } from 'react';
3
+ import { ExtraProps } from 'react-markdown';
4
+ import { ReadonlyComponentsOptions } from './markdown.js';
5
+
6
+ /**
7
+ * Portable shared API request/response contracts for local coding-agent applications.
8
+ *
9
+ * This module owns the DTOs that cross `/api` and have no dependency on app
10
+ * storage, processes, or Node runtimes: delegation, Workflow projections,
11
+ * attachments, provider/capability metadata, and the request inputs the Zod
12
+ * schemas in the host validate. Response envelopes that compose host-owned
13
+ * projections (workspaces, sessions, transcripts) stay in the host's wire
14
+ * module, which re-exports everything here for compatibility.
15
+ *
16
+ * **This module stays stdlib-free — no `node:` imports, ever.** It ships to
17
+ * other apps as a versioned package alongside `./routes`, and the host's
18
+ * boundary check (`scripts/check-imports.ts`) enforces that nothing under it
19
+ * reaches for Node or for host `src/` modules.
20
+ *
21
+ * Request DTOs here are structural mirrors of the host's Zod input schemas.
22
+ * The schemas remain the single runtime validator; `tests/http/api-contracts`
23
+ * asserts the inferred schema types stay assignable to these interfaces so the
24
+ * two spellings cannot drift apart silently.
25
+ */
26
+
27
+ /**
28
+ * Every native provider a host can dispatch to. The order is the model catalog's wire order.
29
+ * A list for a narrower question, such as providers with importable history, keeps its own
30
+ * members typed against `NativeProvider`, so a new provider joins it only on purpose.
31
+ */
32
+ declare const NATIVE_PROVIDERS: readonly ["codex", "claude", "opencode", "cursor", "antigravity"];
33
+ /** A native provider id. Never inferred from a model label. */
34
+ type NativeProvider = (typeof NATIVE_PROVIDERS)[number];
35
+ /**
36
+ * queue wakes the parent after its turn; steer joins a running turn and falls back
37
+ * to queue; hold never wakes and rides into the parent's next human prompt.
38
+ */
39
+ type DelegationReturnMode = 'queue' | 'steer' | 'hold';
40
+ /** Delivery lifecycle: acknowledged (tool receipt) and delivered (prompt receipt) are both terminal. */
41
+ type DelegationReportState = 'ready' | 'offered' | 'acknowledged' | 'delivered';
42
+ /** How a report reached the parent's context: a completion prompt, a human prompt it rode with, or the Wake action. */
43
+ interface DelegationReportDelivery {
44
+ by: 'wake' | 'attach' | 'manual';
45
+ promptId: string;
46
+ at: number;
47
+ }
48
+ /**
49
+ * The job attempt that produced a report. Version-1 records predate the field and are ordinary.
50
+ * A Workflow report is one attempt of one job: a retry or cancellation starts a new identity.
51
+ * A user share is one explicit Report back of one completed specialist result. Its identity is
52
+ * that result, so a repeated click or a later origin continuation finds the same share.
53
+ */
54
+ type DelegationReportSource = {
55
+ kind: 'ordinary';
56
+ jobId: string;
57
+ reviewer?: {
58
+ maker: string;
59
+ model: string;
60
+ };
61
+ } | {
62
+ kind: 'workflow';
63
+ runId: string;
64
+ jobId: string;
65
+ attempt: number;
66
+ cycle: number;
67
+ cancellationGeneration: number;
68
+ } | {
69
+ kind: 'user_share';
70
+ /** The completed turn whose final assistant entry was shared. */
71
+ turnId: string;
72
+ assistantRowid: number;
73
+ /** SHA-256 of the shared text. */
74
+ digest: string;
75
+ /** The displayed logical origin; `parentSessionId` is the physical chat it was sent to. */
76
+ originSessionId: string;
77
+ /** The startup job of the user-started specialist, when it is known. */
78
+ delegationId?: string;
79
+ /** Undispatched attempts withdrawn from an earlier context of the origin, oldest first. */
80
+ handoffs?: Array<{
81
+ sessionId: string;
82
+ promptId: string;
83
+ at: number;
84
+ }>;
85
+ };
86
+ /**
87
+ * Durable completion record, keyed by the ordinary job id or by the deterministic Workflow
88
+ * attempt id. Outlives the job row and owns delivery after completion.
89
+ */
90
+ interface DelegationReport {
91
+ /** 1 is an ordinary report written before `source` existed; every new write is 2. */
92
+ version: 1 | 2;
93
+ id: string;
94
+ /** Present from version 2. */
95
+ source?: DelegationReportSource;
96
+ workspaceId: string;
97
+ parentSessionId: string;
98
+ childSessionId: string;
99
+ /** The saved preset's name; absent for inline selections. */
100
+ role?: string;
101
+ /** `delegationLabel(job)`: the role name or `subagent` (`helper` in older records). */
102
+ label: string;
103
+ returnMode: DelegationReturnMode;
104
+ /** Legacy Workflow summaries may predate the saved completion cursor. Ordinary outcomes still require it. */
105
+ outcome: DelegationOutcome | {
106
+ kind: 'success';
107
+ assistantRowid?: number;
108
+ text: string;
109
+ };
110
+ attachment: Attachment;
111
+ /** `chatCursor(outcome.assistantRowid)` when the child produced an assistant entry. */
112
+ completionCursor?: string;
113
+ /** When the child's completion was observed. */
114
+ createdAt: number;
115
+ state: DelegationReportState;
116
+ offeredAt?: number;
117
+ /** Unique per offer; the served text carries it so the parent's transcript can prove receipt. */
118
+ offerToken?: string;
119
+ /** The global event seq when the report was first served; only transcript entries written after it can acknowledge. */
120
+ offeredSeq?: number;
121
+ acknowledgedAt?: number;
122
+ /** `tool` is an explicit acknowledgement from the authenticated parent's next receive call. */
123
+ acknowledgedBy?: 'transcript' | 'wait' | 'tool';
124
+ /** The receive operation that confirmed a tool receipt. Host evidence; public projections omit it. */
125
+ acknowledgement?: {
126
+ operationId: string;
127
+ };
128
+ /** The parent's turn when a Workflow offer was served; its confirmed end releases the fallback wake. */
129
+ offeredTurnId?: string;
130
+ /** A completion prompt (`by` wake or manual) admitted for this report and not yet sent; attach skips the report while it is in flight. */
131
+ wake?: DelegationReportDelivery;
132
+ delivery?: DelegationReportDelivery;
133
+ /** A Workflow attempt that no longer counts. It stays readable history and is never offered or woken again. */
134
+ retired?: {
135
+ at: number;
136
+ reason: 'cancelled' | 'superseded';
137
+ };
138
+ /** Workflow completion prompts the provider refused before dispatch; automatic retries stop at a bound. */
139
+ wakeFailures?: number;
140
+ /** Last confirmed failed wake. Its receipt remains inspectable after the retry stops. */
141
+ wakeFailure?: {
142
+ promptId: string;
143
+ at: number;
144
+ error: string;
145
+ };
146
+ /** The legacy Workflow result prompt this report replaced, withdrawn before it was sent. */
147
+ adoptedFrom?: {
148
+ effectId: string;
149
+ promptId?: string;
150
+ };
151
+ }
152
+ /** Only states the host actually exposes are represented; questions stay in Baton content. */
153
+ type DelegationOutcome = {
154
+ kind: 'success';
155
+ assistantRowid: number;
156
+ text: string;
157
+ } | {
158
+ kind: 'error';
159
+ assistantRowid?: number;
160
+ text?: string;
161
+ error: string;
162
+ };
163
+ /** One file written in the host's own attachment layout, ready to add to a prompt. */
164
+ interface Attachment {
165
+ /** Safe file name shown by the host's attachment chip. */
166
+ name: string;
167
+ /** Worktree-relative path for the agent to read. */
168
+ path: string;
169
+ bytes: number;
170
+ /** The host's `@⟦…⟧(…)` composer token. */
171
+ token: string;
172
+ }
173
+
174
+ /** Small transcript receipt. The immutable specification lives beside the host's other chat outputs. */
175
+ interface GeneratedUiReceipt {
176
+ kind: 'farero-ui';
177
+ version: 1;
178
+ reference: string;
179
+ id: string;
180
+ title: string;
181
+ }
182
+
183
+ /** A tool call whose MCP server declared a view for it, as a transcript entry carries it. */
184
+ interface McpAppLink {
185
+ /** The server as the provider names it: Claude's configured name, Codex's server key. */
186
+ server: string;
187
+ /** The `ui://` resource the tool declared. */
188
+ resourceUri: string;
189
+ /** The stored call the view renders (`mcp_app_call_<sha256>`); absent until the call completes. */
190
+ call?: string;
191
+ }
192
+
193
+ /** Servers a tool call needs signed in, stamped from provider state or the host's own tool. */
194
+ interface McpSignInRequest {
195
+ servers: string[];
196
+ }
197
+
198
+ /**
199
+ * The handful of things the relay and the phone must compute *identically*, in the
200
+ * one place both can import.
201
+ *
202
+ * `src/` and `web/src/` are one TypeScript project (tsconfig.json includes both), so
203
+ * a plain relative import crosses between them fine. What does not cross is Node: the
204
+ * moment this file imports `node:anything` it stops being bundleable and every web
205
+ * import of it becomes a build failure. **So this module stays stdlib-free — no
206
+ * `node:` imports, ever.** It is the only file under `src/` the web app may import a
207
+ * *value* from; everything else it may only `import type` (see src/wire.ts), which
208
+ * `verbatimModuleSyntax` erases before the bundler ever sees it.
209
+ *
210
+ * Each of these was a second copy before, and each copy was a way for two screens to
211
+ * disagree about the same workspace.
212
+ */
213
+
214
+ /** Completion notices are automation, even though providers receive them as user messages. */
215
+ declare function isDelegationReturnEntry(e: {
216
+ id: string;
217
+ role: string;
218
+ text: string;
219
+ }): boolean;
220
+ /** Agent prompts start provider turns but must never read as the person's own words. */
221
+ declare function isAgentAuthored(e: {
222
+ origin?: string;
223
+ }): boolean;
224
+ /**
225
+ * The host wrote this prompt, and it keeps the origin of the prompt it retries, so a retry of
226
+ * the person's prompt is automation too. A retry's id is the failed prompt's id with a
227
+ * `-retry` suffix. Text alone can be a person's quotation.
228
+ */
229
+ declare function isAutomaticRetryEntry(e: {
230
+ id: string;
231
+ role: string;
232
+ text: string;
233
+ }): boolean;
234
+
235
+ /**
236
+ * Farero stores each turn's raw Claude Code SDK stream JSON in
237
+ * `session_messages.content`. User-typed prompts are stored as plain text.
238
+ * This turns a row into compact, phone-renderable entries.
239
+ *
240
+ * Classification rule (verified against the whole DB): a JSON frame with
241
+ * `type:"user"` is ALWAYS tool plumbing — every one of them carries
242
+ * tool_result blocks, never the user's own words. Real prompts are the
243
+ * plain-text rows. Never render an SDK user frame as a user bubble.
244
+ */
245
+
246
+ /** Evidence of a successful provider answer submission, not confirmation of delivery. */
247
+ interface QuestionAnswer {
248
+ provider: NativeProvider;
249
+ method: string;
250
+ requestId: string;
251
+ evidence: 'submitted';
252
+ decision?: string;
253
+ questions: {
254
+ id: string;
255
+ question: string;
256
+ values: (string | number | boolean)[];
257
+ labels?: string[];
258
+ redacted?: boolean;
259
+ }[];
260
+ }
261
+ interface TranscriptEntry {
262
+ id: string;
263
+ rowid: number;
264
+ /** Native item revision; rowid remains a stable search/fork anchor. */
265
+ revision?: number;
266
+ /** Abandoned provider stream item replaced by this completed item; retained for audit/replay. */
267
+ supersededBy?: string;
268
+ /** Display role: user | assistant | tool | thinking | system */
269
+ role: 'user' | 'assistant' | 'tool' | 'thinking' | 'system';
270
+ /** Human-readable text. For tool rows: the call's description, else the tool name. */
271
+ text: string;
272
+ /** Provider answer submission evidence; absent from historical entries without this receipt. */
273
+ questionAnswer?: QuestionAnswer;
274
+ /** Questions authored alongside a provider message, before any answer was submitted. */
275
+ questionRequest?: {
276
+ questions: {
277
+ id: string;
278
+ question: string;
279
+ options?: string[];
280
+ }[];
281
+ };
282
+ /** Provider-owned background work result, kept in this chat rather than a delegated Farero chat. */
283
+ backgroundResult?: {
284
+ kind: 'subagent' | 'shell';
285
+ description: string;
286
+ state: 'succeeded' | 'failed' | 'interrupted' | 'unavailable';
287
+ nativeID: string;
288
+ };
289
+ /** Tool name when role === 'tool'. */
290
+ tool?: string;
291
+ /** Full mono secondary detail for tool rows (command, path, pattern, …). */
292
+ detail?: string;
293
+ /**
294
+ * The SDK's `tool_use` id. Carried by the call and by the result answering it — the
295
+ * only thing that pairs the two, which sit in different `session_messages` rows.
296
+ */
297
+ toolUseId?: string;
298
+ /**
299
+ * The agent tool call whose transcript this frame belongs to.
300
+ *
301
+ * Farero writes delegated-agent frames into the parent chat and points every one
302
+ * back at the spawning `tool_use`. The phone uses this durable join to nest the work
303
+ * under that call even when the parent keeps speaking while the subagent runs.
304
+ */
305
+ parentToolUseId?: string;
306
+ /** Host-kept /btw answer. It is local context, not a provider-authored parent turn. */
307
+ sideQuestion?: {
308
+ question: string;
309
+ sourceSessionId: string;
310
+ };
311
+ /** Human label for a tool call that spawned a subagent. Present only on that call. */
312
+ subagentLabel?: string;
313
+ /** A tool result's output, clipped. The phone folds it onto the call row. */
314
+ output?: string;
315
+ /** The tool's stored text/detail/output exceeded the shared persistence budget. */
316
+ outputTruncated?: boolean;
317
+ /** UTF-8 bytes observed when this row first crossed the persistence budget. */
318
+ outputOriginalBytes?: number;
319
+ /** True when `output` is a unified diff (an edit's result), so the phone colours it. */
320
+ diff?: boolean;
321
+ /**
322
+ * True when the diff's line numbers count within the edited text, not the file. A
323
+ * Claude Edit names the text it replaced but not its position, so they are hidden.
324
+ */
325
+ diffExcerpt?: boolean;
326
+ /**
327
+ * True while this row shows an edit that the provider has not applied: the call's input
328
+ * is still arriving, or the call is complete and its result has not come back. `output`
329
+ * then holds what the call will write, never a result. With `diff` it is the complete
330
+ * patch of a finished call. Without `diff` it is the part written so far: lines that
331
+ * start with `-`, `+` or a space, between patch header lines when the tool takes a patch.
332
+ * The last line can be incomplete, and the text only grows. The row loses the flag when
333
+ * the provider reports the result. A draft that was cut off or refused keeps the flag and
334
+ * gains `aborted`: its `output` is what it would have written. A draft outside a running
335
+ * turn was never applied.
336
+ */
337
+ draft?: boolean;
338
+ /**
339
+ * The provider's execution state for this call. A running call may already have output.
340
+ * False when the call has returned. Older rows may omit this observation.
341
+ */
342
+ running?: boolean;
343
+ /** Images the result carried, as `GET /api/tool-images/:reference` references. */
344
+ images?: string[];
345
+ /** The MCP App view the call's server declared, and its stored result once the call completes. */
346
+ app?: McpAppLink;
347
+ /** Servers this call needs signed in; the transcript offers a Connect card for each. */
348
+ mcpSignIn?: McpSignInRequest;
349
+ /** A host-owned panel receipt, retained even when a provider replay omits its tool output. */
350
+ generatedUi?: GeneratedUiReceipt;
351
+ /** Completed assistant UI fences, indexed in their original message order. */
352
+ generatedUiStreams?: Record<string, GeneratedUiReceipt>;
353
+ /** True when this row is a failed tool result. */
354
+ error?: boolean;
355
+ /**
356
+ * True when the call was cut off before it ran or finished: the provider dropped the
357
+ * model's stream mid-call, or the user stopped the turn. Its arguments may never have
358
+ * arrived. Distinct from `error`, which is a tool that ran and failed — an aborted
359
+ * call is never counted as a failure.
360
+ */
361
+ aborted?: boolean;
362
+ ts: string;
363
+ /** True while the message is queued, from the current outbox or the legacy in-row signal. */
364
+ queued: boolean;
365
+ /**
366
+ * Host-recorded author for a user prompt, independent of the provider transcript's
367
+ * user role. Absent on provider history and on rows that predate receipts; the
368
+ * phone treats a missing origin as the person's own words. Agent prompts arrive
369
+ * through MCP send_prompt and must never read as the person.
370
+ */
371
+ origin?: 'human' | 'agent';
372
+ /** Who sent this prompt for an agent. The host records it at acceptance and names a chat at read time. */
373
+ sender?: PromptSender;
374
+ }
375
+ interface PromptSender {
376
+ /** The chat on this computer whose agent sent it. */
377
+ chat?: PromptSenderChat;
378
+ /** The name a local MCP client outside this computer's chats gave itself. */
379
+ client?: string;
380
+ /** The sender's own link back to the conversation it sent from. */
381
+ link?: string;
382
+ }
383
+ /** A chat that sent a prompt. A chat that no longer exists keeps only its id. */
384
+ interface PromptSenderChat {
385
+ sessionId: string;
386
+ workspaceId?: string;
387
+ title?: string;
388
+ provider?: string;
389
+ model?: string;
390
+ }
391
+
392
+ type ClockFormat = '12h' | '24h';
393
+
394
+ /** One visible transcript row and any delegated-agent rows that belong underneath it. */
395
+ interface TranscriptNode {
396
+ e: TranscriptEntry;
397
+ children: TranscriptNode[];
398
+ }
399
+ interface TranscriptSubagent {
400
+ id: string;
401
+ label: string;
402
+ node: TranscriptNode;
403
+ }
404
+ declare function transcriptTree(entries: readonly TranscriptEntry[]): TranscriptNode[];
405
+ /**
406
+ * Flatten every selectable agent call for the transcript's virtual child-tab strip.
407
+ *
408
+ * Native subagents share their parent's `sessions` row, so the spawning tool id is
409
+ * their only durable address. Nested agents join the same strip: selecting one shows
410
+ * exactly its own frame subtree while its parent remains the real chat tab above it.
411
+ * A malformed call without an id stays visible in the parent transcript but cannot
412
+ * become a tab whose selection would be impossible to restore.
413
+ */
414
+ declare function transcriptSubagents(nodes: readonly TranscriptNode[]): TranscriptSubagent[];
415
+ /** Delivered helper reports continue the conversation's turn; a queued report has not joined it yet. */
416
+ declare const isTurnPrompt: (e: TranscriptEntry) => boolean;
417
+ /**
418
+ * The row that closes each turn — the last thing the agent said before the next
419
+ * prompt, and the only place in that turn a fork can be cut from.
420
+ *
421
+ * An agent speaks several times inside one turn (a short update, more work, then the
422
+ * answer), so a control under every assistant row would offer four cuts of one exchange,
423
+ * three of which end a copy mid-answer.
424
+ *
425
+ * A turn with no response closes at its last work row instead of offering nothing:
426
+ * without this a cancelled turn shows no fork control at all. Rows before the first
427
+ * prompt are not a turn and keep the old rule — an answer, if there is one.
428
+ */
429
+ declare function turnActionEnds(entries: readonly TranscriptEntry[]): TranscriptEntry[];
430
+
431
+ /**
432
+ * Find the row that owns Copy/Fork in the current turn.
433
+ *
434
+ * Reasoning, tools, and system notices are supporting rows around a response, so
435
+ * they do not replace it. A prompt starts a new turn and prevents actions from
436
+ * reaching back to an older response while that turn is unanswered.
437
+ * Delivered helper reports continue the turn rather than splitting its actions.
438
+ *
439
+ * A turn the agent never answered in prose still owns actions: a stop, a cancel,
440
+ * or a parked retryable limit leaves thinking and tool calls with no response to
441
+ * cut at, so the cut is the turn's last row and the fork keeps the interrupted
442
+ * work instead of stranding it. Only a bare prompt with nothing after it offers
443
+ * no cut of its own — the previous turn keeps the one it already offered.
444
+ */
445
+ declare function latestTurnActionEnd(entries: readonly TranscriptEntry[]): TranscriptEntry | null;
446
+ /**
447
+ * When the turn holding `target` was dispatched — the origin for how long that answer
448
+ * took.
449
+ *
450
+ * `sessions.turn_started_at` is the better source and is what `dispatched` carries: the
451
+ * relay groups current rows by `turn_id`, so a message typed *into* a running turn
452
+ * (steering) does not restart the clock, with `queue_order` retained for legacy rows.
453
+ * A row carrying neither still needs the transcript fallback below. A dispatch at or
454
+ * after the response belongs to a *later* turn, which is every turn but the newest, so
455
+ * it measures nothing about this one. A report can also wake a continuation: that
456
+ * later dispatch does not measure the preceding work, so use the original prompt.
457
+ * Several cuts share that answer in one walk: `turnOrigins`.
458
+ */
459
+ declare function turnOrigin(entries: readonly TranscriptEntry[], target: TranscriptEntry, dispatched?: string | null): string | null;
460
+ /**
461
+ * `turnOrigin` for each target, from one walk down the transcript.
462
+ *
463
+ * Each target is timed from the rows before it, so its own prompt or report does
464
+ * not time it, and a repeated row keeps its last place. A target the rows do not
465
+ * contain is measured from the end, as a search that never finds it would.
466
+ */
467
+ declare function turnOrigins(entries: readonly TranscriptEntry[], targets: readonly TranscriptEntry[], dispatched?: string | null): Map<TranscriptEntry, string | null>;
468
+
469
+ interface BubbleProps {
470
+ children: ReactNode;
471
+ className?: string;
472
+ }
473
+ declare const Bubble: FC<BubbleProps>;
474
+ /**
475
+ * Where a nested sticky header parks. Browsers measure a sticky offset from the
476
+ * scroller's padding edge, so `top-0` would park 12px below the transcript's top
477
+ * (its `py-3`) and rows would show through the gap. The root header cancels that
478
+ * inset to meet the scrollport, then each open group adds one header height
479
+ * (py-1.5 + a 12.5px line ≈ h-8). Index by nesting depth, clamped to the last
480
+ * entry.
481
+ */
482
+ declare const STICKY_TOP: readonly ["-top-3", "top-5", "top-13"];
483
+
484
+ declare function mcpSignInOf(e: TranscriptEntry): McpSignInRequest | undefined;
485
+ /** The browser sign-in request this row's receipt names, if any. */
486
+ declare function browserSignInOf(e: TranscriptEntry): string | undefined;
487
+ /** The saved-password sign-in this row's receipt names, if any. */
488
+ declare function savedSignInOf(e: TranscriptEntry): string | undefined;
489
+ /** The handoff request this row's receipt names, if any. A sign_in request draws the browser sign-in card. */
490
+ declare function handoffRequestOf(e: TranscriptEntry): string | undefined;
491
+ /** A row that addresses the person with a card, rather than reporting the agent's own work. */
492
+ declare function personCard(e: TranscriptEntry): boolean;
493
+
494
+ /** Hour and minute fields for a date format that also shows the time: 21:45, or 9:45 PM. */
495
+ declare function clockFields(clock: ClockFormat | null): Intl.DateTimeFormatOptions;
496
+ /** Hours and minutes in this device's locale and timezone. */
497
+ declare function clockTime(at: Date | number | string, clock?: ClockFormat | null): string;
498
+ /** Hours, minutes and seconds, for a log of events. */
499
+ declare function clockSeconds(at: Date | number | string, clock?: ClockFormat | null): string;
500
+ /** The locale's full date and time, seconds included. */
501
+ declare function dateTime(at: Date | number | string, clock?: ClockFormat | null): string;
502
+
503
+ /** Legacy ordinary reports have no source discriminator. */
504
+ declare function isWorkflowReport(report: DelegationReport): boolean;
505
+ /** Only a persisted report association can remove automation from the editable queue. */
506
+ declare function workflowReportPromptIds(reports: readonly DelegationReport[], sessionId: string | null): string[];
507
+ /**
508
+ * Count distinct helpers evidenced by this turn's saved calls and completion notices.
509
+ * Completed jobs leave the live projection, so history uses the same transcript evidence.
510
+ * An unreadable launch receipt leaves the total unknown rather than guessing from call count.
511
+ */
512
+ declare function turnDelegationCount(entries: readonly TranscriptEntry[]): number | null;
513
+ interface DelegationReturnNotice {
514
+ /** `Reviewer complete`, `Exploration failed`, or `Worker complete` for an unrecognised notice. */
515
+ title: string;
516
+ /** The first paragraph of the result preview, or the failure reason. */
517
+ lead: string;
518
+ /** The remainder of the preview, if any. */
519
+ rest: string;
520
+ /** The report's attachment token, from the notice's `Report:` line. */
521
+ report: string | null;
522
+ /** The header line and the read_chat pointer: ids an agent needs, not the person. */
523
+ machine: string | null;
524
+ }
525
+ /**
526
+ * Split a completion notice into what the person reads first and what stays behind an expander.
527
+ * The header and the read_chat trailer become `machine`; the `Report:` line becomes `report`.
528
+ */
529
+ declare function parseDelegationReturn(text: string): DelegationReturnNotice;
530
+ /** The line the host writes above the report block it appends to a human prompt. */
531
+ declare const ATTACHED_REPORTS_HEADER = "Helper reports delivered with this message:";
532
+ interface AttachedReport {
533
+ /** The saved role name or generic helper label, including historical `subagent` labels. */
534
+ label: string;
535
+ /** The delegation job id, which is also the report id. */
536
+ id: string;
537
+ outcome: 'completed' | 'failed';
538
+ /** The item's first line without its bullet or `Report:` token. */
539
+ line: string;
540
+ /** The preview carried for a report the agent never received; absent for one it already read. */
541
+ preview?: string;
542
+ attachmentToken?: string;
543
+ }
544
+ /**
545
+ * Separate the person's own text from the helper reports the host appended to their prompt.
546
+ * Only a trailing block that starts with the header line and holds nothing but `- Delegated` items
547
+ * counts; anything else is the person's text and comes back unchanged with no reports.
548
+ */
549
+ declare function splitAttachedReports(text: string): {
550
+ body: string;
551
+ reports: AttachedReport[];
552
+ };
553
+
554
+ /**
555
+ * One flat line of a prompt, for the jump sheet's rows (components/transcript/MessageNav.tsx).
556
+ * The first line that has anything in it — a prompt often opens with a heading or a
557
+ * bullet, and the marker is noise at this size — collapsed and cut to a little past
558
+ * the two lines the row clamps to, so the ellipsis lands where the row does.
559
+ */
560
+ declare function messagePreview(text: string, max?: number): string;
561
+ /**
562
+ * A running duration for the working indicator: `12s` → `4m 07s` → `1h 04m 07s`.
563
+ * Padded once a bigger unit is in play so the label stops twitching as it counts,
564
+ * and clamped at zero — the relay's clock and the phone's don't have to agree.
565
+ */
566
+ declare function elapsed(ms: number): string;
567
+ /**
568
+ * `Jul 7, 04:40`, carrying the year once it isn't the current one — most of the chats
569
+ * this reaches are archived, and half of them are older than the calendar on screen.
570
+ */
571
+ declare function dateStamp(at: Date, now: Date, clock: ClockFormat | null): string;
572
+ /**
573
+ * When a message was sent, in the phone's own locale and timezone. The date is only
574
+ * spelled out once the message isn't from today — a chat left open overnight would
575
+ * otherwise show two "09:14"s a day apart.
576
+ */
577
+ declare function messageTime(iso: string, clock?: ClockFormat | null): string;
578
+
579
+ type Row = {
580
+ kind: 'entry';
581
+ key: string;
582
+ node: TranscriptNode;
583
+ } | {
584
+ kind: 'steps';
585
+ key: string;
586
+ nodes: TranscriptNode[];
587
+ } | {
588
+ kind: 'batch';
589
+ key: string;
590
+ tool: string;
591
+ nodes: TranscriptNode[];
592
+ };
593
+ /** How transcript steps group: ungrouped, tools grouped with thinking as messages, or everything folded. */
594
+ type GroupingMode = 'off' | 'tools' | 'all';
595
+ /** Every Activity layout in picker order. The ids are the saved `grouping` values. */
596
+ declare const ACTIVITY_LAYOUTS: {
597
+ id: GroupingMode;
598
+ label: string;
599
+ }[];
600
+ /** How a finished turn reads: every message, or its final reply with the work folded above it (see `foldTurns`). */
601
+ type CompletedTurns = 'all' | 'final';
602
+ declare const COMPLETED_TURNS: {
603
+ id: CompletedTurns;
604
+ label: string;
605
+ }[];
606
+ /** What a steps group holds once its lookups are folded: never another steps group. */
607
+ type StepRow = Exclude<Row, {
608
+ kind: 'steps';
609
+ }>;
610
+ /** A finished turn's work, folded to one line above the reply it led to (see `foldTurns`). */
611
+ interface WorkRow {
612
+ kind: 'work';
613
+ key: string;
614
+ /** Every row between the turn's prompt and its reply, in transcript order. */
615
+ nodes: TranscriptNode[];
616
+ /** The turn's final reply, drawn as its own row just below this one. */
617
+ reply: TranscriptEntry;
618
+ /** When the turn started, as `turnOrigin` measures it. */
619
+ startedAt: string | null;
620
+ }
621
+ /** A transcript row, or a finished turn's folded work. */
622
+ type TurnRow = Row | WorkRow;
623
+ declare const rowKey: (e: TranscriptEntry) => string;
624
+ type TimedMessage = Pick<TranscriptEntry, 'id' | 'role' | 'text' | 'ts' | 'questionAnswer' | 'subagentLabel' | 'origin'>;
625
+ /** Consecutive messages from the same speaker keep their timestamp only on the last bubble. */
626
+ declare function continuesMessageMinute(entry: TimedMessage, next?: TimedMessage, untimed?: ReadonlySet<string>): boolean;
627
+ /** What a collapsed Steps box previews: every step's label, the latest step, or the latest thinking step. */
628
+ type StepsSummary = 'all' | 'latest' | 'latest-thinking';
629
+ /** Every Group preview in picker order. The ids are the saved `stepsSummary` values. */
630
+ declare const GROUP_PREVIEWS: {
631
+ id: StepsSummary;
632
+ label: string;
633
+ }[];
634
+ /** Latest thinking needs a thought inside the group, and only Group tools + thinking puts one there. */
635
+ declare const groupPreviewAvailable: (preview: StepsSummary, grouping: GroupingMode) => boolean;
636
+ /**
637
+ * The collapsed header's preview text. `latest` and `latest-thinking` surface the
638
+ * step's real text — for short-summary thinkers that is the summary itself — while
639
+ * the box still holds every step for when it is opened. A group with no thinking
640
+ * falls back to its latest step rather than previewing nothing.
641
+ */
642
+ declare function stepSummary(nodes: TranscriptNode[], mode?: StepsSummary): string;
643
+ /**
644
+ * The title a tool row prints. A provider's own title stands: a Bash description, or the
645
+ * relative path OpenCode gives a read. A title that only repeats the tool's name becomes
646
+ * the shared identity's label, so `read` prints as `Read` and an MCP call as its tool,
647
+ * with the server beside it.
648
+ */
649
+ declare function stepTitle(e: TranscriptEntry): {
650
+ title: string;
651
+ server: string | null;
652
+ };
653
+ /**
654
+ * What one lookup took, short enough to list several on a header. OpenCode titles a read
655
+ * with the relative path, so a title that says more than the tool name is used as is.
656
+ * Claude's title is only "Read", and the absolute path behind it is cut to the file name.
657
+ */
658
+ declare function lookupLabel(e: TranscriptEntry, fullPath?: boolean): string;
659
+ /** Fold each run of two or more consecutive calls to the same lookup tool into one batch row. */
660
+ declare function batchLookups(nodes: TranscriptNode[]): StepRow[];
661
+ /**
662
+ * Fold each run of the agent's own work between two spoken messages into one
663
+ * collapsible group — a turn is mostly plumbing, and on a phone that plumbing
664
+ * buries the prose. A run of one stays inline: wrapping a single row in a
665
+ * disclosure hides it without saving anything.
666
+ *
667
+ * `tools` splits the run on thinking: each thought stands as its own message
668
+ * (see `thinkingAsMessages`) and only the tool calls between thoughts group —
669
+ * the GPT-like lane for models whose reasoning already reads as prose. `off`
670
+ * leaves every step inline as its own row: the outer Steps disclosure goes
671
+ * away, while each tool/thinking row keeps its own dropdown. In both modes a
672
+ * run of one lookup tool still folds into a batch: four reads are one line
673
+ * either way.
674
+ */
675
+ declare function groupSteps(nodes: TranscriptNode[], grouping?: GroupingMode): Row[];
676
+ /**
677
+ * Rows a folded turn keeps on screen: notices, answered questions, side answers the
678
+ * person kept, sign-in and handoff cards they must act on, and MCP App views a server drew for them.
679
+ * A fold hides the agent's own work, never something addressed to the person. A background
680
+ * task's end is that work in any state.
681
+ */
682
+ declare const staysVisible: (e: TranscriptEntry) => boolean;
683
+ /**
684
+ * Replies completed before a wake remain part of the turn's visible answer. Entries
685
+ * carry no end-of-turn marker, so keep only the last reply before each wake, and only
686
+ * when no further agent work followed it. Notices do not invalidate a reply.
687
+ */
688
+ declare function repliesBeforeWakes(nodes: TranscriptNode[]): Set<TranscriptEntry>;
689
+ /** A folded turn's one line, "Worked for 25m 37s · 2 delegations", and the rows that stay on screen while it is closed. */
690
+ declare function turnWorkLine(nodes: TranscriptNode[], startedAt: string | null | undefined, endedAt: string): {
691
+ label: string;
692
+ aborted: number;
693
+ kept: TranscriptNode[];
694
+ };
695
+ /**
696
+ * Fold each finished turn to its prompt, one "Worked for …" line and its final reply,
697
+ * as Codex draws a finished turn. The rows in between (thinking, tool calls, updates
698
+ * posted on the way) sit behind that line, except replies completed before a helper
699
+ * report or a background task's end (see `repliesBeforeWakes`). `groupSteps` still
700
+ * arranges them when it opens. Rows after the reply stay where they are.
701
+ * `completedTurns` of `all` leaves every turn open, arranged by `grouping` alone.
702
+ *
703
+ * Delivered helper reports and background task ends continue the preceding prompt's
704
+ * turn: they are work, not a new request. A report with no reply stays inline.
705
+ * Only a turn the agent ended by speaking folds. A stopped or failed turn keeps every
706
+ * row, because its work is the only output it has; so does a turn with work after its
707
+ * last message. While `live` is set, the newest turn stays open, and so does every turn
708
+ * whose reply came after `dispatched` (`sessions.turn_started_at`), which keeps a steered
709
+ * turn whole until it ends. Rows before the first prompt are no turn.
710
+ *
711
+ * A short turn stays open too, unless it holds a helper report. Otherwise the fold
712
+ * needs `FOLD_MIN_ROWS` rows of work, counted as
713
+ * `grouping` draws them, so a batch of twenty reads counts as one row. Hiding a few
714
+ * rows behind a line costs a click and saves little room.
715
+ */
716
+ declare function foldTurns(nodes: TranscriptNode[], grouping?: GroupingMode, { completedTurns, live, dispatched }?: {
717
+ completedTurns?: CompletedTurns;
718
+ live?: boolean;
719
+ dispatched?: string | null;
720
+ }): TurnRow[];
721
+
722
+ /**
723
+ * The shared message bubble bodies, extracted from the live transcript rows so
724
+ * the read-only demo renders the same JSX and styles. The rendered markdown is
725
+ * injected as children: live passes its memoised `<Markdown>` (with the block
726
+ * context menu), the demo passes a static `<MarkdownBody>`. Timestamps,
727
+ * delivery footers, quotation and fork actions stay with each host.
728
+ */
729
+ /** The agent's side — the bulk of the transcript, so it reads as the page. */
730
+ interface AssistantBodyProps {
731
+ children: ReactNode;
732
+ }
733
+ declare const AssistantBody: FC<AssistantBodyProps>;
734
+ /** The person's side — one tinted bubble per prompt. */
735
+ interface UserBodyProps {
736
+ children: ReactNode;
737
+ queued?: boolean;
738
+ }
739
+ declare const UserBody: FC<UserBodyProps>;
740
+ type UserMessageState = 'queued' | 'sending' | 'failed' | 'uncertain';
741
+ interface AutomaticResendProps {
742
+ id: string;
743
+ state?: UserMessageState;
744
+ children?: ReactNode;
745
+ }
746
+ /** An automatic retry keeps its delivery status without repeating the user's prompt. */
747
+ declare const AutomaticResend: FC<AutomaticResendProps>;
748
+ interface AutomationCardProps {
749
+ /** The eyebrow that names who wrote the card: `Automation`, `Assignment`. */
750
+ label: string;
751
+ children: ReactNode;
752
+ }
753
+ /** A prompt an agent or the host wrote, drawn as a card so it never reads as the person's own bubble. */
754
+ declare const AutomationCard: FC<AutomationCardProps>;
755
+ interface SystemLineProps {
756
+ children: ReactNode;
757
+ }
758
+ /** A transcript row that is plain centered metadata rather than a message. */
759
+ declare const SystemLine: FC<SystemLineProps>;
760
+ interface DelegationReturnBodyProps {
761
+ notice: DelegationReturnNotice;
762
+ /** Draws notice text with the host's own markdown, as children do for the bubbles above. */
763
+ markdown: (text: string) => ReactNode;
764
+ /** The chip for `notice.report`. */
765
+ report: ReactNode;
766
+ time: ReactNode;
767
+ }
768
+ /** A completion notice drawn as automation, not as the person's own message. Title, first paragraph and report chip stay visible; the rest of the preview, the ids and the read_chat pointer collapse. */
769
+ declare const DelegationReturnBody: FC<DelegationReturnBodyProps>;
770
+ interface TurnWorkFoldProps {
771
+ /** From `turnWorkLine`. */
772
+ label: string;
773
+ aborted: number;
774
+ open: boolean;
775
+ onToggle: (event: SyntheticEvent<HTMLDetailsElement>) => void;
776
+ /** The turn's work, drawn only while the fold is open. */
777
+ work: () => ReactNode;
778
+ /** The rows that stay on screen while the fold is closed. */
779
+ kept: () => ReactNode;
780
+ }
781
+ /** A finished turn's work behind one quiet line above its final reply (see `foldTurns`). */
782
+ declare const TurnWorkFold: FC<TurnWorkFoldProps>;
783
+
784
+ /** Only render persisted submission evidence; no draft/optimistic state is accepted here. */
785
+ interface QuestionAnswerRecordProps {
786
+ record: NonNullable<TranscriptEntry['questionAnswer']>;
787
+ }
788
+ declare const QuestionAnswerRecord: FC<QuestionAnswerRecordProps>;
789
+
790
+ /** Live controllers supply file/chat navigation and the full source viewer. Static readers never import them. */
791
+ declare const QuestionContent: react.Context<{
792
+ link: (props: ComponentProps<"a"> & ExtraProps) => ReactNode;
793
+ original: (source: string) => ReactNode;
794
+ }>;
795
+ /** Question copy is prose, not executable document content. No images, HTML or rich fences. */
796
+ interface QuestionMarkdownProps {
797
+ text: string;
798
+ }
799
+ declare const QuestionMarkdown: FC<QuestionMarkdownProps>;
800
+
801
+ interface ReadOnlyTranscriptProps {
802
+ /** Curated or fixture entries; read-only, never fetched, never mutated. */
803
+ entries: readonly TranscriptEntry[];
804
+ grouping?: GroupingMode;
805
+ /** `final`, the live default, folds each finished turn's work behind one line above its reply. */
806
+ completedTurns?: CompletedTurns;
807
+ stepsSummary?: StepsSummary;
808
+ /** Hour cycle for timestamps; null leaves it to the browser language. */
809
+ clock?: ClockFormat | null;
810
+ /** Open a linked workspace file. Absent, file links render as static code. */
811
+ onOpenFile?: (path: string) => void;
812
+ filePaths?: readonly string[];
813
+ images?: ReadonlyComponentsOptions['images'];
814
+ /** Open a subagent doorway row. Absent, the doorway renders statically. */
815
+ onSelectSubagent?: (toolUseId: string | null) => void;
816
+ className?: string;
817
+ }
818
+ /**
819
+ * Host-independent transcript reader: the shared user/assistant bubble bodies
820
+ * over a static markdown map, with local disclosures for thinking and tool
821
+ * steps. No find, navigation, polling, receipts or store reads — data arrives
822
+ * as props and every disclosure is a plain `<details>`.
823
+ */
824
+ declare const ReadOnlyTranscript: FC<ReadOnlyTranscriptProps>;
825
+
826
+ /**
827
+ * True when `requestId` is an automatic retry of `originalId`, directly or
828
+ * through a chain. Mirrors `src/host/retryable.ts`: browser code may only
829
+ * `import type` from `src/`, so the check is duplicated here instead of imported.
830
+ */
831
+ declare function isRetryOf(requestId: string, originalId: string): boolean;
832
+ /**
833
+ * Ids of user entries that merely resend an earlier user entry: an automatic
834
+ * retry (`isRetryOf` on the ids) carrying the same text. A retry that made
835
+ * progress sends a short continue instruction instead, which reads as automation
836
+ * (`isAutomaticRetryEntry`).
837
+ */
838
+ declare function automaticResendIds(entries: readonly {
839
+ id: string;
840
+ role: string;
841
+ text: string;
842
+ }[]): Set<string>;
843
+
844
+ type Lookup = 'Read' | 'Grep' | 'Glob' | 'LS';
845
+ /** Pipelines retain their first lookup's kind; sequences must all have the same kind. */
846
+ declare function shellLookup(command: string): Lookup | null;
847
+
848
+ export { ACTIVITY_LAYOUTS, ATTACHED_REPORTS_HEADER, AssistantBody, AutomaticResend, AutomationCard, Bubble, COMPLETED_TURNS, DelegationReturnBody, GROUP_PREVIEWS, QuestionAnswerRecord, QuestionContent, QuestionMarkdown, ReadOnlyTranscript, STICKY_TOP, SystemLine, TurnWorkFold, UserBody, automaticResendIds, batchLookups, browserSignInOf, clockFields, clockSeconds, clockTime, continuesMessageMinute, dateStamp, dateTime, elapsed, foldTurns, groupPreviewAvailable, groupSteps, handoffRequestOf, isAgentAuthored, isAutomaticRetryEntry, isDelegationReturnEntry, isRetryOf, isTurnPrompt, isWorkflowReport, latestTurnActionEnd, lookupLabel, mcpSignInOf, messagePreview, messageTime, parseDelegationReturn, personCard, repliesBeforeWakes, rowKey, savedSignInOf, shellLookup, splitAttachedReports, staysVisible, stepSummary, stepTitle, transcriptSubagents, transcriptTree, turnActionEnds, turnDelegationCount, turnOrigin, turnOrigins, turnWorkLine, workflowReportPromptIds };
849
+ export type { AssistantBodyProps, AttachedReport, ClockFormat, CompletedTurns, DelegationReport, DelegationReturnNotice, GroupingMode, ReadOnlyTranscriptProps, Row, StepRow, StepsSummary, TranscriptEntry, TranscriptNode, TranscriptSubagent, TurnRow, UserBodyProps, UserMessageState, WorkRow };