@vibefield/rosetta-room 0.1.11 → 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 +64 -2
- package/dist/components/Transcript.js +6 -2
- 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/transcript/Activity.d.ts +10 -4
- package/dist/components/transcript/Activity.js +36 -11
- package/dist/components/transcript/Compaction.d.ts +9 -0
- package/dist/components/transcript/Compaction.js +8 -4
- 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 +3 -3
- 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/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/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 +3 -0
- package/dist/room-context.d.ts +1 -7
- package/dist/room-context.js +12 -18
- package/dist/styles/conversation-turn.css +147 -0
- package/dist/styles/conversation.css +45 -0
- package/dist/styles/transcript.css +11 -2
- package/package.json +9 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ConversationView } from "./ConversationView.js";
|
|
2
|
+
export { conversationLeads, conversationRowsOf, estimateRowHeight, knownParts, turnStateOf } from "./model.js";
|
|
3
|
+
export type { ConversationRowRef, ConversationRowSides, ConversationRowsInput, ConversationSide } from "./model.js";
|
|
4
|
+
export { isTurnsUnsupported, TURNS_UNSUPPORTED_ERROR } from "./ports.js";
|
|
5
|
+
export type { ConversationHostItem, ConversationLatest, ConversationMedia, ConversationPrompt, ConversationSessionClient, ConversationSessionPort, ConversationTurnFacts, ConversationUnavailable, ConversationViewHandle, ConversationViewProps, ConversationViewWords, TurnsSubscriptionHandlers, } from "./ports.js";
|
|
6
|
+
export { CONVERSATION_WORDS, defaultOutcomeWords, defaultRequestWords, defaultRunWords } from "./words.js";
|
|
7
|
+
export type { ConversationWords } from "./words.js";
|
|
8
|
+
export { defaultRunRowWords } from "./ConversationRunRows.js";
|
|
9
|
+
export type { RunRowWords } from "./ConversationRunRows.js";
|
|
10
|
+
export { ConversationProse } from "./ConversationProse.js";
|
|
11
|
+
export type { ConversationProseProps } from "./ConversationProse.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @vibefield/rosetta-room/conversation: the conversation view, an entry of its
|
|
2
|
+
// own. It reads one conversation by turns over a chain of sessions, through a
|
|
3
|
+
// session port and the room's asset source, and draws it windowed with the
|
|
4
|
+
// room's own prose, pictures and videos. Its static import graph reaches none
|
|
5
|
+
// of the room's file viewer, charts, worktree, git or search, and no mille or
|
|
6
|
+
// Radix package, so a host can load it apart from the room. Its stylesheet is
|
|
7
|
+
// `@vibefield/rosetta-room/styles/conversation.css`.
|
|
8
|
+
//
|
|
9
|
+
// Two of its parts are for a host's own drawing beside the view's. The
|
|
10
|
+
// `runLead` slot draws a host's node before a run line's words, inside the
|
|
11
|
+
// line, in a span of its own that assistive tech skips; the gap after it is the
|
|
12
|
+
// sheet's (`--tr-conv-run-lead-gap`, 6px by default). `ConversationProse` is the
|
|
13
|
+
// component the view draws every reply's words with: a host draws a reply still
|
|
14
|
+
// being written with it in the `tail`, passing the view's `links`, so nothing
|
|
15
|
+
// changes look when the reply lands.
|
|
16
|
+
//
|
|
17
|
+
// The lines a turn draws of its runs, of the parts its read left out and of
|
|
18
|
+
// its media are a host's to say through `words` (`ConversationViewWords`).
|
|
19
|
+
// Each is the whole line: the view adds nothing to it.
|
|
20
|
+
export { ConversationView } from "./ConversationView.js";
|
|
21
|
+
export { conversationLeads, conversationRowsOf, estimateRowHeight, knownParts, turnStateOf } from "./model.js";
|
|
22
|
+
export { isTurnsUnsupported, TURNS_UNSUPPORTED_ERROR } from "./ports.js";
|
|
23
|
+
export { CONVERSATION_WORDS, defaultOutcomeWords, defaultRequestWords, defaultRunWords } from "./words.js";
|
|
24
|
+
export { defaultRunRowWords } from "./ConversationRunRows.js";
|
|
25
|
+
export { ConversationProse } from "./ConversationProse.js";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { TurnPart, TurnState } from "@vibefield/rosetta-protocol";
|
|
2
|
+
import type { ConversationHostItem } from "./ports.js";
|
|
3
|
+
/**
|
|
4
|
+
* One row of the view, by key: a session's boundary (`b:<sid>`), a day
|
|
5
|
+
* (`d:<sid>:<turnKey>`, before the turn it opens), a turn (`t:<sid>:<turnKey>`),
|
|
6
|
+
* a host's item (`i:<item.key>`) or the tail (`tail`). A day row's time is its
|
|
7
|
+
* turn's own `first_at`, which is never null for a turn that opens a day.
|
|
8
|
+
*/
|
|
9
|
+
export interface ConversationRowRef {
|
|
10
|
+
kind: "boundary" | "day" | "turn" | "item" | "tail";
|
|
11
|
+
key: string;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
turnKey?: string;
|
|
14
|
+
itemKey?: string;
|
|
15
|
+
}
|
|
16
|
+
/** What the rows are made from: the chain's outlines (or any list of each
|
|
17
|
+
* session's turn keys and first times), never a turn's body, so the list's
|
|
18
|
+
* length is known before a body is read. */
|
|
19
|
+
export interface ConversationRowsInput {
|
|
20
|
+
sessions: readonly {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
turns: readonly {
|
|
23
|
+
key: string;
|
|
24
|
+
first_at: number | null;
|
|
25
|
+
}[];
|
|
26
|
+
}[];
|
|
27
|
+
items: readonly ConversationHostItem[];
|
|
28
|
+
dayOf(at: number): string;
|
|
29
|
+
tail: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The view's rows, in the order it draws them.
|
|
33
|
+
*
|
|
34
|
+
* - Each session of the chain opens with its boundary row.
|
|
35
|
+
* - Each turn is its turn row, after a day row when the calendar day of its
|
|
36
|
+
* time differs from the turn's before it in the chain. The chain's first
|
|
37
|
+
* turn has a day row, since no turn before it shares its day.
|
|
38
|
+
* - A turn whose `first_at` is null takes the time of the turn before it; a
|
|
39
|
+
* turn with no time and none before it has no day row.
|
|
40
|
+
* - A host's item stands after the last turn of the chain whose time is at or
|
|
41
|
+
* before the item's `at`. An item earlier than every turn (or when no turn
|
|
42
|
+
* has a time) stands after the first boundary; with no session at all, at
|
|
43
|
+
* the top. Items that stand after the same row are in time order, and items
|
|
44
|
+
* of the same time keep the host's order.
|
|
45
|
+
* - The tail, when asked, is last.
|
|
46
|
+
*/
|
|
47
|
+
export declare function conversationRowsOf(input: ConversationRowsInput): readonly ConversationRowRef[];
|
|
48
|
+
/** Rows `conversationRowsAfter` made, and the time the next ones grow from. */
|
|
49
|
+
export interface ConversationRowsMade {
|
|
50
|
+
readonly input: ConversationRowsInput;
|
|
51
|
+
readonly rows: readonly ConversationRowRef[];
|
|
52
|
+
/** The time the chain's last turn stands at (its own, or the one it took
|
|
53
|
+
* from a turn before it); null when no turn has a time. */
|
|
54
|
+
readonly lastAt: number | null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* `conversationRowsOf(input)`: the same rows in the same order, made from the
|
|
58
|
+
* rows of the input before it when the new one only adds turns at the end of
|
|
59
|
+
* the chain's last session (a turn heard live). The rows before stay as they
|
|
60
|
+
* were and only the new turns' rows are made, so an arriving turn costs at
|
|
61
|
+
* 5,000 turns what it costs at 200. Anything else (a session reached or
|
|
62
|
+
* dropped, a turn's key or time changed, other items, the tail asked or not)
|
|
63
|
+
* makes them whole.
|
|
64
|
+
*
|
|
65
|
+
* The kept rows stay right because of the host's items alone could anything
|
|
66
|
+
* before the new turns move: an item stands after the last turn at or before
|
|
67
|
+
* it, so new turns at or after the last turn's time move only the items that
|
|
68
|
+
* stood after that last turn, and those are placed again among the new turns.
|
|
69
|
+
* A new turn earlier than it makes the rows whole.
|
|
70
|
+
*/
|
|
71
|
+
export declare function conversationRowsAfter(previous: ConversationRowsMade | null, input: ConversationRowsInput): ConversationRowsMade;
|
|
72
|
+
/** Whose a part of a row is: the agent's, the person's, or no one's. */
|
|
73
|
+
export type ConversationSide = "agent" | "person" | "none";
|
|
74
|
+
/** The side a row opens on and the side it ends on. A turn opens on its
|
|
75
|
+
* prompt's side (the person's; the agent's when it has no prompt) and ends on
|
|
76
|
+
* its parts'; an item is its own `side` at both ends; a day, a boundary or a
|
|
77
|
+
* row with nothing in it is `none`. */
|
|
78
|
+
export interface ConversationRowSides {
|
|
79
|
+
readonly first: ConversationSide;
|
|
80
|
+
readonly last: ConversationSide;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The keys of the rows on which the agent's lead draws: once per run of the
|
|
84
|
+
* agent's rows. A row that opens on the agent's side draws it when the row
|
|
85
|
+
* before it did not end there (a day row, a boundary, a person's item or a
|
|
86
|
+
* prompt breaks the run). A row that opens on another side and ends on the
|
|
87
|
+
* agent's (a turn with a prompt and an answer) draws it inside, on its first
|
|
88
|
+
* part after the prompt.
|
|
89
|
+
*/
|
|
90
|
+
export declare function conversationLeads(rows: readonly ConversationRowRef[], sideOf: (row: ConversationRowRef) => ConversationRowSides): ReadonlySet<string>;
|
|
91
|
+
/** The estimate's figures, in px: a turn grows with its prompt's preview. */
|
|
92
|
+
export declare const ROW_ESTIMATE: Readonly<{
|
|
93
|
+
turn: 48;
|
|
94
|
+
perPreviewByte: 0.35;
|
|
95
|
+
day: 28;
|
|
96
|
+
boundary: 28;
|
|
97
|
+
item: 48;
|
|
98
|
+
tail: 48;
|
|
99
|
+
}>;
|
|
100
|
+
/** A row's height before it was measured: 48 + 0.35 × the preview's length
|
|
101
|
+
* for a turn, 28 for a day or a boundary, 48 for a host's item or the tail. A
|
|
102
|
+
* height the view has measured wins over this. */
|
|
103
|
+
export declare function estimateRowHeight(row: ConversationRowRef, previewBytes: number): number;
|
|
104
|
+
/** A turn's state as this build reads it: a state it does not know is `unknown`. */
|
|
105
|
+
export declare function turnStateOf(state: string): TurnState;
|
|
106
|
+
/** A turn's parts less those whose `kind` this build does not know. The same
|
|
107
|
+
* array when every part is known, so a drawing memoised on it stays put. */
|
|
108
|
+
export declare function knownParts(parts: readonly TurnPart[]): readonly TurnPart[];
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The view's rows, in the order it draws them.
|
|
3
|
+
*
|
|
4
|
+
* - Each session of the chain opens with its boundary row.
|
|
5
|
+
* - Each turn is its turn row, after a day row when the calendar day of its
|
|
6
|
+
* time differs from the turn's before it in the chain. The chain's first
|
|
7
|
+
* turn has a day row, since no turn before it shares its day.
|
|
8
|
+
* - A turn whose `first_at` is null takes the time of the turn before it; a
|
|
9
|
+
* turn with no time and none before it has no day row.
|
|
10
|
+
* - A host's item stands after the last turn of the chain whose time is at or
|
|
11
|
+
* before the item's `at`. An item earlier than every turn (or when no turn
|
|
12
|
+
* has a time) stands after the first boundary; with no session at all, at
|
|
13
|
+
* the top. Items that stand after the same row are in time order, and items
|
|
14
|
+
* of the same time keep the host's order.
|
|
15
|
+
* - The tail, when asked, is last.
|
|
16
|
+
*/
|
|
17
|
+
export function conversationRowsOf(input) {
|
|
18
|
+
const turns = [];
|
|
19
|
+
let before = null;
|
|
20
|
+
for (const session of input.sessions) {
|
|
21
|
+
for (const turn of session.turns) {
|
|
22
|
+
const at = turn.first_at ?? before;
|
|
23
|
+
turns.push({ sessionId: session.sessionId, key: turn.key, at });
|
|
24
|
+
before = at;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const placed = itemsByTurn(turns, input.items);
|
|
28
|
+
const rows = [];
|
|
29
|
+
const item = (each) => ({ kind: "item", key: `i:${each.key}`, itemKey: each.key });
|
|
30
|
+
let index = 0;
|
|
31
|
+
let day = null;
|
|
32
|
+
for (const [s, session] of input.sessions.entries()) {
|
|
33
|
+
const sessionId = session.sessionId;
|
|
34
|
+
rows.push({ kind: "boundary", key: `b:${sessionId}`, sessionId });
|
|
35
|
+
if (s === 0)
|
|
36
|
+
for (const each of placed[0])
|
|
37
|
+
rows.push(item(each));
|
|
38
|
+
for (const turn of session.turns) {
|
|
39
|
+
const at = turns[index].at;
|
|
40
|
+
if (at !== null) {
|
|
41
|
+
const here = input.dayOf(at);
|
|
42
|
+
if (here !== day)
|
|
43
|
+
rows.push({ kind: "day", key: `d:${sessionId}:${turn.key}`, sessionId, turnKey: turn.key });
|
|
44
|
+
day = here;
|
|
45
|
+
}
|
|
46
|
+
rows.push({ kind: "turn", key: `t:${sessionId}:${turn.key}`, sessionId, turnKey: turn.key });
|
|
47
|
+
index += 1;
|
|
48
|
+
for (const each of placed[index])
|
|
49
|
+
rows.push(item(each));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (input.sessions.length === 0)
|
|
53
|
+
for (const each of placed[0])
|
|
54
|
+
rows.push(item(each));
|
|
55
|
+
if (input.tail)
|
|
56
|
+
rows.push({ kind: "tail", key: "tail" });
|
|
57
|
+
return rows;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* `conversationRowsOf(input)`: the same rows in the same order, made from the
|
|
61
|
+
* rows of the input before it when the new one only adds turns at the end of
|
|
62
|
+
* the chain's last session (a turn heard live). The rows before stay as they
|
|
63
|
+
* were and only the new turns' rows are made, so an arriving turn costs at
|
|
64
|
+
* 5,000 turns what it costs at 200. Anything else (a session reached or
|
|
65
|
+
* dropped, a turn's key or time changed, other items, the tail asked or not)
|
|
66
|
+
* makes them whole.
|
|
67
|
+
*
|
|
68
|
+
* The kept rows stay right because of the host's items alone could anything
|
|
69
|
+
* before the new turns move: an item stands after the last turn at or before
|
|
70
|
+
* it, so new turns at or after the last turn's time move only the items that
|
|
71
|
+
* stood after that last turn, and those are placed again among the new turns.
|
|
72
|
+
* A new turn earlier than it makes the rows whole.
|
|
73
|
+
*/
|
|
74
|
+
export function conversationRowsAfter(previous, input) {
|
|
75
|
+
const grown = previous === null ? null : grownTurns(previous, input);
|
|
76
|
+
if (previous === null || grown === null) {
|
|
77
|
+
let lastAt = null;
|
|
78
|
+
for (const session of input.sessions)
|
|
79
|
+
for (const turn of session.turns)
|
|
80
|
+
lastAt = turn.first_at ?? lastAt;
|
|
81
|
+
return { input, rows: conversationRowsOf(input), lastAt };
|
|
82
|
+
}
|
|
83
|
+
const session = input.sessions[input.sessions.length - 1];
|
|
84
|
+
const added = session.turns.slice(session.turns.length - grown);
|
|
85
|
+
const ats = [];
|
|
86
|
+
let before = previous.lastAt;
|
|
87
|
+
for (const turn of added) {
|
|
88
|
+
before = turn.first_at ?? before;
|
|
89
|
+
ats.push(before);
|
|
90
|
+
}
|
|
91
|
+
const lastAt = previous.lastAt;
|
|
92
|
+
if (input.items.length > 0 && (lastAt === null || ats.some((at) => at === null || at < lastAt))) {
|
|
93
|
+
return conversationRowsAfter(null, input);
|
|
94
|
+
}
|
|
95
|
+
// The rows after the last turn row before: the items that stood after it,
|
|
96
|
+
// then the tail.
|
|
97
|
+
const rows = previous.rows.slice();
|
|
98
|
+
if (input.tail)
|
|
99
|
+
rows.pop();
|
|
100
|
+
let cut = rows.length;
|
|
101
|
+
while (cut > 0 && rows[cut - 1].kind === "item")
|
|
102
|
+
cut -= 1;
|
|
103
|
+
const moved = cut === rows.length ? [] : rows.splice(cut).map((row) => row.itemKey);
|
|
104
|
+
const itemOf = moved.length === 0 ? null : new Map(input.items.map((each) => [each.key, each]));
|
|
105
|
+
const placed = itemsByTurn(ats.map((at) => ({ at })), moved.map((key) => itemOf.get(key)));
|
|
106
|
+
const item = (each) => ({ kind: "item", key: `i:${each.key}`, itemKey: each.key });
|
|
107
|
+
for (const each of placed[0])
|
|
108
|
+
rows.push(item(each));
|
|
109
|
+
const sessionId = session.sessionId;
|
|
110
|
+
let day = lastAt === null ? null : input.dayOf(lastAt);
|
|
111
|
+
for (const [i, turn] of added.entries()) {
|
|
112
|
+
const at = ats[i];
|
|
113
|
+
if (at !== null) {
|
|
114
|
+
const here = input.dayOf(at);
|
|
115
|
+
if (here !== day)
|
|
116
|
+
rows.push({ kind: "day", key: `d:${sessionId}:${turn.key}`, sessionId, turnKey: turn.key });
|
|
117
|
+
day = here;
|
|
118
|
+
}
|
|
119
|
+
rows.push({ kind: "turn", key: `t:${sessionId}:${turn.key}`, sessionId, turnKey: turn.key });
|
|
120
|
+
for (const each of placed[i + 1])
|
|
121
|
+
rows.push(item(each));
|
|
122
|
+
}
|
|
123
|
+
if (input.tail)
|
|
124
|
+
rows.push({ kind: "tail", key: "tail" });
|
|
125
|
+
return { input, rows, lastAt: ats[ats.length - 1] ?? null };
|
|
126
|
+
}
|
|
127
|
+
/** How many turns `input` adds at the end of the chain's last session to the
|
|
128
|
+
* input `previous` was made from, all else as it was; null when anything else
|
|
129
|
+
* changed, or the last session had no turn. */
|
|
130
|
+
function grownTurns(previous, input) {
|
|
131
|
+
const was = previous.input;
|
|
132
|
+
if (input.items !== was.items || input.dayOf !== was.dayOf || input.tail !== was.tail)
|
|
133
|
+
return null;
|
|
134
|
+
const count = input.sessions.length;
|
|
135
|
+
if (count === 0 || count !== was.sessions.length)
|
|
136
|
+
return null;
|
|
137
|
+
for (let s = 0; s < count; s += 1) {
|
|
138
|
+
const now = input.sessions[s];
|
|
139
|
+
const then = was.sessions[s];
|
|
140
|
+
if (now === then) {
|
|
141
|
+
if (s === count - 1)
|
|
142
|
+
return null;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (now.sessionId !== then.sessionId)
|
|
146
|
+
return null;
|
|
147
|
+
if (s < count - 1 && (now.turns.length !== then.turns.length || !samePrefix(now.turns, then.turns)))
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
const now = input.sessions[count - 1].turns;
|
|
151
|
+
const then = was.sessions[count - 1].turns;
|
|
152
|
+
if (then.length === 0 || now.length <= then.length || !samePrefix(now, then))
|
|
153
|
+
return null;
|
|
154
|
+
return now.length - then.length;
|
|
155
|
+
}
|
|
156
|
+
/** `now` begins with `then`'s turns: the same keys and times. */
|
|
157
|
+
function samePrefix(now, then) {
|
|
158
|
+
if (now === then)
|
|
159
|
+
return true;
|
|
160
|
+
for (let i = 0; i < then.length; i += 1) {
|
|
161
|
+
const a = now[i];
|
|
162
|
+
const b = then[i];
|
|
163
|
+
if (a !== b && (a.key !== b.key || a.first_at !== b.first_at))
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The host's items grouped by the row they stand after: slot 0 is before
|
|
170
|
+
* every turn, slot i + 1 after the chain's i-th turn. The last turn at or
|
|
171
|
+
* before an item is found by halving over the turns' suffix minimum, which is
|
|
172
|
+
* never decreasing, so the answer holds whether or not the times are in order.
|
|
173
|
+
* The items are taken in time order (a stable sort: the same time keeps the
|
|
174
|
+
* host's order), so each slot is in time order too.
|
|
175
|
+
*/
|
|
176
|
+
function itemsByTurn(turns, items) {
|
|
177
|
+
const slots = Array.from({ length: turns.length + 1 }, () => []);
|
|
178
|
+
if (items.length === 0)
|
|
179
|
+
return slots;
|
|
180
|
+
const suffixMin = new Array(turns.length);
|
|
181
|
+
let least = Number.POSITIVE_INFINITY;
|
|
182
|
+
for (let i = turns.length - 1; i >= 0; i -= 1) {
|
|
183
|
+
const at = turns[i].at;
|
|
184
|
+
if (at !== null && at < least)
|
|
185
|
+
least = at;
|
|
186
|
+
suffixMin[i] = least;
|
|
187
|
+
}
|
|
188
|
+
for (const item of [...items].sort((a, b) => a.at - b.at)) {
|
|
189
|
+
// The largest i whose suffix minimum is at or before the item: that turn's
|
|
190
|
+
// own time is, and no later turn's is.
|
|
191
|
+
let low = 0;
|
|
192
|
+
let high = turns.length;
|
|
193
|
+
while (low < high) {
|
|
194
|
+
const mid = (low + high) >>> 1;
|
|
195
|
+
if (suffixMin[mid] <= item.at)
|
|
196
|
+
low = mid + 1;
|
|
197
|
+
else
|
|
198
|
+
high = mid;
|
|
199
|
+
}
|
|
200
|
+
slots[low].push(item);
|
|
201
|
+
}
|
|
202
|
+
return slots;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The keys of the rows on which the agent's lead draws: once per run of the
|
|
206
|
+
* agent's rows. A row that opens on the agent's side draws it when the row
|
|
207
|
+
* before it did not end there (a day row, a boundary, a person's item or a
|
|
208
|
+
* prompt breaks the run). A row that opens on another side and ends on the
|
|
209
|
+
* agent's (a turn with a prompt and an answer) draws it inside, on its first
|
|
210
|
+
* part after the prompt.
|
|
211
|
+
*/
|
|
212
|
+
export function conversationLeads(rows, sideOf) {
|
|
213
|
+
const leads = new Set();
|
|
214
|
+
let before = "none";
|
|
215
|
+
for (const row of rows) {
|
|
216
|
+
const { first, last } = sideOf(row);
|
|
217
|
+
if (first === "agent" ? before !== "agent" : last === "agent")
|
|
218
|
+
leads.add(row.key);
|
|
219
|
+
before = last;
|
|
220
|
+
}
|
|
221
|
+
return leads;
|
|
222
|
+
}
|
|
223
|
+
/* ── a row's height before it is measured ────────────────────────────────── */
|
|
224
|
+
/** The estimate's figures, in px: a turn grows with its prompt's preview. */
|
|
225
|
+
export const ROW_ESTIMATE = Object.freeze({ turn: 48, perPreviewByte: 0.35, day: 28, boundary: 28, item: 48, tail: 48 });
|
|
226
|
+
/** A row's height before it was measured: 48 + 0.35 × the preview's length
|
|
227
|
+
* for a turn, 28 for a day or a boundary, 48 for a host's item or the tail. A
|
|
228
|
+
* height the view has measured wins over this. */
|
|
229
|
+
export function estimateRowHeight(row, previewBytes) {
|
|
230
|
+
switch (row.kind) {
|
|
231
|
+
case "turn":
|
|
232
|
+
return Math.round(ROW_ESTIMATE.turn + ROW_ESTIMATE.perPreviewByte * Math.max(0, previewBytes));
|
|
233
|
+
case "day":
|
|
234
|
+
return ROW_ESTIMATE.day;
|
|
235
|
+
case "boundary":
|
|
236
|
+
return ROW_ESTIMATE.boundary;
|
|
237
|
+
case "item":
|
|
238
|
+
return ROW_ESTIMATE.item;
|
|
239
|
+
case "tail":
|
|
240
|
+
return ROW_ESTIMATE.tail;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/* ── the reader's rules ──────────────────────────────────────────────────── */
|
|
244
|
+
const TURN_STATES = { finished: true, failed: true, stopped: true, cut_off: true, open: true, unknown: true };
|
|
245
|
+
/** A turn's state as this build reads it: a state it does not know is `unknown`. */
|
|
246
|
+
export function turnStateOf(state) {
|
|
247
|
+
return Object.hasOwn(TURN_STATES, state) ? state : "unknown";
|
|
248
|
+
}
|
|
249
|
+
const PART_KINDS = { reply: true, request: true, compaction: true, run: true };
|
|
250
|
+
function isKnownPart(part) {
|
|
251
|
+
return typeof part === "object" && part !== null && Object.hasOwn(PART_KINDS, part.kind);
|
|
252
|
+
}
|
|
253
|
+
/** A turn's parts less those whose `kind` this build does not know. The same
|
|
254
|
+
* array when every part is known, so a drawing memoised on it stays put. */
|
|
255
|
+
export function knownParts(parts) {
|
|
256
|
+
return parts.every(isKnownPart) ? parts : parts.filter(isKnownPart);
|
|
257
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import type { AssetRef, AttachmentRef, McpCalls, TimelineEntry, TimelinePage, TurnOutcome, TurnOutline, TurnPage, TurnRun, TurnsSubscriptionHandlers } from "@vibefield/rosetta-protocol";
|
|
2
|
+
import type { ReactNode, Ref } from "react";
|
|
3
|
+
import type { AssetSource } from "../ports.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a turns subscription tells its reader: one snapshot of the newest turns
|
|
6
|
+
* (with the session's outline when it was asked for), then each turn that
|
|
7
|
+
* changed or arrived, a reset whenever the session must be read again, its
|
|
8
|
+
* status, and its errors. It is the client's own type, so a view and the client
|
|
9
|
+
* that serves it cannot drift apart: `rosetta-client.ts` holds the two together
|
|
10
|
+
* at compile time.
|
|
11
|
+
*
|
|
12
|
+
* A daemon with no turn reads is told by `onError` with the client's
|
|
13
|
+
* `TurnsUnsupportedError`. The view reads it by its `name`
|
|
14
|
+
* (`isTurnsUnsupported`), so that this module imports no class of the client.
|
|
15
|
+
*/
|
|
16
|
+
export type { TurnsSubscriptionHandlers };
|
|
17
|
+
/** The `name` the client's error carries when a daemon has no turn reads: a
|
|
18
|
+
* daemon before them answers a turn route as it answers any route it does not
|
|
19
|
+
* know, and a turns socket with a timeline snapshot. */
|
|
20
|
+
export declare const TURNS_UNSUPPORTED_ERROR = "TurnsUnsupportedError";
|
|
21
|
+
/** True for the client's "this daemon has no turn reads" error, told by its
|
|
22
|
+
* name so that no import of the client's class is needed. */
|
|
23
|
+
export declare function isTurnsUnsupported(error: unknown): boolean;
|
|
24
|
+
/** What the view asks of ONE session. A RosettaClient is one once it reads
|
|
25
|
+
* turns: a compile check holds the two together from then on. */
|
|
26
|
+
export interface ConversationSessionClient {
|
|
27
|
+
subscribeTurns(sessionId: string, h: TurnsSubscriptionHandlers, o?: {
|
|
28
|
+
limit?: number;
|
|
29
|
+
outline?: boolean;
|
|
30
|
+
}): {
|
|
31
|
+
close(): void;
|
|
32
|
+
};
|
|
33
|
+
turnOutline(sessionId: string, signal?: AbortSignal): Promise<TurnOutline>;
|
|
34
|
+
turns(sessionId: string, o?: {
|
|
35
|
+
limit?: number;
|
|
36
|
+
before?: number;
|
|
37
|
+
since?: number;
|
|
38
|
+
watermark?: string;
|
|
39
|
+
}, signal?: AbortSignal): Promise<TurnPage>;
|
|
40
|
+
turnRows(sessionId: string, key: string, o?: {
|
|
41
|
+
first?: number;
|
|
42
|
+
last?: number;
|
|
43
|
+
limit?: number;
|
|
44
|
+
cursor?: string;
|
|
45
|
+
}, signal?: AbortSignal): Promise<TimelinePage>;
|
|
46
|
+
readAsset(asset: AssetRef, signal?: AbortSignal): Promise<Uint8Array>;
|
|
47
|
+
readTextAsset(asset: AssetRef, signal?: AbortSignal): Promise<string>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Opens one session for the view. `open` may answer at once or with a promise
|
|
51
|
+
* (a host that must ask for a credential first). The view opens each session
|
|
52
|
+
* once, for its turn reads and its parts together, and follows every `open`
|
|
53
|
+
* with exactly one `close`.
|
|
54
|
+
*/
|
|
55
|
+
export interface ConversationSessionPort {
|
|
56
|
+
open(sessionId: string): ConversationSessionClient | PromiseLike<ConversationSessionClient>;
|
|
57
|
+
close(sessionId: string): void;
|
|
58
|
+
}
|
|
59
|
+
/** One thing the host places among the turns by its time: `side` says whose it
|
|
60
|
+
* is, for the agent's lead. */
|
|
61
|
+
export interface ConversationHostItem {
|
|
62
|
+
readonly key: string;
|
|
63
|
+
readonly at: number;
|
|
64
|
+
readonly side: "agent" | "person" | "none";
|
|
65
|
+
}
|
|
66
|
+
/** A turn's prompt, as the host may draw it instead of the view's own bubble.
|
|
67
|
+
* `text` is the words the bubble draws: for a prompt stored as a member (past
|
|
68
|
+
* the store's inline size), its preview until the whole text is read, then the
|
|
69
|
+
* whole; the host is asked again when it lands. */
|
|
70
|
+
export interface ConversationPrompt {
|
|
71
|
+
sessionId: string;
|
|
72
|
+
turnKey: string;
|
|
73
|
+
row: TimelineEntry;
|
|
74
|
+
text: string;
|
|
75
|
+
at: number | null;
|
|
76
|
+
}
|
|
77
|
+
/** A turn's facts, for a node the host draws after it. `index` is the turn's
|
|
78
|
+
* place in its session's outline. */
|
|
79
|
+
export interface ConversationTurnFacts {
|
|
80
|
+
sessionId: string;
|
|
81
|
+
turnKey: string;
|
|
82
|
+
index: number;
|
|
83
|
+
outcome: TurnOutcome;
|
|
84
|
+
tools: number;
|
|
85
|
+
mcp: readonly McpCalls[];
|
|
86
|
+
firstAt: number | null;
|
|
87
|
+
lastAt: number | null;
|
|
88
|
+
}
|
|
89
|
+
/** The chain's newest turn, as a host's tail and items read it. */
|
|
90
|
+
export interface ConversationLatest {
|
|
91
|
+
sessionId: string;
|
|
92
|
+
turnKey: string;
|
|
93
|
+
firstAt: number | null;
|
|
94
|
+
replies: number;
|
|
95
|
+
lastReplyOrdinal: number | null;
|
|
96
|
+
outcome: TurnOutcome;
|
|
97
|
+
running: boolean;
|
|
98
|
+
}
|
|
99
|
+
/** Why the view cannot read: the client has no turn reads, or the port
|
|
100
|
+
* refused or closed the session with its own words. */
|
|
101
|
+
export type ConversationUnavailable = {
|
|
102
|
+
kind: "unsupported";
|
|
103
|
+
} | {
|
|
104
|
+
kind: "refused" | "closed";
|
|
105
|
+
message: string;
|
|
106
|
+
};
|
|
107
|
+
/** A picture or a video the reader pressed. */
|
|
108
|
+
export interface ConversationMedia {
|
|
109
|
+
sessionId: string;
|
|
110
|
+
timelineId: string;
|
|
111
|
+
attachment: AttachmentRef;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The lines the view draws inside a turn that a host may say in its own words.
|
|
115
|
+
* Each is the WHOLE line: the view adds nothing to it. A host passes any of
|
|
116
|
+
* them as `words`; the rest are rosetta's own.
|
|
117
|
+
*/
|
|
118
|
+
export interface ConversationViewWords {
|
|
119
|
+
/** A run's rows while they are read. */
|
|
120
|
+
runReading: string;
|
|
121
|
+
/** A run's rows could not be read. Handed the read's own reason, which the
|
|
122
|
+
* line may leave out; rosetta's says it after its own words. */
|
|
123
|
+
runFailed(reason: string): string;
|
|
124
|
+
/** The press that reads a run's earlier rows. */
|
|
125
|
+
runEarlier: string;
|
|
126
|
+
/** A turn's oldest parts, `count` of them, that its read left out. */
|
|
127
|
+
omittedParts(count: number): string;
|
|
128
|
+
/** A picture that could not be loaded, and the press that tries again. */
|
|
129
|
+
mediaFailed: string;
|
|
130
|
+
mediaRetry: string;
|
|
131
|
+
/** A video's play, spoken before its facts: "‹play›, ‹name› · ‹length› · ‹size›". */
|
|
132
|
+
mediaPlay: string;
|
|
133
|
+
}
|
|
134
|
+
export interface ConversationViewProps<I extends ConversationHostItem = ConversationHostItem> {
|
|
135
|
+
sessionPort: ConversationSessionPort;
|
|
136
|
+
assets: AssetSource;
|
|
137
|
+
host?: {
|
|
138
|
+
copyText?: (text: string) => Promise<void>;
|
|
139
|
+
homeDir?: string | null;
|
|
140
|
+
} | null;
|
|
141
|
+
chain: readonly string[];
|
|
142
|
+
items?: readonly I[];
|
|
143
|
+
renderItem?(item: I, place: {
|
|
144
|
+
lead: boolean;
|
|
145
|
+
latest: ConversationLatest | null;
|
|
146
|
+
}): ReactNode;
|
|
147
|
+
renderPrompt?(prompt: ConversationPrompt, drawn: ReactNode): ReactNode;
|
|
148
|
+
renderAfterTurn?(turn: ConversationTurnFacts): ReactNode;
|
|
149
|
+
renderBoundary?(b: {
|
|
150
|
+
before: string | null;
|
|
151
|
+
after: string;
|
|
152
|
+
}): ReactNode;
|
|
153
|
+
agentLead?: ReactNode;
|
|
154
|
+
runWords?(run: TurnRun): string | null;
|
|
155
|
+
/** A node drawn before a run line's words, inside the line, in a span of its own that assistive tech skips (the
|
|
156
|
+
* words carry the meaning). Absent, or null for a run, draws nothing there and the line is as without it. */
|
|
157
|
+
runLead?(run: TurnRun): ReactNode;
|
|
158
|
+
runRowWords?(row: TimelineEntry): {
|
|
159
|
+
words: string;
|
|
160
|
+
detail?: string;
|
|
161
|
+
} | null;
|
|
162
|
+
requestWords?(row: TimelineEntry): string | null;
|
|
163
|
+
outcomeWords?(outcome: TurnOutcome): string | null;
|
|
164
|
+
compactionWords?: string;
|
|
165
|
+
dayWords?(at: number): string;
|
|
166
|
+
/** The lines of a turn's runs, parts and media in the host's words, each whole. */
|
|
167
|
+
words?: Partial<ConversationViewWords>;
|
|
168
|
+
links?: "open" | "inert";
|
|
169
|
+
onOpenMedia?(media: ConversationMedia): void;
|
|
170
|
+
head?: ReactNode;
|
|
171
|
+
foot?: ReactNode;
|
|
172
|
+
tail?: ReactNode | ((latest: ConversationLatest | null) => ReactNode);
|
|
173
|
+
empty?: ReactNode;
|
|
174
|
+
reading?: ReactNode;
|
|
175
|
+
catchingUp?: ReactNode;
|
|
176
|
+
unavailable?(reason: ConversationUnavailable): ReactNode;
|
|
177
|
+
onLatest?(latest: ConversationLatest | null): void;
|
|
178
|
+
onAway?(away: boolean, unseen: number): void;
|
|
179
|
+
label?: string;
|
|
180
|
+
ref?: Ref<ConversationViewHandle>;
|
|
181
|
+
}
|
|
182
|
+
/** What a host may ask of a mounted view. `jumpTo` answers true once the
|
|
183
|
+
* turn's row is placed, false when it is not in the chain or its row could not
|
|
184
|
+
* be placed (a row merely drawn is not placed). */
|
|
185
|
+
export interface ConversationViewHandle {
|
|
186
|
+
scrollToLatest(): void;
|
|
187
|
+
jumpTo(target: {
|
|
188
|
+
sessionId: string;
|
|
189
|
+
turnKey: string;
|
|
190
|
+
} | {
|
|
191
|
+
sessionId: string;
|
|
192
|
+
ordinal: number;
|
|
193
|
+
}): Promise<boolean>;
|
|
194
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The `name` the client's error carries when a daemon has no turn reads: a
|
|
2
|
+
* daemon before them answers a turn route as it answers any route it does not
|
|
3
|
+
* know, and a turns socket with a timeline snapshot. */
|
|
4
|
+
export const TURNS_UNSUPPORTED_ERROR = "TurnsUnsupportedError";
|
|
5
|
+
/** True for the client's "this daemon has no turn reads" error, told by its
|
|
6
|
+
* name so that no import of the client's class is needed. */
|
|
7
|
+
export function isTurnsUnsupported(error) {
|
|
8
|
+
return error instanceof Error && error.name === TURNS_UNSUPPORTED_ERROR;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RosettaClient } from "@vibefield/rosetta-protocol";
|
|
2
|
+
import type { ConversationSessionClient, TurnsSubscriptionHandlers } from "./ports.js";
|
|
3
|
+
type Holds<T extends true> = T;
|
|
4
|
+
/** A `RosettaClient` is a session client for the view. */
|
|
5
|
+
export type ClientIsASessionClient = Holds<RosettaClient extends ConversationSessionClient ? true : false>;
|
|
6
|
+
/** The handlers the view gives a turns subscription are the ones the client takes. */
|
|
7
|
+
export type HandlersAreTheClients = Holds<Parameters<RosettaClient["subscribeTurns"]>[1] extends TurnsSubscriptionHandlers ? TurnsSubscriptionHandlers extends Parameters<RosettaClient["subscribeTurns"]>[1] ? true : false : false>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SessionLeases } from "../lib/session-leases.js";
|
|
2
|
+
import type { ConversationFeed, ConversationFeedState, ConversationFeedTimers } from "./feed.js";
|
|
3
|
+
import type { ConversationSessionClient } from "./ports.js";
|
|
4
|
+
/** What the view draws before its feed is made: nothing held yet. */
|
|
5
|
+
export declare const READING_FEED_STATE: ConversationFeedState;
|
|
6
|
+
export interface ConversationFeedHold {
|
|
7
|
+
/** Null until the component mounted. */
|
|
8
|
+
readonly feed: ConversationFeed | null;
|
|
9
|
+
readonly state: ConversationFeedState;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The feed over `sessions` for `chain`. A chain with the same ids (a new
|
|
13
|
+
* array, the same sessions) changes nothing; a new lease set makes a new feed
|
|
14
|
+
* and lets the old one go.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useConversationFeed(sessions: SessionLeases<ConversationSessionClient>, chain: readonly string[], timers?: ConversationFeedTimers): ConversationFeedHold;
|