@kabmo-labs/kabmo 0.23.0 → 0.25.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 +805 -736
- package/dist/client/static/js/index-bc9aa4mx.css +1 -0
- package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
- package/src/client/components/common/session-actions-menu/index.tsx +33 -2
- package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
- package/src/client/components/common/session-row/index.tsx +27 -1
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +55 -46
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +5 -5
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +12 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +56 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
- package/src/client/hooks/chat/timeline/send.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.ts +59 -53
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +10 -3
- package/src/client/hooks/models/use-harness-update.test.ts +193 -0
- package/src/client/hooks/models/use-harness-update.ts +202 -0
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/hooks/workspace/child-expansion.ts +33 -0
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/tailwind.css +26 -12
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/client.ts +2 -2
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/mapper.ts +6 -4
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
- package/src/server/lib/harness/acp/session-handshake.ts +36 -3
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-requests.ts +47 -0
- package/src/server/lib/harness/acp/session-turns.ts +20 -5
- package/src/server/lib/harness/acp/session.test-util.ts +54 -3
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +79 -79
- package/src/server/lib/harness/acp/turn.test.ts +81 -0
- package/src/server/lib/harness/acp/turn.ts +54 -13
- package/src/server/lib/harness/acp/verbs.ts +12 -2
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +16 -116
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +126 -0
- package/src/server/lib/harness/update-job-store.ts +109 -0
- package/src/server/lib/harness/update-job.server.ts +203 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +197 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/lifecycle/paths.ts +23 -0
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
- package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
- package/src/server/lib/omp/session/delete.server.ts +17 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +209 -0
- package/src/server/lib/sessions/fork.server.ts +304 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +196 -0
- package/src/server/lib/sessions/spawn.server.ts +310 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +6 -0
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +22 -4
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update-status.ts +26 -0
- package/src/server/routes/harness/update.test.ts +119 -0
- package/src/server/routes/harness/update.ts +67 -113
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +74 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/session.ts +4 -0
- package/src/server/routes/sessions/spawn.ts +134 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +59 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +44 -1
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +33 -0
- package/src/shared/lib/harness/update-plan.test.ts +69 -4
- package/src/shared/lib/harness/update-plan.ts +57 -9
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +26 -10
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +65 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +21 -4
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The harness catalog's module-level store and its one read.
|
|
8
|
+
*
|
|
9
|
+
* Split from `use-harnesses.ts` so the hook holds the controller and this file
|
|
10
|
+
* holds the state, the shared in-flight read and the invalidation generation.
|
|
11
|
+
* Two mounted surfaces — the composer's tab strip and Settings → Harnesses — read
|
|
12
|
+
* `/api/harness` at once, and probes used to live in whichever instance ran them;
|
|
13
|
+
* one store is what makes a probe visible everywhere without a reload.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
HarnessConfig, HarnessProviderSupport, HarnessesPayload, HarnessSummary, LiveHarnessModels,
|
|
18
|
+
} from '@/shared/types/harness';
|
|
19
|
+
|
|
20
|
+
export interface HarnessStore {
|
|
21
|
+
harnesses: HarnessSummary[];
|
|
22
|
+
configs: Record<string, HarnessConfig>;
|
|
23
|
+
providerSupport: Record<string, HarnessProviderSupport>;
|
|
24
|
+
liveModels: Record<string, LiveHarnessModels>;
|
|
25
|
+
isLoading: boolean;
|
|
26
|
+
error: string | null;
|
|
27
|
+
/** Bumped on every change, so `useSyncExternalStore`-style subscribers can
|
|
28
|
+
* detect it without holding the arrays themselves. */
|
|
29
|
+
version: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const store: HarnessStore = {
|
|
33
|
+
harnesses: [], configs: {}, providerSupport: {}, liveModels: {}, isLoading: true, error: null, version: 0,
|
|
34
|
+
};
|
|
35
|
+
/** Has the catalog been read at least once? A later mount must NOT re-fetch: the
|
|
36
|
+
* answer is a property of the installed agents, and `reload()` is the explicit
|
|
37
|
+
* way to re-read it. */
|
|
38
|
+
let loaded = false;
|
|
39
|
+
export const listeners = new Set<() => void>();
|
|
40
|
+
/** One in-flight catalog read shared by every mount; a second mount joins it
|
|
41
|
+
* rather than firing its own `GET /api/harness`. */
|
|
42
|
+
let inflight: Promise<void> | null = null;
|
|
43
|
+
/**
|
|
44
|
+
* Bumped by every invalidation. A read that was ALREADY IN FLIGHT when one
|
|
45
|
+
* landed answers from the state before the write (the `models` frame routinely
|
|
46
|
+
* arrives during the mount's own read), so joining it would leave the picker on
|
|
47
|
+
* the old catalog until the next explicit reload. The read re-runs instead.
|
|
48
|
+
*/
|
|
49
|
+
let generation = 0;
|
|
50
|
+
|
|
51
|
+
export function emit(patch: Partial<HarnessStore>): void {
|
|
52
|
+
Object.assign(store, patch);
|
|
53
|
+
store.version += 1;
|
|
54
|
+
for (const listener of listeners) listener();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Drop the cached answer and read again, even if a read is still in flight. */
|
|
58
|
+
export function invalidateCatalog(): Promise<void> {
|
|
59
|
+
loaded = false;
|
|
60
|
+
generation += 1;
|
|
61
|
+
return loadCatalog();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function loadCatalog(): Promise<void> {
|
|
65
|
+
if (inflight) return inflight;
|
|
66
|
+
if (loaded) return;
|
|
67
|
+
const stamp = generation;
|
|
68
|
+
emit({ isLoading: true });
|
|
69
|
+
inflight = fetch('/api/harness')
|
|
70
|
+
.then(async (response) => {
|
|
71
|
+
if (!response.ok) throw new Error(`GET /api/harness answered ${response.status}`);
|
|
72
|
+
return (await response.json()) as HarnessesPayload;
|
|
73
|
+
})
|
|
74
|
+
.then((payload) => {
|
|
75
|
+
loaded = true;
|
|
76
|
+
emit({
|
|
77
|
+
harnesses: Array.isArray(payload.harnesses) ? payload.harnesses : [],
|
|
78
|
+
// Absent from an answer written before per-harness config existed: an
|
|
79
|
+
// empty map is the honest reading, and every card then shows "not set".
|
|
80
|
+
configs: payload.configs ?? {},
|
|
81
|
+
providerSupport: payload.providerSupport ?? {},
|
|
82
|
+
error: null,
|
|
83
|
+
isLoading: false,
|
|
84
|
+
});
|
|
85
|
+
})
|
|
86
|
+
.catch((cause: unknown) => {
|
|
87
|
+
emit({
|
|
88
|
+
error: cause instanceof Error ? cause.message : 'Could not read the harness list',
|
|
89
|
+
isLoading: false,
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
.finally(() => {
|
|
93
|
+
inflight = null;
|
|
94
|
+
// A write landed while this read was in flight: the answer just stored
|
|
95
|
+
// describes the pre-write state, so read once more rather than keep it.
|
|
96
|
+
if (stamp !== generation) void invalidateCatalog();
|
|
97
|
+
});
|
|
98
|
+
return inflight;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Forget everything this process learned about the harnesses.
|
|
102
|
+
*
|
|
103
|
+
* Two callers, one meaning: a test file starts from a cold store, and
|
|
104
|
+
* `bun --hot` re-evaluates this module while the old store may still describe
|
|
105
|
+
* agents that have since been installed or removed.
|
|
106
|
+
*/
|
|
107
|
+
export function resetHarnessesStore(): void {
|
|
108
|
+
inflight = null;
|
|
109
|
+
loaded = false;
|
|
110
|
+
Object.assign(store, {
|
|
111
|
+
harnesses: [], configs: {}, providerSupport: {}, liveModels: {}, isLoading: true, error: null, version: 0,
|
|
112
|
+
});
|
|
113
|
+
for (const listener of listeners) listener();
|
|
114
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A landed provider write must hand the browser the two facts the card cannot
|
|
8
|
+
* derive itself: the config the server saved and the harness tabs whose cached
|
|
9
|
+
* probe measured the OLD registry. Dropping `probeInvalidated` left the composer
|
|
10
|
+
* picker on a stale model list, because nothing told that tab to probe again.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
14
|
+
|
|
15
|
+
import { addProvider, importProvider } from '@/client/hooks/models/provider-writes';
|
|
16
|
+
|
|
17
|
+
const realFetch = Bun.fetch;
|
|
18
|
+
let bodies: unknown[] = [];
|
|
19
|
+
let announceCalls: unknown[][] = [];
|
|
20
|
+
|
|
21
|
+
function stubFetch(payload: unknown, status = 200): void {
|
|
22
|
+
(globalThis as unknown as Record<string, unknown>).fetch = async (_input: unknown, init?: { body?: string }) => {
|
|
23
|
+
bodies.push(init?.body ? JSON.parse(init.body) : null);
|
|
24
|
+
return new Response(JSON.stringify(payload), {
|
|
25
|
+
status,
|
|
26
|
+
headers: { 'content-type': 'application/json' },
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
bodies = [];
|
|
33
|
+
announceCalls = [];
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
(globalThis as unknown as Record<string, unknown>).fetch = realFetch;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function announce(id: string, config?: unknown, invalidated?: unknown): void {
|
|
41
|
+
announceCalls.push([id, config, invalidated]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('provider writes', () => {
|
|
45
|
+
test('an add announces the saved config and the probes it invalidated', async () => {
|
|
46
|
+
const config = { path: '/home/me/.claude.json' };
|
|
47
|
+
stubFetch({ config, probeInvalidated: ['omp-acp'], protocol: 'anthropic', target: 'anthropic' });
|
|
48
|
+
|
|
49
|
+
const outcome = await addProvider('omp-acp', { target: 'registry', id: 'minimax' } as never, announce);
|
|
50
|
+
|
|
51
|
+
expect(outcome.problem).toBeNull();
|
|
52
|
+
expect(outcome.detail).toBe('anthropic → anthropic');
|
|
53
|
+
expect(announceCalls).toEqual([['omp-acp', config, ['omp-acp']]]);
|
|
54
|
+
expect(bodies).toEqual([{ probe: 'omp-acp', addProvider: { target: 'registry', id: 'minimax' } }]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('an import carries the row, not the credential', async () => {
|
|
58
|
+
stubFetch({ imported: { id: 'minimax', replaced: false, path: '/w/models.yml', dialect: 'omp', notes: [] } });
|
|
59
|
+
|
|
60
|
+
const outcome = await importProvider(
|
|
61
|
+
'omp-acp',
|
|
62
|
+
'minimax',
|
|
63
|
+
{ source: 'claude', name: 'MiniMax', baseUrl: 'https://api.minimax.io', protocol: 'anthropic', models: ['m1'], contextWindow: 200_000 } as never,
|
|
64
|
+
announce,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(outcome.problem).toBeNull();
|
|
68
|
+
const body = bodies[0] as { importProvider: { entry: Record<string, unknown> } };
|
|
69
|
+
expect(body.importProvider.entry).not.toHaveProperty('apiKey');
|
|
70
|
+
expect(body.importProvider.entry.models).toEqual(['m1']);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('a refused write reports the server reason and announces nothing', async () => {
|
|
74
|
+
stubFetch({ error: 'that harness has no launch command' }, 400);
|
|
75
|
+
|
|
76
|
+
const outcome = await addProvider('omp-acp', { target: 'registry' } as never, announce);
|
|
77
|
+
|
|
78
|
+
expect(outcome.problem).toBe('that harness has no launch command');
|
|
79
|
+
expect(announceCalls).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -34,14 +34,21 @@ interface ProviderWritePayload {
|
|
|
34
34
|
target?: string;
|
|
35
35
|
protocol?: string;
|
|
36
36
|
probe?: { protocols: string[]; error?: string };
|
|
37
|
+
/** Harness tabs whose cached probe no longer describes the registry. */
|
|
38
|
+
probeInvalidated?: string[];
|
|
37
39
|
error?: string;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/**
|
|
41
43
|
* What `announce` does with a landed write: save the config the server answered
|
|
42
|
-
* with, when there is one, and re-
|
|
44
|
+
* with, when there is one, re-read the catalog, and re-probe the harness tabs
|
|
45
|
+
* whose cached answer the write invalidated.
|
|
43
46
|
*/
|
|
44
|
-
export type ProviderWriteAnnouncer = (
|
|
47
|
+
export type ProviderWriteAnnouncer = (
|
|
48
|
+
id: string,
|
|
49
|
+
config?: HarnessConfig,
|
|
50
|
+
probeInvalidated?: readonly string[],
|
|
51
|
+
) => void;
|
|
45
52
|
|
|
46
53
|
/**
|
|
47
54
|
* Turn one provider-write answer into what the card repeats.
|
|
@@ -63,7 +70,7 @@ function outcomeOf(
|
|
|
63
70
|
}
|
|
64
71
|
// An env-style target answered with a CONFIG; a registry target with what it
|
|
65
72
|
// wrote. Both change what the card shows, so both are folded back in.
|
|
66
|
-
announce(id, payload.config);
|
|
73
|
+
announce(id, payload.config, payload.probeInvalidated);
|
|
67
74
|
const imported = payload.imported;
|
|
68
75
|
const parts = [
|
|
69
76
|
payload.protocol ? `${payload.protocol} → ${payload.target ?? imported?.path ?? 'the agent'}` : null,
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The dialog's half of the background harness update.
|
|
8
|
+
*
|
|
9
|
+
* Three properties, and each one is a failure this design exists to prevent:
|
|
10
|
+
* a `202` means the install is running in a WORKER (so the card must follow it),
|
|
11
|
+
* a `409` must come back as the refusal it is (no second install), and a run
|
|
12
|
+
* already in flight must be ADOPTED when the card opens — otherwise a reload
|
|
13
|
+
* loses the spinner and the user presses the button again.
|
|
14
|
+
*
|
|
15
|
+
* Every wait here is on the settle callback, not on a duration: the poll cadence
|
|
16
|
+
* is handed in at 1ms, so a race shows up as a missing signal rather than as a
|
|
17
|
+
* sleep that "usually" covers it.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
21
|
+
import { Window } from 'happy-dom';
|
|
22
|
+
import { h, render } from 'preact';
|
|
23
|
+
import { act } from 'preact/test-utils';
|
|
24
|
+
import { useHarnessUpdate } from '@/client/hooks/models/use-harness-update';
|
|
25
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
26
|
+
import type { HarnessUpdateJob } from '@/shared/types/harness-update';
|
|
27
|
+
|
|
28
|
+
const realFetch = Bun.fetch;
|
|
29
|
+
const TEST_POLL_MS = 1;
|
|
30
|
+
let container: HTMLElement;
|
|
31
|
+
let calls: string[] = [];
|
|
32
|
+
let postPayload: { status: number; body: unknown } = { status: 202, body: {} };
|
|
33
|
+
let statusPayload: HarnessUpdateJob | null = null;
|
|
34
|
+
|
|
35
|
+
function job(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
|
|
36
|
+
return {
|
|
37
|
+
harness: 'claude',
|
|
38
|
+
label: 'claude',
|
|
39
|
+
startedAt: Date.now(),
|
|
40
|
+
finishedAt: null,
|
|
41
|
+
pid: 1234,
|
|
42
|
+
steps: [{ part: 'adapter', command: 'npm install -g x', argv: ['npm', 'install', '-g', 'x'], state: 'running', code: null }],
|
|
43
|
+
output: '',
|
|
44
|
+
ok: null,
|
|
45
|
+
message: null,
|
|
46
|
+
applied: false,
|
|
47
|
+
repointed: null,
|
|
48
|
+
...overrides,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
54
|
+
container = document.createElement('div');
|
|
55
|
+
document.body.appendChild(container);
|
|
56
|
+
calls = [];
|
|
57
|
+
statusPayload = null;
|
|
58
|
+
postPayload = { status: 202, body: {} };
|
|
59
|
+
(globalThis as unknown as Record<string, unknown>).fetch = async (input: unknown, init?: { method?: string }) => {
|
|
60
|
+
calls.push(`${init?.method ?? 'GET'} ${String(input)}`);
|
|
61
|
+
if (init?.method === 'POST') {
|
|
62
|
+
return new Response(JSON.stringify(postPayload.body), { status: postPayload.status });
|
|
63
|
+
}
|
|
64
|
+
return new Response(JSON.stringify({ job: statusPayload }), { status: 200 });
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
render(null, container);
|
|
70
|
+
container.remove();
|
|
71
|
+
restoreDomGlobals();
|
|
72
|
+
(globalThis as unknown as Record<string, unknown>).fetch = realFetch;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
interface Harness {
|
|
76
|
+
current: () => ReturnType<typeof useHarnessUpdate>;
|
|
77
|
+
/** Resolves with what the card was told when the run settled. */
|
|
78
|
+
settled: Promise<{ message: string; ok: boolean }>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function mount(): Harness {
|
|
82
|
+
const { promise, resolve } = Promise.withResolvers<{ message: string; ok: boolean }>();
|
|
83
|
+
const box = { latest: null as ReturnType<typeof useHarnessUpdate> | null };
|
|
84
|
+
function Consumer() {
|
|
85
|
+
box.latest = useHarnessUpdate((message, ok) => resolve({ message, ok }), { pollMs: TEST_POLL_MS });
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const host = document.createElement('div');
|
|
89
|
+
container.appendChild(host);
|
|
90
|
+
act(() => render(h(Consumer, {}), host));
|
|
91
|
+
return {
|
|
92
|
+
current: () => {
|
|
93
|
+
if (!box.latest) throw new Error('consumer did not render');
|
|
94
|
+
return box.latest;
|
|
95
|
+
},
|
|
96
|
+
settled: promise,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Let the mount's own status read settle. */
|
|
101
|
+
async function flush(): Promise<void> {
|
|
102
|
+
await act(async () => {
|
|
103
|
+
await Promise.resolve();
|
|
104
|
+
await Promise.resolve();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
describe('useHarnessUpdate', () => {
|
|
109
|
+
test('a 202 starts a run and the finished record settles it', async () => {
|
|
110
|
+
const harness = mount();
|
|
111
|
+
await flush();
|
|
112
|
+
expect(harness.current().updating).toBeNull();
|
|
113
|
+
|
|
114
|
+
postPayload = { status: 202, body: { started: true, job: job() } };
|
|
115
|
+
// The worker is already done by the time the first status read lands: this
|
|
116
|
+
// is the spinners-then-message path, with no real delay anywhere.
|
|
117
|
+
statusPayload = job({ finishedAt: Date.now(), pid: null, ok: true, applied: true, message: 'claude updated (adapter)' });
|
|
118
|
+
|
|
119
|
+
const started: { problem: string | null } = { problem: 'unset' };
|
|
120
|
+
await act(async () => {
|
|
121
|
+
started.problem = await harness.current().start('claude');
|
|
122
|
+
});
|
|
123
|
+
expect(started.problem).toBeNull();
|
|
124
|
+
// The spinner's own state is pinned by the adoption case below; here the
|
|
125
|
+
// record was already finished, so the run settles inside the same flush.
|
|
126
|
+
expect(await harness.settled).toEqual({ message: 'claude updated (adapter)', ok: true });
|
|
127
|
+
expect(harness.current().updating).toBeNull();
|
|
128
|
+
// The record outlives the spinner: the log panel reads it AFTER the run, and
|
|
129
|
+
// a cleared `job` would close the reader's only view of what was installed.
|
|
130
|
+
expect(harness.current().job?.message).toBe('claude updated (adapter)');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('a 409 comes back as the refusal, and its record is still readable', async () => {
|
|
134
|
+
// The refusal carries the RUNNING record (`job`), so the press that lost the
|
|
135
|
+
// race can still open the log of the install it collided with.
|
|
136
|
+
postPayload = {
|
|
137
|
+
status: 409,
|
|
138
|
+
body: { error: 'claude update is already running — it continues in the background', job: job({ pid: 999 }) },
|
|
139
|
+
};
|
|
140
|
+
const harness = mount();
|
|
141
|
+
await flush();
|
|
142
|
+
|
|
143
|
+
const refusal: { problem: string | null } = { problem: null };
|
|
144
|
+
await act(async () => {
|
|
145
|
+
refusal.problem = await harness.current().start('claude');
|
|
146
|
+
});
|
|
147
|
+
expect(refusal.problem).toContain('already running');
|
|
148
|
+
expect(harness.current().updating).toBeNull();
|
|
149
|
+
expect(harness.current().job?.pid).toBe(999);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('an in-flight run is adopted when the card opens', async () => {
|
|
153
|
+
statusPayload = job();
|
|
154
|
+
const harness = mount();
|
|
155
|
+
await flush();
|
|
156
|
+
// The spinner belongs to a run this page did not start — a second tab, or
|
|
157
|
+
// this one after a reload.
|
|
158
|
+
expect(harness.current().updating).toBe('claude');
|
|
159
|
+
|
|
160
|
+
statusPayload = job({ finishedAt: Date.now(), pid: null, ok: false, applied: true, message: 'claude update failed (exit 1)' });
|
|
161
|
+
expect(await harness.settled).toEqual({ message: 'claude update failed (exit 1)', ok: false });
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('a finished record on open is history, not a run to follow', async () => {
|
|
165
|
+
statusPayload = job({ finishedAt: Date.now(), pid: null, ok: true, applied: true, message: 'claude updated (adapter)' });
|
|
166
|
+
const harness = mount();
|
|
167
|
+
await flush();
|
|
168
|
+
expect(harness.current().updating).toBeNull();
|
|
169
|
+
// No spinner, but the row can still offer the log of what ran.
|
|
170
|
+
expect(harness.current().job?.harness).toBe('claude');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('"already up to date" is reported without following a job', async () => {
|
|
174
|
+
postPayload = {
|
|
175
|
+
status: 200,
|
|
176
|
+
body: { success: true, id: 'claude', message: 'claude is already up to date (adapter 0.102.0)' },
|
|
177
|
+
};
|
|
178
|
+
const harness = mount();
|
|
179
|
+
await flush();
|
|
180
|
+
|
|
181
|
+
const current: { problem: string | null } = { problem: null };
|
|
182
|
+
await act(async () => {
|
|
183
|
+
current.problem = await harness.current().start('claude');
|
|
184
|
+
});
|
|
185
|
+
expect(current.problem).toBeNull();
|
|
186
|
+
expect(harness.current().updating).toBeNull();
|
|
187
|
+
// Nothing ran, so there is no record for a row to show a log of.
|
|
188
|
+
expect(harness.current().job).toBeNull();
|
|
189
|
+
expect(await harness.settled).toEqual({ message: 'claude is already up to date (adapter 0.102.0)', ok: true });
|
|
190
|
+
// One read — the mount's — and no poll for a job that does not exist.
|
|
191
|
+
expect(calls.filter((call) => call.startsWith('GET /api/harness/update/status'))).toHaveLength(1);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Starting a harness update, and following the background job it becomes.
|
|
8
|
+
*
|
|
9
|
+
* The POST used to hold the request open for the whole install; now it answers
|
|
10
|
+
* `202` and the run continues in a detached worker. So the dialog's job has two
|
|
11
|
+
* halves: start it, then poll `GET /api/harness/update/status` until the record
|
|
12
|
+
* says it finished — and, on open, ADOPT a run that is already in flight. That
|
|
13
|
+
* second half is what makes the update really background: closing About, or
|
|
14
|
+
* reloading the page, does not lose the button's state, and a reopened card
|
|
15
|
+
* shows the spinner for the run that is still installing.
|
|
16
|
+
*
|
|
17
|
+
* The rows are re-read once the run settles (`invalidateHarnessVersions`): the
|
|
18
|
+
* update forgot the cached probe, so the next read is the first honest one.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
22
|
+
import { invalidateHarnessVersions } from '@/client/hooks/models/use-harness-versions';
|
|
23
|
+
import { isHarnessUpdateJob, updateJobFrom } from '@/shared/lib/harness/update-job';
|
|
24
|
+
import type { HarnessUpdateJob } from '@/shared/types/harness-update';
|
|
25
|
+
|
|
26
|
+
/** One poll per second: the worker flushes at 400ms, and this is a dialog. */
|
|
27
|
+
export const HARNESS_UPDATE_POLL_MS = 1_000;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Stop polling after this long and hand the control back.
|
|
31
|
+
*
|
|
32
|
+
* The install itself is bounded per step by the worker; this only stops an
|
|
33
|
+
* open dialog from asking forever if the record stopped moving. The run is not
|
|
34
|
+
* cancelled — closing the dialog never cancels anything.
|
|
35
|
+
*/
|
|
36
|
+
const MAX_FOLLOW_MS = 45 * 60_000;
|
|
37
|
+
|
|
38
|
+
/** How the hook behaves, for the two callers that need to differ from the
|
|
39
|
+
* default: the dialog passes its own open state, and a test its own cadence. */
|
|
40
|
+
export interface HarnessUpdateOptions {
|
|
41
|
+
/** The poll cadence. One second suits a dialog. */
|
|
42
|
+
pollMs?: number;
|
|
43
|
+
/** Is the surface that owns this hook on screen? While it is not, no status is
|
|
44
|
+
* read and no run is followed — a run already in flight is ADOPTED on the
|
|
45
|
+
* next open, which is what "background" means here. */
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface HarnessUpdateController {
|
|
50
|
+
/** The harness whose run this dialog is following, or null. */
|
|
51
|
+
updating: string | null;
|
|
52
|
+
/** The step the worker is on (`adapter`, `Claude Code`, …), when it says. */
|
|
53
|
+
progress: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* The record itself — the last one read, running or finished.
|
|
56
|
+
*
|
|
57
|
+
* The log dialog renders from this: the worker streams every command's output
|
|
58
|
+
* into it, so the panel is the install's own console. It is NOT cleared when a
|
|
59
|
+
* run settles, because the interesting moment to read the log is often after
|
|
60
|
+
* it failed.
|
|
61
|
+
*/
|
|
62
|
+
job: HarnessUpdateJob | null;
|
|
63
|
+
/** Start an update; resolves to a refusal, or null when the run was started
|
|
64
|
+
* (or there was nothing to move). */
|
|
65
|
+
start: (id: string) => Promise<string | null>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type Settled = (message: string, ok: boolean) => void;
|
|
69
|
+
|
|
70
|
+
function runningStep(job: HarnessUpdateJob | null): string | null {
|
|
71
|
+
const steps = job && Array.isArray(job.steps) ? job.steps : [];
|
|
72
|
+
return steps.find((step) => step.state === 'running')?.part ?? null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function useHarnessUpdate(
|
|
76
|
+
onSettled: Settled,
|
|
77
|
+
{ pollMs = HARNESS_UPDATE_POLL_MS, enabled = true }: HarnessUpdateOptions = {},
|
|
78
|
+
): HarnessUpdateController {
|
|
79
|
+
const [updating, setUpdating] = useState<string | null>(null);
|
|
80
|
+
const [progress, setProgress] = useState<string | null>(null);
|
|
81
|
+
const [job, setJob] = useState<HarnessUpdateJob | null>(null);
|
|
82
|
+
const alive = useRef(true);
|
|
83
|
+
// The callback is read through a ref so an inline arrow from the caller does
|
|
84
|
+
// not restart the mount effect (and re-adopt the job) on every render.
|
|
85
|
+
const settled = useRef(onSettled);
|
|
86
|
+
settled.current = onSettled;
|
|
87
|
+
|
|
88
|
+
const follow = useCallback(async (id: string): Promise<void> => {
|
|
89
|
+
const startedAt = Date.now();
|
|
90
|
+
while (alive.current) {
|
|
91
|
+
let job: HarnessUpdateJob | null = null;
|
|
92
|
+
try {
|
|
93
|
+
const response = await fetch('/api/harness/update/status', { cache: 'no-store' });
|
|
94
|
+
if (!response.ok) throw new Error(String(response.status));
|
|
95
|
+
job = updateJobFrom(await response.json());
|
|
96
|
+
} catch {
|
|
97
|
+
// A transient failure is not the update failing: the record lives on
|
|
98
|
+
// disk and the next poll reads it.
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!alive.current) return;
|
|
102
|
+
// Kept even once it finishes: the log stays readable while the panel is
|
|
103
|
+
// open, and a failure is the case a reader wants the output for.
|
|
104
|
+
if (job) setJob(job);
|
|
105
|
+
if (job?.finishedAt != null) {
|
|
106
|
+
setUpdating(null);
|
|
107
|
+
setProgress(null);
|
|
108
|
+
invalidateHarnessVersions();
|
|
109
|
+
settled.current(job.message ?? (job.ok ? 'Update finished' : 'Update failed'), Boolean(job.ok));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (job?.harness === id) setProgress(runningStep(job));
|
|
113
|
+
|
|
114
|
+
if (Date.now() - startedAt > MAX_FOLLOW_MS) {
|
|
115
|
+
setUpdating(null);
|
|
116
|
+
setProgress(null);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
120
|
+
setTimeout(resolve, pollMs);
|
|
121
|
+
await promise;
|
|
122
|
+
}
|
|
123
|
+
}, [pollMs]);
|
|
124
|
+
|
|
125
|
+
// Adopt a run that is already going: another tab, or this dialog reopened.
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
// A closed card has nothing to show and nothing to poll for; the run keeps
|
|
128
|
+
// going in its worker either way.
|
|
129
|
+
if (!enabled) {
|
|
130
|
+
alive.current = false;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
alive.current = true;
|
|
134
|
+
void (async () => {
|
|
135
|
+
try {
|
|
136
|
+
const response = await fetch('/api/harness/update/status', { cache: 'no-store' });
|
|
137
|
+
if (!response.ok) return;
|
|
138
|
+
const running = updateJobFrom(await response.json());
|
|
139
|
+
if (!alive.current || !running) return;
|
|
140
|
+
setJob(running);
|
|
141
|
+
if (running.finishedAt !== null) return;
|
|
142
|
+
setUpdating(running.harness);
|
|
143
|
+
setProgress(runningStep(running));
|
|
144
|
+
void follow(running.harness);
|
|
145
|
+
} catch {
|
|
146
|
+
// Nothing running, or no server to ask: the list still renders.
|
|
147
|
+
}
|
|
148
|
+
})();
|
|
149
|
+
return () => {
|
|
150
|
+
alive.current = false;
|
|
151
|
+
};
|
|
152
|
+
}, [follow, enabled]);
|
|
153
|
+
|
|
154
|
+
const start = useCallback(async (id: string): Promise<string | null> => {
|
|
155
|
+
let response: Response;
|
|
156
|
+
try {
|
|
157
|
+
response = await fetch('/api/harness/update', {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
headers: { 'Content-Type': 'application/json' },
|
|
160
|
+
body: JSON.stringify({ harness: id }),
|
|
161
|
+
});
|
|
162
|
+
} catch (cause) {
|
|
163
|
+
return cause instanceof Error ? cause.message : 'Update failed';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const payload = (await response.json().catch(() => ({}))) as {
|
|
167
|
+
error?: string;
|
|
168
|
+
message?: string;
|
|
169
|
+
success?: boolean;
|
|
170
|
+
started?: boolean;
|
|
171
|
+
job?: HarnessUpdateJob;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// The POST's own record is trusted only if it IS a record; a payload that
|
|
175
|
+
// fails the guard still means "started", just without a step to name.
|
|
176
|
+
const posted = isHarnessUpdateJob(payload.job) ? payload.job : null;
|
|
177
|
+
|
|
178
|
+
if (response.status === 202 && payload.started) {
|
|
179
|
+
setUpdating(id);
|
|
180
|
+
setJob(posted);
|
|
181
|
+
setProgress(runningStep(posted));
|
|
182
|
+
void follow(id);
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
if (!response.ok) {
|
|
186
|
+
// A refusal carries the run that caused it: the reader can open ITS log
|
|
187
|
+
// instead of only being told to wait.
|
|
188
|
+
if (response.status === 409 && posted) setJob(posted);
|
|
189
|
+
return payload.error ?? `Update failed (HTTP ${response.status})`;
|
|
190
|
+
}
|
|
191
|
+
if (payload.success) {
|
|
192
|
+
// Nothing to move: the row is already current, so there is no job to
|
|
193
|
+
// follow. Re-read it anyway — the previous run may have moved it.
|
|
194
|
+
invalidateHarnessVersions();
|
|
195
|
+
settled.current(payload.message ?? 'Update finished', true);
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
return payload.error ?? 'Update failed';
|
|
199
|
+
}, [follow]);
|
|
200
|
+
|
|
201
|
+
return { updating, progress, job, start };
|
|
202
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The `useHarnesses()` contract, named where a consumer can import it.
|
|
8
|
+
*
|
|
9
|
+
* The store's implementation file is at the 350-line ceiling; the type earns its
|
|
10
|
+
* own module and keeps every consumer off `ReturnType<typeof useHarnesses>`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
HarnessConfig, HarnessImportOutcome, HarnessProviderSupport, HarnessSummary, LiveHarnessModels,
|
|
15
|
+
} from '@/shared/types/harness';
|
|
16
|
+
import type { AddProviderInput } from '@/client/components/settings/categories/harness-settings/AddProviderForm';
|
|
17
|
+
|
|
18
|
+
export interface HarnessesController {
|
|
19
|
+
harnesses: HarnessSummary[];
|
|
20
|
+
/** Per-harness config, keyed by id. Empty until the catalog is read. */
|
|
21
|
+
configs: Record<string, HarnessConfig>;
|
|
22
|
+
/** Persist one harness's config; resolves to the server's refusal, or null. */
|
|
23
|
+
saveConfig: (id: string, config: HarnessConfig) => Promise<string | null>;
|
|
24
|
+
/** What each harness can do about other providers, keyed by id. */
|
|
25
|
+
providerSupport: Record<string, HarnessProviderSupport>;
|
|
26
|
+
/**
|
|
27
|
+
* The model/thinking selectors a harness's LIVE chat published, keyed by id.
|
|
28
|
+
*
|
|
29
|
+
* A probe is one throwaway spawn, and it can be refused (`codex` answers
|
|
30
|
+
* "Authentication required" to the probe while the chat the user is running
|
|
31
|
+
* lists its models) or aged. The open session's own selectors are the truth
|
|
32
|
+
* for that harness, so the picker reads them first; absent means "only the
|
|
33
|
+
* probe has spoken".
|
|
34
|
+
*/
|
|
35
|
+
liveModels: Record<string, LiveHarnessModels>;
|
|
36
|
+
/** Copy one provider from a source registry into a harness.
|
|
37
|
+
*
|
|
38
|
+
* The ROW travels with the id: the writer needs the endpoint, dialect and
|
|
39
|
+
* model list, and the server would otherwise have to look them up again. The
|
|
40
|
+
* credential is not in the row — the server reads that from the source file. */
|
|
41
|
+
importProvider: (
|
|
42
|
+
id: string,
|
|
43
|
+
sourceId: string,
|
|
44
|
+
entry: HarnessProviderSupport['importable'][number],
|
|
45
|
+
) => Promise<HarnessImportOutcome>;
|
|
46
|
+
/** Add a provider by typing its endpoint and key. */
|
|
47
|
+
addProvider: (id: string, input: AddProviderInput) => Promise<HarnessImportOutcome>;
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
error: string | null;
|
|
50
|
+
/** Re-read the catalog. */
|
|
51
|
+
reload: () => void;
|
|
52
|
+
/** Probe one harness (spawns that agent once) and merge the answer in. */
|
|
53
|
+
probe: (id: string, cwd?: string) => Promise<string | null>;
|
|
54
|
+
/** Switch one harness on or off. Switching ON also probes it once, server-side,
|
|
55
|
+
* so its models are ready for the composer. Resolves to the refusal, or null. */
|
|
56
|
+
setEnabled: (id: string, enabled: boolean) => Promise<string | null>;
|
|
57
|
+
}
|