@kabmo-labs/kabmo 0.11.1 → 0.12.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 +67 -421
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +426 -413
- package/dist/client/static/js/{index-amss8pge.js → index-0smc9gm2.js} +1123 -747
- package/dist/client/static/js/index-shexbk5f.css +1 -0
- package/marketplace/marketplace.json +13 -3
- package/marketplace/plugins/command-runner/package.json +4 -2
- package/marketplace/plugins/git-forge/README.md +219 -0
- package/marketplace/plugins/git-forge/icon.svg +20 -0
- package/marketplace/plugins/git-forge/package.json +56 -0
- package/marketplace/plugins/git-forge/src/app.tsx +82 -0
- package/marketplace/plugins/git-forge/src/command.test.ts +181 -0
- package/marketplace/plugins/git-forge/src/command.ts +119 -0
- package/marketplace/plugins/git-forge/src/header.tsx +87 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +76 -0
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +150 -0
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +51 -0
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +107 -0
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +70 -0
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +255 -0
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +198 -0
- package/marketplace/plugins/git-forge/src/panel/List.tsx +89 -0
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +68 -0
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +94 -0
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +236 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +78 -0
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +344 -0
- package/marketplace/plugins/git-forge/src/panel/index.tsx +193 -0
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +250 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +269 -0
- package/marketplace/plugins/git-forge/src/protocol.ts +308 -0
- package/marketplace/plugins/git-forge/src/server/adapters.test.ts +274 -0
- package/marketplace/plugins/git-forge/src/server/bitbucket.ts +307 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.test.ts +116 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.ts +105 -0
- package/marketplace/plugins/git-forge/src/server/ci.test.ts +88 -0
- package/marketplace/plugins/git-forge/src/server/ci.ts +118 -0
- package/marketplace/plugins/git-forge/src/server/context.ts +76 -0
- package/marketplace/plugins/git-forge/src/server/diff.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/diff.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/filters.test.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/filters.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/forges.test.ts +235 -0
- package/marketplace/plugins/git-forge/src/server/gitea.ts +296 -0
- package/marketplace/plugins/git-forge/src/server/github-extras.ts +92 -0
- package/marketplace/plugins/git-forge/src/server/github.ts +320 -0
- package/marketplace/plugins/git-forge/src/server/gitlab-detail.ts +207 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.test.ts +195 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.ts +176 -0
- package/marketplace/plugins/git-forge/src/server/http.test.ts +270 -0
- package/marketplace/plugins/git-forge/src/server/http.ts +329 -0
- package/marketplace/plugins/git-forge/src/server/map.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/registry.ts +47 -0
- package/marketplace/plugins/git-forge/src/server/remote.test.ts +146 -0
- package/marketplace/plugins/git-forge/src/server/remote.ts +188 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.test.ts +98 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.ts +128 -0
- package/marketplace/plugins/git-forge/src/server/scope.ts +66 -0
- package/marketplace/plugins/git-forge/src/server/test-context.ts +67 -0
- package/marketplace/plugins/git-forge/src/server/test-host.ts +51 -0
- package/marketplace/plugins/git-forge/src/server/token.test.ts +107 -0
- package/marketplace/plugins/git-forge/src/server/token.ts +139 -0
- package/marketplace/plugins/git-forge/src/server/write-http.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/write-http.ts +110 -0
- package/marketplace/plugins/git-forge/src/server/writes.test.ts +218 -0
- package/marketplace/plugins/git-forge/src/server/writes.ts +313 -0
- package/marketplace/plugins/git-forge/src/server.ts +284 -0
- package/marketplace/plugins/git-forge/tsconfig.json +16 -0
- package/marketplace/plugins/session-info/package.json +4 -2
- package/marketplace/plugins/stats/package.json +4 -2
- package/package.json +6 -1
- package/src/client/components/common/code-surface/blame-hover.ts +188 -0
- package/src/client/components/common/code-surface/blame-panel.test.ts +304 -0
- package/src/client/components/common/code-surface/blame-panel.ts +306 -0
- package/src/client/components/common/code-surface/blame.test.ts +303 -0
- package/src/client/components/common/code-surface/blame.ts +227 -0
- package/src/client/components/common/code-surface/conflict-markers.test.ts +135 -0
- package/src/client/components/common/code-surface/conflict-markers.ts +144 -0
- package/src/client/components/common/code-surface/documents.ts +48 -1
- package/src/client/components/common/code-surface/extensions.test.ts +4 -0
- package/src/client/components/common/code-surface/extensions.ts +44 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +4 -0
- package/src/client/components/common/code-surface/indent.test.ts +5 -0
- package/src/client/components/common/code-surface/index.tsx +16 -2
- package/src/client/components/common/code-surface/lint-parsers.test.ts +109 -0
- package/src/client/components/common/code-surface/lint-parsers.ts +134 -0
- package/src/client/components/common/code-surface/lint.test.ts +101 -0
- package/src/client/components/common/code-surface/lint.ts +85 -0
- package/src/client/components/common/code-surface/props.ts +17 -0
- package/src/client/components/common/code-surface/surface-failures.test.ts +132 -0
- package/src/client/components/common/code-surface/theme.ts +71 -0
- package/src/client/components/common/header-controls/index.test.tsx +1 -1
- package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -1
- package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -1
- package/src/client/components/common/provider-icon/Plate.tsx +88 -0
- package/src/client/components/common/provider-icon/index.tsx +55 -11
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +5 -2
- package/src/client/components/mobile/SessionSidebar.tsx +2 -10
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +6 -0
- package/src/client/components/mobile/mobile-right-sidebar/StatusBar.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +3 -0
- package/src/client/components/settings/categories/ProviderSettings.tsx +43 -41
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +97 -0
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +106 -54
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +14 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +39 -150
- package/src/client/components/settings/categories/panel-plugins/Meta.test.tsx +143 -0
- package/src/client/components/settings/categories/panel-plugins/Meta.tsx +157 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.tsx +99 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +270 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +11 -3
- package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +25 -0
- package/src/client/components/settings/categories/provider-settings/AuthSection.tsx +135 -80
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +51 -21
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +175 -0
- package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +275 -0
- package/src/client/components/settings/categories/provider-settings/Header.tsx +40 -9
- package/src/client/components/settings/categories/provider-settings/LoginModal.tsx +142 -160
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/ModelCapabilitiesModal.tsx +84 -46
- package/src/client/components/settings/categories/provider-settings/ModelsList.tsx +217 -102
- package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +5 -2
- package/src/client/components/settings/categories/provider-settings/SidebarList.plugin.test.ts +3 -3
- package/src/client/components/settings/categories/provider-settings/SidebarList.tsx +158 -102
- package/src/client/components/settings/categories/provider-settings/auth-section.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/groups.test.ts +98 -0
- package/src/client/components/settings/categories/provider-settings/groups.ts +108 -0
- package/src/client/components/settings/categories/provider-settings/layout.test.tsx +325 -0
- package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/preset-picker.test.tsx +73 -0
- package/src/client/components/settings/categories/usage-settings/ProviderCard.tsx +22 -2
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +2 -0
- package/src/client/components/settings/categories/usage-settings/SidebarList.tsx +16 -6
- package/src/client/components/settings/categories/usage-settings/providers.ts +3 -0
- package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +19 -0
- package/src/client/components/settings/categories/usage-settings/usage-icons.test.tsx +143 -0
- package/src/client/components/workspace/chat-timeline/MinimapShortcuts.test.ts +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalBanner.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +20 -18
- package/src/client/components/workspace/chat-timeline/chat-input/compact.test.tsx +19 -6
- package/src/client/components/workspace/chat-timeline/index.tsx +7 -16
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.missing.test.ts +100 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +3 -47
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-test-util.ts +62 -0
- package/src/client/components/workspace/diff-panel/HunkStepper.tsx +62 -0
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +29 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +32 -1
- package/src/client/components/workspace/diff-panel/changes.ts +69 -0
- package/src/client/components/workspace/diff-panel/chunks.ts +85 -0
- package/src/client/components/workspace/diff-panel/index.tsx +21 -1
- package/src/client/components/workspace/diff-panel/merge.test.ts +145 -0
- package/src/client/components/workspace/diff-panel/merge.ts +63 -68
- package/src/client/components/workspace/editor/EditorDropOverlay.tsx +6 -1
- package/src/client/components/workspace/editor/FileDocument.tsx +51 -1
- package/src/client/components/workspace/editor/FilePane.tsx +25 -1
- package/src/client/components/workspace/editor/StatusBar.tsx +19 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +29 -5
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +86 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +48 -16
- package/src/client/components/workspace/editor/viewers/bytes.ts +16 -0
- package/src/client/components/workspace/git-panel/index.test.ts +46 -1
- package/src/client/components/workspace/git-panel/index.tsx +11 -38
- package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +66 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +71 -62
- package/src/client/components/workspace/model-dropdown/Section.tsx +31 -14
- package/src/client/components/workspace/model-dropdown/collapsed.ts +72 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +42 -19
- package/src/client/components/workspace/model-dropdown/refresh.test.tsx +260 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +34 -0
- package/src/client/components/workspace/model-dropdown/use-catalog.ts +13 -2
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +19 -3
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +113 -0
- package/src/client/hooks/chat/omp/index.ts +20 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +21 -0
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +16 -1
- package/src/client/hooks/chat/omp/session-sidebar-controller.test.ts +102 -0
- package/src/client/hooks/chat/omp/session-sidebar-controller.ts +21 -1
- package/src/client/hooks/chat/omp/stream.ts +8 -1
- package/src/client/hooks/chat/timeline/index.ts +1 -1
- package/src/client/hooks/chat/timeline/new-chat-open.ts +60 -0
- package/src/client/hooks/editor/blame-settings.ts +67 -0
- package/src/client/hooks/editor/blame.test.ts +272 -0
- package/src/client/hooks/editor/blame.ts +232 -0
- package/src/client/hooks/editor/file-editor-types.ts +23 -0
- package/src/client/hooks/editor/save-file.test.ts +20 -0
- package/src/client/hooks/editor/use-editor-drop.test-util.ts +198 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +70 -175
- package/src/client/hooks/editor/use-editor-drop.ts +19 -36
- package/src/client/hooks/editor/use-file-editor.ts +7 -1
- package/src/client/hooks/settings/providers/actions.ts +90 -194
- package/src/client/hooks/settings/providers/api.ts +7 -1
- package/src/client/hooks/settings/providers/index.ts +171 -59
- package/src/client/hooks/settings/providers/login.test.ts +79 -0
- package/src/client/hooks/settings/providers/login.ts +276 -0
- package/src/client/hooks/settings/providers/messages.ts +28 -0
- package/src/client/hooks/settings/providers/model-actions.ts +178 -0
- package/src/client/hooks/ui/editor-error-toast.ts +47 -0
- package/src/client/hooks/ui/open-file.ts +7 -0
- package/src/client/hooks/ui/toasts.ts +7 -0
- package/src/client/hooks/workspace/file-tabs.ts +4 -1
- package/src/client/hooks/workspace/folder-expansion.test.ts +62 -0
- package/src/client/hooks/workspace/folder-expansion.ts +33 -0
- package/src/client/hooks/workspace/git-action-outcome.ts +86 -0
- package/src/client/hooks/workspace/git-actions.ts +29 -2
- package/src/client/hooks/workspace/plugin-contributions.test.ts +117 -0
- package/src/client/hooks/workspace/plugin-contributions.ts +146 -0
- package/src/client/lib/editor-errors.test.ts +85 -0
- package/src/client/lib/editor-errors.ts +71 -0
- package/src/client/lib/fs/resolve-open.test.ts +125 -0
- package/src/client/lib/fs/resolve-open.ts +90 -0
- package/src/client/lib/git/action-message.test.ts +82 -0
- package/src/client/lib/git/action-message.ts +160 -0
- package/src/client/lib/launch/device-files.test.ts +160 -0
- package/src/client/lib/launch/device-files.ts +197 -0
- package/src/client/lib/native/open-paths.test.ts +140 -0
- package/src/client/lib/native/open-paths.ts +157 -0
- package/src/client/lib/plugins/bootstrap.test.ts +1 -1
- package/src/client/main.tsx +20 -0
- package/src/server/db.server.test.ts +39 -0
- package/src/server/db.server.ts +21 -2
- package/src/server/lib/db/schema.ts +2 -0
- package/src/server/lib/fs/external-roots.test.ts +100 -0
- package/src/server/lib/fs/external-roots.ts +101 -0
- package/src/server/lib/fs/git-actions-branch.ts +15 -2
- package/src/server/lib/fs/git-actions-shared.ts +24 -0
- package/src/server/lib/fs/git-actions-sync.test.ts +18 -7
- package/src/server/lib/fs/git-actions-worktree.ts +5 -1
- package/src/server/lib/fs/git-blame.test.ts +206 -0
- package/src/server/lib/fs/git-blame.ts +189 -0
- package/src/server/lib/fs/root.ts +14 -0
- package/src/server/lib/http/same-origin.ts +28 -7
- package/src/server/lib/models/catalog.server.ts +230 -0
- package/src/server/lib/models/catalog.test.ts +83 -0
- package/src/server/lib/models/credential-origin.server.ts +108 -0
- package/src/server/lib/models/credential-origin.test.ts +132 -0
- package/src/server/lib/models/provider-icon-fetch.ts +115 -0
- package/src/server/lib/models/provider-icon-parse.test.ts +134 -0
- package/src/server/lib/models/provider-icon-parse.ts +139 -0
- package/src/server/lib/models/provider-icon-store.server.ts +118 -0
- package/src/server/lib/models/provider-icon-store.test.ts +107 -0
- package/src/server/lib/models/provider-icon.server.ts +209 -0
- package/src/server/lib/models/provider-items.server.ts +211 -37
- package/src/server/lib/models/provider-items.test.ts +201 -0
- package/src/server/lib/models/provider-registry.server.test.ts +27 -9
- package/src/server/lib/models/provider-registry.server.ts +160 -67
- package/src/server/lib/models/registry.server.test.ts +3 -3
- package/src/server/lib/models/registry.server.ts +8 -0
- package/src/server/lib/omp/config/definitions.test.ts +5 -4
- package/src/server/lib/omp/config/models-config.ts +42 -0
- package/src/server/lib/omp/config/provider-entry.test.ts +205 -0
- package/src/server/lib/omp/config/provider-entry.ts +197 -0
- package/src/server/lib/omp/config/provider-seeds.ts +10 -0
- package/src/server/lib/omp/core/models-json.ts +69 -0
- package/src/server/lib/omp/session/messages.ts +17 -3
- package/src/server/lib/omp/session/sidebar-data.canonical.test.ts +13 -3
- package/src/server/lib/panels/bundled-catalog.server.ts +7 -0
- package/src/server/lib/panels/catalog-offers.server.ts +68 -0
- package/src/server/lib/panels/git-update.server.test.ts +14 -0
- package/src/server/lib/panels/git-update.server.ts +63 -1
- package/src/server/lib/panels/manifest.test.ts +65 -0
- package/src/server/lib/panels/manifest.ts +55 -1
- package/src/server/lib/panels/offers.server.test.ts +191 -0
- package/src/server/lib/panels/offers.server.ts +108 -0
- package/src/server/lib/panels/registry.server.test.ts +35 -1
- package/src/server/lib/panels/registry.server.ts +51 -142
- package/src/server/lib/panels/scan.server.ts +162 -0
- package/src/server/lib/route-adapter.ts +13 -2
- package/src/server/lib/tray/tray.test.ts +2 -1
- package/src/server/lib/usage/providers.server.ts +4 -1
- package/src/server/routes/chat/session.ts +7 -1
- package/src/server/routes/fs/git-blame-loader.test.ts +146 -0
- package/src/server/routes/fs/git.ts +17 -0
- package/src/server/routes/fs/grant.test.ts +135 -0
- package/src/server/routes/fs/grant.ts +79 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.ts +34 -17
- package/src/server/routes/omp/login.ts +41 -14
- package/src/server/routes/omp/routes.test.ts +23 -10
- package/src/server/routes/settings/index.ts +8 -0
- package/src/server/routes/settings/provider-entry.ts +108 -0
- package/src/server/routes/settings/provider-icon.ts +99 -0
- package/src/server/routes/settings/provider-model.ts +4 -1
- package/src/server/routes/settings/provider-refresh.ts +87 -0
- package/src/server/routes/settings/providers.ts +31 -2
- package/src/shared/lib/chat/omp/fold.test.ts +34 -0
- package/src/shared/lib/chat/omp/tool-frames.test.ts +20 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +5 -1
- package/src/shared/lib/chat/omp/tool-results.ts +29 -3
- package/src/shared/lib/chat/tool/wait-facts.ts +4 -0
- package/src/shared/lib/fs/git-blame.test.ts +266 -0
- package/src/shared/lib/fs/git-blame.ts +246 -0
- package/src/shared/lib/git/url.ts +18 -0
- package/src/shared/lib/markdown/sanitize.test.ts +57 -0
- package/src/shared/lib/markdown/sanitize.ts +30 -7
- package/src/shared/lib/models/provider/connection.ts +135 -0
- package/src/shared/lib/models/provider/dialect.test.ts +4 -2
- package/src/shared/lib/models/provider/dialect.ts +76 -6
- package/src/shared/lib/models/provider/models.ts +2 -0
- package/src/shared/lib/models/provider/origin.ts +94 -0
- package/src/shared/lib/models/provider/provider-ui.test.ts +7 -0
- package/src/shared/lib/models/server-cache.ts +8 -3
- package/src/shared/lib/omp/session/messages-map-pending.test.ts +110 -0
- package/src/shared/lib/omp/session/messages-map.ts +34 -2
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +7 -90
- package/src/shared/lib/omp/session/prewarm.test.ts +133 -0
- package/src/shared/lib/omp/session/prewarm.ts +23 -1
- package/src/shared/lib/omp/session/wait.test.ts +28 -0
- package/src/shared/lib/omp/session/wait.ts +38 -3
- package/src/shared/lib/panels/slot-labels.test.ts +61 -0
- package/src/shared/lib/panels/slot-labels.ts +133 -0
- package/src/shared/lib/workspace/panel-ids.ts +11 -0
- package/src/shared/types/fs.ts +6 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/models.ts +12 -0
- package/src/shared/types/panels-registry.ts +277 -0
- package/src/shared/types/panels.ts +46 -213
- package/src/shared/types/settings/provider.ts +58 -0
- package/src/shared/types/settings/usage.ts +10 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-bq6qeayr.css +0 -1
- package/src/client/components/settings/categories/provider-settings/ReconnectModal.tsx +0 -184
|
@@ -42,6 +42,14 @@ export interface NativeProviderInfo {
|
|
|
42
42
|
auth?: string;
|
|
43
43
|
/** Discovery type from the entry's `discovery`, when omp lists its models. */
|
|
44
44
|
discovery?: string;
|
|
45
|
+
/** Extra request headers the entry pins for every call. */
|
|
46
|
+
headers?: Record<string, string>;
|
|
47
|
+
/** `authHeader: true` — send the credential as a raw auth header. */
|
|
48
|
+
authHeader?: boolean;
|
|
49
|
+
/** `transport: pi-native` routes every model through the auth gateway. */
|
|
50
|
+
transport?: 'pi-native';
|
|
51
|
+
/** The entry carries an `apiKey` (the value is never read here). */
|
|
52
|
+
hasApiKey?: boolean;
|
|
45
53
|
/** Model ids registered under this provider in models.yml. */
|
|
46
54
|
modelIds: string[];
|
|
47
55
|
models: NativeModelInfo[];
|
|
@@ -54,6 +62,14 @@ export interface NativeModelInfo {
|
|
|
54
62
|
maxTokens?: number;
|
|
55
63
|
reasoning?: boolean;
|
|
56
64
|
imageInput?: boolean;
|
|
65
|
+
/** `kind` from the entry, when it declares a non-chat one. */
|
|
66
|
+
kind?: string;
|
|
67
|
+
/** `supportsTools` from the entry; absent means omp's default (true). */
|
|
68
|
+
supportsTools?: boolean;
|
|
69
|
+
/** `thinking` block, when the entry declares a reasoning ladder. */
|
|
70
|
+
thinkingMode?: string;
|
|
71
|
+
thinkingEfforts?: string[];
|
|
72
|
+
cost?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number };
|
|
57
73
|
}
|
|
58
74
|
|
|
59
75
|
/**
|
|
@@ -77,12 +93,26 @@ export async function readNativeProviders(): Promise<NativeProviderInfo[]> {
|
|
|
77
93
|
if (typeof value.baseUrl === 'string') info.baseUrl = value.baseUrl;
|
|
78
94
|
if (typeof value.api === 'string') info.api = value.api;
|
|
79
95
|
if (typeof value.auth === 'string') info.auth = value.auth;
|
|
96
|
+
if (typeof value.apiKey === 'string' && value.apiKey.length > 0) info.hasApiKey = true;
|
|
97
|
+
if (value.authHeader === true) info.authHeader = true;
|
|
98
|
+
if (value.transport === 'pi-native') info.transport = 'pi-native';
|
|
99
|
+
if (isRecord(value.headers)) {
|
|
100
|
+
const headers = Object.entries(value.headers).flatMap(([key, header]) => (
|
|
101
|
+
typeof header === 'string' ? [[key, header] as [string, string]] : []
|
|
102
|
+
));
|
|
103
|
+
if (headers.length > 0) info.headers = Object.fromEntries(headers);
|
|
104
|
+
}
|
|
80
105
|
if (isRecord(value.discovery) && typeof value.discovery.type === 'string') {
|
|
81
106
|
info.discovery = value.discovery.type;
|
|
82
107
|
}
|
|
83
108
|
if (Array.isArray(value.models)) {
|
|
84
109
|
info.models = value.models.flatMap((model) => {
|
|
85
110
|
if (!isRecord(model) || typeof model.id !== 'string') return [];
|
|
111
|
+
const thinking = isRecord(model.thinking) ? model.thinking : undefined;
|
|
112
|
+
const efforts = Array.isArray(thinking?.efforts)
|
|
113
|
+
? thinking.efforts.filter((effort): effort is string => typeof effort === 'string')
|
|
114
|
+
: undefined;
|
|
115
|
+
const cost = isRecord(model.cost) ? model.cost : undefined;
|
|
86
116
|
return [{
|
|
87
117
|
id: model.id,
|
|
88
118
|
...(typeof model.name === 'string' ? { name: model.name } : {}),
|
|
@@ -90,6 +120,18 @@ export async function readNativeProviders(): Promise<NativeProviderInfo[]> {
|
|
|
90
120
|
...(typeof model.maxTokens === 'number' ? { maxTokens: model.maxTokens } : {}),
|
|
91
121
|
...(model.reasoning === true ? { reasoning: true } : {}),
|
|
92
122
|
...(Array.isArray(model.input) && model.input.includes('image') ? { imageInput: true } : {}),
|
|
123
|
+
...(typeof model.kind === 'string' ? { kind: model.kind } : {}),
|
|
124
|
+
...(typeof model.supportsTools === 'boolean' ? { supportsTools: model.supportsTools } : {}),
|
|
125
|
+
...(thinking && typeof thinking.mode === 'string' ? { thinkingMode: thinking.mode } : {}),
|
|
126
|
+
...(efforts && efforts.length > 0 ? { thinkingEfforts: efforts } : {}),
|
|
127
|
+
...(cost ? {
|
|
128
|
+
cost: {
|
|
129
|
+
...(typeof cost.input === 'number' ? { input: cost.input } : {}),
|
|
130
|
+
...(typeof cost.output === 'number' ? { output: cost.output } : {}),
|
|
131
|
+
...(typeof cost.cacheRead === 'number' ? { cacheRead: cost.cacheRead } : {}),
|
|
132
|
+
...(typeof cost.cacheWrite === 'number' ? { cacheWrite: cost.cacheWrite } : {}),
|
|
133
|
+
},
|
|
134
|
+
} : {}),
|
|
93
135
|
}];
|
|
94
136
|
});
|
|
95
137
|
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The provider entry writer — the one path that can change an existing
|
|
8
|
+
* `models.yml` provider.
|
|
9
|
+
*
|
|
10
|
+
* Every case here is a bug the panel shipped: a rotated key that never reached
|
|
11
|
+
* omp, a masked placeholder persisted as a credential, an empty input written as
|
|
12
|
+
* an empty string omp rejects, and a cleared dialect left on an entry that still
|
|
13
|
+
* lists models.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync, mkdirSync } from 'fs';
|
|
18
|
+
import { tmpdir } from 'os';
|
|
19
|
+
import { join } from 'path';
|
|
20
|
+
import { updateOmpProviderEntry } from '@/server/lib/omp/config/provider-entry';
|
|
21
|
+
|
|
22
|
+
let agentDir: string;
|
|
23
|
+
let previousAgentDir: string | undefined;
|
|
24
|
+
|
|
25
|
+
function modelsPath(): string {
|
|
26
|
+
return join(agentDir, 'models.yml');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function read(): string {
|
|
30
|
+
return readFileSync(modelsPath(), 'utf8');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function write(content: string): void {
|
|
34
|
+
writeFileSync(modelsPath(), content);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
agentDir = mkdtempSync(join(tmpdir(), 'kabmo-provider-entry-'));
|
|
39
|
+
mkdirSync(join(agentDir, 'sessions'), { recursive: true });
|
|
40
|
+
previousAgentDir = Bun.env.PI_CODING_AGENT_DIR;
|
|
41
|
+
Bun.env.PI_CODING_AGENT_DIR = agentDir;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
if (previousAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
|
|
46
|
+
else Bun.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
|
47
|
+
rmSync(agentDir, { recursive: true, force: true });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const ENTRY = `providers:
|
|
51
|
+
gateway:
|
|
52
|
+
baseUrl: https://old.example.com/v1
|
|
53
|
+
apiKey: sk-old
|
|
54
|
+
api: openai-completions
|
|
55
|
+
models:
|
|
56
|
+
- id: gpt-x
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
describe('updateOmpProviderEntry', () => {
|
|
60
|
+
test('replaces the endpoint and the key of an existing entry', async () => {
|
|
61
|
+
// The whole point: `upsertOmpProviderModels` is add-only, so this write is
|
|
62
|
+
// the only way a rotated credential reaches the file omp reads.
|
|
63
|
+
write(ENTRY);
|
|
64
|
+
|
|
65
|
+
const result = await updateOmpProviderEntry('gateway', {
|
|
66
|
+
baseUrl: 'https://new.example.com/v1',
|
|
67
|
+
apiKey: 'sk-new',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(result.written).toBe(true);
|
|
71
|
+
expect(result.changed).toEqual(['baseUrl', 'apiKey']);
|
|
72
|
+
const after = read();
|
|
73
|
+
expect(after).toContain('https://new.example.com/v1');
|
|
74
|
+
expect(after).toContain('sk-new');
|
|
75
|
+
expect(after).not.toContain('sk-old');
|
|
76
|
+
// The model list is not this writer's business.
|
|
77
|
+
expect(after).toContain('id: gpt-x');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('refuses a masked placeholder instead of overwriting a working key', async () => {
|
|
81
|
+
write(ENTRY);
|
|
82
|
+
|
|
83
|
+
const result = await updateOmpProviderEntry('gateway', { apiKey: 'sk-••••••••' });
|
|
84
|
+
|
|
85
|
+
expect(result.written).toBe(false);
|
|
86
|
+
expect(result.reason).toContain('masked placeholder');
|
|
87
|
+
expect(read()).toContain('sk-old');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('an empty string REMOVES the field rather than writing an empty one', async () => {
|
|
91
|
+
// omp rejects `baseUrl: ""` outright, and a cleared input is how a user says
|
|
92
|
+
// "no value". A keyless entry is the shape where removing the endpoint is
|
|
93
|
+
// valid — a models-carrying one legitimately refuses (next test).
|
|
94
|
+
write(`providers:
|
|
95
|
+
local:
|
|
96
|
+
baseUrl: http://localhost:1234/v1
|
|
97
|
+
auth: none
|
|
98
|
+
api: openai-completions
|
|
99
|
+
`);
|
|
100
|
+
|
|
101
|
+
const result = await updateOmpProviderEntry('local', { baseUrl: '' });
|
|
102
|
+
|
|
103
|
+
expect(result.written).toBe(true);
|
|
104
|
+
expect(result.changed).toEqual(['baseUrl']);
|
|
105
|
+
expect(read()).not.toContain('baseUrl');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('a removal that would break the entry is refused, not written', async () => {
|
|
109
|
+
// Removing the key from a models-carrying entry leaves omp with a provider
|
|
110
|
+
// it rejects — and one rejected entry disables every custom provider.
|
|
111
|
+
write(ENTRY);
|
|
112
|
+
|
|
113
|
+
await expect(updateOmpProviderEntry('gateway', { apiKey: '' }))
|
|
114
|
+
.rejects.toThrow(/apiKey.*required/);
|
|
115
|
+
expect(read()).toContain('sk-old');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('refuses when the provider has no entry — creating one is another path', async () => {
|
|
119
|
+
write(ENTRY);
|
|
120
|
+
|
|
121
|
+
const result = await updateOmpProviderEntry('missing', { baseUrl: 'https://x/v1' });
|
|
122
|
+
|
|
123
|
+
expect(result.written).toBe(false);
|
|
124
|
+
expect(result.reason).toContain('no models.yml entry');
|
|
125
|
+
expect(read()).not.toContain('missing');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('refuses to clear the dialect of an entry that still lists models', async () => {
|
|
129
|
+
// A models-carrying entry without `api` makes omp reject the whole file.
|
|
130
|
+
write(ENTRY);
|
|
131
|
+
|
|
132
|
+
await expect(updateOmpProviderEntry('gateway', { api: null })).rejects.toThrow(/needs an "api"/);
|
|
133
|
+
expect(read()).toContain('api: openai-completions');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('keeps comments and unrelated keys', async () => {
|
|
137
|
+
write(`# my gateways
|
|
138
|
+
providers:
|
|
139
|
+
gateway:
|
|
140
|
+
# rotated monthly
|
|
141
|
+
baseUrl: https://old.example.com/v1
|
|
142
|
+
apiKey: sk-old
|
|
143
|
+
api: openai-completions
|
|
144
|
+
`);
|
|
145
|
+
|
|
146
|
+
await updateOmpProviderEntry('gateway', { apiKey: 'sk-new' });
|
|
147
|
+
|
|
148
|
+
const after = read();
|
|
149
|
+
expect(after).toContain('# my gateways');
|
|
150
|
+
expect(after).toContain('# rotated monthly');
|
|
151
|
+
expect(after).toContain('sk-new');
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('writes a discovery block with only the knobs its type accepts', async () => {
|
|
155
|
+
// `injectV1` outside openai-models-list is refused by omp, and one refused
|
|
156
|
+
// field disables every custom provider in the file.
|
|
157
|
+
write(`providers:
|
|
158
|
+
local:
|
|
159
|
+
baseUrl: http://localhost:1234/v1
|
|
160
|
+
api: openai-completions
|
|
161
|
+
`);
|
|
162
|
+
|
|
163
|
+
await updateOmpProviderEntry('local', {
|
|
164
|
+
discovery: { type: 'lm-studio', injectV1: true, advertisedReasoning: true, timeoutMs: 5000 },
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const after = read();
|
|
168
|
+
expect(after).toContain('type: lm-studio');
|
|
169
|
+
expect(after).toContain('advertisedReasoning: true');
|
|
170
|
+
expect(after).toContain('timeoutMs: 5000');
|
|
171
|
+
expect(after).not.toContain('injectV1');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('writes and then clears pinned request headers', async () => {
|
|
175
|
+
write(ENTRY);
|
|
176
|
+
|
|
177
|
+
const written = await updateOmpProviderEntry('gateway', {
|
|
178
|
+
headers: { 'X-Route': 'team-a', 'X-Version': '2' },
|
|
179
|
+
});
|
|
180
|
+
expect(written.changed).toEqual(['headers']);
|
|
181
|
+
expect(read()).toContain('X-Route: team-a');
|
|
182
|
+
|
|
183
|
+
const cleared = await updateOmpProviderEntry('gateway', { headers: null });
|
|
184
|
+
expect(cleared.changed).toEqual(['headers']);
|
|
185
|
+
expect(read()).not.toContain('X-Route');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('reports "nothing to change" instead of claiming a write', async () => {
|
|
189
|
+
write(ENTRY);
|
|
190
|
+
|
|
191
|
+
const result = await updateOmpProviderEntry('gateway', {});
|
|
192
|
+
|
|
193
|
+
expect(result.written).toBe(false);
|
|
194
|
+
expect(result.reason).toBe('nothing to change');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('drops `auth: apiKey` rather than pinning omp’s default', async () => {
|
|
198
|
+
write(ENTRY);
|
|
199
|
+
|
|
200
|
+
const result = await updateOmpProviderEntry('gateway', { auth: 'apiKey' });
|
|
201
|
+
|
|
202
|
+
expect(result.written).toBe(false);
|
|
203
|
+
expect(read()).not.toContain('auth:');
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Editing an EXISTING `models.yml` provider entry.
|
|
8
|
+
*
|
|
9
|
+
* `upsertOmpProviderModels` is add-only by design: a field the entry already
|
|
10
|
+
* carries belongs to the user, and rewriting it would discard a credential or
|
|
11
|
+
* endpoint they pinned. That rule is right for a model listing and wrong for
|
|
12
|
+
* this panel's "edit connection": rotating a key, moving an endpoint, or
|
|
13
|
+
* switching the dialect were all writes the UI offered and the writer silently
|
|
14
|
+
* dropped — the new value went into Kabmo's SQLite overlay, the merge discarded
|
|
15
|
+
* it because models.yml owned the slug, and the panel reported "connected"
|
|
16
|
+
* while omp kept using the old credential.
|
|
17
|
+
*
|
|
18
|
+
* So the write is explicit here: a field present in the patch is SET, a field
|
|
19
|
+
* explicitly null is REMOVED, and a field absent is left alone. The document
|
|
20
|
+
* model keeps comments and unrelated keys, and the result is validated against
|
|
21
|
+
* omp's own rules before it reaches disk (one violation disables every custom
|
|
22
|
+
* provider in the file).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { isMap, type Document, type YAMLMap } from 'yaml';
|
|
26
|
+
import { getModelsConfigPath } from '@/server/lib/omp/config/models-config';
|
|
27
|
+
import { withOmpYamlDocument, OmpConfigError } from '@/server/lib/omp/config/document';
|
|
28
|
+
import { validateModelsDocument } from '@/server/lib/omp/config/models-validation';
|
|
29
|
+
import { isMaskedApiKey } from '@/shared/lib/models/provider/dialect';
|
|
30
|
+
import type {
|
|
31
|
+
OmpProviderApi,
|
|
32
|
+
ProviderAuthMode,
|
|
33
|
+
ProviderDiscoveryType,
|
|
34
|
+
} from '@/shared/types/settings/provider';
|
|
35
|
+
|
|
36
|
+
/** omp's `ProviderDiscoverySchema`: a type plus its own optional knobs. */
|
|
37
|
+
export interface ProviderDiscoveryConfig {
|
|
38
|
+
type: ProviderDiscoveryType;
|
|
39
|
+
/** Probe timeout; must be a positive finite number of milliseconds. */
|
|
40
|
+
timeoutMs?: number;
|
|
41
|
+
/** `openai-models-list` only: skip the forced `/v1` prefix. */
|
|
42
|
+
injectV1?: boolean;
|
|
43
|
+
/** `/v1/models`-reading types only: trust the advertised reasoning ladder. */
|
|
44
|
+
advertisedReasoning?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface OmpProviderEntryPatch {
|
|
48
|
+
baseUrl?: string | null;
|
|
49
|
+
apiKey?: string | null;
|
|
50
|
+
api?: OmpProviderApi | null;
|
|
51
|
+
auth?: ProviderAuthMode | null;
|
|
52
|
+
discovery?: ProviderDiscoveryConfig | null;
|
|
53
|
+
headers?: Record<string, string> | null;
|
|
54
|
+
authHeader?: boolean | null;
|
|
55
|
+
transport?: 'pi-native' | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The discovery block as omp's schema wants it: the type plus only the knobs
|
|
60
|
+
* that type accepts.
|
|
61
|
+
*
|
|
62
|
+
* omp REJECTS `injectV1` outside `openai-models-list` and `advertisedReasoning`
|
|
63
|
+
* outside the three types that read `/v1/models` rows — and a rejected field
|
|
64
|
+
* disables every custom provider in the file, so the narrowing happens here
|
|
65
|
+
* rather than trusting the caller's form state.
|
|
66
|
+
*/
|
|
67
|
+
function discoveryNode(doc: Document, discovery: ProviderDiscoveryConfig): unknown {
|
|
68
|
+
const node: Record<string, unknown> = { type: discovery.type };
|
|
69
|
+
if (discovery.type === 'openai-models-list' && discovery.injectV1 !== undefined) {
|
|
70
|
+
node.injectV1 = discovery.injectV1;
|
|
71
|
+
}
|
|
72
|
+
if (
|
|
73
|
+
(discovery.type === 'openai-models-list' || discovery.type === 'lm-studio' || discovery.type === 'proxy')
|
|
74
|
+
&& discovery.advertisedReasoning !== undefined
|
|
75
|
+
) {
|
|
76
|
+
node.advertisedReasoning = discovery.advertisedReasoning;
|
|
77
|
+
}
|
|
78
|
+
if (
|
|
79
|
+
discovery.timeoutMs !== undefined
|
|
80
|
+
&& Number.isFinite(discovery.timeoutMs)
|
|
81
|
+
&& discovery.timeoutMs > 0
|
|
82
|
+
) {
|
|
83
|
+
node.timeoutMs = discovery.timeoutMs;
|
|
84
|
+
}
|
|
85
|
+
return doc.createNode(node);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface OmpProviderEntryWriteResult {
|
|
89
|
+
written: boolean;
|
|
90
|
+
/** Fields actually changed on disk, in the order they were applied. */
|
|
91
|
+
changed: string[];
|
|
92
|
+
reason?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Apply `patch` to one provider entry. Refuses when the entry does not exist —
|
|
97
|
+
* creating one is the add-provider path, and a silent create here would write a
|
|
98
|
+
* provider the caller never described (no models, no dialect).
|
|
99
|
+
*/
|
|
100
|
+
export async function updateOmpProviderEntry(
|
|
101
|
+
slug: string,
|
|
102
|
+
patch: OmpProviderEntryPatch,
|
|
103
|
+
): Promise<OmpProviderEntryWriteResult> {
|
|
104
|
+
const path = await getModelsConfigPath();
|
|
105
|
+
return withOmpYamlDocument<OmpProviderEntryWriteResult>(path, (doc) => {
|
|
106
|
+
const providersNode = doc.get('providers');
|
|
107
|
+
if (!isMap(providersNode)) {
|
|
108
|
+
return {
|
|
109
|
+
result: { written: false, changed: [], reason: 'models.yml has no providers mapping' },
|
|
110
|
+
changed: false,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// Captured BEFORE any edit: the validation below refuses only problems
|
|
114
|
+
// this patch INTRODUCED, so a pre-existing violation elsewhere in the file
|
|
115
|
+
// cannot make an unrelated provider uneditable.
|
|
116
|
+
const original = doc.toJS() as Record<string, unknown> | null;
|
|
117
|
+
const entry = (providersNode as YAMLMap).get(slug);
|
|
118
|
+
if (!isMap(entry)) {
|
|
119
|
+
return {
|
|
120
|
+
result: {
|
|
121
|
+
written: false,
|
|
122
|
+
changed: [],
|
|
123
|
+
reason: `"${slug}" has no models.yml entry — add the provider first`,
|
|
124
|
+
},
|
|
125
|
+
changed: false,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// A masked placeholder is what the UI echoes for a stored key. Writing it
|
|
130
|
+
// would replace a working credential with a string that authenticates
|
|
131
|
+
// nothing, which is worse than leaving the old one in place.
|
|
132
|
+
if (typeof patch.apiKey === 'string' && isMaskedApiKey(patch.apiKey)) {
|
|
133
|
+
return {
|
|
134
|
+
result: { written: false, changed: [], reason: 'the supplied API key is a masked placeholder, not a credential' },
|
|
135
|
+
changed: false,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const applied: string[] = [];
|
|
140
|
+
const apply = (key: string, value: unknown, encoded: unknown): void => {
|
|
141
|
+
if (value === undefined) return;
|
|
142
|
+
if (value === null || (typeof value === 'string' && value.trim().length === 0)) {
|
|
143
|
+
if (entry.has(key)) {
|
|
144
|
+
entry.delete(key);
|
|
145
|
+
applied.push(key);
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
entry.set(key, encoded);
|
|
150
|
+
applied.push(key);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
apply('baseUrl', patch.baseUrl, typeof patch.baseUrl === 'string' ? patch.baseUrl.trim() : patch.baseUrl);
|
|
154
|
+
apply('apiKey', patch.apiKey, typeof patch.apiKey === 'string' ? patch.apiKey.trim() : patch.apiKey);
|
|
155
|
+
apply('api', patch.api, patch.api);
|
|
156
|
+
// `auth: apiKey` is omp's DEFAULT, so writing it would pin a value the file
|
|
157
|
+
// does not need; deleting the key expresses the same thing.
|
|
158
|
+
apply('auth', patch.auth === 'apiKey' ? null : patch.auth, patch.auth);
|
|
159
|
+
apply(
|
|
160
|
+
'discovery',
|
|
161
|
+
patch.discovery,
|
|
162
|
+
patch.discovery ? discoveryNode(doc, patch.discovery) : patch.discovery,
|
|
163
|
+
);
|
|
164
|
+
apply(
|
|
165
|
+
'headers',
|
|
166
|
+
patch.headers,
|
|
167
|
+
patch.headers ? doc.createNode(patch.headers) : patch.headers,
|
|
168
|
+
);
|
|
169
|
+
// `false` is omp's default for both of these, so only `true` is worth a key.
|
|
170
|
+
apply('authHeader', patch.authHeader === false ? null : patch.authHeader, patch.authHeader);
|
|
171
|
+
apply('transport', patch.transport, patch.transport);
|
|
172
|
+
|
|
173
|
+
if (applied.length === 0) {
|
|
174
|
+
return { result: { written: false, changed: [], reason: 'nothing to change' }, changed: false };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// A models-carrying entry needs a dialect at provider or model level; a
|
|
178
|
+
// patch that cleared it would disable the provider, so refuse instead of
|
|
179
|
+
// writing a file omp rejects.
|
|
180
|
+
const models = entry.get('models');
|
|
181
|
+
if (models !== undefined && !entry.has('api')) {
|
|
182
|
+
throw new OmpConfigError(
|
|
183
|
+
`${path}: provider "${slug}" still lists models and needs an "api" — set the wire dialect before saving.`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const errorsAfter = validateModelsDocument(doc.toJS() as Record<string, unknown>);
|
|
188
|
+
const preExisting = new Set(validateModelsDocument(original));
|
|
189
|
+
const introduced = errorsAfter.filter((error) => !preExisting.has(error));
|
|
190
|
+
if (introduced.length > 0) {
|
|
191
|
+
throw new OmpConfigError(`Refusing to write an invalid models.yml: ${introduced[0]}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return { result: { written: true, changed: applied }, changed: true };
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
@@ -22,6 +22,12 @@ import type { ProviderThinkingEffort } from '@/shared/lib/models/provider/dialec
|
|
|
22
22
|
export interface OmpProviderModelSeed {
|
|
23
23
|
id: string;
|
|
24
24
|
name?: string;
|
|
25
|
+
/**
|
|
26
|
+
* omp's `ModelKind`. Absent means chat, which is what omp assumes — so only a
|
|
27
|
+
* non-chat kind is written, and an embedding/image/judge model stops looking
|
|
28
|
+
* like a chat model that behaves oddly.
|
|
29
|
+
*/
|
|
30
|
+
kind?: string;
|
|
25
31
|
reasoning?: boolean;
|
|
26
32
|
imageInput?: boolean;
|
|
27
33
|
contextWindow?: number;
|
|
@@ -53,6 +59,7 @@ export function toModelEntry(model: OmpProviderModelSeed): Record<string, unknow
|
|
|
53
59
|
return sanitizeModelEntry({
|
|
54
60
|
id: model.id,
|
|
55
61
|
...(model.name ? { name: model.name } : {}),
|
|
62
|
+
...(model.kind && model.kind !== 'chat' ? { kind: model.kind } : {}),
|
|
56
63
|
...(model.reasoning !== undefined ? { reasoning: model.reasoning } : {}),
|
|
57
64
|
...(efforts ? { thinking: { mode: 'effort', efforts } } : {}),
|
|
58
65
|
...(model.imageInput ? { input: ['text', 'image'] } : { input: ['text'] }),
|
|
@@ -175,6 +182,8 @@ export function prunableIds(
|
|
|
175
182
|
export interface ManualModelInput {
|
|
176
183
|
id: string;
|
|
177
184
|
name?: string;
|
|
185
|
+
/** omp's `ModelKind`; `chat` (the default) is not written. */
|
|
186
|
+
kind?: string;
|
|
178
187
|
contextWindow?: number;
|
|
179
188
|
maxTokens?: number;
|
|
180
189
|
reasoning?: boolean;
|
|
@@ -203,6 +212,7 @@ export function manualModelSeed(input: ManualModelInput): OmpProviderModelSeed {
|
|
|
203
212
|
return {
|
|
204
213
|
id: input.id.trim(),
|
|
205
214
|
...(input.name?.trim() ? { name: input.name.trim() } : {}),
|
|
215
|
+
...(input.kind && input.kind !== 'chat' ? { kind: input.kind } : {}),
|
|
206
216
|
...(input.reasoning ? { reasoning: true } : {}),
|
|
207
217
|
...(efforts ? { efforts } : {}),
|
|
208
218
|
...(input.imageInput ? { imageInput: true } : {}),
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `omp models --json …` — the CLI's own model listing, as raw rows.
|
|
8
|
+
*
|
|
9
|
+
* Two settings surfaces need it and for the same reason: the RPC's
|
|
10
|
+
* `get_available_models` answers CHAT models only (`modelRegistry.getAvailable()`
|
|
11
|
+
* defaults to kind `chat`), so the role dropdowns and the provider panel both
|
|
12
|
+
* have to ask the CLI to see an embedding, image, judge or rerank model at all.
|
|
13
|
+
*
|
|
14
|
+
* Only the spawn and the parse live here. Each caller caches its own projection
|
|
15
|
+
* — the rows are 32 MB at the ceiling and the two shapes are different — and
|
|
16
|
+
* both are dropped by the same `invalidateModelsCaches` signal.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { childEnv } from '@/server/lib/fs/child-env';
|
|
20
|
+
import { resolveOmpBin } from '@/server/lib/omp/core/cli';
|
|
21
|
+
|
|
22
|
+
const LIST_TIMEOUT_MS = 30_000;
|
|
23
|
+
const MAX_BUFFER = 32 * 1024 * 1024;
|
|
24
|
+
|
|
25
|
+
/** A raw row from the listing. Every field is narrowed by the caller. */
|
|
26
|
+
export type OmpModelsRow = Record<string, unknown>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Run `omp models --json <extra args>` and return its rows.
|
|
30
|
+
*
|
|
31
|
+
* `refresh` forces the online catalog re-fetch (`omp models refresh`), which is
|
|
32
|
+
* the only way to ask omp to re-discover a provider: the RPC has no
|
|
33
|
+
* provider-scoped refresh and the CLI's plain `ls` serves the cache.
|
|
34
|
+
* Throws with omp's own first line so a caller can report it verbatim.
|
|
35
|
+
*/
|
|
36
|
+
export async function readOmpModelsJson(
|
|
37
|
+
options: { refresh?: boolean; kind?: string } = {},
|
|
38
|
+
): Promise<OmpModelsRow[]> {
|
|
39
|
+
const bin = resolveOmpBin();
|
|
40
|
+
if (!bin) throw new Error('omp binary not found — install omp to read the model catalog');
|
|
41
|
+
const args = ['models', ...(options.refresh ? ['refresh'] : []), '--json', '--kind', options.kind ?? 'all'];
|
|
42
|
+
const proc = Bun.spawn({
|
|
43
|
+
env: childEnv(),
|
|
44
|
+
cmd: [bin, ...args],
|
|
45
|
+
stdout: 'pipe',
|
|
46
|
+
stderr: 'pipe',
|
|
47
|
+
timeout: LIST_TIMEOUT_MS,
|
|
48
|
+
maxBuffer: MAX_BUFFER,
|
|
49
|
+
windowsHide: true,
|
|
50
|
+
});
|
|
51
|
+
const [stdout, stderr] = await Promise.all([
|
|
52
|
+
new Response(proc.stdout).text(),
|
|
53
|
+
new Response(proc.stderr).text(),
|
|
54
|
+
]);
|
|
55
|
+
const exitCode = await proc.exited;
|
|
56
|
+
if (exitCode !== 0) {
|
|
57
|
+
const line = (stderr.trim() || stdout.trim()).split('\n').map((row) => row.trim()).find(Boolean);
|
|
58
|
+
throw new Error(line ? line.replace(/^[^\w@/]*/, '') : `omp models exited with code ${exitCode}`);
|
|
59
|
+
}
|
|
60
|
+
let parsed: unknown;
|
|
61
|
+
try {
|
|
62
|
+
parsed = JSON.parse(stdout);
|
|
63
|
+
} catch {
|
|
64
|
+
throw new Error('omp models returned unexpected JSON');
|
|
65
|
+
}
|
|
66
|
+
const rows = typeof parsed === 'object' && parsed !== null && 'models' in parsed ? parsed.models : undefined;
|
|
67
|
+
if (!Array.isArray(rows)) throw new Error('omp models returned no model list');
|
|
68
|
+
return rows.filter((row): row is OmpModelsRow => typeof row === 'object' && row !== null);
|
|
69
|
+
}
|
|
@@ -61,8 +61,17 @@ function skillUserMessageFromRecord(record: Record<string, unknown>): ChatMessag
|
|
|
61
61
|
* response is a faithful projection of the JSONL: nothing here reorders rows,
|
|
62
62
|
* and no display-side reordering is applied anywhere either (a notice row
|
|
63
63
|
* renders exactly where omp wrote it).
|
|
64
|
+
*
|
|
65
|
+
* `liveRun` says whether a run for this session is in flight RIGHT NOW. It is
|
|
66
|
+
* the only thing that can tell a call still blocking (whose result omp has not
|
|
67
|
+
* written yet) from one whose process died before writing it — the two
|
|
68
|
+
* transcripts are identical. Only the first is `running`; the second keeps the
|
|
69
|
+
* settled shape, because a crash must not leave a spinner in scrollback.
|
|
64
70
|
*/
|
|
65
|
-
export async function loadSessionMessages(
|
|
71
|
+
export async function loadSessionMessages(
|
|
72
|
+
filePath: string,
|
|
73
|
+
options: { liveRun?: boolean } = {},
|
|
74
|
+
): Promise<ChatMessageData[]> {
|
|
66
75
|
try {
|
|
67
76
|
const file = Bun.file(filePath);
|
|
68
77
|
if ((await file.stat()).size > MAX_SESSION_LOAD_BYTES) return [];
|
|
@@ -116,14 +125,19 @@ export async function loadSessionMessages(filePath: string): Promise<ChatMessage
|
|
|
116
125
|
mapped.toolCalls = mapped.toolCalls.map((call) => {
|
|
117
126
|
const collected = state.outputsByCall.get(call.id);
|
|
118
127
|
const images = call.images ?? collected?.images;
|
|
128
|
+
// A call with no result entry yet is only RUNNING when the run is
|
|
129
|
+
// actually live (see `liveRun`); its empty output is "not written yet"
|
|
130
|
+
// rather than an answer. Reporting it as a settled success drew a
|
|
131
|
+
// blocking `wait` as a finished call with nothing in it.
|
|
132
|
+
const pending = collected?.pending === true && options.liveRun === true;
|
|
119
133
|
return {
|
|
120
134
|
...call,
|
|
121
|
-
output: call.output || collected?.output || undefined,
|
|
135
|
+
output: pending ? undefined : call.output || collected?.output || undefined,
|
|
122
136
|
details: (call.details || collected?.details || undefined) as Record<string, any> | undefined,
|
|
123
137
|
...(collected?.durationMs !== undefined ? { durationMs: collected.durationMs } : {}),
|
|
124
138
|
...(collected?.startedAt !== undefined ? { startedAt: collected.startedAt } : {}),
|
|
125
139
|
...(images && images.length > 0 ? { images } : {}),
|
|
126
|
-
status: collected?.isError ? 'error' : call.status,
|
|
140
|
+
status: pending ? 'running' : collected?.isError ? 'error' : call.status,
|
|
127
141
|
};
|
|
128
142
|
});
|
|
129
143
|
}
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
|
24
|
+
import { isWindows, testPosix } from '@/test-support/platform';
|
|
24
25
|
import fs from 'node:fs';
|
|
25
26
|
import { tmpdir } from 'node:os';
|
|
26
27
|
import { join } from 'node:path';
|
|
@@ -73,7 +74,7 @@ beforeAll(async () => {
|
|
|
73
74
|
realProject = join(root, 'real-project');
|
|
74
75
|
await fs.promises.mkdir(realProject, { recursive: true });
|
|
75
76
|
linkedProject = join(root, 'linked-project');
|
|
76
|
-
await fs.promises.symlink(realProject, linkedProject, 'dir');
|
|
77
|
+
if (!isWindows) await fs.promises.symlink(realProject, linkedProject, 'dir');
|
|
77
78
|
|
|
78
79
|
Bun.env.PI_CODING_AGENT_DIR = agent;
|
|
79
80
|
// XDG would redirect the sessions dir to $XDG_DATA_HOME/omp when it exists.
|
|
@@ -134,7 +135,16 @@ async function registerFolder(projectPath: string): Promise<number> {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
describe('sidebar folders resolve sessions through a canonical path', () => {
|
|
137
|
-
|
|
138
|
+
// The two cases below need the SYMLINK fixture, which is why they are
|
|
139
|
+
// POSIX-only: `symlinkSync` wants a privilege a default Windows runner does
|
|
140
|
+
// not have, and the one run that did create it resolved the canonical bucket
|
|
141
|
+
// to nothing and reported the fixture's own limitation as this suite's
|
|
142
|
+
// failure (`canonical-hit` expected, `[]` received, 36s). The claim itself is
|
|
143
|
+
// a POSIX fact — macOS `/var` → `/private/var` is what put every temp-dir
|
|
144
|
+
// workspace in a folder that listed zero sessions — so it is pinned where it
|
|
145
|
+
// can be measured. The real-spelling case below stays portable, so the
|
|
146
|
+
// Windows leg still covers the bucketing.
|
|
147
|
+
testPosix('a folder registered under a symlinked spelling lists the sessions that ran in its target', async () => {
|
|
138
148
|
// The session's cwd is the REAL directory; the folder names the symlink.
|
|
139
149
|
// Without the canonical bucket key this is an empty folder.
|
|
140
150
|
await writeSession('canonical-hit', realProject);
|
|
@@ -159,7 +169,7 @@ describe('sidebar folders resolve sessions through a canonical path', () => {
|
|
|
159
169
|
expect(folder?.sessions.map((session) => session.id)).toEqual(['canonical-plain']);
|
|
160
170
|
});
|
|
161
171
|
|
|
162
|
-
|
|
172
|
+
testPosix('a session in an unrelated directory stays out of the folder', async () => {
|
|
163
173
|
const other = join(root, 'other-project');
|
|
164
174
|
await fs.promises.mkdir(other, { recursive: true });
|
|
165
175
|
await writeSession('canonical-elsewhere', other);
|