zidane-ui 9.2.2 → 9.2.3
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/dist/adapters/browser-keybindings-host.js +3 -1
- package/dist/adapters/server-settings-host.js +30 -3
- package/dist/adapters/server-settings-sections.js +23 -1
- package/dist/adapters/server-sidebar-host.d.ts +3 -1
- package/dist/adapters/server-sidebar-host.js +10 -1
- package/dist/app/ModalProvider.js +1 -1
- package/dist/approvals/ApprovalShell.js +1 -1
- package/dist/chat/DaemonOrb.d.ts +29 -1
- package/dist/chat/DaemonOrb.js +25 -12
- package/dist/chat/StatusDot.js +8 -2
- package/dist/chat/Transcript.js +11 -4
- package/dist/chat/headless/index.d.ts +3 -2
- package/dist/chat/headless/index.js +11 -10
- package/dist/chat/headless/labels.d.ts +13 -0
- package/dist/chat/headless/labels.js +12 -0
- package/dist/chat/headless/session-list.d.ts +10 -0
- package/dist/chat/headless/sidebar/directory.d.ts +8 -1
- package/dist/chat/headless/sidebar/directory.js +40 -4
- package/dist/chat/headless/sidebar/environment.d.ts +5 -2
- package/dist/chat/headless/sidebar/environment.js +11 -2
- package/dist/chat/headless/sidebar/host.d.ts +15 -0
- package/dist/chat/headless/sidebar/inbox.d.ts +12 -3
- package/dist/chat/headless/sidebar/inbox.js +18 -9
- package/dist/chat/headless/sidebar/index.d.ts +2 -2
- package/dist/chat/headless/sidebar/index.js +2 -2
- package/dist/chat/headless/sidebar/labels.d.ts +28 -2
- package/dist/chat/headless/sidebar/labels.js +16 -0
- package/dist/chat/headless/transcript/fold-actions.d.ts +8 -3
- package/dist/chat/headless/transcript/fold-actions.js +16 -0
- package/dist/chat/headless/transcript/fold.d.ts +2 -1
- package/dist/chat/headless/transcript/fold.js +22 -2
- package/dist/chat/headless/transcript/index.d.ts +2 -1
- package/dist/chat/headless/transcript/index.js +2 -1
- package/dist/chat/headless/transcript/rail.d.ts +93 -0
- package/dist/chat/headless/transcript/rail.js +148 -0
- package/dist/chat/headless/transcript/rows.d.ts +6 -0
- package/dist/chat/headless/transcript/run-failures.d.ts +4 -0
- package/dist/chat/headless/transcript/run-failures.js +29 -1
- package/dist/chat/headless/transcript-labels.d.ts +1 -0
- package/dist/chat/headless/turn-labels.d.ts +1 -0
- package/dist/chat/headless/turn-labels.js +2 -1
- package/dist/chat/index.d.ts +4 -3
- package/dist/chat/index.js +14 -13
- package/dist/chat/interactions/ElicitationCard.js +1 -1
- package/dist/chat/interactions/InteractionCard.js +1 -1
- package/dist/chat/interactions/PlanCard.js +3 -3
- package/dist/chat/interactions/QuestionField.js +4 -4
- package/dist/chat/interactions/QuestionForm.js +3 -3
- package/dist/chat/interactions/SecretInput.js +1 -1
- package/dist/chat/sidebar/ProjectIcon.d.ts +1 -1
- package/dist/chat/sidebar/ProjectIcon.js +1 -1
- package/dist/chat/sidebar/RowChips.d.ts +3 -2
- package/dist/chat/sidebar/RowChips.js +6 -3
- package/dist/chat/sidebar/SessionSidebar.js +13 -14
- package/dist/chat/sidebar/SidebarFrame.d.ts +2 -0
- package/dist/chat/sidebar/SidebarFrame.js +5 -2
- package/dist/chat/sidebar/SidebarSessionRow.d.ts +3 -1
- package/dist/chat/sidebar/SidebarSessionRow.js +3 -1
- package/dist/chat/sidebar/SpacesSection.d.ts +20 -1
- package/dist/chat/sidebar/SpacesSection.js +34 -13
- package/dist/chat/sidebar/index.d.ts +2 -2
- package/dist/chat/sidebar/session-menu.d.ts +11 -2
- package/dist/chat/sidebar/session-menu.js +50 -5
- package/dist/chat/sidebar/sidebar-live.js +1 -1
- package/dist/chat/sidebar/useInboxRows.js +43 -2
- package/dist/chat/sidebar/useInboxTriage.js +19 -14
- package/dist/chat/testing/fixture-sidebar-host.d.ts +7 -1
- package/dist/chat/testing/fixture-sidebar-host.js +12 -0
- package/dist/chat/testing/sidebar.contract.d.ts +6 -0
- package/dist/chat/testing/sidebar.contract.js +24 -0
- package/dist/chat/transcript/InteractionToolBody.js +1 -1
- package/dist/chat/transcript/SelectCursor.d.ts +11 -1
- package/dist/chat/transcript/SelectCursor.js +10 -5
- package/dist/chat/transcript/TranscriptRail.d.ts +86 -0
- package/dist/chat/transcript/TranscriptRail.js +421 -0
- package/dist/chat/transcript/TranscriptRow.js +5 -2
- package/dist/chat/transcript/actions.d.ts +6 -2
- package/dist/chat/transcript/fold.js +19 -1
- package/dist/chat/transcript/index.d.ts +3 -2
- package/dist/chat/transcript/index.js +3 -2
- package/dist/chat/transcript/notices.d.ts +23 -1
- package/dist/chat/transcript/notices.js +108 -27
- package/dist/chat/transcript/prose.js +1 -0
- package/dist/chat/transcript/receipt-parts.d.ts +22 -0
- package/dist/chat/transcript/receipt-parts.js +87 -0
- package/dist/chat/transcript/run-rows.js +3 -76
- package/dist/chat/transcript/script-input.d.ts +1 -1
- package/dist/chat/transcript/scroll-clamp.js +1 -1
- package/dist/chat/transcript/useSettledReveal.js +15 -3
- package/dist/chat/transcript/useStickToBottom.js +2 -1
- package/dist/components/ChoiceCards.js +1 -1
- package/dist/components/ConfirmDialog.js +1 -1
- package/dist/components/CopyValue.d.ts +33 -0
- package/dist/components/CopyValue.js +54 -0
- package/dist/components/Form.js +1 -1
- package/dist/components/HowItWorks.js +1 -1
- package/dist/components/Menu.js +1 -1
- package/dist/components/StepFrame.js +2 -2
- package/dist/components/SwatchPicker.js +1 -1
- package/dist/components/ToggleCard.js +1 -1
- package/dist/components/floating/HoverCard.js +2 -3
- package/dist/components/floating/hover-delay.d.ts +4 -0
- package/dist/components/floating/hover-delay.js +6 -0
- package/dist/core.css +14 -12
- package/dist/dist/index-De9AbmxS.d.ts +1 -0
- package/dist/dist/{index-Betz0OWq.d.ts → index-E1Z0aPmi.d.ts} +20 -2
- package/dist/dist/index.d.ts +5 -5
- package/dist/dist/sandbox-CSUihARm.d.ts +2 -0
- package/dist/dist/{timeout-CyU7HLyz.d.ts → timeout-CmTx6V9y.d.ts} +1 -0
- package/dist/extensions/ExtensionDialogHost.js +1 -1
- package/dist/files/TreeColumn.js +3 -1
- package/dist/files/headless/host.d.ts +2 -2
- package/dist/git/ImportRepoDialog.js +1 -1
- package/dist/git/MoveSessionDialog.js +2 -2
- package/dist/git/SandboxManager.d.ts +42 -0
- package/dist/git/SandboxManager.js +297 -0
- package/dist/git/SyncChip.js +1 -1
- package/dist/git/headless/index.d.ts +2 -1
- package/dist/git/headless/index.js +2 -1
- package/dist/git/headless/labels.d.ts +29 -0
- package/dist/git/headless/labels.js +34 -1
- package/dist/git/headless/sandboxes.d.ts +43 -0
- package/dist/git/headless/sandboxes.js +52 -0
- package/dist/git/index.d.ts +2 -1
- package/dist/git/index.js +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/keybindings/headless/catalog.d.ts +1 -1
- package/dist/keybindings/headless/catalog.js +12 -0
- package/dist/machines/HostsSection.d.ts +1 -1
- package/dist/machines/headless/labels.js +2 -2
- package/dist/motion/flip-list.js +3 -10
- package/dist/motion/presence.d.ts +10 -0
- package/dist/motion/presence.js +20 -1
- package/dist/motion/swap.d.ts +8 -2
- package/dist/motion/swap.js +5 -2
- package/dist/onboarding/conversation.js +27 -15
- package/dist/onboarding/demos/how-it-works.js +1 -1
- package/dist/onboarding/skills/parts.js +4 -4
- package/dist/onboarding/sources/SourceBrowser.js +1 -1
- package/dist/onboarding/steps/ReadyStep.js +1 -1
- package/dist/onboarding/steps/connect/KeyForm.js +1 -1
- package/dist/palette/headless/app-sources.js +20 -0
- package/dist/palette/headless/labels.js +2 -0
- package/dist/session/PlanTracker.js +3 -3
- package/dist/session/SecretsPanel.js +1 -1
- package/dist/session/SessionHeader.d.ts +18 -6
- package/dist/session/SessionHeader.js +67 -12
- package/dist/session/SessionPlaceMenu.d.ts +35 -0
- package/dist/session/SessionPlaceMenu.js +299 -0
- package/dist/session/SessionShell.js +1 -1
- package/dist/session/TurnDetailsDialog.js +1 -1
- package/dist/session/headless/index.d.ts +2 -1
- package/dist/session/headless/index.js +2 -1
- package/dist/session/headless/labels.d.ts +73 -0
- package/dist/session/headless/labels.js +73 -0
- package/dist/session/headless/place.d.ts +49 -0
- package/dist/session/headless/place.js +57 -0
- package/dist/session/index.d.ts +2 -1
- package/dist/session/index.js +2 -1
- package/dist/settings/ConversationPresetsCard.js +1 -1
- package/dist/settings/SettingCard.js +2 -2
- package/dist/settings/SettingsRowsPage.js +1 -1
- package/dist/settings/headless/fixture-sections.js +7 -0
- package/dist/settings/headless/labels.d.ts +1 -1
- package/dist/settings/headless/labels.js +1 -1
- package/dist/settings/headless/layout.d.ts +4 -4
- package/dist/settings/headless/layout.js +1 -1
- package/dist/settings/headless/search.d.ts +2 -2
- package/dist/settings/headless/sections-host.d.ts +20 -2
- package/dist/settings/sections/claude-import/ClaudeImportDialog.js +1 -1
- package/dist/settings/sections/enabled-list/EnabledListSection.js +2 -2
- package/dist/settings/sections/environments/EnvironmentsSection.d.ts +9 -3
- package/dist/settings/sections/environments/EnvironmentsSection.js +292 -52
- package/dist/settings/sections/environments/labels.d.ts +15 -0
- package/dist/settings/sections/environments/labels.js +18 -3
- package/dist/settings/sections/extensions/ChangeOriginDialog.js +1 -1
- package/dist/settings/sections/extensions/ExtensionSourceBrowser.js +1 -1
- package/dist/settings/sections/extensions/ExtensionsSection.d.ts +3 -2
- package/dist/settings/sections/extensions/ExtensionsSection.js +9 -3
- package/dist/settings/sections/host-catalog/HostCatalogSection.js +15 -5
- package/dist/settings/sections/keybindings/labels.d.ts +2 -0
- package/dist/settings/sections/keybindings/labels.js +2 -0
- package/dist/settings/sections/keybindings/rows.js +8 -0
- package/dist/settings/sections/models/SpacesDefaultsSection.d.ts +7 -3
- package/dist/settings/sections/models/SpacesDefaultsSection.js +11 -5
- package/dist/settings/sections/skills/SkillGroups.js +1 -1
- package/dist/settings/server-app.d.ts +4 -2
- package/dist/settings/server-app.js +7 -3
- package/dist/settings/testing/sections.contract.d.ts +7 -1
- package/dist/settings/testing/sections.contract.js +37 -0
- package/dist/styles.css +212 -19
- package/dist/terminal/TerminalDrawer.js +3 -1
- package/dist/workspace/SidePanel.js +3 -1
- package/package.json +2 -2
- package/src/styles/base.css +13 -0
- package/src/styles/chat.css +30 -0
- package/src/styles/components.css +0 -10
- package/src/styles/files.css +5 -0
- package/src/styles/sidebar.css +29 -7
- package/src/styles/terminal.css +6 -0
- package/src/styles/tokens.css +5 -0
- package/src/styles/transcript.css +107 -0
- package/src/styles/workspace.css +6 -0
- package/dist/dist/index-QcFzZlao.d.ts +0 -1
- package/dist/dist/sandbox-D0zsW8I1.d.ts +0 -2
- /package/dist/dist/{types-_Dtoq_No.d.ts → execution-failure-SREfl-EZ.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An in-memory `SidebarHost` for docs, demos and tests: each session's
|
|
3
3
|
* environment commands and what running one answers, with every reveal,
|
|
4
|
-
* window, retry, run and opened host settings recorded for the caller to read.
|
|
4
|
+
* window, retry, wake, run and opened host settings recorded for the caller to read.
|
|
5
5
|
*/
|
|
6
6
|
import { SessionWindowMode, SidebarHost } from "../headless/sidebar/host.js";
|
|
7
7
|
import { EnvironmentActionResult, EnvironmentActionSummary } from "zidane/chat";
|
|
@@ -34,6 +34,12 @@ export interface FixtureSidebarCalls {
|
|
|
34
34
|
}[];
|
|
35
35
|
/** Every environment retried, in order. */
|
|
36
36
|
retried: string[];
|
|
37
|
+
/** Every paused environment woken, in order. */
|
|
38
|
+
woken: string[];
|
|
39
|
+
/** Every environment paused, in order. */
|
|
40
|
+
paused: string[];
|
|
41
|
+
/** Every sandbox deleted, in order. */
|
|
42
|
+
removed: string[];
|
|
37
43
|
/** Every environment command run, in order. */
|
|
38
44
|
ran: {
|
|
39
45
|
sessionId: string;
|
|
@@ -10,6 +10,9 @@ function createFixtureSidebarHost(options = {}) {
|
|
|
10
10
|
revealed: [],
|
|
11
11
|
windows: [],
|
|
12
12
|
retried: [],
|
|
13
|
+
woken: [],
|
|
14
|
+
paused: [],
|
|
15
|
+
removed: [],
|
|
13
16
|
ran: [],
|
|
14
17
|
hostSettings: []
|
|
15
18
|
};
|
|
@@ -41,6 +44,15 @@ function createFixtureSidebarHost(options = {}) {
|
|
|
41
44
|
},
|
|
42
45
|
retry: async (sessionId) => {
|
|
43
46
|
calls.retried.push(sessionId);
|
|
47
|
+
},
|
|
48
|
+
wake: async (sessionId) => {
|
|
49
|
+
calls.woken.push(sessionId);
|
|
50
|
+
},
|
|
51
|
+
pause: async (sessionId) => {
|
|
52
|
+
calls.paused.push(sessionId);
|
|
53
|
+
},
|
|
54
|
+
remove: async (sessionId) => {
|
|
55
|
+
calls.removed.push(sessionId);
|
|
44
56
|
}
|
|
45
57
|
} } : {}
|
|
46
58
|
};
|
|
@@ -37,6 +37,12 @@ export interface SidebarHostContractControl {
|
|
|
37
37
|
}[];
|
|
38
38
|
/** The environments set up again, in order. Only read with `environment`. */
|
|
39
39
|
retried?: () => readonly string[];
|
|
40
|
+
/** The paused environments woken, in order. Given exactly when the host's `environment` offers `wake`. */
|
|
41
|
+
woken?: () => readonly string[];
|
|
42
|
+
/** The environments paused, in order. Given exactly when the host's `environment` offers `pause`. */
|
|
43
|
+
paused?: () => readonly string[];
|
|
44
|
+
/** The sandboxes deleted, in order. Given exactly when the host's `environment` offers `remove`. */
|
|
45
|
+
removed?: () => readonly string[];
|
|
40
46
|
/** The hosts whose settings were opened, in order. Only read with `openHostSettings`. */
|
|
41
47
|
hostSettingsOpened?: () => readonly string[];
|
|
42
48
|
/** The backend records or changes an artifact of `sessionId`. Only called with `badges`. */
|
|
@@ -105,6 +105,30 @@ function describeSidebarHostContract(name, makeHarness, capabilities) {
|
|
|
105
105
|
await expect(host.environment.retry("s1")).resolves.toBeUndefined();
|
|
106
106
|
expect(control.retried?.()).toEqual(["s1"]);
|
|
107
107
|
});
|
|
108
|
+
it.skipIf(!has("environment"))("wakes a paused environment when it offers that", async () => {
|
|
109
|
+
const { host, control } = await setup();
|
|
110
|
+
const wake = host.environment.wake;
|
|
111
|
+
expect(wake === void 0).toBe(control.woken === void 0);
|
|
112
|
+
if (!wake) return;
|
|
113
|
+
await expect(wake("s1")).resolves.toBeUndefined();
|
|
114
|
+
expect(control.woken?.()).toEqual(["s1"]);
|
|
115
|
+
});
|
|
116
|
+
it.skipIf(!has("environment"))("pauses an environment when it offers that", async () => {
|
|
117
|
+
const { host, control } = await setup();
|
|
118
|
+
const pause = host.environment.pause;
|
|
119
|
+
expect(pause === void 0).toBe(control.paused === void 0);
|
|
120
|
+
if (!pause) return;
|
|
121
|
+
await expect(pause("s1")).resolves.toBeUndefined();
|
|
122
|
+
expect(control.paused?.()).toEqual(["s1"]);
|
|
123
|
+
});
|
|
124
|
+
it.skipIf(!has("environment"))("deletes a session's sandbox when it offers that", async () => {
|
|
125
|
+
const { host, control } = await setup();
|
|
126
|
+
const remove = host.environment.remove;
|
|
127
|
+
expect(remove === void 0).toBe(control.removed === void 0);
|
|
128
|
+
if (!remove) return;
|
|
129
|
+
await expect(remove("s1")).resolves.toBeUndefined();
|
|
130
|
+
expect(control.removed?.()).toEqual(["s1"]);
|
|
131
|
+
});
|
|
108
132
|
it.skipIf(!has("badges"))("reads several sessions' badges at once, none for a session without artifacts", async () => {
|
|
109
133
|
const { host } = await setup();
|
|
110
134
|
expect(await host.badges.read(["s1", "s2"])).toEqual({
|
|
@@ -99,7 +99,7 @@ function Outcome({ icon, tone, label, note }) {
|
|
|
99
99
|
className: `${icon} text-zg-body shrink-0`
|
|
100
100
|
}), label]
|
|
101
101
|
}), note && /* @__PURE__ */ jsx("div", {
|
|
102
|
-
className: "pl-[22px] text-zg-ui leading-5 text-[var(--zg-text)] whitespace-pre-wrap
|
|
102
|
+
className: "pl-[22px] text-zg-ui leading-5 text-[var(--zg-text)] whitespace-pre-wrap",
|
|
103
103
|
children: note
|
|
104
104
|
})]
|
|
105
105
|
});
|
|
@@ -5,6 +5,16 @@ export interface SelectCursorProps {
|
|
|
5
5
|
selected: string | null;
|
|
6
6
|
/** Any value that changes when rows reflow, such as the stops. A change re-measures the highlight. */
|
|
7
7
|
layout: unknown;
|
|
8
|
+
/**
|
|
9
|
+
* The span to tint by its first and last root rows (`data-row`), instead of the rows marked `data-sel`: the
|
|
10
|
+
* prompt rail's hovered exchange.
|
|
11
|
+
*/
|
|
12
|
+
span?: {
|
|
13
|
+
first: string;
|
|
14
|
+
last: string;
|
|
15
|
+
} | null;
|
|
16
|
+
/** Scrolls the selection into view after each move. Off for a tint that only shows where something is. */
|
|
17
|
+
follow?: boolean;
|
|
8
18
|
/** Extra classes on the root element. */
|
|
9
19
|
className?: string;
|
|
10
20
|
/** Inline styles on the root element, merged after the component's own. */
|
|
@@ -15,4 +25,4 @@ export interface SelectCursorProps {
|
|
|
15
25
|
*
|
|
16
26
|
* @param props - Cursor props: the `selected` stop and a `layout` token.
|
|
17
27
|
*/
|
|
18
|
-
export declare function SelectCursor({ selected, layout, className, style }: SelectCursorProps): import("react").JSX.Element;
|
|
28
|
+
export declare function SelectCursor({ selected, layout, span, follow, className, style }: SelectCursorProps): import("react").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useReducedMotion } from "../../motion/reduced.js";
|
|
2
|
+
import { dataRowSelector } from "../headless/transcript/rail.js";
|
|
2
3
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
4
|
import { jsx } from "react/jsx-runtime";
|
|
4
5
|
// src/chat/transcript/SelectCursor.tsx
|
|
@@ -10,7 +11,7 @@ const SELECT_BLEED_TOP_PX = 8;
|
|
|
10
11
|
*
|
|
11
12
|
* @param props - Cursor props: the `selected` stop and a `layout` token.
|
|
12
13
|
*/
|
|
13
|
-
function SelectCursor({ selected, layout, className, style }) {
|
|
14
|
+
function SelectCursor({ selected, layout, span = null, follow = true, className, style }) {
|
|
14
15
|
const ref = useRef(null);
|
|
15
16
|
const reduced = useReducedMotion();
|
|
16
17
|
const [box, setBox] = useState(null);
|
|
@@ -24,8 +25,10 @@ function SelectCursor({ selected, layout, className, style }) {
|
|
|
24
25
|
followed.current = null;
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
28
|
+
const rowSel = (id) => `:scope > ${dataRowSelector(id)}`;
|
|
29
|
+
const pick = () => span ? [span.first, span.last].flatMap((id) => timeline.querySelector(rowSel(id)) ?? []) : [...timeline.querySelectorAll("[data-sel]")];
|
|
27
30
|
const measure = () => {
|
|
28
|
-
const marked =
|
|
31
|
+
const marked = pick();
|
|
29
32
|
if (marked.length === 0) return null;
|
|
30
33
|
const base = timeline.getBoundingClientRect().top;
|
|
31
34
|
let top = Number.POSITIVE_INFINITY;
|
|
@@ -43,7 +46,7 @@ function SelectCursor({ selected, layout, className, style }) {
|
|
|
43
46
|
const next = measure();
|
|
44
47
|
setBox(next);
|
|
45
48
|
const scroller = timeline.closest(".overflow-y-auto");
|
|
46
|
-
if (next && scroller && followed.current !== selected) {
|
|
49
|
+
if (follow && next && scroller && followed.current !== selected) {
|
|
47
50
|
followed.current = selected;
|
|
48
51
|
const view = scroller.getBoundingClientRect();
|
|
49
52
|
const top = timeline.getBoundingClientRect().top + next.top;
|
|
@@ -65,12 +68,14 @@ function SelectCursor({ selected, layout, className, style }) {
|
|
|
65
68
|
const box = measure();
|
|
66
69
|
setBox((prev) => prev && box && prev.top === box.top && prev.height === box.height ? prev : box);
|
|
67
70
|
});
|
|
68
|
-
for (const node of
|
|
71
|
+
for (const node of pick()) ro.observe(node);
|
|
69
72
|
return () => ro.disconnect();
|
|
70
73
|
}, [
|
|
71
74
|
selected,
|
|
72
75
|
layout,
|
|
73
|
-
reduced
|
|
76
|
+
reduced,
|
|
77
|
+
span,
|
|
78
|
+
follow
|
|
74
79
|
]);
|
|
75
80
|
useEffect(() => {
|
|
76
81
|
if (box === null || sliding) return void 0;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prompt rail: one tick per prompt the user typed, left of the
|
|
3
|
+
* transcript's column (`.zg-transcript-column`, `--zg-transcript-gutter`):
|
|
4
|
+
* centred in the space between the pane's edge and the text, and once that
|
|
5
|
+
* space is wide, held near the pane's edge (`RAIL_EDGE_INSET_PX`), clear of
|
|
6
|
+
* the conversation.
|
|
7
|
+
* The tick of the exchange in view is raised as the transcript scrolls (or
|
|
8
|
+
* the one holding select-turn mode's cursor). Hovering a tick tints that
|
|
9
|
+
* exchange's rows and opens a card with the prompt and the start of its
|
|
10
|
+
* answer; moving along the rail moves the card, with no new delay, and Esc
|
|
11
|
+
* closes it. A click, or the previous / next message keys, glides the prompt
|
|
12
|
+
* to the top; next past the last prompt glides to the end of its answer.
|
|
13
|
+
*
|
|
14
|
+
* The rail floats over that space: showing, hiding or growing it never moves
|
|
15
|
+
* the layout. It hides with fewer than two prompts, where the space has no
|
|
16
|
+
* room for it, and on touch screens.
|
|
17
|
+
*
|
|
18
|
+
* <TranscriptRailProvider>
|
|
19
|
+
* <div className="relative">
|
|
20
|
+
* <section ref={scroller} className="overflow-y-auto">
|
|
21
|
+
* <div className="zg-transcript-column"><Transcript … /></div>
|
|
22
|
+
* </section>
|
|
23
|
+
* <TranscriptRail scroller={scroller} keys />
|
|
24
|
+
* </div>
|
|
25
|
+
* </TranscriptRailProvider>
|
|
26
|
+
*
|
|
27
|
+
* The transcript under the provider publishes its exchanges to it; one
|
|
28
|
+
* provider holds one transcript.
|
|
29
|
+
*/
|
|
30
|
+
import { Cluster, Row } from "../headless/transcript/rows.js";
|
|
31
|
+
import { TranscriptRailStore } from "../headless/transcript/rail.js";
|
|
32
|
+
import "../headless/transcript/index.js";
|
|
33
|
+
import { CSSProperties, ReactNode, RefObject } from "react";
|
|
34
|
+
import { RunReceipt } from "zidane/chat/pure";
|
|
35
|
+
/** Props for {@link TranscriptRailProvider}. */
|
|
36
|
+
export interface TranscriptRailProviderProps {
|
|
37
|
+
/** The transcript and its rail. */
|
|
38
|
+
children: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Holds the rail's store for the transcript and the rail below it.
|
|
42
|
+
*
|
|
43
|
+
* @param props - The {@link TranscriptRailProviderProps}.
|
|
44
|
+
*/
|
|
45
|
+
export declare function TranscriptRailProvider({ children }: TranscriptRailProviderProps): import("react").JSX.Element;
|
|
46
|
+
/** The rail store of the nearest {@link TranscriptRailProvider}, or `null` outside one. */
|
|
47
|
+
export declare function useTranscriptRailStore(): TranscriptRailStore | null;
|
|
48
|
+
/**
|
|
49
|
+
* The transcript's side of the rail: publishes its exchanges and the cursor's exchange to the provider's store.
|
|
50
|
+
* Outside a provider it computes nothing.
|
|
51
|
+
*
|
|
52
|
+
* @param clusters - The root clusters the transcript paints.
|
|
53
|
+
* @param isHidden - Whether a row paints nothing.
|
|
54
|
+
* @param receipts - The receipts docked on reply rows.
|
|
55
|
+
* @param selectedTurn - Select-turn mode's selected stop (a turn id), or `null`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useRailPublish(clusters: readonly Cluster[], isHidden: (row: Row) => boolean, receipts: ReadonlyMap<string, RunReceipt>, selectedTurn: string | null): TranscriptRailStore | null;
|
|
58
|
+
/** Props for {@link RailTint}. */
|
|
59
|
+
interface RailTintProps {
|
|
60
|
+
store: TranscriptRailStore;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The hovered exchange's tint, behind the transcript's rows (the select cursor's element, without following).
|
|
64
|
+
*
|
|
65
|
+
* @param props - The rail's store.
|
|
66
|
+
*/
|
|
67
|
+
export declare const RailTint: import("react").MemoExoticComponent<({ store }: RailTintProps) => import("react").JSX.Element>;
|
|
68
|
+
/** Props for {@link TranscriptRail}. */
|
|
69
|
+
export interface TranscriptRailProps {
|
|
70
|
+
/** The transcript's scroll area. The rail sits left of its `.zg-transcript-column`, in the rail's offset parent. */
|
|
71
|
+
scroller: RefObject<HTMLElement | null>;
|
|
72
|
+
/** Binds the previous / next prompt keys (`previousPrompt`, `nextPrompt`) to this rail: the conversation on show. */
|
|
73
|
+
keys?: boolean;
|
|
74
|
+
/** Extra classes on the rail's root element. */
|
|
75
|
+
className?: string;
|
|
76
|
+
/** Inline styles on the root element, merged after the component's own. */
|
|
77
|
+
style?: CSSProperties;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Renders the prompt rail left of a transcript's column: a tick per prompt, the one in view raised, a card on hover,
|
|
81
|
+
* a jump on click.
|
|
82
|
+
*
|
|
83
|
+
* @param props - The {@link TranscriptRailProps}.
|
|
84
|
+
*/
|
|
85
|
+
export declare function TranscriptRail({ scroller, keys, className, style }: TranscriptRailProps): import("react").JSX.Element;
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { FloatingSurface } from "../../components/floating/FloatingSurface.js";
|
|
2
|
+
import "../../components/floating/hover-delay.js";
|
|
3
|
+
import { useKeyCommands } from "../../keybindings/KeyCommands.js";
|
|
4
|
+
import { useReducedMotion } from "../../motion/reduced.js";
|
|
5
|
+
import { constant, useReadable } from "../headless/store.js";
|
|
6
|
+
import { EMPTY_RAIL, computeRailModel, createTranscriptRailStore, dataRowSelector } from "../headless/transcript/rail.js";
|
|
7
|
+
import { useChatLabels } from "../useChatLabels.js";
|
|
8
|
+
import { useModelName } from "./actions.js";
|
|
9
|
+
import { mountRowNow } from "./LazyRow.js";
|
|
10
|
+
import { RUN_RECEIPT_TINT, ReceiptValue } from "./receipt-parts.js";
|
|
11
|
+
import { SelectCursor } from "./SelectCursor.js";
|
|
12
|
+
import { createContext, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
13
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { formatRunReceiptCells } from "zidane/chat/pure";
|
|
15
|
+
// src/chat/transcript/TranscriptRail.tsx
|
|
16
|
+
/** The rail's width: its ticks' hit area. */
|
|
17
|
+
const RAIL_WIDTH_PX = 16;
|
|
18
|
+
/**
|
|
19
|
+
* The farthest the rail sits from the pane's left edge. In a narrow pane it centres in the space left of the text;
|
|
20
|
+
* once that space is wider than twice this, it stays this far from the edge, clear of the conversation.
|
|
21
|
+
*/
|
|
22
|
+
const RAIL_EDGE_INSET_PX = 16;
|
|
23
|
+
/** Where a jump puts the prompt: this far below the view's top. */
|
|
24
|
+
const JUMP_MARGIN_PX = 16;
|
|
25
|
+
/** The exchange in view is the last one starting above this line: this share of the view down, at most `SPY_LINE_MAX_PX`. */
|
|
26
|
+
const SPY_LINE_SHARE = .3;
|
|
27
|
+
const SPY_LINE_MAX_PX = 160;
|
|
28
|
+
/** A jump farther than this many views goes there at once (a glide that long reads as lag). */
|
|
29
|
+
const FAR_VIEWS = 1.5;
|
|
30
|
+
/** A scroll still for this long ends a jump: the spy reads the view again. */
|
|
31
|
+
const JUMP_SETTLE_MS = 140;
|
|
32
|
+
/** A far jump aims again each frame until its target holds still this many frames, for at most `AIM_MAX_FRAMES`. */
|
|
33
|
+
const AIM_STILL_FRAMES = 2;
|
|
34
|
+
const AIM_MAX_FRAMES = 12;
|
|
35
|
+
const CARD_WIDTH_PX = 320;
|
|
36
|
+
/** A tick's accessible name: the prompt's start, cut at a word. */
|
|
37
|
+
const TICK_LABEL_CHARS = 80;
|
|
38
|
+
const RailContext = createContext(null);
|
|
39
|
+
const NO_RAIL = constant(createTranscriptRailStore().get());
|
|
40
|
+
/**
|
|
41
|
+
* Holds the rail's store for the transcript and the rail below it.
|
|
42
|
+
*
|
|
43
|
+
* @param props - The {@link TranscriptRailProviderProps}.
|
|
44
|
+
*/
|
|
45
|
+
function TranscriptRailProvider({ children }) {
|
|
46
|
+
const [store] = useState(createTranscriptRailStore);
|
|
47
|
+
return /* @__PURE__ */ jsx(RailContext.Provider, {
|
|
48
|
+
value: store,
|
|
49
|
+
children
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** The rail store of the nearest {@link TranscriptRailProvider}, or `null` outside one. */
|
|
53
|
+
function useTranscriptRailStore() {
|
|
54
|
+
return useContext(RailContext);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The transcript's side of the rail: publishes its exchanges and the cursor's exchange to the provider's store.
|
|
58
|
+
* Outside a provider it computes nothing.
|
|
59
|
+
*
|
|
60
|
+
* @param clusters - The root clusters the transcript paints.
|
|
61
|
+
* @param isHidden - Whether a row paints nothing.
|
|
62
|
+
* @param receipts - The receipts docked on reply rows.
|
|
63
|
+
* @param selectedTurn - Select-turn mode's selected stop (a turn id), or `null`.
|
|
64
|
+
*/
|
|
65
|
+
function useRailPublish(clusters, isHidden, receipts, selectedTurn) {
|
|
66
|
+
const store = useContext(RailContext);
|
|
67
|
+
const model = useMemo(() => store ? computeRailModel(clusters, {
|
|
68
|
+
isHidden,
|
|
69
|
+
receipts
|
|
70
|
+
}) : null, [
|
|
71
|
+
store,
|
|
72
|
+
clusters,
|
|
73
|
+
isHidden,
|
|
74
|
+
receipts
|
|
75
|
+
]);
|
|
76
|
+
useLayoutEffect(() => {
|
|
77
|
+
if (store && model) store.publish(model);
|
|
78
|
+
}, [store, model]);
|
|
79
|
+
useLayoutEffect(() => store ? () => store.publish(EMPTY_RAIL) : void 0, [store]);
|
|
80
|
+
const selected = selectedTurn && model ? model.exchangeOfTurn.get(selectedTurn) ?? null : null;
|
|
81
|
+
useLayoutEffect(() => {
|
|
82
|
+
store?.select(selected);
|
|
83
|
+
}, [store, selected]);
|
|
84
|
+
return store;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The hovered exchange's tint, behind the transcript's rows (the select cursor's element, without following).
|
|
88
|
+
*
|
|
89
|
+
* @param props - The rail's store.
|
|
90
|
+
*/
|
|
91
|
+
const RailTint = memo(({ store }) => {
|
|
92
|
+
const { exchanges, hovered, selected } = useReadable(store);
|
|
93
|
+
const exchange = hovered && selected === null ? exchanges.find((e) => e.id === hovered) : void 0;
|
|
94
|
+
const first = exchange?.firstRowId;
|
|
95
|
+
const last = exchange?.lastRowId;
|
|
96
|
+
const span = useMemo(() => first && last ? {
|
|
97
|
+
first,
|
|
98
|
+
last
|
|
99
|
+
} : null, [first, last]);
|
|
100
|
+
return /* @__PURE__ */ jsx(SelectCursor, {
|
|
101
|
+
selected: span ? hovered : null,
|
|
102
|
+
layout: exchanges,
|
|
103
|
+
span,
|
|
104
|
+
follow: false,
|
|
105
|
+
className: "zg-rail-tint"
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
RailTint.displayName = "RailTint";
|
|
109
|
+
/** The prompt row of an exchange in the scroller. */
|
|
110
|
+
function promptRow(scroller, id) {
|
|
111
|
+
return scroller.querySelector(dataRowSelector(id));
|
|
112
|
+
}
|
|
113
|
+
/** A tick's accessible name: the prompt, past `TICK_LABEL_CHARS` cut at a word boundary with an ellipsis. */
|
|
114
|
+
function tickLabel(prompt) {
|
|
115
|
+
if (prompt.length <= TICK_LABEL_CHARS) return prompt;
|
|
116
|
+
const cut = prompt.slice(0, TICK_LABEL_CHARS);
|
|
117
|
+
const space = cut.lastIndexOf(" ");
|
|
118
|
+
return `${(space > TICK_LABEL_CHARS / 2 ? cut.slice(0, space) : cut).trimEnd()}…`;
|
|
119
|
+
}
|
|
120
|
+
/** The exchange in view: the last one whose prompt starts above the spy line (the last at the bottom). */
|
|
121
|
+
function spyExchange(scroller, exchanges) {
|
|
122
|
+
if (exchanges.length === 0) return null;
|
|
123
|
+
if (scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight <= 2) return exchanges[exchanges.length - 1].id;
|
|
124
|
+
const line = scroller.getBoundingClientRect().top + Math.min(scroller.clientHeight * SPY_LINE_SHARE, SPY_LINE_MAX_PX);
|
|
125
|
+
let lo = 0;
|
|
126
|
+
let hi = exchanges.length - 1;
|
|
127
|
+
let found = 0;
|
|
128
|
+
while (lo <= hi) {
|
|
129
|
+
const mid = lo + hi >> 1;
|
|
130
|
+
const row = promptRow(scroller, exchanges[mid].id);
|
|
131
|
+
if (row && row.getBoundingClientRect().top <= line) {
|
|
132
|
+
found = mid;
|
|
133
|
+
lo = mid + 1;
|
|
134
|
+
} else hi = mid - 1;
|
|
135
|
+
}
|
|
136
|
+
return exchanges[found].id;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Renders the prompt rail left of a transcript's column: a tick per prompt, the one in view raised, a card on hover,
|
|
140
|
+
* a jump on click.
|
|
141
|
+
*
|
|
142
|
+
* @param props - The {@link TranscriptRailProps}.
|
|
143
|
+
*/
|
|
144
|
+
function TranscriptRail({ scroller, keys = false, className, style }) {
|
|
145
|
+
const store = useContext(RailContext);
|
|
146
|
+
const { exchanges, hovered, selected } = useReadable(store ?? NO_RAIL);
|
|
147
|
+
const labels = useChatLabels();
|
|
148
|
+
const reduced = useReducedMotion();
|
|
149
|
+
const root = useRef(null);
|
|
150
|
+
const list = useRef(null);
|
|
151
|
+
const [place, setPlace] = useState(null);
|
|
152
|
+
const any = exchanges.length > 0;
|
|
153
|
+
useLayoutEffect(() => {
|
|
154
|
+
const el = scroller.current;
|
|
155
|
+
const rail = root.current;
|
|
156
|
+
if (!el || !rail) return void 0;
|
|
157
|
+
const measure = () => {
|
|
158
|
+
const parent = rail.offsetParent;
|
|
159
|
+
const column = el.querySelector(".zg-transcript-column");
|
|
160
|
+
if (!parent || !column) {
|
|
161
|
+
setPlace(null);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const textLeft = column.getBoundingClientRect().left + (Number.parseFloat(getComputedStyle(column).paddingLeft) || 0);
|
|
165
|
+
const view = el.getBoundingClientRect();
|
|
166
|
+
const edge = view.left + el.clientLeft;
|
|
167
|
+
const room = textLeft - edge;
|
|
168
|
+
if (room < 24) {
|
|
169
|
+
setPlace(null);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const base = parent.getBoundingClientRect();
|
|
173
|
+
const left = Math.round(edge + Math.min((room - RAIL_WIDTH_PX) / 2, RAIL_EDGE_INSET_PX) - base.left);
|
|
174
|
+
const top = Math.round(view.top + el.clientHeight / 2 - base.top);
|
|
175
|
+
setPlace((prev) => prev && prev.left === left && prev.top === top ? prev : {
|
|
176
|
+
left,
|
|
177
|
+
top
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
measure();
|
|
181
|
+
const ro = new ResizeObserver(measure);
|
|
182
|
+
ro.observe(el);
|
|
183
|
+
const column = el.querySelector(".zg-transcript-column");
|
|
184
|
+
if (column) ro.observe(column);
|
|
185
|
+
return () => ro.disconnect();
|
|
186
|
+
}, [scroller, any]);
|
|
187
|
+
const [spied, setSpied] = useState(null);
|
|
188
|
+
const jumping = useRef(null);
|
|
189
|
+
const aimFrame = useRef(0);
|
|
190
|
+
const exchangesRef = useRef(exchanges);
|
|
191
|
+
exchangesRef.current = exchanges;
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
const el = scroller.current;
|
|
194
|
+
if (!el) return void 0;
|
|
195
|
+
let frame = 0;
|
|
196
|
+
const read = () => {
|
|
197
|
+
frame = 0;
|
|
198
|
+
if (!jumping.current) setSpied(spyExchange(el, exchangesRef.current));
|
|
199
|
+
};
|
|
200
|
+
const onScroll = () => {
|
|
201
|
+
const jump = jumping.current;
|
|
202
|
+
if (jump) {
|
|
203
|
+
window.clearTimeout(jump.timer);
|
|
204
|
+
jump.timer = window.setTimeout(() => {
|
|
205
|
+
jumping.current = null;
|
|
206
|
+
read();
|
|
207
|
+
}, JUMP_SETTLE_MS);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (!frame) frame = requestAnimationFrame(read);
|
|
211
|
+
};
|
|
212
|
+
read();
|
|
213
|
+
el.addEventListener("scroll", onScroll, { passive: true });
|
|
214
|
+
return () => {
|
|
215
|
+
el.removeEventListener("scroll", onScroll);
|
|
216
|
+
cancelAnimationFrame(frame);
|
|
217
|
+
};
|
|
218
|
+
}, [scroller, exchanges]);
|
|
219
|
+
useEffect(() => () => {
|
|
220
|
+
window.clearTimeout(jumping.current?.timer);
|
|
221
|
+
cancelAnimationFrame(aimFrame.current);
|
|
222
|
+
}, []);
|
|
223
|
+
const active = selected ?? spied;
|
|
224
|
+
const glide = (el, id, end, targetOf) => {
|
|
225
|
+
const target = targetOf();
|
|
226
|
+
const far = Math.abs(target - el.scrollTop) > el.clientHeight * FAR_VIEWS;
|
|
227
|
+
window.clearTimeout(jumping.current?.timer);
|
|
228
|
+
cancelAnimationFrame(aimFrame.current);
|
|
229
|
+
jumping.current = {
|
|
230
|
+
id,
|
|
231
|
+
end,
|
|
232
|
+
timer: window.setTimeout(() => {
|
|
233
|
+
jumping.current = null;
|
|
234
|
+
}, JUMP_SETTLE_MS)
|
|
235
|
+
};
|
|
236
|
+
setSpied(id);
|
|
237
|
+
el.scrollTo({
|
|
238
|
+
top: target,
|
|
239
|
+
behavior: far || reduced ? "auto" : "smooth"
|
|
240
|
+
});
|
|
241
|
+
if (!far) return;
|
|
242
|
+
let frames = 0;
|
|
243
|
+
let still = 0;
|
|
244
|
+
const aim = () => {
|
|
245
|
+
const off = targetOf() - el.scrollTop;
|
|
246
|
+
if (Math.abs(off) > 1) {
|
|
247
|
+
el.scrollTop += off;
|
|
248
|
+
still = 0;
|
|
249
|
+
} else still++;
|
|
250
|
+
aimFrame.current = still < AIM_STILL_FRAMES && ++frames < AIM_MAX_FRAMES ? requestAnimationFrame(aim) : 0;
|
|
251
|
+
};
|
|
252
|
+
aimFrame.current = requestAnimationFrame(aim);
|
|
253
|
+
};
|
|
254
|
+
const jump = (id) => {
|
|
255
|
+
const el = scroller.current;
|
|
256
|
+
const row = el ? promptRow(el, id) : null;
|
|
257
|
+
if (!el || !row) return;
|
|
258
|
+
mountRowNow(row);
|
|
259
|
+
glide(el, id, false, () => el.scrollTop + row.getBoundingClientRect().top - el.getBoundingClientRect().top - JUMP_MARGIN_PX);
|
|
260
|
+
};
|
|
261
|
+
const step = (dir) => {
|
|
262
|
+
const el = scroller.current;
|
|
263
|
+
const all = exchangesRef.current;
|
|
264
|
+
if (!el || all.length === 0) return;
|
|
265
|
+
const inFlight = selected === null ? jumping.current : null;
|
|
266
|
+
const current = selected ?? inFlight?.id ?? spyExchange(el, all);
|
|
267
|
+
let at = all.findIndex((e) => e.id === current);
|
|
268
|
+
if (dir > 0) at++;
|
|
269
|
+
else if (inFlight) {
|
|
270
|
+
if (!inFlight.end) at--;
|
|
271
|
+
} else if (at >= 0) {
|
|
272
|
+
const row = promptRow(el, all[at].id);
|
|
273
|
+
if (!(row ? row.getBoundingClientRect().top < el.getBoundingClientRect().top + JUMP_MARGIN_PX - 4 : false)) at--;
|
|
274
|
+
}
|
|
275
|
+
if (at < 0) return;
|
|
276
|
+
if (at < all.length) jump(all[at].id);
|
|
277
|
+
else glide(el, all[all.length - 1].id, true, () => el.scrollHeight - el.clientHeight);
|
|
278
|
+
};
|
|
279
|
+
useKeyCommands(keys ? {
|
|
280
|
+
previousPrompt: () => step(-1),
|
|
281
|
+
nextPrompt: () => step(1)
|
|
282
|
+
} : {});
|
|
283
|
+
const [card, setCard] = useState(null);
|
|
284
|
+
const cardOpen = useRef(false);
|
|
285
|
+
const cardTimer = useRef(void 0);
|
|
286
|
+
useEffect(() => () => window.clearTimeout(cardTimer.current), []);
|
|
287
|
+
const showCard = useCallback((next) => {
|
|
288
|
+
cardOpen.current = next !== null;
|
|
289
|
+
setCard(next);
|
|
290
|
+
}, []);
|
|
291
|
+
const point = useCallback((id, anchor) => {
|
|
292
|
+
store?.hover(id);
|
|
293
|
+
window.clearTimeout(cardTimer.current);
|
|
294
|
+
if (cardOpen.current) showCard({
|
|
295
|
+
id,
|
|
296
|
+
anchor
|
|
297
|
+
});
|
|
298
|
+
else cardTimer.current = window.setTimeout(showCard, 250, {
|
|
299
|
+
id,
|
|
300
|
+
anchor
|
|
301
|
+
});
|
|
302
|
+
}, [store, showCard]);
|
|
303
|
+
const leave = useCallback(() => {
|
|
304
|
+
store?.hover(null);
|
|
305
|
+
window.clearTimeout(cardTimer.current);
|
|
306
|
+
cardTimer.current = window.setTimeout(showCard, 150, null);
|
|
307
|
+
}, [store, showCard]);
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
const box = list.current;
|
|
310
|
+
const tick = active ? [...box?.querySelectorAll("[data-exchange]") ?? []].find((el) => el.dataset.exchange === active) : null;
|
|
311
|
+
if (!box || !tick) return;
|
|
312
|
+
if (tick.offsetTop < box.scrollTop) box.scrollTop = tick.offsetTop;
|
|
313
|
+
else if (tick.offsetTop + tick.offsetHeight > box.scrollTop + box.clientHeight) box.scrollTop = tick.offsetTop + tick.offsetHeight - box.clientHeight;
|
|
314
|
+
}, [active]);
|
|
315
|
+
const onKeyDown = (e) => {
|
|
316
|
+
if (e.key === "Escape") {
|
|
317
|
+
if (!cardOpen.current && hovered === null) return;
|
|
318
|
+
e.preventDefault();
|
|
319
|
+
e.stopPropagation();
|
|
320
|
+
window.clearTimeout(cardTimer.current);
|
|
321
|
+
showCard(null);
|
|
322
|
+
store?.hover(null);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (e.key !== "ArrowUp" && e.key !== "ArrowDown" && e.key !== "Home" && e.key !== "End") return;
|
|
326
|
+
const ticks = [...list.current?.querySelectorAll("button") ?? []];
|
|
327
|
+
const at = ticks.indexOf(document.activeElement);
|
|
328
|
+
const to = e.key === "Home" ? 0 : e.key === "End" ? ticks.length - 1 : at + (e.key === "ArrowUp" ? -1 : 1);
|
|
329
|
+
const next = ticks[Math.max(0, Math.min(ticks.length - 1, to))];
|
|
330
|
+
if (!next) return;
|
|
331
|
+
e.preventDefault();
|
|
332
|
+
e.stopPropagation();
|
|
333
|
+
next.focus();
|
|
334
|
+
};
|
|
335
|
+
const shown = store !== null && exchanges.length >= 2 && place !== null;
|
|
336
|
+
const tabStop = active && exchanges.some((e) => e.id === active) ? active : exchanges[exchanges.length - 1]?.id;
|
|
337
|
+
const carded = card ? exchanges.find((e) => e.id === card.id) : void 0;
|
|
338
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
|
|
339
|
+
ref: root,
|
|
340
|
+
"aria-hidden": shown ? void 0 : true,
|
|
341
|
+
className: ["zg-prompt-rail", className].filter(Boolean).join(" "),
|
|
342
|
+
"data-on": shown,
|
|
343
|
+
style: {
|
|
344
|
+
...place ? {
|
|
345
|
+
left: place.left,
|
|
346
|
+
top: place.top
|
|
347
|
+
} : {},
|
|
348
|
+
width: RAIL_WIDTH_PX,
|
|
349
|
+
...style
|
|
350
|
+
},
|
|
351
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
352
|
+
ref: list,
|
|
353
|
+
role: "toolbar",
|
|
354
|
+
"aria-orientation": "vertical",
|
|
355
|
+
"aria-label": labels.promptRail,
|
|
356
|
+
className: "zg-prompt-rail-ticks",
|
|
357
|
+
onPointerLeave: leave,
|
|
358
|
+
onBlur: (e) => {
|
|
359
|
+
if (!e.currentTarget.contains(e.relatedTarget)) leave();
|
|
360
|
+
},
|
|
361
|
+
onKeyDown,
|
|
362
|
+
children: exchanges.length >= 2 && exchanges.map((exchange) => /* @__PURE__ */ jsx("button", {
|
|
363
|
+
type: "button",
|
|
364
|
+
className: "zg-prompt-rail-tick",
|
|
365
|
+
"data-exchange": exchange.id,
|
|
366
|
+
"data-hover": exchange.id === hovered ? "" : void 0,
|
|
367
|
+
"aria-label": tickLabel(exchange.prompt),
|
|
368
|
+
"aria-current": exchange.id === active ? "location" : void 0,
|
|
369
|
+
tabIndex: exchange.id === tabStop ? 0 : -1,
|
|
370
|
+
onPointerEnter: (e) => point(exchange.id, e.currentTarget),
|
|
371
|
+
onFocus: (e) => point(exchange.id, e.currentTarget),
|
|
372
|
+
onClick: () => jump(exchange.id)
|
|
373
|
+
}, exchange.id))
|
|
374
|
+
})
|
|
375
|
+
}), /* @__PURE__ */ jsx(FloatingSurface, {
|
|
376
|
+
open: shown && carded !== void 0,
|
|
377
|
+
anchor: { element: card?.anchor ?? null },
|
|
378
|
+
side: "right",
|
|
379
|
+
align: "center",
|
|
380
|
+
offset: 10,
|
|
381
|
+
width: CARD_WIDTH_PX,
|
|
382
|
+
className: "zg-prompt-rail-card",
|
|
383
|
+
children: carded && /* @__PURE__ */ jsx(RailCard, { exchange: carded })
|
|
384
|
+
})] });
|
|
385
|
+
}
|
|
386
|
+
/** The run receipt's cells the card shows, as the receipt row's chips: the model that answered and how long it took. */
|
|
387
|
+
const CARD_CELLS = /* @__PURE__ */ new Set(["model", "duration"]);
|
|
388
|
+
/**
|
|
389
|
+
* The hover card's content: the prompt and the start of its answer, each clamped (a long message never grows the card,
|
|
390
|
+
* a long word or path wraps inside it), then the receipt's chips.
|
|
391
|
+
*/
|
|
392
|
+
function RailCard({ exchange }) {
|
|
393
|
+
const modelName = useModelName();
|
|
394
|
+
const cells = exchange.receipt ? formatRunReceiptCells(exchange.receipt, modelName).filter((c) => CARD_CELLS.has(c.kind)) : [];
|
|
395
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
396
|
+
className: "flex flex-col gap-1.5 px-3 py-2.5",
|
|
397
|
+
"aria-hidden": true,
|
|
398
|
+
children: [
|
|
399
|
+
/* @__PURE__ */ jsx("p", {
|
|
400
|
+
className: "m-0 text-zg-ui leading-zg-ui font-medium text-[var(--zg-text)] line-clamp-2 break-words",
|
|
401
|
+
children: exchange.prompt
|
|
402
|
+
}),
|
|
403
|
+
exchange.answer && /* @__PURE__ */ jsx("p", {
|
|
404
|
+
className: "m-0 text-zg-label leading-zg-label text-[var(--zg-text-muted)] line-clamp-3 break-words",
|
|
405
|
+
children: exchange.answer
|
|
406
|
+
}),
|
|
407
|
+
cells.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
408
|
+
className: "zg-meta flex flex-wrap items-center gap-1 min-w-0 mt-0.5",
|
|
409
|
+
children: cells.map((cell) => /* @__PURE__ */ jsx("span", {
|
|
410
|
+
className: "zg-meta-chip shrink min-w-0 max-w-full overflow-hidden",
|
|
411
|
+
"data-cell": cell.kind,
|
|
412
|
+
children: /* @__PURE__ */ jsx(ReceiptValue, {
|
|
413
|
+
text: cell.text,
|
|
414
|
+
className: RUN_RECEIPT_TINT[cell.kind]
|
|
415
|
+
})
|
|
416
|
+
}, cell.kind))
|
|
417
|
+
})
|
|
418
|
+
]
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
export { RailTint, TranscriptRail, TranscriptRailProvider, useRailPublish, useTranscriptRailStore };
|