@vibefield/rosetta-room 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -3
- package/dist/components/Transcript.js +6 -2
- package/dist/components/file-viewer/FileViewerDialog.js +3 -2
- package/dist/components/file-viewer/diff/parse.js +7 -0
- package/dist/components/file-viewer/kinds.d.ts +22 -0
- package/dist/components/file-viewer/kinds.js +57 -0
- package/dist/components/file-viewer/markdown/render.d.ts +7 -1
- package/dist/components/file-viewer/markdown/render.js +16 -12
- package/dist/components/file-viewer/registry.d.ts +2 -2
- package/dist/components/file-viewer/registry.js +20 -59
- package/dist/components/file-viewer/views/DiffBody.js +7 -2
- package/dist/components/git/CommitViewer.js +3 -2
- package/dist/components/transcript/Activity.d.ts +10 -4
- package/dist/components/transcript/Activity.js +36 -11
- package/dist/components/transcript/Anchor.js +3 -2
- package/dist/components/transcript/Compaction.d.ts +9 -0
- package/dist/components/transcript/Compaction.js +10 -5
- package/dist/components/transcript/Document.js +150 -208
- package/dist/components/transcript/PromptJump.js +28 -8
- package/dist/components/transcript/Prose.d.ts +5 -1
- package/dist/components/transcript/Prose.js +7 -6
- package/dist/components/transcript/ReadingBlocks.d.ts +71 -0
- package/dist/components/transcript/ReadingBlocks.js +279 -0
- package/dist/components/transcript/activity-plan.d.ts +38 -7
- package/dist/components/transcript/activity-plan.js +198 -28
- package/dist/components/transcript/attachment-file-source.d.ts +1 -2
- package/dist/components/transcript/attachment-file-source.js +7 -5
- package/dist/components/transcript/disclosure-state.d.ts +2 -0
- package/dist/components/transcript/disclosure-state.js +6 -2
- package/dist/components/transcript/document-model.js +53 -9
- package/dist/components/transcript/document-plan.js +263 -98
- package/dist/components/transcript/reading-identity.d.ts +14 -1
- package/dist/components/transcript/reading-identity.js +126 -10
- package/dist/components/worktree/WorktreeColumn.js +12 -1
- package/dist/components/worktree/WorktreeList.d.ts +8 -2
- package/dist/components/worktree/WorktreeList.js +200 -5
- package/dist/components/worktree/worktree-ledger.d.ts +40 -0
- package/dist/components/worktree/worktree-ledger.js +68 -0
- package/dist/conversation/ConversationGallery.d.ts +11 -0
- package/dist/conversation/ConversationGallery.js +14 -0
- package/dist/conversation/ConversationMedia.d.ts +44 -0
- package/dist/conversation/ConversationMedia.js +210 -0
- package/dist/conversation/ConversationProse.d.ts +13 -0
- package/dist/conversation/ConversationProse.js +6 -0
- package/dist/conversation/ConversationRunRows.d.ts +57 -0
- package/dist/conversation/ConversationRunRows.js +84 -0
- package/dist/conversation/ConversationTurnView.d.ts +64 -0
- package/dist/conversation/ConversationTurnView.js +169 -0
- package/dist/conversation/ConversationView.d.ts +3 -0
- package/dist/conversation/ConversationView.js +257 -0
- package/dist/conversation/feed-reads.d.ts +36 -0
- package/dist/conversation/feed-reads.js +155 -0
- package/dist/conversation/feed.d.ts +106 -0
- package/dist/conversation/feed.js +884 -0
- package/dist/conversation/index.d.ts +11 -0
- package/dist/conversation/index.js +25 -0
- package/dist/conversation/model.d.ts +108 -0
- package/dist/conversation/model.js +257 -0
- package/dist/conversation/ports.d.ts +194 -0
- package/dist/conversation/ports.js +9 -0
- package/dist/conversation/rosetta-client.d.ts +8 -0
- package/dist/conversation/rosetta-client.js +1 -0
- package/dist/conversation/use-conversation-feed.d.ts +16 -0
- package/dist/conversation/use-conversation-feed.js +41 -0
- package/dist/conversation/use-conversation-window.d.ts +50 -0
- package/dist/conversation/use-conversation-window.js +336 -0
- package/dist/conversation/words.d.ts +51 -0
- package/dist/conversation/words.js +79 -0
- package/dist/fixtures/conversation.d.ts +34 -0
- package/dist/fixtures/conversation.js +723 -0
- package/dist/fixtures/index.d.ts +2 -0
- package/dist/fixtures/index.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/lib/hooks.js +6 -1
- package/dist/lib/session-leases.d.ts +11 -8
- package/dist/lib/transcript/collaboration.js +53 -19
- package/dist/lib/transcript/head-of-document.js +9 -3
- package/dist/lib/transcript/index.d.ts +1 -1
- package/dist/lib/transcript/index.js +1 -1
- package/dist/lib/transcript/prompt-jump.d.ts +2 -0
- package/dist/lib/transcript/prompt-jump.js +5 -1
- package/dist/lib/transcript/sittings.d.ts +2 -1
- package/dist/lib/transcript/sittings.js +72 -10
- package/dist/lib/transcript/tail-state.d.ts +9 -0
- package/dist/lib/transcript/tail-state.js +25 -1
- package/dist/lib/transcript/turns.d.ts +5 -0
- package/dist/lib/transcript/turns.js +221 -57
- package/dist/lib/transcript/use-transcript-tail.js +17 -3
- package/dist/lib/transcript/vocabulary.d.ts +2 -1
- package/dist/lib/transcript/vocabulary.js +11 -1
- package/dist/parts-context.d.ts +25 -0
- package/dist/parts-context.js +32 -0
- package/dist/ports.d.ts +36 -0
- package/dist/room-context.d.ts +1 -2
- package/dist/room-context.js +11 -9
- package/dist/styles/conversation-turn.css +147 -0
- package/dist/styles/conversation.css +45 -0
- package/dist/styles/room.css +102 -12
- package/dist/styles/transcript.css +11 -2
- package/package.json +9 -4
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { TimelineEntry, TimelinePage, TurnRun } from "@vibefield/rosetta-protocol";
|
|
2
|
+
import type { ConversationViewWords } from "./ports.js";
|
|
3
|
+
/** A row's line: its words, and a detail drawn quieter beside them. */
|
|
4
|
+
export interface RunRowWords {
|
|
5
|
+
readonly words: string;
|
|
6
|
+
readonly detail?: string;
|
|
7
|
+
}
|
|
8
|
+
/** What a run's rows say while they are read, when they cannot be, and the
|
|
9
|
+
* ask for the earlier ones a single read left out. */
|
|
10
|
+
export declare const RUN_ROWS_WORDS: Readonly<{
|
|
11
|
+
reading: "Loading…";
|
|
12
|
+
failed: "Could not read this run";
|
|
13
|
+
earlier: "Earlier steps";
|
|
14
|
+
}>;
|
|
15
|
+
/** The lines a run's rows draw, each whole, as the view's `words` name them. */
|
|
16
|
+
export type RunRowsLines = Pick<ConversationViewWords, "runReading" | "runFailed" | "runEarlier">;
|
|
17
|
+
/** Rosetta's own lines: the failed one says the read's reason after its words. */
|
|
18
|
+
export declare const RUN_ROWS_LINES: RunRowsLines;
|
|
19
|
+
/** Rows per read: the newest first, then the earlier ones on asking. */
|
|
20
|
+
export declare const RUN_ROWS_PAGE = 200;
|
|
21
|
+
/**
|
|
22
|
+
* A row as the room's ledger says it: a tool's verb and object (its result
|
|
23
|
+
* beside them), a thought's first line, a notice's sentence. Any other row
|
|
24
|
+
* draws no line.
|
|
25
|
+
*/
|
|
26
|
+
export declare function defaultRunRowWords(row: TimelineEntry, home?: string | null): RunRowWords | null;
|
|
27
|
+
/** A run's rows as far as they were read. `cursor` names the earlier rows
|
|
28
|
+
* still unread; `failed` the read's own words when it could not be made. */
|
|
29
|
+
export interface RunRowsRead {
|
|
30
|
+
readonly rows: readonly TimelineEntry[];
|
|
31
|
+
readonly cursor: string | null;
|
|
32
|
+
readonly reading: boolean;
|
|
33
|
+
readonly failed: string | null;
|
|
34
|
+
}
|
|
35
|
+
export declare const UNREAD_RUN_ROWS: RunRowsRead;
|
|
36
|
+
/** What a run holds when the reader opens it again: a first read that failed
|
|
37
|
+
* and left nothing is let go, so the rows are read again; anything read stays
|
|
38
|
+
* (an earlier page that failed is asked again by its own press). */
|
|
39
|
+
export declare function rowsOnOpening(held: RunRowsRead | null): RunRowsRead | null;
|
|
40
|
+
export interface ConversationRunRowsProps {
|
|
41
|
+
readonly run: TurnRun;
|
|
42
|
+
/** The rows of the run's range, newest first in pages, oldest first within one. */
|
|
43
|
+
readonly read: (o: {
|
|
44
|
+
first: number;
|
|
45
|
+
last: number;
|
|
46
|
+
limit: number;
|
|
47
|
+
cursor?: string;
|
|
48
|
+
}, signal: AbortSignal) => Promise<TimelinePage>;
|
|
49
|
+
readonly rowWords: (row: TimelineEntry) => RunRowWords | null;
|
|
50
|
+
/** Held by the run, so a run opened again draws what it read. */
|
|
51
|
+
readonly state: RunRowsRead | null;
|
|
52
|
+
readonly onState: (next: RunRowsRead) => void;
|
|
53
|
+
/** Its lines, each drawn whole; rosetta's own when absent. */
|
|
54
|
+
readonly words?: RunRowsLines;
|
|
55
|
+
}
|
|
56
|
+
/** The run's rows; reads the newest page when nothing is held yet. */
|
|
57
|
+
export declare function ConversationRunRows({ run, read, rowWords, state, onState, words }: ConversationRunRowsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A run's rows, read when the reader opens its line: one quiet line each, in
|
|
3
|
+
// the order the agent wrote them. Nothing is read until the line opens, and
|
|
4
|
+
// what was read stays with the run while its turn is drawn, so closing and
|
|
5
|
+
// opening it again reads nothing. A first read that failed and left nothing is
|
|
6
|
+
// read again when the line is opened again.
|
|
7
|
+
import { useEffect } from "react";
|
|
8
|
+
import { ledgerLine } from "../lib/transcript/ledger.js";
|
|
9
|
+
import { canonicalText, firstLine, noticeText, objectText } from "../lib/transcript/vocabulary.js";
|
|
10
|
+
/** What a run's rows say while they are read, when they cannot be, and the
|
|
11
|
+
* ask for the earlier ones a single read left out. */
|
|
12
|
+
export const RUN_ROWS_WORDS = Object.freeze({
|
|
13
|
+
reading: "Loading…",
|
|
14
|
+
failed: "Could not read this run",
|
|
15
|
+
earlier: "Earlier steps",
|
|
16
|
+
});
|
|
17
|
+
/** Rosetta's own lines: the failed one says the read's reason after its words. */
|
|
18
|
+
export const RUN_ROWS_LINES = Object.freeze({
|
|
19
|
+
runReading: RUN_ROWS_WORDS.reading,
|
|
20
|
+
runFailed: (reason) => `${RUN_ROWS_WORDS.failed}. ${reason}`,
|
|
21
|
+
runEarlier: RUN_ROWS_WORDS.earlier,
|
|
22
|
+
});
|
|
23
|
+
/** Rows per read: the newest first, then the earlier ones on asking. */
|
|
24
|
+
export const RUN_ROWS_PAGE = 200;
|
|
25
|
+
/**
|
|
26
|
+
* A row as the room's ledger says it: a tool's verb and object (its result
|
|
27
|
+
* beside them), a thought's first line, a notice's sentence. Any other row
|
|
28
|
+
* draws no line.
|
|
29
|
+
*/
|
|
30
|
+
export function defaultRunRowWords(row, home = null) {
|
|
31
|
+
const body = row.body;
|
|
32
|
+
switch (body.type) {
|
|
33
|
+
case "tool_use": {
|
|
34
|
+
const line = ledgerLine(row, { home });
|
|
35
|
+
const words = `${line.verb} ${objectText(line.object)}`.trim();
|
|
36
|
+
return line.result === null || line.result === "" ? { words } : { words, detail: line.result };
|
|
37
|
+
}
|
|
38
|
+
case "thinking": {
|
|
39
|
+
const thought = firstLine(canonicalText(body.text));
|
|
40
|
+
return thought === "" ? null : { words: thought };
|
|
41
|
+
}
|
|
42
|
+
case "notice":
|
|
43
|
+
return { words: noticeText(body.notice) };
|
|
44
|
+
default:
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export const UNREAD_RUN_ROWS = Object.freeze({ rows: Object.freeze([]), cursor: null, reading: true, failed: null });
|
|
49
|
+
/** What a run holds when the reader opens it again: a first read that failed
|
|
50
|
+
* and left nothing is let go, so the rows are read again; anything read stays
|
|
51
|
+
* (an earlier page that failed is asked again by its own press). */
|
|
52
|
+
export function rowsOnOpening(held) {
|
|
53
|
+
return held !== null && held.failed !== null && held.rows.length === 0 && !held.reading ? null : held;
|
|
54
|
+
}
|
|
55
|
+
/** The run's rows; reads the newest page when nothing is held yet. */
|
|
56
|
+
export function ConversationRunRows({ run, read, rowWords, state, onState, words = RUN_ROWS_LINES }) {
|
|
57
|
+
const unread = state === null;
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!unread)
|
|
60
|
+
return;
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
read({ first: run.first_ordinal, last: run.last_ordinal, limit: RUN_ROWS_PAGE }, controller.signal).then((page) => {
|
|
63
|
+
if (!controller.signal.aborted)
|
|
64
|
+
onState({ rows: page.entries, cursor: page.cursor, reading: false, failed: null });
|
|
65
|
+
}, (error) => {
|
|
66
|
+
if (!controller.signal.aborted) {
|
|
67
|
+
onState({ rows: [], cursor: null, reading: false, failed: error instanceof Error ? error.message : String(error) });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return () => controller.abort();
|
|
71
|
+
}, [unread]);
|
|
72
|
+
const held = state ?? UNREAD_RUN_ROWS;
|
|
73
|
+
const earlier = () => {
|
|
74
|
+
if (held.cursor === null || held.reading)
|
|
75
|
+
return;
|
|
76
|
+
const cursor = held.cursor;
|
|
77
|
+
onState({ ...held, reading: true });
|
|
78
|
+
read({ first: run.first_ordinal, last: run.last_ordinal, limit: RUN_ROWS_PAGE, cursor }, new AbortController().signal).then((page) => onState({ rows: [...page.entries, ...held.rows], cursor: page.cursor, reading: false, failed: null }), (error) => onState({ ...held, reading: false, failed: error instanceof Error ? error.message : String(error) }));
|
|
79
|
+
};
|
|
80
|
+
return (_jsxs("div", { className: "tr-conv__rows", "aria-busy": held.reading, children: [held.cursor !== null && (_jsx("button", { type: "button", className: "tr-conv__rows-earlier", onClick: earlier, disabled: held.reading, children: words.runEarlier })), held.rows.length > 0 && (_jsx("ul", { children: held.rows.map((row) => {
|
|
81
|
+
const said = rowWords(row);
|
|
82
|
+
return said === null ? null : (_jsxs("li", { "data-timeline-id": row.timeline_id, children: [_jsx("span", { className: "tr-conv__row-words", children: said.words }), said.detail !== undefined && _jsx("span", { className: "tr-conv__row-detail", children: said.detail })] }, row.timeline_id));
|
|
83
|
+
}) })), held.reading && held.rows.length === 0 && _jsx("p", { className: "tr-conv__rows-status", role: "status", children: words.runReading }), held.failed !== null && _jsx("p", { className: "tr-conv__rows-status", role: "status", children: words.runFailed(held.failed) })] }));
|
|
84
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ConversationTurn, TimelineEntry, TimelinePage, TurnOutcome, TurnRun } from "@vibefield/rosetta-protocol";
|
|
3
|
+
import type { RunRowWords } from "./ConversationRunRows.js";
|
|
4
|
+
import type { ConversationMedia, ConversationPrompt, ConversationTurnFacts, ConversationViewProps, ConversationViewWords } from "./ports.js";
|
|
5
|
+
/** A turn's oldest parts that its read left out, said above the rest. */
|
|
6
|
+
export declare function omittedPartsWords(count: number): string;
|
|
7
|
+
/** The view's lines: each the host's where it gave one, else rosetta's own. */
|
|
8
|
+
export declare function viewWordsOf(words: Partial<ConversationViewWords> | undefined): ConversationViewWords;
|
|
9
|
+
/** Every slot a turn reads, with rosetta's own defaults in place. */
|
|
10
|
+
export interface ConversationTurnSlots {
|
|
11
|
+
readonly renderPrompt: ((prompt: ConversationPrompt, drawn: ReactNode) => ReactNode) | undefined;
|
|
12
|
+
readonly renderAfterTurn: ((turn: ConversationTurnFacts) => ReactNode) | undefined;
|
|
13
|
+
readonly agentLead: ReactNode | undefined;
|
|
14
|
+
readonly runWords: (run: TurnRun) => string | null;
|
|
15
|
+
readonly runLead: ((run: TurnRun) => ReactNode) | undefined;
|
|
16
|
+
readonly runRowWords: (row: TimelineEntry) => RunRowWords | null;
|
|
17
|
+
readonly requestWords: (row: TimelineEntry) => string | null;
|
|
18
|
+
readonly outcomeWords: (outcome: TurnOutcome) => string | null;
|
|
19
|
+
readonly compactionWords: string;
|
|
20
|
+
/** The lines of runs, parts left out and media, each whole. */
|
|
21
|
+
readonly words: ConversationViewWords;
|
|
22
|
+
readonly links: "open" | "inert";
|
|
23
|
+
readonly onOpenMedia: ((media: ConversationMedia) => void) | undefined;
|
|
24
|
+
/** One read of a run's rows, through the session the turn belongs to. */
|
|
25
|
+
readonly readRows: (sessionId: string, turnKey: string, o: {
|
|
26
|
+
first: number;
|
|
27
|
+
last: number;
|
|
28
|
+
limit: number;
|
|
29
|
+
cursor?: string;
|
|
30
|
+
}, signal: AbortSignal) => Promise<TimelinePage>;
|
|
31
|
+
/** The view keeps the turn's body while a run is open in it. */
|
|
32
|
+
readonly keep: ((sessionId: string, turnKey: string) => () => void) | undefined;
|
|
33
|
+
readonly onReceipt: (message: string) => void;
|
|
34
|
+
}
|
|
35
|
+
type SlotProps = Pick<ConversationViewProps, "renderPrompt" | "renderAfterTurn" | "agentLead" | "runWords" | "runLead" | "runRowWords" | "requestWords" | "outcomeWords" | "compactionWords" | "words" | "links" | "onOpenMedia">;
|
|
36
|
+
/** The slots a turn reads, from the view's props and its own doors. */
|
|
37
|
+
export declare function turnSlotsOf(props: SlotProps, doors: {
|
|
38
|
+
readonly readRows: ConversationTurnSlots["readRows"];
|
|
39
|
+
readonly keep?: ConversationTurnSlots["keep"];
|
|
40
|
+
readonly onReceipt?: (message: string) => void;
|
|
41
|
+
readonly homeDir?: string | null;
|
|
42
|
+
}): ConversationTurnSlots;
|
|
43
|
+
/** A prompt as the host may draw it: the row, its plain words, its time. A
|
|
44
|
+
* prompt stored as a member has its preview for words until its `whole` text
|
|
45
|
+
* is read. */
|
|
46
|
+
export declare function promptOf(sessionId: string, turnKey: string, row: TimelineEntry, whole?: string): ConversationPrompt;
|
|
47
|
+
/** A compaction: a quiet line, opening to the summary when one was recorded. */
|
|
48
|
+
export declare function ConversationCompaction({ row, words, onReceipt, defaultOpen }: {
|
|
49
|
+
readonly row: TimelineEntry;
|
|
50
|
+
readonly words: string;
|
|
51
|
+
readonly onReceipt: (message: string) => void;
|
|
52
|
+
readonly defaultOpen?: boolean;
|
|
53
|
+
}): import("react").JSX.Element;
|
|
54
|
+
export interface ConversationTurnViewProps {
|
|
55
|
+
readonly sessionId: string;
|
|
56
|
+
readonly turn: ConversationTurn;
|
|
57
|
+
/** The turn's place in its session's outline. */
|
|
58
|
+
readonly index: number;
|
|
59
|
+
/** The agent's lead draws on this turn's first part after its prompt. */
|
|
60
|
+
readonly lead: boolean;
|
|
61
|
+
readonly slots: ConversationTurnSlots;
|
|
62
|
+
}
|
|
63
|
+
export declare const ConversationTurnView: import("react").NamedExoticComponent<ConversationTurnViewProps>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// One turn of the conversation view: the person's prompt, then the turn's
|
|
3
|
+
// parts in order (each reply whole, each run between them as one line that
|
|
4
|
+
// opens in place, a question or a permission as a quiet line, a compaction as
|
|
5
|
+
// a line that opens to its summary), then how it ended when it did not finish,
|
|
6
|
+
// then whatever the host draws after it.
|
|
7
|
+
//
|
|
8
|
+
// Every word and drawing a host may want its own comes through the slots,
|
|
9
|
+
// resolved once by the view (`turnSlotsOf`) so their identity holds. The
|
|
10
|
+
// component is `memo` over its turn's record and those slots: a turn whose
|
|
11
|
+
// record did not change is not drawn again when another turn's does.
|
|
12
|
+
import { memo, useEffect, useState } from "react";
|
|
13
|
+
import { ReadingSessionProvider, useParts, useReadingSession } from "../parts-context.js";
|
|
14
|
+
import { SummaryBody } from "../components/transcript/Compaction.js";
|
|
15
|
+
import { LineChevron } from "../components/transcript/glyphs.js";
|
|
16
|
+
import { ConversationMediaList, ConversationMediaRail, MEDIA_LINES } from "./ConversationMedia.js";
|
|
17
|
+
import { ConversationProse } from "./ConversationProse.js";
|
|
18
|
+
import { ConversationRunRows, defaultRunRowWords, RUN_ROWS_LINES, rowsOnOpening } from "./ConversationRunRows.js";
|
|
19
|
+
import { knownParts } from "./model.js";
|
|
20
|
+
import { CONVERSATION_WORDS, defaultOutcomeWords, defaultRequestWords, defaultRunWords } from "./words.js";
|
|
21
|
+
/** A turn's oldest parts that its read left out, said above the rest. */
|
|
22
|
+
export function omittedPartsWords(count) {
|
|
23
|
+
return `${count} earlier ${count === 1 ? "step" : "steps"} not shown`;
|
|
24
|
+
}
|
|
25
|
+
/** The view's lines: each the host's where it gave one, else rosetta's own. */
|
|
26
|
+
export function viewWordsOf(words) {
|
|
27
|
+
return {
|
|
28
|
+
runReading: words?.runReading ?? RUN_ROWS_LINES.runReading,
|
|
29
|
+
runFailed: words?.runFailed ?? RUN_ROWS_LINES.runFailed,
|
|
30
|
+
runEarlier: words?.runEarlier ?? RUN_ROWS_LINES.runEarlier,
|
|
31
|
+
omittedParts: words?.omittedParts ?? omittedPartsWords,
|
|
32
|
+
mediaFailed: words?.mediaFailed ?? MEDIA_LINES.mediaFailed,
|
|
33
|
+
mediaRetry: words?.mediaRetry ?? MEDIA_LINES.mediaRetry,
|
|
34
|
+
mediaPlay: words?.mediaPlay ?? MEDIA_LINES.mediaPlay,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** The slots a turn reads, from the view's props and its own doors. */
|
|
38
|
+
export function turnSlotsOf(props, doors) {
|
|
39
|
+
const home = doors.homeDir ?? null;
|
|
40
|
+
return {
|
|
41
|
+
renderPrompt: props.renderPrompt,
|
|
42
|
+
renderAfterTurn: props.renderAfterTurn,
|
|
43
|
+
agentLead: props.agentLead,
|
|
44
|
+
runWords: props.runWords ?? defaultRunWords,
|
|
45
|
+
runLead: props.runLead,
|
|
46
|
+
runRowWords: props.runRowWords ?? ((row) => defaultRunRowWords(row, home)),
|
|
47
|
+
requestWords: props.requestWords ?? defaultRequestWords,
|
|
48
|
+
outcomeWords: props.outcomeWords ?? defaultOutcomeWords,
|
|
49
|
+
compactionWords: props.compactionWords ?? CONVERSATION_WORDS.compaction,
|
|
50
|
+
words: viewWordsOf(props.words),
|
|
51
|
+
links: props.links ?? "open",
|
|
52
|
+
onOpenMedia: props.onOpenMedia,
|
|
53
|
+
readRows: doors.readRows,
|
|
54
|
+
keep: doors.keep,
|
|
55
|
+
onReceipt: doors.onReceipt ?? (() => { }),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/* ── words of a row ──────────────────────────────────────────────────────── */
|
|
59
|
+
function textOf(text) {
|
|
60
|
+
if (text === null)
|
|
61
|
+
return "";
|
|
62
|
+
return text.type === "inline" ? text.text : text.preview;
|
|
63
|
+
}
|
|
64
|
+
/** A prompt as the host may draw it: the row, its plain words, its time. A
|
|
65
|
+
* prompt stored as a member has its preview for words until its `whole` text
|
|
66
|
+
* is read. */
|
|
67
|
+
export function promptOf(sessionId, turnKey, row, whole) {
|
|
68
|
+
const text = whole ?? (row.body.type === "user" ? textOf(row.body.text) : "");
|
|
69
|
+
return { sessionId, turnKey, row, text, at: row.at };
|
|
70
|
+
}
|
|
71
|
+
/** A row's own pictures and videos, as media items. */
|
|
72
|
+
function mediaOfRow(row) {
|
|
73
|
+
const refs = row.body.type === "user" || row.body.type === "agent" ? row.body.attachments
|
|
74
|
+
: row.body.type === "tool_use" ? row.body.tool.attachments ?? [] : [];
|
|
75
|
+
return refs.map((attachment) => ({ timelineId: row.timeline_id, attachment }));
|
|
76
|
+
}
|
|
77
|
+
/* ── the parts ───────────────────────────────────────────────────────────── */
|
|
78
|
+
function Prompt({ sessionId, turnKey, row, slots }) {
|
|
79
|
+
// A prompt stored as a member (a long paste) reads its whole text through
|
|
80
|
+
// the session, as a reply does; its preview stands until then, and the host
|
|
81
|
+
// is given the same words the bubble draws.
|
|
82
|
+
const text = useWholeText(row.body.type === "user" ? row.body.text : null);
|
|
83
|
+
const prompt = promptOf(sessionId, turnKey, row, text);
|
|
84
|
+
const drawn = (_jsxs("div", { className: "tr-conv__you", children: [prompt.text !== "" && _jsx("p", { className: "tr-conv__bubble", children: prompt.text }), _jsx(ConversationMediaRail, { sessionId: sessionId, items: mediaOfRow(row), onOpenMedia: slots.onOpenMedia })] }));
|
|
85
|
+
return _jsx(_Fragment, { children: slots.renderPrompt === undefined ? drawn : slots.renderPrompt(prompt, drawn) });
|
|
86
|
+
}
|
|
87
|
+
/** A prompt or a reply stored as a member reads its whole text through the
|
|
88
|
+
* session; its preview stands until then. */
|
|
89
|
+
function useWholeText(text) {
|
|
90
|
+
const { sessions } = useParts();
|
|
91
|
+
const sessionId = useReadingSession();
|
|
92
|
+
const [whole, setWhole] = useState(null);
|
|
93
|
+
const member = text?.type === "member" ? text : null;
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (member === null || sessionId === null)
|
|
96
|
+
return;
|
|
97
|
+
const controller = new AbortController();
|
|
98
|
+
sessions.run(sessionId, (client) => client.readTextAsset(member.asset, controller.signal)).then((read) => {
|
|
99
|
+
if (!controller.signal.aborted)
|
|
100
|
+
setWhole({ digest: member.asset.digest, text: read });
|
|
101
|
+
}, () => { });
|
|
102
|
+
return () => controller.abort();
|
|
103
|
+
}, [member?.asset.digest, sessionId, sessions]);
|
|
104
|
+
if (member !== null && whole?.digest === member.asset.digest)
|
|
105
|
+
return whole.text;
|
|
106
|
+
return textOf(text);
|
|
107
|
+
}
|
|
108
|
+
function Reply({ sessionId, row, slots }) {
|
|
109
|
+
const text = useWholeText(row.body.type === "agent" ? row.body.text : null);
|
|
110
|
+
return (_jsxs("div", { className: "tr-conv__reply", "data-timeline-id": row.timeline_id, children: [text !== "" && _jsx(ConversationProse, { text: text, links: slots.links, onReceipt: slots.onReceipt }), _jsx(ConversationMediaList, { sessionId: sessionId, items: mediaOfRow(row), onOpenMedia: slots.onOpenMedia, words: slots.words })] }));
|
|
111
|
+
}
|
|
112
|
+
/** Whether a host's node draws anything: null, undefined and a boolean draw nothing in React. */
|
|
113
|
+
function drawsSomething(node) {
|
|
114
|
+
return node !== null && node !== undefined && typeof node !== "boolean";
|
|
115
|
+
}
|
|
116
|
+
function Run({ sessionId, turnKey, run, slots }) {
|
|
117
|
+
const words = slots.runWords(run);
|
|
118
|
+
// The host's lead is asked only for a line that is drawn.
|
|
119
|
+
const lead = words === null ? null : slots.runLead?.(run);
|
|
120
|
+
const [open, setOpen] = useState(false);
|
|
121
|
+
const [rows, setRows] = useState(null);
|
|
122
|
+
const keep = slots.keep;
|
|
123
|
+
useEffect(() => (open && keep !== undefined ? keep(sessionId, turnKey) : undefined), [open, keep, sessionId, turnKey]);
|
|
124
|
+
const media = run.media.map((each) => ({ timelineId: each.timeline_id, attachment: each.attachment }));
|
|
125
|
+
const press = () => {
|
|
126
|
+
// Opened again over a first read that failed: read again.
|
|
127
|
+
if (!open)
|
|
128
|
+
setRows(rowsOnOpening);
|
|
129
|
+
setOpen((now) => !now);
|
|
130
|
+
};
|
|
131
|
+
return (_jsxs("div", { className: "tr-conv__part", "data-part": "run", children: [words !== null && (_jsxs("button", { type: "button", className: "tr-conv__run", "aria-expanded": open, onClick: press, children: [drawsSomething(lead) && _jsx("span", { className: "tr-conv__run-lead", "aria-hidden": "true", children: lead }), _jsx("span", { className: "tr-conv__run-words", children: words }), _jsx("span", { className: "tr-conv__chev", "aria-hidden": "true", children: _jsx(LineChevron, {}) })] })), open && words !== null && (_jsx(ConversationRunRows, { run: run, rowWords: slots.runRowWords, state: rows, onState: setRows, words: slots.words, read: (o, signal) => slots.readRows(sessionId, turnKey, o, signal) })), _jsx(ConversationMediaList, { sessionId: sessionId, items: media, onOpenMedia: slots.onOpenMedia, words: slots.words })] }));
|
|
132
|
+
}
|
|
133
|
+
/** A compaction: a quiet line, opening to the summary when one was recorded. */
|
|
134
|
+
export function ConversationCompaction({ row, words, onReceipt, defaultOpen = false }) {
|
|
135
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
136
|
+
const summary = row.body.type === "summary" ? row.body.text : null;
|
|
137
|
+
if (summary === null)
|
|
138
|
+
return _jsx("p", { className: "tr-conv__quiet tr-conv__compaction", "data-timeline-id": row.timeline_id, children: words });
|
|
139
|
+
return (_jsxs("details", { className: "tr-conv__compaction", "data-timeline-id": row.timeline_id, open: open, onToggle: (event) => setOpen(event.currentTarget.open), children: [_jsxs("summary", { className: "tr-conv__quiet", children: [_jsx("span", { className: "tr-conv__chev", "aria-hidden": "true", children: _jsx(LineChevron, {}) }), words] }), open && (_jsx(SummaryBody, { canonical: summary, messageKey: `conv:${row.timeline_id}`, matched: false, onReceipt: onReceipt }, summary.type === "member" ? summary.asset.digest : "inline"))] }));
|
|
140
|
+
}
|
|
141
|
+
function Part({ sessionId, turnKey, part, slots }) {
|
|
142
|
+
switch (part.kind) {
|
|
143
|
+
case "reply":
|
|
144
|
+
return _jsx(Reply, { sessionId: sessionId, row: part.row, slots: slots });
|
|
145
|
+
case "run":
|
|
146
|
+
return _jsx(Run, { sessionId: sessionId, turnKey: turnKey, run: part.run, slots: slots });
|
|
147
|
+
case "request": {
|
|
148
|
+
const words = slots.requestWords(part.row);
|
|
149
|
+
return words === null ? null : _jsx("p", { className: "tr-conv__quiet tr-conv__request", "data-timeline-id": part.row.timeline_id, children: words });
|
|
150
|
+
}
|
|
151
|
+
case "compaction":
|
|
152
|
+
return _jsx(ConversationCompaction, { row: part.row, words: slots.compactionWords, onReceipt: slots.onReceipt });
|
|
153
|
+
default:
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function partKey(part, at) {
|
|
158
|
+
return part.kind === "run" ? `run:${part.run.first_ordinal}` : `${part.kind}:${part.row.timeline_id}:${at}`;
|
|
159
|
+
}
|
|
160
|
+
export const ConversationTurnView = memo(function ConversationTurnView({ sessionId, turn, index, lead, slots }) {
|
|
161
|
+
const parts = knownParts(turn.parts);
|
|
162
|
+
const facts = {
|
|
163
|
+
sessionId, turnKey: turn.key, index, outcome: turn.outcome, tools: turn.tools, mcp: turn.mcp,
|
|
164
|
+
firstAt: turn.first_at, lastAt: turn.last_at,
|
|
165
|
+
};
|
|
166
|
+
const outcome = slots.outcomeWords(turn.outcome);
|
|
167
|
+
const guttered = slots.agentLead !== undefined;
|
|
168
|
+
return (_jsx(ReadingSessionProvider, { value: sessionId, children: _jsxs("div", { className: "tr-conv__turn", "data-turn-key": turn.key, "data-turn-state": turn.outcome.state, children: [turn.prompt !== null && _jsx(Prompt, { sessionId: sessionId, turnKey: turn.key, row: turn.prompt, slots: slots }), (parts.length > 0 || turn.parts_omitted > 0) && (_jsxs("div", { className: "tr-conv__agent", "data-gutter": guttered || undefined, children: [guttered && _jsx("div", { className: "tr-conv__lead", "aria-hidden": "true", children: lead ? slots.agentLead : null }), _jsxs("div", { className: "tr-conv__parts", children: [turn.parts_omitted > 0 && _jsx("p", { className: "tr-conv__quiet tr-conv__omitted", children: slots.words.omittedParts(turn.parts_omitted) }), parts.map((part, at) => (_jsx(Part, { sessionId: sessionId, turnKey: turn.key, part: part, slots: slots }, partKey(part, at))))] })] })), outcome !== null && _jsx("p", { className: "tr-conv__outcome", "data-outcome": turn.outcome.state, children: outcome }), slots.renderAfterTurn?.(facts)] }) }));
|
|
169
|
+
});
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// The conversation view: one conversation, read by turns over a chain of
|
|
3
|
+
// sessions, windowed, with the host's own drawings in its slots.
|
|
4
|
+
//
|
|
5
|
+
// It opens the chain's sessions through ONE lease set over the host's session
|
|
6
|
+
// port: the feed's turn reads and every part a turn draws (an attachment's
|
|
7
|
+
// bytes, a summary's text) share it, so a session is opened once. It provides
|
|
8
|
+
// the parts' context alone, with no room around it.
|
|
9
|
+
//
|
|
10
|
+
// The rows are `conversationRowsOf`'s, in its order (grown by
|
|
11
|
+
// `conversationRowsAfter` when a turn arrives); the agent's lead is
|
|
12
|
+
// `conversationLeads`'. The root says what the view is doing
|
|
13
|
+
// (`data-conv-state`): reading, ready, catching up, or unavailable. Never a
|
|
14
|
+
// blank: each state draws its slot, or rosetta's own words.
|
|
15
|
+
import { useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
16
|
+
import { createRoomStorage } from "../lib/room-storage.js";
|
|
17
|
+
import { createSessionLeases } from "../lib/session-leases.js";
|
|
18
|
+
import { calendarDayKey, sittingDayLabel } from "../lib/transcript/sittings.js";
|
|
19
|
+
import { PartsContext } from "../parts-context.js";
|
|
20
|
+
import { useViewerDay } from "../components/transcript/viewer-day.js";
|
|
21
|
+
import { ConversationGalleryHost } from "./ConversationMedia.js";
|
|
22
|
+
import { ConversationTurnView, turnSlotsOf } from "./ConversationTurnView.js";
|
|
23
|
+
import { viewportOfRows } from "./feed-reads.js";
|
|
24
|
+
import { conversationLeads, conversationRowsAfter, estimateRowHeight } from "./model.js";
|
|
25
|
+
import { useConversationFeed } from "./use-conversation-feed.js";
|
|
26
|
+
import { useConversationWindow } from "./use-conversation-window.js";
|
|
27
|
+
import { CONVERSATION_WORDS } from "./words.js";
|
|
28
|
+
const RECEIPT_MS = 2400;
|
|
29
|
+
function defaultUnavailable(reason) {
|
|
30
|
+
const words = CONVERSATION_WORDS.unavailable[reason.kind];
|
|
31
|
+
return reason.kind === "unsupported" ? _jsx("p", { children: words }) : _jsxs("p", { children: [words, ". ", _jsx("span", { className: "tr-conv__why", children: reason.message })] });
|
|
32
|
+
}
|
|
33
|
+
/** The parts' view of the host's desktop doors, whole, as the parts read them. */
|
|
34
|
+
function partsHostOf(host) {
|
|
35
|
+
if (host === undefined || host === null)
|
|
36
|
+
return null;
|
|
37
|
+
return host.copyText === undefined ? { homeDir: host.homeDir ?? null } : { homeDir: host.homeDir ?? null, copyText: host.copyText };
|
|
38
|
+
}
|
|
39
|
+
/** A turn's sides, from its body when held, else from its mark. */
|
|
40
|
+
function turnSides(mark, body) {
|
|
41
|
+
if (body !== null) {
|
|
42
|
+
const parts = body.parts.length > 0;
|
|
43
|
+
if (body.prompt === null)
|
|
44
|
+
return parts ? { first: "agent", last: "agent" } : { first: "none", last: "none" };
|
|
45
|
+
return { first: "person", last: parts ? "agent" : "person" };
|
|
46
|
+
}
|
|
47
|
+
return { first: mark?.preview != null ? "person" : "agent", last: "agent" };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The places of every session's turns, from the places before: a session
|
|
51
|
+
* whose outline is the same array keeps them; one that only grew at its end
|
|
52
|
+
* (or had a mark replaced under the same key) adds the new keys to them; any
|
|
53
|
+
* other change makes them again. A key's place is never moved by adding,
|
|
54
|
+
* since outlines hold each key once.
|
|
55
|
+
*/
|
|
56
|
+
function turnPlacesOf(previous, sessions) {
|
|
57
|
+
const next = new Map();
|
|
58
|
+
for (const session of sessions) {
|
|
59
|
+
const was = previous.get(session.sessionId);
|
|
60
|
+
const turns = session.turns;
|
|
61
|
+
if (was !== undefined && was.turns === turns) {
|
|
62
|
+
next.set(session.sessionId, was.kept ? was : { ...was, kept: true });
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
let grown = was !== undefined && turns.length >= was.turns.length;
|
|
66
|
+
let same = grown;
|
|
67
|
+
for (let i = 0; grown && i < was.turns.length; i += 1) {
|
|
68
|
+
if (turns[i] === was.turns[i])
|
|
69
|
+
continue;
|
|
70
|
+
same = false;
|
|
71
|
+
grown = turns[i].key === was.turns[i].key;
|
|
72
|
+
}
|
|
73
|
+
const index = grown ? was.index : new Map();
|
|
74
|
+
for (let i = grown ? was.turns.length : 0; i < turns.length; i += 1)
|
|
75
|
+
index.set(turns[i].key, i);
|
|
76
|
+
next.set(session.sessionId, { turns, index, kept: same });
|
|
77
|
+
}
|
|
78
|
+
return next;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The guesses for `rows`, from the guesses before: the rows that are the same
|
|
82
|
+
* objects at the same places, from the first row on, keep theirs, while every
|
|
83
|
+
* mark is the one they were made from (`kept`); the rest are made.
|
|
84
|
+
*/
|
|
85
|
+
function rowGuessesOf(previous, rows, places, guess) {
|
|
86
|
+
let from = 0;
|
|
87
|
+
if (previous !== null && [...places.values()].every((each) => each.kept)) {
|
|
88
|
+
const most = Math.min(previous.rows.length, rows.length);
|
|
89
|
+
while (from < most && previous.rows[from] === rows[from])
|
|
90
|
+
from += 1;
|
|
91
|
+
}
|
|
92
|
+
const guesses = from === 0 ? [] : previous.guesses.slice(0, from);
|
|
93
|
+
for (let i = from; i < rows.length; i += 1)
|
|
94
|
+
guesses.push(guess(rows[i]));
|
|
95
|
+
return { rows, guesses };
|
|
96
|
+
}
|
|
97
|
+
export function ConversationView(props) {
|
|
98
|
+
const { sessionPort, assets, host, chain, items, renderItem, renderBoundary, dayWords, head, foot, tail, empty, reading, catchingUp, unavailable, onLatest, onAway, label, ref } = props;
|
|
99
|
+
// ONE lease set over the host's port: the turn reads and the parts.
|
|
100
|
+
const leases = useMemo(() => createSessionLeases(sessionPort), [sessionPort]);
|
|
101
|
+
const partsHost = useMemo(() => partsHostOf(host), [host?.copyText, host?.homeDir]);
|
|
102
|
+
const storage = useMemo(() => createRoomStorage("conversation.", null), []);
|
|
103
|
+
const parts = useMemo(() => ({ assets, sessions: leases, host: partsHost, storage }), [assets, leases, partsHost, storage]);
|
|
104
|
+
const { feed, state } = useConversationFeed(leases, chain);
|
|
105
|
+
const [receipt, setReceipt] = useState(null);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (receipt === null)
|
|
108
|
+
return;
|
|
109
|
+
const timer = setTimeout(() => setReceipt(null), RECEIPT_MS);
|
|
110
|
+
return () => clearTimeout(timer);
|
|
111
|
+
}, [receipt]);
|
|
112
|
+
const slots = useMemo(() => turnSlotsOf(props, {
|
|
113
|
+
readRows: (sessionId, turnKey, o, signal) => leases.run(sessionId, (client) => client.turnRows(sessionId, turnKey, o, signal)),
|
|
114
|
+
...(feed === null ? {} : { keep: feed.keep }),
|
|
115
|
+
onReceipt: setReceipt,
|
|
116
|
+
homeDir: partsHost?.homeDir ?? null,
|
|
117
|
+
}), [props.renderPrompt, props.renderAfterTurn, props.agentLead, props.runWords, props.runLead, props.runRowWords,
|
|
118
|
+
props.requestWords, props.outcomeWords, props.compactionWords, props.words, props.links, props.onOpenMedia, leases, feed,
|
|
119
|
+
partsHost]);
|
|
120
|
+
// The rows: outlines, the host's items, a tail when the host draws one or
|
|
121
|
+
// the view is catching up.
|
|
122
|
+
const viewerDay = useViewerDay();
|
|
123
|
+
const hostItems = items ?? NO_ITEMS;
|
|
124
|
+
const catching = state.phase === "catching-up";
|
|
125
|
+
const hasTail = tail !== undefined || catching;
|
|
126
|
+
// An arriving turn grows the rows and the places made before: neither is
|
|
127
|
+
// made again over every turn, so it costs at 5,000 turns what it costs at 200.
|
|
128
|
+
const rowsMade = useRef(null);
|
|
129
|
+
const rows = useMemo(() => {
|
|
130
|
+
rowsMade.current = conversationRowsAfter(rowsMade.current, { sessions: state.sessions, items: hostItems, dayOf: calendarDayKey, tail: hasTail });
|
|
131
|
+
return rowsMade.current.rows;
|
|
132
|
+
}, [state.sessions, hostItems, hasTail]);
|
|
133
|
+
// Each turn's place in its session's outline, by session and key.
|
|
134
|
+
const placesMade = useRef(new Map());
|
|
135
|
+
const placed = useMemo(() => {
|
|
136
|
+
placesMade.current = turnPlacesOf(placesMade.current, state.sessions);
|
|
137
|
+
return placesMade.current;
|
|
138
|
+
}, [state.sessions]);
|
|
139
|
+
const placeOf = (sessionId, turnKey) => sessionId === undefined || turnKey === undefined ? undefined : placed.get(sessionId)?.index.get(turnKey);
|
|
140
|
+
const markOf = (sessionId, turnKey) => {
|
|
141
|
+
const index = placeOf(sessionId, turnKey);
|
|
142
|
+
return index === undefined ? undefined : placed.get(sessionId).turns[index];
|
|
143
|
+
};
|
|
144
|
+
const guessOf = (row) => estimateRowHeight(row, row.kind === "turn" ? (markOf(row.sessionId, row.turnKey)?.preview?.length ?? 0) : 0);
|
|
145
|
+
const guessesMade = useRef(null);
|
|
146
|
+
const guesses = useMemo(() => {
|
|
147
|
+
guessesMade.current = rowGuessesOf(guessesMade.current, rows, placed, guessOf);
|
|
148
|
+
return guessesMade.current.guesses;
|
|
149
|
+
}, [rows, placed]);
|
|
150
|
+
const itemOf = useMemo(() => new Map(hostItems.map((item) => [item.key, item])), [hostItems]);
|
|
151
|
+
const sessionOf = useMemo(() => new Map(state.sessions.map((session) => [session.sessionId, session])), [state.sessions]);
|
|
152
|
+
const bodyOf = (row) => row.kind === "turn" && feed !== null ? feed.body(row.sessionId, row.turnKey) : null;
|
|
153
|
+
const sideOf = (row) => {
|
|
154
|
+
switch (row.kind) {
|
|
155
|
+
case "turn":
|
|
156
|
+
return turnSides(markOf(row.sessionId, row.turnKey), bodyOf(row));
|
|
157
|
+
case "item": {
|
|
158
|
+
const side = itemOf.get(row.itemKey)?.side ?? "none";
|
|
159
|
+
return { first: side, last: side };
|
|
160
|
+
}
|
|
161
|
+
case "tail":
|
|
162
|
+
return { first: "agent", last: "agent" };
|
|
163
|
+
default:
|
|
164
|
+
return { first: "none", last: "none" };
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const root = useRef(null);
|
|
168
|
+
const scroller = useRef(null);
|
|
169
|
+
const turnRows = rows.some((row) => row.kind === "turn");
|
|
170
|
+
const windowed = useConversationWindow({
|
|
171
|
+
rows,
|
|
172
|
+
estimate: (row, index) => (rows[index] === row ? guesses[index] : guessOf(row)),
|
|
173
|
+
measured: (row) => row.kind !== "turn" || bodyOf(row) !== null,
|
|
174
|
+
scroller,
|
|
175
|
+
root,
|
|
176
|
+
ready: state.phase !== "reading" && rows.length > 0,
|
|
177
|
+
// The turns in view, or the nearest ones when only other rows are (a tall
|
|
178
|
+
// tail, a host's item, a day): a reader at the foot is never read as at the
|
|
179
|
+
// top, which would reach every earlier session.
|
|
180
|
+
onRange: (first, last) => {
|
|
181
|
+
if (feed === null)
|
|
182
|
+
return;
|
|
183
|
+
feed.setViewport(viewportOfRows(rows, first, last));
|
|
184
|
+
},
|
|
185
|
+
onAway,
|
|
186
|
+
});
|
|
187
|
+
// The chain's newest turn, told to the host when it changes.
|
|
188
|
+
const latest = state.latest;
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
onLatest?.(latest);
|
|
191
|
+
}, [latest]);
|
|
192
|
+
const rowsNow = useRef(rows);
|
|
193
|
+
rowsNow.current = rows;
|
|
194
|
+
useImperativeHandle(ref, () => ({
|
|
195
|
+
scrollToLatest: () => windowed.scrollToLatest(),
|
|
196
|
+
async jumpTo(target) {
|
|
197
|
+
if (feed === null)
|
|
198
|
+
return false;
|
|
199
|
+
const at = await feed.locate(target);
|
|
200
|
+
if (at === null)
|
|
201
|
+
return false;
|
|
202
|
+
const key = `t:${at.sessionId}:${at.turnKey}`;
|
|
203
|
+
for (let frame = 0; frame < 120; frame += 1) {
|
|
204
|
+
if (rowsNow.current.some((row) => row.key === key))
|
|
205
|
+
return windowed.scrollToKey(key);
|
|
206
|
+
await new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
},
|
|
210
|
+
}), [feed, windowed]);
|
|
211
|
+
const drawRow = (row, index) => {
|
|
212
|
+
switch (row.kind) {
|
|
213
|
+
case "boundary": {
|
|
214
|
+
const at = chain.indexOf(row.sessionId);
|
|
215
|
+
const before = at > 0 ? chain[at - 1] : null;
|
|
216
|
+
const session = sessionOf.get(row.sessionId);
|
|
217
|
+
const drawn = renderBoundary?.({ before, after: row.sessionId }) ?? (before === null ? null : _jsx("div", { className: "tr-conv__boundary" }));
|
|
218
|
+
return session?.unavailable != null ? _jsxs(_Fragment, { children: [drawn, _jsx("div", { className: "tr-conv__state", children: (unavailable ?? defaultUnavailable)(session.unavailable) })] }) : drawn;
|
|
219
|
+
}
|
|
220
|
+
case "day": {
|
|
221
|
+
const at = markOf(row.sessionId, row.turnKey)?.first_at ?? null;
|
|
222
|
+
return at === null ? null : _jsx("div", { className: "tr-conv__day", children: dayWords?.(at) ?? sittingDayLabel(at, viewerDay.now) });
|
|
223
|
+
}
|
|
224
|
+
case "turn": {
|
|
225
|
+
const body = bodyOf(row);
|
|
226
|
+
const outlineIndex = placeOf(row.sessionId, row.turnKey) ?? -1;
|
|
227
|
+
const lead = conversationLeads(index > 0 ? [rows[index - 1], row] : [row], sideOf).has(row.key);
|
|
228
|
+
if (body === null) {
|
|
229
|
+
return _jsx("div", { className: "tr-conv__placeholder", "aria-busy": "true", style: { height: windowed.virtualizer.options.estimateSize(index) } });
|
|
230
|
+
}
|
|
231
|
+
return _jsx(ConversationTurnView, { sessionId: row.sessionId, turn: body, index: outlineIndex, lead: lead, slots: slots });
|
|
232
|
+
}
|
|
233
|
+
case "item": {
|
|
234
|
+
const item = itemOf.get(row.itemKey);
|
|
235
|
+
if (item === undefined || renderItem === undefined)
|
|
236
|
+
return null;
|
|
237
|
+
const lead = conversationLeads(index > 0 ? [rows[index - 1], row] : [row], sideOf).has(row.key);
|
|
238
|
+
return renderItem(item, { lead, latest });
|
|
239
|
+
}
|
|
240
|
+
case "tail":
|
|
241
|
+
if (catching)
|
|
242
|
+
return _jsx("div", { className: "tr-conv__state", role: "status", children: catchingUp ?? CONVERSATION_WORDS.catchingUp });
|
|
243
|
+
return typeof tail === "function" ? tail(latest) : tail;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const phase = state.phase;
|
|
247
|
+
const showEmpty = phase === "ready" && !turnRows && state.atTop;
|
|
248
|
+
const body = phase === "unavailable" && state.unavailable !== null ? (_jsx("div", { className: "tr-conv__state", children: (unavailable ?? defaultUnavailable)(state.unavailable) })) : phase === "reading" && !turnRows ? (_jsx("div", { className: "tr-conv__state", role: "status", children: reading ?? CONVERSATION_WORDS.reading })) : null;
|
|
249
|
+
return (_jsx(PartsContext.Provider, { value: parts, children: _jsx(ConversationGalleryHost, { homeDir: partsHost?.homeDir ?? null, onReceipt: setReceipt, children: _jsxs("div", { ref: root, className: "tr-conv", "data-conv-state": phase, "aria-label": label ?? CONVERSATION_WORDS.label, "aria-busy": phase === "reading" || phase === "catching-up", children: [head, _jsx("div", { ref: scroller, className: "tr-conv__scroll", children: body ?? (_jsxs(_Fragment, { children: [showEmpty && _jsx("div", { className: "tr-conv__state", children: empty ?? CONVERSATION_WORDS.empty }), _jsx("div", { className: "tr-conv__list", style: { height: windowed.totalSize }, children: windowed.items.map((item) => {
|
|
250
|
+
const row = rows[item.index];
|
|
251
|
+
if (row === undefined)
|
|
252
|
+
return null;
|
|
253
|
+
return (_jsx("div", { ref: windowed.measure, "data-index": item.index, "data-conv-row": row.kind, "data-key": row.key, className: "tr-conv__row", style: { transform: `translateY(${item.start}px)`, paddingLeft: windowed.box.left,
|
|
254
|
+
paddingRight: windowed.box.right }, children: _jsx("div", { className: "tr-conv__cell", children: drawRow(row, item.index) }) }, item.key));
|
|
255
|
+
}) })] })) }), foot, _jsx("p", { className: "tr-conv__receipt", role: "status", "aria-live": "polite", children: receipt })] }) }) }));
|
|
256
|
+
}
|
|
257
|
+
const NO_ITEMS = Object.freeze([]);
|