zidane-ui 9.2.2 → 9.3.1
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/live.d.ts +6 -0
- package/dist/adapters/live.js +16 -8
- package/dist/adapters/server-composer-host.js +22 -9
- package/dist/adapters/server-host.js +143 -18
- package/dist/adapters/server-media.d.ts +9 -1
- package/dist/adapters/server-media.js +14 -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/HostTranscript.d.ts +0 -12
- package/dist/chat/HostTranscript.js +6 -1
- package/dist/chat/SessionStreamsProvider.d.ts +8 -0
- package/dist/chat/SessionStreamsProvider.js +11 -2
- package/dist/chat/StatusDot.js +8 -2
- package/dist/chat/Transcript.d.ts +20 -11
- package/dist/chat/Transcript.js +335 -162
- package/dist/chat/composer/ComposerEditor.js +1 -1
- package/dist/chat/headless/host.d.ts +43 -7
- package/dist/chat/headless/index.d.ts +8 -6
- package/dist/chat/headless/index.js +11 -9
- package/dist/chat/headless/labels.d.ts +30 -0
- package/dist/chat/headless/labels.js +29 -0
- package/dist/chat/headless/markdown-chunks.d.ts +2 -1
- package/dist/chat/headless/markdown-chunks.js +12 -20
- package/dist/chat/headless/markdown-scan.d.ts +66 -0
- package/dist/chat/headless/markdown-scan.js +124 -0
- package/dist/chat/headless/markdown-stream.d.ts +64 -0
- package/dist/chat/headless/markdown-stream.js +143 -0
- package/dist/chat/headless/output-pager.d.ts +68 -0
- package/dist/chat/headless/output-pager.js +113 -0
- package/dist/chat/headless/session-list.d.ts +20 -0
- package/dist/chat/headless/sidebar/activity.d.ts +14 -0
- package/dist/chat/headless/sidebar/activity.js +32 -0
- package/dist/chat/headless/sidebar/directory.d.ts +17 -2
- package/dist/chat/headless/sidebar/directory.js +50 -54
- 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 +38 -2
- package/dist/chat/headless/sidebar/labels.js +16 -0
- package/dist/chat/headless/sidebar/prewarm.d.ts +68 -0
- package/dist/chat/headless/sidebar/prewarm.js +114 -0
- package/dist/chat/headless/streams/actions.d.ts +2 -0
- package/dist/chat/headless/streams/actions.js +1 -0
- package/dist/chat/headless/streams/event-bytes.d.ts +6 -0
- package/dist/chat/headless/streams/event-bytes.js +34 -0
- package/dist/chat/headless/streams/live-events.d.ts +25 -1
- package/dist/chat/headless/streams/live-events.js +53 -2
- package/dist/chat/headless/streams/selectors.d.ts +3 -0
- package/dist/chat/headless/streams/selectors.js +8 -1
- package/dist/chat/headless/streams/session-streams.d.ts +15 -3
- package/dist/chat/headless/streams/session-streams.js +31 -3
- package/dist/chat/headless/streams/store.d.ts +24 -1
- package/dist/chat/headless/streams/store.js +51 -26
- package/dist/chat/headless/streams/transcript-map.d.ts +57 -0
- package/dist/chat/headless/streams/transcript-map.js +88 -0
- package/dist/chat/headless/streams/transcript.d.ts +4 -2
- package/dist/chat/headless/streams/transcript.js +19 -7
- package/dist/chat/headless/transcript/batch.js +5 -1
- package/dist/chat/headless/transcript/blob-media.d.ts +15 -0
- package/dist/chat/headless/transcript/blob-media.js +23 -0
- package/dist/chat/headless/transcript/collapse.d.ts +10 -0
- package/dist/chat/headless/transcript/collapse.js +32 -6
- package/dist/chat/headless/transcript/derive.d.ts +98 -0
- package/dist/chat/headless/transcript/derive.js +89 -0
- package/dist/chat/headless/transcript/exchange-media.d.ts +3 -1
- package/dist/chat/headless/transcript/exchange-media.js +8 -5
- 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-attachments.d.ts +2 -0
- package/dist/chat/headless/transcript/fold-attachments.js +3 -2
- package/dist/chat/headless/transcript/fold.d.ts +4 -2
- package/dist/chat/headless/transcript/fold.js +37 -7
- package/dist/chat/headless/transcript/incremental.d.ts +53 -0
- package/dist/chat/headless/transcript/incremental.js +181 -0
- package/dist/chat/headless/transcript/index.d.ts +2 -1
- package/dist/chat/headless/transcript/index.js +2 -1
- package/dist/chat/headless/transcript/nesting.js +2 -1
- package/dist/chat/headless/transcript/rail.d.ts +142 -0
- package/dist/chat/headless/transcript/rail.js +290 -0
- package/dist/chat/headless/transcript/rows.d.ts +11 -1
- package/dist/chat/headless/transcript/run-failures.d.ts +4 -0
- package/dist/chat/headless/transcript/run-failures.js +31 -2
- package/dist/chat/headless/transcript/seams.d.ts +78 -0
- package/dist/chat/headless/transcript/seams.js +116 -0
- package/dist/chat/headless/transcript/tool-media.d.ts +6 -7
- package/dist/chat/headless/transcript/tool-media.js +27 -9
- 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 +10 -8
- package/dist/chat/index.js +9 -7
- 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/SidebarFooter.d.ts +8 -5
- package/dist/chat/sidebar/SidebarFooter.js +6 -6
- 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/contract.d.ts +5 -3
- package/dist/chat/testing/contract.js +66 -1
- 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/DiffLines.d.ts +6 -1
- package/dist/chat/transcript/DiffLines.js +35 -20
- package/dist/chat/transcript/EditDiffBlock.d.ts +5 -1
- package/dist/chat/transcript/EditDiffBlock.js +89 -30
- package/dist/chat/transcript/InteractionToolBody.js +1 -1
- package/dist/chat/transcript/LazyRow.d.ts +40 -40
- package/dist/chat/transcript/LazyRow.js +101 -149
- package/dist/chat/transcript/MermaidDiagram.js +2 -1
- package/dist/chat/transcript/SelectCursor.d.ts +11 -1
- package/dist/chat/transcript/SelectCursor.js +10 -5
- package/dist/chat/transcript/SubagentBlock.js +3 -2
- package/dist/chat/transcript/TranscriptRail.d.ts +109 -0
- package/dist/chat/transcript/TranscriptRail.js +579 -0
- package/dist/chat/transcript/TranscriptRow.d.ts +4 -7
- package/dist/chat/transcript/TranscriptRow.js +9 -5
- package/dist/chat/transcript/actions.d.ts +43 -3
- package/dist/chat/transcript/actions.js +27 -1
- package/dist/chat/transcript/clipped-output.d.ts +58 -0
- package/dist/chat/transcript/clipped-output.js +131 -0
- package/dist/chat/transcript/fold-attachments.js +10 -5
- package/dist/chat/transcript/fold-worker.js +3 -2
- package/dist/chat/transcript/fold.js +21 -2
- package/dist/chat/transcript/index.d.ts +11 -9
- package/dist/chat/transcript/index.js +10 -8
- package/dist/chat/transcript/markdown-cache.d.ts +7 -1
- package/dist/chat/transcript/markdown-cache.js +12 -1
- package/dist/chat/transcript/markdown.js +116 -54
- package/dist/chat/transcript/media-gallery.d.ts +3 -2
- package/dist/chat/transcript/media-gallery.js +10 -7
- package/dist/chat/transcript/notices.d.ts +23 -1
- package/dist/chat/transcript/notices.js +110 -28
- package/dist/chat/transcript/prompt.js +6 -4
- package/dist/chat/transcript/prose.js +3 -1
- package/dist/chat/transcript/receipt-parts.d.ts +22 -0
- package/dist/chat/transcript/receipt-parts.js +87 -0
- package/dist/chat/transcript/root-items.d.ts +96 -0
- package/dist/chat/transcript/root-items.js +180 -0
- package/dist/chat/transcript/row-mount.d.ts +165 -0
- package/dist/chat/transcript/row-mount.js +498 -0
- package/dist/chat/transcript/row-parking.d.ts +125 -0
- package/dist/chat/transcript/row-parking.js +135 -0
- package/dist/chat/transcript/row-ui-state.d.ts +37 -0
- package/dist/chat/transcript/row-ui-state.js +53 -0
- package/dist/chat/transcript/run-rows.js +6 -78
- package/dist/chat/transcript/script-input.d.ts +1 -1
- package/dist/chat/transcript/scroll-clamp.js +1 -1
- package/dist/chat/transcript/tasks.js +3 -2
- package/dist/chat/transcript/tool-media.d.ts +4 -2
- package/dist/chat/transcript/tool-media.js +15 -7
- package/dist/chat/transcript/tool-parts.d.ts +27 -4
- package/dist/chat/transcript/tool-parts.js +31 -5
- package/dist/chat/transcript/tool-payload.js +26 -11
- package/dist/chat/transcript/tool-row.d.ts +2 -1
- package/dist/chat/transcript/tool-row.js +38 -19
- package/dist/chat/transcript/use-transcript-rows.d.ts +24 -7
- package/dist/chat/transcript/use-transcript-rows.js +28 -46
- package/dist/chat/transcript/useSettledReveal.js +15 -3
- package/dist/chat/transcript/useStickToBottom.js +4 -4
- package/dist/chat/transcript/useTranscriptSearch.js +30 -14
- package/dist/chat/transcript/view-scope.d.ts +26 -6
- package/dist/chat/transcript/view-scope.js +106 -20
- 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-Betz0OWq.d.ts → index-C6-t1SS9.d.ts} +21 -2
- package/dist/dist/index-De9AbmxS.d.ts +1 -0
- 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 +68 -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-performance.js +4 -2
- 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/performance.d.ts +4 -0
- 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/performance/PerformanceSection.js +8 -1
- package/dist/settings/sections/performance/labels.d.ts +2 -0
- package/dist/settings/sections/performance/labels.js +2 -0
- 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 +243 -19
- package/dist/terminal/TerminalDrawer.js +3 -1
- package/dist/views/headless/answers.d.ts +8 -2
- package/dist/views/headless/answers.js +58 -1
- package/dist/views/headless/placement.d.ts +78 -0
- package/dist/views/headless/placement.js +154 -44
- 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 +138 -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
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isFenceClose, parseFenceOpen } from "zidane/chat/pure";
|
|
2
|
+
// src/chat/headless/markdown-scan.ts
|
|
3
|
+
/** A line that may define a link reference or a footnote, after any container markers. */
|
|
4
|
+
const DEFINITION = /^(?:[ \t>]|[*+-][ \t]|\d{1,9}[.)][ \t])*\[(?:[^\]\\\n]|\\.){1,999}\]:/;
|
|
5
|
+
/** The start of an HTML block that runs past blank lines (CommonMark types 1 to 5). */
|
|
6
|
+
const HTML_START = /^ {0,3}(?:<(script|pre|style|textarea)(?=[\s>]|$)|<!--|<\?|<![a-z]|<!\[CDATA\[)/i;
|
|
7
|
+
const HTML_END_RAW = /<\/(?:script|pre|style|textarea)>/i;
|
|
8
|
+
const HTML_END_COMMENT = /-->/;
|
|
9
|
+
const HTML_END_PI = /\?>/;
|
|
10
|
+
const HTML_END_DECL = />/;
|
|
11
|
+
const HTML_END_CDATA = /\]\]>/;
|
|
12
|
+
/** The end marker of the HTML block `line` opens and does not close, or `null`. */
|
|
13
|
+
function htmlBlockOf(line) {
|
|
14
|
+
const start = HTML_START.exec(line);
|
|
15
|
+
if (!start) return null;
|
|
16
|
+
const opener = start[0].trimStart();
|
|
17
|
+
const end = start[1] ? HTML_END_RAW : opener.startsWith("<!--") ? HTML_END_COMMENT : opener.startsWith("<?") ? HTML_END_PI : opener.startsWith("<![") ? HTML_END_CDATA : HTML_END_DECL;
|
|
18
|
+
return end.test(line.slice(start[0].length)) ? null : end;
|
|
19
|
+
}
|
|
20
|
+
/** `line` without the CR of a CRLF line ending. */
|
|
21
|
+
function withoutCR(line) {
|
|
22
|
+
return line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
23
|
+
}
|
|
24
|
+
/** Whether `line` holds only spaces, tabs and a carriage return. */
|
|
25
|
+
function isBlank(line) {
|
|
26
|
+
for (let i = 0; i < line.length; i++) {
|
|
27
|
+
const c = line.charCodeAt(i);
|
|
28
|
+
if (c !== 32 && c !== 9 && c !== 13 && c !== 11 && c !== 12) return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const isDigit = (c) => c !== void 0 && c >= "0" && c <= "9";
|
|
33
|
+
const isMarkerGap = (c) => c === " " || c === " " || c === "\r";
|
|
34
|
+
/**
|
|
35
|
+
* Whether a chunk can start at `line`, the line after a candidate blank line:
|
|
36
|
+
* it starts at column 0 and is not a list item. `undefined` while that depends
|
|
37
|
+
* on characters still to come (`-` may become `- item` or `-1`).
|
|
38
|
+
*
|
|
39
|
+
* @param line - The line, or what has arrived of it.
|
|
40
|
+
* @param complete - The line is whole (its newline arrived, or the text ended).
|
|
41
|
+
*/
|
|
42
|
+
function opensChunk(line, complete) {
|
|
43
|
+
const c = line[0];
|
|
44
|
+
if (c === void 0) return complete ? false : void 0;
|
|
45
|
+
if (c === " " || c === " " || c === "\r") return false;
|
|
46
|
+
if (c === "*" || c === "+" || c === "-") {
|
|
47
|
+
if (line.length > 1) return !isMarkerGap(line[1]);
|
|
48
|
+
return complete ? false : void 0;
|
|
49
|
+
}
|
|
50
|
+
if (!isDigit(c)) return true;
|
|
51
|
+
let i = 1;
|
|
52
|
+
while (i < line.length && isDigit(line[i])) i++;
|
|
53
|
+
if (i > 9) return true;
|
|
54
|
+
if (i === line.length) return complete ? true : void 0;
|
|
55
|
+
const after = line[i];
|
|
56
|
+
if (after !== "." && after !== ")") return true;
|
|
57
|
+
if (i + 1 < line.length) return !isMarkerGap(line[i + 1]);
|
|
58
|
+
return complete ? false : void 0;
|
|
59
|
+
}
|
|
60
|
+
/** Whether `line` may be a definition, read outside every block. */
|
|
61
|
+
function isDefinitionLine(line) {
|
|
62
|
+
return DEFINITION.test(line);
|
|
63
|
+
}
|
|
64
|
+
/** The block state after each line, and whether the next line may start a chunk. */
|
|
65
|
+
var BlockScanner = class {
|
|
66
|
+
target;
|
|
67
|
+
/** The fence open after the lines fed. */
|
|
68
|
+
fence = null;
|
|
69
|
+
/** Where the open fence's line starts. */
|
|
70
|
+
fenceAt = -1;
|
|
71
|
+
/** Where the open fence's line ends (its newline). */
|
|
72
|
+
fenceEnd = -1;
|
|
73
|
+
/** The end marker of the open HTML block, or `null`. */
|
|
74
|
+
html = null;
|
|
75
|
+
/** Characters since the chunk started. */
|
|
76
|
+
size = 0;
|
|
77
|
+
/** The last line was blank, outside every block, past the target: the next line may start a chunk. */
|
|
78
|
+
pending = false;
|
|
79
|
+
/** A definition was seen. */
|
|
80
|
+
refs = false;
|
|
81
|
+
/** @param target - The size a chunk reaches before it may end. */
|
|
82
|
+
constructor(target) {
|
|
83
|
+
this.target = target;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Feeds one whole line.
|
|
87
|
+
*
|
|
88
|
+
* @param line - The line, without its newline.
|
|
89
|
+
* @param at - Where it starts in the text.
|
|
90
|
+
*/
|
|
91
|
+
feed(line, at) {
|
|
92
|
+
this.size += line.length + 1;
|
|
93
|
+
const bare = withoutCR(line);
|
|
94
|
+
if (this.fence) {
|
|
95
|
+
if (isFenceClose(bare, this.fence.char, this.fence.length)) this.fence = null;
|
|
96
|
+
} else if (this.html) {
|
|
97
|
+
if (this.html.test(line)) this.html = null;
|
|
98
|
+
} else {
|
|
99
|
+
const open = parseFenceOpen(bare);
|
|
100
|
+
if (open) {
|
|
101
|
+
this.fence = open;
|
|
102
|
+
this.fenceAt = at;
|
|
103
|
+
this.fenceEnd = at + line.length;
|
|
104
|
+
} else {
|
|
105
|
+
this.html = htmlBlockOf(line);
|
|
106
|
+
if (!this.html && !this.refs && isDefinitionLine(line)) this.refs = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.pending = !this.fence && !this.html && this.size >= this.target && isBlank(line);
|
|
110
|
+
}
|
|
111
|
+
/** A chunk starts at the next line. */
|
|
112
|
+
startChunk() {
|
|
113
|
+
this.size = 0;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/** Below this, a streaming reply parses whole. */
|
|
117
|
+
const STREAMING_THRESHOLD = 1200;
|
|
118
|
+
/** While a reply streams, every block boundary is a chunk boundary. */
|
|
119
|
+
const STREAMING_TARGET = 0;
|
|
120
|
+
/** The language a fence's info string names, as the parsed block's class does (`plaintext` for none). */
|
|
121
|
+
function fenceLanguage(info) {
|
|
122
|
+
return /^(\w+)/.exec(info.trim().split(/\s/)[0] ?? "")?.[1] ?? "plaintext";
|
|
123
|
+
}
|
|
124
|
+
export { BlockScanner, STREAMING_TARGET, STREAMING_THRESHOLD, fenceLanguage, isDefinitionLine, opensChunk, withoutCR };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A streaming reply's chunks, kept up to date as text arrives instead of split
|
|
3
|
+
* again from the start on every frame.
|
|
4
|
+
*
|
|
5
|
+
* `splitMarkdown` reads the whole reply, and so did the partial-fence and
|
|
6
|
+
* partial-emphasis trims (their patterns anchor at the end, but scan the whole
|
|
7
|
+
* string to get there) and the open-fence read of the last chunk: O(L) per
|
|
8
|
+
* frame, O(L²) over a reply. A {@link MarkdownStream} keeps the scan's state
|
|
9
|
+
* (the open fence or HTML block, the closed chunks, the line not yet whole) and
|
|
10
|
+
* reads only the characters that arrived since the last frame, plus the line
|
|
11
|
+
* still arriving. Closed chunks keep their string from frame to frame, so a
|
|
12
|
+
* memoised render compares them by identity.
|
|
13
|
+
*
|
|
14
|
+
* The chunks it gives once the text is final are exactly `splitMarkdown(text,
|
|
15
|
+
* { streaming: true })`. Internal to the chat area.
|
|
16
|
+
*/
|
|
17
|
+
import { OpenFence } from "./markdown-chunks.js";
|
|
18
|
+
/** One frame of a reply. */
|
|
19
|
+
export interface MarkdownFrame {
|
|
20
|
+
/** The chunks that can no longer change. The same array until one more closes. */
|
|
21
|
+
closed: readonly string[];
|
|
22
|
+
/** The rest, held back as the trims hold it while streaming. May be empty. */
|
|
23
|
+
tail: string;
|
|
24
|
+
/** The fence the tail ends inside, while streaming (as `openFenceOf` reads it). */
|
|
25
|
+
fence: OpenFence | null;
|
|
26
|
+
}
|
|
27
|
+
/** What the stream read: deterministic counts for the tests and benches. */
|
|
28
|
+
export interface MarkdownStreamStats {
|
|
29
|
+
/** Characters read by the scan: new characters, each whole line once, and the line still arriving on each frame. */
|
|
30
|
+
scanned: number;
|
|
31
|
+
/** Frames asked for. */
|
|
32
|
+
frames: number;
|
|
33
|
+
/** Texts that did not extend the last one, so the scan started over. */
|
|
34
|
+
restarts: number;
|
|
35
|
+
}
|
|
36
|
+
/** One reply's chunks, read incrementally. Feed it the reply on each frame. */
|
|
37
|
+
export declare class MarkdownStream {
|
|
38
|
+
private text;
|
|
39
|
+
/** Where the line not yet whole starts. */
|
|
40
|
+
private lineStart;
|
|
41
|
+
/** Where the search for the next newline resumes. */
|
|
42
|
+
private searched;
|
|
43
|
+
private scanner;
|
|
44
|
+
private starts;
|
|
45
|
+
private chunks;
|
|
46
|
+
private view;
|
|
47
|
+
/** Whether a chunk starts at the line not yet whole is already decided. */
|
|
48
|
+
private decided;
|
|
49
|
+
readonly stats: MarkdownStreamStats;
|
|
50
|
+
/**
|
|
51
|
+
* The reply's chunks as of `text`.
|
|
52
|
+
*
|
|
53
|
+
* @param text - The whole reply so far. Usually the last one with more at its end; anything else starts the scan over.
|
|
54
|
+
* @param streaming - Still streaming: trim what is still arriving, and read the open fence.
|
|
55
|
+
*/
|
|
56
|
+
frame(text: string, streaming: boolean): MarkdownFrame;
|
|
57
|
+
/** The fence open at the end of the tail, `last` being its trimmed last line. */
|
|
58
|
+
private openFence;
|
|
59
|
+
private wholeLine;
|
|
60
|
+
/** A chunk starts at `at` (a line start): the one before closes, without the newline between them. */
|
|
61
|
+
private cut;
|
|
62
|
+
private closedView;
|
|
63
|
+
private restart;
|
|
64
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { BlockScanner, fenceLanguage, isDefinitionLine, opensChunk, withoutCR } from "./markdown-scan.js";
|
|
2
|
+
import { isFenceClose, parseFenceOpen } from "zidane/chat/pure";
|
|
3
|
+
// src/chat/headless/markdown-stream.ts
|
|
4
|
+
/** A last line of one or two backticks or tildes: a fence still arriving (`withoutPartialFence`). */
|
|
5
|
+
const PARTIAL_FENCE_LINE = /^ {0,3}(?:`{1,2}|~{1,2})$/;
|
|
6
|
+
/** A last line of emphasis markers with nothing after them (`withoutPartialEmphasis`). */
|
|
7
|
+
const PARTIAL_EMPHASIS_LINE = /^( {0,3}(?:[*+-]|\d{1,9}[.)]) +)?(?:\*{1,3}|_{1,3})$/;
|
|
8
|
+
const NONE = [];
|
|
9
|
+
/**
|
|
10
|
+
* A copy of `text` that holds nothing of the string it was cut from. A slice
|
|
11
|
+
* keeps its source alive, and the source here is the whole reply as of one
|
|
12
|
+
* frame: a closed chunk, held for the reply's life (and by the parse cache),
|
|
13
|
+
* would hold a frame's reply each. Slicing a concatenation flattens it into a
|
|
14
|
+
* string of its own first.
|
|
15
|
+
*/
|
|
16
|
+
function detach(text) {
|
|
17
|
+
return text.length < 13 ? text : `${text} `.slice(0, -1);
|
|
18
|
+
}
|
|
19
|
+
/** One reply's chunks, read incrementally. Feed it the reply on each frame. */
|
|
20
|
+
var MarkdownStream = class {
|
|
21
|
+
text = "";
|
|
22
|
+
/** Where the line not yet whole starts. */
|
|
23
|
+
lineStart = 0;
|
|
24
|
+
/** Where the search for the next newline resumes. */
|
|
25
|
+
searched = 0;
|
|
26
|
+
scanner = new BlockScanner(0);
|
|
27
|
+
starts = [0];
|
|
28
|
+
chunks = [];
|
|
29
|
+
view = NONE;
|
|
30
|
+
/** Whether a chunk starts at the line not yet whole is already decided. */
|
|
31
|
+
decided = false;
|
|
32
|
+
stats = {
|
|
33
|
+
scanned: 0,
|
|
34
|
+
frames: 0,
|
|
35
|
+
restarts: 0
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The reply's chunks as of `text`.
|
|
39
|
+
*
|
|
40
|
+
* @param text - The whole reply so far. Usually the last one with more at its end; anything else starts the scan over.
|
|
41
|
+
* @param streaming - Still streaming: trim what is still arriving, and read the open fence.
|
|
42
|
+
*/
|
|
43
|
+
frame(text, streaming) {
|
|
44
|
+
this.stats.frames++;
|
|
45
|
+
if (!text.startsWith(this.text)) this.restart();
|
|
46
|
+
this.text = text;
|
|
47
|
+
let from = this.searched;
|
|
48
|
+
for (let nl = text.indexOf("\n", from); nl !== -1; nl = text.indexOf("\n", from)) {
|
|
49
|
+
this.stats.scanned += nl + 1 - from;
|
|
50
|
+
this.wholeLine(text.slice(this.lineStart, nl));
|
|
51
|
+
this.lineStart = nl + 1;
|
|
52
|
+
from = nl + 1;
|
|
53
|
+
}
|
|
54
|
+
this.stats.scanned += text.length - from;
|
|
55
|
+
this.searched = text.length;
|
|
56
|
+
const partial = text.slice(this.lineStart);
|
|
57
|
+
this.stats.scanned += partial.length;
|
|
58
|
+
let cutAt = -1;
|
|
59
|
+
if (this.scanner.pending && !this.decided) {
|
|
60
|
+
const opens = opensChunk(partial, false);
|
|
61
|
+
if (opens !== void 0) {
|
|
62
|
+
this.decided = true;
|
|
63
|
+
if (opens) this.cut(this.lineStart);
|
|
64
|
+
} else if (!streaming && opensChunk(partial, true)) cutAt = this.lineStart;
|
|
65
|
+
}
|
|
66
|
+
const { fence, html } = this.scanner;
|
|
67
|
+
const whole = this.scanner.refs || !fence && !html && isDefinitionLine(partial) || text.length < 1200;
|
|
68
|
+
let closed = NONE;
|
|
69
|
+
let tailStart = 0;
|
|
70
|
+
if (!whole) {
|
|
71
|
+
closed = this.closedView();
|
|
72
|
+
tailStart = this.starts.at(-1);
|
|
73
|
+
if (cutAt >= 0) {
|
|
74
|
+
closed = [...closed, detach(text.slice(tailStart, cutAt - 1))];
|
|
75
|
+
tailStart = cutAt;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!streaming) return {
|
|
79
|
+
closed,
|
|
80
|
+
tail: text.slice(tailStart),
|
|
81
|
+
fence: null
|
|
82
|
+
};
|
|
83
|
+
let last = partial;
|
|
84
|
+
if (this.lineStart > 0 && PARTIAL_FENCE_LINE.test(last)) last = "";
|
|
85
|
+
else if (PARTIAL_EMPHASIS_LINE.test(last)) last = last.replace(PARTIAL_EMPHASIS_LINE, "$1");
|
|
86
|
+
const tail = last === partial ? text.slice(tailStart) : text.slice(tailStart, this.lineStart) + last;
|
|
87
|
+
return {
|
|
88
|
+
closed,
|
|
89
|
+
tail,
|
|
90
|
+
fence: this.openFence(last, tailStart)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** The fence open at the end of the tail, `last` being its trimmed last line. */
|
|
94
|
+
openFence(last, tailStart) {
|
|
95
|
+
const { text, lineStart } = this;
|
|
96
|
+
let open = this.scanner.fence;
|
|
97
|
+
let at = this.scanner.fenceAt;
|
|
98
|
+
let end = this.scanner.fenceEnd;
|
|
99
|
+
if (open) {
|
|
100
|
+
if (isFenceClose(withoutCR(last), open.char, open.length)) open = null;
|
|
101
|
+
} else if (!this.scanner.html) {
|
|
102
|
+
open = parseFenceOpen(withoutCR(last));
|
|
103
|
+
at = lineStart;
|
|
104
|
+
end = -1;
|
|
105
|
+
}
|
|
106
|
+
if (!open || open.indent !== 0) return null;
|
|
107
|
+
const opener = end < 0 ? last : text.slice(at, end);
|
|
108
|
+
const body = end < 0 ? "" : text.slice(end + 1, lineStart) + last;
|
|
109
|
+
return {
|
|
110
|
+
before: at > tailStart ? text.slice(tailStart, at - 1) : "",
|
|
111
|
+
language: fenceLanguage(opener.slice(open.length)),
|
|
112
|
+
code: body.endsWith("\n") ? body.slice(0, -1) : body
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
wholeLine(line) {
|
|
116
|
+
const at = this.lineStart;
|
|
117
|
+
if (this.scanner.pending && !this.decided && opensChunk(line, true)) this.cut(at);
|
|
118
|
+
this.decided = false;
|
|
119
|
+
this.scanner.feed(line, at);
|
|
120
|
+
this.stats.scanned += line.length;
|
|
121
|
+
}
|
|
122
|
+
/** A chunk starts at `at` (a line start): the one before closes, without the newline between them. */
|
|
123
|
+
cut(at) {
|
|
124
|
+
this.chunks.push(detach(this.text.slice(this.starts.at(-1), at - 1)));
|
|
125
|
+
this.starts.push(at);
|
|
126
|
+
this.scanner.startChunk();
|
|
127
|
+
}
|
|
128
|
+
closedView() {
|
|
129
|
+
if (this.view.length !== this.chunks.length) this.view = this.chunks.slice();
|
|
130
|
+
return this.view;
|
|
131
|
+
}
|
|
132
|
+
restart() {
|
|
133
|
+
this.stats.restarts++;
|
|
134
|
+
this.lineStart = 0;
|
|
135
|
+
this.searched = 0;
|
|
136
|
+
this.scanner = new BlockScanner(0);
|
|
137
|
+
this.starts = [0];
|
|
138
|
+
this.chunks = [];
|
|
139
|
+
this.view = NONE;
|
|
140
|
+
this.decided = false;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
export { MarkdownStream };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paging through a tool result the host clipped for the wire: a pure model
|
|
3
|
+
* of what is loaded (the text from the start, the whole length), read one
|
|
4
|
+
* range at a time through the host (`ChatHost.toolOutputRange`). "Load full
|
|
5
|
+
* output" reads the first page, "Load more" the next one, "Load all" the
|
|
6
|
+
* rest, a few pages at a time and appended in order. Sizes and offsets are
|
|
7
|
+
* UTF-16 code units, as `ToolResultSlice` counts them.
|
|
8
|
+
*/
|
|
9
|
+
import { Readable } from "./store.js";
|
|
10
|
+
import { ToolResultSlice } from "zidane/chat";
|
|
11
|
+
/** UTF-16 code units in one page of a clipped tool result: what "Load full output" and "Load more" each read. */
|
|
12
|
+
export declare const TOOL_OUTPUT_PAGE_SIZE = 65536;
|
|
13
|
+
/** A range of a tool result's text, in UTF-16 code units. */
|
|
14
|
+
export interface ToolOutputRange {
|
|
15
|
+
/** Where the range starts. */
|
|
16
|
+
offset: number;
|
|
17
|
+
/** How many code units it covers. */
|
|
18
|
+
length: number;
|
|
19
|
+
}
|
|
20
|
+
/** Reads one range of a call's result: `null` when the host holds no result for the call. */
|
|
21
|
+
export type ToolOutputRangeReader = (range: ToolOutputRange) => Promise<ToolResultSlice | null>;
|
|
22
|
+
/** What a {@link ToolOutputPager} has loaded. */
|
|
23
|
+
export interface ToolOutputPagerState {
|
|
24
|
+
/** The text loaded so far, from the start of the result. */
|
|
25
|
+
text: string;
|
|
26
|
+
/** The whole result's length; `null` until the first page answered. */
|
|
27
|
+
total: number | null;
|
|
28
|
+
/** The host holds no result for the call: the clipped preview stays. */
|
|
29
|
+
missing: boolean;
|
|
30
|
+
/** A read is in flight. */
|
|
31
|
+
loading: boolean;
|
|
32
|
+
/** The last read's failure, raw (the UI words it through labels); `null` when it succeeded. */
|
|
33
|
+
error: string | null;
|
|
34
|
+
}
|
|
35
|
+
/** A clipped result's pages, loaded on demand. */
|
|
36
|
+
export interface ToolOutputPager extends Readable<ToolOutputPagerState> {
|
|
37
|
+
/** Reads the next page (the first one on the first call). No-op while a read runs or once all is loaded. */
|
|
38
|
+
loadMore: () => Promise<void>;
|
|
39
|
+
/** Reads every page still missing, appended in order. No-op while a read runs or once all is loaded. */
|
|
40
|
+
loadAll: () => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/** Options of {@link createToolOutputPager}. */
|
|
43
|
+
export interface ToolOutputPagerOptions {
|
|
44
|
+
/** Code units per page. Default {@link TOOL_OUTPUT_PAGE_SIZE}. */
|
|
45
|
+
pageSize?: number;
|
|
46
|
+
/** Pages "Load all" reads at once. Default 4. */
|
|
47
|
+
parallel?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether every page of the result is loaded.
|
|
51
|
+
*
|
|
52
|
+
* @param state - The pager's state.
|
|
53
|
+
*/
|
|
54
|
+
export declare function toolOutputPagerDone(state: ToolOutputPagerState): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* A range of a whole text, as a host that holds the text whole answers it (a server too old for ranges).
|
|
57
|
+
*
|
|
58
|
+
* @param text - The whole result.
|
|
59
|
+
* @param range - The range asked.
|
|
60
|
+
*/
|
|
61
|
+
export declare function sliceToolOutput(text: string, range: ToolOutputRange): ToolResultSlice;
|
|
62
|
+
/**
|
|
63
|
+
* A pager over one call's result.
|
|
64
|
+
*
|
|
65
|
+
* @param read - Reads a range of the result (the host's `toolOutputRange`, bound to the call).
|
|
66
|
+
* @param options - Page size and how many pages "Load all" reads at once.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createToolOutputPager(read: ToolOutputRangeReader, options?: ToolOutputPagerOptions): ToolOutputPager;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { writable } from "./store.js";
|
|
2
|
+
// src/chat/headless/output-pager.ts
|
|
3
|
+
/** UTF-16 code units in one page of a clipped tool result: what "Load full output" and "Load more" each read. */
|
|
4
|
+
const TOOL_OUTPUT_PAGE_SIZE = 65536;
|
|
5
|
+
/** Pages "Load all" reads at once. */
|
|
6
|
+
const PARALLEL_PAGES = 4;
|
|
7
|
+
/**
|
|
8
|
+
* Whether every page of the result is loaded.
|
|
9
|
+
*
|
|
10
|
+
* @param state - The pager's state.
|
|
11
|
+
*/
|
|
12
|
+
function toolOutputPagerDone(state) {
|
|
13
|
+
return state.missing || state.total !== null && state.text.length >= state.total;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A range of a whole text, as a host that holds the text whole answers it (a server too old for ranges).
|
|
17
|
+
*
|
|
18
|
+
* @param text - The whole result.
|
|
19
|
+
* @param range - The range asked.
|
|
20
|
+
*/
|
|
21
|
+
function sliceToolOutput(text, range) {
|
|
22
|
+
const offset = Math.min(Math.max(0, Math.floor(range.offset)), text.length);
|
|
23
|
+
return {
|
|
24
|
+
text: text.slice(offset, offset + Math.max(0, Math.floor(range.length))),
|
|
25
|
+
offset,
|
|
26
|
+
total: text.length
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const INITIAL = {
|
|
30
|
+
text: "",
|
|
31
|
+
total: null,
|
|
32
|
+
missing: false,
|
|
33
|
+
loading: false,
|
|
34
|
+
error: null
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A pager over one call's result.
|
|
38
|
+
*
|
|
39
|
+
* @param read - Reads a range of the result (the host's `toolOutputRange`, bound to the call).
|
|
40
|
+
* @param options - Page size and how many pages "Load all" reads at once.
|
|
41
|
+
*/
|
|
42
|
+
function createToolOutputPager(read, options = {}) {
|
|
43
|
+
const pageSize = Math.max(1, options.pageSize ?? 65536);
|
|
44
|
+
const parallel = Math.max(1, options.parallel ?? PARALLEL_PAGES);
|
|
45
|
+
const state = writable(INITIAL);
|
|
46
|
+
/** Reads up to `pages` pages from the end of what is loaded. */
|
|
47
|
+
const run = async (pages) => {
|
|
48
|
+
const start = state.get();
|
|
49
|
+
if (start.loading || toolOutputPagerDone(start)) return;
|
|
50
|
+
let { text, total } = start;
|
|
51
|
+
let missing = false;
|
|
52
|
+
let error = null;
|
|
53
|
+
state.set({
|
|
54
|
+
...start,
|
|
55
|
+
loading: true,
|
|
56
|
+
error: null
|
|
57
|
+
});
|
|
58
|
+
let left = pages;
|
|
59
|
+
while (left > 0 && error === null && !missing && (total === null || text.length < total)) {
|
|
60
|
+
const count = total === null ? 1 : Math.min(left, parallel, Math.ceil((total - text.length) / pageSize));
|
|
61
|
+
const from = text.length;
|
|
62
|
+
const reads = await Promise.allSettled(Array.from({ length: count }, (_, i) => read({
|
|
63
|
+
offset: from + i * pageSize,
|
|
64
|
+
length: pageSize
|
|
65
|
+
})));
|
|
66
|
+
left -= count;
|
|
67
|
+
for (const answer of reads) {
|
|
68
|
+
const appended = text.length > from;
|
|
69
|
+
if (answer.status === "rejected") {
|
|
70
|
+
error = answer.reason instanceof Error ? answer.reason.message : String(answer.reason);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
const slice = answer.value;
|
|
74
|
+
if (slice === null) {
|
|
75
|
+
missing = text.length === 0;
|
|
76
|
+
if (!missing) error = `no result past ${text.length}`;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (slice.offset !== text.length) {
|
|
80
|
+
if (!appended) error = `slice at ${slice.offset}, asked ${text.length}`;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (slice.text.length === 0 && slice.offset < slice.total) {
|
|
84
|
+
error = `empty slice at ${slice.offset} of ${slice.total}`;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
text += slice.text;
|
|
88
|
+
total = slice.total;
|
|
89
|
+
}
|
|
90
|
+
if (left > 0) state.set({
|
|
91
|
+
text,
|
|
92
|
+
total,
|
|
93
|
+
missing,
|
|
94
|
+
loading: true,
|
|
95
|
+
error
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
state.set({
|
|
99
|
+
text,
|
|
100
|
+
total: missing ? 0 : total,
|
|
101
|
+
missing,
|
|
102
|
+
loading: false,
|
|
103
|
+
error
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
get: state.get,
|
|
108
|
+
subscribe: state.subscribe,
|
|
109
|
+
loadMore: () => run(1),
|
|
110
|
+
loadAll: () => run(Number.POSITIVE_INFINITY)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export { TOOL_OUTPUT_PAGE_SIZE, createToolOutputPager, sliceToolOutput, toolOutputPagerDone };
|
|
@@ -200,6 +200,15 @@ export declare function dateBucket(at: number, now: number, labels?: {
|
|
|
200
200
|
stoppedByYou: string;
|
|
201
201
|
retry: string;
|
|
202
202
|
retryHint: string;
|
|
203
|
+
retryEnvironmentHint: string;
|
|
204
|
+
environmentRepaired: {
|
|
205
|
+
lost: string;
|
|
206
|
+
unreachable: string;
|
|
207
|
+
};
|
|
208
|
+
retryEnvironmentLostTitle: string;
|
|
209
|
+
retryEnvironmentLostDetail: string;
|
|
210
|
+
retryEnvironmentLostSandboxDetail: string;
|
|
211
|
+
retryEnvironmentLostConfirm: string;
|
|
203
212
|
continueRun: string;
|
|
204
213
|
continueHint: string;
|
|
205
214
|
resetsAt: (time: string) => string;
|
|
@@ -238,6 +247,16 @@ export declare function dateBucket(at: number, now: number, labels?: {
|
|
|
238
247
|
modelVerdictTitle: (approved: boolean, model: string, confidence: string | null) => string;
|
|
239
248
|
loadFullOutput: string;
|
|
240
249
|
loadingFullOutput: string;
|
|
250
|
+
loadMoreOutput: string;
|
|
251
|
+
loadAllOutput: string;
|
|
252
|
+
loadingOutput: string;
|
|
253
|
+
outputLoaded: (loaded: string, total: string) => string;
|
|
254
|
+
outputLoadFailed: string;
|
|
255
|
+
loadFullInput: string;
|
|
256
|
+
loadingFullInput: string;
|
|
257
|
+
loadFullDiff: string;
|
|
258
|
+
loadingFullDiff: string;
|
|
259
|
+
diffNotShown: (hunks: number, size: string) => string;
|
|
241
260
|
showOutput: string;
|
|
242
261
|
inputCaption: string;
|
|
243
262
|
outputCaption: string;
|
|
@@ -641,6 +660,7 @@ export declare function dateBucket(at: number, now: number, labels?: {
|
|
|
641
660
|
selectTurnCopied: string;
|
|
642
661
|
selectTurnNothingToCopy: string;
|
|
643
662
|
selectTurnForkFailed: string;
|
|
663
|
+
promptRail: string;
|
|
644
664
|
copy: string;
|
|
645
665
|
copied: string;
|
|
646
666
|
copyCode: string;
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Subagent events are left out: the parent's own call that spawned them
|
|
9
9
|
* (still running) is what the row says.
|
|
10
|
+
*
|
|
11
|
+
* A window gets the transcript stream only of the sessions it shows or keeps
|
|
12
|
+
* warm (`sessions.subscribe`). For the others, the running tools come from
|
|
13
|
+
* the session's work list (`work:snapshot`, sent to every window), named by
|
|
14
|
+
* the tool alone.
|
|
10
15
|
*/
|
|
11
16
|
import { SidebarLabels } from "./labels.js";
|
|
12
17
|
import { StreamEvent } from "zidane/chat";
|
|
@@ -38,6 +43,15 @@ export type SessionActivitySignal = {
|
|
|
38
43
|
kind: 'stream:retry:cleared';
|
|
39
44
|
sessionId: string;
|
|
40
45
|
source: string;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'work:snapshot';
|
|
48
|
+
sessionId: string;
|
|
49
|
+
items: readonly {
|
|
50
|
+
kind: string;
|
|
51
|
+
id: string;
|
|
52
|
+
label: string;
|
|
53
|
+
childId?: string;
|
|
54
|
+
}[];
|
|
41
55
|
} | {
|
|
42
56
|
kind: 'event';
|
|
43
57
|
sessionId: string;
|
|
@@ -22,6 +22,37 @@ const THINKING = {
|
|
|
22
22
|
phase: "thinking",
|
|
23
23
|
run: true
|
|
24
24
|
};
|
|
25
|
+
/** A tool named by its name alone (a work list item), as the row words it. */
|
|
26
|
+
function toolByName(callId, name) {
|
|
27
|
+
const overview = toolOverview({
|
|
28
|
+
name,
|
|
29
|
+
displayName: displayNameFor(name, {}),
|
|
30
|
+
ok: null
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
callId,
|
|
34
|
+
label: overview.label,
|
|
35
|
+
...overview.title ? { title: overview.title } : {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The running tools as the session's work list has them. A tool the stream
|
|
40
|
+
* already named keeps its words (they read its input); a new one is named by
|
|
41
|
+
* the tool alone. Background tasks and subagents' calls are left out.
|
|
42
|
+
*/
|
|
43
|
+
function reduceWorkSnapshot(prev, items) {
|
|
44
|
+
const running = items.filter((item) => item.kind === "tool" && item.childId === void 0);
|
|
45
|
+
const before = prev?.tools ?? [];
|
|
46
|
+
if (running.length === before.length && running.every((item, i) => before[i].callId === item.id)) return prev;
|
|
47
|
+
if (!prev && running.length === 0) return prev;
|
|
48
|
+
const tools = running.map((item) => before.find((t) => t.callId === item.id) ?? toolByName(item.id, item.label));
|
|
49
|
+
const phase = prev?.phase === "compacting" || prev?.phase === "retrying" ? prev.phase : "thinking";
|
|
50
|
+
return {
|
|
51
|
+
tools,
|
|
52
|
+
phase: tools.length === 0 && prev ? prev.phase : phase,
|
|
53
|
+
run: prev?.run ?? true
|
|
54
|
+
};
|
|
55
|
+
}
|
|
25
56
|
/**
|
|
26
57
|
* The next activity after `signal`; the same object when nothing a row shows changed, `null` once the run ended.
|
|
27
58
|
*
|
|
@@ -52,6 +83,7 @@ function reduceActivity(prev, signal) {
|
|
|
52
83
|
...prev,
|
|
53
84
|
phase: "thinking"
|
|
54
85
|
} : prev;
|
|
86
|
+
case "work:snapshot": return reduceWorkSnapshot(prev, signal.items);
|
|
55
87
|
case "event": {
|
|
56
88
|
const event = signal.event;
|
|
57
89
|
if (event.childId) return prev;
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* switch drops every stream, unless the runtime comes back as the same
|
|
20
20
|
* process. After a reconnect (runtime or the open session's server), the
|
|
21
21
|
* windows on screen climb the reconnect ladder (`streams.resync`).
|
|
22
|
-
* - Prewarm: the transcripts around the open session load in idle time
|
|
22
|
+
* - Prewarm: the transcripts around the open session load in idle time,
|
|
23
|
+
* when the open session or the order around it changes (`prewarm.ts`).
|
|
23
24
|
* - Spaces: the shown space (kept by the views store), the slide direction of
|
|
24
25
|
* the last switch, following the open session to its space, and reopening
|
|
25
26
|
* the conversation last open in a space when switching back to it.
|
|
@@ -43,7 +44,7 @@ import { SessionNotificationStore } from "./notifications.js";
|
|
|
43
44
|
import { SidebarContributions, SidebarSpace } from "./query.js";
|
|
44
45
|
import { SessionActivityFilter, SessionArchiveFilter, SidebarListSession } from "./types.js";
|
|
45
46
|
import { SidebarViewDefaults, SidebarViews } from "./view.js";
|
|
46
|
-
import { SessionInboxPatch } from "zidane/chat/pure";
|
|
47
|
+
import { SessionInboxPatch, Space } from "zidane/chat/pure";
|
|
47
48
|
/** A project as one space lists it: its path (`projectPathOf`), the host it is on, the space. */
|
|
48
49
|
export interface ProjectInSpace {
|
|
49
50
|
/** The project's folder (`projectPathOf`). */
|
|
@@ -126,6 +127,8 @@ export interface SessionDirectoryStreams<K extends string, P> {
|
|
|
126
127
|
resync: (sessionId: K) => void;
|
|
127
128
|
/** Drop every cached transcript except these. */
|
|
128
129
|
evictExcept: (keep: ReadonlySet<K>) => void;
|
|
130
|
+
/** About how many bytes the session's cached rows hold: prewarm keeps its window within a byte budget. */
|
|
131
|
+
eventBytes?: (sessionId: K) => number;
|
|
129
132
|
/** Drop every stream (a runtime switch). */
|
|
130
133
|
dropAll: () => void;
|
|
131
134
|
/** Drop one session's stream (deleted). */
|
|
@@ -164,6 +167,11 @@ export interface DirectorySettings {
|
|
|
164
167
|
orchestration: boolean;
|
|
165
168
|
/** The Sidebar settings: what a space follows until it picks its own (`sidebarViewDefaults`). Absent: the built-in defaults. */
|
|
166
169
|
sidebar?: SidebarViewDefaults;
|
|
170
|
+
/**
|
|
171
|
+
* The list is a home server's (`Settings.spacesHome`): the switcher's order and hidden spaces are the
|
|
172
|
+
* list's own, saved with it (`saveSpaceList`), so every device shows the same switcher.
|
|
173
|
+
*/
|
|
174
|
+
spacesShared?: boolean;
|
|
167
175
|
}
|
|
168
176
|
/** Options of {@link createSessionDirectory}: the ports it reads and acts through. */
|
|
169
177
|
export interface SessionDirectoryOptions<S extends SidebarListSession, P, C = unknown> {
|
|
@@ -215,6 +223,11 @@ export interface SessionDirectoryOptions<S extends SidebarListSession, P, C = un
|
|
|
215
223
|
pinned?: () => Iterable<S['id']>;
|
|
216
224
|
/** A window that only ever shows this session (its other sessions are never opened). */
|
|
217
225
|
pinnedSession?: S['id'] | null;
|
|
226
|
+
/** Prewarm's settle delay and byte budget (`prewarm.ts`). */
|
|
227
|
+
prewarm?: {
|
|
228
|
+
delayMs?: number;
|
|
229
|
+
maxBytes?: number;
|
|
230
|
+
};
|
|
218
231
|
/** Schedules prewarm reads; defaults to `requestIdleCallback` with a timer fallback. */
|
|
219
232
|
idle?: {
|
|
220
233
|
request: (run: () => void) => number;
|
|
@@ -233,6 +246,8 @@ export interface SessionDirectoryOptions<S extends SidebarListSession, P, C = un
|
|
|
233
246
|
contributions?: Readable<SidebarContributions>;
|
|
234
247
|
/** Adds a space to the user's list (the settings' `spaceList`). Absent: a view can't be saved as a space. */
|
|
235
248
|
saveSpace?: (space: SidebarSpace) => Promise<void>;
|
|
249
|
+
/** Replaces the user's list (the settings' `spaceList`): the switcher's arrangement while `spacesShared`. */
|
|
250
|
+
saveSpaceList?: (list: Space[]) => Promise<void>;
|
|
236
251
|
}
|
|
237
252
|
/** The directory's state as one snapshot: a new object whenever any field changes. */
|
|
238
253
|
export interface SessionDirectoryState<S extends SidebarListSession> {
|