@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,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Write a provider into a harness's OWN registry, in that harness's own format.
|
|
8
|
+
*
|
|
9
|
+
* One writer per FORMAT, dispatched by `HARNESS_PROVIDER_FACTS`. Every format
|
|
10
|
+
* merges rather than rewrites — these files also hold plugins, agents, MCP
|
|
11
|
+
* servers and approval policy — refuses an unparseable file untouched, keeps a
|
|
12
|
+
* stored credential and the user's own dialect on update, and writes 0600
|
|
13
|
+
* because the file can hold a key.
|
|
14
|
+
*
|
|
15
|
+
* Two rules decide whether an import is HONEST, and both live here because this
|
|
16
|
+
* is the only place that touches disk:
|
|
17
|
+
*
|
|
18
|
+
* - **A vendor id is never written.** `anthropic` copied into codex would
|
|
19
|
+
* override codex's own built-in provider instead of adding a gateway; the
|
|
20
|
+
* import list filters those rows out (`vendors.ts`) and the writer refuses
|
|
21
|
+
* one that arrives anyway.
|
|
22
|
+
* - **A format that stores a VARIABLE NAME gets the value elsewhere.** codex's
|
|
23
|
+
* `env_key` and qwen's `envKey` name an env var; writing the name and no
|
|
24
|
+
* value leaves every request unauthenticated. The write answers with the env
|
|
25
|
+
* lines the caller must save into the harness config, so the credential lands
|
|
26
|
+
* where the agent actually reads it.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { writeFileAtomic } from '@/server/lib/fs/atomic-write';
|
|
30
|
+
import { parseDocument, providerMap, serialise } from '@/server/lib/harness/provider-file.server';
|
|
31
|
+
import { withConfigLock } from '@/server/lib/fs/config-lock';
|
|
32
|
+
import { providerFacts, type ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
|
|
33
|
+
import {
|
|
34
|
+
adaptBaseUrl,
|
|
35
|
+
dialectFor,
|
|
36
|
+
planProtocol,
|
|
37
|
+
supportedProtocols,
|
|
38
|
+
type CanonicalProtocol,
|
|
39
|
+
} from '@/shared/lib/harness/dialects';
|
|
40
|
+
import { isVendorProviderId } from '@/shared/lib/models/provider/vendors';
|
|
41
|
+
import { registryFilePath, readProviderKey, readRegistryProviders } from '@/server/lib/harness/provider-sources.server';
|
|
42
|
+
import { asRecord, modelRowsFor, pickExisting, providerEntryFor, type ProviderDraft } from '@/server/lib/harness/provider-entry';
|
|
43
|
+
import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
|
|
44
|
+
import { writeZcodeProvider } from '@/server/lib/harness/provider-zcode.server';
|
|
45
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
46
|
+
|
|
47
|
+
/** What a successful write changed, so the card can report it rather than guess. */
|
|
48
|
+
export interface ProviderWriteResult {
|
|
49
|
+
id: string;
|
|
50
|
+
replaced: boolean;
|
|
51
|
+
path: string;
|
|
52
|
+
/** The protocol that landed, at the target's own spelling. */
|
|
53
|
+
dialect: string;
|
|
54
|
+
/** Env lines the caller must save for a variable-name format (`KEY=VALUE`). */
|
|
55
|
+
env: Record<string, string>;
|
|
56
|
+
/** Facts the UI repeats verbatim — a restart, an injected variable name. */
|
|
57
|
+
notes: string[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A provider id each format accepts as a key.
|
|
62
|
+
*
|
|
63
|
+
* `.` and `:` are legal in kimi's provider names (`managed:kimi-code`) and in
|
|
64
|
+
* opencode's model ids, so the pattern is the INTERSECTION that every format
|
|
65
|
+
* accepts rather than the strictest one — an id the source already holds must
|
|
66
|
+
* not be refused by a target that could spell it.
|
|
67
|
+
*/
|
|
68
|
+
const ID_PATTERN = /^[a-z0-9][a-z0-9._:-]{0,63}$/;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Under `bun test`, a write is confined to a temp `HOME`.
|
|
72
|
+
*
|
|
73
|
+
* This is not defensive styling. A verification run of this very feature wrote
|
|
74
|
+
* into the developer's real `~/.codex/config.toml`, `~/.pi/agent/models.json`,
|
|
75
|
+
* `~/.kimi/config.toml`, `~/.qwen/settings.json` and `~/.omp/agent/models.yml`,
|
|
76
|
+
* because a test process with `HOME` reassigned was fine while a REAL server
|
|
77
|
+
* (started for a browser check) was not. A registry is an agent's working config:
|
|
78
|
+
* a test that reaches the real one breaks an install, so the check lives at the
|
|
79
|
+
* ONE place that writes.
|
|
80
|
+
*
|
|
81
|
+
* `KABMO_TEST_HOME` is the escape hatch: a suite that WANTS a real path in a temp
|
|
82
|
+
* root sets it, and the guard allows a path under it.
|
|
83
|
+
*/
|
|
84
|
+
function assertWritableUnderTest(path: string): void {
|
|
85
|
+
if (!Bun.env.KABMO_TEST_HOME) return;
|
|
86
|
+
const allowed = Bun.env.KABMO_TEST_HOME;
|
|
87
|
+
if (!path.startsWith(allowed)) {
|
|
88
|
+
throw new ProviderWriteError(
|
|
89
|
+
`refusing to write ${path}: under test, writes are limited to ${allowed}`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The protocol a draft should land as, and the base URL that fits the target.
|
|
96
|
+
*
|
|
97
|
+
* `protocol` on the draft is authoritative when the target speaks it (a probe
|
|
98
|
+
* measured it against the live endpoint). Otherwise the source's own protocol is
|
|
99
|
+
* kept — the API is the source's, the file is the target's.
|
|
100
|
+
*/
|
|
101
|
+
function planFor(target: HarnessId, draft: ProviderDraft): { protocol: CanonicalProtocol; baseUrl: string } {
|
|
102
|
+
const facts = providerFacts(target);
|
|
103
|
+
const target_protocols = supportedProtocols(facts.registry.kind, facts.envProtocol);
|
|
104
|
+
const protocol = planProtocol(draft.protocol ?? null, target_protocols);
|
|
105
|
+
if (!protocol) {
|
|
106
|
+
throw new ProviderWriteError(
|
|
107
|
+
`${target} has no protocol that matches "${draft.id}" (${draft.protocol ?? 'unknown dialect'}). `
|
|
108
|
+
+ `It accepts: ${target_protocols.join(', ') || 'none'}.`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (dialectFor(facts.registry.kind, protocol) === null) {
|
|
112
|
+
throw new ProviderWriteError(
|
|
113
|
+
`${target} cannot speak ${protocol}: it stores no such dialect.`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
// An env target is a vendor SDK, which appends the version itself: measured,
|
|
117
|
+
// Claude Code with `.../v1` requested `/v1/v1/messages` and answered an empty
|
|
118
|
+
// turn. A registry target appends only the route, so its base keeps `/v1`.
|
|
119
|
+
const baseUrl = adaptBaseUrl(draft.baseUrl ?? '', facts.registry.kind === 'env' ? 'root' : 'api-base');
|
|
120
|
+
return { protocol, baseUrl };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The variable NAME a variable-name format stores, and the env line it needs.
|
|
125
|
+
*
|
|
126
|
+
* Derived from the provider id rather than a fixed `OPENAI_API_KEY`: measured,
|
|
127
|
+
* two providers added to qwen both wrote that one name, so adding the second
|
|
128
|
+
* silently re-pointed the first at a different key. `KENARI_ID_API_KEY` is
|
|
129
|
+
* unique per provider by construction, and the env block carries its value.
|
|
130
|
+
*/
|
|
131
|
+
function credentialEnvFor(kind: ProviderRegistryKind, draft: ProviderDraft): Record<string, string> {
|
|
132
|
+
if (!draft.apiKey) return {};
|
|
133
|
+
if (kind !== 'toml-model-providers' && kind !== 'json-model-providers') return {};
|
|
134
|
+
const name = `${draft.id.toUpperCase().replace(/[^A-Z0-9]+/g, '_')}_API_KEY`;
|
|
135
|
+
return { [name]: draft.apiKey };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Merge ONE provider into a harness's registry.
|
|
140
|
+
*
|
|
141
|
+
* Returns what changed — the id, whether it replaced an entry, the dialect that
|
|
142
|
+
* landed, the env lines a variable-name format needs, and the notes the card must
|
|
143
|
+
* repeat — so the UI reports facts instead of a bare success.
|
|
144
|
+
*/
|
|
145
|
+
export async function writeProvider(
|
|
146
|
+
target: HarnessId,
|
|
147
|
+
draft: ProviderDraft,
|
|
148
|
+
): Promise<ProviderWriteResult> {
|
|
149
|
+
const facts = providerFacts(target);
|
|
150
|
+
// The ORDER matters for the message: an agent-managed registry (minimax) has
|
|
151
|
+
// no path Kabmo owns, and telling that reader "no registry Kabmo writes" hides
|
|
152
|
+
// the true situation — a registry exists, `mcode` owns it.
|
|
153
|
+
if (!facts.registry.writable) {
|
|
154
|
+
throw new ProviderWriteError(
|
|
155
|
+
facts.registry.kind === 'agent-managed'
|
|
156
|
+
? `${target} keeps its providers itself; add one with its own command`
|
|
157
|
+
: `${target} has no provider registry Kabmo writes`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
const path = registryFilePath(target);
|
|
161
|
+
if (!path) throw new ProviderWriteError(`${target} has no provider registry Kabmo writes`);
|
|
162
|
+
assertWritableUnderTest(path);
|
|
163
|
+
|
|
164
|
+
const id = draft.id.trim().toLowerCase();
|
|
165
|
+
if (!ID_PATTERN.test(id)) {
|
|
166
|
+
throw new ProviderWriteError(`"${id}" is not a provider id ${target} accepts (lowercase, digits, . _ : -)`);
|
|
167
|
+
}
|
|
168
|
+
const kind = facts.registry.kind;
|
|
169
|
+
// ZCode keys personal rules by the USER's id; its runtime ids are the
|
|
170
|
+
// `builtin:`/`account:` prefixes, and ids like `local` are its own documented
|
|
171
|
+
// example of a custom provider. The shared census is about the other agents,
|
|
172
|
+
// so it must not refuse a legitimate ZCode gateway.
|
|
173
|
+
if (kind !== 'zcode-provider-rules' && isVendorProviderId(id, facts.registry.bundledIds)) {
|
|
174
|
+
throw new ProviderWriteError(
|
|
175
|
+
`"${id}" is a provider ${target} ships itself, so writing it would override the vendor's entry instead of `
|
|
176
|
+
+ 'adding a gateway. Only providers you registered yourself can be imported.',
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const plan = planFor(target, draft);
|
|
181
|
+
const planned: ProviderDraft = { ...draft, protocol: plan.protocol, baseUrl: plan.baseUrl };
|
|
182
|
+
const dialect = dialectFor(kind, plan.protocol) ?? '';
|
|
183
|
+
|
|
184
|
+
// ZCode's personal-provider file is a RULE GRAPH (one provider rule plus one
|
|
185
|
+
// model rule per id), not a providers map. Its writer owns that read-modify-
|
|
186
|
+
// write; this module still owns the format/protocol decisions above.
|
|
187
|
+
if (kind === 'zcode-provider-rules') {
|
|
188
|
+
if (id.startsWith('builtin:') || id.startsWith('account:')) {
|
|
189
|
+
throw new ProviderWriteError(
|
|
190
|
+
`"${id}" is a provider the ZCode runtime owns; a personal rule cannot replace a built-in or account plan.`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return writeZcodeProvider({ path, id, draft: planned, dialect });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const env = credentialEnvFor(kind, planned);
|
|
197
|
+
const notes: string[] = [];
|
|
198
|
+
|
|
199
|
+
return withConfigLock(path, async () => {
|
|
200
|
+
const file = Bun.file(path);
|
|
201
|
+
const raw = (await file.exists()) ? await file.text() : '';
|
|
202
|
+
const doc = raw.trim() ? parseDocument(kind, raw, path) : {};
|
|
203
|
+
|
|
204
|
+
if (kind === 'json-model-providers') {
|
|
205
|
+
// Array-per-protocol: the protocol key is the BUCKET, and every row is a
|
|
206
|
+
// model. The bucket comes from the planned protocol, not from the provider
|
|
207
|
+
// id: a provider called `gateway` used to land in an `openai` bucket by
|
|
208
|
+
// accident of the id, which routed an Anthropic endpoint through the
|
|
209
|
+
// OpenAI SDK.
|
|
210
|
+
const groups = providerMap(doc, facts.registry.pointer, path);
|
|
211
|
+
const bucket = dialect;
|
|
212
|
+
const list = Array.isArray(groups[bucket]) ? (groups[bucket] as unknown[]) : [];
|
|
213
|
+
// A provider is a SET of model rows here, and qwen identifies a row by
|
|
214
|
+
// protocol + id + baseUrl (its own docs). Finding a row by id alone made
|
|
215
|
+
// two gateways serving one model id collapse into one, so the second add
|
|
216
|
+
// silently replaced the first.
|
|
217
|
+
const baseUrl = planned.baseUrl;
|
|
218
|
+
let replaced = false;
|
|
219
|
+
for (const modelId of planned.models.length > 0 ? planned.models : [planned.id]) {
|
|
220
|
+
const incoming = providerEntryFor(kind, { ...planned, models: [modelId] }, target);
|
|
221
|
+
const index = list.findIndex((entry) => {
|
|
222
|
+
const row = asRecord(entry);
|
|
223
|
+
return row.id === incoming.id && (row.baseUrl ?? '') === (baseUrl ?? '');
|
|
224
|
+
});
|
|
225
|
+
if (index >= 0) {
|
|
226
|
+
list[index] = { ...asRecord(list[index]), ...incoming };
|
|
227
|
+
replaced = true;
|
|
228
|
+
} else {
|
|
229
|
+
list.push(incoming);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
groups[bucket] = list;
|
|
233
|
+
// qwen reads the value from `env`, never from the row — its docs are
|
|
234
|
+
// explicit that `envKey` is a NAME.
|
|
235
|
+
const envBlock = asRecord(doc.env);
|
|
236
|
+
if (planned.apiKey) {
|
|
237
|
+
doc.env = { ...envBlock, ...env };
|
|
238
|
+
notes.push('The key was written to settings.json `env` — qwen reads `envKey` as a variable NAME.');
|
|
239
|
+
}
|
|
240
|
+
await writeFileAtomic(path, serialise(kind, doc), { createMode: 0o600 });
|
|
241
|
+
return { id, replaced, path, dialect: bucket, env, notes };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const providers = providerMap(doc, facts.registry.pointer, path);
|
|
245
|
+
const replaced = Object.prototype.hasOwnProperty.call(providers, id);
|
|
246
|
+
const existing = asRecord(providers[id]);
|
|
247
|
+
const incoming = providerEntryFor(kind, planned, target);
|
|
248
|
+
// The user's own choices win over the import's defaults; the import still
|
|
249
|
+
// brings the endpoint and the model rows.
|
|
250
|
+
const merged = {
|
|
251
|
+
...incoming,
|
|
252
|
+
...(replaced ? pickExisting(existing, incoming) : {}),
|
|
253
|
+
};
|
|
254
|
+
providers[id] = merged;
|
|
255
|
+
|
|
256
|
+
// Formats that select models by ALIAS need the model table beside the
|
|
257
|
+
// provider, or the agent lists the provider and serves nothing from it.
|
|
258
|
+
if (facts.registry.modelsAreRows) {
|
|
259
|
+
const models = asRecord(doc[facts.registry.modelsField ?? 'models']);
|
|
260
|
+
const rows = modelRowsFor(kind, planned);
|
|
261
|
+
for (const [alias, row] of Object.entries(rows)) {
|
|
262
|
+
models[alias] = { ...asRecord(models[alias]), ...row };
|
|
263
|
+
}
|
|
264
|
+
doc[facts.registry.modelsField ?? 'models'] = models;
|
|
265
|
+
if (Object.keys(rows).length > 0) {
|
|
266
|
+
notes.push(`Wrote ${Object.keys(rows).length} model alias${Object.keys(rows).length === 1 ? '' : 'es'} into ${facts.registry.modelsField} — kimi selects models by alias.`);
|
|
267
|
+
} else {
|
|
268
|
+
// A provider with no alias is invisible to the agent's model picker. That
|
|
269
|
+
// is a legitimate intermediate state (the user may add models next), but
|
|
270
|
+
// reporting a bare success would read as "ready".
|
|
271
|
+
notes.push('No model ids were given, so this provider has no alias yet — it serves nothing until one is added.');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Measured: omp serves NOTHING from an entry with no models and no
|
|
276
|
+
// `discovery` block, and says nothing about it. Reporting a bare success
|
|
277
|
+
// would let the user ship a provider that answers no model at all.
|
|
278
|
+
const modelCount = Array.isArray(merged.models) ? merged.models.length : 0;
|
|
279
|
+
const declaresDiscovery = asRecord(merged.discovery).type !== undefined;
|
|
280
|
+
if (modelCount === 0 && !declaresDiscovery && !facts.registry.modelsAreRows) {
|
|
281
|
+
notes.push('No models on this provider yet — the agent serves nothing from it until ids are added (or it is registered as discovery).');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (env && Object.keys(env).length > 0) {
|
|
285
|
+
notes.push(`Set ${Object.keys(env).join(', ')} in this harness's environment — the file stores a variable NAME, not the key.`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
await writeFileAtomic(path, serialise(kind, doc), { createMode: 0o600 });
|
|
289
|
+
return { id, replaced, path, dialect, env, notes };
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** The row the import list handed out, as the writer needs it. */
|
|
294
|
+
export interface ListedProvider {
|
|
295
|
+
id: string;
|
|
296
|
+
name: string;
|
|
297
|
+
baseUrl?: string;
|
|
298
|
+
protocol?: CanonicalProtocol;
|
|
299
|
+
models: string[];
|
|
300
|
+
contextWindow?: Record<string, number>;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* The draft for importing `source`'s provider into a target.
|
|
305
|
+
*
|
|
306
|
+
* `readProviderKey` is called HERE, and only here: the list the browser holds has
|
|
307
|
+
* a boolean `hasKey`, never the credential.
|
|
308
|
+
*
|
|
309
|
+
* `measured` is the protocol a live probe found, when the import ran one. It
|
|
310
|
+
* outranks the source's declared dialect because the endpoint is the authority:
|
|
311
|
+
* measured on kenari, whose models.yml entry says `openai-completions` while the
|
|
312
|
+
* host also answers Anthropic Messages — an import into claude has to use the
|
|
313
|
+
* latter or Claude Code fails every request.
|
|
314
|
+
*/
|
|
315
|
+
export async function draftForImport(
|
|
316
|
+
source: HarnessId,
|
|
317
|
+
listed: ListedProvider,
|
|
318
|
+
measured?: CanonicalProtocol | null,
|
|
319
|
+
): Promise<ProviderDraft> {
|
|
320
|
+
const apiKey = await readProviderKey(source, listed.id);
|
|
321
|
+
return {
|
|
322
|
+
id: listed.id,
|
|
323
|
+
name: listed.name,
|
|
324
|
+
...(listed.baseUrl ? { baseUrl: listed.baseUrl } : {}),
|
|
325
|
+
...(measured ?? listed.protocol ? { protocol: (measured ?? listed.protocol) as CanonicalProtocol } : {}),
|
|
326
|
+
models: listed.models,
|
|
327
|
+
...(listed.contextWindow ? { contextWindow: listed.contextWindow } : {}),
|
|
328
|
+
...(apiKey ? { apiKey } : {}),
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Every provider a harness could import FROM, custom only. */
|
|
333
|
+
export async function importableFrom(source: HarnessId) {
|
|
334
|
+
return readRegistryProviders(source);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** Re-exported so a caller imports one module for a write. */
|
|
338
|
+
export { ProviderWriteError, providerEntryFor };
|
|
339
|
+
export type { ProviderDraft };
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ZCode's personal provider file is a RULE GRAPH, and these cases pin the two
|
|
8
|
+
* things a map-shaped writer would get wrong:
|
|
9
|
+
*
|
|
10
|
+
* - a provider rule alone is invisible (the bridge builds its dropdown from
|
|
11
|
+
* `modelConfigRules`), so a write must emit one model rule per id;
|
|
12
|
+
* - the file also holds the desktop's manual capability blocks, headers and
|
|
13
|
+
* default selection — a merge that rewrites them breaks an install.
|
|
14
|
+
*
|
|
15
|
+
* Measured against the bridge's own 0.82.3 reader (`loadPersonalModels` /
|
|
16
|
+
* `appendPersonalOnlyProviders`): with this file present, `session/new`
|
|
17
|
+
* advertises `kenari\qwen3-8-27b:free` even when `config.json` does not exist.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { describe, expect, test } from 'bun:test';
|
|
21
|
+
import fs from 'node:fs';
|
|
22
|
+
import os from 'node:os';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
|
|
25
|
+
import { readZcodeProviderKey, readZcodeProviders, writeZcodeProvider } from '@/server/lib/harness/provider-zcode.server';
|
|
26
|
+
import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
|
|
27
|
+
import { isWindows } from '@/test-support/platform';
|
|
28
|
+
|
|
29
|
+
function tempFile(content?: string): string {
|
|
30
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kabmo-zcode-'));
|
|
31
|
+
const file = path.join(dir, 'provider_config.json');
|
|
32
|
+
if (content !== undefined) fs.writeFileSync(file, content, { mode: 0o600 });
|
|
33
|
+
return file;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const EXISTING = JSON.stringify({
|
|
37
|
+
schemaVersion: 1,
|
|
38
|
+
config: {
|
|
39
|
+
providerConfigRules: {
|
|
40
|
+
providerRules: [
|
|
41
|
+
{
|
|
42
|
+
providerId: 'existing',
|
|
43
|
+
providerName: 'Existing Gateway',
|
|
44
|
+
enabled: true,
|
|
45
|
+
config: {
|
|
46
|
+
group: 'standard-personal',
|
|
47
|
+
access: { type: 'api-key', apiKey: 'sk-keep' },
|
|
48
|
+
api: { type: 'anthropic-messages', baseUrl: 'https://old.example', headers: { 'X-Keep': '1' } },
|
|
49
|
+
personalModelIds: ['old-model'],
|
|
50
|
+
modelOrder: ['old-model'],
|
|
51
|
+
visibility: 'visible',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
modelConfigRules: {
|
|
57
|
+
providerModelRules: [],
|
|
58
|
+
manualProviderModelRules: [
|
|
59
|
+
{
|
|
60
|
+
providerId: 'existing',
|
|
61
|
+
modelId: 'old-model',
|
|
62
|
+
config: {
|
|
63
|
+
enabled: true,
|
|
64
|
+
properties: { contextWindow: 64000, supportsJsonSchemaOutput: false },
|
|
65
|
+
optionSpecs: { reasoningLevel: { values: ['low'], map: '{}' } },
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
defaultModelSelection: { providerId: 'existing', modelId: 'old-model' },
|
|
71
|
+
},
|
|
72
|
+
}, null, 2);
|
|
73
|
+
|
|
74
|
+
describe('reading the personal provider rules', () => {
|
|
75
|
+
test('a provider is listed with its model rules, personal ids and no key', () => {
|
|
76
|
+
const rows = readZcodeProviders(EXISTING, 'zcode');
|
|
77
|
+
expect(rows).toHaveLength(1);
|
|
78
|
+
expect(rows[0]).toMatchObject({
|
|
79
|
+
id: 'existing',
|
|
80
|
+
name: 'Existing Gateway',
|
|
81
|
+
baseUrl: 'https://old.example',
|
|
82
|
+
dialect: 'anthropic-messages',
|
|
83
|
+
protocol: 'anthropic-messages',
|
|
84
|
+
models: ['old-model'],
|
|
85
|
+
contextWindow: { 'old-model': 64000 },
|
|
86
|
+
hasKey: true,
|
|
87
|
+
source: 'zcode',
|
|
88
|
+
});
|
|
89
|
+
// The credential itself never leaves the file.
|
|
90
|
+
expect('apiKey' in rows[0]!).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('custom providers added only through personalModelIds stay visible', () => {
|
|
94
|
+
const text = JSON.stringify({
|
|
95
|
+
schemaVersion: 1,
|
|
96
|
+
config: {
|
|
97
|
+
providerConfigRules: {
|
|
98
|
+
providerRules: [{
|
|
99
|
+
providerId: 'gateway',
|
|
100
|
+
providerName: 'Gateway',
|
|
101
|
+
config: { api: { type: 'openai-chat-completions', baseUrl: 'https://gw.example/v1' }, personalModelIds: ['m-1'] },
|
|
102
|
+
}],
|
|
103
|
+
},
|
|
104
|
+
modelConfigRules: { providerModelRules: [], manualProviderModelRules: [] },
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
expect(readZcodeProviders(text, 'zcode')[0]?.models).toEqual(['m-1']);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('builtin and account ids are runtime-owned, but `local` is a custom id', () => {
|
|
111
|
+
const text = JSON.stringify({
|
|
112
|
+
schemaVersion: 1,
|
|
113
|
+
config: {
|
|
114
|
+
providerConfigRules: {
|
|
115
|
+
providerRules: [
|
|
116
|
+
{ providerId: 'builtin:zai-coding-plan', config: {} },
|
|
117
|
+
{ providerId: 'account:bigmodel-individual-coding-plan', config: {} },
|
|
118
|
+
{ providerId: 'local', providerName: 'Local llama.cpp', config: {} },
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
modelConfigRules: { providerModelRules: [], manualProviderModelRules: [] },
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
// ZCode's own reference uses `local` as its custom-provider example; the
|
|
125
|
+
// shared vendor census names `local` too and must not hide it here.
|
|
126
|
+
expect(readZcodeProviders(text, 'zcode').map((row) => row.id)).toEqual(['local']);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('a malformed file yields no rows and no key', () => {
|
|
130
|
+
expect(readZcodeProviders('{not json', 'zcode')).toEqual([]);
|
|
131
|
+
expect(readZcodeProviderKey('{not json', 'existing')).toBeNull();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('a stored key is read only by id', () => {
|
|
135
|
+
expect(readZcodeProviderKey(EXISTING, 'existing')).toBe('sk-keep');
|
|
136
|
+
expect(readZcodeProviderKey(EXISTING, 'missing')).toBeNull();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
describe('writing a provider into the rule graph', () => {
|
|
141
|
+
test('a new provider gets a rule and one model rule per id', async () => {
|
|
142
|
+
const file = tempFile(EXISTING);
|
|
143
|
+
const result = await writeZcodeProvider({
|
|
144
|
+
path: file,
|
|
145
|
+
id: 'kenari',
|
|
146
|
+
draft: {
|
|
147
|
+
id: 'kenari',
|
|
148
|
+
name: 'Kenari',
|
|
149
|
+
baseUrl: 'https://kenari.id/v1',
|
|
150
|
+
protocol: 'openai-chat',
|
|
151
|
+
models: ['qwen3-8-27b:free'],
|
|
152
|
+
apiKey: 'kn-1',
|
|
153
|
+
contextWindow: { 'qwen3-8-27b:free': 262144 },
|
|
154
|
+
},
|
|
155
|
+
dialect: 'openai-chat-completions',
|
|
156
|
+
});
|
|
157
|
+
expect(result.replaced).toBe(false);
|
|
158
|
+
// POSIX only: Windows has no permission bits and `statSync().mode` there
|
|
159
|
+
// reports a synthesised 0o666 for every file — measured on the Windows gate
|
|
160
|
+
// as `Expected: 384, Received: 438` (0o600 vs 0o666) for a write that set
|
|
161
|
+
// the mode correctly on the host. `chmod` is a no-op there.
|
|
162
|
+
if (!isWindows) expect(fs.statSync(file).mode & 0o777).toBe(0o600);
|
|
163
|
+
|
|
164
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
165
|
+
expect(text.endsWith('}')).toBe(true);
|
|
166
|
+
const doc = JSON.parse(text);
|
|
167
|
+
const rules = doc.config.providerConfigRules.providerRules;
|
|
168
|
+
expect(rules).toHaveLength(2);
|
|
169
|
+
expect(rules[1]).toMatchObject({
|
|
170
|
+
providerId: 'kenari',
|
|
171
|
+
providerName: 'Kenari',
|
|
172
|
+
enabled: true,
|
|
173
|
+
config: {
|
|
174
|
+
access: { type: 'api-key', apiKey: 'kn-1' },
|
|
175
|
+
api: { type: 'openai-chat-completions', baseUrl: 'https://kenari.id/v1' },
|
|
176
|
+
personalModelIds: ['qwen3-8-27b:free'],
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
expect(doc.config.modelConfigRules.providerModelRules).toEqual([{
|
|
180
|
+
providerId: 'kenari',
|
|
181
|
+
modelId: 'qwen3-8-27b:free',
|
|
182
|
+
config: {
|
|
183
|
+
enabled: true,
|
|
184
|
+
properties: { contextWindow: 262144 },
|
|
185
|
+
optionSpecs: { reasoningLevel: { values: ['disabled', 'enabled'], map: '{}' } },
|
|
186
|
+
},
|
|
187
|
+
}]);
|
|
188
|
+
// The desktop's own state is not ours to rewrite.
|
|
189
|
+
expect(doc.config.modelConfigRules.manualProviderModelRules).toHaveLength(1);
|
|
190
|
+
expect(doc.config.defaultModelSelection).toEqual({ providerId: 'existing', modelId: 'old-model' });
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('an update keeps the stored key, headers and a manual model rule', async () => {
|
|
194
|
+
const file = tempFile(EXISTING);
|
|
195
|
+
await writeZcodeProvider({
|
|
196
|
+
path: file,
|
|
197
|
+
id: 'existing',
|
|
198
|
+
draft: {
|
|
199
|
+
id: 'existing',
|
|
200
|
+
name: 'Existing Gateway',
|
|
201
|
+
baseUrl: 'https://new.example',
|
|
202
|
+
protocol: 'anthropic-messages',
|
|
203
|
+
models: ['new-model'],
|
|
204
|
+
},
|
|
205
|
+
dialect: 'anthropic-messages',
|
|
206
|
+
});
|
|
207
|
+
const doc = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
208
|
+
const rule = doc.config.providerConfigRules.providerRules[0];
|
|
209
|
+
expect(rule.config.access.apiKey).toBe('sk-keep');
|
|
210
|
+
expect(rule.config.api).toMatchObject({
|
|
211
|
+
type: 'anthropic-messages',
|
|
212
|
+
baseUrl: 'https://new.example',
|
|
213
|
+
headers: { 'X-Keep': '1' },
|
|
214
|
+
});
|
|
215
|
+
// Union, not replacement: a model the user already had is not dropped.
|
|
216
|
+
expect(rule.config.personalModelIds).toEqual(['old-model', 'new-model']);
|
|
217
|
+
// The manual rule stays manual (moving it would drop the capability block),
|
|
218
|
+
// and the new model gets a smart rule.
|
|
219
|
+
expect(doc.config.modelConfigRules.manualProviderModelRules).toHaveLength(1);
|
|
220
|
+
expect(doc.config.modelConfigRules.providerModelRules).toEqual([{
|
|
221
|
+
providerId: 'existing',
|
|
222
|
+
modelId: 'new-model',
|
|
223
|
+
config: {
|
|
224
|
+
enabled: true,
|
|
225
|
+
optionSpecs: { reasoningLevel: { values: ['disabled', 'enabled'], map: '{}' } },
|
|
226
|
+
},
|
|
227
|
+
}]);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('a model rule is never duplicated across the two arrays', async () => {
|
|
231
|
+
const file = tempFile(EXISTING);
|
|
232
|
+
await writeZcodeProvider({
|
|
233
|
+
path: file,
|
|
234
|
+
id: 'existing',
|
|
235
|
+
draft: {
|
|
236
|
+
id: 'existing',
|
|
237
|
+
name: 'Existing Gateway',
|
|
238
|
+
baseUrl: 'https://old.example',
|
|
239
|
+
protocol: 'anthropic-messages',
|
|
240
|
+
models: ['old-model'],
|
|
241
|
+
},
|
|
242
|
+
dialect: 'anthropic-messages',
|
|
243
|
+
});
|
|
244
|
+
const doc = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
245
|
+
expect(doc.config.modelConfigRules.providerModelRules).toEqual([]);
|
|
246
|
+
expect(doc.config.modelConfigRules.manualProviderModelRules[0].modelId).toBe('old-model');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('a malformed file is refused untouched', async () => {
|
|
250
|
+
const file = tempFile('{broken');
|
|
251
|
+
await expect(writeZcodeProvider({
|
|
252
|
+
path: file,
|
|
253
|
+
id: 'kenari',
|
|
254
|
+
draft: { id: 'kenari', name: 'Kenari', baseUrl: 'https://kenari.id/v1', protocol: 'openai-chat', models: ['m'] },
|
|
255
|
+
dialect: 'openai-chat-completions',
|
|
256
|
+
})).rejects.toThrow(ProviderWriteError);
|
|
257
|
+
expect(fs.readFileSync(file, 'utf8')).toBe('{broken');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('a provider with no endpoint is refused instead of written broken', async () => {
|
|
261
|
+
const file = tempFile();
|
|
262
|
+
await expect(writeZcodeProvider({
|
|
263
|
+
path: file,
|
|
264
|
+
id: 'kenari',
|
|
265
|
+
draft: { id: 'kenari', name: 'Kenari', protocol: 'openai-chat', models: ['m'] },
|
|
266
|
+
dialect: 'openai-chat-completions',
|
|
267
|
+
})).rejects.toThrow(/base URL/);
|
|
268
|
+
expect(fs.existsSync(file)).toBe(false);
|
|
269
|
+
});
|
|
270
|
+
});
|