@zyro-sec/tui 0.0.0-stage → 1.0.2
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/AGENTS.md +6 -0
- package/bunfig.toml +4 -0
- package/package.json +79 -4
- package/src/app.tsx +1632 -0
- package/src/assets/backgrounds/anime.png +0 -0
- package/src/assets/backgrounds/circuit.jpg +0 -0
- package/src/assets/backgrounds/cyber-grid.jpg +0 -0
- package/src/assets/backgrounds/datacenter.jpg +0 -0
- package/src/assets/backgrounds/hacker-desk.jpg +0 -0
- package/src/assets/backgrounds/matrix-code.jpg +0 -0
- package/src/attention-sounds.bun.ts +8 -0
- package/src/attention-sounds.node.ts +16 -0
- package/src/attention.ts +189 -0
- package/src/audio.d.ts +9 -0
- package/src/audio.ts +49 -0
- package/src/clipboard.ts +68 -0
- package/src/component/background-image.tsx +26 -0
- package/src/component/command-palette.tsx +74 -0
- package/src/component/devtools-bar.tsx +611 -0
- package/src/component/dialog-agent.tsx +33 -0
- package/src/component/dialog-background.tsx +102 -0
- package/src/component/dialog-config.tsx +494 -0
- package/src/component/dialog-debug.tsx +90 -0
- package/src/component/dialog-error-details.tsx +130 -0
- package/src/component/dialog-experiments.tsx +101 -0
- package/src/component/dialog-go-upsell.tsx +448 -0
- package/src/component/dialog-highlights.tsx +88 -0
- package/src/component/dialog-image-preview.tsx +85 -0
- package/src/component/dialog-install-mcp.tsx +67 -0
- package/src/component/dialog-integration.tsx +1332 -0
- package/src/component/dialog-mcp.tsx +184 -0
- package/src/component/dialog-model-free.tsx +79 -0
- package/src/component/dialog-model.tsx +238 -0
- package/src/component/dialog-open.tsx +509 -0
- package/src/component/dialog-pair.tsx +123 -0
- package/src/component/dialog-session-list.tsx +328 -0
- package/src/component/dialog-session-rename.tsx +37 -0
- package/src/component/dialog-shell-output.tsx +194 -0
- package/src/component/dialog-skill.tsx +93 -0
- package/src/component/dialog-speed.tsx +48 -0
- package/src/component/dialog-stash.tsx +90 -0
- package/src/component/dialog-status.tsx +50 -0
- package/src/component/dialog-theme-list.tsx +56 -0
- package/src/component/dialog-update.tsx +144 -0
- package/src/component/dialog-variant.tsx +43 -0
- package/src/component/dialog-workspace-file-changes.tsx +187 -0
- package/src/component/dialog-workspaces.tsx +413 -0
- package/src/component/dialog-worktree-name.tsx +40 -0
- package/src/component/error-component.tsx +258 -0
- package/src/component/fade-in-text.tsx +113 -0
- package/src/component/go-upsell-art.ts +338 -0
- package/src/component/logo.tsx +79 -0
- package/src/component/masked-text.ts +59 -0
- package/src/component/media-source.ts +43 -0
- package/src/component/migration-overlay.tsx +73 -0
- package/src/component/model-options.tsx +121 -0
- package/src/component/one-cell-spinner.tsx +75 -0
- package/src/component/panel-host.tsx +64 -0
- package/src/component/patch-diff.tsx +211 -0
- package/src/component/plugin-route-missing.tsx +21 -0
- package/src/component/prompt/autocomplete.tsx +1005 -0
- package/src/component/prompt/draft-stash.ts +47 -0
- package/src/component/prompt/index.tsx +2080 -0
- package/src/component/prompt/local-attachment.ts +188 -0
- package/src/component/prompt/metadata.tsx +193 -0
- package/src/component/prompt/move.tsx +181 -0
- package/src/component/reconnecting.tsx +40 -0
- package/src/component/retry-provider.tsx +202 -0
- package/src/component/session-frame.tsx +408 -0
- package/src/component/session-tabs-rail.tsx +94 -0
- package/src/component/session-tabs.tsx +1789 -0
- package/src/component/shimmer-text.tsx +64 -0
- package/src/component/spinner-frames.ts +1 -0
- package/src/component/spinner-renderable.ts +126 -0
- package/src/component/spinner.tsx +50 -0
- package/src/component/startup-loading.tsx +63 -0
- package/src/component/tab-pulse.tsx +819 -0
- package/src/component/terminal-pane.tsx +377 -0
- package/src/component/theme-error-toast.tsx +20 -0
- package/src/component/title-shimmer.tsx +272 -0
- package/src/component/todo-item.tsx +27 -0
- package/src/component/usage.tsx +329 -0
- package/src/component/use-connected.tsx +14 -0
- package/src/config/index.tsx +438 -0
- package/src/config/keybind.ts +367 -0
- package/src/config/new-session-location.ts +16 -0
- package/src/config/v1/index.tsx +149 -0
- package/src/config/v1/keybind.ts +463 -0
- package/src/context/args.tsx +31 -0
- package/src/context/attention.tsx +23 -0
- package/src/context/client-mcp.tsx +119 -0
- package/src/context/client.tsx +76 -0
- package/src/context/clipboard.tsx +19 -0
- package/src/context/data.tsx +69 -0
- package/src/context/editor.ts +408 -0
- package/src/context/epilogue.tsx +14 -0
- package/src/context/event.ts +32 -0
- package/src/context/exit.tsx +8 -0
- package/src/context/helper.tsx +26 -0
- package/src/context/interactivity.tsx +20 -0
- package/src/context/keymap.tsx +515 -0
- package/src/context/local.tsx +723 -0
- package/src/context/location.tsx +80 -0
- package/src/context/log.tsx +24 -0
- package/src/context/panel.tsx +59 -0
- package/src/context/path-format.tsx +12 -0
- package/src/context/permission.tsx +18 -0
- package/src/context/program-status.ts +94 -0
- package/src/context/prompt.tsx +18 -0
- package/src/context/route.tsx +73 -0
- package/src/context/runtime.tsx +98 -0
- package/src/context/session-tabs-model.ts +263 -0
- package/src/context/session-tabs.tsx +508 -0
- package/src/context/session-terminals.tsx +136 -0
- package/src/context/storage.tsx +150 -0
- package/src/context/theme.tsx +447 -0
- package/src/context/thinking.ts +20 -0
- package/src/context/update-notification.tsx +158 -0
- package/src/devtools/index.ts +41 -0
- package/src/editor-zed-sqlite.bun.ts +1 -0
- package/src/editor-zed-sqlite.node.ts +21 -0
- package/src/editor-zed.ts +277 -0
- package/src/editor.ts +86 -0
- package/src/feature-plugins/home/footer.tsx +116 -0
- package/src/feature-plugins/prompt/btw.tsx +190 -0
- package/src/feature-plugins/prompt/footer.tsx +163 -0
- package/src/feature-plugins/prompt/goal.tsx +211 -0
- package/src/feature-plugins/sidebar/context.tsx +52 -0
- package/src/feature-plugins/sidebar/footer.tsx +126 -0
- package/src/feature-plugins/sidebar/limit.tsx +47 -0
- package/src/feature-plugins/sidebar/mcp.tsx +103 -0
- package/src/feature-plugins/sidebar/todo.tsx +58 -0
- package/src/feature-plugins/system/diff-viewer-file-menu.tsx +87 -0
- package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +174 -0
- package/src/feature-plugins/system/diff-viewer-file-tree.tsx +274 -0
- package/src/feature-plugins/system/diff-viewer-image.tsx +96 -0
- package/src/feature-plugins/system/diff-viewer.tsx +1380 -0
- package/src/feature-plugins/system/notifications.ts +102 -0
- package/src/feature-plugins/system/plugins.tsx +356 -0
- package/src/feature-plugins/system/stats-data.ts +18 -0
- package/src/feature-plugins/system/stats.tsx +217 -0
- package/src/feature-plugins/system/storybook/footer.tsx +51 -0
- package/src/feature-plugins/system/storybook/highlights.tsx +71 -0
- package/src/feature-plugins/system/storybook/index.tsx +153 -0
- package/src/feature-plugins/system/storybook/link-clicks.tsx +125 -0
- package/src/feature-plugins/system/storybook/merman-layouts.tsx +200 -0
- package/src/feature-plugins/system/storybook/one-cell-spinner.fixtures.ts +144 -0
- package/src/feature-plugins/system/storybook/one-cell-spinner.tsx +293 -0
- package/src/feature-plugins/system/storybook/session-location-missing.tsx +80 -0
- package/src/feature-plugins/system/storybook/session-tabs.tsx +571 -0
- package/src/feature-plugins/system/storybook/subcell-spinner.fixtures.ts +115 -0
- package/src/feature-plugins/system/storybook/todo.tsx +166 -0
- package/src/index.tsx +2 -0
- package/src/logo.ts +21 -0
- package/src/mini/catalog.shared.ts +116 -0
- package/src/mini/demo.ts +1086 -0
- package/src/mini/entry.body.ts +244 -0
- package/src/mini/footer.command.tsx +1205 -0
- package/src/mini/footer.form.tsx +647 -0
- package/src/mini/footer.menu.tsx +313 -0
- package/src/mini/footer.permission.tsx +562 -0
- package/src/mini/footer.prompt.tsx +1533 -0
- package/src/mini/footer.subagent.tsx +268 -0
- package/src/mini/footer.ts +1193 -0
- package/src/mini/footer.view.tsx +1022 -0
- package/src/mini/footer.width.ts +118 -0
- package/src/mini/form.shared.ts +241 -0
- package/src/mini/index.ts +7 -0
- package/src/mini/mono.ts +277 -0
- package/src/mini/permission.shared.ts +199 -0
- package/src/mini/prompt.editor.ts +74 -0
- package/src/mini/prompt.shared.ts +192 -0
- package/src/mini/runtime.boot.ts +98 -0
- package/src/mini/runtime.lifecycle.ts +393 -0
- package/src/mini/runtime.queue.ts +320 -0
- package/src/mini/runtime.ts +1117 -0
- package/src/mini/scrollback.shared.ts +82 -0
- package/src/mini/scrollback.surface.ts +548 -0
- package/src/mini/scrollback.writer.tsx +380 -0
- package/src/mini/session-data.ts +13 -0
- package/src/mini/session.shared.ts +113 -0
- package/src/mini/splash.ts +307 -0
- package/src/mini/stream-v2.fragment.ts +83 -0
- package/src/mini/stream-v2.image.ts +38 -0
- package/src/mini/stream-v2.subagent.ts +1130 -0
- package/src/mini/stream-v2.transport.ts +1916 -0
- package/src/mini/stream.ts +152 -0
- package/src/mini/theme.ts +328 -0
- package/src/mini/tool.public.ts +3 -0
- package/src/mini/tool.ts +1394 -0
- package/src/mini/turn-summary.ts +21 -0
- package/src/mini/types.ts +482 -0
- package/src/mini/variant.shared.ts +58 -0
- package/src/mini/verbosity.ts +84 -0
- package/src/model-preference.ts +206 -0
- package/src/parsers-config.ts +386 -0
- package/src/plugin/api.tsx +486 -0
- package/src/plugin/builtins.ts +35 -0
- package/src/plugin/context.tsx +757 -0
- package/src/plugin/discovery.ts +67 -0
- package/src/plugin/markdown.ts +18 -0
- package/src/plugin/render.tsx +116 -0
- package/src/plugin/runtime-plugin-support.bun.ts +11 -0
- package/src/plugin/runtime-plugin-support.node.ts +1 -0
- package/src/plugin/source.ts +1 -0
- package/src/plugin/structure.ts +159 -0
- package/src/plugin/watch.ts +113 -0
- package/src/prompt/attachment.ts +97 -0
- package/src/prompt/codec.ts +61 -0
- package/src/prompt/content.ts +22 -0
- package/src/prompt/directory-completion.ts +97 -0
- package/src/prompt/directory-recents.ts +36 -0
- package/src/prompt/display.ts +41 -0
- package/src/prompt/frecency.tsx +80 -0
- package/src/prompt/history.tsx +175 -0
- package/src/prompt/mention.ts +173 -0
- package/src/prompt/parse.ts +25 -0
- package/src/prompt/part.ts +35 -0
- package/src/prompt/restore.ts +39 -0
- package/src/prompt/stash.tsx +93 -0
- package/src/prompt/traits.ts +29 -0
- package/src/routes/home.tsx +180 -0
- package/src/routes/session/activity-summary.ts +101 -0
- package/src/routes/session/anchor-view.tsx +53 -0
- package/src/routes/session/anchors.ts +85 -0
- package/src/routes/session/composer/context.ts +24 -0
- package/src/routes/session/composer/index.tsx +143 -0
- package/src/routes/session/composer/scripts-tab.tsx +166 -0
- package/src/routes/session/composer/shell-tab.tsx +149 -0
- package/src/routes/session/composer/subagents-tab.tsx +264 -0
- package/src/routes/session/composer/tabs.ts +91 -0
- package/src/routes/session/composer/terminals-tab.tsx +114 -0
- package/src/routes/session/dialog-execute.tsx +276 -0
- package/src/routes/session/dialog-fork.tsx +87 -0
- package/src/routes/session/dialog-message.tsx +89 -0
- package/src/routes/session/dialog-timeline.tsx +43 -0
- package/src/routes/session/form.tsx +1177 -0
- package/src/routes/session/group-view.tsx +407 -0
- package/src/routes/session/grouping/session.ts +184 -0
- package/src/routes/session/grouping/tree.ts +111 -0
- package/src/routes/session/history.ts +59 -0
- package/src/routes/session/index.tsx +3922 -0
- package/src/routes/session/location-missing.tsx +81 -0
- package/src/routes/session/message-navigation.ts +48 -0
- package/src/routes/session/message-parts.tsx +322 -0
- package/src/routes/session/mount-budget.ts +38 -0
- package/src/routes/session/permission.tsx +622 -0
- package/src/routes/session/render-context.tsx +44 -0
- package/src/routes/session/rows.ts +493 -0
- package/src/routes/session/sidebar.tsx +80 -0
- package/src/routes/session/thinking-syntax.ts +8 -0
- package/src/runtime.tsx +1 -0
- package/src/simulation/semantics.ts +12 -0
- package/src/theme/assets/aura.json +69 -0
- package/src/theme/assets/ayu.json +80 -0
- package/src/theme/assets/carbonfox.json +248 -0
- package/src/theme/assets/catppuccin-frappe.json +230 -0
- package/src/theme/assets/catppuccin-macchiato.json +230 -0
- package/src/theme/assets/catppuccin.json +112 -0
- package/src/theme/assets/cobalt2.json +225 -0
- package/src/theme/assets/cursor.json +249 -0
- package/src/theme/assets/dracula.json +219 -0
- package/src/theme/assets/everforest.json +241 -0
- package/src/theme/assets/flexoki.json +237 -0
- package/src/theme/assets/github.json +233 -0
- package/src/theme/assets/gruvbox.json +242 -0
- package/src/theme/assets/kanagawa.json +77 -0
- package/src/theme/assets/lucent-orng.json +234 -0
- package/src/theme/assets/material.json +235 -0
- package/src/theme/assets/matrix.json +77 -0
- package/src/theme/assets/mercury.json +252 -0
- package/src/theme/assets/monokai.json +221 -0
- package/src/theme/assets/nightowl.json +221 -0
- package/src/theme/assets/nord.json +223 -0
- package/src/theme/assets/one-dark.json +84 -0
- package/src/theme/assets/opencode.json +245 -0
- package/src/theme/assets/orng.json +249 -0
- package/src/theme/assets/osaka-jade.json +93 -0
- package/src/theme/assets/palenight.json +222 -0
- package/src/theme/assets/rosepine.json +234 -0
- package/src/theme/assets/solarized.json +223 -0
- package/src/theme/assets/synthwave84.json +226 -0
- package/src/theme/assets/tokyonight.json +243 -0
- package/src/theme/assets/v2/opencode-classic.json +387 -0
- package/src/theme/assets/v2/opencode.json +395 -0
- package/src/theme/assets/vercel.json +245 -0
- package/src/theme/assets/vesper.json +218 -0
- package/src/theme/assets/zenburn.json +223 -0
- package/src/theme/color.ts +48 -0
- package/src/theme/component.ts +51 -0
- package/src/theme/discovery.ts +21 -0
- package/src/theme/index.ts +109 -0
- package/src/theme/resolve.ts +53 -0
- package/src/theme/system.ts +144 -0
- package/src/theme/v1.ts +70 -0
- package/src/ui/animation.ts +235 -0
- package/src/ui/border.ts +21 -0
- package/src/ui/dialog-alert.tsx +51 -0
- package/src/ui/dialog-confirm.tsx +62 -0
- package/src/ui/dialog-export-options.tsx +316 -0
- package/src/ui/dialog-export-result.tsx +84 -0
- package/src/ui/dialog-help.tsx +40 -0
- package/src/ui/dialog-prompt.tsx +180 -0
- package/src/ui/dialog-select.tsx +1006 -0
- package/src/ui/dialog.tsx +560 -0
- package/src/ui/file-path.tsx +112 -0
- package/src/ui/layout.ts +26 -0
- package/src/ui/link.tsx +51 -0
- package/src/ui/one-cell-motion.ts +111 -0
- package/src/ui/pane-resize-handle.tsx +33 -0
- package/src/ui/pane-resize.ts +76 -0
- package/src/ui/select-controller.ts +45 -0
- package/src/ui/session-link.ts +92 -0
- package/src/ui/spinner.ts +368 -0
- package/src/ui/subcell.ts +37 -0
- package/src/ui/toast.tsx +222 -0
- package/src/ui/working-directory-actions.tsx +66 -0
- package/src/util/collapse-tool-output.ts +95 -0
- package/src/util/config-directories.ts +53 -0
- package/src/util/connected-provider.ts +15 -0
- package/src/util/delayed-presence.ts +34 -0
- package/src/util/diff.ts +84 -0
- package/src/util/error-details.ts +21 -0
- package/src/util/error.ts +141 -0
- package/src/util/filetype.ts +135 -0
- package/src/util/form.ts +146 -0
- package/src/util/highlights.ts +51 -0
- package/src/util/locale.ts +81 -0
- package/src/util/marquee.ts +51 -0
- package/src/util/media.ts +43 -0
- package/src/util/model.ts +33 -0
- package/src/util/path-format.ts +37 -0
- package/src/util/path.ts +12 -0
- package/src/util/permission.ts +188 -0
- package/src/util/persistence.ts +42 -0
- package/src/util/presentation.ts +42 -0
- package/src/util/project.ts +7 -0
- package/src/util/record.ts +3 -0
- package/src/util/renderer.ts +15 -0
- package/src/util/scroll.ts +29 -0
- package/src/util/selection.ts +103 -0
- package/src/util/session.ts +103 -0
- package/src/util/signal.ts +49 -0
- package/src/util/single-flight.ts +12 -0
- package/src/util/string-width.bun.ts +1 -0
- package/src/util/string-width.node.ts +26 -0
- package/src/util/string-width.ts +1 -0
- package/src/util/system.ts +23 -0
- package/src/util/todo.ts +43 -0
- package/src/util/tool-display.ts +70 -0
- package/src/util/usage-limits.ts +152 -0
- package/src/util/watch.ts +24 -0
- package/test/app-lifecycle.test.tsx +2962 -0
- package/test/clear-session.test.tsx +67 -0
- package/test/cli/cmd/tui/integration-options.test.ts +98 -0
- package/test/cli/cmd/tui/model-options.test.ts +105 -0
- package/test/cli/cmd/tui/notifications.test.ts +356 -0
- package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +22 -0
- package/test/cli/tui/anchors.test.ts +77 -0
- package/test/cli/tui/collapse-tool-output.test.ts +14 -0
- package/test/cli/tui/command-palette.test.tsx +86 -0
- package/test/cli/tui/composer-keymap.test.tsx +346 -0
- package/test/cli/tui/data.test.tsx +3669 -0
- package/test/cli/tui/dialog-integration.test.tsx +588 -0
- package/test/cli/tui/dialog-mcp.test.tsx +197 -0
- package/test/cli/tui/dialog-open.test.tsx +1037 -0
- package/test/cli/tui/dialog-prompt.test.tsx +253 -0
- package/test/cli/tui/dialog-select.test.tsx +740 -0
- package/test/cli/tui/dialog-session-list.test.tsx +130 -0
- package/test/cli/tui/diff-viewer-file-tree.test.tsx +256 -0
- package/test/cli/tui/diff-viewer-image.test.tsx +172 -0
- package/test/cli/tui/diff-viewer.test.tsx +2510 -0
- package/test/cli/tui/form.test.tsx +950 -0
- package/test/cli/tui/group-boundary.test.ts +63 -0
- package/test/cli/tui/group-view.test.tsx +352 -0
- package/test/cli/tui/grouping-tree.test.ts +82 -0
- package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +248 -0
- package/test/cli/tui/input-scope.test.tsx +282 -0
- package/test/cli/tui/keymap-arguments.test.tsx +45 -0
- package/test/cli/tui/message-navigation.test.ts +164 -0
- package/test/cli/tui/mount-budget.test.ts +74 -0
- package/test/cli/tui/permission.test.ts +7 -0
- package/test/cli/tui/plugins-dialog.test.tsx +217 -0
- package/test/cli/tui/prompt-interrupt-status.test.tsx +25 -0
- package/test/cli/tui/prompt-move.test.tsx +446 -0
- package/test/cli/tui/reasoning-body.test.tsx +80 -0
- package/test/cli/tui/script-changes.test.ts +41 -0
- package/test/cli/tui/session-grouping.test.ts +21 -0
- package/test/cli/tui/session-history.test.ts +124 -0
- package/test/cli/tui/session-rows.test.ts +616 -0
- package/test/cli/tui/session-verbosity.test.ts +307 -0
- package/test/cli/tui/theme-mode.test.tsx +179 -0
- package/test/cli/tui/thinking.test.ts +36 -0
- package/test/cli/tui/toast.test.tsx +117 -0
- package/test/cli/tui/use-event.test.tsx +295 -0
- package/test/client-mcp.test.tsx +226 -0
- package/test/clipboard.test.ts +148 -0
- package/test/command-selection.test.tsx +123 -0
- package/test/compact-admission.test.tsx +251 -0
- package/test/completion-notices.test.tsx +197 -0
- package/test/component/animation-ticks.test.tsx +212 -0
- package/test/component/dialog-error-details.test.tsx +110 -0
- package/test/component/dialog-export-options.test.tsx +68 -0
- package/test/component/dialog-highlights.test.tsx +73 -0
- package/test/component/dialog-model.test.tsx +145 -0
- package/test/component/dialog-shell-output.test.tsx +255 -0
- package/test/component/dialog-speed.test.tsx +114 -0
- package/test/component/dialog-update.test.tsx +111 -0
- package/test/component/dialog-variant.test.tsx +24 -0
- package/test/component/go-upsell-art.test.tsx +110 -0
- package/test/component/retry-provider.test.tsx +288 -0
- package/test/component/session-tabs-marquee.test.tsx +100 -0
- package/test/component/session-tabs-mouse.test.tsx +216 -0
- package/test/component/session-tabs-rail.test.tsx +120 -0
- package/test/component/session-tabs-status.test.tsx +345 -0
- package/test/component/shimmer-text.test.tsx +37 -0
- package/test/component/spinner-renderable.test.tsx +133 -0
- package/test/component/tab-pulse.test.tsx +196 -0
- package/test/component/terminal-pane-theme.test.ts +68 -0
- package/test/config-v2.test.tsx +335 -0
- package/test/config.test.tsx +184 -0
- package/test/context/local-selection.test.tsx +204 -0
- package/test/context/local.test.ts +15 -0
- package/test/context/program-status.test.ts +73 -0
- package/test/context/session-retention.test.ts +234 -0
- package/test/context/session-tabs-model.test.ts +341 -0
- package/test/context/session-tabs.test.tsx +864 -0
- package/test/context/storage.test.ts +37 -0
- package/test/context/theme.test.tsx +183 -0
- package/test/copy-session-id.test.tsx +79 -0
- package/test/editor.test.ts +69 -0
- package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +234 -0
- package/test/feature-plugins/goal.test.tsx +126 -0
- package/test/feature-plugins/home-footer.test.ts +13 -0
- package/test/feature-plugins/prompt-footer.test.tsx +303 -0
- package/test/feature-plugins/sidebar-context.test.tsx +70 -0
- package/test/feature-plugins/sidebar-footer.test.tsx +139 -0
- package/test/fixture/animation-ticks.ts +19 -0
- package/test/fixture/app.ts +95 -0
- package/test/fixture/diff-image.ts +7 -0
- package/test/fixture/fixture.ts +27 -0
- package/test/fixture/frame.ts +25 -0
- package/test/fixture/local.tsx +158 -0
- package/test/fixture/plugin/client-reads/tui.tsx +9 -0
- package/test/fixture/plugin/dialog-throw/tui.tsx +11 -0
- package/test/fixture/plugin/native-resources/tui.tsx +26 -0
- package/test/fixture/plugin/setup-keymap/tui.tsx +72 -0
- package/test/fixture/plugin/slot-string/tui.tsx +10 -0
- package/test/fixture/tui-client.ts +186 -0
- package/test/fixture/tui-environment.tsx +47 -0
- package/test/fixture/tui-runtime.ts +21 -0
- package/test/highlights.test.ts +43 -0
- package/test/interactivity.test.tsx +46 -0
- package/test/keybind.test.ts +7 -0
- package/test/keymap-scope.test.tsx +271 -0
- package/test/keymap.test.tsx +244 -0
- package/test/markdown-streaming.test.tsx +49 -0
- package/test/mini/blocker.responsive.test.tsx +732 -0
- package/test/mini/catalog.shared.test.ts +76 -0
- package/test/mini/entry.body.test.ts +622 -0
- package/test/mini/fixture/catalog.ts +63 -0
- package/test/mini/fixture/footer-api.ts +69 -0
- package/test/mini/fixture/tool-part.ts +20 -0
- package/test/mini/footer-keymap.test.tsx +141 -0
- package/test/mini/footer.menu.test.ts +43 -0
- package/test/mini/footer.responsive.test.tsx +438 -0
- package/test/mini/footer.test.ts +446 -0
- package/test/mini/footer.view.test.tsx +2627 -0
- package/test/mini/footer.width.test.ts +120 -0
- package/test/mini/form.shared.test.ts +66 -0
- package/test/mini/permission.shared.test.ts +195 -0
- package/test/mini/prompt.editor.test.ts +118 -0
- package/test/mini/prompt.shared.test.ts +104 -0
- package/test/mini/runtime.boot.test.ts +118 -0
- package/test/mini/runtime.queue.test.ts +443 -0
- package/test/mini/runtime.test.ts +591 -0
- package/test/mini/scrollback.image.test.ts +213 -0
- package/test/mini/scrollback.surface.test.ts +1078 -0
- package/test/mini/session.shared.test.ts +267 -0
- package/test/mini/splash.test.ts +196 -0
- package/test/mini/stream-v2.transport.test.ts +4705 -0
- package/test/mini/stream.test.ts +52 -0
- package/test/mini/theme.test.ts +438 -0
- package/test/mini/tool.test.ts +134 -0
- package/test/mini/variant.shared.test.ts +58 -0
- package/test/mini/verbosity.test.ts +53 -0
- package/test/model-preference.test.ts +70 -0
- package/test/new-session-id.test.tsx +102 -0
- package/test/new-session-location.test.ts +30 -0
- package/test/panel.test.ts +71 -0
- package/test/plugin-discovery.test.ts +18 -0
- package/test/plugin-keymap.test.tsx +143 -0
- package/test/plugin-markdown.test.tsx +120 -0
- package/test/plugin-model.test.tsx +46 -0
- package/test/plugin-native-resources.test.tsx +11 -0
- package/test/plugin-select.test.tsx +391 -0
- package/test/plugin-slot-output.test.tsx +23 -0
- package/test/plugin-source.test.ts +871 -0
- package/test/plugin-toast.test.tsx +62 -0
- package/test/preload.ts +17 -0
- package/test/prompt/attachment.test.ts +138 -0
- package/test/prompt/autocomplete.test.ts +218 -0
- package/test/prompt/codec.test.ts +136 -0
- package/test/prompt/display.test.ts +72 -0
- package/test/prompt/draft-stash.test.ts +42 -0
- package/test/prompt/history-composer.test.tsx +52 -0
- package/test/prompt/history-provider.test.tsx +108 -0
- package/test/prompt/history.test.ts +94 -0
- package/test/prompt/jsonl.test.ts +24 -0
- package/test/prompt/local-attachment.test.ts +244 -0
- package/test/prompt/mention.test.ts +119 -0
- package/test/prompt/parse.test.ts +46 -0
- package/test/prompt/part.test.ts +40 -0
- package/test/prompt/persistence.test.ts +23 -0
- package/test/prompt/traits.test.ts +25 -0
- package/test/prompt-cursor.test.tsx +27 -0
- package/test/prompt-offset.test.tsx +58 -0
- package/test/prompt-paste.test.tsx +127 -0
- package/test/prompt-shell-failure.test.tsx +76 -0
- package/test/routes/composer-tabs.test.tsx +97 -0
- package/test/runtime.test.tsx +37 -0
- package/test/session-activity-anchor.test.tsx +180 -0
- package/test/session-backfill-disclosure.test.tsx +89 -0
- package/test/session-dialog-resync.test.tsx +122 -0
- package/test/session-fork-pending.test.tsx +60 -0
- package/test/session-group-navigation.test.tsx +252 -0
- package/test/session-history-interactions.test.tsx +305 -0
- package/test/session-history-reveal.test.tsx +108 -0
- package/test/session-home.test.tsx +401 -0
- package/test/session-interrupt-undo.test.tsx +98 -0
- package/test/session-media-refs.test.tsx +360 -0
- package/test/session-mount-budget.test.tsx +137 -0
- package/test/session-panel.test.tsx +721 -0
- package/test/session-shell-output.test.tsx +114 -0
- package/test/session-shell-stopped.test.tsx +107 -0
- package/test/session-subagent-navigation.test.tsx +44 -0
- package/test/session-submit-scroll.test.tsx +85 -0
- package/test/session-terminal-availability.test.tsx +80 -0
- package/test/session-wheel-focus.test.tsx +176 -0
- package/test/simulation/semantics.test.ts +23 -0
- package/test/stats.test.ts +33 -0
- package/test/stats.view.test.tsx +94 -0
- package/test/theme/v2/component.test.ts +87 -0
- package/test/theme/v2/resolve.test.ts +424 -0
- package/test/theme/v2/select.test.ts +25 -0
- package/test/theme/v2/types.typecheck.ts +57 -0
- package/test/theme/v2/v1-migrate.test.ts +397 -0
- package/test/theme.test.ts +150 -0
- package/test/ui/dialog-layout.test.tsx +56 -0
- package/test/ui/file-path.test.ts +61 -0
- package/test/ui/layout.test.ts +31 -0
- package/test/ui/link.test.tsx +60 -0
- package/test/ui/pane-resize-handle.test.tsx +134 -0
- package/test/ui/pane-resize.test.ts +258 -0
- package/test/ui/select-controller.test.ts +44 -0
- package/test/ui/session-link.test.tsx +325 -0
- package/test/usage-limits.test.tsx +162 -0
- package/test/util/added-patch.test.ts +44 -0
- package/test/util/connected-provider.test.ts +59 -0
- package/test/util/delayed-presence.test.ts +114 -0
- package/test/util/error-details.test.ts +26 -0
- package/test/util/error.test.ts +36 -0
- package/test/util/filetype.test.ts +23 -0
- package/test/util/form.test.ts +110 -0
- package/test/util/locale.test.ts +32 -0
- package/test/util/marquee.test.ts +45 -0
- package/test/util/media.test.ts +54 -0
- package/test/util/model.test.ts +70 -0
- package/test/util/path-format.test.ts +15 -0
- package/test/util/permission.test.ts +23 -0
- package/test/util/presentation.test.ts +30 -0
- package/test/util/renderer.test.ts +42 -0
- package/test/util/selection-copy-on-select.test.tsx +64 -0
- package/test/util/selection-keys.test.ts +172 -0
- package/test/util/selection.test.ts +115 -0
- package/test/util/session.test.ts +70 -0
- package/test/util/tool-display.test.ts +65 -0
- package/test/util/usage-limits.test.ts +154 -0
- package/tsconfig.json +13 -0
- package/README.md +0 -3
|
@@ -0,0 +1,3922 @@
|
|
|
1
|
+
import {
|
|
2
|
+
batch,
|
|
3
|
+
createEffect,
|
|
4
|
+
createMemo,
|
|
5
|
+
createSignal,
|
|
6
|
+
For,
|
|
7
|
+
Index,
|
|
8
|
+
Match,
|
|
9
|
+
on,
|
|
10
|
+
onCleanup,
|
|
11
|
+
Show,
|
|
12
|
+
Switch,
|
|
13
|
+
type Accessor,
|
|
14
|
+
} from "solid-js"
|
|
15
|
+
import path from "node:path"
|
|
16
|
+
import { EOL, tmpdir } from "node:os"
|
|
17
|
+
import { mkdir, writeFile } from "node:fs/promises"
|
|
18
|
+
import { useRoute, useRouteData } from "../../context/route"
|
|
19
|
+
import { createStore } from "solid-js/store"
|
|
20
|
+
import { useData } from "../../context/data"
|
|
21
|
+
import { SplitBorder } from "../../ui/border"
|
|
22
|
+
import { useSessionLinks } from "../../ui/session-link"
|
|
23
|
+
import { useTuiPaths, useTuiTerminalEnvironment } from "../../context/runtime"
|
|
24
|
+
import { Spinner, SPINNER_FRAMES } from "../../component/spinner"
|
|
25
|
+
import { PatchDiff } from "../../component/patch-diff"
|
|
26
|
+
import { useTheme, useThemes } from "../../context/theme"
|
|
27
|
+
import {
|
|
28
|
+
BoxRenderable,
|
|
29
|
+
ScrollBoxRenderable,
|
|
30
|
+
addDefaultParsers,
|
|
31
|
+
TextAttributes,
|
|
32
|
+
RGBA,
|
|
33
|
+
MouseEvent,
|
|
34
|
+
} from "@opentui/core"
|
|
35
|
+
import { Prompt, type PromptRef } from "../../component/prompt"
|
|
36
|
+
import {
|
|
37
|
+
mediaHashFromUri,
|
|
38
|
+
type PromptAttachment,
|
|
39
|
+
type SessionMessageInfo,
|
|
40
|
+
type SessionMessageAssistant,
|
|
41
|
+
type SessionMessageAssistantReasoning,
|
|
42
|
+
type SessionMessageAssistantText,
|
|
43
|
+
type SessionMessageAssistantTool,
|
|
44
|
+
type SessionMessageUser,
|
|
45
|
+
type SessionInfo,
|
|
46
|
+
type ModelInfo,
|
|
47
|
+
} from "@zyro-sec/client"
|
|
48
|
+
import { useLocal } from "../../context/local"
|
|
49
|
+
import { Locale } from "../../util/locale"
|
|
50
|
+
import { FilePath } from "../../ui/file-path"
|
|
51
|
+
import {
|
|
52
|
+
canonicalToolName,
|
|
53
|
+
executeCalls,
|
|
54
|
+
executeCallSummary,
|
|
55
|
+
finiteNumber,
|
|
56
|
+
primitiveInputSummary,
|
|
57
|
+
toolDisplayContent,
|
|
58
|
+
toolDisplayMetadata,
|
|
59
|
+
type ExecuteCall,
|
|
60
|
+
} from "../../util/tool-display"
|
|
61
|
+
import { DialogExecute } from "./dialog-execute"
|
|
62
|
+
import { RetryProvider } from "../../component/retry-provider"
|
|
63
|
+
import { useRenderer, useTerminalDimensions, type JSX } from "@opentui/solid"
|
|
64
|
+
import { useClient } from "../../context/client"
|
|
65
|
+
import { useEditorContext } from "../../context/editor"
|
|
66
|
+
import { useDialog } from "../../ui/dialog"
|
|
67
|
+
import { DialogSelect } from "../../ui/dialog-select"
|
|
68
|
+
import { DialogSessionRename } from "../../component/dialog-session-rename"
|
|
69
|
+
import { TodoItem } from "../../component/todo-item"
|
|
70
|
+
import { DialogImagePreview } from "../../component/dialog-image-preview"
|
|
71
|
+
import { createMediaSource } from "../../component/media-source"
|
|
72
|
+
import { statusLabel } from "../../component/dialog-workspace-file-changes"
|
|
73
|
+
import { DialogMessage } from "./dialog-message"
|
|
74
|
+
import { DialogFork } from "./dialog-fork"
|
|
75
|
+
import { DialogTimeline } from "./dialog-timeline"
|
|
76
|
+
import { DialogGoUpsell } from "../../component/dialog-go-upsell"
|
|
77
|
+
import { UsageLimitNotice, useLimitNotice, useUsageAlerts } from "../../component/usage"
|
|
78
|
+
import { useStorage } from "../../context/storage"
|
|
79
|
+
import { Composer } from "./composer"
|
|
80
|
+
import { busyCounts, busyTab } from "./composer/tabs"
|
|
81
|
+
import { filetype } from "../../util/filetype"
|
|
82
|
+
import parsers from "../../parsers-config"
|
|
83
|
+
import { errorMessage } from "../../util/error"
|
|
84
|
+
import { useToast } from "../../ui/toast"
|
|
85
|
+
import stripAnsi from "strip-ansi"
|
|
86
|
+
import { usePromptRef } from "../../context/prompt"
|
|
87
|
+
import { usePromptRestore } from "../../prompt/restore"
|
|
88
|
+
import { appendToSessionPrompt } from "../../component/prompt/draft-stash"
|
|
89
|
+
import type { ProjectedPrompt } from "../../prompt/codec"
|
|
90
|
+
import { deduplicateVisibleImages } from "../../prompt/attachment"
|
|
91
|
+
import { useEpilogue } from "../../context/epilogue"
|
|
92
|
+
import { normalizePath } from "../../util/path"
|
|
93
|
+
import { PermissionPrompt } from "./permission"
|
|
94
|
+
import { FormPrompt } from "./form"
|
|
95
|
+
import { DialogExportOptions } from "../../ui/dialog-export-options"
|
|
96
|
+
import { DialogExportResult } from "../../ui/dialog-export-result"
|
|
97
|
+
import { useConfig, useNewDesigns } from "../../config"
|
|
98
|
+
import { useClipboard } from "../../context/clipboard"
|
|
99
|
+
import { nextThinkingMode, type ThinkingMode } from "../../context/thinking"
|
|
100
|
+
import { getScrollAcceleration } from "../../util/scroll"
|
|
101
|
+
import { collapseShellOutput, collapseToolOutput } from "../../util/collapse-tool-output"
|
|
102
|
+
import { Keymap, type KeymapCommand } from "../../context/keymap"
|
|
103
|
+
import { usePathFormatter } from "../../context/path-format"
|
|
104
|
+
import { useLocation } from "../../context/location"
|
|
105
|
+
import { Slot } from "../../plugin/render"
|
|
106
|
+
import { usePlugin } from "../../plugin/context"
|
|
107
|
+
import {
|
|
108
|
+
cacheReuseDrop,
|
|
109
|
+
completeGroupBoundary,
|
|
110
|
+
createSessionRows,
|
|
111
|
+
messageBoundaryIDs,
|
|
112
|
+
resolvePart,
|
|
113
|
+
sessionRowID,
|
|
114
|
+
type CacheUsage,
|
|
115
|
+
type PartRef,
|
|
116
|
+
type SessionRow,
|
|
117
|
+
} from "./rows"
|
|
118
|
+
import { switchLabel } from "../../util/model"
|
|
119
|
+
import { findMessageBoundary, messageNavigationSlack } from "./message-navigation"
|
|
120
|
+
import { stringWidth } from "../../util/string-width"
|
|
121
|
+
import { useArgs } from "../../context/args"
|
|
122
|
+
import { withTimestampedFallback } from "@zyro-sec/util/session-title-fallback"
|
|
123
|
+
import { SessionTurn } from "@zyro-sec/util/session-turn"
|
|
124
|
+
import { TextBoundary } from "@zyro-sec/util/text-boundary"
|
|
125
|
+
import { useSessionTabs, type ScrollAnchor } from "../../context/session-tabs"
|
|
126
|
+
import { createSingleFlight } from "../../util/single-flight"
|
|
127
|
+
import { createDelayedPresence } from "../../util/delayed-presence"
|
|
128
|
+
import { SessionLocationMissing } from "./location-missing"
|
|
129
|
+
import { isRecord } from "../../util/record"
|
|
130
|
+
import { parseTodos } from "../../util/todo"
|
|
131
|
+
import { createHistoryPrepend } from "./history"
|
|
132
|
+
import { context, use, type PendingAction } from "./render-context"
|
|
133
|
+
import { INLINE_TOOL_ICON_WIDTH, InlineToolRow, ReasoningPart, TextPart, toolDisplay } from "./message-parts"
|
|
134
|
+
import { defaultVerbosity, type GroupKind, type SessionEntry } from "./grouping/session"
|
|
135
|
+
import { SessionGroupView } from "./group-view"
|
|
136
|
+
import { useEntryAnchor } from "./anchor-view"
|
|
137
|
+
import { containsAnchor, createTimelineAnchors, groupID } from "./anchors"
|
|
138
|
+
import { rowsAfter, rowsBefore, rowWeight } from "./mount-budget"
|
|
139
|
+
export { InlineToolRow } from "./message-parts"
|
|
140
|
+
export { toolDisplay } from "./message-parts"
|
|
141
|
+
|
|
142
|
+
addDefaultParsers(parsers.parsers)
|
|
143
|
+
|
|
144
|
+
// Exclude temporary bottom space when measuring the real transcript height.
|
|
145
|
+
const NAVIGATION_SLACK_ID = "session-navigation-slack"
|
|
146
|
+
const BACKGROUND_TOOL_HINT_DELAY = 3_000
|
|
147
|
+
|
|
148
|
+
// Budgets count rendered entries (see mount-budget.ts); a collapsed group costs one.
|
|
149
|
+
// The tail comfortably overfills a tall viewport; older rows mount as the reader approaches them.
|
|
150
|
+
const TRANSCRIPT_TAIL_ROWS = 40
|
|
151
|
+
const TRANSCRIPT_BACKFILL_CHUNK = 60
|
|
152
|
+
|
|
153
|
+
export function Session(props: {
|
|
154
|
+
scrollRef?: (scroll: ScrollBoxRenderable | undefined) => void
|
|
155
|
+
verticalTabsWidth: number
|
|
156
|
+
promptMuted?: boolean
|
|
157
|
+
sidebarVisible: boolean
|
|
158
|
+
onToggleSidebar: () => void
|
|
159
|
+
terminals?: boolean
|
|
160
|
+
visibleTerminalID?: string
|
|
161
|
+
onTerminalPicker?: (show: (() => void) | undefined) => void
|
|
162
|
+
width?: number
|
|
163
|
+
}) {
|
|
164
|
+
const epilogue = useEpilogue()
|
|
165
|
+
const clipboard = useClipboard()
|
|
166
|
+
const paths = useTuiPaths()
|
|
167
|
+
const writeExport = async (file: string, content: string) => {
|
|
168
|
+
await mkdir(path.dirname(file), { recursive: true })
|
|
169
|
+
await writeFile(file, content)
|
|
170
|
+
}
|
|
171
|
+
const route = useRouteData("session")
|
|
172
|
+
const sessionID = route.sessionID
|
|
173
|
+
const { navigate } = useRoute()
|
|
174
|
+
const data = useData()
|
|
175
|
+
const local = useLocal()
|
|
176
|
+
const args = useArgs()
|
|
177
|
+
const configState = useConfig()
|
|
178
|
+
const config = configState.data
|
|
179
|
+
const theme = useTheme()
|
|
180
|
+
const promptRef = usePromptRef()
|
|
181
|
+
const session = createMemo(() => data.session.get(route.sessionID))
|
|
182
|
+
const messages = () => data.session.message.list(route.sessionID)
|
|
183
|
+
const messageIndexes = createMemo(() => new Map(messages().map((message, index) => [message.id, index])))
|
|
184
|
+
const legacy = createMemo(() => SessionTurn.legacy(messages()))
|
|
185
|
+
const messagesBeforeRevert = () => {
|
|
186
|
+
const messageID = session()?.revert?.messageID
|
|
187
|
+
if (!messageID) return messages()
|
|
188
|
+
const index = messages().findIndex((message) => message.id === messageID)
|
|
189
|
+
return index === -1 ? messages() : messages().slice(0, index)
|
|
190
|
+
}
|
|
191
|
+
const messagesFromRevert = () => {
|
|
192
|
+
const messageID = session()?.revert?.messageID
|
|
193
|
+
if (!messageID) return []
|
|
194
|
+
const index = messages().findIndex((message) => message.id === messageID)
|
|
195
|
+
return index === -1 ? [] : messages().slice(index)
|
|
196
|
+
}
|
|
197
|
+
const currentLocation = useLocation()
|
|
198
|
+
const location = createMemo(() => session()?.location ?? currentLocation.ref)
|
|
199
|
+
|
|
200
|
+
createEffect(() => currentLocation.set(location()))
|
|
201
|
+
|
|
202
|
+
createEffect(() => {
|
|
203
|
+
const title = Locale.truncate(session()?.title ?? "", 50)
|
|
204
|
+
epilogue.session({ title, sessionID: session()?.id })
|
|
205
|
+
})
|
|
206
|
+
onCleanup(() => epilogue.session())
|
|
207
|
+
const descendantSessionIDs = createMemo(() => {
|
|
208
|
+
if (session()?.parentID) return []
|
|
209
|
+
return data.session.family(route.sessionID).filter((id) => id !== route.sessionID)
|
|
210
|
+
})
|
|
211
|
+
const permissions = createMemo(() => {
|
|
212
|
+
return [route.sessionID, ...descendantSessionIDs()].flatMap(
|
|
213
|
+
(sessionID) => data.session.permission.list(sessionID) ?? [],
|
|
214
|
+
)
|
|
215
|
+
})
|
|
216
|
+
const promptedPermissions = createMemo(() => (local.permission.mode === "autoaccept" ? [] : permissions()))
|
|
217
|
+
const forms = createMemo(() => {
|
|
218
|
+
const global = data.session.form.list("global", location()) ?? []
|
|
219
|
+
if (session()?.parentID) return global
|
|
220
|
+
return [route.sessionID, ...descendantSessionIDs()]
|
|
221
|
+
.flatMap((sessionID) => data.session.form.list(sessionID) ?? [])
|
|
222
|
+
.concat(global)
|
|
223
|
+
})
|
|
224
|
+
const pendingUsers = createMemo(() =>
|
|
225
|
+
data.session.pending.list(route.sessionID).flatMap((item) => (item.type === "user" ? [item] : [])),
|
|
226
|
+
)
|
|
227
|
+
const pendingDeliveries = createMemo(() => new Map(pendingUsers().map((item) => [item.id, item.delivery])))
|
|
228
|
+
const queuedPrompts = createMemo(() =>
|
|
229
|
+
pendingUsers().flatMap((item) =>
|
|
230
|
+
item.delivery === "queue" ? [{ id: item.id, text: item.payload.text, payload: item.payload }] : [],
|
|
231
|
+
),
|
|
232
|
+
)
|
|
233
|
+
const openingTab = () => busyTab(busyCounts({ data, sessionID: route.sessionID, location: location() }))
|
|
234
|
+
const [composer, setComposer] = createStore({
|
|
235
|
+
open: false,
|
|
236
|
+
tab: undefined as string | undefined,
|
|
237
|
+
})
|
|
238
|
+
const composerVisible = createMemo(
|
|
239
|
+
() => promptedPermissions().length === 0 && (composer.open || (!!session()?.parentID && forms().length === 0)),
|
|
240
|
+
)
|
|
241
|
+
props.onTerminalPicker?.(() => setComposer({ open: true, tab: "terminals" }))
|
|
242
|
+
onCleanup(() => props.onTerminalPicker?.(undefined))
|
|
243
|
+
createEffect(() => {
|
|
244
|
+
if (props.promptMuted && composer.open) setComposer("open", false)
|
|
245
|
+
})
|
|
246
|
+
const disabled = createMemo(() => promptedPermissions().length > 0 || forms().length > 0)
|
|
247
|
+
|
|
248
|
+
const renderer = useRenderer()
|
|
249
|
+
const dimensions = useTerminalDimensions()
|
|
250
|
+
const thinkingMode = createMemo<ThinkingMode>(() => config.session?.thinking ?? "hide")
|
|
251
|
+
const showScrollbar = createMemo(() => config.session?.scrollbar ?? false)
|
|
252
|
+
const markdownMode = createMemo(() => config.session?.markdown ?? "rendered")
|
|
253
|
+
const diffWrapMode = createMemo(() => config.diffs?.wrap ?? "word")
|
|
254
|
+
const groupExploration = createMemo(() => config.session?.grouping !== "none")
|
|
255
|
+
const verbosity = createMemo(() => config.session?.verbosity ?? defaultVerbosity)
|
|
256
|
+
// High opens exploration and instruction summaries by default; everything else starts collapsed.
|
|
257
|
+
const groupExpanded = (groupID: string, kind: GroupKind) =>
|
|
258
|
+
sessionTabs.groupExpanded(sessionID, groupID) ??
|
|
259
|
+
(verbosity() === "high" && (kind === "exploration" || kind === "instructions"))
|
|
260
|
+
const groupedKind = (kind: GroupKind) =>
|
|
261
|
+
kind === "reasoning" ? thinkingMode() === "hide" : kind === "exploration" ? groupExploration() : true
|
|
262
|
+
|
|
263
|
+
Keymap.createLayer(() => ({
|
|
264
|
+
priority: 10,
|
|
265
|
+
enabled: () => props.sidebarVisible && dimensions().width - props.verticalTabsWidth <= 120 && !disabled(),
|
|
266
|
+
commands: [{ bind: "escape,ctrl+c", title: "Close sidebar", group: "Session", run: props.onToggleSidebar }],
|
|
267
|
+
}))
|
|
268
|
+
const contentWidth = createMemo(() => (props.width ?? dimensions().width - props.verticalTabsWidth) - 4)
|
|
269
|
+
const models = createMemo(() => data.location.model.list(location()) ?? [])
|
|
270
|
+
|
|
271
|
+
const scrollAcceleration = createMemo(() => getScrollAcceleration(config))
|
|
272
|
+
const toast = useToast()
|
|
273
|
+
const restorePrompt = usePromptRestore()
|
|
274
|
+
const client = useClient()
|
|
275
|
+
const autoApproved = new Set<string>()
|
|
276
|
+
createEffect(() => {
|
|
277
|
+
if (local.permission.mode !== "autoaccept") return
|
|
278
|
+
permissions().forEach((request) => {
|
|
279
|
+
if (autoApproved.has(request.id)) return
|
|
280
|
+
autoApproved.add(request.id)
|
|
281
|
+
void data.session.permission
|
|
282
|
+
.reply({
|
|
283
|
+
sessionID: request.sessionID,
|
|
284
|
+
decision: "once",
|
|
285
|
+
requestID: request.id,
|
|
286
|
+
})
|
|
287
|
+
.catch((error) => {
|
|
288
|
+
autoApproved.delete(request.id)
|
|
289
|
+
toast.error(error)
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
})
|
|
293
|
+
const editor = useEditorContext()
|
|
294
|
+
const [rowsSynced, setRowsSynced] = createSignal(false)
|
|
295
|
+
const rows = createSessionRows(
|
|
296
|
+
() => route.sessionID,
|
|
297
|
+
(id) => {
|
|
298
|
+
if (id === sessionID) setRowsSynced(true)
|
|
299
|
+
},
|
|
300
|
+
// A scroll-triggered history load joins this boundary load instead of publishing its own page.
|
|
301
|
+
() => pinAbove(),
|
|
302
|
+
)
|
|
303
|
+
const boundaries = createMemo(() => messageBoundaryIDs(rows, messages()))
|
|
304
|
+
const anchors = createTimelineAnchors()
|
|
305
|
+
const [navigationMessage, setNavigationMessage] = createSignal<string>()
|
|
306
|
+
const [navigationSlack, setNavigationSlack] = createSignal(0)
|
|
307
|
+
const [firstJump, setFirstJump] = createSignal<() => void>()
|
|
308
|
+
const [synced, setSynced] = createSignal(false)
|
|
309
|
+
const sessionTabs = useSessionTabs()
|
|
310
|
+
const [awayFromBottom, setAwayFromBottom] = createSignal(false)
|
|
311
|
+
const [latestHovered, setLatestHovered] = createSignal(false)
|
|
312
|
+
let ensureAllRowsPending: (() => void)[] | undefined
|
|
313
|
+
createEffect(() => {
|
|
314
|
+
if (!awayFromBottom()) setLatestHovered(false)
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
const clearMessageNavigation = () => {
|
|
318
|
+
ensureAllRowsPending?.splice(0)
|
|
319
|
+
prependHistory.cancel()
|
|
320
|
+
firstJump()?.()
|
|
321
|
+
setFirstJump(undefined)
|
|
322
|
+
setNavigationSlack(0)
|
|
323
|
+
setNavigationMessage(undefined)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
createEffect(
|
|
327
|
+
on(
|
|
328
|
+
() => [dimensions().width, dimensions().height, props.verticalTabsWidth] as const,
|
|
329
|
+
(_, previous) => {
|
|
330
|
+
if (!previous) return
|
|
331
|
+
clearMessageNavigation()
|
|
332
|
+
if (scroll && !scroll.isDestroyed) updateAwayFromBottom()
|
|
333
|
+
},
|
|
334
|
+
),
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
createEffect(
|
|
338
|
+
on([descendantSessionIDs, () => client.connection.status()], ([sessionIDs, status]) => {
|
|
339
|
+
if (status !== "connected") return
|
|
340
|
+
void Promise.allSettled(
|
|
341
|
+
sessionIDs.flatMap((sessionID) => [data.session.permission.sync(sessionID), data.session.form.sync(sessionID)]),
|
|
342
|
+
)
|
|
343
|
+
}),
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
createEffect(() => {
|
|
347
|
+
if (client.connection.status() !== "connected") return
|
|
348
|
+
setSynced(false)
|
|
349
|
+
const sessionID = route.sessionID
|
|
350
|
+
void (async () => {
|
|
351
|
+
await Promise.all([
|
|
352
|
+
data.session.sync(sessionID, { children: true }),
|
|
353
|
+
data.session.permission.sync(sessionID).catch(() => undefined),
|
|
354
|
+
data.session.form.sync(sessionID).catch(() => undefined),
|
|
355
|
+
])
|
|
356
|
+
const info = data.session.get(sessionID)
|
|
357
|
+
if (!info) {
|
|
358
|
+
toast.show({
|
|
359
|
+
message: `Session not found: ${sessionID}`,
|
|
360
|
+
variant: "error",
|
|
361
|
+
duration: 5000,
|
|
362
|
+
})
|
|
363
|
+
sessionTabs.enabled() ? sessionTabs.close(sessionID) : navigate({ type: "home" })
|
|
364
|
+
return
|
|
365
|
+
}
|
|
366
|
+
editor.reconnect(info.location.directory)
|
|
367
|
+
void data.job.sync(data.session.root(sessionID)).catch(() => undefined)
|
|
368
|
+
setSynced(true)
|
|
369
|
+
})().catch((error) => {
|
|
370
|
+
if (route.sessionID !== sessionID) return
|
|
371
|
+
toast.show({
|
|
372
|
+
message: errorMessage(error),
|
|
373
|
+
variant: "error",
|
|
374
|
+
duration: 5000,
|
|
375
|
+
})
|
|
376
|
+
sessionTabs.enabled() ? sessionTabs.close(sessionID) : navigate({ type: "home" })
|
|
377
|
+
})
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
let seeded = false
|
|
381
|
+
let sent = false
|
|
382
|
+
let restored = false
|
|
383
|
+
let scroll: ScrollBoxRenderable
|
|
384
|
+
createEffect(() => {
|
|
385
|
+
if (restored || !synced() || !rowsSynced() || !scroll || scroll.isDestroyed) return
|
|
386
|
+
restored = true
|
|
387
|
+
// Initial synchronization can finish after the reader has already navigated.
|
|
388
|
+
if (!isAwayFromBottom()) restoreScrollPosition()
|
|
389
|
+
})
|
|
390
|
+
let awayTimer: ReturnType<typeof setTimeout> | undefined
|
|
391
|
+
onCleanup(() => {
|
|
392
|
+
if (awayTimer) clearTimeout(awayTimer)
|
|
393
|
+
props.scrollRef?.(undefined)
|
|
394
|
+
prependHistory.cancel()
|
|
395
|
+
firstJump()?.()
|
|
396
|
+
if (!scroll || scroll.isDestroyed) return
|
|
397
|
+
scroll.verticalScrollBar.off("change", updateAwayFromBottom)
|
|
398
|
+
saveScrollAnchor(true)
|
|
399
|
+
})
|
|
400
|
+
const [prompt, setPrompt] = createSignal<PromptRef>()
|
|
401
|
+
const bind = (r: PromptRef | undefined) => {
|
|
402
|
+
setPrompt(r)
|
|
403
|
+
promptRef.set(r)
|
|
404
|
+
if (seeded || !route.prompt || !r) return
|
|
405
|
+
seeded = true
|
|
406
|
+
r.set(route.prompt)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** Runs after the next frame's layout and before it paints, unless the transcript was torn down. */
|
|
410
|
+
const afterLayout = (continuation: () => void) => {
|
|
411
|
+
if (!scroll || scroll.isDestroyed) return
|
|
412
|
+
scroll.afterLayout(() => {
|
|
413
|
+
if (!scroll.isDestroyed) continuation()
|
|
414
|
+
})
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Pin an existing row before publication. Total height also counts streamed output below the
|
|
418
|
+
// reader, which must not move their viewport when it arrives alongside the older rows.
|
|
419
|
+
const pinAbove = () => {
|
|
420
|
+
if (!scroll || scroll.isDestroyed) return
|
|
421
|
+
if (scroll.stickyScroll && scroll.scrollTop >= scroll.scrollHeight - scroll.viewport.height) return
|
|
422
|
+
const node = scroll.getChildren().find((node) => node.height > 0 && node.y + node.height > scroll.viewport.y)
|
|
423
|
+
if (node) afterLayout(scroll.anchor(node))
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Tail-first transcript mounting: only the newest rows mount when the session opens. Older rows
|
|
427
|
+
// mount on demand near the top, keeping inactive tabs cheap to tear down. While the reader stays
|
|
428
|
+
// at the bottom the hidden span follows appends; leaving the bottom pins it to preserve the viewport.
|
|
429
|
+
const [hiddenRows, setHiddenRows] = createSignal<number>()
|
|
430
|
+
const [visibleRowsEnd, setVisibleRowsEnd] = createSignal<number>()
|
|
431
|
+
const weights = createMemo(() =>
|
|
432
|
+
rows.map((row) =>
|
|
433
|
+
rowWeight(row, {
|
|
434
|
+
expanded: groupExpanded,
|
|
435
|
+
grouped: groupedKind,
|
|
436
|
+
}),
|
|
437
|
+
),
|
|
438
|
+
)
|
|
439
|
+
const hidden = createMemo(() =>
|
|
440
|
+
Math.min(hiddenRows() ?? Infinity, rowsBefore(weights(), rows.length, TRANSCRIPT_TAIL_ROWS)),
|
|
441
|
+
)
|
|
442
|
+
const visibleEnd = createMemo(() => Math.max(hidden(), Math.min(visibleRowsEnd() ?? rows.length, rows.length)))
|
|
443
|
+
const visibleRows = createMemo(() => rows.slice(hidden(), visibleEnd()))
|
|
444
|
+
const prependHistory = createHistoryPrepend({
|
|
445
|
+
sessionID: () => route.sessionID,
|
|
446
|
+
more: (id) => data.session.message.more(id),
|
|
447
|
+
loadMore: async (id) => {
|
|
448
|
+
const beforePublish = () => {
|
|
449
|
+
if (route.sessionID === id) pinAbove()
|
|
450
|
+
}
|
|
451
|
+
await data.session.message.loadMore(id, { beforePublish })
|
|
452
|
+
await completeGroupBoundary({
|
|
453
|
+
rows,
|
|
454
|
+
messages: () => data.session.message.list(id).length,
|
|
455
|
+
more: () => data.session.message.more(id),
|
|
456
|
+
loadMore: () => data.session.message.loadMore(id, { beforePublish }),
|
|
457
|
+
active: () => route.sessionID === id,
|
|
458
|
+
})
|
|
459
|
+
},
|
|
460
|
+
afterLayout,
|
|
461
|
+
active: (id) => route.sessionID === id && Boolean(scroll && !scroll.isDestroyed),
|
|
462
|
+
scrollBy: (amount) => {
|
|
463
|
+
scroll.scrollBy(amount)
|
|
464
|
+
updateAwayFromBottom()
|
|
465
|
+
},
|
|
466
|
+
})
|
|
467
|
+
let revealingOlderRows = false
|
|
468
|
+
const revealOlderRows = (scrollBy = 0) => {
|
|
469
|
+
const current = hidden()
|
|
470
|
+
if (revealingOlderRows || !scroll || scroll.isDestroyed || scroll.scrollTop > scroll.viewport.height) return false
|
|
471
|
+
if (current === 0) return prependHistory(scrollBy)
|
|
472
|
+
revealingOlderRows = true
|
|
473
|
+
scroll.stickyScroll = false
|
|
474
|
+
pinAbove()
|
|
475
|
+
setHiddenRows(rowsBefore(weights(), current, TRANSCRIPT_BACKFILL_CHUNK))
|
|
476
|
+
afterLayout(() => {
|
|
477
|
+
scroll.scrollBy(scrollBy)
|
|
478
|
+
scroll.stickyScroll = !navigationMessage()
|
|
479
|
+
revealingOlderRows = false
|
|
480
|
+
})
|
|
481
|
+
return true
|
|
482
|
+
}
|
|
483
|
+
let revealingNewerRows = false
|
|
484
|
+
const revealNewerRows = (scrollBy = 0) => {
|
|
485
|
+
const current = visibleEnd()
|
|
486
|
+
if (
|
|
487
|
+
revealingNewerRows ||
|
|
488
|
+
current === rows.length ||
|
|
489
|
+
!scroll ||
|
|
490
|
+
scroll.isDestroyed ||
|
|
491
|
+
scroll.scrollTop + scroll.viewport.height < scroll.scrollHeight - scroll.viewport.height
|
|
492
|
+
)
|
|
493
|
+
return false
|
|
494
|
+
revealingNewerRows = true
|
|
495
|
+
const next = rowsAfter(weights(), current, TRANSCRIPT_BACKFILL_CHUNK)
|
|
496
|
+
setVisibleRowsEnd(next === rows.length ? undefined : next)
|
|
497
|
+
afterLayout(() => {
|
|
498
|
+
revealingNewerRows = false
|
|
499
|
+
scroll.scrollBy(scrollBy)
|
|
500
|
+
updateAwayFromBottom()
|
|
501
|
+
})
|
|
502
|
+
return true
|
|
503
|
+
}
|
|
504
|
+
/** Message navigation needs the full transcript mounted before walking or jumping. */
|
|
505
|
+
const ensureAllRows = (continuation: () => void) => {
|
|
506
|
+
if (firstJump()) clearMessageNavigation()
|
|
507
|
+
if (!ensureAllRowsPending && hidden() === 0 && visibleEnd() === rows.length) return continuation()
|
|
508
|
+
if (ensureAllRowsPending) {
|
|
509
|
+
ensureAllRowsPending.push(continuation)
|
|
510
|
+
return
|
|
511
|
+
}
|
|
512
|
+
const pending = [continuation]
|
|
513
|
+
ensureAllRowsPending = pending
|
|
514
|
+
setHiddenRows(0)
|
|
515
|
+
setVisibleRowsEnd(undefined)
|
|
516
|
+
afterLayout(() => {
|
|
517
|
+
if (ensureAllRowsPending === pending) ensureAllRowsPending = undefined
|
|
518
|
+
pending.forEach((continuation) => continuation())
|
|
519
|
+
updateAwayFromBottom()
|
|
520
|
+
})
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function isAwayFromBottom() {
|
|
524
|
+
if (
|
|
525
|
+
revealingOlderRows ||
|
|
526
|
+
revealingNewerRows ||
|
|
527
|
+
ensureAllRowsPending ||
|
|
528
|
+
navigationMessage() ||
|
|
529
|
+
navigationSlack() ||
|
|
530
|
+
firstJump()
|
|
531
|
+
)
|
|
532
|
+
return true
|
|
533
|
+
if (visibleEnd() < rows.length) return true
|
|
534
|
+
return scroll.scrollTop < Math.max(0, scroll.scrollHeight - scroll.viewport.height)
|
|
535
|
+
}
|
|
536
|
+
function updateAwayFromBottom() {
|
|
537
|
+
const preserveWindow = revealingOlderRows || revealingNewerRows || !!ensureAllRowsPending || !!firstJump()
|
|
538
|
+
if (isAwayFromBottom()) setHiddenRows((current) => current ?? hidden())
|
|
539
|
+
if (awayTimer) clearTimeout(awayTimer)
|
|
540
|
+
awayTimer = setTimeout(() => {
|
|
541
|
+
awayTimer = undefined
|
|
542
|
+
if (!scroll || scroll.isDestroyed) return
|
|
543
|
+
const away = preserveWindow || isAwayFromBottom()
|
|
544
|
+
setAwayFromBottom(away)
|
|
545
|
+
if (!away) {
|
|
546
|
+
if (!renderer.getSelection()) setHiddenRows(undefined)
|
|
547
|
+
scroll.stickyScroll = true
|
|
548
|
+
}
|
|
549
|
+
saveScrollAnchor()
|
|
550
|
+
})
|
|
551
|
+
}
|
|
552
|
+
function saveScrollAnchor(unmounting = false) {
|
|
553
|
+
// Initial layout must not overwrite the saved position before synchronization restores it.
|
|
554
|
+
if (!restored) return
|
|
555
|
+
const mounted = anchors.list()
|
|
556
|
+
// Solid disposes child registrations before the route's cleanup. Keep the
|
|
557
|
+
// last scroll-event anchor once those children have gone away.
|
|
558
|
+
if (unmounting && !mounted.length) return
|
|
559
|
+
if (!isAwayFromBottom()) {
|
|
560
|
+
sessionTabs.setScrollAnchor(sessionID, undefined)
|
|
561
|
+
return
|
|
562
|
+
}
|
|
563
|
+
let first: ScrollAnchor | undefined
|
|
564
|
+
let anchor: ScrollAnchor | undefined
|
|
565
|
+
for (const child of mounted) {
|
|
566
|
+
const item = {
|
|
567
|
+
target: child.target,
|
|
568
|
+
screenY: child.node.y - scroll.viewport.y,
|
|
569
|
+
}
|
|
570
|
+
first ??= item
|
|
571
|
+
const inset =
|
|
572
|
+
item.target.type === "group" ||
|
|
573
|
+
data.session.message.get(sessionID, item.target.ref.messageID)?.type === "assistant"
|
|
574
|
+
? 1
|
|
575
|
+
: 0
|
|
576
|
+
if (item.screenY <= inset && (!anchor || item.screenY > anchor.screenY)) anchor = item
|
|
577
|
+
}
|
|
578
|
+
anchor ??= first
|
|
579
|
+
if (anchor) sessionTabs.setScrollAnchor(sessionID, anchor)
|
|
580
|
+
else sessionTabs.setScrollAnchor(sessionID, undefined)
|
|
581
|
+
}
|
|
582
|
+
function restoreScrollPosition() {
|
|
583
|
+
const anchor = sessionTabs.scrollAnchor(sessionID)
|
|
584
|
+
const index = anchor ? rows.findIndex((row) => containsAnchor(row, anchor.target)) : -1
|
|
585
|
+
if (!anchor || index === -1) {
|
|
586
|
+
scroll.scrollTo(scroll.scrollHeight)
|
|
587
|
+
setAwayFromBottom(false)
|
|
588
|
+
return
|
|
589
|
+
}
|
|
590
|
+
setHiddenRows(rowsBefore(weights(), index, TRANSCRIPT_BACKFILL_CHUNK))
|
|
591
|
+
const end = rowsAfter(weights(), index, TRANSCRIPT_BACKFILL_CHUNK)
|
|
592
|
+
setVisibleRowsEnd(end === rows.length ? undefined : end)
|
|
593
|
+
scroll.stickyScroll = false
|
|
594
|
+
const restore = () =>
|
|
595
|
+
afterLayout(() => {
|
|
596
|
+
const boundary = anchors.get(anchor.target)
|
|
597
|
+
if (!boundary) {
|
|
598
|
+
sessionTabs.setScrollAnchor(sessionID, undefined)
|
|
599
|
+
scroll.stickyScroll = true
|
|
600
|
+
scroll.scrollTo(scroll.scrollHeight)
|
|
601
|
+
setAwayFromBottom(false)
|
|
602
|
+
return
|
|
603
|
+
}
|
|
604
|
+
const contentY = scroll.scrollTop + boundary.node.y - scroll.viewport.y
|
|
605
|
+
const target = contentY - anchor.screenY
|
|
606
|
+
const maximum = Math.max(0, scroll.scrollHeight - scroll.viewport.height)
|
|
607
|
+
if (target > maximum && visibleEnd() < rows.length) {
|
|
608
|
+
const next = rowsAfter(weights(), visibleEnd(), TRANSCRIPT_BACKFILL_CHUNK)
|
|
609
|
+
setVisibleRowsEnd(next === rows.length ? undefined : next)
|
|
610
|
+
restore()
|
|
611
|
+
return
|
|
612
|
+
}
|
|
613
|
+
if (target > maximum) {
|
|
614
|
+
setNavigationSlack(
|
|
615
|
+
messageNavigationSlack({
|
|
616
|
+
top: target,
|
|
617
|
+
viewportHeight: scroll.viewport.height,
|
|
618
|
+
scrollHeight: scroll.scrollHeight,
|
|
619
|
+
currentSlack: scroll.getRenderable(NAVIGATION_SLACK_ID)?.height ?? 0,
|
|
620
|
+
}),
|
|
621
|
+
)
|
|
622
|
+
restore()
|
|
623
|
+
return
|
|
624
|
+
}
|
|
625
|
+
scroll.scrollTo(target)
|
|
626
|
+
updateAwayFromBottom()
|
|
627
|
+
})
|
|
628
|
+
restore()
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
createEffect(() => {
|
|
632
|
+
const current = prompt()
|
|
633
|
+
if (sent || !current || !synced() || !local.model.ready || !local.model.catalogReady) return
|
|
634
|
+
if (!local.agent.current() || !local.model.current()) return
|
|
635
|
+
if (!args.prompt || route.prompt?.text !== args.prompt || current.current.text !== args.prompt) return
|
|
636
|
+
sent = true
|
|
637
|
+
current.submit()
|
|
638
|
+
})
|
|
639
|
+
const dialog = useDialog()
|
|
640
|
+
const storage = useStorage()
|
|
641
|
+
const [goUpsell, updateGoUpsell] = storage.store<{ lastSeenAt?: number; dontShow?: boolean }>("go-upsell", {
|
|
642
|
+
initial: {},
|
|
643
|
+
})
|
|
644
|
+
const [goUpsellMemory, updateGoUpsellMemory] = storage.memory<{ lastSeenAt?: number; dontShow?: boolean }>(
|
|
645
|
+
"go-upsell",
|
|
646
|
+
{ initial: {} },
|
|
647
|
+
)
|
|
648
|
+
const handledLimits = new Set<string>()
|
|
649
|
+
useUsageAlerts(() => route.sessionID)
|
|
650
|
+
let sessionDisposed = false
|
|
651
|
+
onCleanup(() => {
|
|
652
|
+
sessionDisposed = true
|
|
653
|
+
})
|
|
654
|
+
// Restore the prompt when the free allowance or an OpenCode Go limit stops it, and offer OpenCode Go on the first free
|
|
655
|
+
// allowance hit in a day.
|
|
656
|
+
onCleanup(
|
|
657
|
+
data.on("session.step.failed", async (event) => {
|
|
658
|
+
const type = event.data.error.type
|
|
659
|
+
if (event.data.sessionID !== route.sessionID) return
|
|
660
|
+
if (type !== "provider.free-limit" && type !== "provider.go-limit") return
|
|
661
|
+
if (handledLimits.has(event.data.assistantMessageID)) return
|
|
662
|
+
handledLimits.add(event.data.assistantMessageID)
|
|
663
|
+
const empty = (ref: PromptRef | undefined): ref is PromptRef =>
|
|
664
|
+
!!ref &&
|
|
665
|
+
!ref.current.text.trim() &&
|
|
666
|
+
!ref.current.files?.length &&
|
|
667
|
+
!ref.current.agents?.length &&
|
|
668
|
+
!ref.current.skills?.length &&
|
|
669
|
+
!ref.current.pasted.length
|
|
670
|
+
if (!empty(prompt())) return
|
|
671
|
+
const list = messages()
|
|
672
|
+
const end = list.findIndex((item) => item.id === event.data.assistantMessageID)
|
|
673
|
+
let recalled: SessionMessageUser | undefined
|
|
674
|
+
for (let i = end - 1; i >= 0 && !recalled; i--) {
|
|
675
|
+
const item = list[i]
|
|
676
|
+
if (!item || item.type === "shell" || item.type === "idle") break
|
|
677
|
+
if (item.type === "user" && !data.session.input.has(route.sessionID, item.id)) recalled = item
|
|
678
|
+
}
|
|
679
|
+
const restored = recalled
|
|
680
|
+
? await restorePrompt(recalled).catch((error) => {
|
|
681
|
+
toast.show({ message: errorMessage(error), variant: "error", duration: 5000 })
|
|
682
|
+
return null
|
|
683
|
+
})
|
|
684
|
+
: undefined
|
|
685
|
+
// Media refs load before the prompt comes back; typing or a shell command meanwhile keeps it and skips the offer.
|
|
686
|
+
if (restored === null || sessionDisposed || route.sessionID !== event.data.sessionID) return
|
|
687
|
+
const current = prompt()
|
|
688
|
+
if (!empty(current) || current.mode !== "normal") return
|
|
689
|
+
if (restored) current.set(restored)
|
|
690
|
+
if (type === "provider.go-limit" || dialog.stack.length > 0) return
|
|
691
|
+
if (goUpsell.dontShow || goUpsellMemory.dontShow) return
|
|
692
|
+
const now = Date.now()
|
|
693
|
+
const seen = Math.max(goUpsell.lastSeenAt ?? 0, goUpsellMemory.lastSeenAt ?? 0)
|
|
694
|
+
if (seen > 0 && now - seen < 86_400_000) return
|
|
695
|
+
const expectedText = current.current.text
|
|
696
|
+
const expectedFiles = current.current.files?.length ?? 0
|
|
697
|
+
const expectedAgents = current.current.agents?.length ?? 0
|
|
698
|
+
const expectedSkills = current.current.skills?.length ?? 0
|
|
699
|
+
const expectedPasted = current.current.pasted.length
|
|
700
|
+
const hasRecalledPrompt = () => {
|
|
701
|
+
const active = prompt()
|
|
702
|
+
return Boolean(
|
|
703
|
+
!sessionDisposed &&
|
|
704
|
+
route.sessionID === event.data.sessionID &&
|
|
705
|
+
active &&
|
|
706
|
+
active.current.text === expectedText &&
|
|
707
|
+
(active.current.files?.length ?? 0) === expectedFiles &&
|
|
708
|
+
(active.current.agents?.length ?? 0) === expectedAgents &&
|
|
709
|
+
(active.current.skills?.length ?? 0) === expectedSkills &&
|
|
710
|
+
active.current.pasted.length === expectedPasted,
|
|
711
|
+
)
|
|
712
|
+
}
|
|
713
|
+
const canOpen = () =>
|
|
714
|
+
Boolean(hasRecalledPrompt() && dialog.stack.length === 0 && !goUpsell.dontShow && !goUpsellMemory.dontShow)
|
|
715
|
+
const previousSeen = goUpsellMemory.lastSeenAt
|
|
716
|
+
updateGoUpsellMemory((draft) => {
|
|
717
|
+
draft.lastSeenAt = now
|
|
718
|
+
})
|
|
719
|
+
let claimed = false
|
|
720
|
+
void updateGoUpsell((draft) => {
|
|
721
|
+
if (draft.dontShow) {
|
|
722
|
+
updateGoUpsellMemory((mem) => {
|
|
723
|
+
mem.dontShow = true
|
|
724
|
+
mem.lastSeenAt = draft.lastSeenAt ?? previousSeen
|
|
725
|
+
})
|
|
726
|
+
return
|
|
727
|
+
}
|
|
728
|
+
if ((draft.lastSeenAt ?? 0) > 0 && now - (draft.lastSeenAt ?? 0) < 86_400_000) {
|
|
729
|
+
updateGoUpsellMemory((mem) => {
|
|
730
|
+
mem.lastSeenAt = draft.lastSeenAt
|
|
731
|
+
})
|
|
732
|
+
return
|
|
733
|
+
}
|
|
734
|
+
if (!canOpen()) {
|
|
735
|
+
updateGoUpsellMemory((mem) => {
|
|
736
|
+
mem.lastSeenAt = previousSeen
|
|
737
|
+
})
|
|
738
|
+
return
|
|
739
|
+
}
|
|
740
|
+
draft.lastSeenAt = now
|
|
741
|
+
claimed = true
|
|
742
|
+
})
|
|
743
|
+
.catch(() => {
|
|
744
|
+
claimed = true
|
|
745
|
+
})
|
|
746
|
+
.then(() => {
|
|
747
|
+
if (!claimed || !canOpen()) return
|
|
748
|
+
dialog.replace(() => (
|
|
749
|
+
<DialogGoUpsell
|
|
750
|
+
reset={freeLimitReset(event.data.error.retryAfterMs, event.created)}
|
|
751
|
+
canContinue={hasRecalledPrompt}
|
|
752
|
+
onDontShowAgain={() => {
|
|
753
|
+
updateGoUpsellMemory((draft) => {
|
|
754
|
+
draft.dontShow = true
|
|
755
|
+
})
|
|
756
|
+
void updateGoUpsell((draft) => {
|
|
757
|
+
draft.dontShow = true
|
|
758
|
+
}).catch(() => undefined)
|
|
759
|
+
}}
|
|
760
|
+
onSubscribe={() => {
|
|
761
|
+
prompt()?.submit()
|
|
762
|
+
}}
|
|
763
|
+
/>
|
|
764
|
+
))
|
|
765
|
+
})
|
|
766
|
+
}),
|
|
767
|
+
)
|
|
768
|
+
const runPendingAction = createSingleFlight<string>()
|
|
769
|
+
// Uses the captured sessionID: after an await, route.sessionID may already name another tab, or none.
|
|
770
|
+
const requestPending = async (action: PendingAction, inboxID: string, failureLabel?: string) => {
|
|
771
|
+
const request =
|
|
772
|
+
action === "steer"
|
|
773
|
+
? client.api.session.inbox.update({ sessionID, inboxID, delivery: "steer" })
|
|
774
|
+
: action === "queue"
|
|
775
|
+
? client.api.session.inbox.update({ sessionID, inboxID, delivery: "queue" })
|
|
776
|
+
: client.api.session.inbox.cancel({ sessionID, inboxID })
|
|
777
|
+
const error = await request.then(
|
|
778
|
+
() => undefined,
|
|
779
|
+
(error) => error,
|
|
780
|
+
)
|
|
781
|
+
if (!error) return true
|
|
782
|
+
const label = failureLabel ?? (action === "cancel" ? "delete" : action)
|
|
783
|
+
toast.show({ title: `Failed to ${label} pending prompt`, message: errorMessage(error), variant: "error" })
|
|
784
|
+
return false
|
|
785
|
+
}
|
|
786
|
+
const mutatePending = async (action: PendingAction, inboxID: string) =>
|
|
787
|
+
(await runPendingAction(inboxID, () => requestPending(action, inboxID))) ?? false
|
|
788
|
+
// The cancel releases blobs nothing else references, so media refs load into the draft first. Resolves with the
|
|
789
|
+
// composer it wrote to, if any, once the prompt is back; undefined if the cancel failed or was already running.
|
|
790
|
+
const undoPending = (inboxID: string, message: ProjectedPrompt, failureLabel?: string) =>
|
|
791
|
+
runPendingAction(inboxID, async () => {
|
|
792
|
+
const restored = await restorePrompt(message)
|
|
793
|
+
if (!(await requestPending("cancel", inboxID, failureLabel))) return
|
|
794
|
+
return { composer: appendToSessionPrompt(sessionID, restored, renderer.widthMethod) }
|
|
795
|
+
})
|
|
796
|
+
const openQueuedPrompts = () =>
|
|
797
|
+
dialog.replace(() => (
|
|
798
|
+
<DialogSelect
|
|
799
|
+
title="Queued prompts"
|
|
800
|
+
searchInTitle
|
|
801
|
+
titlePlaceholder="Search queued prompts"
|
|
802
|
+
options={queuedPrompts().map((prompt, index) => ({
|
|
803
|
+
title: prompt.text,
|
|
804
|
+
value: prompt.id,
|
|
805
|
+
footer: `${index + 1} of ${queuedPrompts().length}`,
|
|
806
|
+
}))}
|
|
807
|
+
onSelect={(option) => {
|
|
808
|
+
void mutatePending("steer", option.value).then((steered) => {
|
|
809
|
+
if (steered) dialog.clear()
|
|
810
|
+
})
|
|
811
|
+
}}
|
|
812
|
+
actions={[
|
|
813
|
+
{
|
|
814
|
+
command: "queued_prompt.delete",
|
|
815
|
+
title: "delete",
|
|
816
|
+
onTrigger: (option) => {
|
|
817
|
+
const last = queuedPrompts().length === 1
|
|
818
|
+
void mutatePending("cancel", option.value).then((cancelled) => {
|
|
819
|
+
if (cancelled && last) dialog.clear()
|
|
820
|
+
})
|
|
821
|
+
},
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
command: "queued_prompt.undo",
|
|
825
|
+
title: "undo",
|
|
826
|
+
onTrigger: (option) => {
|
|
827
|
+
const target = prompt()
|
|
828
|
+
const queued = queuedPrompts().find((item) => item.id === option.value)
|
|
829
|
+
if (!target || !queued) return
|
|
830
|
+
if (target.mode === "shell" && target.current.text) {
|
|
831
|
+
toast.show({ message: "Leave shell mode before undoing a queued prompt", variant: "error" })
|
|
832
|
+
return
|
|
833
|
+
}
|
|
834
|
+
void undoPending(queued.id, queued.payload, "undo")
|
|
835
|
+
.then((undone) => {
|
|
836
|
+
if (!undone || sessionDisposed) return
|
|
837
|
+
dialog.clear()
|
|
838
|
+
undone.composer?.focus()
|
|
839
|
+
})
|
|
840
|
+
.catch((error) =>
|
|
841
|
+
toast.show({
|
|
842
|
+
title: "Failed to undo pending prompt",
|
|
843
|
+
message: errorMessage(error),
|
|
844
|
+
variant: "error",
|
|
845
|
+
}),
|
|
846
|
+
)
|
|
847
|
+
},
|
|
848
|
+
},
|
|
849
|
+
]}
|
|
850
|
+
footerHints={[{ title: "steer", label: "enter", group: "primary" }]}
|
|
851
|
+
/>
|
|
852
|
+
))
|
|
853
|
+
const alignMessage = (messageID: string, top: number) => {
|
|
854
|
+
scroll.stickyScroll = false
|
|
855
|
+
setNavigationMessage(messageID)
|
|
856
|
+
updateAwayFromBottom()
|
|
857
|
+
setNavigationSlack(
|
|
858
|
+
messageNavigationSlack({
|
|
859
|
+
top,
|
|
860
|
+
viewportHeight: scroll.viewport.height,
|
|
861
|
+
scrollHeight: scroll.scrollHeight,
|
|
862
|
+
currentSlack: scroll.getRenderable(NAVIGATION_SLACK_ID)?.height ?? 0,
|
|
863
|
+
}),
|
|
864
|
+
)
|
|
865
|
+
afterLayout(() => {
|
|
866
|
+
if (navigationMessage() !== messageID) return
|
|
867
|
+
scroll.scrollTo(top)
|
|
868
|
+
})
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
const scrollToMessage = (direction: "next" | "prev", dialog: ReturnType<typeof useDialog>, userOnly = false) =>
|
|
872
|
+
ensureAllRows(() => {
|
|
873
|
+
const target = findMessageBoundary({
|
|
874
|
+
direction,
|
|
875
|
+
children: anchors.messagePositions(),
|
|
876
|
+
messages: messages(),
|
|
877
|
+
scrollTop: scroll.scrollTop,
|
|
878
|
+
viewportY: scroll.viewport.y,
|
|
879
|
+
currentID: navigationMessage(),
|
|
880
|
+
userOnly,
|
|
881
|
+
})
|
|
882
|
+
|
|
883
|
+
if (target) {
|
|
884
|
+
jumpToMessage(target.id)
|
|
885
|
+
dialog.clear()
|
|
886
|
+
return
|
|
887
|
+
}
|
|
888
|
+
if (direction === "prev" && data.session.message.more(route.sessionID)) {
|
|
889
|
+
prependHistory(0, () => scrollToMessage(direction, dialog, userOnly))
|
|
890
|
+
return
|
|
891
|
+
}
|
|
892
|
+
dialog.clear()
|
|
893
|
+
})
|
|
894
|
+
|
|
895
|
+
const jumpToMessage = (messageID: string) =>
|
|
896
|
+
ensureAllRows(() => {
|
|
897
|
+
const child = anchors.forMessage(messageID)
|
|
898
|
+
if (!child) return
|
|
899
|
+
const y = scroll.scrollTop + child.node.y - scroll.viewport.y
|
|
900
|
+
const message = data.session.message.get(route.sessionID, messageID)
|
|
901
|
+
alignMessage(messageID, Math.max(0, y - (message?.type === "assistant" ? 1 : 0)))
|
|
902
|
+
})
|
|
903
|
+
|
|
904
|
+
function toBottom() {
|
|
905
|
+
clearMessageNavigation()
|
|
906
|
+
ensureAllRowsPending = undefined
|
|
907
|
+
if (awayTimer) clearTimeout(awayTimer)
|
|
908
|
+
awayTimer = undefined
|
|
909
|
+
setAwayFromBottom(false)
|
|
910
|
+
sessionTabs.setScrollAnchor(route.sessionID, undefined)
|
|
911
|
+
setHiddenRows(undefined)
|
|
912
|
+
setVisibleRowsEnd(undefined)
|
|
913
|
+
setTimeout(() => {
|
|
914
|
+
if (!scroll || scroll.isDestroyed) return
|
|
915
|
+
scroll.stickyScroll = true
|
|
916
|
+
scroll.scrollTo(scroll.scrollHeight)
|
|
917
|
+
}, 50)
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function moveTranscript(delta: number) {
|
|
921
|
+
clearMessageNavigation()
|
|
922
|
+
if (delta < 0 && revealOlderRows(delta)) {
|
|
923
|
+
dialog.clear()
|
|
924
|
+
return
|
|
925
|
+
}
|
|
926
|
+
if (delta > 0 && revealNewerRows(delta)) {
|
|
927
|
+
dialog.clear()
|
|
928
|
+
return
|
|
929
|
+
}
|
|
930
|
+
scroll.scrollBy(delta)
|
|
931
|
+
updateAwayFromBottom()
|
|
932
|
+
dialog.clear()
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const globalCommands = [
|
|
936
|
+
{
|
|
937
|
+
id: "session.page.up",
|
|
938
|
+
title: "Page up",
|
|
939
|
+
group: "Session",
|
|
940
|
+
palette: undefined,
|
|
941
|
+
run: () => moveTranscript(-scroll.height / 2),
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
id: "session.page.down",
|
|
945
|
+
title: "Page down",
|
|
946
|
+
group: "Session",
|
|
947
|
+
palette: undefined,
|
|
948
|
+
run: () => moveTranscript(scroll.height / 2),
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
id: "session.line.up",
|
|
952
|
+
title: "Line up",
|
|
953
|
+
group: "Session",
|
|
954
|
+
palette: undefined,
|
|
955
|
+
run: () => moveTranscript(-1),
|
|
956
|
+
},
|
|
957
|
+
{
|
|
958
|
+
id: "session.line.down",
|
|
959
|
+
title: "Line down",
|
|
960
|
+
group: "Session",
|
|
961
|
+
palette: undefined,
|
|
962
|
+
run: () => moveTranscript(1),
|
|
963
|
+
},
|
|
964
|
+
{
|
|
965
|
+
id: "session.half.page.up",
|
|
966
|
+
title: "Half page up",
|
|
967
|
+
group: "Session",
|
|
968
|
+
palette: undefined,
|
|
969
|
+
run: () => moveTranscript(-scroll.height / 4),
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
id: "session.half.page.down",
|
|
973
|
+
title: "Half page down",
|
|
974
|
+
group: "Session",
|
|
975
|
+
palette: undefined,
|
|
976
|
+
run: () => moveTranscript(scroll.height / 4),
|
|
977
|
+
},
|
|
978
|
+
]
|
|
979
|
+
|
|
980
|
+
const baseAndUnfocusedCommands = [
|
|
981
|
+
{
|
|
982
|
+
id: "session.first",
|
|
983
|
+
title: "First message",
|
|
984
|
+
group: "Session",
|
|
985
|
+
palette: undefined,
|
|
986
|
+
run: () => {
|
|
987
|
+
if (firstJump()) return
|
|
988
|
+
clearMessageNavigation()
|
|
989
|
+
const request = new AbortController()
|
|
990
|
+
const cancel = () => request.abort()
|
|
991
|
+
setFirstJump(() => cancel)
|
|
992
|
+
const start = () => {
|
|
993
|
+
if (firstJump() !== cancel || scroll.isDestroyed) return
|
|
994
|
+
if (revealingOlderRows || revealingNewerRows || ensureAllRowsPending) return afterLayout(start)
|
|
995
|
+
const previous = { start: hiddenRows(), end: visibleRowsEnd() }
|
|
996
|
+
const restore = () => {
|
|
997
|
+
cancel()
|
|
998
|
+
batch(() => {
|
|
999
|
+
setHiddenRows(previous.start)
|
|
1000
|
+
setVisibleRowsEnd(previous.end)
|
|
1001
|
+
})
|
|
1002
|
+
}
|
|
1003
|
+
const commit = () => {
|
|
1004
|
+
if (firstJump() !== restore || scroll.isDestroyed) return
|
|
1005
|
+
scroll.stickyScroll = false
|
|
1006
|
+
batch(() => {
|
|
1007
|
+
setHiddenRows(0)
|
|
1008
|
+
setVisibleRowsEnd(TRANSCRIPT_BACKFILL_CHUNK)
|
|
1009
|
+
setFirstJump(() => cancel)
|
|
1010
|
+
})
|
|
1011
|
+
}
|
|
1012
|
+
// Pin both ends until the head budget commits in the same batch as history.
|
|
1013
|
+
batch(() => {
|
|
1014
|
+
setFirstJump(() => restore)
|
|
1015
|
+
setHiddenRows(hidden())
|
|
1016
|
+
setVisibleRowsEnd(visibleEnd())
|
|
1017
|
+
})
|
|
1018
|
+
void data.session.message
|
|
1019
|
+
.loadMore(route.sessionID, {
|
|
1020
|
+
all: true,
|
|
1021
|
+
signal: request.signal,
|
|
1022
|
+
beforePublish: commit,
|
|
1023
|
+
})
|
|
1024
|
+
.then(
|
|
1025
|
+
() => {
|
|
1026
|
+
commit()
|
|
1027
|
+
if (firstJump() !== cancel || scroll.isDestroyed) return
|
|
1028
|
+
if (rows.length <= TRANSCRIPT_BACKFILL_CHUNK) setVisibleRowsEnd(undefined)
|
|
1029
|
+
scroll.scrollTo(0)
|
|
1030
|
+
afterLayout(() => {
|
|
1031
|
+
if (firstJump() !== cancel) return
|
|
1032
|
+
scroll.scrollTo(0)
|
|
1033
|
+
setFirstJump(undefined)
|
|
1034
|
+
updateAwayFromBottom()
|
|
1035
|
+
})
|
|
1036
|
+
},
|
|
1037
|
+
(error) => {
|
|
1038
|
+
if (firstJump() !== restore || scroll.isDestroyed) return
|
|
1039
|
+
clearMessageNavigation()
|
|
1040
|
+
toast.error(error)
|
|
1041
|
+
updateAwayFromBottom()
|
|
1042
|
+
},
|
|
1043
|
+
)
|
|
1044
|
+
}
|
|
1045
|
+
prependHistory.after(start)
|
|
1046
|
+
dialog.clear()
|
|
1047
|
+
},
|
|
1048
|
+
},
|
|
1049
|
+
{
|
|
1050
|
+
id: "session.last",
|
|
1051
|
+
title: "Last message",
|
|
1052
|
+
group: "Session",
|
|
1053
|
+
palette: undefined,
|
|
1054
|
+
run: () => {
|
|
1055
|
+
toBottom()
|
|
1056
|
+
dialog.clear()
|
|
1057
|
+
},
|
|
1058
|
+
},
|
|
1059
|
+
]
|
|
1060
|
+
|
|
1061
|
+
const baseCommands = createMemo(() => [
|
|
1062
|
+
{
|
|
1063
|
+
title: "Rename session",
|
|
1064
|
+
id: "session.rename",
|
|
1065
|
+
group: "Session",
|
|
1066
|
+
slash: { name: "rename", arguments: true as const },
|
|
1067
|
+
run: (input?: string) => {
|
|
1068
|
+
if (input === undefined) return DialogSessionRename.show(dialog, route.sessionID, session()?.title)
|
|
1069
|
+
const title = input.trim()
|
|
1070
|
+
void (
|
|
1071
|
+
title
|
|
1072
|
+
? client.api.session.update({ sessionID: route.sessionID, title })
|
|
1073
|
+
: data.session.title.generate(route.sessionID)
|
|
1074
|
+
).catch((error) => toast.error(error))
|
|
1075
|
+
},
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
title: "Jump to message",
|
|
1079
|
+
id: "session.timeline",
|
|
1080
|
+
group: "Session",
|
|
1081
|
+
slash: { name: "timeline" },
|
|
1082
|
+
run: () => {
|
|
1083
|
+
dialog.replace(() => <DialogTimeline sessionID={route.sessionID} onMove={jumpToMessage} />)
|
|
1084
|
+
},
|
|
1085
|
+
},
|
|
1086
|
+
{
|
|
1087
|
+
title: "Fork session",
|
|
1088
|
+
id: "session.fork",
|
|
1089
|
+
group: "Session",
|
|
1090
|
+
slash: { name: "fork" },
|
|
1091
|
+
run: () => {
|
|
1092
|
+
dialog.replace(() => (
|
|
1093
|
+
<DialogFork
|
|
1094
|
+
sessionID={route.sessionID}
|
|
1095
|
+
onMove={(messageID) => {
|
|
1096
|
+
if (!messageID) return
|
|
1097
|
+
jumpToMessage(messageID)
|
|
1098
|
+
}}
|
|
1099
|
+
/>
|
|
1100
|
+
))
|
|
1101
|
+
},
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
title: "Compact session",
|
|
1105
|
+
id: "session.compact",
|
|
1106
|
+
group: "Session",
|
|
1107
|
+
slash: {
|
|
1108
|
+
name: "compact",
|
|
1109
|
+
},
|
|
1110
|
+
run: () => {
|
|
1111
|
+
const selection = local.model.current()
|
|
1112
|
+
void data.session
|
|
1113
|
+
.compact({
|
|
1114
|
+
sessionID: route.sessionID,
|
|
1115
|
+
model: selection
|
|
1116
|
+
? {
|
|
1117
|
+
providerID: selection.providerID,
|
|
1118
|
+
id: selection.modelID,
|
|
1119
|
+
variant: local.model.variant.current(),
|
|
1120
|
+
}
|
|
1121
|
+
: undefined,
|
|
1122
|
+
})
|
|
1123
|
+
.catch((error) => toast.show({ message: errorMessage(error), variant: "error" }))
|
|
1124
|
+
dialog.clear()
|
|
1125
|
+
},
|
|
1126
|
+
},
|
|
1127
|
+
{
|
|
1128
|
+
title: "Undo previous message",
|
|
1129
|
+
id: "session.undo",
|
|
1130
|
+
group: "Session",
|
|
1131
|
+
slash: { name: "undo" },
|
|
1132
|
+
run: () => {
|
|
1133
|
+
const message = messagesBeforeRevert().findLast(
|
|
1134
|
+
(message): message is SessionMessageUser => message.type === "user" && !!message.text.trim(),
|
|
1135
|
+
)
|
|
1136
|
+
if (!message) {
|
|
1137
|
+
toast.show({ message: "Nothing to undo", variant: "error", duration: 3000 })
|
|
1138
|
+
dialog.clear()
|
|
1139
|
+
return
|
|
1140
|
+
}
|
|
1141
|
+
const undo = pendingDeliveries().has(message.id)
|
|
1142
|
+
? undoPending(message.id, message)
|
|
1143
|
+
: (async () => {
|
|
1144
|
+
const restored = await restorePrompt(message)
|
|
1145
|
+
await client.api.session.interrupt({ sessionID })
|
|
1146
|
+
await client.api.experimental.session.wait({ sessionID })
|
|
1147
|
+
await client.api.session.revert.stage({ sessionID, messageID: message.id })
|
|
1148
|
+
appendToSessionPrompt(sessionID, restored, renderer.widthMethod)
|
|
1149
|
+
})()
|
|
1150
|
+
void undo.catch((error) => toast.show({ message: errorMessage(error), variant: "error", duration: 5000 }))
|
|
1151
|
+
dialog.clear()
|
|
1152
|
+
},
|
|
1153
|
+
},
|
|
1154
|
+
{
|
|
1155
|
+
title: "Redo",
|
|
1156
|
+
id: "session.redo",
|
|
1157
|
+
group: "Session",
|
|
1158
|
+
enabled: !!session()?.revert?.messageID,
|
|
1159
|
+
slash: { name: "redo" },
|
|
1160
|
+
run: () => {
|
|
1161
|
+
void (async () => {
|
|
1162
|
+
const error = await client.api.session.revert.clear({ sessionID: route.sessionID }).then(
|
|
1163
|
+
() => undefined,
|
|
1164
|
+
(error) => error,
|
|
1165
|
+
)
|
|
1166
|
+
if (error) toast.show({ message: errorMessage(error), variant: "error", duration: 5000 })
|
|
1167
|
+
dialog.clear()
|
|
1168
|
+
})()
|
|
1169
|
+
},
|
|
1170
|
+
},
|
|
1171
|
+
{
|
|
1172
|
+
title: (() => {
|
|
1173
|
+
const next = nextThinkingMode(thinkingMode())
|
|
1174
|
+
if (next === "hide") return "Collapse thinking"
|
|
1175
|
+
return "Expand thinking"
|
|
1176
|
+
})(),
|
|
1177
|
+
id: "session.toggle.thinking",
|
|
1178
|
+
group: "Session",
|
|
1179
|
+
palette: undefined,
|
|
1180
|
+
run: () => {
|
|
1181
|
+
void configState
|
|
1182
|
+
.update((draft) => {
|
|
1183
|
+
draft.session = { ...draft.session, thinking: nextThinkingMode(thinkingMode()) }
|
|
1184
|
+
})
|
|
1185
|
+
.catch(toast.error)
|
|
1186
|
+
dialog.clear()
|
|
1187
|
+
},
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
title: "Toggle session scrollbar",
|
|
1191
|
+
id: "session.toggle.scrollbar",
|
|
1192
|
+
group: "Session",
|
|
1193
|
+
palette: undefined,
|
|
1194
|
+
run: () => {
|
|
1195
|
+
void configState
|
|
1196
|
+
.update((draft) => {
|
|
1197
|
+
draft.session = { ...draft.session, scrollbar: !showScrollbar() }
|
|
1198
|
+
})
|
|
1199
|
+
.catch(toast.error)
|
|
1200
|
+
dialog.clear()
|
|
1201
|
+
},
|
|
1202
|
+
},
|
|
1203
|
+
{
|
|
1204
|
+
title: groupExploration() ? "Show tool calls individually" : "Group related tool calls",
|
|
1205
|
+
id: "session.toggle.exploration_grouping",
|
|
1206
|
+
group: "Session",
|
|
1207
|
+
palette: undefined,
|
|
1208
|
+
run: () => {
|
|
1209
|
+
void configState
|
|
1210
|
+
.update((draft) => {
|
|
1211
|
+
draft.session = { ...draft.session, grouping: groupExploration() ? "none" : "auto" }
|
|
1212
|
+
})
|
|
1213
|
+
.catch(toast.error)
|
|
1214
|
+
dialog.clear()
|
|
1215
|
+
},
|
|
1216
|
+
},
|
|
1217
|
+
{
|
|
1218
|
+
title: `Verbosity: ${Locale.titlecase(verbosity())}`,
|
|
1219
|
+
id: "session.verbosity.cycle",
|
|
1220
|
+
group: "Session",
|
|
1221
|
+
run: () => {
|
|
1222
|
+
const levels = ["low", "medium", "high"] as const
|
|
1223
|
+
const next = levels[(levels.indexOf(verbosity()) + 1) % levels.length]
|
|
1224
|
+
void configState
|
|
1225
|
+
.update((draft) => {
|
|
1226
|
+
draft.session = { ...draft.session, verbosity: next }
|
|
1227
|
+
})
|
|
1228
|
+
.catch(toast.error)
|
|
1229
|
+
dialog.clear()
|
|
1230
|
+
},
|
|
1231
|
+
},
|
|
1232
|
+
{
|
|
1233
|
+
title: "Jump to last user message",
|
|
1234
|
+
id: "session.messages_last_user",
|
|
1235
|
+
group: "Session",
|
|
1236
|
+
palette: undefined,
|
|
1237
|
+
run: () => {
|
|
1238
|
+
const messages = data.session.message.list(route.sessionID)
|
|
1239
|
+
if (!messages || !messages.length) return
|
|
1240
|
+
|
|
1241
|
+
// Find the most recent user message with non-ignored, non-synthetic text parts
|
|
1242
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1243
|
+
const message = messages[i]
|
|
1244
|
+
if (!message || message.type !== "user" || !message.text.trim()) continue
|
|
1245
|
+
{
|
|
1246
|
+
jumpToMessage(message.id)
|
|
1247
|
+
break
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
},
|
|
1251
|
+
},
|
|
1252
|
+
{
|
|
1253
|
+
title: "Next message",
|
|
1254
|
+
id: "session.message.next",
|
|
1255
|
+
group: "Session",
|
|
1256
|
+
palette: undefined,
|
|
1257
|
+
run: () => scrollToMessage("next", dialog),
|
|
1258
|
+
},
|
|
1259
|
+
{
|
|
1260
|
+
title: "Previous message",
|
|
1261
|
+
id: "session.message.previous",
|
|
1262
|
+
group: "Session",
|
|
1263
|
+
palette: undefined,
|
|
1264
|
+
run: () => scrollToMessage("prev", dialog),
|
|
1265
|
+
},
|
|
1266
|
+
{
|
|
1267
|
+
title: "Next user message",
|
|
1268
|
+
id: "session.message.user.next",
|
|
1269
|
+
group: "Session",
|
|
1270
|
+
palette: undefined,
|
|
1271
|
+
run: () => scrollToMessage("next", dialog, true),
|
|
1272
|
+
},
|
|
1273
|
+
{
|
|
1274
|
+
title: "Previous user message",
|
|
1275
|
+
id: "session.message.user.previous",
|
|
1276
|
+
group: "Session",
|
|
1277
|
+
palette: undefined,
|
|
1278
|
+
run: () => scrollToMessage("prev", dialog, true),
|
|
1279
|
+
},
|
|
1280
|
+
{
|
|
1281
|
+
title: "Copy last assistant message",
|
|
1282
|
+
id: "messages.copy",
|
|
1283
|
+
group: "Session",
|
|
1284
|
+
slash: {
|
|
1285
|
+
name: "copy",
|
|
1286
|
+
},
|
|
1287
|
+
run: () => {
|
|
1288
|
+
const lastAssistantMessage = messagesBeforeRevert().findLast(
|
|
1289
|
+
(msg) => msg.type === "assistant" || (msg.type === "compaction" && msg.status === "completed" && msg.summary.trim() !== ""),
|
|
1290
|
+
)
|
|
1291
|
+
if (!lastAssistantMessage) {
|
|
1292
|
+
toast.show({ message: "No assistant messages found", variant: "error" })
|
|
1293
|
+
dialog.clear()
|
|
1294
|
+
return
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
const text =
|
|
1298
|
+
lastAssistantMessage.type === "assistant"
|
|
1299
|
+
? lastAssistantMessage.content
|
|
1300
|
+
.filter((part) => part.type === "text")
|
|
1301
|
+
.map((part) => part.text)
|
|
1302
|
+
.join("\n")
|
|
1303
|
+
.trim()
|
|
1304
|
+
: lastAssistantMessage.type === "compaction" && lastAssistantMessage.status === "completed"
|
|
1305
|
+
? lastAssistantMessage.summary.trim()
|
|
1306
|
+
: ""
|
|
1307
|
+
if (!text) {
|
|
1308
|
+
toast.show({
|
|
1309
|
+
message: "No text content found in last assistant message",
|
|
1310
|
+
variant: "error",
|
|
1311
|
+
})
|
|
1312
|
+
dialog.clear()
|
|
1313
|
+
return
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
clipboard
|
|
1317
|
+
.write(text)
|
|
1318
|
+
.then(() => toast.show({ message: "Message copied to clipboard!", variant: "success" }))
|
|
1319
|
+
.catch(() => toast.show({ message: "Failed to copy to clipboard", variant: "error" }))
|
|
1320
|
+
dialog.clear()
|
|
1321
|
+
},
|
|
1322
|
+
},
|
|
1323
|
+
{
|
|
1324
|
+
title: "Copy session ID",
|
|
1325
|
+
id: "session.copy.id",
|
|
1326
|
+
group: "Session",
|
|
1327
|
+
run: () => {
|
|
1328
|
+
clipboard
|
|
1329
|
+
.write(route.sessionID)
|
|
1330
|
+
.then(() => toast.show({ message: "Session ID copied to clipboard!", variant: "success" }))
|
|
1331
|
+
.catch(() => toast.show({ message: "Failed to copy session ID", variant: "error" }))
|
|
1332
|
+
dialog.clear()
|
|
1333
|
+
},
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
title: "Copy session transcript",
|
|
1337
|
+
id: "session.copy",
|
|
1338
|
+
group: "Session",
|
|
1339
|
+
run: async () => {
|
|
1340
|
+
try {
|
|
1341
|
+
const sessionData = session()
|
|
1342
|
+
if (!sessionData) return
|
|
1343
|
+
const transcript = await client.api.experimental.session.export({ sessionID: sessionData.id })
|
|
1344
|
+
const content = formatSessionTranscript(transcript.info, transcript.messages, true)
|
|
1345
|
+
await clipboard.write(content)
|
|
1346
|
+
toast.show({ message: "Session transcript copied to clipboard!", variant: "success" })
|
|
1347
|
+
} catch {
|
|
1348
|
+
toast.show({ message: "Failed to copy session transcript", variant: "error" })
|
|
1349
|
+
}
|
|
1350
|
+
dialog.clear()
|
|
1351
|
+
},
|
|
1352
|
+
},
|
|
1353
|
+
{
|
|
1354
|
+
title: "Export session transcript",
|
|
1355
|
+
id: "session.export",
|
|
1356
|
+
group: "Session",
|
|
1357
|
+
slash: {
|
|
1358
|
+
name: "export",
|
|
1359
|
+
},
|
|
1360
|
+
run: async () => {
|
|
1361
|
+
try {
|
|
1362
|
+
const sessionData = session()
|
|
1363
|
+
if (!sessionData) return
|
|
1364
|
+
|
|
1365
|
+
const options = await DialogExportOptions.show(dialog, true)
|
|
1366
|
+
|
|
1367
|
+
if (options === null) return
|
|
1368
|
+
|
|
1369
|
+
const transcript = await client.api.experimental.session.export({
|
|
1370
|
+
sessionID: sessionData.id,
|
|
1371
|
+
sanitize: options.format === "json" ? options.sanitize : undefined,
|
|
1372
|
+
})
|
|
1373
|
+
const content =
|
|
1374
|
+
options.format === "markdown"
|
|
1375
|
+
? formatSessionTranscript(transcript.info, transcript.messages, options.thinking, options.tools)
|
|
1376
|
+
: JSON.stringify(transcript, null, 2) + EOL
|
|
1377
|
+
|
|
1378
|
+
if (options.action === "copy") {
|
|
1379
|
+
await clipboard.write(content)
|
|
1380
|
+
dialog.clear()
|
|
1381
|
+
toast.show({ message: "Copied to clipboard", variant: "success" })
|
|
1382
|
+
return
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
const filepath = path.join(
|
|
1386
|
+
options.location === "temp" ? tmpdir() : paths.cwd,
|
|
1387
|
+
`session-${crypto.randomUUID()}.${options.format === "markdown" ? "md" : "json"}`,
|
|
1388
|
+
)
|
|
1389
|
+
await writeExport(filepath, content)
|
|
1390
|
+
await DialogExportResult.show(dialog, filepath)
|
|
1391
|
+
} catch {
|
|
1392
|
+
toast.show({ message: "Failed to export session", variant: "error" })
|
|
1393
|
+
}
|
|
1394
|
+
dialog.clear()
|
|
1395
|
+
},
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
title: "Background blocking tools",
|
|
1399
|
+
id: "session.background",
|
|
1400
|
+
group: "Session",
|
|
1401
|
+
palette: undefined,
|
|
1402
|
+
run: () => {
|
|
1403
|
+
void client.api.session.background({ sessionID: route.sessionID })
|
|
1404
|
+
dialog.clear()
|
|
1405
|
+
},
|
|
1406
|
+
},
|
|
1407
|
+
{
|
|
1408
|
+
title: "Toggle subagent picker",
|
|
1409
|
+
id: "session.child.first",
|
|
1410
|
+
group: "Session",
|
|
1411
|
+
run: (tab?: string) => {
|
|
1412
|
+
if (tab === "shell" || tab === "subagents" || tab === "scripts") setComposer({ open: true, tab })
|
|
1413
|
+
else if (composer.open || session()?.parentID) setComposer("open", false)
|
|
1414
|
+
else setComposer({ open: true, tab: openingTab() })
|
|
1415
|
+
dialog.clear()
|
|
1416
|
+
},
|
|
1417
|
+
},
|
|
1418
|
+
{
|
|
1419
|
+
title: "View queued prompts",
|
|
1420
|
+
id: "session.queued_prompts",
|
|
1421
|
+
group: "Prompt",
|
|
1422
|
+
enabled: queuedPrompts().length > 0,
|
|
1423
|
+
run: openQueuedPrompts,
|
|
1424
|
+
},
|
|
1425
|
+
{
|
|
1426
|
+
title: "Go to parent session",
|
|
1427
|
+
id: "session.parent",
|
|
1428
|
+
group: "Session",
|
|
1429
|
+
palette: undefined,
|
|
1430
|
+
enabled: !!session()?.parentID,
|
|
1431
|
+
run: () => {
|
|
1432
|
+
const parentID = session()?.parentID
|
|
1433
|
+
if (parentID) {
|
|
1434
|
+
navigate({
|
|
1435
|
+
type: "session",
|
|
1436
|
+
sessionID: parentID,
|
|
1437
|
+
})
|
|
1438
|
+
}
|
|
1439
|
+
dialog.clear()
|
|
1440
|
+
},
|
|
1441
|
+
},
|
|
1442
|
+
])
|
|
1443
|
+
|
|
1444
|
+
const commands = createMemo(() =>
|
|
1445
|
+
[...globalCommands, ...baseAndUnfocusedCommands, ...baseCommands()].map(
|
|
1446
|
+
(command) =>
|
|
1447
|
+
({
|
|
1448
|
+
bind: false,
|
|
1449
|
+
palette: true as const,
|
|
1450
|
+
...command,
|
|
1451
|
+
}) satisfies KeymapCommand,
|
|
1452
|
+
),
|
|
1453
|
+
)
|
|
1454
|
+
|
|
1455
|
+
Keymap.createLayer(() => ({
|
|
1456
|
+
mode: "global",
|
|
1457
|
+
commands: commands(),
|
|
1458
|
+
bindings: globalCommands.map((command) => command.id),
|
|
1459
|
+
}))
|
|
1460
|
+
|
|
1461
|
+
Keymap.createLayer(() => ({
|
|
1462
|
+
mode: "composer",
|
|
1463
|
+
enabled: () => renderer.currentFocusedEditor === null,
|
|
1464
|
+
bindings: baseAndUnfocusedCommands.map((command) => command.id),
|
|
1465
|
+
}))
|
|
1466
|
+
|
|
1467
|
+
Keymap.createLayer(() => ({
|
|
1468
|
+
bindings: [...baseAndUnfocusedCommands, ...baseCommands()].map((command) => command.id),
|
|
1469
|
+
}))
|
|
1470
|
+
|
|
1471
|
+
createEffect(
|
|
1472
|
+
on(
|
|
1473
|
+
() => route.sessionID,
|
|
1474
|
+
() => {
|
|
1475
|
+
setComposer("open", false)
|
|
1476
|
+
clearMessageNavigation()
|
|
1477
|
+
},
|
|
1478
|
+
),
|
|
1479
|
+
)
|
|
1480
|
+
|
|
1481
|
+
// Memoized per axis so width readers do not re-run on height-only resizes
|
|
1482
|
+
// (dimensions() is one object signal with identity equality) and vice versa.
|
|
1483
|
+
const terminalWidth = createMemo(() => dimensions().width)
|
|
1484
|
+
const terminalHeight = createMemo(() => dimensions().height)
|
|
1485
|
+
|
|
1486
|
+
return (
|
|
1487
|
+
<context.Provider
|
|
1488
|
+
value={{
|
|
1489
|
+
anchors,
|
|
1490
|
+
groupExpanded,
|
|
1491
|
+
setGroupExpanded: (id, expanded, anchor) => {
|
|
1492
|
+
// A group that ends the transcript would open off screen while the reader follows the bottom.
|
|
1493
|
+
const last = rows.findLast((row) => row.type !== "assistant-footer" && row.type !== "turn-usage")
|
|
1494
|
+
const ending = last?.type === "group" && groupID(last, 0) === id
|
|
1495
|
+
// Keeps the toggled disclosure's header on its viewport row through the next layout.
|
|
1496
|
+
if (anchor && !(ending && !isAwayFromBottom())) afterLayout(scroll.anchor(anchor))
|
|
1497
|
+
sessionTabs.setGroupExpanded(sessionID, id, expanded)
|
|
1498
|
+
afterLayout(saveScrollAnchor)
|
|
1499
|
+
},
|
|
1500
|
+
get width() {
|
|
1501
|
+
return contentWidth()
|
|
1502
|
+
},
|
|
1503
|
+
terminal: {
|
|
1504
|
+
get width() {
|
|
1505
|
+
return terminalWidth()
|
|
1506
|
+
},
|
|
1507
|
+
get height() {
|
|
1508
|
+
return terminalHeight()
|
|
1509
|
+
},
|
|
1510
|
+
},
|
|
1511
|
+
sessionID: route.sessionID,
|
|
1512
|
+
thinkingMode,
|
|
1513
|
+
markdownMode,
|
|
1514
|
+
groupExploration,
|
|
1515
|
+
diffWrapMode,
|
|
1516
|
+
models,
|
|
1517
|
+
messageIndex: (messageID) => messageIndexes().get(messageID),
|
|
1518
|
+
legacyTurns: legacy,
|
|
1519
|
+
config,
|
|
1520
|
+
mutatePending,
|
|
1521
|
+
pendingDelivery: (inboxID) => pendingDeliveries().get(inboxID),
|
|
1522
|
+
}}
|
|
1523
|
+
>
|
|
1524
|
+
<box flexDirection="row" flexGrow={1} minHeight={0}>
|
|
1525
|
+
<box
|
|
1526
|
+
flexGrow={1}
|
|
1527
|
+
minHeight={0}
|
|
1528
|
+
paddingBottom={1}
|
|
1529
|
+
paddingLeft={dimensions().width < 44 ? 1 : 2}
|
|
1530
|
+
paddingRight={dimensions().width < 44 ? 1 : 2}
|
|
1531
|
+
>
|
|
1532
|
+
<Show when={session()}>
|
|
1533
|
+
<box flexGrow={1} minHeight={0} position="relative">
|
|
1534
|
+
<scrollbox
|
|
1535
|
+
ref={(r) => {
|
|
1536
|
+
scroll = r
|
|
1537
|
+
props.scrollRef?.(r)
|
|
1538
|
+
scroll.verticalScrollBar.on("change", updateAwayFromBottom)
|
|
1539
|
+
}}
|
|
1540
|
+
viewportOptions={{
|
|
1541
|
+
paddingRight: showScrollbar() ? 1 : 0,
|
|
1542
|
+
}}
|
|
1543
|
+
verticalScrollbarOptions={{
|
|
1544
|
+
paddingLeft: 1,
|
|
1545
|
+
visible: showScrollbar(),
|
|
1546
|
+
trackOptions: {
|
|
1547
|
+
backgroundColor: theme.decrease(theme.background.raised.base),
|
|
1548
|
+
foregroundColor: theme.border.base,
|
|
1549
|
+
},
|
|
1550
|
+
}}
|
|
1551
|
+
stickyScroll={!navigationMessage() && !navigationSlack()}
|
|
1552
|
+
stickyStart="bottom"
|
|
1553
|
+
// Rows never grow or shrink, so a change to one row lays out only that row.
|
|
1554
|
+
contentOptions={{ layoutMode: "list" }}
|
|
1555
|
+
flexGrow={1}
|
|
1556
|
+
scrollAcceleration={scrollAcceleration()}
|
|
1557
|
+
onMouseScroll={(event) => {
|
|
1558
|
+
if (firstJump()) clearMessageNavigation()
|
|
1559
|
+
if (event.scroll?.direction === "up" && revealOlderRows()) return
|
|
1560
|
+
if (event.scroll?.direction === "down" && revealNewerRows()) return
|
|
1561
|
+
updateAwayFromBottom()
|
|
1562
|
+
}}
|
|
1563
|
+
>
|
|
1564
|
+
<For each={visibleRows()}>
|
|
1565
|
+
{(row, index) => (
|
|
1566
|
+
<SessionRowView
|
|
1567
|
+
row={row}
|
|
1568
|
+
message={(messageID) => data.session.message.get(route.sessionID, messageID)}
|
|
1569
|
+
boundaryID={boundaries()[index() + hidden()]}
|
|
1570
|
+
/>
|
|
1571
|
+
)}
|
|
1572
|
+
</For>
|
|
1573
|
+
<BackgroundToolHint messages={messages()} />
|
|
1574
|
+
<Show when={session()?.revert?.messageID}>
|
|
1575
|
+
<RevertMessage
|
|
1576
|
+
count={messagesFromRevert().filter((message) => message.type === "user").length}
|
|
1577
|
+
files={session()!.revert!.files ?? []}
|
|
1578
|
+
/>
|
|
1579
|
+
</Show>
|
|
1580
|
+
<Show when={navigationSlack()}>
|
|
1581
|
+
{(height) => <box id={NAVIGATION_SLACK_ID} height={height()} flexShrink={0} />}
|
|
1582
|
+
</Show>
|
|
1583
|
+
</scrollbox>
|
|
1584
|
+
</box>
|
|
1585
|
+
<box height={1} flexShrink={0} flexDirection="row" justifyContent="flex-end">
|
|
1586
|
+
<Show when={firstJump()}>
|
|
1587
|
+
<text fg={theme.text.feedback.info.base}>Loading session history…</text>
|
|
1588
|
+
</Show>
|
|
1589
|
+
<Show when={!firstJump() && awayFromBottom()}>
|
|
1590
|
+
<box
|
|
1591
|
+
id="session-jump-to-latest"
|
|
1592
|
+
paddingLeft={1}
|
|
1593
|
+
onMouseOver={() => setLatestHovered(true)}
|
|
1594
|
+
onMouseOut={() => setLatestHovered(false)}
|
|
1595
|
+
onMouseUp={toBottom}
|
|
1596
|
+
>
|
|
1597
|
+
<text
|
|
1598
|
+
fg={latestHovered() ? theme.text.action.secondary.hovered : theme.text.action.secondary.base}
|
|
1599
|
+
>
|
|
1600
|
+
Jump to latest ↓
|
|
1601
|
+
</text>
|
|
1602
|
+
</box>
|
|
1603
|
+
</Show>
|
|
1604
|
+
</box>
|
|
1605
|
+
<box flexShrink={0}>
|
|
1606
|
+
<Show when={!composer.open && !disabled() && queuedPrompts().length > 0}>
|
|
1607
|
+
<QueuedPromptDock prompts={queuedPrompts()} onOpen={openQueuedPrompts} />
|
|
1608
|
+
</Show>
|
|
1609
|
+
<Slot path="session.composer.top" input={{ sessionID: route.sessionID }} />
|
|
1610
|
+
<Composer
|
|
1611
|
+
sessionID={route.sessionID}
|
|
1612
|
+
open={composerVisible()}
|
|
1613
|
+
defaultTab={composer.tab ?? (session()?.parentID ? "subagents" : undefined)}
|
|
1614
|
+
onClose={() => {
|
|
1615
|
+
const parent = session()?.parentID
|
|
1616
|
+
if (parent) {
|
|
1617
|
+
navigate({ type: "session", sessionID: parent })
|
|
1618
|
+
return
|
|
1619
|
+
}
|
|
1620
|
+
setComposer("open", false)
|
|
1621
|
+
}}
|
|
1622
|
+
terminals={props.terminals}
|
|
1623
|
+
visibleTerminalID={props.visibleTerminalID}
|
|
1624
|
+
/>
|
|
1625
|
+
<Switch>
|
|
1626
|
+
<Match when={composerVisible()}>{null}</Match>
|
|
1627
|
+
<Match when={promptedPermissions().length > 0}>
|
|
1628
|
+
<Show when={promptedPermissions()[0]?.id} keyed>
|
|
1629
|
+
{(_) => {
|
|
1630
|
+
const request = promptedPermissions()[0]
|
|
1631
|
+
return request ? (
|
|
1632
|
+
<PermissionPrompt request={request} directory={session()?.location.directory} />
|
|
1633
|
+
) : null
|
|
1634
|
+
}}
|
|
1635
|
+
</Show>
|
|
1636
|
+
</Match>
|
|
1637
|
+
<Match when={forms().length > 0}>
|
|
1638
|
+
<Show when={forms()[0]?.id} keyed>
|
|
1639
|
+
{(_) => {
|
|
1640
|
+
const form = forms()[0]
|
|
1641
|
+
return form ? <FormPrompt form={form} /> : null
|
|
1642
|
+
}}
|
|
1643
|
+
</Show>
|
|
1644
|
+
</Match>
|
|
1645
|
+
<Match
|
|
1646
|
+
when={
|
|
1647
|
+
session() &&
|
|
1648
|
+
currentLocation.error?.location.directory === session()!.location.directory
|
|
1649
|
+
}
|
|
1650
|
+
>
|
|
1651
|
+
<SessionLocationMissing
|
|
1652
|
+
directory={session()!.location.directory}
|
|
1653
|
+
projectID={session()!.projectID}
|
|
1654
|
+
sessionID={route.sessionID}
|
|
1655
|
+
/>
|
|
1656
|
+
</Match>
|
|
1657
|
+
<Match when={!disabled()}>
|
|
1658
|
+
<Prompt
|
|
1659
|
+
visible={true}
|
|
1660
|
+
ref={bind}
|
|
1661
|
+
muted={props.promptMuted}
|
|
1662
|
+
onSubmit={() => {
|
|
1663
|
+
if (config.session?.submit_scroll !== "keep") toBottom()
|
|
1664
|
+
}}
|
|
1665
|
+
onEmptySubmit={async () => {
|
|
1666
|
+
const next = queuedPrompts()[0]
|
|
1667
|
+
if (!next) return false
|
|
1668
|
+
return mutatePending("steer", next.id)
|
|
1669
|
+
}}
|
|
1670
|
+
sessionID={route.sessionID}
|
|
1671
|
+
/>
|
|
1672
|
+
</Match>
|
|
1673
|
+
</Switch>
|
|
1674
|
+
</box>
|
|
1675
|
+
</Show>
|
|
1676
|
+
</box>
|
|
1677
|
+
</box>
|
|
1678
|
+
</context.Provider>
|
|
1679
|
+
)
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
type SessionRowViewProps = {
|
|
1683
|
+
row: SessionRow
|
|
1684
|
+
message: (messageID: string) => SessionMessageInfo | undefined
|
|
1685
|
+
boundaryID?: string
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
function SessionRowView(props: SessionRowViewProps) {
|
|
1689
|
+
const [target, setTarget] = createSignal<BoxRenderable>()
|
|
1690
|
+
useEntryAnchor({
|
|
1691
|
+
entry: () => (props.row.type === "group" ? undefined : props.row),
|
|
1692
|
+
node: target,
|
|
1693
|
+
})
|
|
1694
|
+
return (
|
|
1695
|
+
<box ref={setTarget} id={sessionRowID(props.row, props.boundaryID)} marginTop={1} flexShrink={0}>
|
|
1696
|
+
<Switch>
|
|
1697
|
+
<Match when={props.row.type === "group" ? props.row : undefined}>
|
|
1698
|
+
{(row) => (
|
|
1699
|
+
<SessionGroupView
|
|
1700
|
+
row={row()}
|
|
1701
|
+
message={props.message}
|
|
1702
|
+
entry={(entry, images) => <SessionEntryView row={entry} message={props.message} images={images} />}
|
|
1703
|
+
images={(parts) => <ToolImages parts={parts} />}
|
|
1704
|
+
/>
|
|
1705
|
+
)}
|
|
1706
|
+
</Match>
|
|
1707
|
+
<Match when={props.row.type !== "group" ? props.row : undefined}>
|
|
1708
|
+
{(row) => <SessionEntryView row={row()} message={props.message} />}
|
|
1709
|
+
</Match>
|
|
1710
|
+
</Switch>
|
|
1711
|
+
</box>
|
|
1712
|
+
)
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
function SessionEntryView(props: { row: SessionEntry; message: SessionRowViewProps["message"]; images?: boolean }) {
|
|
1716
|
+
return (
|
|
1717
|
+
<Switch>
|
|
1718
|
+
<Match when={props.row.type === "message" ? props.row : undefined}>
|
|
1719
|
+
{(row) => (
|
|
1720
|
+
<Show when={props.message(row().messageID)}>{(message) => <SessionMessageView message={message()} />}</Show>
|
|
1721
|
+
)}
|
|
1722
|
+
</Match>
|
|
1723
|
+
<Match when={props.row.type === "compaction-queued"}>
|
|
1724
|
+
<CompactionQueued />
|
|
1725
|
+
</Match>
|
|
1726
|
+
<Match when={props.row.type === "part" ? props.row : undefined}>
|
|
1727
|
+
{(row) => <SessionPartView partRef={row().ref} message={props.message} images={props.images} />}
|
|
1728
|
+
</Match>
|
|
1729
|
+
<Match when={props.row.type === "assistant-footer" ? props.row : undefined}>
|
|
1730
|
+
{(row) => (
|
|
1731
|
+
<Show when={props.message(row().messageID)}>
|
|
1732
|
+
{(message) => (
|
|
1733
|
+
<Show when={message().type === "assistant"}>
|
|
1734
|
+
<AssistantFooter message={message() as SessionMessageAssistant} />
|
|
1735
|
+
</Show>
|
|
1736
|
+
)}
|
|
1737
|
+
</Show>
|
|
1738
|
+
)}
|
|
1739
|
+
</Match>
|
|
1740
|
+
<Match when={props.row.type === "turn-usage" ? props.row : undefined}>
|
|
1741
|
+
{(row) => (
|
|
1742
|
+
<TurnTokenUsage messageIDs={row().messageIDs} previousCache={row().previousCache} message={props.message} />
|
|
1743
|
+
)}
|
|
1744
|
+
</Match>
|
|
1745
|
+
</Switch>
|
|
1746
|
+
)
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
function TurnTokenUsage(props: {
|
|
1750
|
+
messageIDs: string[]
|
|
1751
|
+
previousCache?: CacheUsage
|
|
1752
|
+
message: (messageID: string) => SessionMessageInfo | undefined
|
|
1753
|
+
}) {
|
|
1754
|
+
const config = useConfig()
|
|
1755
|
+
const theme = useTheme()
|
|
1756
|
+
const renderer = useRenderer()
|
|
1757
|
+
// Collapsed by default: one summary line for the whole turn. Click to
|
|
1758
|
+
// open the full per-step table, click again to close.
|
|
1759
|
+
const [expanded, setExpanded] = createSignal(false)
|
|
1760
|
+
const [hover, setHover] = createSignal(false)
|
|
1761
|
+
const verbose = () => config.data.debug?.turn_tokens === "verbose"
|
|
1762
|
+
const steps = createMemo(() => {
|
|
1763
|
+
let previousCache = props.previousCache
|
|
1764
|
+
return props.messageIDs.flatMap((messageID) => {
|
|
1765
|
+
const message = props.message(messageID)
|
|
1766
|
+
if (message?.type !== "assistant" || !message.tokens) return []
|
|
1767
|
+
const total =
|
|
1768
|
+
message.tokens.input +
|
|
1769
|
+
message.tokens.output +
|
|
1770
|
+
message.tokens.reasoning +
|
|
1771
|
+
message.tokens.cache.read +
|
|
1772
|
+
message.tokens.cache.write
|
|
1773
|
+
if (total === 0) return []
|
|
1774
|
+
const newTokens = total - message.tokens.cache.read
|
|
1775
|
+
const currentCache = { read: message.tokens.cache.read, model: message.model }
|
|
1776
|
+
const reuseDrop = cacheReuseDrop(previousCache, currentCache)
|
|
1777
|
+
previousCache = currentCache
|
|
1778
|
+
return [
|
|
1779
|
+
{
|
|
1780
|
+
finish: message.finish === "tool-calls" ? "tool-call" : (message.finish ?? "unknown"),
|
|
1781
|
+
tools: verbose() ? message.content.filter((part) => part.type === "tool") : [],
|
|
1782
|
+
newTokens,
|
|
1783
|
+
cached: message.tokens.cache.read,
|
|
1784
|
+
total,
|
|
1785
|
+
reuseDrop,
|
|
1786
|
+
},
|
|
1787
|
+
]
|
|
1788
|
+
})
|
|
1789
|
+
})
|
|
1790
|
+
const columns = createMemo(() => ({
|
|
1791
|
+
step: Math.max("Step".length, ...steps().map((item) => item.finish.length)),
|
|
1792
|
+
newTokens: Math.max("New".length, ...steps().map((item) => item.newTokens.toLocaleString().length)),
|
|
1793
|
+
cached: Math.max("Cached".length, ...steps().map((item) => item.cached.toLocaleString().length)),
|
|
1794
|
+
total: Math.max("Total".length, ...steps().map((item) => item.total.toLocaleString().length)),
|
|
1795
|
+
}))
|
|
1796
|
+
const summary = createMemo(() => {
|
|
1797
|
+
const items = steps()
|
|
1798
|
+
const latest = items.at(-1)
|
|
1799
|
+
return {
|
|
1800
|
+
count: items.length,
|
|
1801
|
+
latestNewTokens: latest?.newTokens ?? 0,
|
|
1802
|
+
latestCached: latest?.cached ?? 0,
|
|
1803
|
+
latestTotal: latest?.total ?? 0,
|
|
1804
|
+
reuseDrops: items.filter((item) => item.reuseDrop !== undefined).length,
|
|
1805
|
+
}
|
|
1806
|
+
})
|
|
1807
|
+
return (
|
|
1808
|
+
<Show when={Boolean(config.data.debug?.turn_tokens) && steps().length > 0}>
|
|
1809
|
+
<box paddingLeft={3} flexDirection="column">
|
|
1810
|
+
<box
|
|
1811
|
+
flexDirection="row"
|
|
1812
|
+
onMouseOver={() => setHover(true)}
|
|
1813
|
+
onMouseOut={() => setHover(false)}
|
|
1814
|
+
onMouseUp={() => {
|
|
1815
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
1816
|
+
setExpanded((value) => !value)
|
|
1817
|
+
}}
|
|
1818
|
+
>
|
|
1819
|
+
<text fg={hover() ? theme.text.base : theme.text.muted} wrapMode="none">
|
|
1820
|
+
<span>{expanded() ? "- " : "+ "}</span>
|
|
1821
|
+
<span style={{ attributes: TextAttributes.BOLD }}>Tokens</span>
|
|
1822
|
+
<span>
|
|
1823
|
+
: {summary().count} {summary().count === 1 ? "step" : "steps"} · latest:{" "}
|
|
1824
|
+
{summary().latestNewTokens.toLocaleString()} new · {summary().latestCached.toLocaleString()} cached ·{" "}
|
|
1825
|
+
{summary().latestTotal.toLocaleString()} total
|
|
1826
|
+
</span>
|
|
1827
|
+
<Show when={summary().reuseDrops > 0}>
|
|
1828
|
+
<span style={{ fg: theme.text.feedback.warning.base }}>
|
|
1829
|
+
{" "}
|
|
1830
|
+
· ! {summary().reuseDrops} likely cache {summary().reuseDrops === 1 ? "bust" : "busts"}
|
|
1831
|
+
</span>
|
|
1832
|
+
</Show>
|
|
1833
|
+
</text>
|
|
1834
|
+
</box>
|
|
1835
|
+
<Show when={expanded()}>
|
|
1836
|
+
<box paddingLeft={INLINE_TOOL_ICON_WIDTH}>
|
|
1837
|
+
<text fg={theme.text.muted} attributes={TextAttributes.ITALIC}>
|
|
1838
|
+
{"Step".padEnd(columns().step + 2)}
|
|
1839
|
+
{"New".padStart(columns().newTokens)}
|
|
1840
|
+
{" "}
|
|
1841
|
+
{"Cached".padStart(columns().cached)}
|
|
1842
|
+
{" "}
|
|
1843
|
+
{"Total".padStart(columns().total)}
|
|
1844
|
+
</text>
|
|
1845
|
+
</box>
|
|
1846
|
+
<For each={steps()}>
|
|
1847
|
+
{(item) => (
|
|
1848
|
+
<box paddingLeft={INLINE_TOOL_ICON_WIDTH} flexDirection="column">
|
|
1849
|
+
<text fg={verbose() && item.finish === "tool-call" ? undefined : theme.text.muted}>
|
|
1850
|
+
{item.finish.padEnd(columns().step + 2)}
|
|
1851
|
+
<span style={{ attributes: TextAttributes.BOLD }}>
|
|
1852
|
+
{item.newTokens.toLocaleString().padStart(columns().newTokens)}
|
|
1853
|
+
</span>
|
|
1854
|
+
{" "}
|
|
1855
|
+
{item.cached.toLocaleString().padStart(columns().cached)}
|
|
1856
|
+
{" "}
|
|
1857
|
+
{item.total.toLocaleString().padStart(columns().total)}
|
|
1858
|
+
</text>
|
|
1859
|
+
<TurnTokenToolCalls tools={item.tools} />
|
|
1860
|
+
<Show when={item.reuseDrop !== undefined}>
|
|
1861
|
+
<text fg={theme.text.feedback.warning.base}>
|
|
1862
|
+
! Likely cache bust: {item.reuseDrop?.toLocaleString()} fewer cached tokens than the previous step
|
|
1863
|
+
</text>
|
|
1864
|
+
</Show>
|
|
1865
|
+
</box>
|
|
1866
|
+
)}
|
|
1867
|
+
</For>
|
|
1868
|
+
</Show>
|
|
1869
|
+
</box>
|
|
1870
|
+
</Show>
|
|
1871
|
+
)
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
function TurnTokenToolCalls(props: { tools: SessionMessageAssistantTool[] }) {
|
|
1875
|
+
const theme = useTheme()
|
|
1876
|
+
const nameWidth = () => Math.max(0, ...props.tools.map((tool) => tool.name.length)) + 2
|
|
1877
|
+
return (
|
|
1878
|
+
<Show when={props.tools.length > 0}>
|
|
1879
|
+
<box paddingLeft={2} flexDirection="column">
|
|
1880
|
+
<For each={props.tools}>
|
|
1881
|
+
{(tool) => (
|
|
1882
|
+
<box flexDirection="row">
|
|
1883
|
+
<text width={nameWidth()} flexShrink={0} fg={theme.text.muted} attributes={TextAttributes.BOLD}>
|
|
1884
|
+
{tool.name}
|
|
1885
|
+
</text>
|
|
1886
|
+
<text fg={theme.text.muted} attributes={TextAttributes.DIM} wrapMode="word" flexGrow={1} minWidth={0}>
|
|
1887
|
+
{turnTokenToolSummary(tool)}
|
|
1888
|
+
</text>
|
|
1889
|
+
</box>
|
|
1890
|
+
)}
|
|
1891
|
+
</For>
|
|
1892
|
+
</box>
|
|
1893
|
+
</Show>
|
|
1894
|
+
)
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
function turnTokenToolSummary(tool: SessionMessageAssistantTool) {
|
|
1898
|
+
const data = tool.state.input
|
|
1899
|
+
if (typeof data === "string") return data
|
|
1900
|
+
const primaryKey = ["command", "id", "pattern", "url", "query", "path", "description", "code"].find(
|
|
1901
|
+
(key) => key in data,
|
|
1902
|
+
)
|
|
1903
|
+
const input = Object.entries(data).filter(([, value]) => ["string", "number", "boolean"].includes(typeof value))
|
|
1904
|
+
const primary = input.find(([key]) => key === primaryKey)?.[1]
|
|
1905
|
+
const details = input.filter(([key]) => key !== primaryKey).map(([key, value]) => `${key}: ${String(value)}`)
|
|
1906
|
+
return [primary === undefined ? "" : String(primary), ...details].filter(Boolean).join(" ")
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
function BackgroundToolHint(props: { messages: SessionMessageInfo[] }) {
|
|
1910
|
+
const theme = useTheme()
|
|
1911
|
+
const shortcut = Keymap.useShortcut("session.background")
|
|
1912
|
+
const running = createMemo(() => {
|
|
1913
|
+
if (!shortcut()) return
|
|
1914
|
+
const current = props.messages.findLast(
|
|
1915
|
+
(message): message is SessionMessageAssistant => message.type === "assistant" && !message.time.completed,
|
|
1916
|
+
)
|
|
1917
|
+
const part = current?.content.find((part): part is SessionMessageAssistantTool => {
|
|
1918
|
+
if (part.type !== "tool" || part.state.status !== "running") return false
|
|
1919
|
+
return canonicalToolName(part.name) === "shell"
|
|
1920
|
+
})
|
|
1921
|
+
if (!current || !part) return
|
|
1922
|
+
return { key: `${current.id}:${part.id}`, started: part.time.ran ?? part.time.created }
|
|
1923
|
+
})
|
|
1924
|
+
const visible = createDelayedPresence(
|
|
1925
|
+
running,
|
|
1926
|
+
(tool) => Math.max(0, BACKGROUND_TOOL_HINT_DELAY - (Date.now() - tool.started)),
|
|
1927
|
+
(previous, next) => previous.key === next.key && previous.started === next.started,
|
|
1928
|
+
)
|
|
1929
|
+
return (
|
|
1930
|
+
<Show when={visible() && shortcut()}>
|
|
1931
|
+
{(value) => (
|
|
1932
|
+
<box marginTop={1} paddingLeft={3} flexShrink={0}>
|
|
1933
|
+
<text fg={theme.text.muted}>
|
|
1934
|
+
Press <span style={{ fg: theme.text.base }}>{value()}</span> to move running work to the background
|
|
1935
|
+
</text>
|
|
1936
|
+
</box>
|
|
1937
|
+
)}
|
|
1938
|
+
</Show>
|
|
1939
|
+
)
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
function SessionMessageView(props: { message: SessionMessageInfo }) {
|
|
1943
|
+
return (
|
|
1944
|
+
<Switch>
|
|
1945
|
+
<Match when={props.message.type === "user"}>
|
|
1946
|
+
<UserMessage message={props.message as SessionMessageUser} />
|
|
1947
|
+
</Match>
|
|
1948
|
+
<Match when={props.message.type === "shell"}>
|
|
1949
|
+
<ShellMessage message={props.message as Extract<SessionMessageInfo, { type: "shell" }>} />
|
|
1950
|
+
</Match>
|
|
1951
|
+
<Match
|
|
1952
|
+
when={
|
|
1953
|
+
props.message.type === "agent-switched" ||
|
|
1954
|
+
props.message.type === "model-switched" ||
|
|
1955
|
+
props.message.type === "location-switched"
|
|
1956
|
+
}
|
|
1957
|
+
>
|
|
1958
|
+
<SessionSwitchMessageV2 message={props.message} />
|
|
1959
|
+
</Match>
|
|
1960
|
+
<Match
|
|
1961
|
+
when={props.message.type === "system" || props.message.type === "synthetic" || props.message.type === "skill"}
|
|
1962
|
+
>
|
|
1963
|
+
<Show when={props.message.type === "skill"} fallback={<SessionNoticeMessageV2 message={props.message} />}>
|
|
1964
|
+
<SessionSkillMessage message={props.message as Extract<SessionMessageInfo, { type: "skill" }>} />
|
|
1965
|
+
</Show>
|
|
1966
|
+
</Match>
|
|
1967
|
+
<Match when={props.message.type === "compaction"}>
|
|
1968
|
+
<CompactionMessage message={props.message as Extract<SessionMessageInfo, { type: "compaction" }>} />
|
|
1969
|
+
</Match>
|
|
1970
|
+
<Match when={props.message.type === "idle" ? props.message.error : undefined}>
|
|
1971
|
+
{(error) => <ExecutionError error={error()} />}
|
|
1972
|
+
</Match>
|
|
1973
|
+
</Switch>
|
|
1974
|
+
)
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
function ExecutionError(props: { error: NonNullable<Extract<SessionMessageInfo, { type: "idle" }>["error"]> }) {
|
|
1978
|
+
const theme = useTheme()
|
|
1979
|
+
return (
|
|
1980
|
+
<box paddingLeft={3}>
|
|
1981
|
+
<text fg={theme.text.feedback.error.base}>Error: {errorMessage(props.error)}</text>
|
|
1982
|
+
</box>
|
|
1983
|
+
)
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
function SessionPartView(props: {
|
|
1987
|
+
partRef: PartRef
|
|
1988
|
+
message: (messageID: string) => SessionMessageInfo | undefined
|
|
1989
|
+
images?: boolean
|
|
1990
|
+
}) {
|
|
1991
|
+
const message = createMemo(() => props.message(props.partRef.messageID))
|
|
1992
|
+
const part = createMemo(() => {
|
|
1993
|
+
const item = message()
|
|
1994
|
+
if (item?.type !== "assistant") return
|
|
1995
|
+
return resolvePart(item, props.partRef.partID)
|
|
1996
|
+
})
|
|
1997
|
+
return (
|
|
1998
|
+
<Show when={part()}>
|
|
1999
|
+
{(item) => (
|
|
2000
|
+
<Switch>
|
|
2001
|
+
<Match when={item().type === "text"}>
|
|
2002
|
+
<TextPart
|
|
2003
|
+
part={item() as SessionMessageAssistantText}
|
|
2004
|
+
message={message() as SessionMessageAssistant}
|
|
2005
|
+
last={false}
|
|
2006
|
+
/>
|
|
2007
|
+
</Match>
|
|
2008
|
+
<Match when={item().type === "reasoning"}>
|
|
2009
|
+
<ReasoningPart
|
|
2010
|
+
part={item() as SessionMessageAssistantReasoning}
|
|
2011
|
+
message={message() as SessionMessageAssistant}
|
|
2012
|
+
last={false}
|
|
2013
|
+
/>
|
|
2014
|
+
</Match>
|
|
2015
|
+
<Match when={item().type === "tool"}>
|
|
2016
|
+
<ToolPart part={item() as SessionMessageAssistantTool} images={props.images} />
|
|
2017
|
+
</Match>
|
|
2018
|
+
</Switch>
|
|
2019
|
+
)}
|
|
2020
|
+
</Show>
|
|
2021
|
+
)
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
function AssistantFooter(props: { message: SessionMessageAssistant }) {
|
|
2025
|
+
const ctx = use()
|
|
2026
|
+
const config = useConfig()
|
|
2027
|
+
const data = useData()
|
|
2028
|
+
const local = useLocal()
|
|
2029
|
+
const theme = useTheme()
|
|
2030
|
+
const model = createMemo(
|
|
2031
|
+
() =>
|
|
2032
|
+
ctx
|
|
2033
|
+
.models()
|
|
2034
|
+
.find((model) => model.providerID === props.message.model.providerID && model.id === props.message.model.id)
|
|
2035
|
+
?.name ?? `${props.message.model.providerID}/${props.message.model.id}`,
|
|
2036
|
+
)
|
|
2037
|
+
const messages = createMemo(() => data.session.message.list(ctx.sessionID))
|
|
2038
|
+
const turn = () => ({ index: ctx.messageIndex(props.message.id), legacy: ctx.legacyTurns() })
|
|
2039
|
+
const duration = createMemo(() => SessionTurn.duration(messages(), props.message, turn()))
|
|
2040
|
+
const tokensPerSecond = createMemo(() => SessionTurn.tokensPerSecond(messages(), props.message, turn()))
|
|
2041
|
+
const interrupted = createMemo(() => props.message.error?.message === "Step interrupted")
|
|
2042
|
+
const freeLimit = createMemo(() => props.message.error?.type === "provider.free-limit")
|
|
2043
|
+
const limitNotice = useLimitNotice(() => props.message)
|
|
2044
|
+
return (
|
|
2045
|
+
<>
|
|
2046
|
+
<Show when={props.message.error && !interrupted() && !props.message.retry}>
|
|
2047
|
+
<Switch
|
|
2048
|
+
fallback={
|
|
2049
|
+
<box paddingLeft={3}>
|
|
2050
|
+
<text fg={theme.text.feedback.error.base}>Error: {errorMessage(props.message.error)}</text>
|
|
2051
|
+
</box>
|
|
2052
|
+
}
|
|
2053
|
+
>
|
|
2054
|
+
<Match when={freeLimit()}>
|
|
2055
|
+
<FreeLimitNotice message={props.message} />
|
|
2056
|
+
</Match>
|
|
2057
|
+
<Match when={limitNotice()}>{(notice) => <UsageLimitNotice notice={notice()} />}</Match>
|
|
2058
|
+
</Switch>
|
|
2059
|
+
</Show>
|
|
2060
|
+
<AssistantRetry retry={props.message.retry} />
|
|
2061
|
+
<box paddingLeft={3} marginTop={props.message.retry || (props.message.error && !interrupted()) ? 1 : 0}>
|
|
2062
|
+
<text>
|
|
2063
|
+
<span style={{ fg: props.message.error ? theme.text.muted : local.agent.color(props.message.agent) }}>
|
|
2064
|
+
{Locale.titlecase(props.message.agent)}
|
|
2065
|
+
</span>
|
|
2066
|
+
<Show when={ctx.terminal.width >= 28}>
|
|
2067
|
+
<span style={{ fg: theme.text.muted }}> · {model()}</span>
|
|
2068
|
+
</Show>
|
|
2069
|
+
<Show when={duration() && (ctx.terminal.width < 28 || ctx.terminal.width >= 36)}>
|
|
2070
|
+
<span style={{ fg: theme.text.muted }}> · {Locale.duration(duration())}</span>
|
|
2071
|
+
</Show>
|
|
2072
|
+
<Show when={config.data.session.tps && tokensPerSecond()}>
|
|
2073
|
+
{(value) => <span style={{ fg: theme.text.muted }}> · {value().toFixed(1)} tok/s</span>}
|
|
2074
|
+
</Show>
|
|
2075
|
+
<Show when={interrupted()}>
|
|
2076
|
+
<span style={{ fg: theme.text.muted }}> · interrupted</span>
|
|
2077
|
+
</Show>
|
|
2078
|
+
</text>
|
|
2079
|
+
</box>
|
|
2080
|
+
</>
|
|
2081
|
+
)
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
function SessionSwitchMessageV2(props: { message: SessionMessageInfo }) {
|
|
2085
|
+
const ctx = use()
|
|
2086
|
+
const theme = useTheme()
|
|
2087
|
+
if (props.message.type === "location-switched")
|
|
2088
|
+
return (
|
|
2089
|
+
<box paddingLeft={3}>
|
|
2090
|
+
<text>
|
|
2091
|
+
<span style={{ fg: theme.text.muted }}>↳ Moved to </span>
|
|
2092
|
+
<span style={{ fg: theme.text.feedback.info.base }}>{props.message.location.directory}</span>
|
|
2093
|
+
</text>
|
|
2094
|
+
</box>
|
|
2095
|
+
)
|
|
2096
|
+
const text = () => {
|
|
2097
|
+
if (props.message.type === "agent-switched") {
|
|
2098
|
+
const agent = Locale.titlecase(props.message.agent)
|
|
2099
|
+
if (props.message.previous && props.message.previous !== props.message.agent)
|
|
2100
|
+
return `Switched agent from ${Locale.titlecase(props.message.previous)} to ${agent}`
|
|
2101
|
+
return `Switched agent to ${agent}`
|
|
2102
|
+
}
|
|
2103
|
+
if (props.message.type === "model-switched")
|
|
2104
|
+
return switchLabel(props.message.model, ctx.models(), props.message.previous)
|
|
2105
|
+
return ""
|
|
2106
|
+
}
|
|
2107
|
+
return (
|
|
2108
|
+
<box paddingLeft={3}>
|
|
2109
|
+
<text fg={theme.text.muted}>{text()}</text>
|
|
2110
|
+
</box>
|
|
2111
|
+
)
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
function SessionNoticeMessageV2(props: { message: SessionMessageInfo }) {
|
|
2115
|
+
const ctx = use()
|
|
2116
|
+
const theme = useTheme()
|
|
2117
|
+
const renderer = useRenderer()
|
|
2118
|
+
const { navigate } = useRoute()
|
|
2119
|
+
const [hover, setHover] = createSignal(false)
|
|
2120
|
+
const metadata = () => (props.message.type === "synthetic" ? props.message.metadata : undefined)
|
|
2121
|
+
const source = () => stringValue(metadata()?.source)
|
|
2122
|
+
const completion = () => source() === "subagent" || source() === "shell" || source() === "codemode"
|
|
2123
|
+
const childID = () => (source() === "subagent" ? stringValue(metadata()?.childID) : undefined)
|
|
2124
|
+
const state = () => stringValue(metadata()?.state)
|
|
2125
|
+
const actor = () => {
|
|
2126
|
+
if (source() === "shell") return "Shell"
|
|
2127
|
+
if (source() === "codemode") return "Script"
|
|
2128
|
+
return Locale.titlecase(stringValue(metadata()?.agent) ?? "Subagent")
|
|
2129
|
+
}
|
|
2130
|
+
const text = () => {
|
|
2131
|
+
if (props.message.type === "system") return props.message.description ?? "Instructions updated"
|
|
2132
|
+
if (props.message.type === "synthetic") return props.message.description ?? ""
|
|
2133
|
+
return ""
|
|
2134
|
+
}
|
|
2135
|
+
const description = () => {
|
|
2136
|
+
if (source() === "codemode") return stringValue(metadata()?.jobID) ?? ""
|
|
2137
|
+
return source() === "shell" ? text().replace(/\s+/g, " ").trim() : text()
|
|
2138
|
+
}
|
|
2139
|
+
const status = () => {
|
|
2140
|
+
if (state() === "completed") return "finished"
|
|
2141
|
+
if (state() === "error") return "failed"
|
|
2142
|
+
return state() ?? "finished"
|
|
2143
|
+
}
|
|
2144
|
+
const heading = () => `${state() === "completed" ? "↳" : "!"} ${actor()} ${status()}`
|
|
2145
|
+
const suffix = () => Locale.truncateWidth(` · ${description()}`, Math.max(0, ctx.width - 3 - stringWidth(heading())))
|
|
2146
|
+
const color = () => {
|
|
2147
|
+
if (state() === "error") return theme.text.feedback.error.base
|
|
2148
|
+
if (state() === "cancelled") return theme.text.feedback.warning.base
|
|
2149
|
+
if (hover() && childID()) return theme.text.base
|
|
2150
|
+
return theme.text.feedback.info.base
|
|
2151
|
+
}
|
|
2152
|
+
return (
|
|
2153
|
+
<Show
|
|
2154
|
+
when={completion()}
|
|
2155
|
+
fallback={
|
|
2156
|
+
<InlineToolRow icon={source() === "goal" ? "◎" : "◈"} color={theme.text.muted} pending="Notice" complete={true}>
|
|
2157
|
+
{text()}
|
|
2158
|
+
</InlineToolRow>
|
|
2159
|
+
}
|
|
2160
|
+
>
|
|
2161
|
+
<box
|
|
2162
|
+
marginLeft={3}
|
|
2163
|
+
onMouseOver={() => childID() && setHover(true)}
|
|
2164
|
+
onMouseOut={() => setHover(false)}
|
|
2165
|
+
onMouseUp={() => {
|
|
2166
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
2167
|
+
const id = childID()
|
|
2168
|
+
if (id) navigate({ type: "session", sessionID: id })
|
|
2169
|
+
}}
|
|
2170
|
+
>
|
|
2171
|
+
<text wrapMode="none">
|
|
2172
|
+
<span style={{ fg: color() }}>{heading()}</span>
|
|
2173
|
+
<span style={{ fg: theme.text.muted }}>{suffix()}</span>
|
|
2174
|
+
</text>
|
|
2175
|
+
</box>
|
|
2176
|
+
</Show>
|
|
2177
|
+
)
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
function SessionSkillMessage(props: { message: Extract<SessionMessageInfo, { type: "skill" }> }) {
|
|
2181
|
+
const theme = useTheme()
|
|
2182
|
+
return (
|
|
2183
|
+
<InlineToolRow icon="→" color={theme.text.muted} pending="Skill" complete={true}>
|
|
2184
|
+
Skill {props.message.name}
|
|
2185
|
+
</InlineToolRow>
|
|
2186
|
+
)
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
function CompactionMessage(props: { message: Extract<SessionMessageInfo, { type: "compaction" }> }) {
|
|
2190
|
+
const ctx = use()
|
|
2191
|
+
const theme = useTheme()
|
|
2192
|
+
const { currentSyntax: syntax } = useThemes()
|
|
2193
|
+
const plugins = usePlugin()
|
|
2194
|
+
const status = () => props.message.status
|
|
2195
|
+
const cancelled = () => props.message.status === "failed" && props.message.error.type === "aborted"
|
|
2196
|
+
const text = () =>
|
|
2197
|
+
props.message.status === "failed" ? (cancelled() ? "" : props.message.error.message) : props.message.summary
|
|
2198
|
+
const content = createMemo(() => text().trim())
|
|
2199
|
+
const color = () => (status() === "failed" && !cancelled() ? theme.text.feedback.error.base : theme.text.muted)
|
|
2200
|
+
// Usage of the compaction request itself; the resulting context size only shows on the next assistant step.
|
|
2201
|
+
const usage = () => {
|
|
2202
|
+
if (props.message.status === "running" || !props.message.tokens) return
|
|
2203
|
+
const tokens = props.message.tokens
|
|
2204
|
+
const input = tokens.input + tokens.cache.read + tokens.cache.write
|
|
2205
|
+
const output = tokens.output + tokens.reasoning
|
|
2206
|
+
if (input + output <= 0) return
|
|
2207
|
+
return `${Locale.number(input)} in · ${Locale.number(output)} out`
|
|
2208
|
+
}
|
|
2209
|
+
return (
|
|
2210
|
+
<box>
|
|
2211
|
+
<box flexDirection="row" alignItems="center">
|
|
2212
|
+
<box border={["top"]} borderColor={color()} flexGrow={1} />
|
|
2213
|
+
<box flexDirection="row" gap={1} paddingLeft={1} paddingRight={1}>
|
|
2214
|
+
<Switch>
|
|
2215
|
+
<Match when={status() === "running"}>
|
|
2216
|
+
<Show when={ctx.config.animations ?? true} fallback={<text fg={color()}>⋯</text>}>
|
|
2217
|
+
<spinner frames={SPINNER_FRAMES} interval={80} color={color()} />
|
|
2218
|
+
</Show>
|
|
2219
|
+
</Match>
|
|
2220
|
+
<Match when={status() === "failed" && !cancelled()}>
|
|
2221
|
+
<text fg={color()}>✗</text>
|
|
2222
|
+
</Match>
|
|
2223
|
+
</Switch>
|
|
2224
|
+
<text fg={color()}>
|
|
2225
|
+
{props.message.status === "completed" && props.message.native?.messages
|
|
2226
|
+
? "Provider compaction"
|
|
2227
|
+
: "Compaction"}
|
|
2228
|
+
</text>
|
|
2229
|
+
<Show when={cancelled()}>
|
|
2230
|
+
<text fg={color()}>· cancelled</text>
|
|
2231
|
+
</Show>
|
|
2232
|
+
<Show when={usage()}>
|
|
2233
|
+
<text fg={color()}>· {usage()}</text>
|
|
2234
|
+
</Show>
|
|
2235
|
+
</box>
|
|
2236
|
+
<box border={["top"]} borderColor={color()} flexGrow={1} />
|
|
2237
|
+
</box>
|
|
2238
|
+
<Show when={content()}>
|
|
2239
|
+
<box paddingTop={1} paddingLeft={3}>
|
|
2240
|
+
<markdown
|
|
2241
|
+
ref={useSessionLinks()}
|
|
2242
|
+
syntaxStyle={syntax()}
|
|
2243
|
+
renderBlock={plugins.markdown()}
|
|
2244
|
+
streaming={status() === "running"}
|
|
2245
|
+
content={content()}
|
|
2246
|
+
tableOptions={{ style: "grid", cellPaddingX: 1 }}
|
|
2247
|
+
conceal={ctx.markdownMode() === "rendered"}
|
|
2248
|
+
fg={theme.markdown.text}
|
|
2249
|
+
bg={theme.background.base}
|
|
2250
|
+
/>
|
|
2251
|
+
</box>
|
|
2252
|
+
</Show>
|
|
2253
|
+
</box>
|
|
2254
|
+
)
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
function CompactionQueued() {
|
|
2258
|
+
const theme = useTheme()
|
|
2259
|
+
return (
|
|
2260
|
+
<box flexDirection="row" alignItems="center">
|
|
2261
|
+
<box border={["top"]} borderColor={theme.border.base} flexGrow={1} />
|
|
2262
|
+
<box flexDirection="row" gap={1} paddingLeft={1} paddingRight={1}>
|
|
2263
|
+
<text fg={theme.text.muted}>◇</text>
|
|
2264
|
+
<text fg={theme.text.muted}>Compaction queued</text>
|
|
2265
|
+
</box>
|
|
2266
|
+
<box border={["top"]} borderColor={theme.border.base} flexGrow={1} />
|
|
2267
|
+
</box>
|
|
2268
|
+
)
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
function RevertMessage(props: {
|
|
2272
|
+
count: number
|
|
2273
|
+
files: ReadonlyArray<{
|
|
2274
|
+
readonly file: string
|
|
2275
|
+
readonly status: "added" | "modified" | "deleted"
|
|
2276
|
+
readonly additions: number
|
|
2277
|
+
readonly deletions: number
|
|
2278
|
+
}>
|
|
2279
|
+
}) {
|
|
2280
|
+
const ctx = use()
|
|
2281
|
+
const theme = useTheme()
|
|
2282
|
+
const route = useRouteData("session")
|
|
2283
|
+
const client = useClient()
|
|
2284
|
+
const toast = useToast()
|
|
2285
|
+
const renderer = useRenderer()
|
|
2286
|
+
const [hover, setHover] = createSignal(false)
|
|
2287
|
+
const redoKey = Keymap.useShortcut("session.redo")
|
|
2288
|
+
return (
|
|
2289
|
+
<box
|
|
2290
|
+
onMouseOver={() => setHover(true)}
|
|
2291
|
+
onMouseOut={() => setHover(false)}
|
|
2292
|
+
onMouseUp={() => {
|
|
2293
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
2294
|
+
void (async () => {
|
|
2295
|
+
const error = await client.api.session.revert.clear({ sessionID: route.sessionID }).then(
|
|
2296
|
+
() => undefined,
|
|
2297
|
+
(error) => error,
|
|
2298
|
+
)
|
|
2299
|
+
if (error) toast.show({ message: errorMessage(error), variant: "error", duration: 5000 })
|
|
2300
|
+
})()
|
|
2301
|
+
}}
|
|
2302
|
+
flexShrink={0}
|
|
2303
|
+
marginTop={1}
|
|
2304
|
+
border={["left"]}
|
|
2305
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
2306
|
+
borderColor={theme.background.raised.base}
|
|
2307
|
+
>
|
|
2308
|
+
<box
|
|
2309
|
+
paddingTop={1}
|
|
2310
|
+
paddingBottom={1}
|
|
2311
|
+
paddingLeft={2}
|
|
2312
|
+
paddingRight={2}
|
|
2313
|
+
backgroundColor={hover() ? theme.decrease(theme.background.raised.base) : theme.background.raised.base}
|
|
2314
|
+
>
|
|
2315
|
+
<text fg={theme.text.muted}>
|
|
2316
|
+
{props.count} message{props.count === 1 ? "" : "s"} reverted
|
|
2317
|
+
</text>
|
|
2318
|
+
<Show when={props.files.length > 0}>
|
|
2319
|
+
<box paddingTop={1} paddingBottom={1} flexDirection="column">
|
|
2320
|
+
<For each={props.files}>
|
|
2321
|
+
{(file) => (
|
|
2322
|
+
<box flexDirection="row" gap={1} flexShrink={0}>
|
|
2323
|
+
<text fg={theme.text.muted}>{statusLabel(file.status)}</text>
|
|
2324
|
+
<FilePath
|
|
2325
|
+
value={file.file}
|
|
2326
|
+
maxWidth={Math.max(
|
|
2327
|
+
2,
|
|
2328
|
+
ctx.width -
|
|
2329
|
+
7 -
|
|
2330
|
+
(file.additions > 0 ? stringWidth(`+${file.additions}`) + 1 : 0) -
|
|
2331
|
+
(file.deletions > 0 ? stringWidth(`-${file.deletions}`) + 1 : 0),
|
|
2332
|
+
)}
|
|
2333
|
+
fg={theme.text.base}
|
|
2334
|
+
/>
|
|
2335
|
+
<Show when={file.additions > 0}>
|
|
2336
|
+
<text fg={theme.diff.text.added}>+{file.additions}</text>
|
|
2337
|
+
</Show>
|
|
2338
|
+
<Show when={file.deletions > 0}>
|
|
2339
|
+
<text fg={theme.diff.text.removed}>-{file.deletions}</text>
|
|
2340
|
+
</Show>
|
|
2341
|
+
</box>
|
|
2342
|
+
)}
|
|
2343
|
+
</For>
|
|
2344
|
+
</box>
|
|
2345
|
+
</Show>
|
|
2346
|
+
<text fg={theme.text.muted}>
|
|
2347
|
+
<span style={{ fg: theme.text.base }}>{redoKey()}</span> or /redo to restore
|
|
2348
|
+
</text>
|
|
2349
|
+
</box>
|
|
2350
|
+
</box>
|
|
2351
|
+
)
|
|
2352
|
+
}
|
|
2353
|
+
|
|
2354
|
+
function ShellMessage(props: { message: Extract<SessionMessageInfo, { type: "shell" }> }) {
|
|
2355
|
+
const error = createMemo(() => {
|
|
2356
|
+
if (props.message.status === "killed") return "Command cancelled"
|
|
2357
|
+
if (props.message.status === "timeout") return "Command timed out"
|
|
2358
|
+
if (props.message.exit !== undefined && props.message.exit !== 0)
|
|
2359
|
+
return `Command exited with code ${props.message.exit}`
|
|
2360
|
+
})
|
|
2361
|
+
|
|
2362
|
+
return (
|
|
2363
|
+
<ShellDisplay
|
|
2364
|
+
shellID={props.message.shellID}
|
|
2365
|
+
command={props.message.command}
|
|
2366
|
+
status={props.message.status === "running" ? "running" : "completed"}
|
|
2367
|
+
output={props.message.output?.output}
|
|
2368
|
+
error={error()}
|
|
2369
|
+
/>
|
|
2370
|
+
)
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
function UserMessage(props: { message: SessionMessageUser }) {
|
|
2374
|
+
const ctx = use()
|
|
2375
|
+
const newDesigns = useNewDesigns()
|
|
2376
|
+
const data = useData()
|
|
2377
|
+
const local = useLocal()
|
|
2378
|
+
// Opted-in reads leave stored files as `media:` refs, a PromptAttachment variant the generated message type omits.
|
|
2379
|
+
const files = createMemo(() => deduplicateVisibleImages<PromptAttachment>(props.message.files ?? []))
|
|
2380
|
+
const skills = createMemo(() => props.message.skills ?? [])
|
|
2381
|
+
const images = createMemo(() =>
|
|
2382
|
+
files().flatMap((file) =>
|
|
2383
|
+
file.mime.startsWith("image/")
|
|
2384
|
+
? [{ uri: "uri" in file ? file.uri : `data:${file.mime};base64,${file.data}` }]
|
|
2385
|
+
: [],
|
|
2386
|
+
),
|
|
2387
|
+
)
|
|
2388
|
+
const themes = useThemes()
|
|
2389
|
+
const theme = useTheme()
|
|
2390
|
+
const mode = themes.mode
|
|
2391
|
+
const [hover, setHover] = createSignal(false)
|
|
2392
|
+
const color = createMemo(() => local.agent.color(data.session.get(ctx.sessionID)?.agent ?? "build"))
|
|
2393
|
+
const delivery = createMemo(() => ctx.pendingDelivery(props.message.id))
|
|
2394
|
+
const dialog = useDialog()
|
|
2395
|
+
const renderer = useRenderer()
|
|
2396
|
+
|
|
2397
|
+
const updatePendingSteer = async (action: "queue" | "cancel") => {
|
|
2398
|
+
if (await ctx.mutatePending(action, props.message.id)) dialog.clear()
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
return (
|
|
2402
|
+
<Show when={props.message.text.trim() || files().length || skills().length}>
|
|
2403
|
+
<box
|
|
2404
|
+
border={["left"]}
|
|
2405
|
+
borderColor={delivery() ? theme.border.base : color()}
|
|
2406
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
2407
|
+
backgroundColor={theme.background.raised.base}
|
|
2408
|
+
>
|
|
2409
|
+
<SessionImages images={images()} paddingLeft={2} />
|
|
2410
|
+
<box
|
|
2411
|
+
onMouseOver={() => {
|
|
2412
|
+
setHover(true)
|
|
2413
|
+
}}
|
|
2414
|
+
onMouseOut={() => {
|
|
2415
|
+
setHover(false)
|
|
2416
|
+
}}
|
|
2417
|
+
onMouseUp={() => {
|
|
2418
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
2419
|
+
if (delivery() === "steer") {
|
|
2420
|
+
dialog.replace(() => (
|
|
2421
|
+
<DialogSelect
|
|
2422
|
+
title="Pending steer"
|
|
2423
|
+
renderFilter={!newDesigns()}
|
|
2424
|
+
options={[
|
|
2425
|
+
{ title: "Move to queue", value: "queue" as const },
|
|
2426
|
+
{ title: "Delete", value: "cancel" as const },
|
|
2427
|
+
]}
|
|
2428
|
+
onSelect={(option) => {
|
|
2429
|
+
void updatePendingSteer(option.value)
|
|
2430
|
+
}}
|
|
2431
|
+
/>
|
|
2432
|
+
))
|
|
2433
|
+
return
|
|
2434
|
+
}
|
|
2435
|
+
// The dialog outlives this row, whose props go stale when a resync drops the message.
|
|
2436
|
+
const messageID = props.message.id
|
|
2437
|
+
dialog.replace(() => <DialogMessage messageID={messageID} sessionID={ctx.sessionID} />)
|
|
2438
|
+
}}
|
|
2439
|
+
paddingTop={1}
|
|
2440
|
+
paddingBottom={1}
|
|
2441
|
+
paddingLeft={2}
|
|
2442
|
+
paddingRight={2}
|
|
2443
|
+
backgroundColor={hover() ? theme.decrease(theme.background.raised.base) : theme.background.raised.base}
|
|
2444
|
+
flexShrink={0}
|
|
2445
|
+
>
|
|
2446
|
+
<text fg={theme.text.base}>{props.message.text}</text>
|
|
2447
|
+
<Show when={skills().length}>
|
|
2448
|
+
<box flexDirection="row" paddingTop={1} gap={1} flexWrap="wrap">
|
|
2449
|
+
<For each={skills()}>
|
|
2450
|
+
{(skill) => (
|
|
2451
|
+
<text fg={theme.text.base}>
|
|
2452
|
+
<span
|
|
2453
|
+
style={{
|
|
2454
|
+
bg: theme.hue.accent[mode() === "light" ? 300 : 200],
|
|
2455
|
+
fg: theme.background.raised.base,
|
|
2456
|
+
bold: true,
|
|
2457
|
+
}}
|
|
2458
|
+
>
|
|
2459
|
+
{" skill "}
|
|
2460
|
+
</span>
|
|
2461
|
+
<span style={{ bg: theme.decrease(theme.background.raised.base), fg: theme.text.muted }}>
|
|
2462
|
+
{` ${skill.name} `}
|
|
2463
|
+
</span>
|
|
2464
|
+
</text>
|
|
2465
|
+
)}
|
|
2466
|
+
</For>
|
|
2467
|
+
</box>
|
|
2468
|
+
</Show>
|
|
2469
|
+
<Show when={files().length}>
|
|
2470
|
+
<box flexDirection="row" paddingTop={1} gap={1} flexWrap="wrap">
|
|
2471
|
+
<For each={files()}>
|
|
2472
|
+
{(file) => {
|
|
2473
|
+
const label = file.mime === "application/x-directory" ? "dir" : "file"
|
|
2474
|
+
return (
|
|
2475
|
+
<text fg={theme.text.base}>
|
|
2476
|
+
<span
|
|
2477
|
+
style={{
|
|
2478
|
+
bg: theme.hue.accent[mode() === "light" ? 300 : 200],
|
|
2479
|
+
fg: theme.background.raised.base,
|
|
2480
|
+
bold: true,
|
|
2481
|
+
}}
|
|
2482
|
+
>
|
|
2483
|
+
{` ${label} `}
|
|
2484
|
+
</span>
|
|
2485
|
+
<span style={{ bg: theme.decrease(theme.background.raised.base), fg: theme.text.muted }}>
|
|
2486
|
+
{" "}
|
|
2487
|
+
{file.name ?? (file.source.type === "uri" ? file.source.uri : "attachment")}{" "}
|
|
2488
|
+
</span>
|
|
2489
|
+
</text>
|
|
2490
|
+
)
|
|
2491
|
+
}}
|
|
2492
|
+
</For>
|
|
2493
|
+
</box>
|
|
2494
|
+
</Show>
|
|
2495
|
+
</box>
|
|
2496
|
+
</box>
|
|
2497
|
+
</Show>
|
|
2498
|
+
)
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
function QueuedPromptDock(props: { prompts: { id: string; text: string }[]; onOpen: () => void }) {
|
|
2502
|
+
const theme = useTheme()
|
|
2503
|
+
const [hover, setHover] = createSignal(false)
|
|
2504
|
+
const next = createMemo(() => props.prompts[0]?.text.replaceAll("\n", " "))
|
|
2505
|
+
|
|
2506
|
+
return (
|
|
2507
|
+
<box
|
|
2508
|
+
marginBottom={1}
|
|
2509
|
+
border={["left"]}
|
|
2510
|
+
borderColor={theme.border.base}
|
|
2511
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
2512
|
+
onMouseOver={() => setHover(true)}
|
|
2513
|
+
onMouseOut={() => setHover(false)}
|
|
2514
|
+
onMouseUp={props.onOpen}
|
|
2515
|
+
>
|
|
2516
|
+
<box
|
|
2517
|
+
width="100%"
|
|
2518
|
+
paddingTop={1}
|
|
2519
|
+
paddingBottom={1}
|
|
2520
|
+
paddingLeft={2}
|
|
2521
|
+
paddingRight={2}
|
|
2522
|
+
backgroundColor={hover() ? theme.decrease(theme.background.raised.base) : theme.background.raised.base}
|
|
2523
|
+
flexDirection="row"
|
|
2524
|
+
>
|
|
2525
|
+
<text fg={theme.text.muted} wrapMode="none" truncate flexGrow={1} flexShrink={1} minWidth={0}>
|
|
2526
|
+
<span style={{ fg: theme.text.base }}>{props.prompts.length} queued</span>
|
|
2527
|
+
<Show when={next()}>{(text) => <> · {text()}</>}</Show>
|
|
2528
|
+
</text>
|
|
2529
|
+
</box>
|
|
2530
|
+
</box>
|
|
2531
|
+
)
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
function freeLimitReset(delay: number | undefined, base: number) {
|
|
2535
|
+
if (delay === undefined || !Number.isFinite(delay) || delay < 0 || delay > 7 * 86_400_000 || !Number.isFinite(base))
|
|
2536
|
+
return
|
|
2537
|
+
const at = base + delay
|
|
2538
|
+
if (Number.isNaN(new Date(at).getTime())) return
|
|
2539
|
+
const now = Date.now()
|
|
2540
|
+
return new Date(at).toDateString() === new Date(now).toDateString() && at - now < 86_400_000
|
|
2541
|
+
? Locale.time(at)
|
|
2542
|
+
: Locale.datetime(at)
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
function FreeLimitNotice(props: { message: Pick<SessionMessageAssistant, "error" | "time"> }) {
|
|
2546
|
+
const theme = useTheme()
|
|
2547
|
+
const reset = createMemo(() =>
|
|
2548
|
+
freeLimitReset(props.message.error?.retryAfterMs, props.message.time.completed ?? props.message.time.created),
|
|
2549
|
+
)
|
|
2550
|
+
return (
|
|
2551
|
+
<box paddingLeft={3} flexDirection="column">
|
|
2552
|
+
<text fg={theme.text.muted}>You've used today's free messages.{reset() ? ` They reset at ${reset()}.` : ""}</text>
|
|
2553
|
+
<text fg={theme.text.muted}>
|
|
2554
|
+
Upgrade to Zyro Sec Go → <span style={{ fg: theme.text.base }}>/connect</span> · Switch model →{" "}
|
|
2555
|
+
<span style={{ fg: theme.text.base }}>/models</span>
|
|
2556
|
+
</text>
|
|
2557
|
+
</box>
|
|
2558
|
+
)
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
function AssistantRetry(props: { retry: SessionMessageAssistant["retry"] }) {
|
|
2562
|
+
const theme = useTheme()
|
|
2563
|
+
const [seconds, setSeconds] = createSignal(0)
|
|
2564
|
+
createEffect(() => {
|
|
2565
|
+
const at = props.retry?.at
|
|
2566
|
+
if (at === undefined) return
|
|
2567
|
+
const update = () => setSeconds(Math.max(0, Math.ceil((at - Date.now()) / 1_000)))
|
|
2568
|
+
if (update() === 0) return
|
|
2569
|
+
const timer = setInterval(() => {
|
|
2570
|
+
if (update() === 0) clearInterval(timer)
|
|
2571
|
+
}, 1_000)
|
|
2572
|
+
onCleanup(() => clearInterval(timer))
|
|
2573
|
+
})
|
|
2574
|
+
return (
|
|
2575
|
+
<Show when={props.retry}>
|
|
2576
|
+
{(retry) => (
|
|
2577
|
+
<box paddingLeft={3}>
|
|
2578
|
+
<text fg={theme.text.feedback.warning.base}>
|
|
2579
|
+
⚠ {seconds() > 0 ? `Retrying in ${seconds()}s` : "Retry due"} · attempt {retry().attempt} ·{" "}
|
|
2580
|
+
{retry().error.message}
|
|
2581
|
+
</text>
|
|
2582
|
+
</box>
|
|
2583
|
+
)}
|
|
2584
|
+
</Show>
|
|
2585
|
+
)
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
// Pending messages moved to individual tool pending functions
|
|
2589
|
+
|
|
2590
|
+
function ToolPart(props: { part: SessionMessageAssistantTool; images?: boolean }) {
|
|
2591
|
+
const display = createMemo(() => toolDisplay(props.part.name))
|
|
2592
|
+
|
|
2593
|
+
const toolprops = {
|
|
2594
|
+
get metadata() {
|
|
2595
|
+
return toolDisplayMetadata(props.part.state)
|
|
2596
|
+
},
|
|
2597
|
+
get input() {
|
|
2598
|
+
return typeof props.part.state.input === "string" ? {} : props.part.state.input
|
|
2599
|
+
},
|
|
2600
|
+
get output() {
|
|
2601
|
+
if (props.part.state.status === "streaming") return undefined
|
|
2602
|
+
return toolDisplayContent(props.part.state)
|
|
2603
|
+
.flatMap((content) => (content.type === "text" ? [content.text] : [content.name ?? content.uri]))
|
|
2604
|
+
.join("\n")
|
|
2605
|
+
},
|
|
2606
|
+
get tool() {
|
|
2607
|
+
return props.part.name
|
|
2608
|
+
},
|
|
2609
|
+
get part() {
|
|
2610
|
+
return props.part
|
|
2611
|
+
},
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
const content = (
|
|
2615
|
+
<Switch>
|
|
2616
|
+
<Match when={display() === "shell"}>
|
|
2617
|
+
<Shell {...toolprops} />
|
|
2618
|
+
</Match>
|
|
2619
|
+
<Match when={display() === "glob"}>
|
|
2620
|
+
<Glob {...toolprops} />
|
|
2621
|
+
</Match>
|
|
2622
|
+
<Match when={display() === "read"}>
|
|
2623
|
+
<Read {...toolprops} />
|
|
2624
|
+
</Match>
|
|
2625
|
+
<Match when={display() === "grep"}>
|
|
2626
|
+
<Grep {...toolprops} />
|
|
2627
|
+
</Match>
|
|
2628
|
+
<Match when={display() === "webfetch"}>
|
|
2629
|
+
<WebFetch {...toolprops} />
|
|
2630
|
+
</Match>
|
|
2631
|
+
<Match when={display() === "websearch"}>
|
|
2632
|
+
<WebSearch {...toolprops} />
|
|
2633
|
+
</Match>
|
|
2634
|
+
<Match when={display() === "write"}>
|
|
2635
|
+
<Write {...toolprops} />
|
|
2636
|
+
</Match>
|
|
2637
|
+
<Match when={display() === "edit"}>
|
|
2638
|
+
<Edit {...toolprops} />
|
|
2639
|
+
</Match>
|
|
2640
|
+
<Match when={display() === "subagent"}>
|
|
2641
|
+
<Subagent {...toolprops} />
|
|
2642
|
+
</Match>
|
|
2643
|
+
<Match when={display() === "execute"}>
|
|
2644
|
+
<Execute {...toolprops} />
|
|
2645
|
+
</Match>
|
|
2646
|
+
<Match when={display() === "patch"}>
|
|
2647
|
+
<ApplyPatch {...toolprops} />
|
|
2648
|
+
</Match>
|
|
2649
|
+
<Match when={display() === "todowrite"}>
|
|
2650
|
+
<TodoWrite {...toolprops} />
|
|
2651
|
+
</Match>
|
|
2652
|
+
<Match when={display() === "question"}>
|
|
2653
|
+
<Question {...toolprops} />
|
|
2654
|
+
</Match>
|
|
2655
|
+
<Match when={display() === "skill"}>
|
|
2656
|
+
<Skill {...toolprops} />
|
|
2657
|
+
</Match>
|
|
2658
|
+
<Match when={true}>
|
|
2659
|
+
<GenericTool {...toolprops} />
|
|
2660
|
+
</Match>
|
|
2661
|
+
</Switch>
|
|
2662
|
+
)
|
|
2663
|
+
return [
|
|
2664
|
+
content,
|
|
2665
|
+
<Show when={props.images !== false}>
|
|
2666
|
+
<ToolImages parts={[props.part]} />
|
|
2667
|
+
</Show>,
|
|
2668
|
+
]
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
function ToolImages(props: { parts: readonly SessionMessageAssistantTool[] }) {
|
|
2672
|
+
const images = createMemo(() => props.parts.flatMap(inlineToolImages))
|
|
2673
|
+
return <SessionImages images={images()} />
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
function SessionImages(props: { images: readonly { uri: string }[]; paddingLeft?: number }) {
|
|
2677
|
+
const ctx = use()
|
|
2678
|
+
const dialog = useDialog()
|
|
2679
|
+
const images = createMemo(() => (ctx.config.session?.image_preview ? props.images : []))
|
|
2680
|
+
const height = createMemo(() => Math.max(4, Math.min(8, Math.floor(ctx.terminal.height / 4))))
|
|
2681
|
+
const visible = createMemo(() => images().slice(0, 3))
|
|
2682
|
+
|
|
2683
|
+
return (
|
|
2684
|
+
<Show when={visible().length > 0}>
|
|
2685
|
+
<box
|
|
2686
|
+
flexDirection="row"
|
|
2687
|
+
flexShrink={0}
|
|
2688
|
+
paddingTop={1}
|
|
2689
|
+
paddingLeft={props.paddingLeft ?? 3}
|
|
2690
|
+
paddingRight={2}
|
|
2691
|
+
paddingBottom={1}
|
|
2692
|
+
gap={1}
|
|
2693
|
+
>
|
|
2694
|
+
<For each={visible()}>
|
|
2695
|
+
{(image, index) => {
|
|
2696
|
+
const media = createMediaSource(() => image.uri)
|
|
2697
|
+
return (
|
|
2698
|
+
<box
|
|
2699
|
+
width={height() * 2}
|
|
2700
|
+
height={height()}
|
|
2701
|
+
flexBasis={height() * 2}
|
|
2702
|
+
flexShrink={1}
|
|
2703
|
+
alignItems="center"
|
|
2704
|
+
justifyContent="center"
|
|
2705
|
+
onMouseUp={(event: MouseEvent) => {
|
|
2706
|
+
if (event.button !== 0) return
|
|
2707
|
+
event.stopPropagation()
|
|
2708
|
+
dialog.replace(() => <DialogImagePreview images={images()} initial={index()} />)
|
|
2709
|
+
}}
|
|
2710
|
+
>
|
|
2711
|
+
<Show when={!media.failed()} fallback={<text>No preview</text>}>
|
|
2712
|
+
<image
|
|
2713
|
+
source={media.source()}
|
|
2714
|
+
fit="cover"
|
|
2715
|
+
protocol="auto"
|
|
2716
|
+
width="100%"
|
|
2717
|
+
height="100%"
|
|
2718
|
+
onError={media.onError}
|
|
2719
|
+
/>
|
|
2720
|
+
</Show>
|
|
2721
|
+
</box>
|
|
2722
|
+
)
|
|
2723
|
+
}}
|
|
2724
|
+
</For>
|
|
2725
|
+
<Show when={images().length > visible().length}>
|
|
2726
|
+
<box width={8} height={height()} flexShrink={1} alignItems="center" justifyContent="center">
|
|
2727
|
+
<text wrapMode="none" truncate>
|
|
2728
|
+
+{images().length - visible().length} more
|
|
2729
|
+
</text>
|
|
2730
|
+
</box>
|
|
2731
|
+
</Show>
|
|
2732
|
+
</box>
|
|
2733
|
+
</Show>
|
|
2734
|
+
)
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
function inlineToolImages(part: SessionMessageAssistantTool) {
|
|
2738
|
+
return toolDisplayContent(part.state).flatMap((content) =>
|
|
2739
|
+
content.type === "file" &&
|
|
2740
|
+
content.mime.startsWith("image/") &&
|
|
2741
|
+
// An emptied `data:` URI is a payload the store dropped while previews were off.
|
|
2742
|
+
((content.uri.startsWith("data:image/") && !content.uri.endsWith(",")) || mediaHashFromUri(content.uri))
|
|
2743
|
+
? [{ uri: content.uri }]
|
|
2744
|
+
: [],
|
|
2745
|
+
)
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
type ToolProps = {
|
|
2749
|
+
input: Record<string, unknown>
|
|
2750
|
+
metadata: Record<string, unknown>
|
|
2751
|
+
tool: string
|
|
2752
|
+
output?: string
|
|
2753
|
+
part: SessionMessageAssistantTool
|
|
2754
|
+
}
|
|
2755
|
+
function GenericTool(props: ToolProps) {
|
|
2756
|
+
const theme = useTheme()
|
|
2757
|
+
const output = createMemo(() => stripAnsi(props.output?.trim() ?? ""))
|
|
2758
|
+
const input = createMemo(() => Object.entries(props.input))
|
|
2759
|
+
const [expanded, setExpanded] = createSignal(false)
|
|
2760
|
+
const expandable = createMemo(() => input().length > 0 || output().length > 0)
|
|
2761
|
+
const loading = createMemo(() => props.part.state.status === "streaming" || props.part.state.status === "running")
|
|
2762
|
+
|
|
2763
|
+
return (
|
|
2764
|
+
<>
|
|
2765
|
+
<InlineTool
|
|
2766
|
+
icon={props.part.state.status === "error" ? "✗" : "✓"}
|
|
2767
|
+
complete={props.part.state.status === "completed"}
|
|
2768
|
+
pending={props.tool}
|
|
2769
|
+
spinner={loading()}
|
|
2770
|
+
part={props.part}
|
|
2771
|
+
onClick={expandable() ? () => setExpanded((value) => !value) : undefined}
|
|
2772
|
+
>
|
|
2773
|
+
{genericToolSummary(props.tool, props.input)}
|
|
2774
|
+
</InlineTool>
|
|
2775
|
+
<Show when={expanded()}>
|
|
2776
|
+
<box paddingLeft={3 + INLINE_TOOL_ICON_WIDTH}>
|
|
2777
|
+
<For each={input()}>
|
|
2778
|
+
{([key, value]) => (
|
|
2779
|
+
<box flexDirection="row">
|
|
2780
|
+
<text flexShrink={0} fg={theme.text.muted}>
|
|
2781
|
+
{key}:{" "}
|
|
2782
|
+
</text>
|
|
2783
|
+
<text flexGrow={1} wrapMode="word" fg={theme.text.base}>
|
|
2784
|
+
{typeof value === "string" ? value : JSON.stringify(value, null, 2)}
|
|
2785
|
+
</text>
|
|
2786
|
+
</box>
|
|
2787
|
+
)}
|
|
2788
|
+
</For>
|
|
2789
|
+
<Show when={output()}>
|
|
2790
|
+
{(value) => (
|
|
2791
|
+
<box flexDirection="row">
|
|
2792
|
+
<text flexShrink={0} fg={theme.text.muted}>
|
|
2793
|
+
output:{" "}
|
|
2794
|
+
</text>
|
|
2795
|
+
<text flexGrow={1} fg={theme.text.base} wrapMode="word">
|
|
2796
|
+
{value()}
|
|
2797
|
+
</text>
|
|
2798
|
+
</box>
|
|
2799
|
+
)}
|
|
2800
|
+
</Show>
|
|
2801
|
+
</box>
|
|
2802
|
+
</Show>
|
|
2803
|
+
</>
|
|
2804
|
+
)
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
export function genericToolSummary(tool: string, input: Record<string, unknown>) {
|
|
2808
|
+
const args = primitiveInputSummary(input).replace(/\s+/g, " ")
|
|
2809
|
+
return `${tool}${args ? ` ${args}` : ""}`
|
|
2810
|
+
}
|
|
2811
|
+
|
|
2812
|
+
function useToolPermission(part: () => SessionMessageAssistantTool | undefined) {
|
|
2813
|
+
const ctx = use()
|
|
2814
|
+
const data = useData()
|
|
2815
|
+
const local = useLocal()
|
|
2816
|
+
return createMemo(() => {
|
|
2817
|
+
if (local.permission.mode === "autoaccept") return false
|
|
2818
|
+
const request = data.session.permission.list(ctx.sessionID)?.[0]
|
|
2819
|
+
return request?.source?.type === "tool" && request.source.id === part()?.id
|
|
2820
|
+
})
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
function InlineTool(props: {
|
|
2824
|
+
icon: string
|
|
2825
|
+
color?: RGBA
|
|
2826
|
+
complete: unknown
|
|
2827
|
+
pending: string
|
|
2828
|
+
spinner?: boolean
|
|
2829
|
+
running?: boolean
|
|
2830
|
+
status?: JSX.Element
|
|
2831
|
+
children: JSX.Element
|
|
2832
|
+
part: SessionMessageAssistantTool
|
|
2833
|
+
onClick?: () => void
|
|
2834
|
+
onErrorClick?: () => void
|
|
2835
|
+
}) {
|
|
2836
|
+
const theme = useTheme()
|
|
2837
|
+
const renderer = useRenderer()
|
|
2838
|
+
const [hover, setHover] = createSignal(false)
|
|
2839
|
+
const [errorExpanded, setErrorExpanded] = createSignal(false)
|
|
2840
|
+
const permission = useToolPermission(() => props.part)
|
|
2841
|
+
|
|
2842
|
+
const error = createMemo(() =>
|
|
2843
|
+
!props.running && props.part.state.status === "error" ? stripAnsi(props.part.state.error.message) : undefined,
|
|
2844
|
+
)
|
|
2845
|
+
|
|
2846
|
+
const denied = createMemo(
|
|
2847
|
+
() =>
|
|
2848
|
+
error()?.includes("QuestionRejectedError") ||
|
|
2849
|
+
error()?.includes("rejected permission") ||
|
|
2850
|
+
error()?.includes("specified a rule") ||
|
|
2851
|
+
error()?.includes("user dismissed"),
|
|
2852
|
+
)
|
|
2853
|
+
|
|
2854
|
+
const failed = createMemo(() => Boolean(error() && !denied()))
|
|
2855
|
+
const clickable = createMemo(() => Boolean(props.onClick || failed()))
|
|
2856
|
+
const fg = createMemo(() => {
|
|
2857
|
+
if (props.color) return props.color
|
|
2858
|
+
if (permission()) return theme.text.feedback.warning.base
|
|
2859
|
+
if (failed()) return theme.text.feedback.error.base
|
|
2860
|
+
if (hover() && props.onClick) return theme.text.base
|
|
2861
|
+
return theme.text.muted
|
|
2862
|
+
})
|
|
2863
|
+
|
|
2864
|
+
return (
|
|
2865
|
+
<InlineToolRow
|
|
2866
|
+
icon={props.icon}
|
|
2867
|
+
color={fg()}
|
|
2868
|
+
errorColor={theme.text.feedback.error.base}
|
|
2869
|
+
failed={failed()}
|
|
2870
|
+
denied={Boolean(denied())}
|
|
2871
|
+
error={error()}
|
|
2872
|
+
errorExpanded={errorExpanded()}
|
|
2873
|
+
complete={props.complete}
|
|
2874
|
+
pending={props.pending}
|
|
2875
|
+
spinner={props.spinner}
|
|
2876
|
+
status={props.status}
|
|
2877
|
+
onMouseOver={() => clickable() && setHover(true)}
|
|
2878
|
+
onMouseOut={() => setHover(false)}
|
|
2879
|
+
onMouseUp={() => {
|
|
2880
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
2881
|
+
if (failed()) {
|
|
2882
|
+
if (props.onErrorClick) return props.onErrorClick()
|
|
2883
|
+
setErrorExpanded((value) => !value)
|
|
2884
|
+
return
|
|
2885
|
+
}
|
|
2886
|
+
props.onClick?.()
|
|
2887
|
+
}}
|
|
2888
|
+
>
|
|
2889
|
+
{props.children}
|
|
2890
|
+
</InlineToolRow>
|
|
2891
|
+
)
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
function StatusBadge(props: { children: string; raised?: boolean }) {
|
|
2895
|
+
const theme = useTheme()
|
|
2896
|
+
const background = () => (props.raised ? theme.background.raised.base : theme.background.base)
|
|
2897
|
+
return (
|
|
2898
|
+
<text flexShrink={0} bg={theme.decrease(background())} fg={theme.text.muted}>
|
|
2899
|
+
{" "}
|
|
2900
|
+
{props.children}{" "}
|
|
2901
|
+
</text>
|
|
2902
|
+
)
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2905
|
+
type BlockToolProps = {
|
|
2906
|
+
title?: string
|
|
2907
|
+
path?: { label: string; value: string }
|
|
2908
|
+
headerColor?: RGBA
|
|
2909
|
+
children?: JSX.Element
|
|
2910
|
+
onClick?: () => void
|
|
2911
|
+
part?: SessionMessageAssistantTool
|
|
2912
|
+
spinner?: boolean
|
|
2913
|
+
error?: string
|
|
2914
|
+
errorColor?: RGBA
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
function BlockTool(props: BlockToolProps) {
|
|
2918
|
+
const theme = useTheme()
|
|
2919
|
+
const background = () => theme.background.raised.base
|
|
2920
|
+
const ctx = use()
|
|
2921
|
+
const renderer = useRenderer()
|
|
2922
|
+
const [hover, setHover] = createSignal(false)
|
|
2923
|
+
const error = createMemo(() =>
|
|
2924
|
+
stripAnsi(props.error ?? (props.part?.state.status === "error" ? props.part.state.error.message : "")),
|
|
2925
|
+
)
|
|
2926
|
+
const permission = useToolPermission(() => props.part)
|
|
2927
|
+
return (
|
|
2928
|
+
<box
|
|
2929
|
+
border={["left"]}
|
|
2930
|
+
flexShrink={0}
|
|
2931
|
+
paddingTop={1}
|
|
2932
|
+
paddingBottom={1}
|
|
2933
|
+
paddingLeft={2}
|
|
2934
|
+
paddingRight={2}
|
|
2935
|
+
gap={1}
|
|
2936
|
+
backgroundColor={hover() ? theme.decrease(background()) : background()}
|
|
2937
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
2938
|
+
borderColor={theme.background.base}
|
|
2939
|
+
onMouseOver={() => props.onClick && setHover(true)}
|
|
2940
|
+
onMouseOut={() => setHover(false)}
|
|
2941
|
+
onMouseUp={() => {
|
|
2942
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
2943
|
+
props.onClick?.()
|
|
2944
|
+
}}
|
|
2945
|
+
>
|
|
2946
|
+
<Show
|
|
2947
|
+
when={props.path}
|
|
2948
|
+
fallback={
|
|
2949
|
+
<Show when={props.title}>
|
|
2950
|
+
{(title) => (
|
|
2951
|
+
<Show
|
|
2952
|
+
when={props.spinner}
|
|
2953
|
+
fallback={
|
|
2954
|
+
<text
|
|
2955
|
+
fg={permission() ? theme.text.feedback.warning.base : (props.headerColor ?? theme.text.muted)}
|
|
2956
|
+
>
|
|
2957
|
+
{title()}
|
|
2958
|
+
</text>
|
|
2959
|
+
}
|
|
2960
|
+
>
|
|
2961
|
+
<Spinner color={permission() ? theme.text.feedback.warning.base : theme.text.muted}>
|
|
2962
|
+
{title().replace(/^# /, "")}
|
|
2963
|
+
</Spinner>
|
|
2964
|
+
</Show>
|
|
2965
|
+
)}
|
|
2966
|
+
</Show>
|
|
2967
|
+
}
|
|
2968
|
+
>
|
|
2969
|
+
{(path) => (
|
|
2970
|
+
<box flexDirection="row" gap={1} minWidth={0}>
|
|
2971
|
+
<Show
|
|
2972
|
+
when={props.spinner}
|
|
2973
|
+
fallback={
|
|
2974
|
+
<text
|
|
2975
|
+
flexShrink={0}
|
|
2976
|
+
fg={permission() ? theme.text.feedback.warning.base : (props.headerColor ?? theme.text.muted)}
|
|
2977
|
+
>
|
|
2978
|
+
{path().label}
|
|
2979
|
+
</text>
|
|
2980
|
+
}
|
|
2981
|
+
>
|
|
2982
|
+
<Spinner color={permission() ? theme.text.feedback.warning.base : theme.text.muted}>
|
|
2983
|
+
{path().label.replace(/^# /, "")}
|
|
2984
|
+
</Spinner>
|
|
2985
|
+
</Show>
|
|
2986
|
+
<FilePath
|
|
2987
|
+
value={path().value}
|
|
2988
|
+
maxWidth={Math.max(2, ctx.width - 6 - stringWidth(path().label) - (props.spinner ? 2 : 0))}
|
|
2989
|
+
fg={permission() ? theme.text.feedback.warning.base : (props.headerColor ?? theme.text.muted)}
|
|
2990
|
+
/>
|
|
2991
|
+
</box>
|
|
2992
|
+
)}
|
|
2993
|
+
</Show>
|
|
2994
|
+
{props.children}
|
|
2995
|
+
<Show when={error()}>
|
|
2996
|
+
<text fg={props.errorColor ?? theme.text.feedback.error.base}>{error()}</text>
|
|
2997
|
+
</Show>
|
|
2998
|
+
</box>
|
|
2999
|
+
)
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
const SHELL_DISPLAY_LIMIT = 1024 * 1024
|
|
3003
|
+
|
|
3004
|
+
function Shell(props: ToolProps) {
|
|
3005
|
+
const stopped = createMemo(() => stoppedShell(props.part, props.metadata))
|
|
3006
|
+
return (
|
|
3007
|
+
<ShellDisplay
|
|
3008
|
+
part={props.part}
|
|
3009
|
+
shellID={stringValue(props.metadata.shellID)}
|
|
3010
|
+
command={stringValue(props.input.command)}
|
|
3011
|
+
workdir={stringValue(props.input.workdir)}
|
|
3012
|
+
status={props.part.state.status}
|
|
3013
|
+
background={props.part.state.status === "completed" && props.metadata.status === "running"}
|
|
3014
|
+
output={stopped()?.output ?? (stringValue(props.metadata.shellID) ? undefined : props.output)}
|
|
3015
|
+
error={stopped()?.notice}
|
|
3016
|
+
/>
|
|
3017
|
+
)
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
// A call the user stopped fails with its output followed by a notice, which its metadata names. Its output shows like
|
|
3021
|
+
// a finished call's and only the notice as the error. A plugin that rewrote the error gets it shown as is.
|
|
3022
|
+
function stoppedShell(part: SessionMessageAssistantTool, metadata: Record<string, unknown>) {
|
|
3023
|
+
if (part.state.status !== "error" || metadata.interrupted !== true) return
|
|
3024
|
+
const notice = stringValue(metadata.notice)
|
|
3025
|
+
const message = part.state.error.message
|
|
3026
|
+
if (!notice || !message.endsWith(notice)) return
|
|
3027
|
+
return { output: message.slice(0, -notice.length).replace(/\n+$/, ""), notice }
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
function ShellDisplay(props: {
|
|
3031
|
+
part?: SessionMessageAssistantTool
|
|
3032
|
+
shellID?: string
|
|
3033
|
+
command?: string
|
|
3034
|
+
workdir?: string
|
|
3035
|
+
status: SessionMessageAssistantTool["state"]["status"]
|
|
3036
|
+
background?: boolean
|
|
3037
|
+
output?: string
|
|
3038
|
+
error?: string
|
|
3039
|
+
}) {
|
|
3040
|
+
const theme = useTheme()
|
|
3041
|
+
const ctx = use()
|
|
3042
|
+
const client = useClient()
|
|
3043
|
+
const data = useData()
|
|
3044
|
+
const pathFormatter = usePathFormatter()
|
|
3045
|
+
// A Session can move while its shell is still running in the original Location.
|
|
3046
|
+
const location = data.shell.get(props.shellID ?? "")?.location ?? data.session.get(ctx.sessionID)?.location
|
|
3047
|
+
const permission = useToolPermission(() => props.part)
|
|
3048
|
+
const color = createMemo(() => (permission() ? theme.text.feedback.warning.base : theme.text.base))
|
|
3049
|
+
const backgroundRunning = createMemo(() => {
|
|
3050
|
+
const id = props.shellID
|
|
3051
|
+
return Boolean(id && data.shell.get(id))
|
|
3052
|
+
})
|
|
3053
|
+
const isRunning = createMemo(() => props.status === "running" || backgroundRunning())
|
|
3054
|
+
const workdir = createMemo(() => pathFormatter.format(props.workdir))
|
|
3055
|
+
const [expanded, setExpanded] = createSignal(false)
|
|
3056
|
+
const [backgroundOutput, setBackgroundOutput] = createSignal("")
|
|
3057
|
+
const [outputTruncated, setOutputTruncated] = createSignal(false)
|
|
3058
|
+
let loading = false
|
|
3059
|
+
let drainRequested = false
|
|
3060
|
+
let cursor = 0
|
|
3061
|
+
let wasRunning = false
|
|
3062
|
+
const loadBackgroundOutput = async (drain = false) => {
|
|
3063
|
+
if (props.status === "completed" && props.output !== undefined) return
|
|
3064
|
+
const id = props.shellID
|
|
3065
|
+
if (!id) return
|
|
3066
|
+
if (loading) {
|
|
3067
|
+
if (drain) drainRequested = true
|
|
3068
|
+
return
|
|
3069
|
+
}
|
|
3070
|
+
loading = true
|
|
3071
|
+
do {
|
|
3072
|
+
const response = await client.api.shell
|
|
3073
|
+
.output({
|
|
3074
|
+
id,
|
|
3075
|
+
cursor,
|
|
3076
|
+
limit: SHELL_DISPLAY_LIMIT,
|
|
3077
|
+
location: location ? { directory: location.directory } : undefined,
|
|
3078
|
+
})
|
|
3079
|
+
.catch(() => undefined)
|
|
3080
|
+
if (!response) break
|
|
3081
|
+
if (response.data.output)
|
|
3082
|
+
setBackgroundOutput((output) => {
|
|
3083
|
+
const next = stripAnsi(output + response.data.output)
|
|
3084
|
+
if (next.length <= SHELL_DISPLAY_LIMIT) return next
|
|
3085
|
+
setOutputTruncated(true)
|
|
3086
|
+
return TextBoundary.tail(next, SHELL_DISPLAY_LIMIT)
|
|
3087
|
+
})
|
|
3088
|
+
if (response.data.cursor <= cursor) break
|
|
3089
|
+
cursor = response.data.cursor
|
|
3090
|
+
if (!drain || cursor >= response.data.size) break
|
|
3091
|
+
const tail = Math.max(cursor, response.data.size - SHELL_DISPLAY_LIMIT)
|
|
3092
|
+
if (tail > cursor) {
|
|
3093
|
+
cursor = tail
|
|
3094
|
+
setOutputTruncated(true)
|
|
3095
|
+
}
|
|
3096
|
+
} while (true)
|
|
3097
|
+
loading = false
|
|
3098
|
+
if (drainRequested) {
|
|
3099
|
+
drainRequested = false
|
|
3100
|
+
void loadBackgroundOutput(true)
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
createEffect(() => {
|
|
3104
|
+
const running = backgroundRunning()
|
|
3105
|
+
if (!running) {
|
|
3106
|
+
if (wasRunning) void loadBackgroundOutput(true)
|
|
3107
|
+
wasRunning = false
|
|
3108
|
+
return
|
|
3109
|
+
}
|
|
3110
|
+
wasRunning = true
|
|
3111
|
+
if (props.background && !expanded()) return
|
|
3112
|
+
void loadBackgroundOutput()
|
|
3113
|
+
const interval = setInterval(() => void loadBackgroundOutput(), 1_000)
|
|
3114
|
+
onCleanup(() => clearInterval(interval))
|
|
3115
|
+
})
|
|
3116
|
+
const output = createMemo(() => {
|
|
3117
|
+
if (props.status === "streaming") return ""
|
|
3118
|
+
if (props.shellID) {
|
|
3119
|
+
if (props.background && !expanded()) return ""
|
|
3120
|
+
if (props.status === "completed" && props.output !== undefined) return stripAnsi(props.output.trim())
|
|
3121
|
+
const text = stripAnsi((backgroundOutput() || props.output || "").trim())
|
|
3122
|
+
return outputTruncated() ? `[earlier output omitted]\n${text}` : text
|
|
3123
|
+
}
|
|
3124
|
+
return stripAnsi(props.output?.trim() ?? "")
|
|
3125
|
+
})
|
|
3126
|
+
const maxLines = 10
|
|
3127
|
+
const maxChars = createMemo(() => maxLines * Math.max(20, ctx.width - 8 - (isRunning() ? 2 : 0)))
|
|
3128
|
+
const prefix = createMemo(() => (workdir() && workdir() !== "." ? `cd ${workdir()} && ` : ""))
|
|
3129
|
+
const input = createMemo(() => (props.command ? `${isRunning() ? "" : "$ "}${prefix()}${props.command}` : ""))
|
|
3130
|
+
const collapsed = createMemo(() => collapseShellOutput(input(), output(), maxLines, maxChars()))
|
|
3131
|
+
const limitedInput = createMemo(() => (expanded() ? input() : collapsed().input))
|
|
3132
|
+
const limitedOutput = createMemo(() => (expanded() ? output() : collapsed().output))
|
|
3133
|
+
const expandable = createMemo(() => Boolean(props.shellID) || collapsed().overflow)
|
|
3134
|
+
const toggle = () => {
|
|
3135
|
+
const next = !expanded()
|
|
3136
|
+
setExpanded(next)
|
|
3137
|
+
if (next) void loadBackgroundOutput(!backgroundRunning())
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
return (
|
|
3141
|
+
<BlockTool part={props.part} error={props.error} onClick={expandable() ? toggle : undefined}>
|
|
3142
|
+
<box gap={1}>
|
|
3143
|
+
<Show
|
|
3144
|
+
when={props.command}
|
|
3145
|
+
fallback={
|
|
3146
|
+
isRunning() || props.status === "streaming" ? (
|
|
3147
|
+
<Spinner color={color()}>Writing command…</Spinner>
|
|
3148
|
+
) : (
|
|
3149
|
+
<text fg={theme.text.muted}>Writing command…</text>
|
|
3150
|
+
)
|
|
3151
|
+
}
|
|
3152
|
+
>
|
|
3153
|
+
<Show
|
|
3154
|
+
when={isRunning()}
|
|
3155
|
+
fallback={
|
|
3156
|
+
<text
|
|
3157
|
+
fg={theme.text.base}
|
|
3158
|
+
wrapMode={expanded() ? "word" : "char"}
|
|
3159
|
+
maxHeight={expanded() ? undefined : 2}
|
|
3160
|
+
>
|
|
3161
|
+
{limitedInput()}
|
|
3162
|
+
</text>
|
|
3163
|
+
}
|
|
3164
|
+
>
|
|
3165
|
+
<box flexDirection="row" gap={1}>
|
|
3166
|
+
<Spinner color={color()} />
|
|
3167
|
+
<text
|
|
3168
|
+
fg={color()}
|
|
3169
|
+
wrapMode={expanded() ? "word" : "char"}
|
|
3170
|
+
maxHeight={expanded() ? undefined : 2}
|
|
3171
|
+
flexGrow={1}
|
|
3172
|
+
minWidth={0}
|
|
3173
|
+
>
|
|
3174
|
+
{limitedInput()}
|
|
3175
|
+
</text>
|
|
3176
|
+
</box>
|
|
3177
|
+
</Show>
|
|
3178
|
+
<Show when={limitedOutput()}>
|
|
3179
|
+
<text fg={theme.text.muted}>{limitedOutput()}</text>
|
|
3180
|
+
</Show>
|
|
3181
|
+
</Show>
|
|
3182
|
+
<Show when={props.background}>
|
|
3183
|
+
<StatusBadge raised>Background</StatusBadge>
|
|
3184
|
+
</Show>
|
|
3185
|
+
</box>
|
|
3186
|
+
</BlockTool>
|
|
3187
|
+
)
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
function Write(props: ToolProps) {
|
|
3191
|
+
const theme = useTheme()
|
|
3192
|
+
const { currentSyntax: syntax } = useThemes()
|
|
3193
|
+
const pathFormatter = usePathFormatter()
|
|
3194
|
+
const code = createMemo(() => {
|
|
3195
|
+
return stringValue(props.input.content) ?? ""
|
|
3196
|
+
})
|
|
3197
|
+
|
|
3198
|
+
return (
|
|
3199
|
+
<Switch>
|
|
3200
|
+
<Match when={props.part.state.status === "completed"}>
|
|
3201
|
+
<BlockTool
|
|
3202
|
+
path={{ label: "# Wrote", value: pathFormatter.format(stringValue(props.input.path)) }}
|
|
3203
|
+
part={props.part}
|
|
3204
|
+
>
|
|
3205
|
+
<line_number fg={theme.text.muted} minWidth={3} paddingRight={1}>
|
|
3206
|
+
<code
|
|
3207
|
+
conceal={false}
|
|
3208
|
+
fg={theme.text.base}
|
|
3209
|
+
filetype={filetype(stringValue(props.input.path))}
|
|
3210
|
+
syntaxStyle={syntax()}
|
|
3211
|
+
content={code()}
|
|
3212
|
+
/>
|
|
3213
|
+
</line_number>
|
|
3214
|
+
<Diagnostics diagnostics={props.metadata.diagnostics} filePath={stringValue(props.input.path) ?? ""} />
|
|
3215
|
+
</BlockTool>
|
|
3216
|
+
</Match>
|
|
3217
|
+
<Match when={true}>
|
|
3218
|
+
<InlineTool icon="←" pending="Preparing write…" complete={stringValue(props.input.path)} part={props.part}>
|
|
3219
|
+
Write {pathFormatter.format(stringValue(props.input.path))}
|
|
3220
|
+
</InlineTool>
|
|
3221
|
+
</Match>
|
|
3222
|
+
</Switch>
|
|
3223
|
+
)
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
function Glob(props: ToolProps) {
|
|
3227
|
+
const pathFormatter = usePathFormatter()
|
|
3228
|
+
return (
|
|
3229
|
+
<InlineTool icon="✱" pending="Finding files…" complete={stringValue(props.input.pattern)} part={props.part}>
|
|
3230
|
+
Glob "{stringValue(props.input.pattern)}"{" "}
|
|
3231
|
+
<Show when={stringValue(props.input.path)}>in {pathFormatter.format(stringValue(props.input.path))} </Show>
|
|
3232
|
+
<Show when={finiteNumber(props.metadata.count)}>
|
|
3233
|
+
({finiteNumber(props.metadata.count)} {finiteNumber(props.metadata.count) === 1 ? "match" : "matches"})
|
|
3234
|
+
</Show>
|
|
3235
|
+
</InlineTool>
|
|
3236
|
+
)
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3239
|
+
function Read(props: ToolProps) {
|
|
3240
|
+
const theme = useTheme()
|
|
3241
|
+
const pathFormatter = usePathFormatter()
|
|
3242
|
+
const isRunning = createMemo(() => props.part.state.status === "running")
|
|
3243
|
+
const loaded = createMemo(() => {
|
|
3244
|
+
if (props.part.state.status !== "completed") return []
|
|
3245
|
+
const value = props.metadata.loaded
|
|
3246
|
+
if (!value || !Array.isArray(value)) return []
|
|
3247
|
+
return value.filter((p): p is string => typeof p === "string")
|
|
3248
|
+
})
|
|
3249
|
+
return (
|
|
3250
|
+
<>
|
|
3251
|
+
<InlineTool
|
|
3252
|
+
icon="→"
|
|
3253
|
+
pending="Reading file…"
|
|
3254
|
+
complete={stringValue(props.input.path)}
|
|
3255
|
+
spinner={isRunning()}
|
|
3256
|
+
part={props.part}
|
|
3257
|
+
>
|
|
3258
|
+
Read {pathFormatter.format(stringValue(props.input.path))}
|
|
3259
|
+
<Show when={props.input.offset !== undefined || props.input.limit !== undefined}>
|
|
3260
|
+
:{finiteNumber(props.input.offset) || 1}-
|
|
3261
|
+
{props.input.limit ? (finiteNumber(props.input.offset) || 1) + (finiteNumber(props.input.limit) || 0) - 1 : ""}
|
|
3262
|
+
</Show>
|
|
3263
|
+
</InlineTool>
|
|
3264
|
+
<For each={loaded()}>
|
|
3265
|
+
{(filepath) => (
|
|
3266
|
+
<box paddingLeft={3}>
|
|
3267
|
+
<text fg={theme.text.muted}>
|
|
3268
|
+
↳ Loaded {pathFormatter.format(filepath)}
|
|
3269
|
+
</text>
|
|
3270
|
+
</box>
|
|
3271
|
+
)}
|
|
3272
|
+
</For>
|
|
3273
|
+
</>
|
|
3274
|
+
)
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
function Grep(props: ToolProps) {
|
|
3278
|
+
const pathFormatter = usePathFormatter()
|
|
3279
|
+
return (
|
|
3280
|
+
<InlineTool icon="✱" pending="Searching content…" complete={stringValue(props.input.pattern)} part={props.part}>
|
|
3281
|
+
Grep "{stringValue(props.input.pattern)}"{" "}
|
|
3282
|
+
<Show when={stringValue(props.input.path)}>in {pathFormatter.format(stringValue(props.input.path))} </Show>
|
|
3283
|
+
<Show when={finiteNumber(props.metadata.matches)}>
|
|
3284
|
+
({finiteNumber(props.metadata.matches)} {finiteNumber(props.metadata.matches) === 1 ? "match" : "matches"})
|
|
3285
|
+
</Show>
|
|
3286
|
+
</InlineTool>
|
|
3287
|
+
)
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3290
|
+
function WebFetch(props: ToolProps) {
|
|
3291
|
+
return (
|
|
3292
|
+
<InlineTool icon="%" pending="Fetching from the web…" complete={stringValue(props.input.url)} part={props.part}>
|
|
3293
|
+
WebFetch {stringValue(props.input.url)}
|
|
3294
|
+
</InlineTool>
|
|
3295
|
+
)
|
|
3296
|
+
}
|
|
3297
|
+
|
|
3298
|
+
function WebSearch(props: ToolProps) {
|
|
3299
|
+
const ctx = use()
|
|
3300
|
+
const provider = createMemo(() => stringValue(props.metadata.provider))
|
|
3301
|
+
return (
|
|
3302
|
+
<InlineTool icon="◈" pending="Searching web…" complete={stringValue(props.input.query)} part={props.part}>
|
|
3303
|
+
<Show when={provider()} fallback="Web Search">
|
|
3304
|
+
{(value) => (
|
|
3305
|
+
<>
|
|
3306
|
+
Web Search via{" "}
|
|
3307
|
+
<RetryProvider
|
|
3308
|
+
value={{
|
|
3309
|
+
id: `${ctx.sessionID}:${props.part.time.created}:${props.part.id}`,
|
|
3310
|
+
provider: value(),
|
|
3311
|
+
running: props.part.state.status === "running",
|
|
3312
|
+
}}
|
|
3313
|
+
enabled={ctx.config.animations ?? true}
|
|
3314
|
+
/>
|
|
3315
|
+
</>
|
|
3316
|
+
)}
|
|
3317
|
+
</Show>{" "}
|
|
3318
|
+
"{stringValue(props.input.query)}"
|
|
3319
|
+
</InlineTool>
|
|
3320
|
+
)
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
function Subagent(props: ToolProps) {
|
|
3324
|
+
const { navigate } = useRoute()
|
|
3325
|
+
const data = useData()
|
|
3326
|
+
const sessionID = createMemo(
|
|
3327
|
+
() =>
|
|
3328
|
+
stringValue(props.metadata.sessionID) ??
|
|
3329
|
+
stringValue(props.metadata.sessionId) ??
|
|
3330
|
+
// A failed continuation may name an unrelated session, such as the parent itself.
|
|
3331
|
+
(props.part.state.status === "error" ? undefined : stringValue(props.input.sessionID)),
|
|
3332
|
+
)
|
|
3333
|
+
const description = createMemo(() => stringValue(props.input.description))
|
|
3334
|
+
const continuation = createMemo(() => Boolean(stringValue(props.input.sessionID)))
|
|
3335
|
+
const model = createMemo(() => subagentModelLabel(stringValue(props.input.model), data.location.model.list()))
|
|
3336
|
+
const isRunning = createMemo(() => {
|
|
3337
|
+
const id = sessionID()
|
|
3338
|
+
return props.part.state.status === "running" || Boolean(id && data.session.status(id) === "running")
|
|
3339
|
+
})
|
|
3340
|
+
|
|
3341
|
+
return (
|
|
3342
|
+
<InlineTool
|
|
3343
|
+
icon={isRunning() ? "│" : continuation() ? "↳" : props.part.state.status === "completed" ? "✓" : "│"}
|
|
3344
|
+
spinner={isRunning()}
|
|
3345
|
+
running={isRunning()}
|
|
3346
|
+
complete={description()}
|
|
3347
|
+
pending="Delegating…"
|
|
3348
|
+
part={props.part}
|
|
3349
|
+
onClick={() => {
|
|
3350
|
+
const id = sessionID()
|
|
3351
|
+
if (id) navigate({ type: "session", sessionID: id })
|
|
3352
|
+
}}
|
|
3353
|
+
>
|
|
3354
|
+
{`${continuation() ? "Continue subagent" : `${Locale.titlecase(stringValue(props.input.agent) ?? stringValue(props.input.subagent_type) ?? "General")} Subagent`} — ${description() ?? "Subagent"}${model() ? ` · ${model()}` : ""}`}
|
|
3355
|
+
</InlineTool>
|
|
3356
|
+
)
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
export function subagentModelLabel(
|
|
3360
|
+
value: string | undefined,
|
|
3361
|
+
models: readonly Pick<ModelInfo, "providerID" | "id" | "name">[] | undefined,
|
|
3362
|
+
) {
|
|
3363
|
+
if (!value) return
|
|
3364
|
+
const [reference, variant] = value.split("#")
|
|
3365
|
+
const separator = reference.indexOf("/")
|
|
3366
|
+
const providerID = separator === -1 ? "" : reference.slice(0, separator)
|
|
3367
|
+
const modelID = separator === -1 ? reference : reference.slice(separator + 1)
|
|
3368
|
+
const name = models?.find((item) => item.providerID === providerID && item.id === modelID)?.name
|
|
3369
|
+
return `${name ?? reference}${variant ? ` (${variant})` : ""}`
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3372
|
+
export { executeCallSummary }
|
|
3373
|
+
|
|
3374
|
+
function ExecuteCallView(props: { call: Accessor<ExecuteCall> }) {
|
|
3375
|
+
const theme = useTheme()
|
|
3376
|
+
const renderer = useRenderer()
|
|
3377
|
+
const [expanded, setExpanded] = createSignal(false)
|
|
3378
|
+
const [hover, setHover] = createSignal(false)
|
|
3379
|
+
const input = createMemo(() => Object.entries(props.call().input ?? {}))
|
|
3380
|
+
const expandable = createMemo(() => input().length > 0)
|
|
3381
|
+
const expandedColor = createMemo(() => theme.decrease(theme.text.muted))
|
|
3382
|
+
const color = createMemo(() => {
|
|
3383
|
+
if (props.call().status === "error") return theme.text.feedback.error.base
|
|
3384
|
+
if (hover()) return theme.text.base
|
|
3385
|
+
return expanded() ? expandedColor() : theme.text.muted
|
|
3386
|
+
})
|
|
3387
|
+
|
|
3388
|
+
return (
|
|
3389
|
+
<box
|
|
3390
|
+
paddingLeft={3}
|
|
3391
|
+
onMouseOver={() => expandable() && setHover(true)}
|
|
3392
|
+
onMouseOut={() => setHover(false)}
|
|
3393
|
+
onMouseUp={() => {
|
|
3394
|
+
if (!expandable() || renderer.getSelection()?.getSelectedText()) return
|
|
3395
|
+
setExpanded((value) => !value)
|
|
3396
|
+
}}
|
|
3397
|
+
>
|
|
3398
|
+
<box flexDirection="row">
|
|
3399
|
+
<box width={INLINE_TOOL_ICON_WIDTH} flexShrink={0}>
|
|
3400
|
+
<text fg={color()}>{props.call().status === "error" ? "✗" : "›"}</text>
|
|
3401
|
+
</box>
|
|
3402
|
+
<text flexGrow={1} wrapMode="none" truncate fg={color()}>
|
|
3403
|
+
{expanded() ? props.call().tool : executeCallSummary(props.call())}
|
|
3404
|
+
</text>
|
|
3405
|
+
</box>
|
|
3406
|
+
<Show when={expanded()}>
|
|
3407
|
+
<box paddingLeft={1} border={["left"]} borderColor={expandedColor()}>
|
|
3408
|
+
<For each={input()}>
|
|
3409
|
+
{([key, value]) => (
|
|
3410
|
+
<box flexDirection="row">
|
|
3411
|
+
<text flexShrink={0} fg={theme.text.muted}>
|
|
3412
|
+
{key}:{" "}
|
|
3413
|
+
</text>
|
|
3414
|
+
<text flexGrow={1} wrapMode="word" fg={theme.text.base}>
|
|
3415
|
+
{typeof value === "string" ? value : JSON.stringify(value, null, 2)}
|
|
3416
|
+
</text>
|
|
3417
|
+
</box>
|
|
3418
|
+
)}
|
|
3419
|
+
</For>
|
|
3420
|
+
</box>
|
|
3421
|
+
</Show>
|
|
3422
|
+
</box>
|
|
3423
|
+
)
|
|
3424
|
+
}
|
|
3425
|
+
|
|
3426
|
+
// The `execute` tool streams child tool calls through metadata, not a child session like Task.
|
|
3427
|
+
function Execute(props: ToolProps) {
|
|
3428
|
+
const ctx = use()
|
|
3429
|
+
const theme = useTheme()
|
|
3430
|
+
const dialog = useDialog()
|
|
3431
|
+
const isLoading = createMemo(() => props.part.state.status === "streaming" || props.part.state.status === "running")
|
|
3432
|
+
const calls = createMemo(() => executeCalls(props.metadata.toolCalls))
|
|
3433
|
+
// One block per change a script made, in order; a change past the size cap or to a binary file has no patch.
|
|
3434
|
+
const files = createMemo(() => parseScriptChanges(props.metadata.files))
|
|
3435
|
+
const output = createMemo(() => stripAnsi(props.output?.trim() ?? ""))
|
|
3436
|
+
const hasRuntimeError = createMemo(() => props.metadata.error === true || props.part.state.status === "error")
|
|
3437
|
+
const outputPreview = createMemo(() => collapseToolOutput(output(), 4, 4 * Math.max(20, ctx.width - 6)).output)
|
|
3438
|
+
const showOutput = createMemo(() => output() && hasRuntimeError())
|
|
3439
|
+
const openDetails = () => {
|
|
3440
|
+
// The dialog outlives this row, whose props go stale when a resync drops the message.
|
|
3441
|
+
const part = props.part
|
|
3442
|
+
dialog.replace(() => <DialogExecute part={part} />)
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
return (
|
|
3446
|
+
<>
|
|
3447
|
+
<InlineTool
|
|
3448
|
+
icon={hasRuntimeError() ? "✗" : props.part.state.status === "completed" ? "✓" : "│"}
|
|
3449
|
+
color={hasRuntimeError() ? theme.text.feedback.error.base : undefined}
|
|
3450
|
+
spinner={isLoading()}
|
|
3451
|
+
pending="execute"
|
|
3452
|
+
complete={true}
|
|
3453
|
+
part={props.part}
|
|
3454
|
+
onClick={openDetails}
|
|
3455
|
+
onErrorClick={openDetails}
|
|
3456
|
+
>
|
|
3457
|
+
execute
|
|
3458
|
+
</InlineTool>
|
|
3459
|
+
<Index each={calls()}>{(call) => <ExecuteCallView call={call} />}</Index>
|
|
3460
|
+
<Show when={showOutput()}>
|
|
3461
|
+
<box paddingLeft={3}>
|
|
3462
|
+
<For each={outputPreview().split("\n")}>
|
|
3463
|
+
{(line, index) => (
|
|
3464
|
+
<text fg={theme.text.feedback.error.base}>
|
|
3465
|
+
{index() === 0 ? "↳ " : " "}
|
|
3466
|
+
{line}
|
|
3467
|
+
</text>
|
|
3468
|
+
)}
|
|
3469
|
+
</For>
|
|
3470
|
+
</box>
|
|
3471
|
+
</Show>
|
|
3472
|
+
<Show when={files().length > 0}>
|
|
3473
|
+
<box marginTop={1}>
|
|
3474
|
+
<PatchedFiles files={files()} />
|
|
3475
|
+
</box>
|
|
3476
|
+
</Show>
|
|
3477
|
+
</>
|
|
3478
|
+
)
|
|
3479
|
+
}
|
|
3480
|
+
|
|
3481
|
+
function Edit(props: ToolProps) {
|
|
3482
|
+
const ctx = use()
|
|
3483
|
+
const theme = useTheme()
|
|
3484
|
+
const { currentSyntax: syntax } = useThemes()
|
|
3485
|
+
const pathFormatter = usePathFormatter()
|
|
3486
|
+
|
|
3487
|
+
const view = createMemo(() => {
|
|
3488
|
+
const diffView = ctx.config.diffs?.view
|
|
3489
|
+
if (diffView === "unified") return "unified"
|
|
3490
|
+
if (diffView === "split") return "split"
|
|
3491
|
+
// Default to "auto" behavior
|
|
3492
|
+
return ctx.width > 120 ? "split" : "unified"
|
|
3493
|
+
})
|
|
3494
|
+
|
|
3495
|
+
const file = createMemo(() => parseApplyPatchFiles(props.metadata.files)[0])
|
|
3496
|
+
const path = createMemo(() => file()?.relativePath ?? stringValue(props.input.path))
|
|
3497
|
+
|
|
3498
|
+
return (
|
|
3499
|
+
<Switch>
|
|
3500
|
+
<Match when={file()}>
|
|
3501
|
+
{(item) => (
|
|
3502
|
+
<BlockTool path={{ label: "← Edit", value: pathFormatter.format(path()) }} part={props.part}>
|
|
3503
|
+
<box paddingLeft={1} paddingRight={1}>
|
|
3504
|
+
<PatchDiff
|
|
3505
|
+
diff={item().patch}
|
|
3506
|
+
hunkFg={theme.diff.text.hunkHeader}
|
|
3507
|
+
view={view()}
|
|
3508
|
+
filetype={filetype(path())}
|
|
3509
|
+
syntaxStyle={syntax()}
|
|
3510
|
+
showLineNumbers={true}
|
|
3511
|
+
width="100%"
|
|
3512
|
+
wrapMode={ctx.diffWrapMode()}
|
|
3513
|
+
fg={theme.text.base}
|
|
3514
|
+
addedBg={theme.diff.background.added}
|
|
3515
|
+
removedBg={theme.diff.background.removed}
|
|
3516
|
+
contextBg={theme.diff.background.context}
|
|
3517
|
+
addedSignColor={theme.diff.highlight.added}
|
|
3518
|
+
removedSignColor={theme.diff.highlight.removed}
|
|
3519
|
+
lineNumberFg={theme.diff.lineNumber.text}
|
|
3520
|
+
lineNumberBg={theme.diff.background.context}
|
|
3521
|
+
addedLineNumberBg={theme.diff.lineNumber.background.added}
|
|
3522
|
+
removedLineNumberBg={theme.diff.lineNumber.background.removed}
|
|
3523
|
+
/>
|
|
3524
|
+
</box>
|
|
3525
|
+
<Diagnostics diagnostics={props.metadata.diagnostics} filePath={stringValue(props.input.path) ?? ""} />
|
|
3526
|
+
</BlockTool>
|
|
3527
|
+
)}
|
|
3528
|
+
</Match>
|
|
3529
|
+
<Match when={true}>
|
|
3530
|
+
<BlockTool
|
|
3531
|
+
path={
|
|
3532
|
+
stringValue(props.input.path)
|
|
3533
|
+
? { label: "← Edit", value: pathFormatter.format(stringValue(props.input.path)) }
|
|
3534
|
+
: undefined
|
|
3535
|
+
}
|
|
3536
|
+
title={stringValue(props.input.path) ? undefined : "# Preparing edit…"}
|
|
3537
|
+
part={props.part}
|
|
3538
|
+
spinner={props.part.state.status === "streaming"}
|
|
3539
|
+
/>
|
|
3540
|
+
</Match>
|
|
3541
|
+
</Switch>
|
|
3542
|
+
)
|
|
3543
|
+
}
|
|
3544
|
+
|
|
3545
|
+
function ApplyPatch(props: ToolProps) {
|
|
3546
|
+
const ctx = use()
|
|
3547
|
+
const theme = useTheme()
|
|
3548
|
+
const pathFormatter = usePathFormatter()
|
|
3549
|
+
const files = createMemo(() => parseApplyPatchFiles(props.metadata.files))
|
|
3550
|
+
const targets = createMemo(() => {
|
|
3551
|
+
const patch = stringValue(props.input.patchText)
|
|
3552
|
+
if (!patch) return []
|
|
3553
|
+
return [...patch.matchAll(/\*\*\* (?:Add|Update|Delete) File: ([^\r\n]+)/g)].map((match) => match[1].trim())
|
|
3554
|
+
})
|
|
3555
|
+
const applied = createMemo(() => {
|
|
3556
|
+
const applied = props.metadata.applied
|
|
3557
|
+
if (!Array.isArray(applied)) return []
|
|
3558
|
+
return applied.flatMap((value) => {
|
|
3559
|
+
const item = recordValue(value)
|
|
3560
|
+
const type = stringValue(item?.type)
|
|
3561
|
+
const resource = stringValue(item?.resource)
|
|
3562
|
+
return type && resource ? [{ type, resource }] : []
|
|
3563
|
+
})
|
|
3564
|
+
})
|
|
3565
|
+
return (
|
|
3566
|
+
<Switch>
|
|
3567
|
+
<Match when={files().length > 0}>
|
|
3568
|
+
<PatchedFiles files={files()} part={props.part} />
|
|
3569
|
+
</Match>
|
|
3570
|
+
<Match when={applied().length > 0}>
|
|
3571
|
+
<box flexDirection="column" gap={1}>
|
|
3572
|
+
<For each={applied()}>
|
|
3573
|
+
{(file) => (
|
|
3574
|
+
<BlockTool
|
|
3575
|
+
path={{
|
|
3576
|
+
label: file.type === "add" ? "# Created" : file.type === "delete" ? "# Deleted" : "← Patched",
|
|
3577
|
+
value: pathFormatter.format(file.resource),
|
|
3578
|
+
}}
|
|
3579
|
+
part={props.part}
|
|
3580
|
+
>
|
|
3581
|
+
<FilePath
|
|
3582
|
+
value={file.resource}
|
|
3583
|
+
maxWidth={Math.max(2, ctx.width - 5)}
|
|
3584
|
+
fg={file.type === "delete" ? theme.diff.text.removed : theme.text.muted}
|
|
3585
|
+
/>
|
|
3586
|
+
</BlockTool>
|
|
3587
|
+
)}
|
|
3588
|
+
</For>
|
|
3589
|
+
</box>
|
|
3590
|
+
</Match>
|
|
3591
|
+
<Match when={true}>
|
|
3592
|
+
<BlockTool
|
|
3593
|
+
path={
|
|
3594
|
+
targets().length === 1
|
|
3595
|
+
? {
|
|
3596
|
+
label: props.part.state.status === "error" ? "# Patch failed" : "Patching",
|
|
3597
|
+
value: pathFormatter.format(targets()[0]),
|
|
3598
|
+
}
|
|
3599
|
+
: undefined
|
|
3600
|
+
}
|
|
3601
|
+
title={
|
|
3602
|
+
targets().length === 1 ? undefined : props.part.state.status === "error" ? "# Patch failed" : "Patching"
|
|
3603
|
+
}
|
|
3604
|
+
part={props.part}
|
|
3605
|
+
spinner={props.part.state.status === "streaming" || props.part.state.status === "running"}
|
|
3606
|
+
headerColor={props.part.state.status === "error" ? theme.text.feedback.error.base : undefined}
|
|
3607
|
+
errorColor={props.part.state.status === "error" ? theme.text.muted : undefined}
|
|
3608
|
+
/>
|
|
3609
|
+
</Match>
|
|
3610
|
+
</Switch>
|
|
3611
|
+
)
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
function TodoWrite(props: ToolProps) {
|
|
3615
|
+
const theme = useTheme()
|
|
3616
|
+
const todos = createMemo(() => parseTodos(props.input.todos))
|
|
3617
|
+
return (
|
|
3618
|
+
<Switch>
|
|
3619
|
+
<Match when={props.part.state.status === "completed" && todos().length > 0}>
|
|
3620
|
+
<BlockTool title="# Todos" part={props.part}>
|
|
3621
|
+
<box>
|
|
3622
|
+
<For each={todos()}>{(todo) => <TodoItem theme={theme} todo={todo} />}</For>
|
|
3623
|
+
</box>
|
|
3624
|
+
</BlockTool>
|
|
3625
|
+
</Match>
|
|
3626
|
+
<Match when={true}>
|
|
3627
|
+
<InlineTool
|
|
3628
|
+
icon="⚙"
|
|
3629
|
+
pending="Updating todos…"
|
|
3630
|
+
complete={props.part.state.status === "completed" || props.part.state.status === "error"}
|
|
3631
|
+
part={props.part}
|
|
3632
|
+
>
|
|
3633
|
+
{props.part.state.status === "error" ? "Todo update failed" : "Cleared todos"}
|
|
3634
|
+
</InlineTool>
|
|
3635
|
+
</Match>
|
|
3636
|
+
</Switch>
|
|
3637
|
+
)
|
|
3638
|
+
}
|
|
3639
|
+
|
|
3640
|
+
function Question(props: ToolProps) {
|
|
3641
|
+
const theme = useTheme()
|
|
3642
|
+
const questions = createMemo(() => parseQuestions(props.input.questions))
|
|
3643
|
+
const answers = createMemo(() => parseQuestionAnswers(props.metadata.answers))
|
|
3644
|
+
const count = createMemo(() => questions().length)
|
|
3645
|
+
|
|
3646
|
+
function format(answer?: ReadonlyArray<string>) {
|
|
3647
|
+
if (!answer?.length) return "(no answer)"
|
|
3648
|
+
return answer.join(", ")
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
return (
|
|
3652
|
+
<Switch>
|
|
3653
|
+
<Match when={answers()}>
|
|
3654
|
+
<BlockTool title="# Questions" part={props.part}>
|
|
3655
|
+
<box gap={1}>
|
|
3656
|
+
<For each={questions()}>
|
|
3657
|
+
{(q, i) => (
|
|
3658
|
+
<box flexDirection="column">
|
|
3659
|
+
<text fg={theme.text.muted}>{q.question}</text>
|
|
3660
|
+
<text fg={theme.text.base}>{format(answers()?.[i()])}</text>
|
|
3661
|
+
</box>
|
|
3662
|
+
)}
|
|
3663
|
+
</For>
|
|
3664
|
+
</box>
|
|
3665
|
+
</BlockTool>
|
|
3666
|
+
</Match>
|
|
3667
|
+
<Match when={true}>
|
|
3668
|
+
<InlineTool icon="→" pending="Asking questions…" complete={count()} part={props.part}>
|
|
3669
|
+
Asked {count()} question{count() !== 1 ? "s" : ""}
|
|
3670
|
+
</InlineTool>
|
|
3671
|
+
</Match>
|
|
3672
|
+
</Switch>
|
|
3673
|
+
)
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3676
|
+
function Skill(props: ToolProps) {
|
|
3677
|
+
const name = createMemo(() => stringValue(props.metadata.name) ?? stringValue(props.input.id))
|
|
3678
|
+
return (
|
|
3679
|
+
<InlineTool icon="→" pending="Loading skill…" complete={name()} part={props.part}>
|
|
3680
|
+
Skill "{name()}"
|
|
3681
|
+
</InlineTool>
|
|
3682
|
+
)
|
|
3683
|
+
}
|
|
3684
|
+
|
|
3685
|
+
function Diagnostics(props: { diagnostics: unknown; filePath: string }) {
|
|
3686
|
+
const theme = useTheme()
|
|
3687
|
+
const terminalEnvironment = useTuiTerminalEnvironment()
|
|
3688
|
+
const errors = createMemo(() => {
|
|
3689
|
+
const normalized = normalizePath(
|
|
3690
|
+
typeof props.filePath === "string" ? props.filePath : "",
|
|
3691
|
+
terminalEnvironment.platform,
|
|
3692
|
+
)
|
|
3693
|
+
return parseDiagnostics(props.diagnostics, normalized)
|
|
3694
|
+
})
|
|
3695
|
+
|
|
3696
|
+
return (
|
|
3697
|
+
<Show when={errors().length}>
|
|
3698
|
+
<box>
|
|
3699
|
+
<For each={errors()}>
|
|
3700
|
+
{(diagnostic) => (
|
|
3701
|
+
<text fg={theme.text.feedback.error.base}>
|
|
3702
|
+
Error [{diagnostic.range.start.line + 1}:{diagnostic.range.start.character + 1}] {diagnostic.message}
|
|
3703
|
+
</text>
|
|
3704
|
+
)}
|
|
3705
|
+
</For>
|
|
3706
|
+
</box>
|
|
3707
|
+
</Show>
|
|
3708
|
+
)
|
|
3709
|
+
}
|
|
3710
|
+
|
|
3711
|
+
function stringValue(value: unknown) {
|
|
3712
|
+
return typeof value === "string" ? value : undefined
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
function recordValue(value: unknown): Record<string, unknown> | undefined {
|
|
3716
|
+
return isRecord(value) ? value : undefined
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
function formatSessionTranscript(
|
|
3720
|
+
session: SessionInfo,
|
|
3721
|
+
messages: SessionMessageInfo[],
|
|
3722
|
+
thinking: boolean,
|
|
3723
|
+
tools = true,
|
|
3724
|
+
) {
|
|
3725
|
+
const body = messages.flatMap((message) => {
|
|
3726
|
+
if (message.type === "user") return [`## User\n\n${message.text}`]
|
|
3727
|
+
if (message.type === "shell")
|
|
3728
|
+
return [`## Shell\n\n\`\`\`\n$ ${message.command}\n${message.output?.output ?? ""}\n\`\`\``]
|
|
3729
|
+
if (message.type !== "assistant") return []
|
|
3730
|
+
const content = message.content.flatMap((item) => {
|
|
3731
|
+
if (item.type === "text") return [item.text]
|
|
3732
|
+
if (item.type === "reasoning") return thinking ? [`_Thinking:_\n\n${item.text}`] : []
|
|
3733
|
+
if (!tools) return []
|
|
3734
|
+
const input = typeof item.state.input === "string" ? item.state.input : JSON.stringify(item.state.input, null, 2)
|
|
3735
|
+
const output =
|
|
3736
|
+
item.state.status === "error"
|
|
3737
|
+
? item.state.error.message
|
|
3738
|
+
: item.state.status === "streaming"
|
|
3739
|
+
? ""
|
|
3740
|
+
: toolDisplayContent(item.state)
|
|
3741
|
+
.flatMap((entry) => (entry.type === "text" ? [entry.text] : [entry.name ?? entry.uri]))
|
|
3742
|
+
.join("\n")
|
|
3743
|
+
return [`**Tool: ${item.name}**\n\n**Input:**\n\`\`\`json\n${input}\n\`\`\`\n\n${output}`]
|
|
3744
|
+
})
|
|
3745
|
+
if (content.length === 0) return []
|
|
3746
|
+
return [`## Assistant\n\n${content.join("\n\n")}`]
|
|
3747
|
+
})
|
|
3748
|
+
return `# ${withTimestampedFallback(session)}\n\n**Session ID:** ${session.id}\n**Created:** ${new Date(session.time.created).toLocaleString()}\n**Updated:** ${new Date(session.time.updated).toLocaleString()}\n\n---\n\n${body.join("\n\n---\n\n")}\n`
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
// Files a patch, or a Code Mode script, changed: one block per change with its diff, or its counts when the diff is
|
|
3752
|
+
// missing (a deleted file, or a script's change past the size cap). A change without counts shows only its path.
|
|
3753
|
+
// Blocks are kept by position, so a running script's stay put as its changes arrive.
|
|
3754
|
+
// A script's error and permission request stay on its own row, so its changes take no part.
|
|
3755
|
+
function PatchedFiles(props: { files: ReturnType<typeof parseScriptChanges>; part?: ToolProps["part"] }) {
|
|
3756
|
+
const ctx = use()
|
|
3757
|
+
const theme = useTheme()
|
|
3758
|
+
const { currentSyntax: syntax } = useThemes()
|
|
3759
|
+
const pathFormatter = usePathFormatter()
|
|
3760
|
+
const view = createMemo(() => {
|
|
3761
|
+
if (ctx.config.diffs?.view === "unified") return "unified"
|
|
3762
|
+
if (ctx.config.diffs?.view === "split") return "split"
|
|
3763
|
+
return ctx.width > 120 ? "split" : "unified"
|
|
3764
|
+
})
|
|
3765
|
+
|
|
3766
|
+
return (
|
|
3767
|
+
<box flexDirection="column" gap={1}>
|
|
3768
|
+
<Index each={props.files}>
|
|
3769
|
+
{(file) => (
|
|
3770
|
+
<BlockTool
|
|
3771
|
+
path={{
|
|
3772
|
+
label: file().type === "add" ? "# Created" : file().type === "delete" ? "# Deleted" : "← Patched",
|
|
3773
|
+
value: pathFormatter.format(file().relativePath),
|
|
3774
|
+
}}
|
|
3775
|
+
part={props.part}
|
|
3776
|
+
>
|
|
3777
|
+
<Show
|
|
3778
|
+
when={file().type !== "delete" && file().patch.includes("@@")}
|
|
3779
|
+
fallback={
|
|
3780
|
+
<Show when={changeCounts(file())}>
|
|
3781
|
+
{(counts) => (
|
|
3782
|
+
<text>
|
|
3783
|
+
<Show when={counts().additions}>
|
|
3784
|
+
{(text) => <span style={{ fg: theme.diff.text.added }}>{text()}</span>}
|
|
3785
|
+
</Show>
|
|
3786
|
+
<Show when={counts().additions && counts().deletions}> </Show>
|
|
3787
|
+
<Show when={counts().deletions}>
|
|
3788
|
+
{(text) => <span style={{ fg: theme.diff.text.removed }}>{text()}</span>}
|
|
3789
|
+
</Show>
|
|
3790
|
+
{counts().unit}
|
|
3791
|
+
</text>
|
|
3792
|
+
)}
|
|
3793
|
+
</Show>
|
|
3794
|
+
}
|
|
3795
|
+
>
|
|
3796
|
+
<box paddingLeft={1} paddingRight={1}>
|
|
3797
|
+
<PatchDiff
|
|
3798
|
+
diff={file().patch}
|
|
3799
|
+
hunkFg={theme.diff.text.hunkHeader}
|
|
3800
|
+
view={view()}
|
|
3801
|
+
filetype={filetype(file().relativePath)}
|
|
3802
|
+
syntaxStyle={syntax()}
|
|
3803
|
+
showLineNumbers={true}
|
|
3804
|
+
width="100%"
|
|
3805
|
+
wrapMode={ctx.diffWrapMode()}
|
|
3806
|
+
fg={theme.text.base}
|
|
3807
|
+
addedBg={theme.diff.background.added}
|
|
3808
|
+
removedBg={theme.diff.background.removed}
|
|
3809
|
+
contextBg={theme.diff.background.context}
|
|
3810
|
+
addedSignColor={theme.diff.highlight.added}
|
|
3811
|
+
removedSignColor={theme.diff.highlight.removed}
|
|
3812
|
+
lineNumberFg={theme.diff.lineNumber.text}
|
|
3813
|
+
lineNumberBg={theme.diff.background.context}
|
|
3814
|
+
addedLineNumberBg={theme.diff.lineNumber.background.added}
|
|
3815
|
+
removedLineNumberBg={theme.diff.lineNumber.background.removed}
|
|
3816
|
+
/>
|
|
3817
|
+
</box>
|
|
3818
|
+
</Show>
|
|
3819
|
+
</BlockTool>
|
|
3820
|
+
)}
|
|
3821
|
+
</Index>
|
|
3822
|
+
</box>
|
|
3823
|
+
)
|
|
3824
|
+
}
|
|
3825
|
+
|
|
3826
|
+
/**
|
|
3827
|
+
* The line counts a change shows without its diff: "+2 lines", "-40 lines", "+5 -1 lines". Nothing where they are
|
|
3828
|
+
* unknown or zero, so a change without counts shows only its path.
|
|
3829
|
+
*/
|
|
3830
|
+
export function changeCounts(file: { additions?: number; deletions?: number }) {
|
|
3831
|
+
const additions = file.additions ?? 0
|
|
3832
|
+
const deletions = file.deletions ?? 0
|
|
3833
|
+
if (additions === 0 && deletions === 0) return undefined
|
|
3834
|
+
return {
|
|
3835
|
+
additions: additions > 0 ? `+${additions}` : "",
|
|
3836
|
+
deletions: deletions > 0 ? `-${deletions}` : "",
|
|
3837
|
+
unit: additions + deletions === 1 ? " line" : " lines",
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
|
|
3841
|
+
// A script's changes, like a patch's files, but a change may have no patch and, where nothing could be derived
|
|
3842
|
+
// without reading the file, no counts.
|
|
3843
|
+
export function parseScriptChanges(value: unknown) {
|
|
3844
|
+
if (!Array.isArray(value)) return []
|
|
3845
|
+
return value.flatMap((item) => {
|
|
3846
|
+
const file = recordValue(item)
|
|
3847
|
+
const status = stringValue(file?.status)
|
|
3848
|
+
const type =
|
|
3849
|
+
status === "added" ? "add" : status === "deleted" ? "delete" : status === "modified" ? "update" : undefined
|
|
3850
|
+
const relativePath = stringValue(file?.file)
|
|
3851
|
+
if (!file || !type || !relativePath) return []
|
|
3852
|
+
return [
|
|
3853
|
+
{
|
|
3854
|
+
type,
|
|
3855
|
+
relativePath,
|
|
3856
|
+
filePath: relativePath,
|
|
3857
|
+
patch: stringValue(file.patch) ?? "",
|
|
3858
|
+
additions: finiteNumber(file.additions),
|
|
3859
|
+
deletions: finiteNumber(file.deletions),
|
|
3860
|
+
movePath: undefined as string | undefined,
|
|
3861
|
+
},
|
|
3862
|
+
]
|
|
3863
|
+
})
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3866
|
+
export function parseApplyPatchFiles(value: unknown) {
|
|
3867
|
+
if (!Array.isArray(value)) return []
|
|
3868
|
+
return value.flatMap((item) => {
|
|
3869
|
+
const file = recordValue(item)
|
|
3870
|
+
if (!file) return []
|
|
3871
|
+
const status = stringValue(file.status)
|
|
3872
|
+
const type =
|
|
3873
|
+
stringValue(file.type) ??
|
|
3874
|
+
(status === "added" ? "add" : status === "deleted" ? "delete" : status === "modified" ? "update" : undefined)
|
|
3875
|
+
const relativePath = stringValue(file.file) ?? stringValue(file.relativePath)
|
|
3876
|
+
const filePath = stringValue(file.filePath) ?? relativePath
|
|
3877
|
+
const patch = stringValue(file.patch)
|
|
3878
|
+
const additions = finiteNumber(file.additions)
|
|
3879
|
+
const deletions = finiteNumber(file.deletions)
|
|
3880
|
+
if (
|
|
3881
|
+
!type ||
|
|
3882
|
+
!relativePath ||
|
|
3883
|
+
!filePath ||
|
|
3884
|
+
patch === undefined ||
|
|
3885
|
+
additions === undefined ||
|
|
3886
|
+
deletions === undefined
|
|
3887
|
+
)
|
|
3888
|
+
return []
|
|
3889
|
+
return [{ type, relativePath, filePath, patch, additions, deletions, movePath: stringValue(file.movePath) }]
|
|
3890
|
+
})
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
export function parseQuestions(value: unknown) {
|
|
3894
|
+
if (!Array.isArray(value)) return []
|
|
3895
|
+
return value.flatMap((item) => {
|
|
3896
|
+
const question = stringValue(recordValue(item)?.question)
|
|
3897
|
+
return question ? [{ question }] : []
|
|
3898
|
+
})
|
|
3899
|
+
}
|
|
3900
|
+
|
|
3901
|
+
export function parseQuestionAnswers(value: unknown) {
|
|
3902
|
+
if (!Array.isArray(value)) return
|
|
3903
|
+
return value.map((answer) =>
|
|
3904
|
+
Array.isArray(answer) ? answer.filter((item): item is string => typeof item === "string") : [],
|
|
3905
|
+
)
|
|
3906
|
+
}
|
|
3907
|
+
|
|
3908
|
+
export function parseDiagnostics(value: unknown, filePath: string) {
|
|
3909
|
+
const diagnostics = recordValue(value)?.[filePath]
|
|
3910
|
+
if (!Array.isArray(diagnostics)) return []
|
|
3911
|
+
return diagnostics
|
|
3912
|
+
.flatMap((item) => {
|
|
3913
|
+
const diagnostic = recordValue(item)
|
|
3914
|
+
const start = recordValue(recordValue(diagnostic?.range)?.start)
|
|
3915
|
+
const line = finiteNumber(start?.line)
|
|
3916
|
+
const character = finiteNumber(start?.character)
|
|
3917
|
+
const message = stringValue(diagnostic?.message)
|
|
3918
|
+
if (diagnostic?.severity !== 1 || line === undefined || character === undefined || !message) return []
|
|
3919
|
+
return [{ range: { start: { line, character } }, message }]
|
|
3920
|
+
})
|
|
3921
|
+
.slice(0, 3)
|
|
3922
|
+
}
|