@vibefield/rosetta-room 0.1.11 → 0.1.13
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
|
@@ -1,9 +1,89 @@
|
|
|
1
|
-
import { activityRowKey } from "./activity-plan.js";
|
|
1
|
+
import { activityRowKey, activityRows } from "./activity-plan.js";
|
|
2
|
+
/** Every row a reading block draws, in order. */
|
|
3
|
+
export function readingBlockRows(block) {
|
|
4
|
+
switch (block.kind) {
|
|
5
|
+
case "prompt": return block.prompts.flatMap(prompt => prompt.rows);
|
|
6
|
+
case "reply": return [block.segment.row];
|
|
7
|
+
case "activity": return block.rows;
|
|
8
|
+
case "request": return activityRows(block.item);
|
|
9
|
+
case "gap":
|
|
10
|
+
case "watermark": return [];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** A derived value past this depth is never called equal: the document is
|
|
14
|
+
* plain data a few levels deep, and a cycle must not recurse forever. */
|
|
15
|
+
const MAX_DEPTH = 48;
|
|
16
|
+
/** Structural equality over the document's plain data: arrays, maps and sets
|
|
17
|
+
* in order, own keys of plain objects (whose prototype is `Object.prototype`
|
|
18
|
+
* or null), and identity for everything else: two dates, two patterns or two
|
|
19
|
+
* instances of a class are equal only when they are one object. A row that is
|
|
20
|
+
* the same object is equal without being read. */
|
|
21
|
+
export function sameValue(a, b, depth = 0) {
|
|
22
|
+
if (Object.is(a, b))
|
|
23
|
+
return true;
|
|
24
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null || depth > MAX_DEPTH)
|
|
25
|
+
return false;
|
|
26
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
27
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length)
|
|
28
|
+
return false;
|
|
29
|
+
for (let index = 0; index < a.length; index += 1)
|
|
30
|
+
if (!sameValue(a[index], b[index], depth + 1))
|
|
31
|
+
return false;
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (a instanceof Map || b instanceof Map) {
|
|
35
|
+
if (!(a instanceof Map) || !(b instanceof Map) || a.size !== b.size)
|
|
36
|
+
return false;
|
|
37
|
+
const right = b.entries();
|
|
38
|
+
for (const [key, value] of a) {
|
|
39
|
+
const next = right.next().value;
|
|
40
|
+
if (!Object.is(key, next[0]) || !sameValue(value, next[1], depth + 1))
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (a instanceof Set || b instanceof Set) {
|
|
46
|
+
if (!(a instanceof Set) || !(b instanceof Set) || a.size !== b.size)
|
|
47
|
+
return false;
|
|
48
|
+
const right = b.values();
|
|
49
|
+
for (const value of a)
|
|
50
|
+
if (!sameValue(value, right.next().value, depth + 1))
|
|
51
|
+
return false;
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
const prototype = Object.getPrototypeOf(a);
|
|
55
|
+
if (prototype !== Object.getPrototypeOf(b) || (prototype !== Object.prototype && prototype !== null))
|
|
56
|
+
return false;
|
|
57
|
+
const keys = Object.keys(a);
|
|
58
|
+
if (keys.length !== Object.keys(b).length)
|
|
59
|
+
return false;
|
|
60
|
+
for (const key of keys) {
|
|
61
|
+
if (!Object.prototype.hasOwnProperty.call(b, key))
|
|
62
|
+
return false;
|
|
63
|
+
if (!sameValue(a[key], b[key], depth + 1))
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
function sameRows(a, b) {
|
|
69
|
+
if (a.length !== b.length)
|
|
70
|
+
return false;
|
|
71
|
+
for (let index = 0; index < a.length; index += 1)
|
|
72
|
+
if (a[index] !== b[index])
|
|
73
|
+
return false;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
/** The same rows, as the same objects in the same order, and every other
|
|
77
|
+
* field equal: the block draws exactly what it drew. */
|
|
78
|
+
function sameBlock(previous, next) {
|
|
79
|
+
return previous.kind === next.kind && previous.key === next.key
|
|
80
|
+
&& sameRows(readingBlockRows(previous), readingBlockRows(next)) && sameValue(previous, next);
|
|
81
|
+
}
|
|
2
82
|
/** Prefer the largest surviving overlap, with one owner per old key. Inserting
|
|
3
83
|
* older rows must not remount an existing sitting, fold, or attachment rail.
|
|
4
84
|
* Real splits/merges keep the best surviving owner; row disclosure state is
|
|
5
85
|
* independently keyed by canonical identity. No historical rows are retained. */
|
|
6
|
-
function retainedKeys(previous, next) {
|
|
86
|
+
function retainedKeys(previous, next, taken = new Set()) {
|
|
7
87
|
const owner = new Map();
|
|
8
88
|
for (const group of previous)
|
|
9
89
|
for (const row of group.rows)
|
|
@@ -18,7 +98,7 @@ function retainedKeys(previous, next) {
|
|
|
18
98
|
return [...counts].map(([key, count]) => ({ index, key, count }));
|
|
19
99
|
}).sort((a, b) => b.count - a.count || a.index - b.index);
|
|
20
100
|
const assigned = new Map();
|
|
21
|
-
const used = new Set();
|
|
101
|
+
const used = new Set(taken);
|
|
22
102
|
for (const match of matches) {
|
|
23
103
|
if (assigned.has(match.index) || used.has(match.key))
|
|
24
104
|
continue;
|
|
@@ -36,17 +116,53 @@ function retainedKeys(previous, next) {
|
|
|
36
116
|
return key;
|
|
37
117
|
});
|
|
38
118
|
}
|
|
119
|
+
/** Keys survive as before; beyond that, a block whose rows did not change is
|
|
120
|
+
* handed back as the PREVIOUS object, and a sitting whose blocks all came back
|
|
121
|
+
* is the previous sitting. A memoised view of either then skips its render, so
|
|
122
|
+
* one arriving row costs the blocks it changed and not the document. */
|
|
39
123
|
export function retainReadingIdentity(previous, next) {
|
|
40
|
-
|
|
124
|
+
// The leading sittings the plan handed back as the objects it made last time
|
|
125
|
+
// keep what they were retained as: retaining a sitting again against its own
|
|
126
|
+
// result gives that result, so they are neither read nor compared, and one
|
|
127
|
+
// arriving row compares the sittings it changed (2026-11-29, the reader's
|
|
128
|
+
// arrival cost). Their keys stay taken for the sittings after them.
|
|
129
|
+
let kept = 0;
|
|
130
|
+
while (kept < next.length && kept < previous.length && retainedFrom.get(next[kept]) === previous[kept])
|
|
131
|
+
kept += 1;
|
|
132
|
+
const head = previous.slice(0, kept);
|
|
133
|
+
const result = [...head, ...retainSittings(previous.slice(kept), next.slice(kept), new Set(head.map(renderKeyOf)))];
|
|
134
|
+
next.forEach((entry, index) => retainedFrom.set(entry, result[index]));
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
/** What each sitting the plan made was retained as. */
|
|
138
|
+
const retainedFrom = new WeakMap();
|
|
139
|
+
const renderKeyOf = (entry) => entry.renderKey ?? entry.sitting.key;
|
|
140
|
+
function retainSittings(previous, next, taken) {
|
|
141
|
+
const previousByKey = new Map(previous.map(entry => [renderKeyOf(entry), entry]));
|
|
142
|
+
const sittingKeys = retainedKeys(previous.map(entry => ({ key: renderKeyOf(entry), rows: entry.sitting.rows })), next.map(entry => entry.sitting), taken);
|
|
41
143
|
return next.map(({ sitting, blocks }, index) => {
|
|
42
|
-
const
|
|
144
|
+
const renderKey = sittingKeys[index];
|
|
145
|
+
const old = previousByKey.get(renderKey);
|
|
43
146
|
const groups = blocks.filter(block => block.kind === "activity");
|
|
44
147
|
const keys = retainedKeys(old?.blocks.filter(block => block.kind === "activity") ?? [], groups);
|
|
148
|
+
const oldByKey = new Map((old?.blocks ?? []).map(block => [block.key, block]));
|
|
45
149
|
let groupIndex = 0;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
150
|
+
let unchanged = old !== undefined && old.renderKey === renderKey && old.blocks.length === blocks.length;
|
|
151
|
+
const kept = blocks.map((block, at) => {
|
|
152
|
+
let keyed = block;
|
|
153
|
+
if (block.kind === "activity") {
|
|
154
|
+
const key = keys[groupIndex++];
|
|
155
|
+
if (key !== block.key)
|
|
156
|
+
keyed = { ...block, key };
|
|
157
|
+
}
|
|
158
|
+
const prior = oldByKey.get(keyed.key);
|
|
159
|
+
const result = prior !== undefined && sameBlock(prior, keyed) ? prior : keyed;
|
|
160
|
+
if (unchanged && old.blocks[at] !== result)
|
|
161
|
+
unchanged = false;
|
|
162
|
+
return result;
|
|
163
|
+
});
|
|
164
|
+
if (unchanged && sameValue(old.sitting, sitting))
|
|
165
|
+
return old;
|
|
166
|
+
return { sitting, renderKey, blocks: kept };
|
|
51
167
|
});
|
|
52
168
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "../styles/room.css";
|
|
2
|
+
import type { AttachmentReader } from "../components/transcript/attachment-file-source.js";
|
|
3
|
+
import type { AttachmentFact } from "../lib/transcript/index.js";
|
|
4
|
+
export declare function ConversationGallery({ reader, fact, row, homeDir, onClose, onReceipt }: {
|
|
5
|
+
readonly reader: AttachmentReader;
|
|
6
|
+
readonly fact: AttachmentFact;
|
|
7
|
+
readonly row: readonly AttachmentFact[];
|
|
8
|
+
readonly homeDir: string | null;
|
|
9
|
+
readonly onClose: () => void;
|
|
10
|
+
readonly onReceipt: (message: string) => void;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// The room's gallery over the conversation view's pictures. Loaded only when
|
|
3
|
+
// a reader presses a picture and the host takes no press of its own: this
|
|
4
|
+
// module brings the file viewer's dialog and the room's sheet for it, which
|
|
5
|
+
// the view's own entry never imports.
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import "../styles/room.css";
|
|
8
|
+
import { ImageGalleryDialog } from "../components/file-viewer/ImageGalleryDialog.js";
|
|
9
|
+
import { attachmentGallery, createAttachmentGallerySource } from "../components/transcript/attachment-gallery.js";
|
|
10
|
+
export function ConversationGallery({ reader, fact, row, homeDir, onClose, onReceipt }) {
|
|
11
|
+
const source = useMemo(() => createAttachmentGallerySource(reader), [reader]);
|
|
12
|
+
const { images, initialKey } = attachmentGallery(reader, fact, row);
|
|
13
|
+
return (_jsx(ImageGalleryDialog, { images: images, initialKey: initialKey, source: source, tint: null, homeDirectory: homeDir, onClose: onClose, onReceipt: onReceipt, openInBrowser: null }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { AttachmentRef } from "@vibefield/rosetta-protocol";
|
|
3
|
+
import type { AttachmentFact } from "../lib/transcript/index.js";
|
|
4
|
+
import type { AttachmentReader } from "../components/transcript/attachment-file-source.js";
|
|
5
|
+
import type { ConversationMedia, ConversationViewWords } from "./ports.js";
|
|
6
|
+
/** One medium of a reply or a run, by the row that holds it. */
|
|
7
|
+
export interface ConversationMediaItem {
|
|
8
|
+
readonly timelineId: string;
|
|
9
|
+
readonly attachment: AttachmentRef;
|
|
10
|
+
}
|
|
11
|
+
/** The words the media draw themselves. */
|
|
12
|
+
export declare const CONVERSATION_MEDIA_WORDS: Readonly<{
|
|
13
|
+
failed: "Could not load image";
|
|
14
|
+
retry: "Retry";
|
|
15
|
+
play: "Play video";
|
|
16
|
+
}>;
|
|
17
|
+
/** The media's lines, each whole, as the view's `words` name them. */
|
|
18
|
+
export type MediaLines = Pick<ConversationViewWords, "mediaFailed" | "mediaRetry" | "mediaPlay">;
|
|
19
|
+
export declare const MEDIA_LINES: MediaLines;
|
|
20
|
+
/** The room's fact for one medium, keyed as the room keys a message's own. */
|
|
21
|
+
export declare function mediaFactOf(sessionId: string, item: ConversationMediaItem): AttachmentFact;
|
|
22
|
+
/** Opens the room's gallery on one picture among its row's. */
|
|
23
|
+
export type ConversationGalleryOpener = (reader: AttachmentReader, fact: AttachmentFact, row: readonly AttachmentFact[]) => void;
|
|
24
|
+
/** Where the room's gallery opens for the view's pictures; the view mounts
|
|
25
|
+
* one around its rows. */
|
|
26
|
+
export declare function ConversationGalleryHost({ children, homeDir, onReceipt }: {
|
|
27
|
+
readonly children: ReactNode;
|
|
28
|
+
readonly homeDir: string | null;
|
|
29
|
+
readonly onReceipt: (message: string) => void;
|
|
30
|
+
}): import("react").JSX.Element;
|
|
31
|
+
/** A length in seconds as a clock: `0:07`, `12:30`, `1:02:03`; null when the
|
|
32
|
+
* element could not say (a recording that names no duration). */
|
|
33
|
+
export declare function lengthText(seconds: number | null): string | null;
|
|
34
|
+
export interface ConversationMediaListProps {
|
|
35
|
+
readonly sessionId: string;
|
|
36
|
+
readonly items: readonly ConversationMediaItem[];
|
|
37
|
+
readonly onOpenMedia?: ((media: ConversationMedia) => void) | undefined;
|
|
38
|
+
/** The lines a picture or a video draws itself; rosetta's own when absent. */
|
|
39
|
+
readonly words?: MediaLines;
|
|
40
|
+
}
|
|
41
|
+
/** Always the room's rail, however many: a prompt's own pictures. */
|
|
42
|
+
export declare function ConversationMediaRail({ sessionId, items, onOpenMedia }: ConversationMediaListProps): import("react").JSX.Element | null;
|
|
43
|
+
/** Draws nothing for no media. */
|
|
44
|
+
export declare function ConversationMediaList({ sessionId, items, onOpenMedia, words }: ConversationMediaListProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A reply's or a run's pictures and videos, as the conversation view draws
|
|
3
|
+
// them:
|
|
4
|
+
//
|
|
5
|
+
// - one picture, as wide as the reply up to the host's `--tr-conv-media-max`,
|
|
6
|
+
// drawn from its preview rendition;
|
|
7
|
+
// - two or more, or pictures with videos, as the room's own rail;
|
|
8
|
+
// - one video with its first frame, its length and its size, played in place
|
|
9
|
+
// with the element's own controls, when the host's address honours byte
|
|
10
|
+
// ranges and may be asked before play (`AssetSource.mediaFirstFrame`).
|
|
11
|
+
// Otherwise, or when that address fails, the room's tile, which asks for
|
|
12
|
+
// nothing until the reader presses play.
|
|
13
|
+
//
|
|
14
|
+
// A press on a picture is the host's (`onOpenMedia`). With none, the room's
|
|
15
|
+
// gallery opens, and its code (the file viewer's dialog and its sheet) is
|
|
16
|
+
// loaded only then: it is never in the view's static import graph.
|
|
17
|
+
import { createContext, lazy, Suspense, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
18
|
+
import { fmtBytes } from "../lib/format.js";
|
|
19
|
+
import { readAttachments } from "../lib/transcript/index.js";
|
|
20
|
+
import { useParts } from "../parts-context.js";
|
|
21
|
+
import { useImageUrl } from "../components/file-viewer/image-resource.js";
|
|
22
|
+
import { Attachments } from "../components/transcript/Attachments.js";
|
|
23
|
+
import { useAttachmentReader } from "../components/transcript/attachment-file-source.js";
|
|
24
|
+
import { VideoFace, videoAspect } from "../components/transcript/VideoTile.js";
|
|
25
|
+
import { IDLE_VIDEO, createVideoSource } from "../components/transcript/video-source.js";
|
|
26
|
+
/** The words the media draw themselves. */
|
|
27
|
+
export const CONVERSATION_MEDIA_WORDS = Object.freeze({
|
|
28
|
+
failed: "Could not load image",
|
|
29
|
+
retry: "Retry",
|
|
30
|
+
play: "Play video",
|
|
31
|
+
});
|
|
32
|
+
export const MEDIA_LINES = Object.freeze({
|
|
33
|
+
mediaFailed: CONVERSATION_MEDIA_WORDS.failed,
|
|
34
|
+
mediaRetry: CONVERSATION_MEDIA_WORDS.retry,
|
|
35
|
+
mediaPlay: CONVERSATION_MEDIA_WORDS.play,
|
|
36
|
+
});
|
|
37
|
+
/** The room's fact for one medium, keyed as the room keys a message's own. */
|
|
38
|
+
export function mediaFactOf(sessionId, item) {
|
|
39
|
+
const [fact] = readAttachments(null, [item.attachment]).attachments;
|
|
40
|
+
return { ...fact, key: `${sessionId}:${item.timelineId}:attachment:${fact.key}` };
|
|
41
|
+
}
|
|
42
|
+
const GalleryContext = createContext(null);
|
|
43
|
+
const LazyGallery = lazy(() => import("./ConversationGallery.js").then((module) => ({ default: module.ConversationGallery })));
|
|
44
|
+
/** Where the room's gallery opens for the view's pictures; the view mounts
|
|
45
|
+
* one around its rows. */
|
|
46
|
+
export function ConversationGalleryHost({ children, homeDir, onReceipt }) {
|
|
47
|
+
const [shown, setShown] = useState(null);
|
|
48
|
+
const open = useCallback((reader, fact, row) => setShown({ reader, fact, row }), []);
|
|
49
|
+
return (_jsxs(GalleryContext.Provider, { value: open, children: [children, shown !== null && (_jsx(Suspense, { fallback: null, children: _jsx(LazyGallery, { ...shown, homeDir: homeDir, onReceipt: onReceipt, onClose: () => setShown(null) }) }))] }));
|
|
50
|
+
}
|
|
51
|
+
/* ── one picture ─────────────────────────────────────────────────────────── */
|
|
52
|
+
function OnePicture({ fact, onOpen, words }) {
|
|
53
|
+
const reader = useAttachmentReader();
|
|
54
|
+
const resource = reader.imageResource(fact);
|
|
55
|
+
const [attempt, setAttempt] = useState(0);
|
|
56
|
+
const [failedUrl, setFailedUrl] = useState(null);
|
|
57
|
+
const { url, pending } = useImageUrl(resource, "preview", attempt);
|
|
58
|
+
const label = fact.ref?.label ?? "Image";
|
|
59
|
+
const failed = !pending && (url === null || failedUrl === url);
|
|
60
|
+
const style = fact.width !== null && fact.height !== null && fact.width > 0 && fact.height > 0
|
|
61
|
+
? { "--tr-conv-media-aspect": `${fact.width} / ${fact.height}` }
|
|
62
|
+
: undefined;
|
|
63
|
+
return (_jsx("figure", { className: "tr-conv-media", "data-count": "1", "data-attachment-id": fact.key, style: style, children: failed ? (_jsxs("div", { className: "tr-conv-media__missing", role: "status", children: [_jsx("span", { children: words.mediaFailed }), _jsx("button", { type: "button", onClick: () => { setFailedUrl(null); setAttempt((value) => value + 1); }, children: words.mediaRetry })] })) : (_jsx("button", { type: "button", className: "tr-conv-media__open", "aria-haspopup": "dialog", "aria-busy": pending, "aria-label": `Open ${label}${fact.name ? `, ${fact.name}` : ""}`, onClick: () => onOpen(fact), children: url !== null && _jsx("img", { src: url, alt: fact.name ?? label, decoding: "async", onError: () => setFailedUrl(url) }, url) })) }));
|
|
64
|
+
}
|
|
65
|
+
/* ── one video ───────────────────────────────────────────────────────────── */
|
|
66
|
+
/** A length in seconds as a clock: `0:07`, `12:30`, `1:02:03`; null when the
|
|
67
|
+
* element could not say (a recording that names no duration). */
|
|
68
|
+
export function lengthText(seconds) {
|
|
69
|
+
if (seconds === null || !Number.isFinite(seconds) || seconds <= 0)
|
|
70
|
+
return null;
|
|
71
|
+
const whole = Math.max(1, Math.round(seconds));
|
|
72
|
+
const h = Math.floor(whole / 3600);
|
|
73
|
+
const m = Math.floor((whole % 3600) / 60);
|
|
74
|
+
const s = String(whole % 60).padStart(2, "0");
|
|
75
|
+
return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${s}` : `${m}:${s}`;
|
|
76
|
+
}
|
|
77
|
+
function PlayGlyph() {
|
|
78
|
+
return (_jsxs("svg", { width: "32", height: "32", viewBox: "0 0 28 28", fill: "none", "aria-hidden": "true", children: [_jsx("circle", { cx: "14", cy: "14", r: "12.5", stroke: "currentColor", strokeWidth: "1.3" }), _jsx("path", { d: "M11.5 9.2v9.6l8-4.8z", fill: "currentColor" })] }));
|
|
79
|
+
}
|
|
80
|
+
/** The host's address, asked at mount: a first frame, a length and a size
|
|
81
|
+
* before play, and the same element plays in place. */
|
|
82
|
+
function FirstFrame({ fact, asset, reader, onFallback, words }) {
|
|
83
|
+
const [url, setUrl] = useState(null);
|
|
84
|
+
const [phase, setPhase] = useState("idle");
|
|
85
|
+
const [length, setLength] = useState(null);
|
|
86
|
+
const element = useRef(null);
|
|
87
|
+
const fallback = useRef(onFallback);
|
|
88
|
+
fallback.current = onFallback;
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
let live = true;
|
|
91
|
+
let answer = null;
|
|
92
|
+
try {
|
|
93
|
+
answer = reader.mediaAssetUrl?.(asset) ?? null;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
answer = null;
|
|
97
|
+
}
|
|
98
|
+
Promise.resolve(answer).then((address) => {
|
|
99
|
+
if (!live)
|
|
100
|
+
return;
|
|
101
|
+
if (typeof address === "string" && address !== "")
|
|
102
|
+
setUrl(address);
|
|
103
|
+
else
|
|
104
|
+
fallback.current();
|
|
105
|
+
}, () => {
|
|
106
|
+
if (live)
|
|
107
|
+
fallback.current();
|
|
108
|
+
});
|
|
109
|
+
return () => {
|
|
110
|
+
live = false;
|
|
111
|
+
};
|
|
112
|
+
}, [asset.digest, reader]);
|
|
113
|
+
const name = fact.name?.trim() || fact.ref?.label || "Video";
|
|
114
|
+
const facts = [name, lengthText(length), fact.byteLen === null ? null : fmtBytes(fact.byteLen)].filter(Boolean).join(" · ");
|
|
115
|
+
const style = { "--tr-video-aspect": videoAspect(fact.width, fact.height).toFixed(4) };
|
|
116
|
+
const play = () => {
|
|
117
|
+
const video = element.current;
|
|
118
|
+
if (video === null)
|
|
119
|
+
return;
|
|
120
|
+
setPhase("ready");
|
|
121
|
+
video.play().catch(() => fallback.current());
|
|
122
|
+
};
|
|
123
|
+
return (_jsxs("figure", { className: "tr-conv-video", "data-video": phase, "data-attachment-id": fact.key, style: style, children: [_jsxs("div", { className: "tr-conv-video__stage", children: [url !== null && (_jsx("video", { ref: element, src: `${url}#t=0.001`, preload: "metadata", playsInline: true, controls: phase === "ready", "aria-label": name, onLoadedMetadata: (event) => setLength(event.currentTarget.duration), onLoadedData: () => setPhase((now) => (now === "idle" ? "frame" : now)), onError: () => fallback.current() })), phase !== "ready" && (_jsx("button", { type: "button", className: "tr-conv-video__play", "aria-label": `${words.mediaPlay}, ${facts}`, "aria-busy": phase === "idle", onClick: play, children: _jsx(PlayGlyph, {}) }))] }), _jsx("figcaption", { className: "tr-conv-video__facts", children: facts })] }));
|
|
124
|
+
}
|
|
125
|
+
/** The room's tile over its own load: nothing is asked until play. */
|
|
126
|
+
function Tile({ fact, asset, reader }) {
|
|
127
|
+
const [state, setState] = useState(IDLE_VIDEO);
|
|
128
|
+
const source = useRef(null);
|
|
129
|
+
const target = useRef(null);
|
|
130
|
+
const restoreFocus = useRef(false);
|
|
131
|
+
useEffect(() => () => {
|
|
132
|
+
source.current?.dispose();
|
|
133
|
+
source.current = null;
|
|
134
|
+
setState(IDLE_VIDEO);
|
|
135
|
+
}, [asset?.digest, reader]);
|
|
136
|
+
useLayoutEffect(() => {
|
|
137
|
+
if (!restoreFocus.current)
|
|
138
|
+
return;
|
|
139
|
+
restoreFocus.current = false;
|
|
140
|
+
target.current?.focus({ preventScroll: true });
|
|
141
|
+
}, [state]);
|
|
142
|
+
const play = () => {
|
|
143
|
+
if (asset === null)
|
|
144
|
+
return;
|
|
145
|
+
restoreFocus.current = true;
|
|
146
|
+
source.current ??= createVideoSource(asset, {
|
|
147
|
+
mediaAssetUrl: reader.mediaAssetUrl,
|
|
148
|
+
readAsset: reader.readAsset,
|
|
149
|
+
createObjectURL: (bytes, mediaType) => URL.createObjectURL(new Blob([bytes], { type: mediaType })),
|
|
150
|
+
revokeObjectURL: (url) => URL.revokeObjectURL(url),
|
|
151
|
+
onChange: setState,
|
|
152
|
+
});
|
|
153
|
+
source.current.play();
|
|
154
|
+
};
|
|
155
|
+
const playable = asset !== null;
|
|
156
|
+
const phase = !playable ? "uncaptured" : state.phase === "loading" ? "idle" : state.phase;
|
|
157
|
+
return (_jsx("figure", { className: "tr-conv-video", "data-video": phase, "data-attachment-id": fact.key, children: _jsx(VideoFace, { fact: fact, index: 0, playable: playable, state: state, onPlay: play, onElementError: (url) => source.current?.elementFailed(url), focusRef: (element) => { target.current = element; } }) }));
|
|
158
|
+
}
|
|
159
|
+
function OneVideo({ fact, words }) {
|
|
160
|
+
const reader = useAttachmentReader();
|
|
161
|
+
const { assets } = useParts();
|
|
162
|
+
const asset = reader.videoAsset(fact);
|
|
163
|
+
const early = asset !== null && assets.mediaFirstFrame === true && reader.mediaAssetUrl !== undefined;
|
|
164
|
+
// A first frame needs the host's address; one that fails, or a host that
|
|
165
|
+
// answers none, is the tile from then on.
|
|
166
|
+
const [tile, setTile] = useState(false);
|
|
167
|
+
if (!early || tile || asset === null)
|
|
168
|
+
return _jsx(Tile, { fact: fact, asset: asset, reader: reader });
|
|
169
|
+
return _jsx(FirstFrame, { fact: fact, asset: asset, reader: reader, onFallback: () => setTile(true), words: words });
|
|
170
|
+
}
|
|
171
|
+
/** A press on one of `items`' pictures: the host's, else the room's gallery. */
|
|
172
|
+
function useMediaOpener(sessionId, items, facts, onOpenMedia) {
|
|
173
|
+
const reader = useAttachmentReader();
|
|
174
|
+
const gallery = useContext(GalleryContext);
|
|
175
|
+
return {
|
|
176
|
+
reader,
|
|
177
|
+
open(fact, row = facts) {
|
|
178
|
+
const item = items[facts.findIndex((each) => each.key === fact.key)];
|
|
179
|
+
if (onOpenMedia !== undefined) {
|
|
180
|
+
if (item !== undefined)
|
|
181
|
+
onOpenMedia({ sessionId, timelineId: item.timelineId, attachment: item.attachment });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (fact.kind === "image" && reader.canOpen(fact))
|
|
185
|
+
gallery?.(reader, fact, row);
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** Always the room's rail, however many: a prompt's own pictures. */
|
|
190
|
+
export function ConversationMediaRail({ sessionId, items, onOpenMedia }) {
|
|
191
|
+
const facts = items.map((item) => mediaFactOf(sessionId, item));
|
|
192
|
+
const { open } = useMediaOpener(sessionId, items, facts, onOpenMedia);
|
|
193
|
+
return facts.length === 0 ? null : _jsx(Attachments, { facts: facts, onOpenAttachment: open });
|
|
194
|
+
}
|
|
195
|
+
/** Draws nothing for no media. */
|
|
196
|
+
export function ConversationMediaList({ sessionId, items, onOpenMedia, words = MEDIA_LINES }) {
|
|
197
|
+
const facts = items.map((item) => mediaFactOf(sessionId, item));
|
|
198
|
+
const { reader, open } = useMediaOpener(sessionId, items, facts, onOpenMedia);
|
|
199
|
+
if (items.length === 0)
|
|
200
|
+
return null;
|
|
201
|
+
const [only] = facts;
|
|
202
|
+
if (facts.length === 1 && only !== undefined) {
|
|
203
|
+
if (only.kind === "image" && reader.imageResource(only) !== null) {
|
|
204
|
+
return _jsx(OnePicture, { fact: only, onOpen: (fact) => open(fact), words: words });
|
|
205
|
+
}
|
|
206
|
+
if (only.kind === "video")
|
|
207
|
+
return _jsx(OneVideo, { fact: only, words: words });
|
|
208
|
+
}
|
|
209
|
+
return (_jsx("figure", { className: "tr-conv-media", "data-count": facts.length, children: _jsx(Attachments, { facts: facts, onOpenAttachment: open }) }));
|
|
210
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
/** What a reply's words take. */
|
|
3
|
+
export interface ConversationProseProps {
|
|
4
|
+
/** The reply's words, as markdown. */
|
|
5
|
+
readonly text: string;
|
|
6
|
+
/** What a link draws: `"open"` (the default, as the view's) a link the host
|
|
7
|
+
* opens, `"inert"` its words alone. A host passes the view's own `links`. */
|
|
8
|
+
readonly links?: "open" | "inert";
|
|
9
|
+
/** Told how a code bar's copy went ("Copied", or why not). Absent, nothing
|
|
10
|
+
* is said. */
|
|
11
|
+
readonly onReceipt?: (message: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function ConversationProse({ text, links, onReceipt }: ConversationProseProps): ReactElement;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Prose } from "../components/transcript/Prose.js";
|
|
3
|
+
const SAY_NOTHING = () => { };
|
|
4
|
+
export function ConversationProse({ text, links = "open", onReceipt = SAY_NOTHING }) {
|
|
5
|
+
return (_jsx("div", { className: "tr-prose ah-syntax tr-conv__prose", children: _jsx(Prose, { text: text, onReceipt: onReceipt, links: links }) }));
|
|
6
|
+
}
|
|
@@ -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
|
+
}
|