@kabmo-labs/kabmo 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +495 -467
- package/dist/client/static/js/index-81f7berm.css +1 -0
- package/dist/client/static/js/{index-e3qh2yps.js → index-xzvyrxya.js} +795 -795
- package/marketplace/plugins/command-runner/package.json +3 -17
- package/marketplace/plugins/command-runner/settings-schema.json +14 -0
- package/marketplace/plugins/git-forge/README.md +17 -7
- package/marketplace/plugins/git-forge/package.json +4 -30
- package/marketplace/plugins/git-forge/panel.css +16 -0
- package/marketplace/plugins/git-forge/settings-schema.json +27 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +35 -22
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +20 -24
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +16 -7
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +31 -26
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +18 -2
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +160 -96
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +60 -44
- package/marketplace/plugins/git-forge/src/panel/List.tsx +150 -22
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +11 -5
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +17 -15
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +84 -61
- package/marketplace/plugins/git-forge/src/panel/format.test.ts +99 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +59 -16
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +109 -5
- package/marketplace/plugins/git-forge/src/panel/index.tsx +37 -4
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +17 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +31 -0
- package/marketplace/plugins/session-info/package.json +2 -10
- package/marketplace/plugins/session-info/settings-schema.json +8 -0
- package/marketplace/plugins/stats/README.md +17 -5
- package/marketplace/plugins/stats/package.json +3 -23
- package/marketplace/plugins/stats/settings-schema.json +20 -0
- package/marketplace/plugins/stats/src/app.tsx +1 -1
- package/marketplace/plugins/stats/src/groups.test.ts +46 -1
- package/marketplace/plugins/stats/src/groups.ts +22 -11
- package/marketplace/plugins/stats/src/harness-leases.test.ts +84 -0
- package/marketplace/plugins/stats/src/harness-leases.ts +132 -0
- package/marketplace/plugins/stats/src/labels.test.ts +54 -1
- package/marketplace/plugins/stats/src/labels.ts +33 -7
- package/marketplace/plugins/stats/src/sampler.test.ts +61 -0
- package/marketplace/plugins/stats/src/sampler.ts +39 -5
- package/marketplace/plugins/stats/src/snapshot.ts +6 -0
- package/package.json +2 -2
- package/src/client/components/common/harness-glyph/index.tsx +18 -1
- package/src/client/components/common/session-actions-menu/index.test.tsx +106 -0
- package/src/client/components/common/session-actions-menu/index.tsx +43 -1
- package/src/client/components/common/session-row/TrailingSlot.tsx +9 -4
- package/src/client/components/common/session-row/index.tsx +4 -0
- package/src/client/components/common/session-row/session-row.test.tsx +6 -0
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +2 -1
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +2 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +202 -0
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +80 -19
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +23 -3
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +3 -0
- package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +156 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +41 -86
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +6 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +9 -1
- package/src/client/components/settings/Modal.tsx +6 -2
- package/src/client/components/settings/Sidebar.tsx +30 -3
- package/src/client/components/settings/categories/HarnessSettings.tsx +11 -7
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +40 -15
- package/src/client/components/settings/categories/NotificationSettings.tsx +142 -64
- package/src/client/components/settings/categories/PanelPluginSettings.tsx +1 -1
- package/src/client/components/settings/categories/harness-settings/CustomHarnessForm.tsx +186 -0
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +11 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +1 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +15 -1
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.test.tsx +165 -0
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.tsx +260 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +24 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +8 -4
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +34 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -2
- package/src/client/components/workspace/chat-timeline/MessageItem.fork.test.ts +80 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +9 -3
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +8 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +9 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +24 -0
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +13 -20
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/props.ts +5 -5
- package/src/client/components/workspace/chat-timeline/index.tsx +11 -5
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +1 -9
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +101 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +2 -2
- package/src/client/components/workspace/editor/FilePane.tsx +9 -4
- package/src/client/components/workspace/editor/Notices.tsx +2 -2
- package/src/client/components/workspace/editor/Pane.tsx +2 -2
- package/src/client/components/workspace/editor/Toolbar.tsx +16 -10
- package/src/client/components/workspace/editor/index.tsx +6 -10
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +4 -3
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +23 -14
- package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +9 -1
- package/src/client/components/workspace/terminal-panel/focus.test.ts +70 -0
- package/src/client/components/workspace/terminal-panel/focus.ts +46 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +14 -1
- package/src/client/components/workspace/terminal-panel/mount.ts +17 -9
- package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +158 -0
- package/src/client/components/workspace/terminal-panel/scroll-hold.ts +136 -0
- package/src/client/hooks/chat/composer/use-draft.ts +45 -1
- package/src/client/hooks/chat/omp/pending-sessions.waiting.test.ts +11 -10
- package/src/client/hooks/chat/omp/pending-waiting.ts +15 -7
- package/src/client/hooks/chat/omp/prompt-send.test.ts +11 -0
- package/src/client/hooks/chat/omp/prompt-send.ts +3 -0
- package/src/client/hooks/chat/timeline/actions.ts +4 -4
- package/src/client/hooks/chat/timeline/composer-modes.ts +13 -2
- package/src/client/hooks/chat/timeline/fork-open.ts +52 -0
- package/src/client/hooks/chat/timeline/index.ts +5 -2
- package/src/client/hooks/chat/timeline/mode-availability.ts +7 -0
- package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
- package/src/client/hooks/chat/timeline/modes-hydrate.ts +93 -0
- package/src/client/hooks/chat/timeline/modes.ts +32 -52
- package/src/client/hooks/chat/timeline/new-chat-open.ts +7 -6
- package/src/client/hooks/chat/timeline/new-chat.ts +10 -1
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +4 -0
- package/src/client/hooks/chat/timeline/pending-session-mode.test.ts +136 -0
- package/src/client/hooks/chat/timeline/pending-session-mode.ts +69 -0
- package/src/client/hooks/chat/timeline/pending-warmup.test.ts +147 -0
- package/src/client/hooks/chat/timeline/pending-warmup.ts +62 -0
- package/src/client/hooks/chat/timeline/run-identity.test.ts +12 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +4 -1
- package/src/client/hooks/chat/timeline/send-props.ts +2 -0
- package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test-util.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test.ts +1 -0
- package/src/client/hooks/chat/timeline/session-harness.ts +4 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +9 -22
- package/src/client/hooks/chat/waiting/cancel.ts +13 -6
- package/src/client/hooks/chat/waiting/choice.ts +13 -16
- package/src/client/hooks/chat/waiting/composer-wait.ts +70 -0
- package/src/client/hooks/chat/waiting/dispatch.ts +48 -28
- package/src/client/hooks/chat/waiting/held.ts +37 -13
- package/src/client/hooks/chat/waiting/hold.test.ts +22 -0
- package/src/client/hooks/chat/waiting/hold.ts +20 -11
- package/src/client/hooks/chat/waiting/restore.test.ts +69 -0
- package/src/client/hooks/chat/waiting/restore.ts +34 -0
- package/src/client/hooks/chat/waiting/store.ts +9 -3
- package/src/client/hooks/editor/file-editor-types.ts +21 -12
- package/src/client/hooks/editor/save-file.test.ts +1 -1
- package/src/client/hooks/editor/save-file.ts +35 -8
- package/src/client/hooks/editor/target-key.ts +17 -0
- package/src/client/hooks/editor/use-disk-digest.test.ts +82 -0
- package/src/client/hooks/editor/use-disk-digest.ts +164 -0
- package/src/client/hooks/editor/use-disk-sync.ts +212 -0
- package/src/client/hooks/editor/use-file-cache.ts +113 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +90 -0
- package/src/client/hooks/editor/use-file-editor.ts +90 -52
- package/src/client/hooks/editor/use-file-read.ts +24 -10
- package/src/client/hooks/editor/use-file-writes.ts +4 -4
- package/src/client/hooks/models/harness-catalog.ts +15 -0
- package/src/client/hooks/ui/notifications.ts +17 -8
- package/src/client/hooks/workspace/panel-registry.ts +1 -1
- package/src/client/hooks/workspace/scheduled-tasks.ts +26 -11
- package/src/client/lib/notifications/os.test.ts +1 -30
- package/src/client/lib/notifications/os.ts +0 -15
- package/src/client/lib/notifications/platform.test.ts +68 -0
- package/src/client/lib/notifications/platform.ts +36 -0
- package/src/server/index.ts +7 -0
- package/src/server/lib/harness/acp/client.ts +81 -87
- package/src/server/lib/harness/acp/prewarm.server.ts +237 -0
- package/src/server/lib/harness/acp/prewarm.test.ts +171 -0
- package/src/server/lib/harness/acp/prompt.test.ts +70 -1
- package/src/server/lib/harness/acp/prompt.ts +32 -1
- package/src/server/lib/harness/acp/protocol.ts +23 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +26 -0
- package/src/server/lib/harness/acp/session-handshake.ts +22 -20
- package/src/server/lib/harness/acp/session-options.ts +16 -0
- package/src/server/lib/harness/acp/session-process.ts +43 -0
- package/src/server/lib/harness/acp/session.ts +11 -12
- package/src/server/lib/harness/acp/stdio.ts +129 -0
- package/src/server/lib/harness/acp/verbs.test.ts +97 -0
- package/src/server/lib/harness/acp/verbs.ts +16 -6
- package/src/server/lib/harness/auto-probe.server.ts +4 -3
- package/src/server/lib/harness/capabilities.ts +8 -0
- package/src/server/lib/harness/config.server.ts +3 -2
- package/src/server/lib/harness/custom.server.ts +209 -0
- package/src/server/lib/harness/launch.ts +6 -1
- package/src/server/lib/harness/register.server.ts +8 -1
- package/src/server/lib/harness/schema.server.ts +21 -0
- package/src/server/lib/harness/session-lease.server.test.ts +99 -0
- package/src/server/lib/harness/session-lease.server.ts +193 -0
- package/src/server/lib/harness/session-store.server.test.ts +8 -8
- package/src/server/lib/harness/session-store.server.ts +25 -4
- package/src/server/lib/harness/session-title.server.ts +12 -2
- package/src/server/lib/harness/spawn.server.ts +123 -20
- package/src/server/lib/harness/update-queue.server.ts +3 -3
- package/src/server/lib/lifecycle/after-listen.ts +12 -1
- package/src/server/lib/lifecycle/paths.ts +19 -1
- package/src/server/lib/mcp/registry.server.ts +155 -0
- package/src/server/lib/mcp/registry.test.ts +169 -0
- package/src/server/lib/mcp/store.server.ts +38 -0
- package/src/server/lib/omp/rpc/frame-fold-contract.ts +59 -0
- package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +64 -1
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +2 -1
- package/src/server/lib/omp/rpc/frame-fold.test.ts +2 -1
- package/src/server/lib/omp/rpc/frame-fold.ts +6 -45
- package/src/server/lib/omp/rpc/prewarm-pool.ts +19 -5
- package/src/server/lib/omp/rpc/run-model.test.ts +116 -0
- package/src/server/lib/omp/rpc/run-model.ts +4 -2
- package/src/server/lib/omp/session/sidebar-data.harness.test.ts +6 -3
- package/src/server/lib/omp/session/standby.server.ts +13 -2
- package/src/server/lib/panels/manifest.test.ts +47 -1
- package/src/server/lib/panels/manifest.ts +19 -0
- package/src/server/lib/panels/registry.server.ts +19 -2
- package/src/server/lib/panels/scan.server.ts +26 -2
- package/src/server/lib/panels/settings-schema.server.ts +72 -0
- package/src/server/lib/plugins/background.server.ts +21 -3
- package/src/server/lib/plugins/background.test.ts +13 -0
- package/src/server/lib/plugins/loader.server.ts +35 -51
- package/src/server/lib/plugins/mcp.server.ts +100 -0
- package/src/server/lib/plugins/mcp.test.ts +75 -0
- package/src/server/lib/plugins/schedule-runner.server.ts +153 -0
- package/src/server/lib/plugins/schedule-runner.test.ts +186 -0
- package/src/server/lib/plugins/schedule-store.server.ts +107 -0
- package/src/server/lib/plugins/schema.server.ts +8 -0
- package/src/server/lib/plugins/settings.server.ts +56 -19
- package/src/server/lib/plugins/shutdown.server.ts +58 -0
- package/src/server/lib/plugins/shutdown.test.ts +28 -3
- package/src/server/lib/realtime/topics/global.server.ts +5 -1
- package/src/server/lib/schedule/rows.server.ts +9 -0
- package/src/server/lib/schedule/runtime.server.test.ts +91 -0
- package/src/server/lib/schedule/runtime.server.ts +101 -23
- package/src/server/lib/schedule/schema.server.ts +15 -0
- package/src/server/lib/schedule/store.server.test.ts +34 -0
- package/src/server/lib/schedule/store.server.ts +33 -9
- package/src/server/lib/sessions/fork.server.test.ts +47 -0
- package/src/server/lib/sessions/fork.server.ts +17 -1
- package/src/server/lib/sessions/spawn.server.ts +2 -2
- package/src/server/lib/waiting/runtime.server.test.ts +48 -0
- package/src/server/lib/waiting/runtime.server.ts +22 -0
- package/src/server/lib/waiting/schema.server.ts +8 -0
- package/src/server/lib/waiting/store.server.test.ts +14 -0
- package/src/server/lib/waiting/store.server.ts +6 -2
- package/src/server/routes/agent/command-resume.test.ts +9 -4
- package/src/server/routes/agent/new-mode.test.ts +40 -0
- package/src/server/routes/agent/new.ts +31 -10
- package/src/server/routes/agent/prewarm.ts +48 -7
- package/src/server/routes/fs/action.ts +9 -1
- package/src/server/routes/fs/digest.test.ts +100 -0
- package/src/server/routes/fs/digest.ts +106 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/harness/custom.test.ts +131 -0
- package/src/server/routes/harness/import-action.ts +2 -2
- package/src/server/routes/harness/root.ts +41 -8
- package/src/server/routes/harness/update.ts +2 -2
- package/src/server/routes/panels/bindings.ts +2 -0
- package/src/server/routes/panels/settings.test.ts +165 -0
- package/src/server/routes/panels/settings.ts +106 -0
- package/src/server/routes/schedule/body.ts +14 -0
- package/src/server/routes/schedule/index.ts +28 -4
- package/src/server/routes/settings/mcp.ts +9 -26
- package/src/server/routes/waiting/index.ts +21 -2
- package/src/server/routes/waiting/routes.test.ts +21 -0
- package/src/shared/lib/chat/composer/delegation.ts +3 -3
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +97 -0
- package/src/shared/lib/chat/timeline/fork-anchor.ts +47 -0
- package/src/shared/lib/fs/content-hash.ts +29 -0
- package/src/shared/lib/harness/catalog.ts +48 -6
- package/src/shared/lib/harness/fork.ts +60 -0
- package/src/shared/lib/harness/mcp-facts.test.ts +30 -0
- package/src/shared/lib/harness/mcp-facts.ts +65 -0
- package/src/shared/lib/harness/menu.test.ts +16 -1
- package/src/shared/lib/harness/menu.ts +2 -2
- package/src/shared/lib/harness/rewind.ts +6 -6
- package/src/shared/lib/harness/session-modes.ts +31 -0
- package/src/shared/lib/harness/transcript.test.ts +29 -0
- package/src/shared/lib/harness/transcript.ts +19 -0
- package/src/shared/lib/notifications/settings.test.ts +21 -0
- package/src/shared/lib/notifications/settings.ts +24 -0
- package/src/shared/lib/omp/session/prewarm.test.ts +28 -4
- package/src/shared/lib/omp/session/prewarm.ts +25 -6
- package/src/shared/lib/omp/session/stream-state.server.test.ts +25 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +8 -4
- package/src/shared/lib/panels/capabilities.test.ts +1 -1
- package/src/shared/lib/panels/capabilities.ts +3 -0
- package/src/shared/lib/plugins/settings.ts +22 -0
- package/src/shared/lib/schedule/parse.test.ts +48 -0
- package/src/shared/lib/schedule/parse.ts +69 -45
- package/src/shared/lib/schedule/timezone.ts +128 -0
- package/src/shared/lib/settings/defaults.ts +2 -0
- package/src/shared/lib/workspace/refresh-cadence.test.ts +25 -1
- package/src/shared/lib/workspace/relative-time.ts +16 -0
- package/src/shared/types/harness.ts +7 -0
- package/src/shared/types/omp/agent.ts +6 -0
- package/src/shared/types/panels-registry.ts +3 -3
- package/src/shared/types/panels.ts +4 -2
- package/src/shared/types/schedule.ts +13 -0
- package/src/shared/types/settings/state.ts +12 -1
- package/src/shared/types/waiting.ts +9 -0
- package/src/test-support/file-editor.test-util.ts +70 -5
- package/dist/client/static/js/index-32rpkj6b.css +0 -1
- package/src/client/hooks/editor/use-external-change-notice.ts +0 -71
- package/src/client/hooks/editor/use-external-change.test.ts +0 -88
- package/src/client/hooks/editor/use-external-change.ts +0 -146
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The schema-driven settings form.
|
|
8
|
+
*
|
|
9
|
+
* The load-bearing cases are the two a visual check cannot see: a secret is
|
|
10
|
+
* never prefilled and is left OUT of the request when untouched (sending the
|
|
11
|
+
* mask back would overwrite the credential), and a number field is sent as a
|
|
12
|
+
* number rather than the string the input holds.
|
|
13
|
+
*
|
|
14
|
+
* Rendered with `h()` against happy-dom, following the panel suites.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
18
|
+
import { Window } from 'happy-dom';
|
|
19
|
+
import { h, render } from 'preact';
|
|
20
|
+
import { act } from 'preact/test-utils';
|
|
21
|
+
import { PluginSettingsModal } from '@/client/components/settings/categories/panel-plugins/SettingsModal';
|
|
22
|
+
import { PLUGIN_SECRET_MASK } from '@/shared/lib/plugins/settings';
|
|
23
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
24
|
+
|
|
25
|
+
let container: HTMLElement;
|
|
26
|
+
const nativeFetch = globalThis.fetch;
|
|
27
|
+
|
|
28
|
+
const DEFINITIONS = {
|
|
29
|
+
note: { type: 'string', label: 'Note prefix', description: 'Prepended to every note.' },
|
|
30
|
+
retries: { type: 'number', label: 'Retries' },
|
|
31
|
+
verbose: { type: 'boolean', label: 'Verbose' },
|
|
32
|
+
token: { type: 'string', label: 'API token', secret: true },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const VALUES = { note: 'hello', retries: 3, verbose: false, token: PLUGIN_SECRET_MASK };
|
|
36
|
+
|
|
37
|
+
interface Sent {
|
|
38
|
+
url: string;
|
|
39
|
+
method: string;
|
|
40
|
+
body: unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let sent: Sent[] = [];
|
|
44
|
+
|
|
45
|
+
/** The one shape the component sends. */
|
|
46
|
+
function isValuesBody(body: unknown): body is { values: Record<string, unknown> } {
|
|
47
|
+
if (typeof body !== 'object' || body === null || !('values' in body)) return false;
|
|
48
|
+
const values = body.values;
|
|
49
|
+
return typeof values === 'object' && values !== null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
beforeAll(() => {
|
|
53
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
if (container) render(null, container);
|
|
58
|
+
globalThis.fetch = nativeFetch;
|
|
59
|
+
sent = [];
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
afterAll(() => {
|
|
63
|
+
restoreDomGlobals();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
function stubFetch() {
|
|
67
|
+
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
68
|
+
const url = String(input);
|
|
69
|
+
const method = init?.method ?? 'GET';
|
|
70
|
+
const body = init?.body ? JSON.parse(String(init.body)) : undefined;
|
|
71
|
+
sent.push({ url, method, body });
|
|
72
|
+
const values = method === 'PUT' && isValuesBody(body) ? { ...VALUES, ...body.values } : VALUES;
|
|
73
|
+
return new Response(JSON.stringify({ pluginId: 'demo', definitions: DEFINITIONS, values }), {
|
|
74
|
+
status: 200,
|
|
75
|
+
headers: { 'content-type': 'application/json' },
|
|
76
|
+
});
|
|
77
|
+
}) as typeof fetch;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function mount(): Promise<HTMLElement> {
|
|
81
|
+
stubFetch();
|
|
82
|
+
container = document.createElement('div');
|
|
83
|
+
document.body.append(container);
|
|
84
|
+
await act(async () => {
|
|
85
|
+
render(h(PluginSettingsModal, { pluginId: 'demo', name: 'Demo', onClose: () => {} }), container);
|
|
86
|
+
});
|
|
87
|
+
await flush();
|
|
88
|
+
return container;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Let the fetch promise chain settle; each `await` in the component is a tick. */
|
|
92
|
+
async function flush(): Promise<void> {
|
|
93
|
+
for (let tick = 0; tick < 6; tick += 1) {
|
|
94
|
+
await act(async () => {
|
|
95
|
+
await Promise.resolve();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function input(el: HTMLElement, label: string): HTMLInputElement {
|
|
101
|
+
const field = el.querySelector<HTMLInputElement>(`#plugin-setting-${label}`);
|
|
102
|
+
if (!field) throw new Error(`no input for ${label}`);
|
|
103
|
+
return field;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
describe('PluginSettingsModal', () => {
|
|
107
|
+
test('renders one control per definition, from the schema', async () => {
|
|
108
|
+
const el = await mount();
|
|
109
|
+
expect(el.textContent).toContain('Note prefix');
|
|
110
|
+
expect(el.textContent).toContain('Prepended to every note.');
|
|
111
|
+
expect(input(el, 'note').value).toBe('hello');
|
|
112
|
+
expect(input(el, 'retries').value).toBe('3');
|
|
113
|
+
expect(input(el, 'verbose').checked).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('a stored secret starts empty and says it is stored', async () => {
|
|
117
|
+
const el = await mount();
|
|
118
|
+
const token = input(el, 'token');
|
|
119
|
+
expect(token.type).toBe('password');
|
|
120
|
+
expect(token.value).toBe('');
|
|
121
|
+
expect(token.getAttribute('placeholder')).toContain('stored');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('saves typed values, sends numbers as numbers, and omits an untouched secret', async () => {
|
|
125
|
+
const el = await mount();
|
|
126
|
+
|
|
127
|
+
const note = input(el, 'note');
|
|
128
|
+
await act(async () => {
|
|
129
|
+
note.value = 'changed';
|
|
130
|
+
note.dispatchEvent(new Event('input', { bubbles: true }));
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const save = Array.from(el.querySelectorAll('button')).find((button) => button.textContent?.trim() === 'Save');
|
|
134
|
+
if (!save) throw new Error('no Save button');
|
|
135
|
+
await act(async () => {
|
|
136
|
+
save.click();
|
|
137
|
+
});
|
|
138
|
+
await flush();
|
|
139
|
+
|
|
140
|
+
const put = sent.find((request) => request.method === 'PUT');
|
|
141
|
+
expect(put?.url).toBe('/api/panels/settings/demo');
|
|
142
|
+
expect(put?.body).toEqual({ values: { note: 'changed', retries: 3, verbose: false } });
|
|
143
|
+
expect(el.textContent).toContain('Saved');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('a typed secret replaces the stored one', async () => {
|
|
147
|
+
const el = await mount();
|
|
148
|
+
|
|
149
|
+
const token = input(el, 'token');
|
|
150
|
+
await act(async () => {
|
|
151
|
+
token.value = 'new-token';
|
|
152
|
+
token.dispatchEvent(new Event('input', { bubbles: true }));
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const save = Array.from(el.querySelectorAll('button')).find((button) => button.textContent?.trim() === 'Save');
|
|
156
|
+
if (!save) throw new Error('no Save button');
|
|
157
|
+
await act(async () => {
|
|
158
|
+
save.click();
|
|
159
|
+
});
|
|
160
|
+
await flush();
|
|
161
|
+
|
|
162
|
+
const put = sent.find((request) => request.method === 'PUT');
|
|
163
|
+
expect(put && isValuesBody(put.body) ? put.body.values.token : undefined).toBe('new-token');
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A panel plugin's settings form, rendered from its declared schema.
|
|
8
|
+
*
|
|
9
|
+
* The schema is the plugin's `settings-schema.json`, read by the server, so the
|
|
10
|
+
* form exists without the plugin running — a switched-off plugin can still be
|
|
11
|
+
* configured. Three field types are rendered (`string`, `number`, `boolean`);
|
|
12
|
+
* the schema validator refuses anything else before it reaches this file, which
|
|
13
|
+
* is why there is no fallback branch that would draw a control the server cannot
|
|
14
|
+
* validate.
|
|
15
|
+
*
|
|
16
|
+
* A secret is treated as WRITE-ONLY. The server never sends the stored value, so
|
|
17
|
+
* the box starts empty with a "stored" placeholder: an untouched field is left
|
|
18
|
+
* out of the request, and only text the user actually typed replaces it.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
22
|
+
import { AlertTriangle, Loader2, SlidersHorizontal } from 'lucide-preact';
|
|
23
|
+
import { Modal } from '@/client/components/common/Modal';
|
|
24
|
+
import { CHECKBOX_CLASS } from '@/client/components/common/checkbox/style';
|
|
25
|
+
import { PLUGIN_SECRET_MASK } from '@/shared/lib/plugins/settings';
|
|
26
|
+
import type { PluginSettingDefinition } from '@kabmo-labs/kabmo-sdk';
|
|
27
|
+
|
|
28
|
+
type SettingValue = string | number | boolean;
|
|
29
|
+
type Draft = Record<string, string | boolean>;
|
|
30
|
+
|
|
31
|
+
interface SettingsPayload {
|
|
32
|
+
pluginId: string;
|
|
33
|
+
definitions: Record<string, PluginSettingDefinition>;
|
|
34
|
+
values: Record<string, SettingValue>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface PluginSettingsModalProps {
|
|
38
|
+
pluginId: string;
|
|
39
|
+
/** The plugin's display name, for the dialog header. */
|
|
40
|
+
name: string;
|
|
41
|
+
onClose: () => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function PluginSettingsModal({ pluginId, name, onClose }: PluginSettingsModalProps) {
|
|
45
|
+
const [payload, setPayload] = useState<SettingsPayload | null>(null);
|
|
46
|
+
const [draft, setDraft] = useState<Draft>({});
|
|
47
|
+
const [error, setError] = useState<string | null>(null);
|
|
48
|
+
const [saving, setSaving] = useState(false);
|
|
49
|
+
const [saved, setSaved] = useState(false);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
let cancelled = false;
|
|
53
|
+
fetch(`/api/panels/settings/${encodeURIComponent(pluginId)}`, { credentials: 'same-origin' })
|
|
54
|
+
.then(async (response) => {
|
|
55
|
+
if (!response.ok) throw new Error(await errorOf(response));
|
|
56
|
+
return (await response.json()) as SettingsPayload;
|
|
57
|
+
})
|
|
58
|
+
.then(
|
|
59
|
+
(next) => {
|
|
60
|
+
if (cancelled) return;
|
|
61
|
+
setPayload(next);
|
|
62
|
+
setDraft(initialDraft(next.definitions, next.values));
|
|
63
|
+
},
|
|
64
|
+
(cause: unknown) => {
|
|
65
|
+
if (!cancelled) setError(cause instanceof Error ? cause.message : String(cause));
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
return () => {
|
|
69
|
+
cancelled = true;
|
|
70
|
+
};
|
|
71
|
+
}, [pluginId]);
|
|
72
|
+
|
|
73
|
+
const definitions = payload ? Object.entries(payload.definitions) : [];
|
|
74
|
+
|
|
75
|
+
function change(key: string, value: string | boolean) {
|
|
76
|
+
setDraft((current) => ({ ...current, [key]: value }));
|
|
77
|
+
setSaved(false);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function submit(event: Event) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
if (!payload) return;
|
|
83
|
+
setError(null);
|
|
84
|
+
setSaved(false);
|
|
85
|
+
|
|
86
|
+
const values: Record<string, unknown> = {};
|
|
87
|
+
for (const [key, definition] of Object.entries(payload.definitions)) {
|
|
88
|
+
const current = draft[key];
|
|
89
|
+
if (definition.type === 'boolean') {
|
|
90
|
+
values[key] = current === true;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const text = String(current ?? '');
|
|
94
|
+
// An untouched secret is not sent: the field means "keep the stored
|
|
95
|
+
// value", and the server never gave us the value to repeat.
|
|
96
|
+
if (definition.secret && !text) continue;
|
|
97
|
+
if (definition.type === 'number') {
|
|
98
|
+
const parsed = Number(text.trim());
|
|
99
|
+
if (text.trim() === '' || !Number.isFinite(parsed)) {
|
|
100
|
+
setError(`${definition.label} needs a number.`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
values[key] = parsed;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
values[key] = text;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
setSaving(true);
|
|
110
|
+
try {
|
|
111
|
+
const response = await fetch(`/api/panels/settings/${encodeURIComponent(pluginId)}`, {
|
|
112
|
+
method: 'PUT',
|
|
113
|
+
credentials: 'same-origin',
|
|
114
|
+
headers: { 'content-type': 'application/json' },
|
|
115
|
+
body: JSON.stringify({ values }),
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) throw new Error(await errorOf(response));
|
|
118
|
+
const next = (await response.json()) as SettingsPayload;
|
|
119
|
+
setPayload(next);
|
|
120
|
+
setDraft(initialDraft(next.definitions, next.values));
|
|
121
|
+
setSaved(true);
|
|
122
|
+
} catch (cause) {
|
|
123
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
124
|
+
} finally {
|
|
125
|
+
setSaving(false);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<Modal
|
|
131
|
+
onClose={onClose}
|
|
132
|
+
maxWidthClass="max-w-lg"
|
|
133
|
+
header={
|
|
134
|
+
<div className="flex items-center gap-2 min-w-0">
|
|
135
|
+
<SlidersHorizontal size={15} className="text-ink/50 flex-shrink-0" />
|
|
136
|
+
<span className="text-sm font-medium text-ink truncate">{name}</span>
|
|
137
|
+
<span className="text-[11px] text-ink/45 font-mono truncate">{pluginId}</span>
|
|
138
|
+
</div>
|
|
139
|
+
}
|
|
140
|
+
form={{ onSubmit: submit, className: 'px-5 py-4 space-y-4' }}
|
|
141
|
+
footer={
|
|
142
|
+
<div className="flex items-center gap-2">
|
|
143
|
+
{error ? (
|
|
144
|
+
<span className="flex items-start gap-1.5 text-error min-w-0">
|
|
145
|
+
<AlertTriangle size={13} className="flex-shrink-0 mt-0.5" />
|
|
146
|
+
<span className="text-[11px] leading-snug">{error}</span>
|
|
147
|
+
</span>
|
|
148
|
+
) : saved ? (
|
|
149
|
+
<span className="text-[11px] text-success">Saved</span>
|
|
150
|
+
) : null}
|
|
151
|
+
<button
|
|
152
|
+
type="submit"
|
|
153
|
+
disabled={saving || !payload}
|
|
154
|
+
className="ml-auto px-3 py-1.5 rounded-md bg-ink text-paper text-[11px] font-medium hover:bg-ink/90 transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
|
|
155
|
+
>
|
|
156
|
+
{saving ? 'Saving…' : 'Save'}
|
|
157
|
+
</button>
|
|
158
|
+
</div>
|
|
159
|
+
}
|
|
160
|
+
>
|
|
161
|
+
{!payload ? (
|
|
162
|
+
error ? null : (
|
|
163
|
+
<div className="flex items-center gap-2 text-ink/50">
|
|
164
|
+
<Loader2 size={14} className="animate-spin" />
|
|
165
|
+
<span className="text-xs">Reading settings…</span>
|
|
166
|
+
</div>
|
|
167
|
+
)
|
|
168
|
+
) : definitions.length === 0 ? (
|
|
169
|
+
<p className="text-xs text-ink/50">This plugin declares no settings.</p>
|
|
170
|
+
) : (
|
|
171
|
+
definitions.map(([key, definition]) => (
|
|
172
|
+
<SettingField
|
|
173
|
+
key={key}
|
|
174
|
+
name={key}
|
|
175
|
+
definition={definition}
|
|
176
|
+
value={draft[key]}
|
|
177
|
+
stored={definition.secret === true && payload.values[key] === PLUGIN_SECRET_MASK}
|
|
178
|
+
onChange={(value) => change(key, value)}
|
|
179
|
+
/>
|
|
180
|
+
))
|
|
181
|
+
)}
|
|
182
|
+
</Modal>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Every field is one labelled control plus its description. */
|
|
187
|
+
function SettingField({
|
|
188
|
+
name,
|
|
189
|
+
definition,
|
|
190
|
+
value,
|
|
191
|
+
stored,
|
|
192
|
+
onChange,
|
|
193
|
+
}: {
|
|
194
|
+
name: string;
|
|
195
|
+
definition: PluginSettingDefinition;
|
|
196
|
+
value: string | boolean | undefined;
|
|
197
|
+
/** A secret already has a value; the box starts empty and says so. */
|
|
198
|
+
stored: boolean;
|
|
199
|
+
onChange: (value: string | boolean) => void;
|
|
200
|
+
}) {
|
|
201
|
+
const inputClass =
|
|
202
|
+
'w-full px-2.5 py-1.5 rounded-lg border border-ink/15 bg-paper focus:outline-none focus:border-ink/40 text-xs text-ink transition-colors';
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<div className="space-y-1">
|
|
206
|
+
<label className="block text-xs font-medium text-ink" for={`plugin-setting-${name}`}>
|
|
207
|
+
{definition.label}
|
|
208
|
+
</label>
|
|
209
|
+
{definition.description ? (
|
|
210
|
+
<p className="text-[11px] text-ink/50 leading-snug">{definition.description}</p>
|
|
211
|
+
) : null}
|
|
212
|
+
|
|
213
|
+
{definition.type === 'boolean' ? (
|
|
214
|
+
<label className="flex items-center gap-2 cursor-pointer select-none pt-0.5">
|
|
215
|
+
<input
|
|
216
|
+
id={`plugin-setting-${name}`}
|
|
217
|
+
type="checkbox"
|
|
218
|
+
checked={value === true}
|
|
219
|
+
onChange={(event) => onChange(event.currentTarget.checked)}
|
|
220
|
+
className={`${CHECKBOX_CLASS} accent-ink cursor-pointer`}
|
|
221
|
+
/>
|
|
222
|
+
<span className="text-[11px] text-ink/70">{value === true ? 'on' : 'off'}</span>
|
|
223
|
+
</label>
|
|
224
|
+
) : (
|
|
225
|
+
<input
|
|
226
|
+
id={`plugin-setting-${name}`}
|
|
227
|
+
type={definition.type === 'number' ? 'number' : definition.secret ? 'password' : 'text'}
|
|
228
|
+
value={typeof value === 'string' ? value : ''}
|
|
229
|
+
spellcheck={false}
|
|
230
|
+
autocomplete="off"
|
|
231
|
+
placeholder={stored ? 'stored — type a new value to replace' : undefined}
|
|
232
|
+
onInput={(event) => onChange(event.currentTarget.value)}
|
|
233
|
+
className={`${inputClass} font-mono`}
|
|
234
|
+
/>
|
|
235
|
+
)}
|
|
236
|
+
</div>
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** The server's error sentence, or the status when the body carried none. */
|
|
241
|
+
async function errorOf(response: Response): Promise<string> {
|
|
242
|
+
const body = (await response.json().catch(() => null)) as { error?: string } | null;
|
|
243
|
+
return body?.error ?? `The settings request failed (${response.status})`;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** The form's starting values: secrets empty, everything else as stored. */
|
|
247
|
+
function initialDraft(
|
|
248
|
+
definitions: Record<string, PluginSettingDefinition>,
|
|
249
|
+
values: Record<string, SettingValue>,
|
|
250
|
+
): Draft {
|
|
251
|
+
const draft: Draft = {};
|
|
252
|
+
for (const [key, definition] of Object.entries(definitions)) {
|
|
253
|
+
if (definition.type === 'boolean') {
|
|
254
|
+
draft[key] = values[key] === true;
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
draft[key] = definition.secret ? '' : String(values[key] ?? '');
|
|
258
|
+
}
|
|
259
|
+
return draft;
|
|
260
|
+
}
|
|
@@ -91,4 +91,28 @@ describe('assistant footer fork', () => {
|
|
|
91
91
|
const el = mount(h(RunFooter, { msg: answerRow, retryTargetId: 'user-3' }));
|
|
92
92
|
expect(el.querySelector('button[aria-label="Fork session from this answer"]')).toBeNull();
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
test('an AIR adapter offers Fork on the answer', () => {
|
|
96
|
+
for (const harness of ['claude', 'codex']) {
|
|
97
|
+
const el = mount(h(RunFooter, {
|
|
98
|
+
msg: answerRow,
|
|
99
|
+
retryTargetId: 'user-3',
|
|
100
|
+
harness,
|
|
101
|
+
onFork: () => {},
|
|
102
|
+
}));
|
|
103
|
+
expect(el.querySelector('button[aria-label="Fork session from this answer"]')).not.toBeNull();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('a harness that can only fork the whole chat draws no Fork action', () => {
|
|
108
|
+
for (const harness of ['zcode', 'opencode', 'dsh']) {
|
|
109
|
+
const el = mount(h(RunFooter, {
|
|
110
|
+
msg: answerRow,
|
|
111
|
+
retryTargetId: 'user-3',
|
|
112
|
+
harness,
|
|
113
|
+
onFork: () => {},
|
|
114
|
+
}));
|
|
115
|
+
expect(el.querySelector('button[aria-label="Fork session from this answer"]')).toBeNull();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
94
118
|
});
|
|
@@ -7,6 +7,7 @@ import { PluginMessageActions } from '@/client/components/workspace/chat-timelin
|
|
|
7
7
|
import { formatDuration } from '@/shared/lib/chat/duration';
|
|
8
8
|
import { providerLabel } from '@/shared/lib/models/provider/label';
|
|
9
9
|
import { formatCompactTokens } from '@/shared/lib/format/number';
|
|
10
|
+
import { canForkAt, type ForkAnchorRole } from '@/shared/lib/chat/timeline/fork-anchor';
|
|
10
11
|
|
|
11
12
|
interface AiMessageFooterProps {
|
|
12
13
|
provider?: string;
|
|
@@ -40,7 +41,7 @@ interface AiMessageFooterProps {
|
|
|
40
41
|
* keeps the answer.
|
|
41
42
|
*/
|
|
42
43
|
forkTargetId?: string;
|
|
43
|
-
onFork?: (msgId: string) => void;
|
|
44
|
+
onFork?: (msgId: string, role: ForkAnchorRole) => void;
|
|
44
45
|
isMobile?: boolean;
|
|
45
46
|
/**
|
|
46
47
|
* Whether the row offers Retry / Fork / New-chat. All of them act on the
|
|
@@ -70,6 +71,9 @@ export function AiMessageFooter({
|
|
|
70
71
|
showActions = true,
|
|
71
72
|
}: AiMessageFooterProps) {
|
|
72
73
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
74
|
+
// A harness that cannot fork at an assistant row draws no Fork action: the
|
|
75
|
+
// button would only ever answer "whole chat", which is the dropdown's job.
|
|
76
|
+
const canFork = Boolean(onFork && forkTargetId) && canForkAt(harness, 'assistant');
|
|
73
77
|
|
|
74
78
|
const handleRetry = () => {
|
|
75
79
|
setIsMenuOpen(false);
|
|
@@ -83,7 +87,7 @@ export function AiMessageFooter({
|
|
|
83
87
|
|
|
84
88
|
const handleFork = () => {
|
|
85
89
|
setIsMenuOpen(false);
|
|
86
|
-
if (forkTargetId) onFork?.(forkTargetId);
|
|
90
|
+
if (forkTargetId) onFork?.(forkTargetId, 'assistant');
|
|
87
91
|
};
|
|
88
92
|
|
|
89
93
|
useEffect(() => {
|
|
@@ -236,7 +240,7 @@ export function AiMessageFooter({
|
|
|
236
240
|
<RotateCcw size={20} className="shrink-0 text-ink/55" />
|
|
237
241
|
<span>Retry response</span>
|
|
238
242
|
</button>
|
|
239
|
-
{
|
|
243
|
+
{canFork && (
|
|
240
244
|
<button type="button" aria-label="Fork session from this answer" onClick={handleFork} className="flex min-h-12 w-full items-center gap-3 rounded-lg px-3 text-left text-sm text-ink transition-colors hover:bg-ink/5 cursor-pointer">
|
|
241
245
|
<GitFork size={20} className="shrink-0 text-ink/55" />
|
|
242
246
|
<span>Fork from this answer</span>
|
|
@@ -288,7 +292,7 @@ export function AiMessageFooter({
|
|
|
288
292
|
ariaLabel="Copy response"
|
|
289
293
|
emptyTitle="Nothing to copy — this run produced no text"
|
|
290
294
|
/>
|
|
291
|
-
{showActions &&
|
|
295
|
+
{showActions && canFork && (
|
|
292
296
|
<button type="button" className="flex items-center hover:text-ink transition-colors p-1 rounded hover:bg-ink/5 cursor-pointer" title="Fork from here" aria-label="Fork session from this answer" onClick={handleFork}>
|
|
293
297
|
<GitFork size={12} />
|
|
294
298
|
</button>
|
|
@@ -8,7 +8,9 @@ import { QueueList } from '@/client/components/workspace/chat-timeline/QueueList
|
|
|
8
8
|
import type { Attachment, QueuedMessage } from '@/shared/types';
|
|
9
9
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
10
10
|
import type { ComposerModes } from '@/client/components/workspace/chat-timeline/chat-input/modes-props';
|
|
11
|
+
import type { WaitingCandidate } from '@/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker';
|
|
11
12
|
import { PluginComposerBanners } from '@/client/components/workspace/chat-timeline/chat-input/PluginComposerSlots';
|
|
13
|
+
import { Hourglass } from 'lucide-preact';
|
|
12
14
|
|
|
13
15
|
interface ComposerDockProps {
|
|
14
16
|
isMobile: boolean;
|
|
@@ -71,6 +73,15 @@ interface ComposerDockProps {
|
|
|
71
73
|
* switching needs a new chat rather than changing the transport silently. */
|
|
72
74
|
harnessEditable?: boolean;
|
|
73
75
|
onSelectHarness?: (harness: string) => void;
|
|
76
|
+
/** "Wait for session" for the next prompt, mounted in the toolbar. */
|
|
77
|
+
waiting?: {
|
|
78
|
+
value: WaitingCandidate | null;
|
|
79
|
+
candidates: WaitingCandidate[];
|
|
80
|
+
onChange: (candidate: WaitingCandidate | null) => void;
|
|
81
|
+
};
|
|
82
|
+
/** A held prompt for THIS chat: the composer waits until it is released. */
|
|
83
|
+
heldWait?: { title: string | null } | null;
|
|
84
|
+
onCancelWait?: () => void;
|
|
74
85
|
}
|
|
75
86
|
|
|
76
87
|
/**
|
|
@@ -115,6 +126,9 @@ export function ComposerDock({
|
|
|
115
126
|
harness,
|
|
116
127
|
harnessEditable = true,
|
|
117
128
|
onSelectHarness,
|
|
129
|
+
waiting,
|
|
130
|
+
heldWait = null,
|
|
131
|
+
onCancelWait,
|
|
118
132
|
}: ComposerDockProps) {
|
|
119
133
|
// Side questions take over the composer entirely: the chat's own input is
|
|
120
134
|
// hidden while the form is open, so a stray Enter cannot send to the wrong
|
|
@@ -136,6 +150,24 @@ export function ComposerDock({
|
|
|
136
150
|
{...(harness ? { harness } : {})}
|
|
137
151
|
/>
|
|
138
152
|
)}
|
|
153
|
+
{heldWait && (
|
|
154
|
+
<div className="mb-2 flex items-center gap-2 rounded-lg border border-ink/15 bg-ink/[0.03] px-3 py-2 text-xs text-ink/70">
|
|
155
|
+
<Hourglass size={12} className="shrink-0 animate-pulse text-ink/60" />
|
|
156
|
+
<span className="min-w-0 flex-1 truncate">
|
|
157
|
+
Waiting for {heldWait.title ?? 'another session'} to finish before this prompt is sent.
|
|
158
|
+
</span>
|
|
159
|
+
{onCancelWait && (
|
|
160
|
+
<button
|
|
161
|
+
type="button"
|
|
162
|
+
data-testid="cancel-held-prompt"
|
|
163
|
+
onClick={onCancelWait}
|
|
164
|
+
className="shrink-0 rounded border border-ink/20 px-2 py-0.5 text-[11px] text-ink/70 hover:bg-ink/5 hover:text-ink cursor-pointer"
|
|
165
|
+
>
|
|
166
|
+
Cancel
|
|
167
|
+
</button>
|
|
168
|
+
)}
|
|
169
|
+
</div>
|
|
170
|
+
)}
|
|
139
171
|
<QueueList
|
|
140
172
|
queue={messageQueue}
|
|
141
173
|
onRemove={onRemoveQueueItem}
|
|
@@ -164,6 +196,7 @@ export function ComposerDock({
|
|
|
164
196
|
onAttachmentsChange={setAttachments}
|
|
165
197
|
onSend={onSend}
|
|
166
198
|
isGenerating={isGenerating}
|
|
199
|
+
disabled={Boolean(heldWait)}
|
|
167
200
|
chatRunning={showGeneratingIndicator}
|
|
168
201
|
onStop={onStop}
|
|
169
202
|
appSettings={appSettings}
|
|
@@ -174,6 +207,7 @@ export function ComposerDock({
|
|
|
174
207
|
modes={modes}
|
|
175
208
|
composerModelRef={composerModelRef}
|
|
176
209
|
deferredComposerPickRef={deferredComposerPickRef}
|
|
210
|
+
{...(waiting ? { waiting } : {})}
|
|
177
211
|
sessionModel={sessionModel}
|
|
178
212
|
sessionThinkingLevel={sessionThinkingLevel}
|
|
179
213
|
harness={harness}
|
|
@@ -227,6 +227,9 @@ export function EmptyWorkspacePrompt({
|
|
|
227
227
|
modes={modes}
|
|
228
228
|
composerModelRef={composerModelRef}
|
|
229
229
|
deferredComposerPickRef={deferredComposerPickRef}
|
|
230
|
+
{...(onWaitingForChange && docked
|
|
231
|
+
? { waiting: { value: waitingFor ?? null, candidates, onChange: onWaitingForChange } }
|
|
232
|
+
: {})}
|
|
230
233
|
{...(harness ? { harness } : {})}
|
|
231
234
|
harnessEditable={harnessEditable}
|
|
232
235
|
{...(onSelectHarness ? { onSelectHarness } : {})}
|
|
@@ -320,8 +323,6 @@ export function EmptyWorkspacePrompt({
|
|
|
320
323
|
branchAllowNone={branchAllowNone}
|
|
321
324
|
waitingFor={waitingFor}
|
|
322
325
|
onWaitingForChange={onWaitingForChange}
|
|
323
|
-
streamStatusMap={streamStatusMap}
|
|
324
|
-
titleForSession={titleForSession}
|
|
325
326
|
candidates={candidates}
|
|
326
327
|
/>
|
|
327
328
|
{/* A held prompt owns this chat until it is released: there is no
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The user row's Fork action is drawn only where the harness can fork at a
|
|
8
|
+
* user turn. omp cuts its own JSONL at any turn; the AIR adapters (claude,
|
|
9
|
+
* codex) only take an assistant message; every other agent forks the whole
|
|
10
|
+
* chat, which is the "Fork from" picker's job, not a per-row button.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
14
|
+
import { Window } from 'happy-dom';
|
|
15
|
+
import { h, render } from 'preact';
|
|
16
|
+
import { act } from 'preact/test-utils';
|
|
17
|
+
import { ChatMessageItem } from '@/client/components/workspace/chat-timeline/MessageItem';
|
|
18
|
+
import { SessionStateProvider } from '@/client/components/common/session-state-provider';
|
|
19
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
20
|
+
import type { ChatMessageData } from '@/shared/types';
|
|
21
|
+
|
|
22
|
+
let container: HTMLElement;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
26
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
render(null, container);
|
|
31
|
+
container.remove();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterAll(() => restoreDomGlobals());
|
|
35
|
+
|
|
36
|
+
const userRow: ChatMessageData = { id: 'u1', role: 'user', content: 'hello' };
|
|
37
|
+
|
|
38
|
+
function mount(harness?: string): { el: HTMLElement; calls: Array<[string, string]> } {
|
|
39
|
+
const calls: Array<[string, string]> = [];
|
|
40
|
+
act(() => {
|
|
41
|
+
render(
|
|
42
|
+
h(SessionStateProvider, {
|
|
43
|
+
sessionId: 'fork-test',
|
|
44
|
+
children: h(ChatMessageItem, {
|
|
45
|
+
msg: userRow,
|
|
46
|
+
onFork: (id, role) => calls.push([id, role]),
|
|
47
|
+
...(harness ? { harness } : {}),
|
|
48
|
+
}),
|
|
49
|
+
}),
|
|
50
|
+
container,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
return { el: container, calls };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const FORK = 'button[aria-label="Fork this session from this message"]';
|
|
57
|
+
|
|
58
|
+
describe('user row fork visibility', () => {
|
|
59
|
+
test('omp offers Fork on a user turn and anchors at that row', () => {
|
|
60
|
+
const { el, calls } = mount('omp-rpc');
|
|
61
|
+
const fork = el.querySelector(FORK) as HTMLButtonElement | null;
|
|
62
|
+
expect(fork).not.toBeNull();
|
|
63
|
+
act(() => fork!.click());
|
|
64
|
+
expect(calls).toEqual([['u1', 'user']]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('an AIR adapter has no fork point on a user turn', () => {
|
|
68
|
+
expect(mount('claude').el.querySelector(FORK)).toBeNull();
|
|
69
|
+
expect(mount('codex').el.querySelector(FORK)).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a harness that can only fork the whole chat draws no per-row Fork', () => {
|
|
73
|
+
expect(mount('zcode').el.querySelector(FORK)).toBeNull();
|
|
74
|
+
expect(mount('opencode').el.querySelector(FORK)).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('an unresolved harness keeps the historical button', () => {
|
|
78
|
+
expect(mount().el.querySelector(FORK)).not.toBeNull();
|
|
79
|
+
});
|
|
80
|
+
});
|