omnicell-router 0.7.0 → 0.8.1

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.
Files changed (243) hide show
  1. package/backend/dist/cli/clients/base.d.ts +13 -2
  2. package/backend/dist/cli/clients/claude.d.ts +2 -2
  3. package/backend/dist/cli/clients/codex.d.ts +2 -2
  4. package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
  5. package/backend/dist/cli/clients/core-adapters.js +3 -4
  6. package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
  7. package/backend/dist/cli/clients/cursor-proxy.js +421 -0
  8. package/backend/dist/cli/clients/dsh.d.ts +2 -2
  9. package/backend/dist/cli/clients/grok.d.ts +2 -2
  10. package/backend/dist/cli/clients/index.d.ts +8 -1
  11. package/backend/dist/cli/clients/index.js +48 -20
  12. package/backend/dist/cli/clients/kimi.d.ts +2 -2
  13. package/backend/dist/cli/clients/launcher.d.ts +8 -0
  14. package/backend/dist/cli/clients/model-meta.js +1 -1
  15. package/backend/dist/cli/clients/omp.d.ts +2 -2
  16. package/backend/dist/cli/clients/openclaw.d.ts +2 -2
  17. package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
  18. package/backend/dist/cli/clients/opencode-proxy.js +351 -0
  19. package/backend/dist/cli/clients/opencode.d.ts +2 -2
  20. package/backend/dist/cli/clients/pi.d.ts +2 -2
  21. package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
  22. package/backend/dist/cli/clients/plugin-adapters.js +6 -29
  23. package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
  24. package/backend/dist/cli/clients/qoder-proxy.js +497 -0
  25. package/backend/dist/cli/clients/reserved.d.ts +2 -6
  26. package/backend/dist/cli/clients/reserved.js +2 -0
  27. package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
  28. package/backend/dist/cli/index.js +60 -9
  29. package/backend/dist/cli/types.d.ts +20 -8
  30. package/backend/dist/compression/caveman-prompts.d.ts +1 -1
  31. package/backend/dist/config/comments-en.js +6 -12
  32. package/backend/dist/config/comments-zh.js +6 -12
  33. package/backend/dist/config/defaults.d.ts +56 -1
  34. package/backend/dist/config/defaults.js +68 -0
  35. package/backend/dist/config/index.d.ts +9 -2
  36. package/backend/dist/config/index.js +26 -3
  37. package/backend/dist/config/types.d.ts +55 -43
  38. package/backend/dist/forward-proxy/egress.d.ts +10 -2
  39. package/backend/dist/forward-proxy/egress.js +42 -4
  40. package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
  41. package/backend/dist/forward-proxy/ordered-relay.js +46 -0
  42. package/backend/dist/forward-proxy/rules.d.ts +66 -19
  43. package/backend/dist/forward-proxy/rules.js +61 -14
  44. package/backend/dist/forward-proxy/server.js +226 -77
  45. package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
  46. package/backend/dist/forward-proxy/system-proxy.js +199 -22
  47. package/backend/dist/harness/common/market.d.ts +3 -3
  48. package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
  49. package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
  50. package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
  51. package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
  52. package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
  53. package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
  54. package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
  55. package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
  56. package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
  57. package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
  58. package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
  59. package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
  60. package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
  61. package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
  62. package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
  63. package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
  64. package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
  65. package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
  66. package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
  67. package/backend/dist/harness/translation.js +64 -21
  68. package/backend/dist/harness/types.d.ts +1 -1
  69. package/backend/dist/harness/types.js +1 -1
  70. package/backend/dist/index.js +31 -18
  71. package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
  72. package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
  73. package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
  74. package/backend/dist/ir/adapters/anthropic.js +788 -0
  75. package/backend/dist/ir/adapters/chat.d.ts +15 -0
  76. package/backend/dist/ir/adapters/chat.js +602 -0
  77. package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
  78. package/backend/dist/ir/adapters/google-stream.js +242 -0
  79. package/backend/dist/ir/adapters/google.d.ts +9 -0
  80. package/backend/dist/ir/adapters/google.js +317 -0
  81. package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
  82. package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
  83. package/backend/dist/ir/adapters/openai-responses.js +26 -1
  84. package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
  85. package/backend/dist/ir/adapters/responses-output.js +348 -0
  86. package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
  87. package/backend/dist/ir/adapters/responses-stream.js +178 -0
  88. package/backend/dist/ir/adapters/responses.d.ts +14 -0
  89. package/backend/dist/ir/adapters/responses.js +646 -0
  90. package/backend/dist/ir/errors.d.ts +2 -2
  91. package/backend/dist/ir/types.d.ts +2 -1
  92. package/backend/dist/metrics/request-cost.d.ts +11 -2
  93. package/backend/dist/metrics/request-cost.js +12 -3
  94. package/backend/dist/observability/request-identity.d.ts +1 -1
  95. package/backend/dist/observability/trace-id.d.ts +40 -0
  96. package/backend/dist/observability/trace-id.js +134 -0
  97. package/backend/dist/observability/upstream-events.d.ts +82 -60
  98. package/backend/dist/observability/upstream-events.js +142 -67
  99. package/backend/dist/opencode/catalog/types.d.ts +9 -0
  100. package/backend/dist/opencode/credentials/types.d.ts +2 -2
  101. package/backend/dist/opencode/probe.d.ts +24 -1
  102. package/backend/dist/opencode/probe.js +28 -4
  103. package/backend/dist/opencode/user-config.d.ts +5 -0
  104. package/backend/dist/pipeline/directives.d.ts +6 -2
  105. package/backend/dist/pipeline/directives.js +7 -3
  106. package/backend/dist/pipeline/orchestrator.d.ts +28 -27
  107. package/backend/dist/pipeline/orchestrator.js +220 -194
  108. package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
  109. package/backend/dist/pipeline/unresolved-model.js +43 -0
  110. package/backend/dist/plugins/catalog-def.d.ts +143 -0
  111. package/backend/dist/plugins/catalog-def.js +177 -0
  112. package/backend/dist/plugins/gateways.d.ts +62 -3
  113. package/backend/dist/plugins/gateways.js +139 -2
  114. package/backend/dist/plugins/host.d.ts +42 -5
  115. package/backend/dist/plugins/host.js +454 -38
  116. package/backend/dist/plugins/manifest.d.ts +119 -10
  117. package/backend/dist/plugins/manifest.js +265 -14
  118. package/backend/dist/plugins/pack.js +26 -0
  119. package/backend/dist/plugins/types.d.ts +187 -21
  120. package/backend/dist/protocols/systemone/convert.d.ts +1 -0
  121. package/backend/dist/protocols/systemone/convert.js +6 -1
  122. package/backend/dist/protocols/systemone/decide.js +18 -8
  123. package/backend/dist/providers/anthropic-messages.d.ts +12 -0
  124. package/backend/dist/providers/anthropic-messages.js +53 -0
  125. package/backend/dist/providers/anthropic.d.ts +7 -8
  126. package/backend/dist/providers/anthropic.js +36 -324
  127. package/backend/dist/providers/base.d.ts +14 -2
  128. package/backend/dist/providers/boot-direct.js +68 -38
  129. package/backend/dist/providers/dispatch.d.ts +5 -19
  130. package/backend/dist/providers/dispatch.js +46 -58
  131. package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
  132. package/backend/dist/providers/executors/anthropic-messages.js +3 -0
  133. package/backend/dist/providers/executors/dispatch.d.ts +16 -2
  134. package/backend/dist/providers/executors/dispatch.js +39 -9
  135. package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
  136. package/backend/dist/providers/executors/google-gemini.js +3 -0
  137. package/backend/dist/providers/executors/http-stream.js +16 -3
  138. package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
  139. package/backend/dist/providers/executors/openai-chat.js +3 -0
  140. package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
  141. package/backend/dist/providers/executors/openai-responses.js +3 -0
  142. package/backend/dist/providers/executors/plugin-adapter.js +4 -4
  143. package/backend/dist/providers/google-gemini.d.ts +12 -0
  144. package/backend/dist/providers/google-gemini.js +50 -0
  145. package/backend/dist/providers/google.d.ts +7 -8
  146. package/backend/dist/providers/google.js +35 -308
  147. package/backend/dist/providers/http-json.d.ts +19 -0
  148. package/backend/dist/providers/http-json.js +104 -0
  149. package/backend/dist/providers/http-stream.d.ts +52 -0
  150. package/backend/dist/providers/http-stream.js +423 -0
  151. package/backend/dist/providers/member-match.d.ts +4 -5
  152. package/backend/dist/providers/member-match.js +4 -5
  153. package/backend/dist/providers/openai-chat.d.ts +13 -0
  154. package/backend/dist/providers/openai-chat.js +99 -0
  155. package/backend/dist/providers/openai-compatible.d.ts +7 -4
  156. package/backend/dist/providers/openai-compatible.js +71 -368
  157. package/backend/dist/providers/openai-responses.d.ts +12 -0
  158. package/backend/dist/providers/openai-responses.js +68 -0
  159. package/backend/dist/providers/opencode-proxy.d.ts +5 -5
  160. package/backend/dist/providers/opencode-proxy.js +49 -125
  161. package/backend/dist/providers/plugin-adapter.d.ts +9 -0
  162. package/backend/dist/providers/plugin-adapter.js +31 -0
  163. package/backend/dist/providers/registry.d.ts +49 -24
  164. package/backend/dist/providers/registry.js +97 -55
  165. package/backend/dist/providers/responses.d.ts +7 -28
  166. package/backend/dist/providers/responses.js +45 -253
  167. package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
  168. package/backend/dist/providers/tool-markup-leak.js +57 -0
  169. package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
  170. package/backend/dist/providers/tool-markup-recovery.js +786 -0
  171. package/backend/dist/providers/virtual-meta.d.ts +21 -2
  172. package/backend/dist/providers/virtual-meta.js +49 -9
  173. package/backend/dist/proxy/asset-download.d.ts +54 -0
  174. package/backend/dist/proxy/asset-download.js +420 -0
  175. package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
  176. package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
  177. package/backend/dist/proxy/mihomo-binary.js +62 -51
  178. package/backend/dist/proxy/mihomo-client.js +15 -1
  179. package/backend/dist/proxy/mihomo-config.js +11 -2
  180. package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
  181. package/backend/dist/proxy/mihomo-geo.js +213 -0
  182. package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
  183. package/backend/dist/proxy/mihomo-logs.js +70 -0
  184. package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
  185. package/backend/dist/proxy/mihomo-pac.js +15 -0
  186. package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
  187. package/backend/dist/proxy/mihomo-rules-import.js +7 -7
  188. package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
  189. package/backend/dist/proxy/mihomo-sidecar.js +148 -26
  190. package/backend/dist/quota/adapters/minimax.js +36 -13
  191. package/backend/dist/quota/cli-login.d.ts +8 -0
  192. package/backend/dist/quota/cli-login.js +18 -0
  193. package/backend/dist/quota/declarations.js +10 -0
  194. package/backend/dist/quota/dsl.js +18 -5
  195. package/backend/dist/quota/engine.d.ts +22 -1
  196. package/backend/dist/quota/engine.js +170 -29
  197. package/backend/dist/quota/prober.d.ts +5 -0
  198. package/backend/dist/quota/prober.js +11 -2
  199. package/backend/dist/quota/types.d.ts +87 -8
  200. package/backend/dist/quota/verdict.d.ts +35 -0
  201. package/backend/dist/quota/verdict.js +135 -0
  202. package/backend/dist/ratelimit/admission.d.ts +131 -0
  203. package/backend/dist/ratelimit/admission.js +233 -0
  204. package/backend/dist/ratelimit/rate-limiter.js +6 -0
  205. package/backend/dist/resilience/types.d.ts +2 -2
  206. package/backend/dist/router/layer2-decision.d.ts +1 -1
  207. package/backend/dist/router/layer2-decision.js +5 -8
  208. package/backend/dist/routes/console.js +242 -51
  209. package/backend/dist/routes/mihomo.d.ts +2 -0
  210. package/backend/dist/routes/mihomo.js +334 -29
  211. package/backend/dist/routes/responses.d.ts +87 -8
  212. package/backend/dist/routes/responses.js +314 -33
  213. package/backend/dist/server.js +26 -6
  214. package/backend/dist/session/session-manager.d.ts +6 -0
  215. package/backend/dist/session/session-manager.js +20 -9
  216. package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
  217. package/backend/dist/surfaces/chat-pipeline.js +17 -7
  218. package/backend/dist/surfaces/chat.js +15 -0
  219. package/backend/dist/surfaces/decision-pipeline.js +7 -10
  220. package/backend/dist/surfaces/direct-forward.d.ts +3 -0
  221. package/backend/dist/surfaces/direct-forward.js +206 -0
  222. package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
  223. package/backend/dist/surfaces/rate-limit-response.js +57 -0
  224. package/backend/dist/surfaces/types.d.ts +11 -0
  225. package/backend/dist/trace/tracker.d.ts +32 -1
  226. package/backend/dist/trace/tracker.js +29 -4
  227. package/backend/dist/types/router.d.ts +34 -12
  228. package/backend/dist/types/router.js +35 -6
  229. package/backend/dist/utils/chat-stream.d.ts +21 -8
  230. package/backend/dist/utils/chat-stream.js +46 -9
  231. package/backend/dist/utils/event-ring.d.ts +4 -0
  232. package/backend/dist/utils/event-ring.js +4 -0
  233. package/backend/dist/utils/popularity.js +29 -4
  234. package/backend/dist/utils/proxy.d.ts +7 -0
  235. package/backend/dist/utils/proxy.js +35 -10
  236. package/backend/dist/utils/retry-after.d.ts +21 -0
  237. package/backend/dist/utils/retry-after.js +36 -0
  238. package/bin/ocr.js +2 -2
  239. package/frontend/dist/assets/index-Cn3QMOQx.js +1487 -0
  240. package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
  241. package/frontend/dist/index.html +2 -2
  242. package/package.json +1 -1
  243. package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
@@ -22,10 +22,10 @@ import { appendRoutingLedger } from '../router/routing-ledger.js';
22
22
  import { Layer2Decision } from '../router/layer2-decision.js';
23
23
  import { EFFORT_LADDER, modelSupportsEfforts } from '../types/router.js';
24
24
  import { runSystemoneDecision } from '../protocols/systemone/decide.js';
25
- import { SMART_ASSIGN_TIMEOUT_MS, DEFAULT_REPLAY_TIMEOUT_MS, CREDENTIAL_WEIGHT_MAX, DEFAULT_FORWARD_PROXY_PORT, DEFAULT_FORWARD_PROXY_RULES, DEFAULT_FORWARD_PROXY_INTERCEPT, PLUGIN_PACKAGE_MAX_BYTES } from '../config/defaults.js';
25
+ import { SMART_ASSIGN_TIMEOUT_MS, DEFAULT_REPLAY_TIMEOUT_MS, CREDENTIAL_WEIGHT_MAX, DEFAULT_FORWARD_PROXY_PORT, DEFAULT_FORWARD_PROXY_RULES, DEFAULT_FORWARD_PROXY_INTERCEPT, DEFAULT_MIHOMO_MIXED_PORT, PLUGIN_PACKAGE_MAX_BYTES, DEFAULT_TRAFFIC_DISSECT_WINDOW_BYTES } from '../config/defaults.js';
26
26
  import { initProxyConfig, proxiedFetch } from '../utils/proxy.js';
27
27
  import { registerMihomoRoutes } from './mihomo.js';
28
- import { reconcileMihomoSidecar } from '../proxy/mihomo-sidecar.js';
28
+ import { reconcileMihomoSidecar, getMihomoStatus } from '../proxy/mihomo-sidecar.js';
29
29
  import { getOcrHomeDir } from '../cli/paths.js';
30
30
  import { getHeadroomSidecarStatus, startHeadroomSidecar, stopHeadroomSidecar } from '../compression/headroom-sidecar.js';
31
31
  import { APP_VERSION } from '../version.js';
@@ -35,11 +35,13 @@ import { caCertPath, describeCa, ensureCa, resolveCaDir } from '../forward-proxy
35
35
  import { probeCaTrustedCached } from '../forward-proxy/ca-trust.js';
36
36
  import { getForwardProxyStatus } from '../forward-proxy/status.js';
37
37
  import { lintRules, normalizeRules, osBypassHosts, resolveHost, } from '../forward-proxy/rules.js';
38
- import { listGatewayHosts, WILDCARD_HOST_CLAIM } from '../plugins/gateways.js';
38
+ import { listGatewayHosts, listClaimedEgress, claimEgressFor, WILDCARD_HOST_CLAIM } from '../plugins/gateways.js';
39
39
  import { listProxyAccessEvents, readProxyAccessHistory, clearProxyAccessLog, deletePersistedProxyEvents, forgetProxyAccessRingEvents, proxyAccessLogSettings, proxyAccessBodyPath } from '../forward-proxy/access-log.js';
40
40
  import { hideLiveEvents, liveHiddenProxyIds, liveHiddenPluginKeys } from '../observability/traffic-live-hidden.js';
41
- import { getSystemProxyStatus, enableSystemProxy, disableSystemProxy } from '../forward-proxy/system-proxy.js';
41
+ import { getSystemProxyStatus, enableSystemProxy, disableSystemProxy, buildOverride, lanBypassHosts } from '../forward-proxy/system-proxy.js';
42
+ import { pacUrlFor } from '../proxy/mihomo-pac.js';
42
43
  import { keyHashPrefix } from '../opencode/credentials/types.js';
44
+ import { CLI_LOGIN_QUOTA_PREFIX, providerUsesCliLogin } from '../quota/cli-login.js';
43
45
  import { CLASSIFIER_TAXONOMY } from '../resilience/index.js';
44
46
  import { maskSecret, isValidProviderId, PROVIDER_ID_RULE, getProviderNodeById } from '../opencode/user-config.js';
45
47
  import { listOpenCodeAgentsLive } from '../opencode/agents.js';
@@ -520,6 +522,10 @@ async function buildQuotaPairRows(registry, traceTracker) {
520
522
  overview = [];
521
523
  }
522
524
  for (const o of overview) {
525
+ if (providerUsesCliLogin(o.providerId)) {
526
+ add(o.providerId, CLI_LOGIN_QUOTA_PREFIX, undefined, undefined);
527
+ continue;
528
+ }
523
529
  let metas = [];
524
530
  try {
525
531
  metas = store.listCredentials(o.providerId);
@@ -541,6 +547,10 @@ async function buildQuotaPairRows(registry, traceTracker) {
541
547
  // when a provider registered no chain (the chain-less degeneracy). Union
542
548
  // with (1) — `add` dedupes by pair id, so a store row keeps its identity.
543
549
  for (const m of registry.getAllModels()) {
550
+ if (providerUsesCliLogin(m.provider)) {
551
+ add(m.provider, CLI_LOGIN_QUOTA_PREFIX, undefined, undefined);
552
+ continue;
553
+ }
544
554
  const chain = registry.getCredentialChain(m.provider) ?? [];
545
555
  for (const c of chain)
546
556
  add(m.provider, c.keyHashPrefix, c.label, maskSecret(c.key));
@@ -562,6 +572,7 @@ async function buildQuotaPairRows(registry, traceTracker) {
562
572
  outputTokens: row.outputTokens,
563
573
  cachedTokens: row.cachedTokens,
564
574
  costUsd: row.costUsd,
575
+ unpricedRequests: row.unpricedRequests,
565
576
  };
566
577
  }
567
578
  }
@@ -707,6 +718,13 @@ async function storeProviderViews(store, lang) {
707
718
  v.name = preset.name;
708
719
  if (preset.logo && !v.logo)
709
720
  v.logo = preset.logo;
721
+ v.authTypes = preset.authTypes;
722
+ v.keyHint = preset.keyHint;
723
+ // Credential-less preset: the def is the connection. Drop any stored
724
+ // key from the card summary so the console does not offer another one.
725
+ if (Array.isArray(preset.authTypes) && preset.authTypes.includes('none') && !preset.authTypes.some((t) => t === 'key' || t === 'webLogin')) {
726
+ v.auth = { connected: true };
727
+ }
710
728
  }
711
729
  }
712
730
  }
@@ -1385,10 +1403,12 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
1385
1403
  // environment-book-set switch (ADR-0007) and may change under a live server.
1386
1404
  const trafficRoot = () => path.join(getOcrHomeDir(), 'plugins', 'traffic');
1387
1405
  const TRAFFIC_TAIL = 500;
1388
- /** Per-side DISPLAY window handed to the dissector (and the hex preview).
1389
- * Capture is full fidelity on disk; only this read is bounded. */
1390
- const TRAFFIC_DISSECT_WINDOW = 32 * 1024;
1391
- /** Inline hex preview length (the drawer's hex fallback). */
1406
+ /** Per-side DISPLAY window handed to the dissector. Capture is full fidelity
1407
+ * on disk; only this read is bounded, per row on every poll — the drawer's
1408
+ * own render cap is DEFAULT_TRAFFIC_BODY_PREVIEW_BYTES. */
1409
+ const TRAFFIC_DISSECT_WINDOW = DEFAULT_TRAFFIC_DISSECT_WINDOW_BYTES;
1410
+ /** Inline hex preview length — first paint only. The drawer replaces it with
1411
+ * the token-addressed body, so keeping it small keeps every poll cheap. */
1392
1412
  const TRAFFIC_HEX_PREVIEW = 1024;
1393
1413
  /** Strict sidecar ref: `<YYYYMMDD>/<id>-<side>.bin`, no traversal. */
1394
1414
  const TRAFFIC_BODY_REF_RE = /^\d{8}\/[A-Za-z0-9._-]+\.bin$/;
@@ -1423,8 +1443,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
1423
1443
  try {
1424
1444
  const fd = fs.openSync(abs, 'r');
1425
1445
  try {
1426
- const buf = Buffer.alloc(TRAFFIC_DISSECT_WINDOW);
1427
- const read = fs.readSync(fd, buf, 0, TRAFFIC_DISSECT_WINDOW, 0);
1446
+ // Allocate the bytes the file actually has, not the window: a
1447
+ // 500-row tail decorates ~1000 sides per poll, and a full-window
1448
+ // buffer per side is the dominant cost (window × rows), while most
1449
+ // bodies are kilobytes.
1450
+ const take = Math.min(fs.fstatSync(fd).size, TRAFFIC_DISSECT_WINDOW);
1451
+ const buf = Buffer.allocUnsafe(take);
1452
+ const read = fs.readSync(fd, buf, 0, take, 0);
1428
1453
  return buf.subarray(0, read);
1429
1454
  }
1430
1455
  finally {
@@ -1526,25 +1551,57 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
1526
1551
  reply.header('content-disposition', `attachment; filename="${path.basename(abs)}"`);
1527
1552
  return reply.send(fs.createReadStream(abs));
1528
1553
  });
1529
- // 3A3. OS system proxy ownership for the inbound forward proxy: snapshot →
1530
- // point at 127.0.0.1:<port> → one-click restore (forward-proxy/system-proxy.ts).
1531
- app.get('/api/admin/system-proxy', async () => {
1532
- const fp = getRuntimeConfigRef()?.forwardProxy;
1554
+ // 3A3. OS system proxy ownership — ONE snapshot, TWO endpoints: the inbound
1555
+ // forward proxy (default) or the Clash core's mixed port. A target switch
1556
+ // rewrites the OS pointer without re-reading the pre-OCR snapshot; restore
1557
+ // always returns what the OS held before OCR first took ownership.
1558
+ const systemProxyPayload = async (req) => {
1559
+ const live = getRuntimeConfigRef();
1560
+ const fp = live?.forwardProxy;
1533
1561
  const port = fp?.port ?? DEFAULT_FORWARD_PROXY_PORT;
1562
+ const mixedPort = live?.proxy?.mihomo?.mixedPort ?? DEFAULT_MIHOMO_MIXED_PORT;
1534
1563
  const sys = await getSystemProxyStatus(port, osBypassHosts(fp?.rules));
1535
- return { status: 'ok', ...sys, proxyEnabled: Boolean(fp?.enabled) };
1536
- });
1537
- app.post('/api/admin/system-proxy/enable', async () => {
1538
- const fp = getRuntimeConfigRef()?.forwardProxy;
1564
+ const clashBypass = lanBypassHosts(process.platform);
1565
+ const clashRunning = (await getMihomoStatus()).running;
1566
+ return {
1567
+ status: 'ok',
1568
+ ...sys,
1569
+ proxyEnabled: Boolean(fp?.enabled),
1570
+ forward: { port, enabled: Boolean(fp?.enabled) },
1571
+ // The clash card names the bypass ITS target would write (LAN ranges),
1572
+ // not the inbound one on `override` (loopback + literal direct rows).
1573
+ clash: { mixedPort, running: clashRunning, override: buildOverride(clashBypass, process.platform) },
1574
+ // The PAC URL follows the origin THIS request reached, never the console
1575
+ // document's origin (a dev console on Vite would advertise a URL that
1576
+ // dies with its dev server).
1577
+ pacUrl: pacUrlFor(req.headers.host, req.protocol, live?.port),
1578
+ };
1579
+ };
1580
+ app.get('/api/admin/system-proxy', async (req) => systemProxyPayload(req));
1581
+ app.post('/api/admin/system-proxy/enable', async (req, reply) => {
1582
+ const body = (req.body ?? {});
1583
+ const live = getRuntimeConfigRef();
1584
+ if (body.target === 'clash') {
1585
+ // Pointing the OS at a dead port is one click away from a dead network:
1586
+ // the core must answer before it owns the OS proxy.
1587
+ if (!(await getMihomoStatus()).running) {
1588
+ reply.code(409);
1589
+ return { status: 'error', code: 'not-running' };
1590
+ }
1591
+ const mixedPort = live?.proxy?.mihomo?.mixedPort ?? DEFAULT_MIHOMO_MIXED_PORT;
1592
+ await enableSystemProxy(mixedPort, lanBypassHosts(process.platform), 'clash');
1593
+ return systemProxyPayload(req);
1594
+ }
1595
+ const fp = live?.forwardProxy;
1539
1596
  const port = fp?.port ?? DEFAULT_FORWARD_PROXY_PORT;
1540
- const sys = await enableSystemProxy(port, osBypassHosts(fp?.rules));
1541
- return { status: 'ok', ...sys };
1597
+ await enableSystemProxy(port, osBypassHosts(fp?.rules), 'forward');
1598
+ return systemProxyPayload(req);
1542
1599
  });
1543
- app.post('/api/admin/system-proxy/disable', async () => {
1600
+ app.post('/api/admin/system-proxy/disable', async (req) => {
1544
1601
  const fp = getRuntimeConfigRef()?.forwardProxy;
1545
1602
  const port = fp?.port ?? DEFAULT_FORWARD_PROXY_PORT;
1546
- const sys = await disableSystemProxy(port, osBypassHosts(fp?.rules));
1547
- return { status: 'ok', ...sys };
1603
+ await disableSystemProxy(port, osBypassHosts(fp?.rules));
1604
+ return systemProxyPayload(req);
1548
1605
  });
1549
1606
  // 3A4. Forward-proxy rule table (ADR-0018): lint + dry-run resolution. The
1550
1607
  // console renders the warning CODES through i18n and shows which rule a probe
@@ -1570,27 +1627,54 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
1570
1627
  // the wildcard's own attribution stays visible through `claimSources`.
1571
1628
  const claimed = [...listGatewayHosts()].filter((h) => h !== WILDCARD_HOST_CLAIM).sort();
1572
1629
  // Per-plugin attribution for the console's "decrypted without a rule" list:
1573
- // the SAME live registry `listGatewayHosts()` unions, so the two can never
1574
- // disagree — one is the host set, the other says who claimed it.
1630
+ // the SAME live registry the proxy legs read, so the two can never disagree —
1631
+ // one is the host set, the other says who claimed it and what leg that claim
1632
+ // owns (ADR-0018 Revision 5). The preview asks `claimEgressFor` — the very callback
1633
+ // the relay injects into `resolveHost` — because the tier that answers can be
1634
+ // the plugin's code, and a preview of a snapshot would be a second opinion.
1635
+ const claimOutcomes = (hosts) => hosts.map((host) => {
1636
+ const d = resolveHost(host, rules, {
1637
+ claimed: new Set(claimed), claimEgress: claimEgressFor, intercept,
1638
+ });
1639
+ return {
1640
+ host,
1641
+ action: d.action,
1642
+ tunnel: d.tunnel,
1643
+ reason: d.reason,
1644
+ egressClaim: d.egressClaim,
1645
+ ruleIndex: d.ruleIndex,
1646
+ };
1647
+ });
1575
1648
  const claimSources = [...listGateways().entries()]
1576
- .map(([pluginId, gw]) => ({
1577
- pluginId,
1578
- hosts: [...new Set(gw.hosts.filter((h) => h !== WILDCARD_HOST_CLAIM))].sort(),
1579
- }))
1649
+ .map(([pluginId, gw]) => {
1650
+ const hosts = [...new Set(gw.hosts.filter((h) => h !== WILDCARD_HOST_CLAIM))].sort();
1651
+ // The DISTINCT legs this plugin's claims ask for. One package normally
1652
+ // answers once — but a per-host hook may split, and a host two gateways
1653
+ // answer oppositely drops out entirely (no winner), which the dialog has
1654
+ // to be able to show rather than invent.
1655
+ const egress = [...new Set(hosts.map((h) => claimEgressFor(h)?.action))]
1656
+ .filter((e) => e !== undefined)
1657
+ .sort();
1658
+ return { pluginId, hosts, egress, outcomes: claimOutcomes(hosts) };
1659
+ })
1580
1660
  .filter((s) => s.hosts.length > 0)
1581
1661
  .sort((a, b) => a.pluginId.localeCompare(b.pluginId));
1582
1662
  const host = typeof body.host === 'string' ? body.host.trim() : '';
1583
1663
  return {
1584
1664
  status: 'ok',
1585
1665
  rules,
1586
- warnings: lintRules(rawRules, proxyEnabled, intercept),
1666
+ warnings: lintRules(rawRules, proxyEnabled, intercept, listClaimedEgress()),
1587
1667
  proxyEnabled,
1588
1668
  intercept,
1589
1669
  claimed,
1590
1670
  claimSources,
1591
1671
  // The resolver is the SAME function the proxy legs call, so the preview
1592
- // can never disagree with the live decision.
1593
- decision: host ? resolveHost(host, rules, { claimed: new Set(claimed), intercept }) : null,
1672
+ // can never disagree with the live decision — which is why the claim legs
1673
+ // ride in here too: omitting them would make an unsaved table preview as
1674
+ // `direct` while the relay already goes `proxy`.
1675
+ decision: host
1676
+ ? resolveHost(host, rules, { claimed: new Set(claimed), claimEgress: claimEgressFor, intercept })
1677
+ : null,
1594
1678
  };
1595
1679
  });
1596
1680
  // 3A5. One-click "tighten to allowlist" (ADR-0018 Revision 4). An install
@@ -1622,7 +1706,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
1622
1706
  status: 'ok',
1623
1707
  rules,
1624
1708
  intercept: DEFAULT_FORWARD_PROXY_INTERCEPT,
1625
- warnings: lintRules(rules, live?.proxy?.enabled === true, DEFAULT_FORWARD_PROXY_INTERCEPT),
1709
+ warnings: lintRules(rules, live?.proxy?.enabled === true, DEFAULT_FORWARD_PROXY_INTERCEPT, listClaimedEgress()),
1626
1710
  };
1627
1711
  });
1628
1712
  // 3B. Token usage aggregation from the trace ring: windowed totals plus
@@ -1915,6 +1999,14 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
1915
1999
  * NO tier ladder here: writing "ultra = broadest" made every role land on
1916
2000
  * `ultra`.
1917
2001
  */
2002
+ /**
2003
+ * Price sentence for the decision prompt. An UNPRICED model must not render
2004
+ * as `$0/$0`: the LLM reads these lines when choosing a candidate, so a
2005
+ * fabricated zero is an active instruction to prefer it as "free".
2006
+ */
2007
+ const priceLine = (p) => p
2008
+ ? `price $${p.input}/$${p.output} per 1M tokens in/out`
2009
+ : 'price unknown (no published dollar price — do NOT read this as free)';
1918
2010
  const describeCandidate = (rawId, note, cat) => {
1919
2011
  const m = registry.getModel(rawId);
1920
2012
  let body;
@@ -1922,7 +2014,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
1922
2014
  const tiers = registry.tiersOf(m);
1923
2015
  const parts = [
1924
2016
  `registered model; tiers=${tiers.length > 0 ? tiers.join('|') : 'none'}`,
1925
- `price $${m.pricing?.input ?? 0}/$${m.pricing?.output ?? 0} per 1M tokens in/out`,
2017
+ priceLine(m.pricing),
1926
2018
  ...catalogTokens(cat),
1927
2019
  ];
1928
2020
  if (m.wire === 'systemone') {
@@ -1950,7 +2042,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
1950
2042
  body =
1951
2043
  `variant of ${base.id} (pins reasoning_effort '${variant.reasoningEffort}'); ` +
1952
2044
  `tiers=${tiers.length > 0 ? tiers.join('|') : 'none'}; ` +
1953
- `price $${base.pricing?.input ?? 0}/$${base.pricing?.output ?? 0} per 1M tokens in/out` +
2045
+ priceLine(base.pricing) +
1954
2046
  (catTokens.length > 0 ? `; ${catTokens.join('; ')}` : '') +
1955
2047
  `; wire=${base.wire ?? 'unknown'}`;
1956
2048
  }
@@ -2456,8 +2548,8 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
2456
2548
  // tiers.exclude filter. No preview; what the runtime would actually use.
2457
2549
  //
2458
2550
  // Read-only on purpose: the previous version called applyTierConfigNow()
2459
- // here as a "force-commit view" trick, but that mutated m.tier / m.unclassified
2460
- // on every Live tab open — a stealth commit with no save event behind it.
2551
+ // here as a "force-commit view" trick, but that mutated m.tier on every
2552
+ // Live tab open — a stealth commit with no save event behind it.
2461
2553
  // The console must NEVER write routing state from a GET. Out-of-band file
2462
2554
  // edits get picked up on the next save commit (the console already triggers
2463
2555
  // applyTierConfigNow in handleSaveConfig / handleSaveRawYaml).
@@ -2513,13 +2605,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
2513
2605
  const members = expanded.tiers;
2514
2606
  const modelIds = registry
2515
2607
  .getAllModels()
2516
- .filter((m) => m.tierMatch)
2608
+ .filter((m) => m.autoTier)
2517
2609
  .map((m) => m.id);
2518
2610
  const orphans = [];
2519
2611
  for (const tier of MEMBER_TIER_ORDER) {
2520
2612
  for (const rule of members[tier]) {
2521
2613
  // exact rules = combo-expanded ids: registered by construction, and a
2522
- // hand-configured member (no tierMatch) is not in modelIds — flagging
2614
+ // hand-configured member (no autoTier stamp) is not in modelIds — flagging
2523
2615
  // them here would be a false positive; ref liveness is deadCombo's job
2524
2616
  if (rule.exact)
2525
2617
  continue;
@@ -2539,7 +2631,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
2539
2631
  // End-to-end tier test — one REAL minimal completion pinned to the tier via
2540
2632
  // the bare tier alias: the same force_tier path a client's
2541
2633
  // `model: "pro"` request takes (tier aliases are reserved gateway ids,
2542
- // never classifier-routed). One run only
2634
+ // never pool-routed). One run only
2543
2635
  // exercises the SELECTED member (the default credential, or the weighted/round-robin
2544
2636
  // pick), never the whole pool — deep per-model checks stay on the providers
2545
2637
  // page. An EMPTY tier degrades inside getModelForTier (the session-pin birth
@@ -3457,12 +3549,33 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3457
3549
  return reply.status(400).send({ success: false, error: err.message });
3458
3550
  }
3459
3551
  },
3552
+ /** Connect a preset whose plugin owns login. Materializes the def and
3553
+ * lifts a deletion tombstone. Refuses a provider that still takes a key. */
3554
+ connectLocal: async (req, reply) => {
3555
+ const { id } = req.params;
3556
+ const { providerDeclinesCredentials, ensurePresetProvider } = await import('../plugins/host.js');
3557
+ if (!providerDeclinesCredentials(id)) {
3558
+ return reply.status(400).send({ success: false, error: `Provider '${id}' takes a credential` });
3559
+ }
3560
+ if (!(await ensurePresetProvider(id))) {
3561
+ return reply.status(404).send({ success: false, error: `Provider '${id}' is not a plugin preset` });
3562
+ }
3563
+ return { status: 'ok', success: true, connected: true };
3564
+ },
3460
3565
  /** Resolve the model-service plugin serving a provider def's wire
3461
3566
  * (plugin wires only — the vendor protocol stays in the plugin). */
3462
3567
  webLoginPluginFor: async (id) => {
3463
3568
  const { getProviderNodeById } = await import('../opencode/user-config.js');
3464
3569
  const { wireFor } = await import('../providers/wire.js');
3465
- const def = getProviderNodeById(id);
3570
+ let def = getProviderNodeById(id);
3571
+ if (!def) {
3572
+ // The catalog row comes from the manifest, so the login button stays
3573
+ // offered even for a provider the operator deleted. A click IS connect
3574
+ // intent: materialize the preset (and lift its deletion tombstone).
3575
+ const { ensurePresetProvider } = await import('../plugins/host.js');
3576
+ if (await ensurePresetProvider(id))
3577
+ def = getProviderNodeById(id);
3578
+ }
3466
3579
  if (!def)
3467
3580
  return { error: `provider '${id}' not found` };
3468
3581
  const node = def;
@@ -3481,7 +3594,9 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3481
3594
  if ('error' in r)
3482
3595
  return reply.code(404).send({ success: false, error: r.error });
3483
3596
  try {
3484
- const { authUrl } = await r.plugin.webLogin.start({ baseURL: r.baseURL });
3597
+ // `provider: id` lets the plugin hand this call to `host.fetch` and have
3598
+ // the operator's proxy split govern sign-in too (ADR-0022).
3599
+ const { authUrl } = await r.plugin.webLogin.start({ baseURL: r.baseURL, provider: id });
3485
3600
  return { status: 'ok', authUrl };
3486
3601
  }
3487
3602
  catch (err) {
@@ -3494,7 +3609,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3494
3609
  if ('error' in r)
3495
3610
  return reply.code(404).send({ success: false, error: r.error });
3496
3611
  try {
3497
- const result = await r.plugin.webLogin.poll({ baseURL: r.baseURL });
3612
+ const result = await r.plugin.webLogin.poll({ baseURL: r.baseURL, provider: id });
3498
3613
  if (!result.done) {
3499
3614
  return { status: 'ok', done: false, error: result.error };
3500
3615
  }
@@ -3533,7 +3648,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3533
3648
  return reply.code(404).send({ success: false, error: `provider '${id}' web-login has no manual token submission` });
3534
3649
  }
3535
3650
  try {
3536
- const result = await r.plugin.webLogin.submit({ baseURL: r.baseURL, code });
3651
+ const result = await r.plugin.webLogin.submit({ baseURL: r.baseURL, code, provider: id });
3537
3652
  if (!result.ok)
3538
3653
  return { status: 'ok', connected: false, error: result.error };
3539
3654
  // Same wiring as a finished poll: credential-store write + connect-time
@@ -3674,6 +3789,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3674
3789
  for (const c of enabledChain)
3675
3790
  probeAttempts.push({ key: c.key, credentialId: c.credentialId });
3676
3791
  }
3792
+ if (probeAttempts.length === 0) {
3793
+ // `none` owns login outside the credential store. One empty attempt
3794
+ // lets the plugin probe run; a missing key is not a failure.
3795
+ const { providerDeclinesCredentials } = await import('../plugins/host.js');
3796
+ if (providerDeclinesCredentials(id))
3797
+ probeAttempts.push({ key: '' });
3798
+ }
3677
3799
  if (probeAttempts.length === 0) {
3678
3800
  // Every stored key parked: say THAT, not the misleading no-key/OAuth
3679
3801
  // hint (the operator must know a takedown is the cause). Reaching this
@@ -3723,6 +3845,12 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3723
3845
  });
3724
3846
  }
3725
3847
  const { probeProvider, probeKindFor } = await import('../opencode/probe.js');
3848
+ // The verdict's egress (ADR-0018 / ADR-0022 vocabulary) is taken from the
3849
+ // attempt that produced it and rides on the reply, so "Test" answers "did
3850
+ // my model-scoped split apply" — the include/exclude page can only state
3851
+ // intent, never what this provider actually dialed.
3852
+ let egress;
3853
+ let egressProxy;
3726
3854
  const { baseForWire } = await import('../providers/wire.js');
3727
3855
  const { sanitizeExtraHeaders } = await import('../utils/http-headers.js');
3728
3856
  // Two nested rotation loops, both stopping on one green:
@@ -3754,16 +3882,37 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3754
3882
  // Responses API) beats provider-level npm when picking the wire shape.
3755
3883
  const modelNpm = cat?.models.find((mm) => mm.id === modelId)?.npm;
3756
3884
  const kind = probeKindFor(cat?.api, modelNpm || def?.npm || cat?.npm);
3885
+ // The model's own capability flags, read from the def the console
3886
+ // holds — a plugin probe builds a REAL request, so guessing
3887
+ // "not a reasoning model" makes it send thinking-off to a model that
3888
+ // always thinks and report 400 for a model inference serves fine.
3889
+ const modelDef = defs?.[modelId];
3890
+ const catModel = cat?.models.find((mm) => mm.id === modelId);
3757
3891
  result = await probeProvider({
3758
3892
  baseURL: baseForWire(kind, baseURL),
3759
3893
  apiKey: attempt.key,
3760
3894
  model: modelId,
3761
3895
  provider: id,
3762
3896
  kind,
3897
+ capabilities: {
3898
+ reasoning: modelDef?.reasoning === true || Array.isArray(modelDef?.reasoningOptions) && modelDef.reasoningOptions.length > 0 || catModel?.reasoning === true,
3899
+ vision: modelDef?.attachment === true || catModel?.modalities?.input?.includes('image') === true,
3900
+ },
3763
3901
  headers: sanitizeExtraHeaders(def?.options?.headers
3764
3902
  ? Object.fromEntries(Object.entries(def.options.headers).map(([k, v]) => [k, expandEnvTemplate(String(v))]))
3765
3903
  : undefined),
3766
3904
  });
3905
+ // Stamp the egress the MOMENT the probe answers, before any break:
3906
+ // `break probes` (a green verdict, or a mount failure) skips the rest
3907
+ // of the loop body, and the operator's question — did MY split apply
3908
+ // to this call — must be answered on success too, not only when the
3909
+ // rotation happens to fall through. Assign UNCONDITIONALLY: the
3910
+ // verdict belongs to the attempt that produced it, so its egress is
3911
+ // the answer even when that attempt reports UNKNOWN (a pre-dial
3912
+ // failure) — keeping a prior attempt's stamp would describe a dial
3913
+ // the verdict never made (model rotation can switch the wire/baseURL).
3914
+ egress = result.egress;
3915
+ egressProxy = result.egressProxy;
3767
3916
  if (result.ok)
3768
3917
  break probes;
3769
3918
  // Key-scoped refusal → this key is done, hand over to the next one.
@@ -3796,6 +3945,8 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3796
3945
  ...(tried.length > 1 ? { triedModels: tried } : {}),
3797
3946
  ...(triedCredentials.length > 1 ? { triedCredentials } : {}),
3798
3947
  ...(credentialMeta ? { credential: credentialMeta } : {}),
3948
+ ...(egress ? { egress } : {}),
3949
+ ...(egressProxy ? { egressProxy } : {}),
3799
3950
  ...result,
3800
3951
  };
3801
3952
  },
@@ -3847,6 +3998,12 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
3847
3998
  const result = deleteProviderDef(id);
3848
3999
  if (!result.success)
3849
4000
  return reply.status(400).send(result);
4001
+ // Delete is intent: without this, the next plugin reload/install sees
4002
+ // the preset's def missing and re-creates it (the row reappears on the
4003
+ // Connected surface). A surviving credential still re-creates a node
4004
+ // through the boot bind sweep — credential truth outranks the def.
4005
+ const { forgetProviderRegistration } = await import('../plugins/host.js');
4006
+ forgetProviderRegistration(id);
3850
4007
  // Decision 8 double confirmation is enforced by the console UI
3851
4008
  // (purgeAuth opt-in) — server-side the loop reports honestly.
3852
4009
  const purge = purgeAuth ? await purgeProviderCredentials(store, id) : null;
@@ -4615,6 +4772,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
4615
4772
  app.post(`${prefix}/opencode/providers`, withPoolSync(registry, ocHandlers.create));
4616
4773
  app.patch(`${prefix}/opencode/providers/:id`, withPoolSync(registry, ocHandlers.update));
4617
4774
  app.post(`${prefix}/opencode/providers/:id/connect`, withPoolSync(registry, ocHandlers.connect));
4775
+ app.post(`${prefix}/opencode/providers/:id/connect-local`, withPoolSync(registry, ocHandlers.connectLocal));
4618
4776
  // Generic plugin web-authorization seam (device flow): start opens the
4619
4777
  // vendor login page; poll returns done+token and wires the fresh token
4620
4778
  // into the credential store. The plugin owns the whole protocol.
@@ -4812,12 +4970,15 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
4812
4970
  const { installPluginPackage, packageIdOf, pluginPackageZip, listInstalledPlugins: listing } = await import('../plugins/host.js');
4813
4971
  // Snapshot the version this upload is about to REPLACE (a packaged one
4814
4972
  // — a dev-tree plugin is not ours to materialize here). A failed upgrade
4815
- // must not delete a working install.
4973
+ // must not delete a working install. `disabled` does NOT disqualify the
4974
+ // snapshot: a switched-off package is still an install the operator
4975
+ // owns, and a broken upload over it would otherwise leave them with
4976
+ // nothing to roll back to.
4816
4977
  let previous;
4817
4978
  try {
4818
4979
  const target = packageIdOf(new Uint8Array(bytes));
4819
4980
  const existing = listing().find((p) => p.id === target);
4820
- if (existing?.source === 'packaged' && !existing.disabled)
4981
+ if (existing?.source === 'packaged')
4821
4982
  previous = await pluginPackageZip(target);
4822
4983
  }
4823
4984
  catch {
@@ -4827,8 +4988,24 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
4827
4988
  const { loadInstalledPlugins, syncPluginPresets, listInstalledPlugins } = await import('../plugins/host.js');
4828
4989
  await loadInstalledPlugins();
4829
4990
  const plugins = listInstalledPlugins();
4830
- const view = plugins.find((p) => p.id === installed && !p.disabled);
4831
- if (!view?.loaded) {
4991
+ // An engine-INCOMPATIBLE package is not a broken one: it is on disk,
4992
+ // it is listed as disabled, and it becomes usable in place once the
4993
+ // matching side is updated. Discarding it would only make the operator
4994
+ // upload the same file again after that update, so the discard /
4995
+ // rollback path below stays reserved for packages that genuinely fail
4996
+ // to load. The test is the ROW'S OWN flag, never `disabled && !loaded`
4997
+ // — an operator-disabled package satisfies that shape too, and a
4998
+ // failed load of one must still be discarded and rolled back.
4999
+ //
5000
+ // An UPLOAD is normally refused before it ever lands
5001
+ // (`installPluginPackage` → `assertSupportedPluginApi`), so a 400 with
5002
+ // the core sentence is the common answer. This branch covers the case
5003
+ // that reaches the disk anyway (a package that became incompatible
5004
+ // under a downgraded gateway), where the refusal must be reported and
5005
+ // NOT followed by a discard.
5006
+ const view = plugins.find((p) => p.id === installed);
5007
+ const incompatible = view?.incompatible === true;
5008
+ if (!view?.loaded && !incompatible) {
4832
5009
  // a package that cannot load would re-fail every boot — discard it;
4833
5010
  // discard BEFORE preset sync / pool refresh so a broken package
4834
5011
  // registers nothing
@@ -4858,10 +5035,24 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
4858
5035
  }
4859
5036
  // presets register at install time (same contract as boot/reload) —
4860
5037
  // after a verified successful load, BEFORE the pool refresh so the
4861
- // fresh defs are routable immediately
5038
+ // defs are routable immediately on the next dispatch. An engine-refused
5039
+ // package reaches this line too: it loaded nothing, so `syncPluginPresets`
5040
+ // has nothing of it to register, and its row stays DISABLED in `plugins`.
4862
5041
  const registered = await syncPluginPresets();
4863
5042
  await refreshDirectPool(registry);
4864
- return { status: 'ok', id: installed, version: installedVersion, replacedVersion, plugins, registered };
5043
+ return {
5044
+ status: 'ok',
5045
+ id: installed,
5046
+ version: installedVersion,
5047
+ replacedVersion,
5048
+ plugins,
5049
+ registered,
5050
+ // Kept in the 200 body so the console can toast the honest outcome:
5051
+ // the bytes landed, but the package answers nothing until one side
5052
+ // is updated. A green "installed" toast over a red row is the one
5053
+ // reading an operator must not be left with.
5054
+ ...(incompatible ? { incompatible: true, error: view.error } : {}),
5055
+ };
4865
5056
  }
4866
5057
  catch (err) {
4867
5058
  return reply.code(400).send({ status: 'error', error: err instanceof Error ? err.message : String(err) });
@@ -5152,7 +5343,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
5152
5343
  // offer ONLY these — anything else would be clamped right back by
5153
5344
  // downgradeReasoning. `[]` is a REAL answer ("no explicit level
5154
5345
  // control", e.g. a toggle-only model), never "unknown".
5155
- efforts: modelSupportsEfforts(m.supportedReasoningEfforts, m.supportsReasoningEffort) ?? [],
5346
+ efforts: modelSupportsEfforts(m.supportedReasoningEfforts, m.supportsReasoningEffort, m.reasoningDisableable) ?? [],
5156
5347
  // Resolved upstream wire (model-level npm beats provider npm, see
5157
5348
  // providers/wire.ts). Console pickers MUST read it from here instead of
5158
5349
  // re-deriving it from the provider's npm string — `systemone` marks a
@@ -1,5 +1,7 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
+ import type { OsProxyEndpoint } from '../forward-proxy/system-proxy.js';
2
3
  import { redactSubscriptionUrl } from '../proxy/mihomo-config.js';
3
4
  export declare function registerMihomoRoutes(app: FastifyInstance): void;
5
+ export declare function setUrlProbeOsProxyReaderForTests(reader?: () => Promise<OsProxyEndpoint | undefined>): void;
4
6
  /** Re-export so a log site that only has a URL can redact it without importing the generator. */
5
7
  export { redactSubscriptionUrl };