@bitkyc08/opencodex 2.91.0 → 2.93.0-preview.20261027
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/bin/ocx.mjs +47 -8
- package/gui/dist/assets/App-CJZoq-uF.js +58 -0
- package/gui/dist/assets/{Tray-BuLy7hL1.js → Tray-BWQPcgZn.js} +1 -1
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/index-Xfct8owH.js +94 -0
- package/gui/dist/assets/quota-summary-DxToX1rV.js +1 -0
- package/gui/dist/index.html +2 -2
- package/gui/dist/provider-icons/workbuddy-color.svg +29 -0
- package/package.json +8 -7
- package/src/adapters/anthropic.ts +28 -5
- package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
- package/src/adapters/coding-agent/profile.ts +54 -16
- package/src/adapters/coding-agent/turn.ts +30 -2
- package/src/adapters/command-code.ts +114 -7
- package/src/adapters/cursor/native-exec-fs.ts +11 -9
- package/src/adapters/devin/live-models.ts +4 -0
- package/src/adapters/google-vertex-endpoint.ts +9 -1
- package/src/adapters/google-vertex-key-project.ts +223 -0
- package/src/adapters/google-wire-compiler.ts +1 -2
- package/src/adapters/google.ts +13 -3
- package/src/adapters/kiro/reasoning.ts +2 -0
- package/src/adapters/kiro-refusal.ts +6 -1
- package/src/adapters/kiro-wire.ts +1 -1
- package/src/adapters/openai-chat/messages.ts +8 -2
- package/src/adapters/openai-chat/passthrough.ts +35 -14
- package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
- package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
- package/src/adapters/openai-chat/required-tool-result.ts +64 -0
- package/src/adapters/openai-chat/tool-name-registry.ts +3 -1
- package/src/adapters/openai-chat.ts +9 -10
- package/src/adapters/openai-responses/passthrough.ts +7 -4
- package/src/adapters/openai-responses/reasoning.ts +13 -0
- package/src/adapters/openai-responses/request-strips.ts +60 -0
- package/src/adapters/qoder/adapter.ts +129 -8
- package/src/adapters/qoder/scaffold-guard.ts +5 -0
- package/src/adapters/reasoning-controls.ts +16 -0
- package/src/adapters/registry.ts +5 -0
- package/src/adapters/tool-call-id.ts +1 -3
- package/src/adapters/workbuddy-schema.ts +61 -0
- package/src/adapters/workbuddy.ts +68 -0
- package/src/bridge/errors.ts +27 -0
- package/src/bridge/response-json.ts +1 -1
- package/src/bridge/sse.ts +1 -1
- package/src/bridge.ts +1 -1
- package/src/chat/inbound.ts +4 -1
- package/src/chat/outbound.ts +20 -6
- package/src/chat/reasoning-details.ts +28 -5
- package/src/claude/desktop-first-party.ts +54 -4
- package/src/claude/desktop-picker.ts +11 -8
- package/src/claude/first-party-settings.ts +3 -1
- package/src/claude/inbound.ts +2 -1
- package/src/claude/intercept/local-ca.ts +2 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
- package/src/claude/intercept/picker-ca-startup.ts +3 -1
- package/src/claude/intercept/picker-models.ts +6 -3
- package/src/claude/intercept/picker-runtime.ts +3 -2
- package/src/claude/intercept/runtime.ts +6 -3
- package/src/claude/model-info.ts +31 -8
- package/src/cli/account-api.ts +11 -0
- package/src/cli/capabilities-agents-routing.ts +3 -3
- package/src/cli/capabilities-base.ts +7 -1
- package/src/cli/capabilities-observe-system.ts +10 -0
- package/src/cli/claude-desktop.ts +9 -8
- package/src/cli/claude.ts +3 -2
- package/src/cli/codex-cli-update.ts +8 -0
- package/src/cli/codex-shim-autorestore.ts +9 -0
- package/src/cli/combo-result.ts +13 -0
- package/src/cli/combo-stats.ts +3 -0
- package/src/cli/combo.ts +83 -41
- package/src/cli/cross-home-owner.ts +13 -1
- package/src/cli/dispatch.ts +25 -6
- package/src/cli/ensure-desired-integrations.ts +8 -6
- package/src/cli/export-command.ts +4 -1
- package/src/cli/help.ts +2 -1
- package/src/cli/index.ts +45 -45
- package/src/cli/integration-plan-dto.ts +4 -0
- package/src/cli/launcher-context.ts +49 -2
- package/src/cli/link.ts +45 -32
- package/src/cli/opencode.ts +20 -9
- package/src/cli/provider.ts +2 -1
- package/src/cli/registry.ts +6 -4
- package/src/cli/root.ts +9 -0
- package/src/cli/status.ts +59 -1
- package/src/cli/stop-restore.ts +113 -0
- package/src/cli/sync-expectation.ts +60 -0
- package/src/cli/uninstall-integrations.ts +41 -7
- package/src/cli/usage-compare.ts +68 -12
- package/src/client/connect.ts +40 -3
- package/src/client/link-home.ts +10 -1
- package/src/client/link-ingress.ts +1 -1
- package/src/client/link-readiness.ts +97 -0
- package/src/client/link-relay-transport.ts +79 -11
- package/src/client/link-relay.ts +74 -15
- package/src/client/link-tunnel.ts +45 -18
- package/src/client/machine-api.ts +3 -1
- package/src/client/machine-listener.ts +20 -2
- package/src/client/runtime.ts +20 -2
- package/src/client/sync-expectation.ts +118 -0
- package/src/clients/config-export/agent-clients.ts +96 -0
- package/src/clients/config-export/contracts.ts +25 -7
- package/src/clients/config-export/qoder.ts +38 -23
- package/src/clients/config-export/reasoning-metadata.ts +55 -8
- package/src/clients/config-export.ts +12 -0
- package/src/clients/lazycodex.ts +7 -2
- package/src/clients/reasoning-controls.ts +49 -0
- package/src/codex/account-store.ts +17 -3
- package/src/codex/app-server-restart-service.ts +6 -5
- package/src/codex/auth-api/account-identity.ts +14 -0
- package/src/codex/auth-api/account-list.ts +29 -2
- package/src/codex/auth-api/http.ts +13 -0
- package/src/codex/auth-api/main-account-probe.ts +2 -2
- package/src/codex/auth-api/pool-mode-gate.ts +16 -3
- package/src/codex/auth-api/pool-quota-probe.ts +15 -0
- package/src/codex/auth-context.ts +15 -12
- package/src/codex/catalog/build-entries.ts +22 -0
- package/src/codex/catalog/configured-tiers.ts +70 -0
- package/src/codex/catalog/effort.ts +52 -11
- package/src/codex/catalog/gather-capture.ts +5 -2
- package/src/codex/catalog/heal-observation.ts +155 -13
- package/src/codex/catalog/metadata.ts +6 -0
- package/src/codex/catalog/model-hints.ts +60 -11
- package/src/codex/catalog/model-visibility.ts +3 -2
- package/src/codex/catalog/native-models.ts +18 -3
- package/src/codex/catalog/parsing.ts +10 -8
- package/src/codex/catalog/pinned-models.ts +2 -1
- package/src/codex/catalog/provider-models.ts +18 -13
- package/src/codex/catalog/retained-sync.ts +2 -1
- package/src/codex/catalog/routed-gather.ts +19 -20
- package/src/codex/catalog/write-audit.ts +3 -2
- package/src/codex/catalog-self-heal.ts +43 -23
- package/src/codex/chatgpt-refresh-failure.ts +6 -2
- package/src/codex/cli-install-provenance.ts +418 -0
- package/src/codex/cli-installation-targets.ts +5 -1
- package/src/codex/cli-update-plan.ts +43 -16
- package/src/codex/collision-identity.ts +30 -5
- package/src/codex/convergence.ts +4 -3
- package/src/codex/data/roster-pinned-models.json +177 -1
- package/src/codex/desired-state.ts +6 -1
- package/src/codex/desktop-app/picker-freshness.ts +10 -8
- package/src/codex/desktop-compatibility/installed-build.ts +88 -12
- package/src/codex/desktop-compatibility/runtime.ts +29 -5
- package/src/codex/desktop-compatibility/usage-activation.ts +2 -1
- package/src/codex/desktop-compatibility/usage-controller.ts +9 -1
- package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
- package/src/codex/inject/config-toml.ts +0 -18
- package/src/codex/inject/plan.ts +18 -3
- package/src/codex/inject/remove.ts +6 -2
- package/src/codex/inject.ts +1 -1
- package/src/codex/journal.ts +61 -1
- package/src/codex/model-entitlements.ts +1 -1
- package/src/codex/native-main-owner.ts +27 -1
- package/src/codex/native-profile-store.ts +2 -1
- package/src/codex/pool-credit-policy.ts +35 -1
- package/src/codex/pool-refresh-backoff.ts +3 -1
- package/src/codex/quota-types.ts +3 -0
- package/src/codex/quota.ts +24 -4
- package/src/codex/role-auto-assign.ts +6 -2
- package/src/codex/subagent-defaults.ts +49 -4
- package/src/codex/user-identity.ts +35 -6
- package/src/codex/windows-current-sid.ts +162 -0
- package/src/combos/failover.ts +17 -2
- package/src/combos/jev-decision-contract.ts +22 -1
- package/src/combos/jev-quota-activation.ts +5 -1
- package/src/combos/jev-quota-route.ts +1 -1
- package/src/combos/jev-quota.ts +9 -1
- package/src/combos/jev-service-exchange.ts +3 -1
- package/src/combos/jev-session-pin-config.ts +51 -0
- package/src/combos/jev.ts +101 -9
- package/src/combos/resolve.ts +45 -1
- package/src/combos/types.ts +43 -0
- package/src/config/load-degrade.ts +5 -0
- package/src/config/paths.ts +19 -3
- package/src/config/pending-teardown.ts +22 -1
- package/src/config/provider-validation.ts +22 -4
- package/src/config/removed-opencode-free.ts +11 -0
- package/src/config/schema/leaf-validators.ts +6 -0
- package/src/generated/compatibility-version.json +467 -311
- package/src/generated/model-metadata.ts +5 -5
- package/src/images/loop.ts +16 -2
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/hermes-profiles.ts +251 -0
- package/src/integrations/merge.ts +8 -0
- package/src/integrations/mutation-plan.ts +19 -4
- package/src/integrations/registry.ts +5 -0
- package/src/integrations/state.ts +36 -1
- package/src/integrations/writer.ts +18 -4
- package/src/lib/bun-path-runtime.mjs +2 -1
- package/src/lib/decision-quota-sink.ts +10 -0
- package/src/lib/errors.ts +62 -0
- package/src/lib/eventstream-decoder.ts +81 -37
- package/src/lib/opaque-proxy-tunnel.ts +32 -8
- package/src/lib/pinned-http.ts +35 -2
- package/src/lib/process-control.ts +13 -1
- package/src/lib/socks5-fetch.ts +59 -64
- package/src/lib/socks5-upload-waiter.ts +50 -0
- package/src/lib/sse-decoder.ts +7 -2
- package/src/lib/state-store-sweeper.ts +40 -14
- package/src/lib/translator-budget.ts +4 -4
- package/src/lib/upstream-retry.ts +4 -1
- package/src/lib/windows-native-principal-worker.ts +14 -0
- package/src/lib/windows-native-principal.ts +188 -0
- package/src/lib/windows-secret-acl.ts +39 -3
- package/src/lib/windows-user-principal.ts +62 -18
- package/src/link/diagnostics.ts +193 -0
- package/src/link/relay-auth.ts +6 -0
- package/src/link/ssh-config.ts +35 -3
- package/src/link/status-projection.ts +39 -0
- package/src/link/supervisor.ts +45 -12
- package/src/link/tunnel-history.ts +109 -0
- package/src/link/tunnel-state.ts +80 -17
- package/src/messaging/remote-files.ts +24 -1
- package/src/oauth/generic-account-failover.ts +91 -7
- package/src/oauth/index.ts +15 -0
- package/src/oauth/model-discovery-auth.ts +5 -0
- package/src/oauth/store.ts +4 -1
- package/src/oauth/token-guardian.ts +7 -0
- package/src/oauth/types.ts +9 -0
- package/src/oauth/workbuddy.ts +139 -0
- package/src/providers/account-quota-disk.ts +12 -4
- package/src/providers/antigravity-quota-identity.ts +37 -0
- package/src/providers/base-url-choices.ts +8 -5
- package/src/providers/codebuddy-models.ts +6 -0
- package/src/providers/codex-capacity.ts +3 -1
- package/src/providers/derive.ts +51 -3
- package/src/providers/kiro-models.ts +3 -0
- package/src/providers/mimo-thinking.ts +12 -0
- package/src/providers/model-discovery.ts +2 -0
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/model-rename-migration.ts +10 -0
- package/src/providers/openai-sidecar-credit.ts +2 -2
- package/src/providers/quota/account-cache.ts +3 -2
- package/src/providers/quota/antigravity.ts +25 -14
- package/src/providers/quota/report-cache.ts +13 -4
- package/src/providers/quota/vendor-probes-key.ts +60 -0
- package/src/providers/quota/workbuddy.ts +83 -0
- package/src/providers/quota-decision-antigravity.ts +64 -0
- package/src/providers/quota-decision-publication.ts +11 -0
- package/src/providers/quota-decision-snapshot.ts +21 -4
- package/src/providers/quota-types.ts +2 -0
- package/src/providers/quota.ts +3 -1
- package/src/providers/reasoning-capabilities.ts +76 -0
- package/src/providers/registry/entries-core.ts +23 -12
- package/src/providers/registry/entries-extended.ts +83 -27
- package/src/providers/registry/model-ids.ts +5 -0
- package/src/providers/registry/model-seeds.ts +120 -56
- package/src/providers/registry/types.ts +29 -2
- package/src/providers/resolved-model-policy.ts +30 -10
- package/src/providers/routed-config.ts +24 -1
- package/src/providers/stale-model-roster-migration.ts +123 -18
- package/src/providers/workbuddy-credit-balance.ts +81 -0
- package/src/providers/workbuddy-models.ts +37 -0
- package/src/providers/workbuddy.ts +60 -0
- package/src/remote-control/workspace-pi-runtime.ts +11 -6
- package/src/responses/compaction-summary.ts +45 -0
- package/src/responses/muse-tool-name-alias.ts +1 -2
- package/src/responses/parser.ts +3 -2
- package/src/responses/reasoning-replay-cache.ts +18 -14
- package/src/responses/schema.ts +1 -0
- package/src/responses/thought-signature-replay.ts +10 -2
- package/src/router.ts +2 -0
- package/src/routing/analytics.ts +2 -3
- package/src/routing/capability.ts +8 -2
- package/src/routing/fallback-policy.ts +3 -3
- package/src/routing/history/ingest.ts +28 -3
- package/src/server/auth-cors.ts +4 -2
- package/src/server/chat-completions.ts +21 -1
- package/src/server/chat-native-eligibility.ts +7 -0
- package/src/server/chat-native-reasoning.ts +24 -7
- package/src/server/chat-native.ts +13 -2
- package/src/server/claude-messages.ts +3 -0
- package/src/server/direct-local-http.ts +5 -2
- package/src/server/effort-policy.ts +5 -1
- package/src/server/index/link-relay-sessions.ts +9 -5
- package/src/server/index/live-sideband.ts +18 -15
- package/src/server/index/optional-listeners.ts +4 -0
- package/src/server/index/serve-options.ts +5 -4
- package/src/server/local-management-read-client.ts +3 -1
- package/src/server/management/agent-settings-routes.ts +27 -15
- package/src/server/management/combo-routes.ts +14 -4
- package/src/server/management/config-routes.ts +2 -2
- package/src/server/management/decision-discovery.ts +12 -2
- package/src/server/management/hermes-profile-routes.ts +156 -0
- package/src/server/management/integration-routes.ts +85 -24
- package/src/server/management/link-routes.ts +5 -2
- package/src/server/management/model-routes.ts +2 -2
- package/src/server/management/model-row-export-metadata.ts +25 -6
- package/src/server/management/model-rows.ts +15 -20
- package/src/server/management/native-integration-routes.ts +11 -8
- package/src/server/management/provider-routes.ts +1 -1
- package/src/server/management/route-registry.ts +4 -0
- package/src/server/management-api.ts +5 -0
- package/src/server/models-capabilities.ts +21 -3
- package/src/server/port-reclaim.ts +51 -9
- package/src/server/request-log-conversation.ts +49 -0
- package/src/server/request-log.ts +2 -0
- package/src/server/responses/adapter-delivery.ts +11 -1
- package/src/server/responses/adapter-dispatch.ts +2 -2
- package/src/server/responses/anthropic-thinking-recovery.ts +1 -0
- package/src/server/responses/codex-ws-exchange.ts +39 -9
- package/src/server/responses/codex-ws-session.ts +38 -4
- package/src/server/responses/codex-ws-wire.ts +6 -1
- package/src/server/responses/combo-required-tool-contract.ts +103 -0
- package/src/server/responses/combo-stream-preflight.ts +8 -1
- package/src/server/responses/compact.ts +14 -5
- package/src/server/responses/context-overflow.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +10 -0
- package/src/server/responses/core-combo.ts +74 -44
- package/src/server/responses/core-lifetime.ts +5 -2
- package/src/server/responses/core-normalize.ts +17 -4
- package/src/server/responses/core-opaque-recovery.ts +1 -0
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-replay.ts +2 -1
- package/src/server/responses/jev-combo-choice.ts +39 -0
- package/src/server/responses/jev-session-pin.ts +203 -0
- package/src/server/responses/main-hard-lock-routing.ts +60 -44
- package/src/server/responses/passthrough-delivery.ts +44 -2
- package/src/server/responses/policy-fallback.ts +6 -1
- package/src/server/responses/request-compression.ts +12 -7
- package/src/server/responses/request-prepare.ts +32 -7
- package/src/server/responses/request-sidecar-auth.ts +2 -0
- package/src/server/responses/request-transport.ts +25 -6
- package/src/server/responses/response-effects.ts +22 -10
- package/src/server/responses/run-turn-execution.ts +2 -4
- package/src/server/responses/sidecar-execution.ts +13 -7
- package/src/server/responses-phase-inference.ts +267 -0
- package/src/server/sse-payload-rewrite.ts +14 -1
- package/src/server/stop-teardown.ts +36 -1
- package/src/server/ws-bridge.ts +1 -1
- package/src/service/definition.ts +20 -8
- package/src/service/desktop-supervision.d.mts +7 -4
- package/src/service/desktop-supervision.mjs +90 -13
- package/src/service/ownership-mutation-lease.mjs +21 -7
- package/src/types/config.ts +14 -2
- package/src/types/provider.ts +29 -7
- package/src/types/request.ts +11 -0
- package/src/types/wire.ts +1 -0
- package/src/types.ts +1 -0
- package/src/update/bind-probe.ts +29 -0
- package/src/update/codex-cli-update-launch-policy.d.mts +9 -0
- package/src/update/codex-cli-update-launch-policy.mjs +30 -0
- package/src/update/job.ts +10 -29
- package/src/update/npm-install-job.ps1 +173 -0
- package/src/update/npm-install.mjs +70 -0
- package/src/update/stop-contract.d.mts +1 -0
- package/src/update/stop-contract.mjs +14 -0
- package/src/update/stop-decision.d.mts +1 -1
- package/src/update/stop-decision.mjs +13 -3
- package/src/update/teardown-handover.ts +166 -0
- package/src/update/transactional-install.d.mts +14 -3
- package/src/update/transactional-install.mjs +33 -7
- package/src/usage/expected-prices.ts +64 -31
- package/src/usage/jev-stats.ts +54 -14
- package/src/usage/timeline.ts +19 -9
- package/src/vision/eligibility.ts +15 -5
- package/src/vision/plan.ts +2 -2
- package/src/web-search/loop.ts +16 -2
- package/gui/dist/assets/App-nZ34cR5G.js +0 -58
- package/gui/dist/assets/index-DGXS51sp.js +0 -94
- package/gui/dist/assets/index-DPeB9HpV.css +0 -1
- package/gui/dist/assets/quota-summary-DO1Sx5TM.js +0 -1
|
@@ -380,8 +380,8 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
380
380
|
if (wantsKeepNative && typeof body.keepNativeChatGptOnV1 !== "boolean") {
|
|
381
381
|
return jsonResponse({ error: "body.keepNativeChatGptOnV1 must be a boolean" }, 400);
|
|
382
382
|
}
|
|
383
|
-
if (wantsThreads && (typeof body.maxConcurrentThreadsPerSession !== "number" || !Number.
|
|
384
|
-
return jsonResponse({ error: "body.maxConcurrentThreadsPerSession must be
|
|
383
|
+
if (wantsThreads && (typeof body.maxConcurrentThreadsPerSession !== "number" || !Number.isSafeInteger(body.maxConcurrentThreadsPerSession) || body.maxConcurrentThreadsPerSession < 1)) {
|
|
384
|
+
return jsonResponse({ error: "body.maxConcurrentThreadsPerSession must be a safe integer >= 1" }, 400);
|
|
385
385
|
}
|
|
386
386
|
// Validate every new field BEFORE any write, so each 400 leaves config untouched.
|
|
387
387
|
// null unsets the key; "" is a meaningful value for instructions and must not be
|
|
@@ -1062,7 +1062,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1062
1062
|
rethrowManagementBodyTooLarge(error);
|
|
1063
1063
|
return jsonResponse({ error: "invalid JSON body" }, 400);
|
|
1064
1064
|
}
|
|
1065
|
-
const { resolveClaudeDesktopApplyMode, observeClaudeDesktopMode, applyDesktopFirstParty, captureDesktopFirstPartyRollback,
|
|
1065
|
+
const { resolveClaudeDesktopApplyMode, observeClaudeDesktopMode, applyDesktopFirstParty, withFirstPartySecretsSettled, captureDesktopFirstPartyRollback, removeDesktopFirstPartySettled } = await import("../../claude/desktop-first-party");
|
|
1066
1066
|
const requested = (parsed as { mode?: unknown } | null)?.mode;
|
|
1067
1067
|
let desktopMode: "first-party" | "gateway" = resolveClaudeDesktopApplyMode(config, observeClaudeDesktopMode(config));
|
|
1068
1068
|
if (requested !== undefined) {
|
|
@@ -1105,7 +1105,8 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1105
1105
|
return await runPickerTransition(config, async ops => {
|
|
1106
1106
|
const { inspectDesktop3pConfigLibrary, removeDesktop3pStandardPivot } = await import("../../claude/desktop-3p");
|
|
1107
1107
|
const rollback = captureDesktopFirstPartyRollback(config);
|
|
1108
|
-
const
|
|
1108
|
+
const { getConfigDir, withConfigDirHardeningSettled } = await import("../../config/paths");
|
|
1109
|
+
const applied = await withFirstPartySecretsSettled(getConfigDir(), () => applyDesktopFirstParty(config));
|
|
1109
1110
|
if (!applied.ok) {
|
|
1110
1111
|
const { firstPartyRefusalMessage } = await import("./native-integration-routes");
|
|
1111
1112
|
return jsonResponse({
|
|
@@ -1113,6 +1114,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1113
1114
|
code: "claude_desktop_first_party_refused",
|
|
1114
1115
|
reason: applied.reason,
|
|
1115
1116
|
path: applied.path,
|
|
1117
|
+
...(applied.diagnostic ? { diagnostic: applied.diagnostic } : {}),
|
|
1116
1118
|
}, applied.reason === "foreign_env" || applied.reason === "intercept_disabled" ? 409 : 500);
|
|
1117
1119
|
}
|
|
1118
1120
|
// Remove the gateway only after the replacement env was written.
|
|
@@ -1122,7 +1124,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1122
1124
|
if (library.kind === "gateway_ours" || library.kind === "gateway_drifted") {
|
|
1123
1125
|
const removed = (deps.removeDesktop3pStandardPivot ?? removeDesktop3pStandardPivot)({ appliedFingerprint, replaceWhileEnabled: true });
|
|
1124
1126
|
if (!removed.ok) {
|
|
1125
|
-
const restored = removed.changed || !applied.changed ||
|
|
1127
|
+
const restored = removed.changed || !applied.changed || await withConfigDirHardeningSettled(getConfigDir(), rollback);
|
|
1126
1128
|
const modeSaved = !removed.changed || (await persistDesktopModeField(config, "first-party")).ok;
|
|
1127
1129
|
const warning = [restored ? "" : "first-party settings rollback did not complete",
|
|
1128
1130
|
modeSaved ? "" : "first-party is active but its mode marker was not saved"].filter(Boolean).join("; ");
|
|
@@ -1219,10 +1221,10 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1219
1221
|
const committed = persistCommittedDesktopGateway(config, state.profile, result.fingerprint);
|
|
1220
1222
|
const modeWarning = committed.ok ? undefined : `Gateway applied, but its mode/profile state was not saved (${committed.reason}).`;
|
|
1221
1223
|
// The durable marker describes the committed gateway even if old-mode cleanup fails.
|
|
1222
|
-
const firstPartyRemoved =
|
|
1224
|
+
const firstPartyRemoved = await removeDesktopFirstPartySettled(loadConfig);
|
|
1223
1225
|
if (!firstPartyRemoved.ok) {
|
|
1224
1226
|
return { response: jsonResponse({
|
|
1225
|
-
error: `Claude Code settings
|
|
1227
|
+
error: `Claude Code first-party settings cleanup did not complete (${firstPartyRemoved.path}); the gateway was applied.`,
|
|
1226
1228
|
code: "claude_desktop_first_party_refused", reason: firstPartyRemoved.reason,
|
|
1227
1229
|
applied: true, saved: committed.ok, mode: "gateway", path: result.path,
|
|
1228
1230
|
...(modeWarning ? { warning: modeWarning } : {}),
|
|
@@ -1407,7 +1409,10 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1407
1409
|
!("fingerprint" in body) || typeof body.fingerprint !== "string" || !/^[a-f0-9]{64}$/.test(body.fingerprint)) {
|
|
1408
1410
|
return jsonResponse({ error: "fingerprint is required" }, 400);
|
|
1409
1411
|
}
|
|
1410
|
-
|
|
1412
|
+
// Fresh admission after the body await: a nested Claude home shares the config-root ACL flight.
|
|
1413
|
+
const fingerprint = body.fingerprint;
|
|
1414
|
+
const { withConfigDirHardeningSettled } = await import("../../config/paths"), { claudeConfigDir } = await import("../../claude/auth-detect");
|
|
1415
|
+
return jsonResponse(await withConfigDirHardeningSettled(claudeConfigDir(), () => applyClaudeModelDefaults(config.claudeCode?.tierModels, fingerprint)));
|
|
1411
1416
|
} catch (error) {
|
|
1412
1417
|
rethrowManagementBodyTooLarge(error);
|
|
1413
1418
|
if (error instanceof ModelDefaultsRecoveryError) return jsonResponse({ error: error.message, code: error.message, backupPath: error.backupPath }, 500);
|
|
@@ -1516,10 +1521,10 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1516
1521
|
visionSidecar: sidecarAnthropicPoolOptions(config, { ...helperVision, backend: helperVisionBackend }, helperParent),
|
|
1517
1522
|
},
|
|
1518
1523
|
...(webSearchOverride && Object.keys(webSearchOverride).length > 0
|
|
1519
|
-
? { webSearchSidecar: { backend: webSearchOverride.backend, model: webSearchOverride.model, ...(webSearchOverride.anthropicInstance ? { anthropicInstance: webSearchOverride.anthropicInstance } : {}) } }
|
|
1524
|
+
? { webSearchSidecar: { enabled: webSearchOverride.enabled, backend: webSearchOverride.backend, model: webSearchOverride.model, ...(webSearchOverride.anthropicInstance ? { anthropicInstance: webSearchOverride.anthropicInstance } : {}) } }
|
|
1520
1525
|
: {}),
|
|
1521
1526
|
...(visionOverride && Object.keys(visionOverride).length > 0
|
|
1522
|
-
? { visionSidecar: { backend: visionOverride.backend, model: visionOverride.model, ...(visionOverride.anthropicInstance ? { anthropicInstance: visionOverride.anthropicInstance } : {}) } }
|
|
1527
|
+
? { visionSidecar: { enabled: visionOverride.enabled, backend: visionOverride.backend, model: visionOverride.model, ...(visionOverride.anthropicInstance ? { anthropicInstance: visionOverride.anthropicInstance } : {}) } }
|
|
1523
1528
|
: {}),
|
|
1524
1529
|
fastMode: config.fastMode,
|
|
1525
1530
|
forceAvailable: [...visibleNativeSlugs(config), ...filterCatalogVisibleModels(models, config).map(catalogModelSlug)],
|
|
@@ -1552,7 +1557,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1552
1557
|
return jsonResponse({ error: "cliFirstParty must be sent alone", code: "cli_first_party_not_alone" }, 400);
|
|
1553
1558
|
if (body.cliFirstParty !== undefined) {
|
|
1554
1559
|
const { claudeInterceptEnabled, claudeInterceptProxyPort, getClaudeInterceptState } = await import("../../claude/intercept/runtime");
|
|
1555
|
-
const { captureDesktopFirstPartyRollback, inspectDesktopFirstParty, observeClaudeDesktopMode, resolveClaudeDesktopMode } = await import("../../claude/desktop-first-party");
|
|
1560
|
+
const { captureDesktopFirstPartyRollback, inspectDesktopFirstParty, observeClaudeDesktopMode, resolveClaudeDesktopMode, withFirstPartySecretsSettled } = await import("../../claude/desktop-first-party");
|
|
1556
1561
|
const { firstPartyDesired, readFirstPartyProxyStatus, reconcileClaudeFirstPartySettings } = await import("../../claude/first-party-settings");
|
|
1557
1562
|
const { commitClaudeCodeBlock } = await import("../../claude/claude-code-block");
|
|
1558
1563
|
let bound = (deps.getClaudeInterceptState ?? getClaudeInterceptState)();
|
|
@@ -1622,13 +1627,15 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1622
1627
|
if (committed.pinnedMode) live.desktopMode = committed.pinnedMode;
|
|
1623
1628
|
config.claudeCode = live;
|
|
1624
1629
|
let result: ReturnType<typeof reconcileClaudeFirstPartySettings> | undefined;
|
|
1625
|
-
|
|
1626
|
-
|
|
1630
|
+
const { getConfigDir, withConfigDirHardeningSettled } = await import("../../config/paths");
|
|
1631
|
+
try { result = await withFirstPartySecretsSettled(getConfigDir(), () =>
|
|
1632
|
+
(deps.reconcileClaudeFirstPartySettings ?? reconcileClaudeFirstPartySettings)(config,
|
|
1633
|
+
firstPartyDesired(config, observeClaudeDesktopMode(config)))); }
|
|
1627
1634
|
catch { /* An unexpected settings failure is mapped after conditional rollback. */ }
|
|
1628
1635
|
if (!result?.ok) {
|
|
1629
1636
|
let settingsRestored = true;
|
|
1630
1637
|
if (body.cliFirstParty) {
|
|
1631
|
-
try { settingsRestored = restoreSettings?.() ?? false; } catch { settingsRestored = false; }
|
|
1638
|
+
try { settingsRestored = result?.reason === "ca_unavailable" || await withConfigDirHardeningSettled(getConfigDir(), () => restoreSettings?.() ?? false); } catch { settingsRestored = false; }
|
|
1632
1639
|
let rollback: ReturnType<typeof mutatePersistedConfig<OcxConfig["claudeCode"]>>;
|
|
1633
1640
|
try {
|
|
1634
1641
|
rollback = mutatePersistedConfig(persisted => {
|
|
@@ -1650,6 +1657,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1650
1657
|
}
|
|
1651
1658
|
const code = result?.reason ?? "write_failed";
|
|
1652
1659
|
return jsonResponse({ error: "Claude first-party reconciliation failed", code,
|
|
1660
|
+
...(result?.diagnostic ? { diagnostic: result.diagnostic } : {}),
|
|
1653
1661
|
...(!body.cliFirstParty && code === "unreadable"
|
|
1654
1662
|
? { cliFirstParty: false, warnings: ["settings_residual"] } : {}),
|
|
1655
1663
|
...(body.cliFirstParty && !settingsRestored
|
|
@@ -1673,6 +1681,9 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1673
1681
|
const section = body[field];
|
|
1674
1682
|
if (section === undefined || section === null) continue;
|
|
1675
1683
|
if (!isPlainObject(section)) return jsonResponse({ error: `${field} must be an object or null` }, 400);
|
|
1684
|
+
if (section.enabled !== undefined && typeof section.enabled !== "boolean") {
|
|
1685
|
+
return jsonResponse({ error: `${field}.enabled must be a boolean` }, 400);
|
|
1686
|
+
}
|
|
1676
1687
|
// Both overrides now speak their full unions (roadmap 060 web, 170
|
|
1677
1688
|
// vision revised). Vision's third arm is "routed" (loopback through the
|
|
1678
1689
|
// proxy's own router), never exa: exa is not an LLM, and accepting an
|
|
@@ -1760,8 +1771,9 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
|
|
|
1760
1771
|
}
|
|
1761
1772
|
// The per-field validation above guarantees vision only ever carries the two-member
|
|
1762
1773
|
// union; the cast is the loop's shared-shape compromise, not a wider write path.
|
|
1763
|
-
const requested = section as { backend?: "openai" | "anthropic" | "xai" | "gemini" | "exa" | null; model?: string; anthropicInstance?: AnthropicInstanceId | null };
|
|
1774
|
+
const requested = section as { enabled?: boolean; backend?: "openai" | "anthropic" | "xai" | "gemini" | "exa" | null; model?: string; anthropicInstance?: AnthropicInstanceId | null };
|
|
1764
1775
|
const override = { ...next[field] } as NonNullable<OcxClaudeCodeConfig[typeof field]>;
|
|
1776
|
+
if (requested.enabled !== undefined) override.enabled = requested.enabled;
|
|
1765
1777
|
if (requested.anthropicInstance === null) delete override.anthropicInstance;
|
|
1766
1778
|
else if (isAnthropicInstanceId(requested.anthropicInstance)) override.anthropicInstance = requested.anthropicInstance;
|
|
1767
1779
|
if (requested.backend === null) delete override.backend;
|
|
@@ -208,7 +208,6 @@ export async function handleComboRoutes(ctx: ManagementContext): Promise<Respons
|
|
|
208
208
|
const {
|
|
209
209
|
clearComboSelectionState,
|
|
210
210
|
clearComboTargetCooldowns,
|
|
211
|
-
comboConfigError,
|
|
212
211
|
comboDisabledModelId,
|
|
213
212
|
comboDisabledModelSelectors,
|
|
214
213
|
comboModelId,
|
|
@@ -223,8 +222,14 @@ export async function handleComboRoutes(ctx: ManagementContext): Promise<Respons
|
|
|
223
222
|
const requestedCombo: Record<string, unknown> = body.combo;
|
|
224
223
|
const effectiveCombo = {
|
|
225
224
|
...requestedCombo,
|
|
225
|
+
// Clients that do not expose this opt-in must preserve it on unrelated edits.
|
|
226
|
+
...(!Object.hasOwn(requestedCombo, "cooldownReprobe") && previous?.cooldownReprobe !== undefined
|
|
227
|
+
? { cooldownReprobe: previous.cooldownReprobe }
|
|
228
|
+
: {}),
|
|
226
229
|
...(!Object.hasOwn(requestedCombo, "decisionQuotaSignals") && requestedCombo.strategy === "jev" && previous?.decisionQuotaSignals !== undefined ? { decisionQuotaSignals: previous.decisionQuotaSignals } : {}),
|
|
227
230
|
...(!Object.hasOwn(requestedCombo, "decisionQuotaTiers") && requestedCombo.strategy === "jev" && previous?.decisionQuotaTiers !== undefined ? { decisionQuotaTiers: previous.decisionQuotaTiers } : {}),
|
|
231
|
+
// The dashboard does not edit the session pin (#7525): an omitted field keeps it on a JEV save.
|
|
232
|
+
...(!Object.hasOwn(requestedCombo, "sessionPin") && requestedCombo.strategy === "jev" && previous?.sessionPin != null ? { sessionPin: previous.sessionPin } : {}),
|
|
228
233
|
...(!Object.hasOwn(requestedCombo, "allowMeteredTargets") && previous?.allowMeteredTargets === true
|
|
229
234
|
? { allowMeteredTargets: true }
|
|
230
235
|
: {}),
|
|
@@ -257,7 +262,7 @@ export async function handleComboRoutes(ctx: ManagementContext): Promise<Respons
|
|
|
257
262
|
...(Array.isArray(requestedCombo.targets) && Array.isArray(previous?.targets)
|
|
258
263
|
? {
|
|
259
264
|
targets: requestedCombo.targets.map(target => {
|
|
260
|
-
// A non-record entry stays as the client sent it so
|
|
265
|
+
// A non-record entry stays as the client sent it so comboConfigIssues reports it.
|
|
261
266
|
// Reading `lastResort` off it here would throw in place of that structured 400.
|
|
262
267
|
if (!isPlainRecord(target)) return target;
|
|
263
268
|
if (["lastResort", "metered"].every(key => Object.hasOwn(target, key))) return target;
|
|
@@ -331,8 +336,13 @@ export async function handleComboRoutes(ctx: ManagementContext): Promise<Respons
|
|
|
331
336
|
excludeComboId: sourceId,
|
|
332
337
|
normalizeDecisionModel: (model: string) => normalizeDecisionModelSelector(prospectiveConfig, model),
|
|
333
338
|
};
|
|
334
|
-
|
|
335
|
-
|
|
339
|
+
// `field` names the top-level combo field of the first issue, so a client can tell a target or
|
|
340
|
+
// JEV-setting refusal from an alias or rename one without parsing the message (#7579).
|
|
341
|
+
const invalid = comboConfigIssues(id, effectiveCombo, config.providers, validationOptions)[0];
|
|
342
|
+
if (invalid) {
|
|
343
|
+
const field = invalid.path[0];
|
|
344
|
+
return jsonResponse({ error: invalid.message, ...(typeof field === "string" ? { field } : {}) }, 400);
|
|
345
|
+
}
|
|
336
346
|
for (const [otherId, combo] of Object.entries(nextCombos)) {
|
|
337
347
|
if (typeof combo.decisionModel !== "string") continue;
|
|
338
348
|
const issue = otherId === id ? undefined : comboConfigIssues(otherId, combo, config.providers, {
|
|
@@ -331,8 +331,8 @@ export async function syncEnabledClientIntegrations(
|
|
|
331
331
|
config,
|
|
332
332
|
port,
|
|
333
333
|
}, unattended
|
|
334
|
-
? ["mcode", "pi", "aside", "raycast", "omo", "commandcode", "droid", "opencode", "kilo", "qoder"]
|
|
335
|
-
: ["mcode", "pi", "aside", "raycast", "omo", "cline", "commandcode", "droid", "opencode", "kilo", "qoder"],
|
|
334
|
+
? ["mcode", "pi", "aside", "raycast", "omo", "commandcode", "droid", "opencode", "kilo", "qoder", "qoder-cn", "workbuddy", "workbuddy-ai"]
|
|
335
|
+
: ["mcode", "pi", "aside", "raycast", "omo", "cline", "commandcode", "droid", "opencode", "kilo", "qoder", "qoder-cn", "workbuddy", "workbuddy-ai"],
|
|
336
336
|
...unattended ? [{ refreshOnly: true, admit }] as const : []));
|
|
337
337
|
|
|
338
338
|
return out;
|
|
@@ -39,7 +39,7 @@ export function isDecisionModelCandidate(row: DiscoveryModelRow, query = ""): bo
|
|
|
39
39
|
const term = normalize(query);
|
|
40
40
|
const haystack = `${row.id} ${row.owned_by ?? ""} ${row.displayName ?? ""}`.toLowerCase();
|
|
41
41
|
if (term.length > 0) return haystack.includes(term);
|
|
42
|
-
return DECISION_MODEL_HINT.test(row.id) || DECISION_MODEL_HINT.test(row.owned_by ?? "");
|
|
42
|
+
return DECISION_MODEL_HINT.test(row.id) || DECISION_MODEL_HINT.test(row.owned_by ?? "") || row.id.toLowerCase().includes("laya");
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -53,7 +53,17 @@ export function isDecisionModelCandidate(row: DiscoveryModelRow, query = ""): bo
|
|
|
53
53
|
export function systemOneEndpoint(baseUrl: string | undefined): string | null {
|
|
54
54
|
const trimmed = (baseUrl ?? "").trim().replace(/\/+$/, "");
|
|
55
55
|
if (!/^https?:\/\//i.test(trimmed)) return null;
|
|
56
|
-
|
|
56
|
+
try {
|
|
57
|
+
const parsed = new URL(trimmed);
|
|
58
|
+
if (parsed.hostname === "ai-gateway.vercel.sh") {
|
|
59
|
+
if (trimmed.endsWith("/decisions")) return trimmed;
|
|
60
|
+
return `${trimmed.replace(/\/systemone$/, "").replace(/\/+$/, "")}/decisions`;
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (trimmed.endsWith("/systemone") || trimmed.endsWith("/decisions")) return trimmed;
|
|
66
|
+
return `${trimmed}/systemone`;
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
/** Deduplicate by provider+model so a row that appears twice is probed once. */
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hermes profile selection for the client-integration routes (#7674).
|
|
3
|
+
*
|
|
4
|
+
* A Hermes profile is the same integration in a different home, so this module
|
|
5
|
+
* adds no mutation of its own. It turns a `profile` selector into a request
|
|
6
|
+
* scope (that profile's ownership store and the HERMES_HOME Hermes runs it with)
|
|
7
|
+
* and hands the request back to the generic routes, which then read, plan, write,
|
|
8
|
+
* journal and restore exactly as they do for the default profile.
|
|
9
|
+
*
|
|
10
|
+
* Accepted spellings, all with `profile=<name>`:
|
|
11
|
+
* - `/api/client-integrations/hermes` (GET, PUT)
|
|
12
|
+
* - `/api/client-integrations/{journal,preview,restore,restore/preview}` with `client=hermes`
|
|
13
|
+
*
|
|
14
|
+
* The `profile` selector is removed before the request continues (the Aside
|
|
15
|
+
* handlers treat any `profile` as an Aside account id, and a Hermes name such as
|
|
16
|
+
* `123` is also a valid one), and the generic routes skip every Aside delegation
|
|
17
|
+
* for a scoped request, `profile=default` included. A Hermes-scoped request can
|
|
18
|
+
* therefore never reach an Aside operation, and it sees only Hermes rows.
|
|
19
|
+
*/
|
|
20
|
+
import {
|
|
21
|
+
HERMES_DEFAULT_PROFILE,
|
|
22
|
+
HermesProfileError,
|
|
23
|
+
guardedHermesProfileStore,
|
|
24
|
+
hermesProfileBoundary,
|
|
25
|
+
hermesProfileEnv,
|
|
26
|
+
hermesProfilePaths,
|
|
27
|
+
hermesProfileStore,
|
|
28
|
+
listHermesProfiles,
|
|
29
|
+
resolveHermesProfile,
|
|
30
|
+
type HermesProfile,
|
|
31
|
+
} from "../../integrations/hermes-profiles";
|
|
32
|
+
import type { ResolvedIntegrationPaths } from "../../integrations/registry";
|
|
33
|
+
import type { IntegrationStateStore } from "../../integrations/store";
|
|
34
|
+
import type { ExportModel } from "../../clients/config-export";
|
|
35
|
+
import { jsonResponse } from "../auth-cors";
|
|
36
|
+
import type { ManagementContext } from "./context";
|
|
37
|
+
|
|
38
|
+
export interface HermesRequestScope {
|
|
39
|
+
profile: HermesProfile;
|
|
40
|
+
store: IntegrationStateStore;
|
|
41
|
+
env: NodeJS.ProcessEnv;
|
|
42
|
+
/** Named profiles only; the default profile resolves its paths as it always has. */
|
|
43
|
+
resolvedPaths?: ResolvedIntegrationPaths;
|
|
44
|
+
/** Throws a HermesProfileError when the pinned profile no longer holds. */
|
|
45
|
+
assertBoundary: () => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface HermesScopeBase {
|
|
49
|
+
store: IntegrationStateStore;
|
|
50
|
+
env?: NodeJS.ProcessEnv;
|
|
51
|
+
home?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const HERMES_PROFILES_PATH = "/api/client-integrations/hermes/profiles";
|
|
55
|
+
const HERMES_CLIENT_PATH = "/api/client-integrations/hermes";
|
|
56
|
+
const HISTORY_PATHS = [
|
|
57
|
+
"/api/client-integrations/journal",
|
|
58
|
+
"/api/client-integrations/preview",
|
|
59
|
+
"/api/client-integrations/restore",
|
|
60
|
+
"/api/client-integrations/restore/preview",
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Keyed by the Request object, which every copy of the management context shares.
|
|
65
|
+
* Entries die with the request.
|
|
66
|
+
*/
|
|
67
|
+
const scopes = new WeakMap<Request, HermesRequestScope>();
|
|
68
|
+
|
|
69
|
+
export function hermesRequestScope(req: Request): HermesRequestScope | undefined {
|
|
70
|
+
return scopes.get(req);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function scopeFor(profile: HermesProfile, base: HermesScopeBase): HermesRequestScope {
|
|
74
|
+
const env = base.env ?? process.env;
|
|
75
|
+
if (profile.name === HERMES_DEFAULT_PROFILE) {
|
|
76
|
+
return { profile, store: base.store, env, assertBoundary: () => {} };
|
|
77
|
+
}
|
|
78
|
+
const store = hermesProfileStore(base.store, profile.name);
|
|
79
|
+
const assertBoundary = hermesProfileBoundary(profile, store);
|
|
80
|
+
return {
|
|
81
|
+
profile, store: guardedHermesProfileStore(store, assertBoundary), env: hermesProfileEnv(profile, env),
|
|
82
|
+
resolvedPaths: hermesProfilePaths(profile), assertBoundary,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function refusal(ctx: ManagementContext, error: HermesProfileError): Response {
|
|
87
|
+
return jsonResponse({ error: error.message, code: error.code, clientId: "hermes" }, error.status, ctx.req, ctx.config);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The context to continue with, a refusal, or null when the request names no
|
|
92
|
+
* Hermes profile. `profile=default` keeps the root store and the default paths.
|
|
93
|
+
*/
|
|
94
|
+
export function scopeHermesProfileRequest(ctx: ManagementContext, base: HermesScopeBase): ManagementContext | Response | null {
|
|
95
|
+
const { url, req } = ctx;
|
|
96
|
+
if (!url.searchParams.has("profile")) return null;
|
|
97
|
+
const onClientPath = url.pathname === HERMES_CLIENT_PATH;
|
|
98
|
+
const onHistoryPath = HISTORY_PATHS.includes(url.pathname) && url.searchParams.get("client") === "hermes";
|
|
99
|
+
if (!onClientPath && !onHistoryPath) return null;
|
|
100
|
+
const selectors = url.searchParams.getAll("profile");
|
|
101
|
+
if (selectors.length !== 1) {
|
|
102
|
+
return refusal(ctx, new HermesProfileError("invalid_hermes_profile", 400, "Name exactly one Hermes profile"));
|
|
103
|
+
}
|
|
104
|
+
let scope: HermesRequestScope;
|
|
105
|
+
try { scope = scopeFor(resolveHermesProfile(selectors[0]!, base.env ?? process.env, base.home), base); }
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error instanceof HermesProfileError) return refusal(ctx, error);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
const next = new URL(url);
|
|
111
|
+
next.searchParams.delete("profile");
|
|
112
|
+
scopes.set(req, scope);
|
|
113
|
+
return { ...ctx, url: next };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* GET /api/client-integrations/hermes/profiles: every profile with its own state.
|
|
118
|
+
*
|
|
119
|
+
* The roster loads first. Each profile's boundary is then checked and its state read with no await
|
|
120
|
+
* in between, and a profile whose boundary does not hold is described from its path alone: reading
|
|
121
|
+
* state also retries snapshot maintenance, which must never run through a store that was refused.
|
|
122
|
+
*/
|
|
123
|
+
export async function hermesProfileListResponse(
|
|
124
|
+
ctx: ManagementContext,
|
|
125
|
+
base: HermesScopeBase,
|
|
126
|
+
loadModels: () => Promise<readonly ExportModel[]>,
|
|
127
|
+
read: (scope: HermesRequestScope | null, models: readonly ExportModel[]) => object,
|
|
128
|
+
): Promise<Response | null> {
|
|
129
|
+
if (ctx.url.pathname !== HERMES_PROFILES_PATH || ctx.req.method !== "GET") return null;
|
|
130
|
+
if ([...ctx.url.searchParams.keys()].length > 0) {
|
|
131
|
+
return refusal(ctx, new HermesProfileError("invalid_hermes_profile", 400, "The profile list takes no selectors"));
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const models = await loadModels();
|
|
135
|
+
const profiles = listHermesProfiles(base.env ?? process.env, base.home);
|
|
136
|
+
const rows = profiles.map(profile => {
|
|
137
|
+
let scope: HermesRequestScope;
|
|
138
|
+
try { scope = scopeFor(profile, base); }
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (!(error instanceof HermesProfileError)) throw error;
|
|
141
|
+
return {
|
|
142
|
+
clientId: "hermes", configPath: profile.configPath, state: "unsafe", installed: true,
|
|
143
|
+
snapshotCount: -1, retentionDegraded: true, hermesProfile: profile.name, error: error.message,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return { ...read(scope.resolvedPaths ? scope : null, models), hermesProfile: profile.name };
|
|
147
|
+
});
|
|
148
|
+
return jsonResponse({ profiles: rows }, 200, ctx.req, ctx.config);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (error instanceof HermesProfileError) return refusal(ctx, error);
|
|
151
|
+
return jsonResponse({
|
|
152
|
+
error: error instanceof Error ? error.message : String(error),
|
|
153
|
+
code: "integration_internal_error",
|
|
154
|
+
}, 500, ctx.req, ctx.config);
|
|
155
|
+
}
|
|
156
|
+
}
|