@kabmo-labs/kabmo 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +805 -736
- package/dist/client/static/js/index-bc9aa4mx.css +1 -0
- package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
- package/src/client/components/common/session-actions-menu/index.tsx +33 -2
- package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
- package/src/client/components/common/session-row/index.tsx +27 -1
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +55 -46
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +5 -5
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +12 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +56 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
- package/src/client/hooks/chat/timeline/send.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.ts +59 -53
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +10 -3
- package/src/client/hooks/models/use-harness-update.test.ts +193 -0
- package/src/client/hooks/models/use-harness-update.ts +202 -0
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/hooks/workspace/child-expansion.ts +33 -0
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/tailwind.css +26 -12
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/client.ts +2 -2
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/mapper.ts +6 -4
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
- package/src/server/lib/harness/acp/session-handshake.ts +36 -3
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-requests.ts +47 -0
- package/src/server/lib/harness/acp/session-turns.ts +20 -5
- package/src/server/lib/harness/acp/session.test-util.ts +54 -3
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +79 -79
- package/src/server/lib/harness/acp/turn.test.ts +81 -0
- package/src/server/lib/harness/acp/turn.ts +54 -13
- package/src/server/lib/harness/acp/verbs.ts +12 -2
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +16 -116
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +126 -0
- package/src/server/lib/harness/update-job-store.ts +109 -0
- package/src/server/lib/harness/update-job.server.ts +203 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +197 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/lifecycle/paths.ts +23 -0
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
- package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
- package/src/server/lib/omp/session/delete.server.ts +17 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +209 -0
- package/src/server/lib/sessions/fork.server.ts +304 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +196 -0
- package/src/server/lib/sessions/spawn.server.ts +310 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +6 -0
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +22 -4
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update-status.ts +26 -0
- package/src/server/routes/harness/update.test.ts +119 -0
- package/src/server/routes/harness/update.ts +67 -113
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +74 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/session.ts +4 -0
- package/src/server/routes/sessions/spawn.ts +134 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +59 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +44 -1
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +33 -0
- package/src/shared/lib/harness/update-plan.test.ts +69 -4
- package/src/shared/lib/harness/update-plan.ts +57 -9
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +26 -10
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +65 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +21 -4
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which harnesses read the same registry file.
|
|
8
|
+
*
|
|
9
|
+
* The bug this pins: a provider added on the `omp-acp` tab was written to the
|
|
10
|
+
* one `models.yml` both transports read, but only the clicked tab's probe was
|
|
11
|
+
* dropped — so the other picker kept serving the pre-write catalog until its
|
|
12
|
+
* TTL expired. The relation therefore has to be derived from the FILE the
|
|
13
|
+
* harness reads, not from a hand-written pair that a third transport would miss.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import { registryFilePath, harnessesSharingRegistry } from '@/server/lib/harness/provider-sources.server';
|
|
18
|
+
|
|
19
|
+
describe('harnesses that share a registry file', () => {
|
|
20
|
+
test('both omp transports read the same models.yml', () => {
|
|
21
|
+
const modelsYml = registryFilePath('omp-rpc');
|
|
22
|
+
expect(modelsYml).not.toBeNull();
|
|
23
|
+
// Measured on the real facts table: omp-acp reads the same file omp-rpc does.
|
|
24
|
+
expect(registryFilePath('omp-acp')).toBe(modelsYml);
|
|
25
|
+
expect(harnessesSharingRegistry(modelsYml!).sort()).toEqual(['omp-acp', 'omp-rpc']);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('a harness with its own file names only itself', () => {
|
|
29
|
+
const codex = registryFilePath('codex');
|
|
30
|
+
expect(codex).not.toBeNull();
|
|
31
|
+
expect(harnessesSharingRegistry(codex!)).toEqual(['codex']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('a path no harness reads invalidates nothing', () => {
|
|
35
|
+
// A caller that wrote some other file must not blank an unrelated picker.
|
|
36
|
+
expect(harnessesSharingRegistry(`${registryFilePath('omp-rpc')}.bak`)).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('harnesses without a registry never appear', () => {
|
|
40
|
+
// `minimax` has no file (`registry.file === null`); it must not match the
|
|
41
|
+
// home directory merely because both strings are empty.
|
|
42
|
+
expect(registryFilePath('minimax')).toBeNull();
|
|
43
|
+
expect(harnessesSharingRegistry('')).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -40,7 +40,9 @@ import { parse as parseToml } from 'smol-toml';
|
|
|
40
40
|
import { providerFacts, type ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
|
|
41
41
|
import { protocolOfSourceDialect, type CanonicalProtocol } from '@/shared/lib/harness/dialects';
|
|
42
42
|
import { isVendorProviderId } from '@/shared/lib/models/provider/vendors';
|
|
43
|
-
import type
|
|
43
|
+
import { HARNESS_IDS, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
44
|
+
import { canonicalize } from '@/server/lib/omp/core/paths';
|
|
45
|
+
import { readZcodeProviderKey, readZcodeProviders } from '@/server/lib/harness/provider-zcode.server';
|
|
44
46
|
|
|
45
47
|
/** One provider as a source registry holds it, minus its credential. */
|
|
46
48
|
export interface ImportableProvider {
|
|
@@ -84,6 +86,22 @@ export function registryFilePath(id: HarnessId): string | null {
|
|
|
84
86
|
return file ? join(homeDir(), file) : null;
|
|
85
87
|
}
|
|
86
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Every harness that reads the SAME registry file.
|
|
91
|
+
*
|
|
92
|
+
* `omp-rpc` and `omp-acp` are two transports over one `models.yml`, so a
|
|
93
|
+
* provider written through either must invalidate the other's cached model
|
|
94
|
+
* list. The comparison is the file itself, not a hand-written pair, so a future
|
|
95
|
+
* harness that shares a registry inherits the rule for free.
|
|
96
|
+
*/
|
|
97
|
+
export function harnessesSharingRegistry(path: string): HarnessId[] {
|
|
98
|
+
const key = canonicalize(path);
|
|
99
|
+
return HARNESS_IDS.filter((id) => {
|
|
100
|
+
const file = registryFilePath(id);
|
|
101
|
+
return file !== null && canonicalize(file) === key;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
87
105
|
/** A value at a dot-path (`options.baseURL`), or undefined. */
|
|
88
106
|
function atPointer(root: Record<string, unknown>, pointer: string): unknown {
|
|
89
107
|
let node: unknown = root;
|
|
@@ -115,7 +133,8 @@ function parseByKind(kind: ProviderRegistryKind, text: string): Record<string, u
|
|
|
115
133
|
case 'toml-providers': return asRecord(parseToml(text));
|
|
116
134
|
case 'json-provider':
|
|
117
135
|
case 'json-providers':
|
|
118
|
-
case 'json-model-providers':
|
|
136
|
+
case 'json-model-providers':
|
|
137
|
+
case 'zcode-provider-rules': return asRecord(JSON.parse(text));
|
|
119
138
|
default: return null;
|
|
120
139
|
}
|
|
121
140
|
} catch {
|
|
@@ -177,6 +196,10 @@ export async function readRegistryProviders(id: HarnessId): Promise<ImportablePr
|
|
|
177
196
|
const doc = parseByKind(kind, text);
|
|
178
197
|
if (!doc) return [];
|
|
179
198
|
|
|
199
|
+
// ZCode's registry is a rule GRAPH, not a providers map: one provider rule
|
|
200
|
+
// plus one rule per model. Its reader lives beside its writer.
|
|
201
|
+
if (kind === 'zcode-provider-rules') return readZcodeProviders(text, id);
|
|
202
|
+
|
|
180
203
|
// `modelProviders` is an ARRAY per protocol (qwen), so its rows are the models
|
|
181
204
|
// themselves and the provider id is the protocol key.
|
|
182
205
|
if (kind === 'json-model-providers') {
|
|
@@ -278,6 +301,7 @@ export async function readProviderKey(source: HarnessId, providerId: string): Pr
|
|
|
278
301
|
if (!text || !facts.registry.apiKeyField) return null;
|
|
279
302
|
const doc = parseByKind(facts.registry.kind, text);
|
|
280
303
|
if (!doc) return null;
|
|
304
|
+
if (facts.registry.kind === 'zcode-provider-rules') return readZcodeProviderKey(text, providerId);
|
|
281
305
|
const entry = asRecord(asRecord(atPointer(doc, facts.registry.pointer))[providerId]);
|
|
282
306
|
const value = atPointer(entry, facts.registry.apiKeyField);
|
|
283
307
|
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
@@ -39,8 +39,9 @@ import {
|
|
|
39
39
|
} from '@/shared/lib/harness/dialects';
|
|
40
40
|
import { isVendorProviderId } from '@/shared/lib/models/provider/vendors';
|
|
41
41
|
import { registryFilePath, readProviderKey, readRegistryProviders } from '@/server/lib/harness/provider-sources.server';
|
|
42
|
-
import { asRecord, modelRowsFor, providerEntryFor, type ProviderDraft } from '@/server/lib/harness/provider-entry';
|
|
42
|
+
import { asRecord, modelRowsFor, pickExisting, providerEntryFor, type ProviderDraft } from '@/server/lib/harness/provider-entry';
|
|
43
43
|
import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
|
|
44
|
+
import { writeZcodeProvider } from '@/server/lib/harness/provider-zcode.server';
|
|
44
45
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
45
46
|
|
|
46
47
|
/** What a successful write changed, so the card can report it rather than guess. */
|
|
@@ -164,17 +165,34 @@ export async function writeProvider(
|
|
|
164
165
|
if (!ID_PATTERN.test(id)) {
|
|
165
166
|
throw new ProviderWriteError(`"${id}" is not a provider id ${target} accepts (lowercase, digits, . _ : -)`);
|
|
166
167
|
}
|
|
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)) {
|
|
168
174
|
throw new ProviderWriteError(
|
|
169
175
|
`"${id}" is a provider ${target} ships itself, so writing it would override the vendor's entry instead of `
|
|
170
176
|
+ 'adding a gateway. Only providers you registered yourself can be imported.',
|
|
171
177
|
);
|
|
172
178
|
}
|
|
173
179
|
|
|
174
|
-
const kind = facts.registry.kind;
|
|
175
180
|
const plan = planFor(target, draft);
|
|
176
181
|
const planned: ProviderDraft = { ...draft, protocol: plan.protocol, baseUrl: plan.baseUrl };
|
|
177
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
|
+
|
|
178
196
|
const env = credentialEnvFor(kind, planned);
|
|
179
197
|
const notes: string[] = [];
|
|
180
198
|
|
|
@@ -272,35 +290,6 @@ export async function writeProvider(
|
|
|
272
290
|
});
|
|
273
291
|
}
|
|
274
292
|
|
|
275
|
-
/**
|
|
276
|
-
* The fields of an EXISTING entry that the import must not overwrite.
|
|
277
|
-
*
|
|
278
|
-
* A stored credential is the one that matters: an import brings an endpoint, and
|
|
279
|
-
* replacing a key the user set by hand is not what asking to copy a provider
|
|
280
|
-
* meant. `npm`/`type`/`wire_api` (the dialect) are kept too — they describe how
|
|
281
|
-
* that provider already works, and the source's dialect is a guess about a
|
|
282
|
-
* different agent.
|
|
283
|
-
*/
|
|
284
|
-
function pickExisting(existing: Record<string, unknown>, incoming: Record<string, unknown>): Record<string, unknown> {
|
|
285
|
-
const keep: Record<string, unknown> = {};
|
|
286
|
-
const scalarKeys = ['npm', 'type', 'wire_api', 'api', 'name'];
|
|
287
|
-
for (const key of scalarKeys) {
|
|
288
|
-
if (existing[key] !== undefined && incoming[key] !== undefined) keep[key] = existing[key];
|
|
289
|
-
}
|
|
290
|
-
// Credentials, in each format's spelling: a top-level apiKey/api_key, or one
|
|
291
|
-
// nested inside opencode's `options`.
|
|
292
|
-
if (typeof existing.apiKey === 'string' && existing.apiKey) keep.apiKey = existing.apiKey;
|
|
293
|
-
if (typeof existing.api_key === 'string' && existing.api_key) keep.api_key = existing.api_key;
|
|
294
|
-
const existingOptions = asRecord(existing.options);
|
|
295
|
-
const incomingOptions = asRecord(incoming.options);
|
|
296
|
-
if (Object.keys(incomingOptions).length > 0) {
|
|
297
|
-
// `options` is merged key by key, so an endpoint arrives while a stored key
|
|
298
|
-
// and any hand-written option stay.
|
|
299
|
-
keep.options = { ...incomingOptions, ...existingOptions };
|
|
300
|
-
}
|
|
301
|
-
return keep;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
293
|
/** The row the import list handed out, as the writer needs it. */
|
|
305
294
|
export interface ListedProvider {
|
|
306
295
|
id: string;
|
|
@@ -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
|
+
});
|