@kabmo-labs/kabmo 0.22.0 → 0.24.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/README.md +1 -1
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +873 -524
- package/dist/client/static/js/{index-297dck9a.js → index-jcr5twtp.js} +799 -795
- package/dist/client/static/js/index-z3w7n85q.css +1 -0
- package/marketplace/plugins/stats/package.json +2 -2
- package/marketplace/plugins/stats/src/groups.test.ts +14 -0
- package/marketplace/plugins/stats/src/groups.ts +20 -0
- package/marketplace/plugins/stats/src/labels.test.ts +9 -0
- package/marketplace/plugins/stats/src/labels.ts +7 -0
- package/marketplace/plugins/stats/src/server.ts +1 -1
- package/package.json +1 -1
- package/src/client/App.tsx +20 -19
- package/src/client/components/common/ComposerTextarea.tsx +10 -1
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/common/PWAInstallButton.tsx +3 -2
- package/src/client/components/common/Toast.test.tsx +298 -0
- package/src/client/components/common/Toast.tsx +103 -37
- package/src/client/components/common/ToastStack.tsx +33 -12
- package/src/client/components/common/ViewportSelector.tsx +122 -114
- package/src/client/components/common/context-usage-button/Ring.tsx +38 -1
- package/src/client/components/common/context-usage-button/index.test.tsx +19 -3
- package/src/client/components/common/context-usage-button/index.tsx +5 -2
- package/src/client/components/common/harness-glyph/brands.ts +65 -0
- package/src/client/components/common/harness-glyph/harness-glyph.test.ts +185 -0
- package/src/client/components/common/harness-glyph/index.tsx +131 -0
- package/src/client/components/common/header-controls/MoreMenu.tsx +2 -1
- package/src/client/components/common/header-controls/index.tsx +16 -8
- package/src/client/components/common/header-panel-buttons/index.tsx +4 -3
- package/src/client/components/common/panel-mark/index.test.tsx +2 -2
- package/src/client/components/common/panel-mark/index.tsx +11 -2
- package/src/client/components/common/search-select/index.tsx +305 -0
- package/src/client/components/common/search-select/search-select.test.tsx +217 -0
- package/src/client/components/common/server-control/index.tsx +3 -2
- package/src/client/components/common/session-row/index.tsx +18 -1
- package/src/client/components/common/toolbar-row/index.tsx +57 -20
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +1 -3
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +3 -2
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/index.tsx +1 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +1 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +18 -1
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +1 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +332 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +310 -0
- package/src/client/components/layout/session-sidebar/about-modal/SocialLinks.tsx +63 -51
- package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +4 -2
- 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 +136 -35
- package/src/client/components/layout/session-sidebar/harness-mark.test.tsx +126 -0
- package/src/client/components/layout/session-sidebar/modern/ActionRow.tsx +4 -3
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +1 -0
- package/src/client/components/mobile/LayoutWrapper.tsx +1 -7
- package/src/client/components/mobile/SessionSidebar.tsx +1 -3
- package/src/client/components/mobile/mobile-main-view/Header.tsx +3 -2
- package/src/client/components/mobile/mobile-session-sidebar/Dialogs.tsx +0 -8
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +1 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +17 -1
- package/src/client/components/settings/Modal.tsx +26 -22
- package/src/client/components/settings/Sidebar.tsx +45 -5
- package/src/client/components/settings/categories/HarnessSettings.tsx +207 -0
- package/src/client/components/settings/categories/ProjectSettings.tsx +1 -3
- package/src/client/components/settings/categories/ProviderSettings.tsx +0 -4
- package/src/client/components/settings/categories/SkillCatalogSettings.tsx +13 -23
- package/src/client/components/settings/categories/agent-settings/ModelPicker.tsx +23 -30
- package/src/client/components/settings/categories/appearance-settings/IconStyleSection.tsx +20 -11
- package/src/client/components/settings/categories/chat-settings/GoalSection.tsx +16 -16
- package/src/client/components/settings/categories/harness-settings/AddProviderForm.tsx +219 -0
- package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +268 -0
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +146 -0
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +278 -0
- package/src/client/components/settings/categories/harness-settings/ImportSection.tsx +195 -0
- package/src/client/components/settings/categories/harness-settings/ProviderPanel.tsx +152 -0
- package/src/client/components/settings/categories/harness-settings/ToggleList.tsx +147 -0
- package/src/client/components/settings/categories/harness-settings/parts.test.tsx +97 -0
- package/src/client/components/settings/categories/harness-settings/parts.tsx +84 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +313 -0
- package/src/client/components/settings/categories/omp-settings/RoleEditor.test.ts +60 -39
- package/src/client/components/settings/categories/omp-settings/RoleRow.tsx +32 -41
- package/src/client/components/settings/categories/omp-settings/role-picker.test-util.ts +45 -0
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +1 -1
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +11 -4
- package/src/client/components/settings/groups.test.tsx +160 -0
- package/src/client/components/settings/harness-icons.test.tsx +134 -0
- package/src/client/components/workspace/browser-panel/AddressBar.tsx +3 -13
- package/src/client/components/workspace/browser-toolbar/clusters.tsx +237 -0
- package/src/client/components/workspace/browser-toolbar/index.test.tsx +167 -0
- package/src/client/components/workspace/browser-toolbar/index.tsx +99 -100
- package/src/client/components/workspace/btw-panel/Messages.tsx +4 -1
- package/src/client/components/workspace/btw-panel/index.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +11 -7
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +13 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +13 -0
- package/src/client/components/workspace/chat-timeline/GeneratingIndicator.test.ts +41 -0
- package/src/client/components/workspace/chat-timeline/GeneratingIndicator.tsx +19 -14
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +6 -0
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +14 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/RunMark.tsx +58 -0
- package/src/client/components/workspace/chat-timeline/SubagentView.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +11 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +13 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +27 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +48 -23
- package/src/client/components/workspace/chat-timeline/chat-input/composer-portal.test.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +21 -1
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +7 -0
- package/src/client/components/workspace/chat-timeline/chat-input/props.ts +13 -0
- package/src/client/components/workspace/chat-timeline/chat-input/selection.ts +11 -2
- package/src/client/components/workspace/chat-timeline/chat-input/styles.test.tsx +1 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +17 -15
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +157 -0
- package/src/client/components/workspace/chat-timeline/run-mark.test.ts +104 -0
- 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/chat-timeline/tool-renderers/panels/Bash.test.ts +31 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +5 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +56 -45
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +38 -94
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-parts.tsx +76 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +10 -6
- package/src/client/components/workspace/git-panel/index.test.ts +13 -3
- package/src/client/components/workspace/git-panel/index.tsx +1 -3
- package/src/client/components/workspace/model-dropdown/Fullscreen.tsx +92 -0
- package/src/client/components/workspace/model-dropdown/HarnessTabs.tsx +290 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +11 -0
- package/src/client/components/workspace/model-dropdown/Panel.tsx +119 -8
- package/src/client/components/workspace/model-dropdown/Section.tsx +4 -0
- package/src/client/components/workspace/model-dropdown/fullscreen-picker.ts +51 -0
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +177 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +148 -0
- package/src/client/components/workspace/model-dropdown/harness-tabs.test.tsx +336 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +114 -85
- package/src/client/components/workspace/model-dropdown/placement.test.tsx +127 -0
- package/src/client/components/workspace/model-dropdown/popover-metrics.test.ts +107 -0
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +118 -0
- package/src/client/components/workspace/model-dropdown/row-mutations.ts +106 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +22 -2
- package/src/client/components/workspace/model-dropdown/use-popover-size.ts +89 -0
- package/src/client/data/settings/omp-schema.json +224 -17
- package/src/client/hooks/chat/composer/index.ts +11 -2
- package/src/client/hooks/chat/composer/items.test.ts +11 -0
- package/src/client/hooks/chat/composer/items.ts +4 -2
- package/src/client/hooks/chat/composer/model-selection.test.ts +110 -0
- package/src/client/hooks/chat/composer/model-selection.ts +45 -4
- package/src/client/hooks/chat/omp/prompt-send.ts +4 -2
- package/src/client/hooks/chat/timeline/actions.ts +10 -5
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/composer-local-actions.test.ts +19 -81
- package/src/client/hooks/chat/timeline/composer-modes.ts +11 -2
- package/src/client/hooks/chat/timeline/composer-refs.ts +16 -1
- package/src/client/hooks/chat/timeline/index.ts +27 -35
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +51 -0
- package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
- package/src/client/hooks/chat/timeline/modes.ts +41 -2
- 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 +7 -0
- package/src/client/hooks/chat/timeline/prompt-text.ts +15 -6
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +51 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +23 -1
- 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 +55 -0
- package/src/client/hooks/chat/timeline/send-props.ts +11 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +2 -3
- package/src/client/hooks/chat/timeline/send.test-util.ts +3 -2
- package/src/client/hooks/chat/timeline/send.test.ts +2 -3
- package/src/client/hooks/chat/timeline/send.ts +34 -8
- package/src/client/hooks/chat/timeline/session-harness.test.ts +163 -0
- package/src/client/hooks/chat/timeline/session-harness.ts +164 -0
- 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/spawn-harness.ts +41 -0
- package/src/client/hooks/chat/timeline/timeline-running.ts +55 -0
- package/src/client/hooks/chat/timeline/tui-only-guard.ts +9 -0
- package/src/client/hooks/chat/timeline/undo-confirmation.test.ts +131 -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 +144 -0
- package/src/client/hooks/models/use-harness-versions.test.ts +152 -0
- package/src/client/hooks/models/use-harness-versions.ts +136 -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 +187 -0
- package/src/client/hooks/models/use-harnesses.ts +215 -0
- package/src/client/hooks/settings/providers/index.ts +1 -3
- package/src/client/hooks/ui/editor-error-toast.ts +10 -3
- package/src/client/hooks/ui/icon-style.ts +28 -0
- package/src/client/hooks/ui/on-click-outside.test.ts +104 -0
- package/src/client/hooks/ui/on-click-outside.ts +14 -2
- package/src/client/hooks/ui/theme.ts +6 -0
- package/src/client/hooks/ui/toast-queue.test.ts +126 -0
- package/src/client/hooks/ui/toasts.ts +132 -27
- package/src/client/hooks/ui/ui-feedback.test.ts +4 -91
- package/src/client/lib/ui/control-plate.test.ts +76 -0
- package/src/client/lib/ui/control-plate.ts +65 -0
- package/src/client/tailwind.css +47 -1
- package/src/server/lib/assets/shell-attributes.server.ts +9 -2
- package/src/server/lib/assets/shell-attributes.test.ts +22 -6
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/harness/acp/acp-audit.server.ts +107 -0
- package/src/server/lib/harness/acp/acp-goal-driver.server.ts +153 -0
- package/src/server/lib/harness/acp/acp-goal-state.server.ts +136 -0
- package/src/server/lib/harness/acp/acp-goal.server.ts +273 -0
- package/src/server/lib/harness/acp/acp-goal.test.ts +229 -0
- package/src/server/lib/harness/acp/acp-telemetry.server.ts +133 -0
- package/src/server/lib/harness/acp/acp-telemetry.test.ts +85 -0
- package/src/server/lib/harness/acp/acp-todos.server.ts +45 -0
- package/src/server/lib/harness/acp/acp-todos.test.ts +43 -0
- 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/calls.ts +97 -0
- package/src/server/lib/harness/acp/client.test.ts +73 -0
- package/src/server/lib/harness/acp/client.ts +339 -0
- package/src/server/lib/harness/acp/commands.test.ts +92 -0
- package/src/server/lib/harness/acp/commands.ts +165 -0
- package/src/server/lib/harness/acp/frames.test.ts +315 -0
- package/src/server/lib/harness/acp/frames.ts +349 -0
- package/src/server/lib/harness/acp/mapper.ts +204 -0
- package/src/server/lib/harness/acp/permissions.test.ts +66 -0
- package/src/server/lib/harness/acp/permissions.ts +155 -0
- package/src/server/lib/harness/acp/prompt.test.ts +130 -0
- package/src/server/lib/harness/acp/prompt.ts +134 -0
- package/src/server/lib/harness/acp/protocol.ts +162 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +148 -0
- package/src/server/lib/harness/acp/session-facts.ts +71 -0
- package/src/server/lib/harness/acp/session-handshake.ts +89 -0
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-notifications.ts +95 -0
- package/src/server/lib/harness/acp/session-observers.test.ts +193 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +105 -0
- package/src/server/lib/harness/acp/session-permissions.ts +74 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-turns.ts +95 -0
- package/src/server/lib/harness/acp/session-usage.ts +60 -0
- package/src/server/lib/harness/acp/session-web-state.ts +61 -0
- package/src/server/lib/harness/acp/session.test-util.ts +160 -0
- package/src/server/lib/harness/acp/session.test.ts +233 -0
- package/src/server/lib/harness/acp/session.ts +350 -0
- package/src/server/lib/harness/acp/turn.ts +199 -0
- package/src/server/lib/harness/acp/verbs.ts +87 -0
- 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/capabilities.ts +67 -0
- package/src/server/lib/harness/config-invalidation.test.ts +91 -0
- package/src/server/lib/harness/config.server.test.ts +105 -0
- package/src/server/lib/harness/config.server.ts +98 -0
- package/src/server/lib/harness/enabled.server.test.ts +87 -0
- package/src/server/lib/harness/enabled.server.ts +61 -0
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +220 -0
- package/src/server/lib/harness/launch.ts +216 -0
- package/src/server/lib/harness/probe-cache.server.test.ts +154 -0
- package/src/server/lib/harness/probe-cache.server.ts +177 -0
- package/src/server/lib/harness/provider-entry.ts +212 -0
- package/src/server/lib/harness/provider-file.server.ts +67 -0
- package/src/server/lib/harness/provider-import.test.ts +191 -0
- package/src/server/lib/harness/provider-probe.server.ts +123 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +308 -0
- package/src/server/lib/harness/provider-write-error.ts +19 -0
- package/src/server/lib/harness/provider-write.server.test.ts +308 -0
- package/src/server/lib/harness/provider-write.server.ts +339 -0
- 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/register.server.ts +36 -0
- package/src/server/lib/harness/registry.ts +58 -0
- package/src/server/lib/harness/schema.server.ts +129 -0
- package/src/server/lib/harness/session-store.server.test.ts +175 -0
- package/src/server/lib/harness/session-store.server.ts +206 -0
- package/src/server/lib/harness/session-title.server.test.ts +109 -0
- package/src/server/lib/harness/session-title.server.ts +70 -0
- package/src/server/lib/harness/session.ts +74 -0
- package/src/server/lib/harness/spawn.server.ts +133 -0
- package/src/server/lib/harness/update-state.server.ts +185 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/models/provider-items.server.ts +1 -1
- 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/config/models-config.ts +4 -0
- package/src/server/lib/omp/core/cli.ts +13 -0
- package/src/server/lib/omp/core/host-resolution.test.ts +6 -3
- 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/event-fanout.ts +9 -0
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/rpc/rpc-primitives.test.ts +11 -0
- package/src/server/lib/omp/rpc/session-registration.ts +7 -2
- package/src/server/lib/omp/rpc/session-registry.test.ts +2 -1
- package/src/server/lib/omp/rpc/session-registry.ts +74 -5
- package/src/server/lib/omp/session/acp-rows.server.ts +79 -0
- package/src/server/lib/omp/session/delete-flow.server.ts +15 -8
- package/src/server/lib/omp/session/delete.server.ts +12 -0
- package/src/server/lib/omp/session/sidebar-data.harness.test.ts +247 -0
- package/src/server/lib/omp/session/sidebar-data.server.ts +56 -3
- package/src/server/lib/queue/delivery.server.test.ts +4 -2
- package/src/server/lib/queue/payload.test.ts +67 -0
- package/src/server/lib/queue/payload.ts +9 -3
- package/src/server/lib/realtime/signals.server.test.ts +99 -0
- package/src/server/lib/realtime/signals.server.ts +25 -5
- package/src/server/lib/realtime/topics/session-data.server.ts +29 -0
- package/src/server/lib/realtime/topics/session.server.ts +3 -3
- package/src/server/routes/agent/command-resume.test.ts +77 -0
- package/src/server/routes/agent/command.test.ts +243 -2
- package/src/server/routes/agent/command.ts +78 -15
- package/src/server/routes/agent/harness-command.ts +133 -0
- package/src/server/routes/agent/new.ts +63 -1
- 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 +240 -0
- package/src/server/routes/chat/session.ts +96 -4
- package/src/server/routes/harness/add-provider.test.ts +233 -0
- package/src/server/routes/harness/import-action.ts +272 -0
- package/src/server/routes/harness/import.test.ts +196 -0
- package/src/server/routes/harness/index.ts +13 -0
- package/src/server/routes/harness/root.ts +280 -0
- package/src/server/routes/harness/toggle.test.ts +127 -0
- package/src/server/routes/harness/update.ts +259 -0
- package/src/server/routes/harness/versions.test.ts +148 -0
- package/src/server/routes/harness/versions.ts +105 -0
- package/src/server/routes/index.ts +2 -0
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/queue.ts +7 -2
- package/src/server/routes/sessions/routes-queue.test.ts +52 -0
- package/src/server/routes/sessions/routes.test.ts +47 -13
- package/src/server/routes/sessions/session.ts +35 -0
- package/src/server/routes/settings/commands-harness.test.ts +92 -0
- package/src/server/routes/settings/commands.ts +26 -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/settings/skills.ts +12 -0
- 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 +20 -8
- package/src/shared/lib/chat/context/usage.test.ts +8 -4
- package/src/shared/lib/chat/context/usage.ts +17 -3
- package/src/shared/lib/chat/omp/abort.test.ts +61 -0
- package/src/shared/lib/chat/omp/abort.ts +8 -2
- package/src/shared/lib/chat/omp/tool-frames.test.ts +23 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +12 -2
- 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 +18 -8
- package/src/shared/lib/chat/tool/wait-facts.ts +14 -8
- package/src/shared/lib/harness/brand-color.test.ts +66 -0
- package/src/shared/lib/harness/brand-color.ts +96 -0
- package/src/shared/lib/harness/catalog.test.ts +88 -0
- package/src/shared/lib/harness/catalog.ts +169 -0
- package/src/shared/lib/harness/config-fields.test.ts +139 -0
- package/src/shared/lib/harness/config-fields.ts +168 -0
- package/src/shared/lib/harness/config.test.ts +153 -0
- package/src/shared/lib/harness/config.ts +206 -0
- package/src/shared/lib/harness/dialects.test.ts +140 -0
- package/src/shared/lib/harness/dialects.ts +249 -0
- package/src/shared/lib/harness/enabled.test.ts +79 -0
- package/src/shared/lib/harness/enabled.ts +72 -0
- package/src/shared/lib/harness/menu.test.ts +94 -0
- package/src/shared/lib/harness/menu.ts +88 -0
- package/src/shared/lib/harness/provider-facts.test.ts +199 -0
- package/src/shared/lib/harness/provider-facts.ts +349 -0
- package/src/shared/lib/harness/provider-slug.ts +46 -0
- package/src/shared/lib/harness/providers.ts +175 -0
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/status.test.ts +158 -0
- package/src/shared/lib/harness/status.ts +112 -0
- package/src/shared/lib/harness/update-plan.test.ts +163 -0
- package/src/shared/lib/harness/update-plan.ts +140 -0
- package/src/shared/lib/harness/updates.test.ts +106 -0
- package/src/shared/lib/harness/updates.ts +177 -0
- package/src/shared/lib/icons/icon-paint-authority.test.ts +16 -4
- package/src/shared/lib/icons/icon-paint-authority.ts +57 -12
- package/src/shared/lib/icons/icon-paint-bucket.test.ts +84 -0
- package/src/shared/lib/icons/icon-paint-css.test.ts +23 -25
- package/src/shared/lib/icons/icon-paint-css.ts +69 -55
- package/src/shared/lib/icons/icon-paint-harness.test.ts +73 -0
- package/src/shared/lib/icons/icon-paint-harness.ts +75 -0
- package/src/shared/lib/icons/icon-paint-ink.ts +108 -0
- package/src/shared/lib/icons/icon-paint-panel.ts +19 -4
- package/src/shared/lib/icons/icon-paint-weight.ts +21 -2
- package/src/shared/lib/icons/icon-tone.ts +118 -21
- package/src/shared/lib/icons/tint-hues.generated.ts +100 -284
- package/src/shared/lib/icons/tint-tones.test.ts +79 -25
- package/src/shared/lib/icons/tint.ts +66 -6
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/models/provider/vendors.ts +72 -0
- package/src/shared/lib/omp/config/schema.test.ts +36 -0
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/omp/session/messages-map-trace.test.ts +42 -0
- package/src/shared/lib/omp/session/messages-map.ts +6 -1
- package/src/shared/lib/omp/session/parse-message-blocks-toolcall.test.ts +8 -0
- package/src/shared/lib/omp/session/parse-message-blocks.ts +6 -1
- package/src/shared/lib/omp/session/shell-trace.test.ts +69 -0
- package/src/shared/lib/omp/session/shell-trace.ts +63 -0
- package/src/shared/lib/omp/session/sidebar.ts +37 -10
- package/src/shared/lib/omp/session/wait-idle.test.ts +47 -0
- package/src/shared/lib/omp/session/wait-idle.ts +93 -0
- package/src/shared/lib/omp/session/wait.test.ts +34 -33
- package/src/shared/lib/omp/session/wait.ts +25 -39
- package/src/shared/lib/settings/sections.ts +24 -0
- 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 +25 -9
- 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/ui/toast-duration.test.ts +74 -0
- package/src/shared/lib/ui/toast-duration.ts +70 -0
- package/src/shared/types/harness-version.ts +59 -0
- package/src/shared/types/harness.ts +201 -0
- package/src/shared/types/index.ts +2 -0
- package/src/shared/types/omp/agent.ts +13 -0
- package/src/shared/types/settings/state.ts +10 -1
- package/src/shared/types/workspace.ts +10 -0
- package/src/test-support/env.ts +38 -0
- 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 +108 -0
- package/dist/client/static/js/index-7ppta1pb.css +0 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* "Add provider" on a harness card — the typed twin of an import.
|
|
8
|
+
*
|
|
9
|
+
* Three rules make it honest, and each replaced a way the feature could lie:
|
|
10
|
+
*
|
|
11
|
+
* - **The id under the field is the key that lands.** The form previews with the
|
|
12
|
+
* same function the route validates with (`providerSlugFrom`), so a name is
|
|
13
|
+
* never silently rewritten into a timestamped id.
|
|
14
|
+
* - **The protocol is measured, not chosen.** A dropdown would offer an opinion;
|
|
15
|
+
* the probe has evidence, and the measured case proves it matters — `kenari`
|
|
16
|
+
* declares Chat Completions and works in Claude Code through Anthropic
|
|
17
|
+
* Messages.
|
|
18
|
+
* - **A successful add is VISIBLE.** The card lists the agent's own registry
|
|
19
|
+
* rows, so "added" and "wrote nothing" cannot render the same.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
23
|
+
import fs from 'node:fs';
|
|
24
|
+
import os from 'node:os';
|
|
25
|
+
import path from 'node:path';
|
|
26
|
+
|
|
27
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
28
|
+
import { restoreEnv } from '@/test-support/env';
|
|
29
|
+
import { action, loader } from '@/server/routes/harness/root';
|
|
30
|
+
import { providerIdProblem, providerSlugFrom } from '@/shared/lib/harness/provider-slug';
|
|
31
|
+
import { isVendorProviderId } from '@/shared/lib/models/provider/vendors';
|
|
32
|
+
|
|
33
|
+
const ROOT = path.join(os.tmpdir(), 'kabmo-harness-add');
|
|
34
|
+
const API = 'http://localhost/api/harness';
|
|
35
|
+
|
|
36
|
+
type Handler = (args: never) => unknown;
|
|
37
|
+
|
|
38
|
+
function call(handler: Handler, request: Request): Promise<Response> {
|
|
39
|
+
return handler({ request, params: {} } as never) as Promise<Response>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function post(body: unknown): Request {
|
|
43
|
+
return new Request(API, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
body: JSON.stringify(body),
|
|
46
|
+
headers: { 'content-type': 'application/json' },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const savedHome = Bun.env.HOME;
|
|
51
|
+
let stub: { port?: number; stop(force?: boolean): void } | null = null;
|
|
52
|
+
let baseUrl = '';
|
|
53
|
+
|
|
54
|
+
beforeAll(() => {
|
|
55
|
+
fs.mkdirSync(path.join(ROOT, '.omp/agent'), { recursive: true });
|
|
56
|
+
Bun.env.HOME = ROOT;
|
|
57
|
+
Bun.env.KABMO_TEST_HOME = ROOT;
|
|
58
|
+
fs.writeFileSync(path.join(ROOT, '.omp/agent/models.yml'), 'providers: {}\n');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
beforeEach(async () => {
|
|
62
|
+
await isolateDb();
|
|
63
|
+
// A host shaped like the measured one: Anthropic Messages and OpenAI Chat
|
|
64
|
+
// answer a malformed body; the Responses route and the Gemini listing do not.
|
|
65
|
+
stub = Bun.serve({
|
|
66
|
+
port: 0,
|
|
67
|
+
fetch(request) {
|
|
68
|
+
const { pathname } = new URL(request.url);
|
|
69
|
+
if (pathname === '/v1/messages') {
|
|
70
|
+
return Response.json({ error: { message: 'invalid Anthropic request JSON: missing field `model`' } }, { status: 400 });
|
|
71
|
+
}
|
|
72
|
+
if (pathname === '/v1/chat/completions') {
|
|
73
|
+
return Response.json({ error: { message: 'invalid JSON: missing field `model`' } }, { status: 400 });
|
|
74
|
+
}
|
|
75
|
+
return new Response('<!DOCTYPE html><html></html>', { status: 404, headers: { 'content-type': 'text/html' } });
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
baseUrl = `http://127.0.0.1:${stub.port ?? 0}/v1`;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
afterEach(async () => {
|
|
82
|
+
stub?.stop(true);
|
|
83
|
+
stub = null;
|
|
84
|
+
await releaseDb();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
afterAll(() => {
|
|
88
|
+
restoreEnv('HOME', savedHome);
|
|
89
|
+
delete Bun.env.KABMO_TEST_HOME;
|
|
90
|
+
fs.rmSync(ROOT, { recursive: true, force: true });
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('the id rule the form and the route share', () => {
|
|
94
|
+
test('a display name becomes the key that lands', () => {
|
|
95
|
+
expect(providerSlugFrom('My Gateway (EU)')).toBe('my-gateway-eu');
|
|
96
|
+
expect(providerSlugFrom(' Kenari.id ')).toBe('kenari-id');
|
|
97
|
+
expect(providerSlugFrom('Tooker')).toBe('tooker');
|
|
98
|
+
expect(providerSlugFrom('!!!')).toBe('');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('an id no registry accepts is refused with the shape it needs', () => {
|
|
102
|
+
expect(providerIdProblem('')).toContain('name');
|
|
103
|
+
expect(providerIdProblem('-leading-dash')).toContain('letter or digit');
|
|
104
|
+
expect(providerIdProblem('ok-with:colon')).toBeNull();
|
|
105
|
+
expect(providerIdProblem('ok.with.dot')).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('adding a provider to a registry harness', () => {
|
|
110
|
+
test('the probe picks the protocol the host answers, and the entry is written', async () => {
|
|
111
|
+
const response = await call(action, post({
|
|
112
|
+
probe: 'omp-acp',
|
|
113
|
+
addProvider: { name: 'Stub Gateway', baseUrl, apiKey: 'sk-add-test' },
|
|
114
|
+
}));
|
|
115
|
+
const payload = await response.json() as { error?: string; protocol?: string; imported?: { id: string; dialect: string } };
|
|
116
|
+
expect(payload.error).toBeUndefined();
|
|
117
|
+
// The host answers Chat and Anthropic; omp's registry speaks both, and the
|
|
118
|
+
// probe's first match wins — so the landing protocol is one the HOST proved.
|
|
119
|
+
expect(['openai-chat', 'anthropic-messages']).toContain(payload.protocol ?? '');
|
|
120
|
+
expect(payload.imported?.id).toBe('stub-gateway');
|
|
121
|
+
|
|
122
|
+
const text = fs.readFileSync(path.join(ROOT, '.omp/agent/models.yml'), 'utf8');
|
|
123
|
+
expect(text).toContain('stub-gateway:');
|
|
124
|
+
expect(text).toContain(`baseUrl: ${baseUrl}`);
|
|
125
|
+
expect(text).toContain('apiKey: sk-add-test');
|
|
126
|
+
// The display name survives the write — the card would otherwise print the
|
|
127
|
+
// slug back and look like the form ignored what was typed.
|
|
128
|
+
expect(text).toContain('name: Stub Gateway');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('the ADDRESSED harness gets it, not omp', async () => {
|
|
132
|
+
await call(action, post({
|
|
133
|
+
probe: 'pi',
|
|
134
|
+
addProvider: { name: 'Pi Gateway', baseUrl, apiKey: 'sk-pi' },
|
|
135
|
+
}));
|
|
136
|
+
const piFile = path.join(ROOT, '.pi/agent/models.json');
|
|
137
|
+
expect(fs.existsSync(piFile)).toBe(true);
|
|
138
|
+
const doc = JSON.parse(fs.readFileSync(piFile, 'utf8'));
|
|
139
|
+
expect(doc.providers['pi-gateway'].baseUrl).toBe(baseUrl);
|
|
140
|
+
// And omp's file is untouched by that write.
|
|
141
|
+
expect(fs.readFileSync(path.join(ROOT, '.omp/agent/models.yml'), 'utf8')).not.toContain('pi-gateway');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('a name that derives a VENDOR id is refused, naming the entry', async () => {
|
|
145
|
+
// `Anthropic` would override the agent's own built-in provider.
|
|
146
|
+
const response = await call(action, post({
|
|
147
|
+
probe: 'omp-acp',
|
|
148
|
+
addProvider: { name: 'Anthropic', baseUrl, apiKey: 'sk-x' },
|
|
149
|
+
}));
|
|
150
|
+
const payload = await response.json() as { error?: string };
|
|
151
|
+
expect(response.status).toBe(400);
|
|
152
|
+
expect(payload.error ?? '').toContain('ships itself');
|
|
153
|
+
expect(isVendorProviderId('anthropic')).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('a protocol the target cannot speak is refused BY NAME', async () => {
|
|
157
|
+
// codex is Responses-only, and the stub does not answer `/v1/responses`.
|
|
158
|
+
const response = await call(action, post({
|
|
159
|
+
probe: 'codex',
|
|
160
|
+
addProvider: { name: 'Chat Only', baseUrl, apiKey: 'sk-x' },
|
|
161
|
+
}));
|
|
162
|
+
const payload = await response.json() as { error?: string; code?: string; probe?: { protocols: string[] } };
|
|
163
|
+
expect(response.status).toBe(400);
|
|
164
|
+
expect(payload.code).toBe('no_shared_protocol');
|
|
165
|
+
expect(payload.error ?? '').toContain('codex');
|
|
166
|
+
// The evidence travels, so the reader can check the claim.
|
|
167
|
+
expect(payload.probe?.protocols).toContain('anthropic-messages');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('a provider with no models says so', () => {
|
|
172
|
+
test('the write reports that nothing will be served, rather than a bare success', async () => {
|
|
173
|
+
// Measured: omp serves zero rows from an entry with no models and no
|
|
174
|
+
// `discovery` block, and prints no warning at all.
|
|
175
|
+
const response = await call(action, post({
|
|
176
|
+
probe: 'omp-acp',
|
|
177
|
+
addProvider: { name: 'Empty Gateway', baseUrl, apiKey: 'sk-empty' },
|
|
178
|
+
}));
|
|
179
|
+
const notes = ((await response.json()) as { imported?: { notes: string[] } }).imported?.notes ?? [];
|
|
180
|
+
expect(notes.join(' ')).toContain('serves nothing');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('a provider WITH models gets no such note', async () => {
|
|
184
|
+
const response = await call(action, post({
|
|
185
|
+
probe: 'omp-acp',
|
|
186
|
+
addProvider: { name: 'Full Gateway', baseUrl, apiKey: 'sk-full', models: ['m-1'] },
|
|
187
|
+
}));
|
|
188
|
+
const notes = ((await response.json()) as { imported?: { notes: string[] } }).imported?.notes ?? [];
|
|
189
|
+
expect(notes.join(' ')).not.toContain('serves nothing');
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
describe('adding a provider to an environment harness', () => {
|
|
194
|
+
test('claude gets the vendor variables at the HOST ROOT, key and model included', async () => {
|
|
195
|
+
const response = await call(action, post({
|
|
196
|
+
probe: 'claude',
|
|
197
|
+
addProvider: { name: 'Stub Anthropic', baseUrl, apiKey: 'sk-claude', models: ['claude-sonnet-5'] },
|
|
198
|
+
}));
|
|
199
|
+
const payload = await response.json() as { config?: { env: string }; envWritten?: string[]; error?: string };
|
|
200
|
+
expect(payload.error).toBeUndefined();
|
|
201
|
+
expect(payload.envWritten).toEqual(['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_MODEL']);
|
|
202
|
+
// `/v1` stripped: the SDK appends `/v1/messages` itself.
|
|
203
|
+
expect(payload.config?.env).toContain(`ANTHROPIC_BASE_URL=${baseUrl.replace(/\/v1$/, '')}`);
|
|
204
|
+
expect(payload.config?.env).toContain('ANTHROPIC_AUTH_TOKEN=sk-claude');
|
|
205
|
+
expect(payload.config?.env).toContain('ANTHROPIC_MODEL=claude-sonnet-5');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('no name is refused before anything is written', async () => {
|
|
209
|
+
const response = await call(action, post({
|
|
210
|
+
probe: 'claude',
|
|
211
|
+
addProvider: { name: ' ', baseUrl, apiKey: 'sk-x' },
|
|
212
|
+
}));
|
|
213
|
+
expect(response.status).toBe(400);
|
|
214
|
+
expect((await response.json() as { error?: string }).error).toContain('name');
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('the card can SEE what it added', () => {
|
|
219
|
+
test('the loader lists the harness own custom providers', async () => {
|
|
220
|
+
await call(action, post({
|
|
221
|
+
probe: 'omp-acp',
|
|
222
|
+
addProvider: { name: 'Visible Gateway', baseUrl, apiKey: 'sk-visible' },
|
|
223
|
+
}));
|
|
224
|
+
const payload = await (await call(loader, new Request(API))).json() as {
|
|
225
|
+
providerSupport: Record<string, { configured: Array<{ id: string; hasKey: boolean }> }>;
|
|
226
|
+
};
|
|
227
|
+
const configured = payload.providerSupport['omp-acp']?.configured ?? [];
|
|
228
|
+
expect(configured.map((row) => row.id)).toContain('visible-gateway');
|
|
229
|
+
expect(configured.find((row) => row.id === 'visible-gateway')?.hasKey).toBe(true);
|
|
230
|
+
// The credential never travels with the row.
|
|
231
|
+
expect(JSON.stringify(configured)).not.toContain('sk-visible');
|
|
232
|
+
});
|
|
233
|
+
});
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Add a provider to ONE harness — the same landing path an import takes, with the
|
|
8
|
+
* endpoint and credential typed instead of copied.
|
|
9
|
+
*
|
|
10
|
+
* The split is deliberate: `import` answers "copy what another agent already
|
|
11
|
+
* has", `add` answers "here is a gateway I use". Everything AFTER that is the
|
|
12
|
+
* same problem, so it is one function (`applyProvider`):
|
|
13
|
+
*
|
|
14
|
+
* 1. **Measure the endpoint** (`probeEndpointProtocols`). A user knows their
|
|
15
|
+
* gateway and rarely knows which wire API it answers; the probe asks, with no
|
|
16
|
+
* credential, so it is safe before the key is validated.
|
|
17
|
+
* 2. **Pick a protocol this target speaks** — the measured one, else the one
|
|
18
|
+
* declared, else refuse BY NAME of both sides.
|
|
19
|
+
* 3. **Write** into the harness's own registry, or flatten into its env when it
|
|
20
|
+
* has none, and return what landed.
|
|
21
|
+
*
|
|
22
|
+
* Split from the route so the two actions read as sentences, and so the only
|
|
23
|
+
* module that touches a credential is this one.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { json } from '@/server/lib/remix-compat';
|
|
27
|
+
import { HARNESS_IDS, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
28
|
+
import { adaptBaseUrl, planProtocol, supportedProtocols, type CanonicalProtocol } from '@/shared/lib/harness/dialects';
|
|
29
|
+
import { providerFacts } from '@/shared/lib/harness/provider-facts';
|
|
30
|
+
import { providerEnv, providerLevel, registryLabel } from '@/shared/lib/harness/providers';
|
|
31
|
+
import { providerIdProblem, providerSlugFrom } from '@/shared/lib/harness/provider-slug';
|
|
32
|
+
import { withEnvValues } from '@/shared/lib/harness/config';
|
|
33
|
+
import { loadHarnessConfig, saveHarnessConfig } from '@/server/lib/harness/config.server';
|
|
34
|
+
import { forgetProbe } from '@/server/lib/harness/probe-cache.server';
|
|
35
|
+
import { probeEndpointProtocols, type EndpointProbe } from '@/server/lib/harness/provider-probe.server';
|
|
36
|
+
import { writeProvider, type ListedProvider, type ProviderDraft } from '@/server/lib/harness/provider-write.server';
|
|
37
|
+
import { readProviderKey, harnessesSharingRegistry } from '@/server/lib/harness/provider-sources.server';
|
|
38
|
+
import { refreshModelRegistryAfterWrite } from '@/server/lib/models/registry-refresh.server';
|
|
39
|
+
|
|
40
|
+
/** A provider about to be written, from any source. */
|
|
41
|
+
interface Candidate extends ListedProvider {
|
|
42
|
+
/** The credential, when the caller has it (an add). An import reads its own. */
|
|
43
|
+
apiKey?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The model a pin should name, from the source's own list.
|
|
48
|
+
*
|
|
49
|
+
* An `environment` harness has ONE model variable, so it needs one id — and the
|
|
50
|
+
* source's first is rarely the right one. Measured against kenari: the list
|
|
51
|
+
* starts with `agnes-2-5-flash:free`, for which Claude Code logged
|
|
52
|
+
* `unrecognized_model`, and with NO model pinned at all it answered an empty
|
|
53
|
+
* turn. A Sonnet id is Claude Code's own default family and was the one that
|
|
54
|
+
* completed a turn, so the newest Sonnet wins; then any `claude-*`; then first.
|
|
55
|
+
*/
|
|
56
|
+
function pinnedModel(protocol: CanonicalProtocol, models: readonly string[]): string | undefined {
|
|
57
|
+
if (models.length === 0) return undefined;
|
|
58
|
+
if (protocol !== 'anthropic-messages') return models[0];
|
|
59
|
+
const sonnets = models.filter((id) => /^claude[-.]sonnet/i.test(id));
|
|
60
|
+
if (sonnets.length > 0) return sonnets.reduce((best, id) => (versionOf(id) > versionOf(best) ? id : best));
|
|
61
|
+
return models.find((id) => /^claude[-.]/i.test(id)) ?? models[0];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** `claude-sonnet-5` → 5, `claude-sonnet-4-6` → 4.6; anything else → 0. */
|
|
65
|
+
function versionOf(id: string): number {
|
|
66
|
+
const match = /(\d+)(?:[-.](\d+))?/.exec(id.replace(/^claude[-.]sonnet[-.]?/i, ''));
|
|
67
|
+
if (!match) return 0;
|
|
68
|
+
return Number(match[1]) + Number(match[2] ?? 0) / 100;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The refusal for "no protocol both ends speak", naming what each side said.
|
|
73
|
+
*
|
|
74
|
+
* The endpoint's answer is included because it is the fact that makes the message
|
|
75
|
+
* actionable: "antigravity takes google-genai; this host answers openai-chat,
|
|
76
|
+
* anthropic-messages" tells the reader the provider is real and the agent is the
|
|
77
|
+
* constraint.
|
|
78
|
+
*/
|
|
79
|
+
function noSharedProtocol(
|
|
80
|
+
target: HarnessId,
|
|
81
|
+
id: string,
|
|
82
|
+
declared: CanonicalProtocol | undefined,
|
|
83
|
+
accepted: readonly CanonicalProtocol[],
|
|
84
|
+
probe: EndpointProbe | null,
|
|
85
|
+
sourceLabel: string,
|
|
86
|
+
) {
|
|
87
|
+
const answers = probe?.protocols.length ? ` and the endpoint answers ${probe.protocols.join(', ')}` : '';
|
|
88
|
+
return json({
|
|
89
|
+
error: `${target} has no protocol "${id}" can land on. ${sourceLabel} declares `
|
|
90
|
+
+ `${declared ?? 'no dialect'}${answers}; ${target} accepts ${accepted.join(', ') || 'no provider protocols'}.`,
|
|
91
|
+
code: 'no_shared_protocol',
|
|
92
|
+
probe,
|
|
93
|
+
}, { status: 400 });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Measure, choose, and write ONE provider into `target`.
|
|
98
|
+
*
|
|
99
|
+
* `sourceLabel` names where the provider came from ("models.yml (omp)" for an
|
|
100
|
+
* import, "this form" for an add) so a refusal points at the right thing.
|
|
101
|
+
*/
|
|
102
|
+
export async function applyProvider(target: HarnessId, candidate: Candidate, sourceLabel: string) {
|
|
103
|
+
const facts = providerFacts(target);
|
|
104
|
+
const accepted = supportedProtocols(facts.registry.kind, facts.envProtocol);
|
|
105
|
+
const level = providerLevel(target);
|
|
106
|
+
|
|
107
|
+
if (level !== 'full' && level !== 'environment') {
|
|
108
|
+
return json({
|
|
109
|
+
error: `${target} has no provider registry Kabmo can write — use its launch command and env`,
|
|
110
|
+
code: 'no_registry',
|
|
111
|
+
}, { status: 400 });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// MEASURE before writing. A probe sends no credential — it asks the HOST a
|
|
115
|
+
// question — so it is safe on a provider whose key is unset, and it is skipped
|
|
116
|
+
// when there is no endpoint to ask.
|
|
117
|
+
const probe = candidate.baseUrl ? await probeEndpointProtocols(candidate.baseUrl) : null;
|
|
118
|
+
const measured = accepted.find((protocol) => probe?.protocols.includes(protocol)) ?? null;
|
|
119
|
+
// A probe that REACHED the host is evidence: when it answers nothing this
|
|
120
|
+
// target speaks, the answer is no — falling back to "the target has only one
|
|
121
|
+
// protocol, so use it" would write a provider the endpoint never agreed to
|
|
122
|
+
// (measured: codex is Responses-only, a Chat-only gateway 404s `/v1/responses`).
|
|
123
|
+
// The fallback stays for the case that has no evidence at all: no endpoint, or
|
|
124
|
+
// a probe that could not be made.
|
|
125
|
+
const evidenceSaysNo = probe !== null && !probe.error && probe.findings.length > 0;
|
|
126
|
+
const planned = measured
|
|
127
|
+
?? (evidenceSaysNo ? null : planProtocol(candidate.protocol ?? null, accepted));
|
|
128
|
+
if (!planned) {
|
|
129
|
+
return noSharedProtocol(target, candidate.id, candidate.protocol, accepted, probe, sourceLabel);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const draft: ProviderDraft = {
|
|
133
|
+
id: candidate.id,
|
|
134
|
+
name: candidate.name,
|
|
135
|
+
...(candidate.baseUrl ? { baseUrl: candidate.baseUrl } : {}),
|
|
136
|
+
protocol: planned,
|
|
137
|
+
models: candidate.models,
|
|
138
|
+
...(candidate.contextWindow ? { contextWindow: candidate.contextWindow } : {}),
|
|
139
|
+
...(candidate.apiKey ? { apiKey: candidate.apiKey } : {}),
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
if (level === 'full') {
|
|
143
|
+
try {
|
|
144
|
+
const written = await writeProvider(target, draft);
|
|
145
|
+
// A variable-name format (codex's `env_key`) stores ONLY the name, so the
|
|
146
|
+
// value is saved into the harness env — where the spawn reads it.
|
|
147
|
+
let config = null;
|
|
148
|
+
if (Object.keys(written.env).length > 0) {
|
|
149
|
+
config = withEnvValues(await loadHarnessConfig(target), written.env);
|
|
150
|
+
await saveHarnessConfig(target, config);
|
|
151
|
+
}
|
|
152
|
+
// WHICH harnesses read this file, not just the one the card named:
|
|
153
|
+
// omp-rpc and omp-acp are two transports over one models.yml, so an add
|
|
154
|
+
// made on either tab has to invalidate both pickers.
|
|
155
|
+
const sharing = harnessesSharingRegistry(written.path);
|
|
156
|
+
const invalidated = sharing.length > 0 ? sharing : [target];
|
|
157
|
+
if (sharing.includes('omp-rpc') || sharing.includes('omp-acp')) {
|
|
158
|
+
// The omp registry is read by the pooled RPC child AND by every ACP
|
|
159
|
+
// probe. Recycle the child and drop the stale probe records here; the
|
|
160
|
+
// browser re-probes the tabs it reads (the response names them).
|
|
161
|
+
await refreshModelRegistryAfterWrite({ path: written.path, probes: true, reprobe: false });
|
|
162
|
+
} else {
|
|
163
|
+
for (const id of invalidated) await forgetProbe(id);
|
|
164
|
+
}
|
|
165
|
+
return json({
|
|
166
|
+
imported: written,
|
|
167
|
+
harness: target,
|
|
168
|
+
target: registryLabel(target),
|
|
169
|
+
protocol: planned,
|
|
170
|
+
probe,
|
|
171
|
+
probeInvalidated: invalidated,
|
|
172
|
+
...(config ? { config } : {}),
|
|
173
|
+
});
|
|
174
|
+
} catch (cause) {
|
|
175
|
+
const message = cause instanceof Error ? cause.message : 'Could not write the registry';
|
|
176
|
+
return json({ error: message, probe }, { status: 400 });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// environment: the same fields FLATTENED into the vars that agent reads. There
|
|
181
|
+
// is no registry, so this REPLACES its endpoint. The base URL is the HOST ROOT
|
|
182
|
+
// — measured, Claude Code appends `/v1/messages` itself and answered an empty
|
|
183
|
+
// turn against `https://kenari.id/v1`.
|
|
184
|
+
const env = providerEnv(target, {
|
|
185
|
+
baseUrl: adaptBaseUrl(draft.baseUrl ?? '', 'root'),
|
|
186
|
+
apiKey: draft.apiKey ?? '',
|
|
187
|
+
...(pinnedModel(planned, draft.models) ? { model: pinnedModel(planned, draft.models)! } : {}),
|
|
188
|
+
});
|
|
189
|
+
if (Object.keys(env).length === 0) {
|
|
190
|
+
return json({ error: `Nothing to write: "${candidate.id}" has no endpoint or key.` }, { status: 400 });
|
|
191
|
+
}
|
|
192
|
+
const saved = withEnvValues(await loadHarnessConfig(target), env);
|
|
193
|
+
await saveHarnessConfig(target, saved);
|
|
194
|
+
await forgetProbe(target);
|
|
195
|
+
return json({
|
|
196
|
+
config: saved,
|
|
197
|
+
harness: target,
|
|
198
|
+
envWritten: Object.keys(env),
|
|
199
|
+
protocol: planned,
|
|
200
|
+
probe,
|
|
201
|
+
provider: candidate.id,
|
|
202
|
+
probeInvalidated: [target],
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The request's own fields, narrowed once because every one of them is untrusted. */
|
|
207
|
+
function stringList(value: unknown): string[] {
|
|
208
|
+
return Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : [];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* `{ addProvider: { name, baseUrl, apiKey, protocol?, models? } }`.
|
|
213
|
+
*
|
|
214
|
+
* The id is DERIVED from the name with the same function the form previews with
|
|
215
|
+
* (`providerSlugFrom`), so what the reader sees under the field is exactly the
|
|
216
|
+
* key that lands in the file. An explicit `id` is honoured when it passes the
|
|
217
|
+
* shared pattern — a provider the user already names in their own registry
|
|
218
|
+
* should not be renamed by a slug rule.
|
|
219
|
+
*/
|
|
220
|
+
export async function addProviderAction(target: HarnessId, body: unknown) {
|
|
221
|
+
const request = body && typeof body === 'object' ? (body as Record<string, unknown>) : {};
|
|
222
|
+
const name = typeof request.name === 'string' ? request.name.trim() : '';
|
|
223
|
+
const explicitId = typeof request.id === 'string' ? request.id.trim().toLowerCase() : '';
|
|
224
|
+
const id = explicitId || providerSlugFrom(name);
|
|
225
|
+
const problem = providerIdProblem(id);
|
|
226
|
+
if (problem) return json({ error: problem }, { status: 400 });
|
|
227
|
+
if (!name) return json({ error: 'A provider needs a name.' }, { status: 400 });
|
|
228
|
+
|
|
229
|
+
const baseUrl = typeof request.baseUrl === 'string' ? request.baseUrl.trim() : '';
|
|
230
|
+
const apiKey = typeof request.apiKey === 'string' ? request.apiKey.trim() : '';
|
|
231
|
+
const protocol = typeof request.protocol === 'string' ? (request.protocol as CanonicalProtocol) : undefined;
|
|
232
|
+
const models = stringList(request.models).map((entry) => entry.trim()).filter(Boolean);
|
|
233
|
+
|
|
234
|
+
// An env harness has no file to hold an endpoint, and no models of its own:
|
|
235
|
+
// the probe picks the protocol, and `pinnedModel` names the one model variable.
|
|
236
|
+
return applyProvider(target, { id, name, baseUrl, apiKey, models, ...(protocol ? { protocol } : {}) }, 'this form');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Handle one import request. `source` and `id` are already validated. */
|
|
240
|
+
export async function importProviderAction(
|
|
241
|
+
target: HarnessId,
|
|
242
|
+
source: HarnessId,
|
|
243
|
+
sourceId: string,
|
|
244
|
+
entry: unknown,
|
|
245
|
+
) {
|
|
246
|
+
const record = entry && typeof entry === 'object' ? (entry as Record<string, unknown>) : {};
|
|
247
|
+
const windows = record.contextWindow;
|
|
248
|
+
const listed: Candidate = {
|
|
249
|
+
id: sourceId,
|
|
250
|
+
name: typeof record.name === 'string' ? record.name : sourceId,
|
|
251
|
+
...(typeof record.baseUrl === 'string' ? { baseUrl: record.baseUrl } : {}),
|
|
252
|
+
...(typeof record.protocol === 'string' ? { protocol: record.protocol as CanonicalProtocol } : {}),
|
|
253
|
+
models: stringList(record.models),
|
|
254
|
+
...(windows && typeof windows === 'object' ? { contextWindow: windows as Record<string, number> } : {}),
|
|
255
|
+
};
|
|
256
|
+
// The KEY is read HERE, from the source file, in the request that writes: the
|
|
257
|
+
// list the browser holds carries a boolean `hasKey`, never the value.
|
|
258
|
+
const key = await readProviderKey(source, sourceId);
|
|
259
|
+
return applyProvider(target, { ...listed, ...(key ? { apiKey: key } : {}) }, registryLabel(source));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** True when the body carries an import request this module should answer. */
|
|
263
|
+
export function isImportBody(value: unknown): boolean {
|
|
264
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** A source id the import may read from. Refuses before any file is touched. */
|
|
268
|
+
export function importSourceOf(value: unknown): HarnessId | null {
|
|
269
|
+
return typeof value === 'string' && HARNESS_IDS.includes(value as HarnessId)
|
|
270
|
+
? (value as HarnessId)
|
|
271
|
+
: null;
|
|
272
|
+
}
|