@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.
Files changed (87) hide show
  1. package/README.md +64 -2
  2. package/dist/components/Transcript.js +6 -2
  3. package/dist/components/file-viewer/kinds.d.ts +22 -0
  4. package/dist/components/file-viewer/kinds.js +57 -0
  5. package/dist/components/file-viewer/markdown/render.d.ts +7 -1
  6. package/dist/components/file-viewer/markdown/render.js +16 -12
  7. package/dist/components/file-viewer/registry.d.ts +2 -2
  8. package/dist/components/file-viewer/registry.js +20 -59
  9. package/dist/components/transcript/Activity.d.ts +10 -4
  10. package/dist/components/transcript/Activity.js +36 -11
  11. package/dist/components/transcript/Compaction.d.ts +9 -0
  12. package/dist/components/transcript/Compaction.js +8 -4
  13. package/dist/components/transcript/Document.js +150 -208
  14. package/dist/components/transcript/PromptJump.js +28 -8
  15. package/dist/components/transcript/Prose.d.ts +5 -1
  16. package/dist/components/transcript/Prose.js +3 -3
  17. package/dist/components/transcript/ReadingBlocks.d.ts +71 -0
  18. package/dist/components/transcript/ReadingBlocks.js +279 -0
  19. package/dist/components/transcript/activity-plan.d.ts +38 -7
  20. package/dist/components/transcript/activity-plan.js +198 -28
  21. package/dist/components/transcript/attachment-file-source.d.ts +1 -2
  22. package/dist/components/transcript/attachment-file-source.js +7 -5
  23. package/dist/components/transcript/disclosure-state.d.ts +2 -0
  24. package/dist/components/transcript/disclosure-state.js +6 -2
  25. package/dist/components/transcript/document-model.js +53 -9
  26. package/dist/components/transcript/document-plan.js +263 -98
  27. package/dist/components/transcript/reading-identity.d.ts +14 -1
  28. package/dist/components/transcript/reading-identity.js +126 -10
  29. package/dist/conversation/ConversationGallery.d.ts +11 -0
  30. package/dist/conversation/ConversationGallery.js +14 -0
  31. package/dist/conversation/ConversationMedia.d.ts +44 -0
  32. package/dist/conversation/ConversationMedia.js +210 -0
  33. package/dist/conversation/ConversationProse.d.ts +13 -0
  34. package/dist/conversation/ConversationProse.js +6 -0
  35. package/dist/conversation/ConversationRunRows.d.ts +57 -0
  36. package/dist/conversation/ConversationRunRows.js +84 -0
  37. package/dist/conversation/ConversationTurnView.d.ts +64 -0
  38. package/dist/conversation/ConversationTurnView.js +169 -0
  39. package/dist/conversation/ConversationView.d.ts +3 -0
  40. package/dist/conversation/ConversationView.js +257 -0
  41. package/dist/conversation/feed-reads.d.ts +36 -0
  42. package/dist/conversation/feed-reads.js +155 -0
  43. package/dist/conversation/feed.d.ts +106 -0
  44. package/dist/conversation/feed.js +884 -0
  45. package/dist/conversation/index.d.ts +11 -0
  46. package/dist/conversation/index.js +25 -0
  47. package/dist/conversation/model.d.ts +108 -0
  48. package/dist/conversation/model.js +257 -0
  49. package/dist/conversation/ports.d.ts +194 -0
  50. package/dist/conversation/ports.js +9 -0
  51. package/dist/conversation/rosetta-client.d.ts +8 -0
  52. package/dist/conversation/rosetta-client.js +1 -0
  53. package/dist/conversation/use-conversation-feed.d.ts +16 -0
  54. package/dist/conversation/use-conversation-feed.js +41 -0
  55. package/dist/conversation/use-conversation-window.d.ts +50 -0
  56. package/dist/conversation/use-conversation-window.js +336 -0
  57. package/dist/conversation/words.d.ts +51 -0
  58. package/dist/conversation/words.js +79 -0
  59. package/dist/fixtures/conversation.d.ts +34 -0
  60. package/dist/fixtures/conversation.js +723 -0
  61. package/dist/fixtures/index.d.ts +2 -0
  62. package/dist/fixtures/index.js +1 -0
  63. package/dist/lib/session-leases.d.ts +11 -8
  64. package/dist/lib/transcript/collaboration.js +53 -19
  65. package/dist/lib/transcript/head-of-document.js +9 -3
  66. package/dist/lib/transcript/index.d.ts +1 -1
  67. package/dist/lib/transcript/index.js +1 -1
  68. package/dist/lib/transcript/prompt-jump.d.ts +2 -0
  69. package/dist/lib/transcript/prompt-jump.js +5 -1
  70. package/dist/lib/transcript/sittings.d.ts +2 -1
  71. package/dist/lib/transcript/sittings.js +72 -10
  72. package/dist/lib/transcript/tail-state.d.ts +9 -0
  73. package/dist/lib/transcript/tail-state.js +25 -1
  74. package/dist/lib/transcript/turns.d.ts +5 -0
  75. package/dist/lib/transcript/turns.js +221 -57
  76. package/dist/lib/transcript/use-transcript-tail.js +17 -3
  77. package/dist/lib/transcript/vocabulary.d.ts +2 -1
  78. package/dist/lib/transcript/vocabulary.js +11 -1
  79. package/dist/parts-context.d.ts +25 -0
  80. package/dist/parts-context.js +32 -0
  81. package/dist/ports.d.ts +3 -0
  82. package/dist/room-context.d.ts +1 -7
  83. package/dist/room-context.js +12 -18
  84. package/dist/styles/conversation-turn.css +147 -0
  85. package/dist/styles/conversation.css +45 -0
  86. package/dist/styles/transcript.css +11 -2
  87. package/package.json +9 -4
@@ -0,0 +1,155 @@
1
+ /* ── where the reader is ─────────────────────────────────────────────────── */
2
+ /**
3
+ * The turns the reader sees, from the rows in view (`first` to `last`, by
4
+ * index; -1 when none is, read as the foot): the first and the last turn row
5
+ * among them. When only
6
+ * other rows are in view (a tail or a host's item taller than the view, a day,
7
+ * a boundary), the nearest turn rows stand for them: the last turn above and
8
+ * the first turn below, or the one there is when the view is above every turn
9
+ * or below every turn. Null only when the rows hold no turn at all, which the
10
+ * feed reads as the top of what is held.
11
+ */
12
+ export function viewportOfRows(rows, first, last) {
13
+ const turnAt = (i) => {
14
+ const row = rows[i];
15
+ return row?.kind === "turn" && row.sessionId !== undefined && row.turnKey !== undefined
16
+ ? { sessionId: row.sessionId, turnKey: row.turnKey }
17
+ : null;
18
+ };
19
+ const from = first < 0 ? rows.length : Math.min(first, rows.length);
20
+ const to = last < 0 ? rows.length - 1 : Math.min(last, rows.length - 1);
21
+ let low = null;
22
+ let high = null;
23
+ for (let i = from; i <= to && low === null; i += 1)
24
+ low = turnAt(i);
25
+ for (let i = to; i >= from && high === null; i -= 1)
26
+ high = turnAt(i);
27
+ if (low !== null && high !== null)
28
+ return { first: low, last: high };
29
+ let above = null;
30
+ let below = null;
31
+ for (let i = Math.min(from, rows.length) - 1; i >= 0 && above === null; i -= 1)
32
+ above = turnAt(i);
33
+ for (let i = Math.max(to + 1, 0); i < rows.length && below === null; i += 1)
34
+ below = turnAt(i);
35
+ return { first: above ?? below, last: below ?? above };
36
+ }
37
+ /* ── reading an answer ───────────────────────────────────────────────────── */
38
+ export function codeOf(error) {
39
+ const code = typeof error === "object" && error !== null ? error.code : undefined;
40
+ return typeof code === "string" ? code : null;
41
+ }
42
+ export function messageOf(error) {
43
+ if (error instanceof Error)
44
+ return error.message;
45
+ const message = typeof error === "object" && error !== null ? error.message : undefined;
46
+ return typeof message === "string" ? message : String(error);
47
+ }
48
+ /** The client's refusal of a session's credential (a 401 it does not read as
49
+ * "no turn reads"): told by its name or its status, as the client's own error
50
+ * carries them, so no import of its class is needed. */
51
+ export function isRefusedCredential(error) {
52
+ if (typeof error !== "object" || error === null)
53
+ return false;
54
+ const { name, status } = error;
55
+ return name === "UnauthorizedError" || status === 401;
56
+ }
57
+ export function isAbort(error) {
58
+ return typeof error === "object" && error !== null && error.name === "AbortError";
59
+ }
60
+ export function hasTurnReads(client) {
61
+ return (typeof client?.subscribeTurns === "function" && typeof client.turnOutline === "function" &&
62
+ typeof client.turns === "function" && typeof client.turnRows === "function");
63
+ }
64
+ /** A promise of what `read` answers, a throw included. */
65
+ export function attempt(read) {
66
+ return new Promise((resolve) => resolve(read()));
67
+ }
68
+ /** UTF-8 bytes of a string, without encoding it. */
69
+ export function utf8Length(text) {
70
+ let bytes = 0;
71
+ for (let i = 0; i < text.length; i += 1) {
72
+ const unit = text.charCodeAt(i);
73
+ if (unit < 0x80)
74
+ bytes += 1;
75
+ else if (unit < 0x800)
76
+ bytes += 2;
77
+ else if (unit >= 0xd800 && unit < 0xdc00 && i + 1 < text.length) {
78
+ bytes += 4;
79
+ i += 1;
80
+ }
81
+ else
82
+ bytes += 3;
83
+ }
84
+ return bytes;
85
+ }
86
+ /** The reply text a body holds: an inline reply whole, a stored one by the
87
+ * preview it carries. */
88
+ export function replyBytesOf(turn) {
89
+ let bytes = 0;
90
+ for (const part of turn.parts) {
91
+ if (part.kind !== "reply")
92
+ continue;
93
+ const body = part.row.body;
94
+ if (body.type !== "agent" || body.text === null)
95
+ continue;
96
+ bytes += utf8Length(body.text.type === "inline" ? body.text.text : body.text.preview);
97
+ }
98
+ return bytes;
99
+ }
100
+ const PREVIEW_MAX_BYTES = 160;
101
+ /** A turn's mark, made from its body, for a turn heard before an outline
102
+ * names it: as the daemon's outline makes it. */
103
+ export function markOfTurn(turn) {
104
+ let preview = null;
105
+ const prompt = turn.prompt?.body;
106
+ if (prompt?.type === "user" && prompt.text !== null) {
107
+ const text = prompt.text.type === "inline" ? prompt.text.text : prompt.text.preview;
108
+ let bytes = 0;
109
+ let out = "";
110
+ for (const char of text) {
111
+ bytes += utf8Length(char);
112
+ if (bytes > PREVIEW_MAX_BYTES)
113
+ break;
114
+ out += char;
115
+ }
116
+ preview = out === "" ? null : out;
117
+ }
118
+ let media = 0;
119
+ for (const part of turn.parts)
120
+ if (part.kind === "run")
121
+ media += part.run.media.length + part.run.media_omitted;
122
+ return {
123
+ key: turn.key, first_ordinal: turn.first_ordinal, last_ordinal: turn.last_ordinal, first_at: turn.first_at,
124
+ last_at: turn.last_at, preview, state: turn.outcome.state, media,
125
+ };
126
+ }
127
+ export function sameStructure(a, b) {
128
+ if (a.length !== b.length)
129
+ return false;
130
+ for (let i = 0; i < a.length; i += 1)
131
+ if (a[i].key !== b[i].key || a[i].first_at !== b[i].first_at)
132
+ return false;
133
+ return true;
134
+ }
135
+ export function latestOf(sessionId, turn) {
136
+ let replies = 0;
137
+ let lastReplyOrdinal = null;
138
+ for (const part of turn.parts) {
139
+ if (part.kind !== "reply")
140
+ continue;
141
+ replies += 1;
142
+ lastReplyOrdinal = part.row.ordinal;
143
+ }
144
+ return {
145
+ sessionId, turnKey: turn.key, firstAt: turn.first_at, replies, lastReplyOrdinal, outcome: turn.outcome,
146
+ running: turn.outcome.state === "open" || turn.running > 0,
147
+ };
148
+ }
149
+ export function sameLatest(a, b) {
150
+ if (a === null || b === null)
151
+ return a === b;
152
+ return (a.sessionId === b.sessionId && a.turnKey === b.turnKey && a.firstAt === b.firstAt && a.replies === b.replies &&
153
+ a.lastReplyOrdinal === b.lastReplyOrdinal && a.running === b.running && a.outcome.state === b.outcome.state &&
154
+ a.outcome.reason === b.outcome.reason && a.outcome.at === b.outcome.at);
155
+ }
@@ -0,0 +1,106 @@
1
+ import type { ConversationTurn, TurnMark } from "@vibefield/rosetta-protocol";
2
+ import type { SessionLeases } from "../lib/session-leases.js";
3
+ import type { ConversationLatest, ConversationSessionClient, ConversationUnavailable } from "./ports.js";
4
+ /** The feed's bounds and pace. */
5
+ export declare const CONVERSATION_FEED_LIMITS: Readonly<{
6
+ /** Turns per read, and per snapshot. */
7
+ page: 20;
8
+ /** Turns read on either side of the ones in view. */
9
+ around: 20;
10
+ bodies: 400;
11
+ replyBytes: number;
12
+ /** Sessions open at once: the newest and the two nearest the view. */
13
+ sessions: 3;
14
+ /** The chain's newest turns, never let go. */
15
+ newest: 20;
16
+ retryFirstMs: 1000;
17
+ retryMostMs: 30000;
18
+ }>;
19
+ /** A turn by its session and key. */
20
+ export interface ConversationTurnAt {
21
+ readonly sessionId: string;
22
+ readonly turnKey: string;
23
+ }
24
+ /** The turn rows the reader sees (or is about to): the first and the last.
25
+ * When only other rows are in view, the view gives the nearest turn rows
26
+ * (`viewportOfRows`); null only when the rows hold no turn at all, which reads
27
+ * as the top of what is held. */
28
+ export interface ConversationFeedViewport {
29
+ readonly first: ConversationTurnAt | null;
30
+ readonly last: ConversationTurnAt | null;
31
+ }
32
+ /** The view as a whole, by its root's `data-conv-state`. */
33
+ export type ConversationFeedPhase = "reading" | "ready" | "catching-up" | "unavailable";
34
+ /** How one session of the chain stands. `missing` answered not_found and
35
+ * `withheld` holds turns that are not public yet: both are asked again on the
36
+ * backoff, and keep what they held. */
37
+ export type ConversationFeedSessionStatus = "reading" | "ready" | "catching-up" | "missing" | "withheld" | "unavailable";
38
+ export interface ConversationFeedSession {
39
+ readonly sessionId: string;
40
+ /** The session's outline, oldest first; empty until it is read. The same
41
+ * array while no turn is added or removed and no turn's time moves, so rows
42
+ * made from it need not be made again when a turn's body changes. */
43
+ readonly turns: readonly TurnMark[];
44
+ /** The outline (or the first snapshot's turns) is held. */
45
+ readonly held: boolean;
46
+ readonly status: ConversationFeedSessionStatus;
47
+ readonly unavailable: ConversationUnavailable | null;
48
+ }
49
+ export interface ConversationFeedState {
50
+ readonly phase: ConversationFeedPhase;
51
+ /** Why the chain's last session cannot be read; null unless `unavailable`. */
52
+ readonly unavailable: ConversationUnavailable | null;
53
+ /** The sessions the rows are made from: the earliest the reader reached to
54
+ * the chain's last, oldest first. The same array until one of them changes
55
+ * its outline or its status, or the reader reaches another. */
56
+ readonly sessions: readonly ConversationFeedSession[];
57
+ /** The chain's newest turn, when its body is held. */
58
+ readonly latest: ConversationLatest | null;
59
+ /** Every session of the chain is reached and read: nothing lies above. */
60
+ readonly atTop: boolean;
61
+ /** Bumps on every change, a body's included. */
62
+ readonly version: number;
63
+ }
64
+ /** A clock a test can drive. */
65
+ export interface ConversationFeedTimers {
66
+ set(run: () => void, ms: number): unknown;
67
+ clear(handle: unknown): void;
68
+ }
69
+ export interface ConversationFeedOptions {
70
+ /** The view's one lease set over its session port. */
71
+ readonly sessions: SessionLeases<ConversationSessionClient>;
72
+ readonly timers?: ConversationFeedTimers;
73
+ }
74
+ export interface ConversationFeed {
75
+ state(): ConversationFeedState;
76
+ /** Called after every change. Answers the way to stop listening. */
77
+ subscribe(listener: () => void): () => void;
78
+ /** A held turn's body; the same object until the turn changes. */
79
+ body(sessionId: string, turnKey: string): ConversationTurn | null;
80
+ /** The chain to read, oldest first. The same ids again change nothing. */
81
+ setChain(chain: readonly string[]): void;
82
+ /** What the reader sees now: bodies around it are read, earlier sessions
83
+ * reached, the farthest let go. */
84
+ setViewport(viewport: ConversationFeedViewport): void;
85
+ /** The view holds this turn (a run is open in it): it is never let go until
86
+ * the answer is called. */
87
+ keep(sessionId: string, turnKey: string): () => void;
88
+ /** Reach a turn, by its key or by an ordinal inside it: its session's
89
+ * outline is read (and every session's between it and the newest), and
90
+ * the bodies around it after. Answers the turn, or null when it is not in
91
+ * the chain. */
92
+ locate(target: ConversationTurnAt | {
93
+ readonly sessionId: string;
94
+ readonly ordinal: number;
95
+ }): Promise<ConversationTurnAt | null>;
96
+ /** What is held now: for tests and the bench. */
97
+ held(): {
98
+ readonly bodies: number;
99
+ readonly replyBytes: number;
100
+ readonly open: readonly string[];
101
+ };
102
+ /** Let everything go: reads aborted, the subscription closed, every
103
+ * session closed. */
104
+ dispose(): void;
105
+ }
106
+ export declare function createConversationFeed(options: ConversationFeedOptions): ConversationFeed;