omnicell-router 0.7.0 → 0.8.2
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/backend/dist/cli/clients/activity.d.ts +35 -0
- package/backend/dist/cli/clients/activity.js +67 -0
- package/backend/dist/cli/clients/base.d.ts +13 -2
- package/backend/dist/cli/clients/claude.d.ts +2 -2
- package/backend/dist/cli/clients/codex.d.ts +2 -2
- package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
- package/backend/dist/cli/clients/core-adapters.js +3 -4
- package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
- package/backend/dist/cli/clients/cursor-proxy.js +421 -0
- package/backend/dist/cli/clients/dsh.d.ts +2 -2
- package/backend/dist/cli/clients/grok.d.ts +2 -2
- package/backend/dist/cli/clients/index.d.ts +8 -1
- package/backend/dist/cli/clients/index.js +55 -21
- package/backend/dist/cli/clients/kimi.d.ts +2 -2
- package/backend/dist/cli/clients/launcher.d.ts +8 -0
- package/backend/dist/cli/clients/model-meta.js +1 -1
- package/backend/dist/cli/clients/omp.d.ts +2 -2
- package/backend/dist/cli/clients/openclaw.d.ts +2 -2
- package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
- package/backend/dist/cli/clients/opencode-proxy.js +351 -0
- package/backend/dist/cli/clients/opencode.d.ts +2 -2
- package/backend/dist/cli/clients/pi.d.ts +2 -2
- package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
- package/backend/dist/cli/clients/plugin-adapters.js +6 -29
- package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
- package/backend/dist/cli/clients/qoder-proxy.js +497 -0
- package/backend/dist/cli/clients/reserved.d.ts +2 -6
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
- package/backend/dist/cli/index.js +60 -9
- package/backend/dist/cli/types.d.ts +29 -8
- package/backend/dist/compression/caveman-prompts.d.ts +1 -1
- package/backend/dist/config/comments-en.js +6 -12
- package/backend/dist/config/comments-zh.js +6 -12
- package/backend/dist/config/defaults.d.ts +56 -1
- package/backend/dist/config/defaults.js +68 -0
- package/backend/dist/config/index.d.ts +9 -2
- package/backend/dist/config/index.js +26 -3
- package/backend/dist/config/types.d.ts +55 -43
- package/backend/dist/forward-proxy/egress.d.ts +10 -2
- package/backend/dist/forward-proxy/egress.js +42 -4
- package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/forward-proxy/ordered-relay.js +46 -0
- package/backend/dist/forward-proxy/rules.d.ts +66 -19
- package/backend/dist/forward-proxy/rules.js +61 -14
- package/backend/dist/forward-proxy/server.js +226 -77
- package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
- package/backend/dist/forward-proxy/system-proxy.js +199 -22
- package/backend/dist/harness/common/market.d.ts +3 -3
- package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
- package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
- package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
- package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
- package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
- package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
- package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
- package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
- package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
- package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
- package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
- package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
- package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
- package/backend/dist/harness/translation.js +64 -21
- package/backend/dist/harness/types.d.ts +1 -1
- package/backend/dist/harness/types.js +1 -1
- package/backend/dist/index.js +31 -18
- package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
- package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
- package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
- package/backend/dist/ir/adapters/anthropic.js +788 -0
- package/backend/dist/ir/adapters/chat.d.ts +15 -0
- package/backend/dist/ir/adapters/chat.js +602 -0
- package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
- package/backend/dist/ir/adapters/google-stream.js +242 -0
- package/backend/dist/ir/adapters/google.d.ts +9 -0
- package/backend/dist/ir/adapters/google.js +317 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
- package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
- package/backend/dist/ir/adapters/openai-responses.js +26 -1
- package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
- package/backend/dist/ir/adapters/responses-output.js +348 -0
- package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
- package/backend/dist/ir/adapters/responses-stream.js +178 -0
- package/backend/dist/ir/adapters/responses.d.ts +14 -0
- package/backend/dist/ir/adapters/responses.js +646 -0
- package/backend/dist/ir/errors.d.ts +2 -2
- package/backend/dist/ir/types.d.ts +2 -1
- package/backend/dist/metrics/request-cost.d.ts +11 -2
- package/backend/dist/metrics/request-cost.js +12 -3
- package/backend/dist/observability/request-identity.d.ts +1 -1
- package/backend/dist/observability/trace-id.d.ts +40 -0
- package/backend/dist/observability/trace-id.js +134 -0
- package/backend/dist/observability/upstream-events.d.ts +82 -60
- package/backend/dist/observability/upstream-events.js +142 -67
- package/backend/dist/opencode/catalog/types.d.ts +9 -0
- package/backend/dist/opencode/credentials/types.d.ts +2 -2
- package/backend/dist/opencode/probe.d.ts +24 -1
- package/backend/dist/opencode/probe.js +28 -4
- package/backend/dist/opencode/user-config.d.ts +5 -0
- package/backend/dist/pipeline/directives.d.ts +6 -2
- package/backend/dist/pipeline/directives.js +7 -3
- package/backend/dist/pipeline/orchestrator.d.ts +28 -27
- package/backend/dist/pipeline/orchestrator.js +220 -194
- package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
- package/backend/dist/pipeline/unresolved-model.js +43 -0
- package/backend/dist/plugins/catalog-def.d.ts +143 -0
- package/backend/dist/plugins/catalog-def.js +177 -0
- package/backend/dist/plugins/gateways.d.ts +62 -3
- package/backend/dist/plugins/gateways.js +139 -2
- package/backend/dist/plugins/host.d.ts +42 -5
- package/backend/dist/plugins/host.js +454 -38
- package/backend/dist/plugins/manifest.d.ts +119 -10
- package/backend/dist/plugins/manifest.js +265 -14
- package/backend/dist/plugins/pack.js +26 -0
- package/backend/dist/plugins/types.d.ts +187 -21
- package/backend/dist/protocols/systemone/convert.d.ts +1 -0
- package/backend/dist/protocols/systemone/convert.js +6 -1
- package/backend/dist/protocols/systemone/decide.js +18 -8
- package/backend/dist/providers/anthropic-messages.d.ts +12 -0
- package/backend/dist/providers/anthropic-messages.js +53 -0
- package/backend/dist/providers/anthropic.d.ts +7 -8
- package/backend/dist/providers/anthropic.js +36 -324
- package/backend/dist/providers/base.d.ts +14 -2
- package/backend/dist/providers/boot-direct.js +68 -38
- package/backend/dist/providers/dispatch.d.ts +5 -19
- package/backend/dist/providers/dispatch.js +46 -58
- package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
- package/backend/dist/providers/executors/anthropic-messages.js +3 -0
- package/backend/dist/providers/executors/dispatch.d.ts +16 -2
- package/backend/dist/providers/executors/dispatch.js +39 -9
- package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
- package/backend/dist/providers/executors/google-gemini.js +3 -0
- package/backend/dist/providers/executors/http-stream.js +16 -3
- package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
- package/backend/dist/providers/executors/openai-chat.js +3 -0
- package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
- package/backend/dist/providers/executors/openai-responses.js +3 -0
- package/backend/dist/providers/executors/plugin-adapter.js +4 -4
- package/backend/dist/providers/google-gemini.d.ts +12 -0
- package/backend/dist/providers/google-gemini.js +50 -0
- package/backend/dist/providers/google.d.ts +7 -8
- package/backend/dist/providers/google.js +35 -308
- package/backend/dist/providers/http-json.d.ts +19 -0
- package/backend/dist/providers/http-json.js +104 -0
- package/backend/dist/providers/http-stream.d.ts +52 -0
- package/backend/dist/providers/http-stream.js +423 -0
- package/backend/dist/providers/member-match.d.ts +4 -5
- package/backend/dist/providers/member-match.js +4 -5
- package/backend/dist/providers/openai-chat.d.ts +13 -0
- package/backend/dist/providers/openai-chat.js +99 -0
- package/backend/dist/providers/openai-compatible.d.ts +7 -4
- package/backend/dist/providers/openai-compatible.js +71 -368
- package/backend/dist/providers/openai-responses.d.ts +12 -0
- package/backend/dist/providers/openai-responses.js +68 -0
- package/backend/dist/providers/opencode-proxy.d.ts +5 -5
- package/backend/dist/providers/opencode-proxy.js +49 -125
- package/backend/dist/providers/plugin-adapter.d.ts +9 -0
- package/backend/dist/providers/plugin-adapter.js +31 -0
- package/backend/dist/providers/registry.d.ts +49 -24
- package/backend/dist/providers/registry.js +97 -55
- package/backend/dist/providers/responses.d.ts +7 -28
- package/backend/dist/providers/responses.js +45 -253
- package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
- package/backend/dist/providers/tool-markup-leak.js +57 -0
- package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
- package/backend/dist/providers/tool-markup-recovery.js +786 -0
- package/backend/dist/providers/virtual-meta.d.ts +21 -2
- package/backend/dist/providers/virtual-meta.js +49 -9
- package/backend/dist/proxy/asset-download.d.ts +54 -0
- package/backend/dist/proxy/asset-download.js +420 -0
- package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
- package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
- package/backend/dist/proxy/mihomo-binary.js +62 -51
- package/backend/dist/proxy/mihomo-client.js +15 -1
- package/backend/dist/proxy/mihomo-config.js +11 -2
- package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/proxy/mihomo-geo.js +213 -0
- package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
- package/backend/dist/proxy/mihomo-logs.js +70 -0
- package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
- package/backend/dist/proxy/mihomo-pac.js +15 -0
- package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
- package/backend/dist/proxy/mihomo-rules-import.js +7 -7
- package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
- package/backend/dist/proxy/mihomo-sidecar.js +148 -26
- package/backend/dist/quota/adapters/minimax.js +36 -13
- package/backend/dist/quota/cli-login.d.ts +8 -0
- package/backend/dist/quota/cli-login.js +18 -0
- package/backend/dist/quota/declarations.js +10 -0
- package/backend/dist/quota/dsl.js +18 -5
- package/backend/dist/quota/engine.d.ts +22 -1
- package/backend/dist/quota/engine.js +170 -29
- package/backend/dist/quota/prober.d.ts +5 -0
- package/backend/dist/quota/prober.js +11 -2
- package/backend/dist/quota/types.d.ts +87 -8
- package/backend/dist/quota/verdict.d.ts +35 -0
- package/backend/dist/quota/verdict.js +135 -0
- package/backend/dist/ratelimit/admission.d.ts +131 -0
- package/backend/dist/ratelimit/admission.js +233 -0
- package/backend/dist/ratelimit/rate-limiter.js +6 -0
- package/backend/dist/resilience/types.d.ts +2 -2
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +5 -8
- package/backend/dist/routes/console.js +248 -52
- package/backend/dist/routes/mihomo.d.ts +2 -0
- package/backend/dist/routes/mihomo.js +334 -29
- package/backend/dist/routes/responses.d.ts +87 -8
- package/backend/dist/routes/responses.js +314 -33
- package/backend/dist/server.js +34 -6
- package/backend/dist/session/session-manager.d.ts +6 -0
- package/backend/dist/session/session-manager.js +20 -9
- package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
- package/backend/dist/surfaces/chat-pipeline.js +17 -7
- package/backend/dist/surfaces/chat.js +15 -0
- package/backend/dist/surfaces/decision-pipeline.js +7 -10
- package/backend/dist/surfaces/direct-forward.d.ts +3 -0
- package/backend/dist/surfaces/direct-forward.js +206 -0
- package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
- package/backend/dist/surfaces/rate-limit-response.js +57 -0
- package/backend/dist/surfaces/types.d.ts +11 -0
- package/backend/dist/trace/tracker.d.ts +32 -1
- package/backend/dist/trace/tracker.js +29 -4
- package/backend/dist/types/router.d.ts +34 -12
- package/backend/dist/types/router.js +35 -6
- package/backend/dist/utils/chat-stream.d.ts +21 -8
- package/backend/dist/utils/chat-stream.js +46 -9
- package/backend/dist/utils/event-ring.d.ts +4 -0
- package/backend/dist/utils/event-ring.js +4 -0
- package/backend/dist/utils/popularity.js +29 -4
- package/backend/dist/utils/proxy.d.ts +7 -0
- package/backend/dist/utils/proxy.js +35 -10
- package/backend/dist/utils/retry-after.d.ts +21 -0
- package/backend/dist/utils/retry-after.js +36 -0
- package/bin/ocr.js +2 -2
- package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
- package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
- package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
- package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { getAllClientStatuses, setupClient, teardownClient } from '../cli/clients/index.js';
|
|
4
|
+
import { clientActivitySnapshot } from '../cli/clients/activity.js';
|
|
4
5
|
import { VIRTUAL_AUTO_IDS } from '../cli/types.js';
|
|
5
6
|
import { MEMBER_TIER_ORDER } from '../providers/member-match.js';
|
|
6
7
|
import { refreshDirectPool } from '../providers/boot-direct.js';
|
|
@@ -22,10 +23,10 @@ import { appendRoutingLedger } from '../router/routing-ledger.js';
|
|
|
22
23
|
import { Layer2Decision } from '../router/layer2-decision.js';
|
|
23
24
|
import { EFFORT_LADDER, modelSupportsEfforts } from '../types/router.js';
|
|
24
25
|
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';
|
|
26
|
+
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
27
|
import { initProxyConfig, proxiedFetch } from '../utils/proxy.js';
|
|
27
28
|
import { registerMihomoRoutes } from './mihomo.js';
|
|
28
|
-
import { reconcileMihomoSidecar } from '../proxy/mihomo-sidecar.js';
|
|
29
|
+
import { reconcileMihomoSidecar, getMihomoStatus } from '../proxy/mihomo-sidecar.js';
|
|
29
30
|
import { getOcrHomeDir } from '../cli/paths.js';
|
|
30
31
|
import { getHeadroomSidecarStatus, startHeadroomSidecar, stopHeadroomSidecar } from '../compression/headroom-sidecar.js';
|
|
31
32
|
import { APP_VERSION } from '../version.js';
|
|
@@ -35,11 +36,13 @@ import { caCertPath, describeCa, ensureCa, resolveCaDir } from '../forward-proxy
|
|
|
35
36
|
import { probeCaTrustedCached } from '../forward-proxy/ca-trust.js';
|
|
36
37
|
import { getForwardProxyStatus } from '../forward-proxy/status.js';
|
|
37
38
|
import { lintRules, normalizeRules, osBypassHosts, resolveHost, } from '../forward-proxy/rules.js';
|
|
38
|
-
import { listGatewayHosts, WILDCARD_HOST_CLAIM } from '../plugins/gateways.js';
|
|
39
|
+
import { listGatewayHosts, listClaimedEgress, claimEgressFor, WILDCARD_HOST_CLAIM } from '../plugins/gateways.js';
|
|
39
40
|
import { listProxyAccessEvents, readProxyAccessHistory, clearProxyAccessLog, deletePersistedProxyEvents, forgetProxyAccessRingEvents, proxyAccessLogSettings, proxyAccessBodyPath } from '../forward-proxy/access-log.js';
|
|
40
41
|
import { hideLiveEvents, liveHiddenProxyIds, liveHiddenPluginKeys } from '../observability/traffic-live-hidden.js';
|
|
41
|
-
import { getSystemProxyStatus, enableSystemProxy, disableSystemProxy } from '../forward-proxy/system-proxy.js';
|
|
42
|
+
import { getSystemProxyStatus, enableSystemProxy, disableSystemProxy, buildOverride, lanBypassHosts } from '../forward-proxy/system-proxy.js';
|
|
43
|
+
import { pacUrlFor } from '../proxy/mihomo-pac.js';
|
|
42
44
|
import { keyHashPrefix } from '../opencode/credentials/types.js';
|
|
45
|
+
import { CLI_LOGIN_QUOTA_PREFIX, providerUsesCliLogin } from '../quota/cli-login.js';
|
|
43
46
|
import { CLASSIFIER_TAXONOMY } from '../resilience/index.js';
|
|
44
47
|
import { maskSecret, isValidProviderId, PROVIDER_ID_RULE, getProviderNodeById } from '../opencode/user-config.js';
|
|
45
48
|
import { listOpenCodeAgentsLive } from '../opencode/agents.js';
|
|
@@ -520,6 +523,10 @@ async function buildQuotaPairRows(registry, traceTracker) {
|
|
|
520
523
|
overview = [];
|
|
521
524
|
}
|
|
522
525
|
for (const o of overview) {
|
|
526
|
+
if (providerUsesCliLogin(o.providerId)) {
|
|
527
|
+
add(o.providerId, CLI_LOGIN_QUOTA_PREFIX, undefined, undefined);
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
523
530
|
let metas = [];
|
|
524
531
|
try {
|
|
525
532
|
metas = store.listCredentials(o.providerId);
|
|
@@ -541,6 +548,10 @@ async function buildQuotaPairRows(registry, traceTracker) {
|
|
|
541
548
|
// when a provider registered no chain (the chain-less degeneracy). Union
|
|
542
549
|
// with (1) — `add` dedupes by pair id, so a store row keeps its identity.
|
|
543
550
|
for (const m of registry.getAllModels()) {
|
|
551
|
+
if (providerUsesCliLogin(m.provider)) {
|
|
552
|
+
add(m.provider, CLI_LOGIN_QUOTA_PREFIX, undefined, undefined);
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
544
555
|
const chain = registry.getCredentialChain(m.provider) ?? [];
|
|
545
556
|
for (const c of chain)
|
|
546
557
|
add(m.provider, c.keyHashPrefix, c.label, maskSecret(c.key));
|
|
@@ -562,6 +573,7 @@ async function buildQuotaPairRows(registry, traceTracker) {
|
|
|
562
573
|
outputTokens: row.outputTokens,
|
|
563
574
|
cachedTokens: row.cachedTokens,
|
|
564
575
|
costUsd: row.costUsd,
|
|
576
|
+
unpricedRequests: row.unpricedRequests,
|
|
565
577
|
};
|
|
566
578
|
}
|
|
567
579
|
}
|
|
@@ -707,6 +719,13 @@ async function storeProviderViews(store, lang) {
|
|
|
707
719
|
v.name = preset.name;
|
|
708
720
|
if (preset.logo && !v.logo)
|
|
709
721
|
v.logo = preset.logo;
|
|
722
|
+
v.authTypes = preset.authTypes;
|
|
723
|
+
v.keyHint = preset.keyHint;
|
|
724
|
+
// Credential-less preset: the def is the connection. Drop any stored
|
|
725
|
+
// key from the card summary so the console does not offer another one.
|
|
726
|
+
if (Array.isArray(preset.authTypes) && preset.authTypes.includes('none') && !preset.authTypes.some((t) => t === 'key' || t === 'webLogin')) {
|
|
727
|
+
v.auth = { connected: true };
|
|
728
|
+
}
|
|
710
729
|
}
|
|
711
730
|
}
|
|
712
731
|
}
|
|
@@ -1008,9 +1027,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1008
1027
|
// "Refresh Status" button must never serve a stale snapshot.
|
|
1009
1028
|
app.get('/api/admin/clients', async (req) => {
|
|
1010
1029
|
const refresh = req.query.refresh === '1';
|
|
1030
|
+
// The activity ledger rides along per row (lastActiveAt / lastSetupAt);
|
|
1031
|
+
// SORTING stays on the console — the CLI's roster table must keep the
|
|
1032
|
+
// registry order regardless of live traffic.
|
|
1033
|
+
const activity = clientActivitySnapshot();
|
|
1011
1034
|
return {
|
|
1012
1035
|
status: 'ok',
|
|
1013
|
-
clients: await getAllClientStatuses({ refresh }),
|
|
1036
|
+
clients: (await getAllClientStatuses({ refresh })).map((c) => ({ ...c, ...(activity[c.name] ?? {}) })),
|
|
1014
1037
|
};
|
|
1015
1038
|
});
|
|
1016
1039
|
// 3A1'. Release update check — display-only and cached in-process. The
|
|
@@ -1385,10 +1408,12 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1385
1408
|
// environment-book-set switch (ADR-0007) and may change under a live server.
|
|
1386
1409
|
const trafficRoot = () => path.join(getOcrHomeDir(), 'plugins', 'traffic');
|
|
1387
1410
|
const TRAFFIC_TAIL = 500;
|
|
1388
|
-
/** Per-side DISPLAY window handed to the dissector
|
|
1389
|
-
*
|
|
1390
|
-
|
|
1391
|
-
|
|
1411
|
+
/** Per-side DISPLAY window handed to the dissector. Capture is full fidelity
|
|
1412
|
+
* on disk; only this read is bounded, per row on every poll — the drawer's
|
|
1413
|
+
* own render cap is DEFAULT_TRAFFIC_BODY_PREVIEW_BYTES. */
|
|
1414
|
+
const TRAFFIC_DISSECT_WINDOW = DEFAULT_TRAFFIC_DISSECT_WINDOW_BYTES;
|
|
1415
|
+
/** Inline hex preview length — first paint only. The drawer replaces it with
|
|
1416
|
+
* the token-addressed body, so keeping it small keeps every poll cheap. */
|
|
1392
1417
|
const TRAFFIC_HEX_PREVIEW = 1024;
|
|
1393
1418
|
/** Strict sidecar ref: `<YYYYMMDD>/<id>-<side>.bin`, no traversal. */
|
|
1394
1419
|
const TRAFFIC_BODY_REF_RE = /^\d{8}\/[A-Za-z0-9._-]+\.bin$/;
|
|
@@ -1423,8 +1448,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1423
1448
|
try {
|
|
1424
1449
|
const fd = fs.openSync(abs, 'r');
|
|
1425
1450
|
try {
|
|
1426
|
-
|
|
1427
|
-
|
|
1451
|
+
// Allocate the bytes the file actually has, not the window: a
|
|
1452
|
+
// 500-row tail decorates ~1000 sides per poll, and a full-window
|
|
1453
|
+
// buffer per side is the dominant cost (window × rows), while most
|
|
1454
|
+
// bodies are kilobytes.
|
|
1455
|
+
const take = Math.min(fs.fstatSync(fd).size, TRAFFIC_DISSECT_WINDOW);
|
|
1456
|
+
const buf = Buffer.allocUnsafe(take);
|
|
1457
|
+
const read = fs.readSync(fd, buf, 0, take, 0);
|
|
1428
1458
|
return buf.subarray(0, read);
|
|
1429
1459
|
}
|
|
1430
1460
|
finally {
|
|
@@ -1526,25 +1556,57 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1526
1556
|
reply.header('content-disposition', `attachment; filename="${path.basename(abs)}"`);
|
|
1527
1557
|
return reply.send(fs.createReadStream(abs));
|
|
1528
1558
|
});
|
|
1529
|
-
// 3A3. OS system proxy ownership
|
|
1530
|
-
//
|
|
1531
|
-
|
|
1532
|
-
|
|
1559
|
+
// 3A3. OS system proxy ownership — ONE snapshot, TWO endpoints: the inbound
|
|
1560
|
+
// forward proxy (default) or the Clash core's mixed port. A target switch
|
|
1561
|
+
// rewrites the OS pointer without re-reading the pre-OCR snapshot; restore
|
|
1562
|
+
// always returns what the OS held before OCR first took ownership.
|
|
1563
|
+
const systemProxyPayload = async (req) => {
|
|
1564
|
+
const live = getRuntimeConfigRef();
|
|
1565
|
+
const fp = live?.forwardProxy;
|
|
1533
1566
|
const port = fp?.port ?? DEFAULT_FORWARD_PROXY_PORT;
|
|
1567
|
+
const mixedPort = live?.proxy?.mihomo?.mixedPort ?? DEFAULT_MIHOMO_MIXED_PORT;
|
|
1534
1568
|
const sys = await getSystemProxyStatus(port, osBypassHosts(fp?.rules));
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1569
|
+
const clashBypass = lanBypassHosts(process.platform);
|
|
1570
|
+
const clashRunning = (await getMihomoStatus()).running;
|
|
1571
|
+
return {
|
|
1572
|
+
status: 'ok',
|
|
1573
|
+
...sys,
|
|
1574
|
+
proxyEnabled: Boolean(fp?.enabled),
|
|
1575
|
+
forward: { port, enabled: Boolean(fp?.enabled) },
|
|
1576
|
+
// The clash card names the bypass ITS target would write (LAN ranges),
|
|
1577
|
+
// not the inbound one on `override` (loopback + literal direct rows).
|
|
1578
|
+
clash: { mixedPort, running: clashRunning, override: buildOverride(clashBypass, process.platform) },
|
|
1579
|
+
// The PAC URL follows the origin THIS request reached, never the console
|
|
1580
|
+
// document's origin (a dev console on Vite would advertise a URL that
|
|
1581
|
+
// dies with its dev server).
|
|
1582
|
+
pacUrl: pacUrlFor(req.headers.host, req.protocol, live?.port),
|
|
1583
|
+
};
|
|
1584
|
+
};
|
|
1585
|
+
app.get('/api/admin/system-proxy', async (req) => systemProxyPayload(req));
|
|
1586
|
+
app.post('/api/admin/system-proxy/enable', async (req, reply) => {
|
|
1587
|
+
const body = (req.body ?? {});
|
|
1588
|
+
const live = getRuntimeConfigRef();
|
|
1589
|
+
if (body.target === 'clash') {
|
|
1590
|
+
// Pointing the OS at a dead port is one click away from a dead network:
|
|
1591
|
+
// the core must answer before it owns the OS proxy.
|
|
1592
|
+
if (!(await getMihomoStatus()).running) {
|
|
1593
|
+
reply.code(409);
|
|
1594
|
+
return { status: 'error', code: 'not-running' };
|
|
1595
|
+
}
|
|
1596
|
+
const mixedPort = live?.proxy?.mihomo?.mixedPort ?? DEFAULT_MIHOMO_MIXED_PORT;
|
|
1597
|
+
await enableSystemProxy(mixedPort, lanBypassHosts(process.platform), 'clash');
|
|
1598
|
+
return systemProxyPayload(req);
|
|
1599
|
+
}
|
|
1600
|
+
const fp = live?.forwardProxy;
|
|
1539
1601
|
const port = fp?.port ?? DEFAULT_FORWARD_PROXY_PORT;
|
|
1540
|
-
|
|
1541
|
-
return
|
|
1602
|
+
await enableSystemProxy(port, osBypassHosts(fp?.rules), 'forward');
|
|
1603
|
+
return systemProxyPayload(req);
|
|
1542
1604
|
});
|
|
1543
|
-
app.post('/api/admin/system-proxy/disable', async () => {
|
|
1605
|
+
app.post('/api/admin/system-proxy/disable', async (req) => {
|
|
1544
1606
|
const fp = getRuntimeConfigRef()?.forwardProxy;
|
|
1545
1607
|
const port = fp?.port ?? DEFAULT_FORWARD_PROXY_PORT;
|
|
1546
|
-
|
|
1547
|
-
return
|
|
1608
|
+
await disableSystemProxy(port, osBypassHosts(fp?.rules));
|
|
1609
|
+
return systemProxyPayload(req);
|
|
1548
1610
|
});
|
|
1549
1611
|
// 3A4. Forward-proxy rule table (ADR-0018): lint + dry-run resolution. The
|
|
1550
1612
|
// console renders the warning CODES through i18n and shows which rule a probe
|
|
@@ -1570,27 +1632,54 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1570
1632
|
// the wildcard's own attribution stays visible through `claimSources`.
|
|
1571
1633
|
const claimed = [...listGatewayHosts()].filter((h) => h !== WILDCARD_HOST_CLAIM).sort();
|
|
1572
1634
|
// Per-plugin attribution for the console's "decrypted without a rule" list:
|
|
1573
|
-
// the SAME live registry
|
|
1574
|
-
//
|
|
1635
|
+
// the SAME live registry the proxy legs read, so the two can never disagree —
|
|
1636
|
+
// one is the host set, the other says who claimed it and what leg that claim
|
|
1637
|
+
// owns (ADR-0018 Revision 5). The preview asks `claimEgressFor` — the very callback
|
|
1638
|
+
// the relay injects into `resolveHost` — because the tier that answers can be
|
|
1639
|
+
// the plugin's code, and a preview of a snapshot would be a second opinion.
|
|
1640
|
+
const claimOutcomes = (hosts) => hosts.map((host) => {
|
|
1641
|
+
const d = resolveHost(host, rules, {
|
|
1642
|
+
claimed: new Set(claimed), claimEgress: claimEgressFor, intercept,
|
|
1643
|
+
});
|
|
1644
|
+
return {
|
|
1645
|
+
host,
|
|
1646
|
+
action: d.action,
|
|
1647
|
+
tunnel: d.tunnel,
|
|
1648
|
+
reason: d.reason,
|
|
1649
|
+
egressClaim: d.egressClaim,
|
|
1650
|
+
ruleIndex: d.ruleIndex,
|
|
1651
|
+
};
|
|
1652
|
+
});
|
|
1575
1653
|
const claimSources = [...listGateways().entries()]
|
|
1576
|
-
.map(([pluginId, gw]) =>
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1654
|
+
.map(([pluginId, gw]) => {
|
|
1655
|
+
const hosts = [...new Set(gw.hosts.filter((h) => h !== WILDCARD_HOST_CLAIM))].sort();
|
|
1656
|
+
// The DISTINCT legs this plugin's claims ask for. One package normally
|
|
1657
|
+
// answers once — but a per-host hook may split, and a host two gateways
|
|
1658
|
+
// answer oppositely drops out entirely (no winner), which the dialog has
|
|
1659
|
+
// to be able to show rather than invent.
|
|
1660
|
+
const egress = [...new Set(hosts.map((h) => claimEgressFor(h)?.action))]
|
|
1661
|
+
.filter((e) => e !== undefined)
|
|
1662
|
+
.sort();
|
|
1663
|
+
return { pluginId, hosts, egress, outcomes: claimOutcomes(hosts) };
|
|
1664
|
+
})
|
|
1580
1665
|
.filter((s) => s.hosts.length > 0)
|
|
1581
1666
|
.sort((a, b) => a.pluginId.localeCompare(b.pluginId));
|
|
1582
1667
|
const host = typeof body.host === 'string' ? body.host.trim() : '';
|
|
1583
1668
|
return {
|
|
1584
1669
|
status: 'ok',
|
|
1585
1670
|
rules,
|
|
1586
|
-
warnings: lintRules(rawRules, proxyEnabled, intercept),
|
|
1671
|
+
warnings: lintRules(rawRules, proxyEnabled, intercept, listClaimedEgress()),
|
|
1587
1672
|
proxyEnabled,
|
|
1588
1673
|
intercept,
|
|
1589
1674
|
claimed,
|
|
1590
1675
|
claimSources,
|
|
1591
1676
|
// The resolver is the SAME function the proxy legs call, so the preview
|
|
1592
|
-
// can never disagree with the live decision
|
|
1593
|
-
|
|
1677
|
+
// can never disagree with the live decision — which is why the claim legs
|
|
1678
|
+
// ride in here too: omitting them would make an unsaved table preview as
|
|
1679
|
+
// `direct` while the relay already goes `proxy`.
|
|
1680
|
+
decision: host
|
|
1681
|
+
? resolveHost(host, rules, { claimed: new Set(claimed), claimEgress: claimEgressFor, intercept })
|
|
1682
|
+
: null,
|
|
1594
1683
|
};
|
|
1595
1684
|
});
|
|
1596
1685
|
// 3A5. One-click "tighten to allowlist" (ADR-0018 Revision 4). An install
|
|
@@ -1622,7 +1711,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1622
1711
|
status: 'ok',
|
|
1623
1712
|
rules,
|
|
1624
1713
|
intercept: DEFAULT_FORWARD_PROXY_INTERCEPT,
|
|
1625
|
-
warnings: lintRules(rules, live?.proxy?.enabled === true, DEFAULT_FORWARD_PROXY_INTERCEPT),
|
|
1714
|
+
warnings: lintRules(rules, live?.proxy?.enabled === true, DEFAULT_FORWARD_PROXY_INTERCEPT, listClaimedEgress()),
|
|
1626
1715
|
};
|
|
1627
1716
|
});
|
|
1628
1717
|
// 3B. Token usage aggregation from the trace ring: windowed totals plus
|
|
@@ -1915,6 +2004,14 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1915
2004
|
* NO tier ladder here: writing "ultra = broadest" made every role land on
|
|
1916
2005
|
* `ultra`.
|
|
1917
2006
|
*/
|
|
2007
|
+
/**
|
|
2008
|
+
* Price sentence for the decision prompt. An UNPRICED model must not render
|
|
2009
|
+
* as `$0/$0`: the LLM reads these lines when choosing a candidate, so a
|
|
2010
|
+
* fabricated zero is an active instruction to prefer it as "free".
|
|
2011
|
+
*/
|
|
2012
|
+
const priceLine = (p) => p
|
|
2013
|
+
? `price $${p.input}/$${p.output} per 1M tokens in/out`
|
|
2014
|
+
: 'price unknown (no published dollar price — do NOT read this as free)';
|
|
1918
2015
|
const describeCandidate = (rawId, note, cat) => {
|
|
1919
2016
|
const m = registry.getModel(rawId);
|
|
1920
2017
|
let body;
|
|
@@ -1922,7 +2019,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1922
2019
|
const tiers = registry.tiersOf(m);
|
|
1923
2020
|
const parts = [
|
|
1924
2021
|
`registered model; tiers=${tiers.length > 0 ? tiers.join('|') : 'none'}`,
|
|
1925
|
-
|
|
2022
|
+
priceLine(m.pricing),
|
|
1926
2023
|
...catalogTokens(cat),
|
|
1927
2024
|
];
|
|
1928
2025
|
if (m.wire === 'systemone') {
|
|
@@ -1950,7 +2047,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1950
2047
|
body =
|
|
1951
2048
|
`variant of ${base.id} (pins reasoning_effort '${variant.reasoningEffort}'); ` +
|
|
1952
2049
|
`tiers=${tiers.length > 0 ? tiers.join('|') : 'none'}; ` +
|
|
1953
|
-
|
|
2050
|
+
priceLine(base.pricing) +
|
|
1954
2051
|
(catTokens.length > 0 ? `; ${catTokens.join('; ')}` : '') +
|
|
1955
2052
|
`; wire=${base.wire ?? 'unknown'}`;
|
|
1956
2053
|
}
|
|
@@ -2456,8 +2553,8 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
2456
2553
|
// tiers.exclude filter. No preview; what the runtime would actually use.
|
|
2457
2554
|
//
|
|
2458
2555
|
// Read-only on purpose: the previous version called applyTierConfigNow()
|
|
2459
|
-
// here as a "force-commit view" trick, but that mutated m.tier
|
|
2460
|
-
//
|
|
2556
|
+
// here as a "force-commit view" trick, but that mutated m.tier on every
|
|
2557
|
+
// Live tab open — a stealth commit with no save event behind it.
|
|
2461
2558
|
// The console must NEVER write routing state from a GET. Out-of-band file
|
|
2462
2559
|
// edits get picked up on the next save commit (the console already triggers
|
|
2463
2560
|
// applyTierConfigNow in handleSaveConfig / handleSaveRawYaml).
|
|
@@ -2513,13 +2610,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
2513
2610
|
const members = expanded.tiers;
|
|
2514
2611
|
const modelIds = registry
|
|
2515
2612
|
.getAllModels()
|
|
2516
|
-
.filter((m) => m.
|
|
2613
|
+
.filter((m) => m.autoTier)
|
|
2517
2614
|
.map((m) => m.id);
|
|
2518
2615
|
const orphans = [];
|
|
2519
2616
|
for (const tier of MEMBER_TIER_ORDER) {
|
|
2520
2617
|
for (const rule of members[tier]) {
|
|
2521
2618
|
// exact rules = combo-expanded ids: registered by construction, and a
|
|
2522
|
-
// hand-configured member (no
|
|
2619
|
+
// hand-configured member (no autoTier stamp) is not in modelIds — flagging
|
|
2523
2620
|
// them here would be a false positive; ref liveness is deadCombo's job
|
|
2524
2621
|
if (rule.exact)
|
|
2525
2622
|
continue;
|
|
@@ -2539,7 +2636,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
2539
2636
|
// End-to-end tier test — one REAL minimal completion pinned to the tier via
|
|
2540
2637
|
// the bare tier alias: the same force_tier path a client's
|
|
2541
2638
|
// `model: "pro"` request takes (tier aliases are reserved gateway ids,
|
|
2542
|
-
// never
|
|
2639
|
+
// never pool-routed). One run only
|
|
2543
2640
|
// exercises the SELECTED member (the default credential, or the weighted/round-robin
|
|
2544
2641
|
// pick), never the whole pool — deep per-model checks stay on the providers
|
|
2545
2642
|
// page. An EMPTY tier degrades inside getModelForTier (the session-pin birth
|
|
@@ -3457,12 +3554,33 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3457
3554
|
return reply.status(400).send({ success: false, error: err.message });
|
|
3458
3555
|
}
|
|
3459
3556
|
},
|
|
3557
|
+
/** Connect a preset whose plugin owns login. Materializes the def and
|
|
3558
|
+
* lifts a deletion tombstone. Refuses a provider that still takes a key. */
|
|
3559
|
+
connectLocal: async (req, reply) => {
|
|
3560
|
+
const { id } = req.params;
|
|
3561
|
+
const { providerDeclinesCredentials, ensurePresetProvider } = await import('../plugins/host.js');
|
|
3562
|
+
if (!providerDeclinesCredentials(id)) {
|
|
3563
|
+
return reply.status(400).send({ success: false, error: `Provider '${id}' takes a credential` });
|
|
3564
|
+
}
|
|
3565
|
+
if (!(await ensurePresetProvider(id))) {
|
|
3566
|
+
return reply.status(404).send({ success: false, error: `Provider '${id}' is not a plugin preset` });
|
|
3567
|
+
}
|
|
3568
|
+
return { status: 'ok', success: true, connected: true };
|
|
3569
|
+
},
|
|
3460
3570
|
/** Resolve the model-service plugin serving a provider def's wire
|
|
3461
3571
|
* (plugin wires only — the vendor protocol stays in the plugin). */
|
|
3462
3572
|
webLoginPluginFor: async (id) => {
|
|
3463
3573
|
const { getProviderNodeById } = await import('../opencode/user-config.js');
|
|
3464
3574
|
const { wireFor } = await import('../providers/wire.js');
|
|
3465
|
-
|
|
3575
|
+
let def = getProviderNodeById(id);
|
|
3576
|
+
if (!def) {
|
|
3577
|
+
// The catalog row comes from the manifest, so the login button stays
|
|
3578
|
+
// offered even for a provider the operator deleted. A click IS connect
|
|
3579
|
+
// intent: materialize the preset (and lift its deletion tombstone).
|
|
3580
|
+
const { ensurePresetProvider } = await import('../plugins/host.js');
|
|
3581
|
+
if (await ensurePresetProvider(id))
|
|
3582
|
+
def = getProviderNodeById(id);
|
|
3583
|
+
}
|
|
3466
3584
|
if (!def)
|
|
3467
3585
|
return { error: `provider '${id}' not found` };
|
|
3468
3586
|
const node = def;
|
|
@@ -3481,7 +3599,9 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3481
3599
|
if ('error' in r)
|
|
3482
3600
|
return reply.code(404).send({ success: false, error: r.error });
|
|
3483
3601
|
try {
|
|
3484
|
-
|
|
3602
|
+
// `provider: id` lets the plugin hand this call to `host.fetch` and have
|
|
3603
|
+
// the operator's proxy split govern sign-in too (ADR-0022).
|
|
3604
|
+
const { authUrl } = await r.plugin.webLogin.start({ baseURL: r.baseURL, provider: id });
|
|
3485
3605
|
return { status: 'ok', authUrl };
|
|
3486
3606
|
}
|
|
3487
3607
|
catch (err) {
|
|
@@ -3494,7 +3614,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3494
3614
|
if ('error' in r)
|
|
3495
3615
|
return reply.code(404).send({ success: false, error: r.error });
|
|
3496
3616
|
try {
|
|
3497
|
-
const result = await r.plugin.webLogin.poll({ baseURL: r.baseURL });
|
|
3617
|
+
const result = await r.plugin.webLogin.poll({ baseURL: r.baseURL, provider: id });
|
|
3498
3618
|
if (!result.done) {
|
|
3499
3619
|
return { status: 'ok', done: false, error: result.error };
|
|
3500
3620
|
}
|
|
@@ -3533,7 +3653,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3533
3653
|
return reply.code(404).send({ success: false, error: `provider '${id}' web-login has no manual token submission` });
|
|
3534
3654
|
}
|
|
3535
3655
|
try {
|
|
3536
|
-
const result = await r.plugin.webLogin.submit({ baseURL: r.baseURL, code });
|
|
3656
|
+
const result = await r.plugin.webLogin.submit({ baseURL: r.baseURL, code, provider: id });
|
|
3537
3657
|
if (!result.ok)
|
|
3538
3658
|
return { status: 'ok', connected: false, error: result.error };
|
|
3539
3659
|
// Same wiring as a finished poll: credential-store write + connect-time
|
|
@@ -3674,6 +3794,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3674
3794
|
for (const c of enabledChain)
|
|
3675
3795
|
probeAttempts.push({ key: c.key, credentialId: c.credentialId });
|
|
3676
3796
|
}
|
|
3797
|
+
if (probeAttempts.length === 0) {
|
|
3798
|
+
// `none` owns login outside the credential store. One empty attempt
|
|
3799
|
+
// lets the plugin probe run; a missing key is not a failure.
|
|
3800
|
+
const { providerDeclinesCredentials } = await import('../plugins/host.js');
|
|
3801
|
+
if (providerDeclinesCredentials(id))
|
|
3802
|
+
probeAttempts.push({ key: '' });
|
|
3803
|
+
}
|
|
3677
3804
|
if (probeAttempts.length === 0) {
|
|
3678
3805
|
// Every stored key parked: say THAT, not the misleading no-key/OAuth
|
|
3679
3806
|
// hint (the operator must know a takedown is the cause). Reaching this
|
|
@@ -3723,6 +3850,12 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3723
3850
|
});
|
|
3724
3851
|
}
|
|
3725
3852
|
const { probeProvider, probeKindFor } = await import('../opencode/probe.js');
|
|
3853
|
+
// The verdict's egress (ADR-0018 / ADR-0022 vocabulary) is taken from the
|
|
3854
|
+
// attempt that produced it and rides on the reply, so "Test" answers "did
|
|
3855
|
+
// my model-scoped split apply" — the include/exclude page can only state
|
|
3856
|
+
// intent, never what this provider actually dialed.
|
|
3857
|
+
let egress;
|
|
3858
|
+
let egressProxy;
|
|
3726
3859
|
const { baseForWire } = await import('../providers/wire.js');
|
|
3727
3860
|
const { sanitizeExtraHeaders } = await import('../utils/http-headers.js');
|
|
3728
3861
|
// Two nested rotation loops, both stopping on one green:
|
|
@@ -3754,16 +3887,37 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3754
3887
|
// Responses API) beats provider-level npm when picking the wire shape.
|
|
3755
3888
|
const modelNpm = cat?.models.find((mm) => mm.id === modelId)?.npm;
|
|
3756
3889
|
const kind = probeKindFor(cat?.api, modelNpm || def?.npm || cat?.npm);
|
|
3890
|
+
// The model's own capability flags, read from the def the console
|
|
3891
|
+
// holds — a plugin probe builds a REAL request, so guessing
|
|
3892
|
+
// "not a reasoning model" makes it send thinking-off to a model that
|
|
3893
|
+
// always thinks and report 400 for a model inference serves fine.
|
|
3894
|
+
const modelDef = defs?.[modelId];
|
|
3895
|
+
const catModel = cat?.models.find((mm) => mm.id === modelId);
|
|
3757
3896
|
result = await probeProvider({
|
|
3758
3897
|
baseURL: baseForWire(kind, baseURL),
|
|
3759
3898
|
apiKey: attempt.key,
|
|
3760
3899
|
model: modelId,
|
|
3761
3900
|
provider: id,
|
|
3762
3901
|
kind,
|
|
3902
|
+
capabilities: {
|
|
3903
|
+
reasoning: modelDef?.reasoning === true || Array.isArray(modelDef?.reasoningOptions) && modelDef.reasoningOptions.length > 0 || catModel?.reasoning === true,
|
|
3904
|
+
vision: modelDef?.attachment === true || catModel?.modalities?.input?.includes('image') === true,
|
|
3905
|
+
},
|
|
3763
3906
|
headers: sanitizeExtraHeaders(def?.options?.headers
|
|
3764
3907
|
? Object.fromEntries(Object.entries(def.options.headers).map(([k, v]) => [k, expandEnvTemplate(String(v))]))
|
|
3765
3908
|
: undefined),
|
|
3766
3909
|
});
|
|
3910
|
+
// Stamp the egress the MOMENT the probe answers, before any break:
|
|
3911
|
+
// `break probes` (a green verdict, or a mount failure) skips the rest
|
|
3912
|
+
// of the loop body, and the operator's question — did MY split apply
|
|
3913
|
+
// to this call — must be answered on success too, not only when the
|
|
3914
|
+
// rotation happens to fall through. Assign UNCONDITIONALLY: the
|
|
3915
|
+
// verdict belongs to the attempt that produced it, so its egress is
|
|
3916
|
+
// the answer even when that attempt reports UNKNOWN (a pre-dial
|
|
3917
|
+
// failure) — keeping a prior attempt's stamp would describe a dial
|
|
3918
|
+
// the verdict never made (model rotation can switch the wire/baseURL).
|
|
3919
|
+
egress = result.egress;
|
|
3920
|
+
egressProxy = result.egressProxy;
|
|
3767
3921
|
if (result.ok)
|
|
3768
3922
|
break probes;
|
|
3769
3923
|
// Key-scoped refusal → this key is done, hand over to the next one.
|
|
@@ -3796,6 +3950,8 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3796
3950
|
...(tried.length > 1 ? { triedModels: tried } : {}),
|
|
3797
3951
|
...(triedCredentials.length > 1 ? { triedCredentials } : {}),
|
|
3798
3952
|
...(credentialMeta ? { credential: credentialMeta } : {}),
|
|
3953
|
+
...(egress ? { egress } : {}),
|
|
3954
|
+
...(egressProxy ? { egressProxy } : {}),
|
|
3799
3955
|
...result,
|
|
3800
3956
|
};
|
|
3801
3957
|
},
|
|
@@ -3847,6 +4003,12 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3847
4003
|
const result = deleteProviderDef(id);
|
|
3848
4004
|
if (!result.success)
|
|
3849
4005
|
return reply.status(400).send(result);
|
|
4006
|
+
// Delete is intent: without this, the next plugin reload/install sees
|
|
4007
|
+
// the preset's def missing and re-creates it (the row reappears on the
|
|
4008
|
+
// Connected surface). A surviving credential still re-creates a node
|
|
4009
|
+
// through the boot bind sweep — credential truth outranks the def.
|
|
4010
|
+
const { forgetProviderRegistration } = await import('../plugins/host.js');
|
|
4011
|
+
forgetProviderRegistration(id);
|
|
3850
4012
|
// Decision 8 double confirmation is enforced by the console UI
|
|
3851
4013
|
// (purgeAuth opt-in) — server-side the loop reports honestly.
|
|
3852
4014
|
const purge = purgeAuth ? await purgeProviderCredentials(store, id) : null;
|
|
@@ -4615,6 +4777,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
4615
4777
|
app.post(`${prefix}/opencode/providers`, withPoolSync(registry, ocHandlers.create));
|
|
4616
4778
|
app.patch(`${prefix}/opencode/providers/:id`, withPoolSync(registry, ocHandlers.update));
|
|
4617
4779
|
app.post(`${prefix}/opencode/providers/:id/connect`, withPoolSync(registry, ocHandlers.connect));
|
|
4780
|
+
app.post(`${prefix}/opencode/providers/:id/connect-local`, withPoolSync(registry, ocHandlers.connectLocal));
|
|
4618
4781
|
// Generic plugin web-authorization seam (device flow): start opens the
|
|
4619
4782
|
// vendor login page; poll returns done+token and wires the fresh token
|
|
4620
4783
|
// into the credential store. The plugin owns the whole protocol.
|
|
@@ -4812,12 +4975,15 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
4812
4975
|
const { installPluginPackage, packageIdOf, pluginPackageZip, listInstalledPlugins: listing } = await import('../plugins/host.js');
|
|
4813
4976
|
// Snapshot the version this upload is about to REPLACE (a packaged one
|
|
4814
4977
|
// — a dev-tree plugin is not ours to materialize here). A failed upgrade
|
|
4815
|
-
// must not delete a working install.
|
|
4978
|
+
// must not delete a working install. `disabled` does NOT disqualify the
|
|
4979
|
+
// snapshot: a switched-off package is still an install the operator
|
|
4980
|
+
// owns, and a broken upload over it would otherwise leave them with
|
|
4981
|
+
// nothing to roll back to.
|
|
4816
4982
|
let previous;
|
|
4817
4983
|
try {
|
|
4818
4984
|
const target = packageIdOf(new Uint8Array(bytes));
|
|
4819
4985
|
const existing = listing().find((p) => p.id === target);
|
|
4820
|
-
if (existing?.source === 'packaged'
|
|
4986
|
+
if (existing?.source === 'packaged')
|
|
4821
4987
|
previous = await pluginPackageZip(target);
|
|
4822
4988
|
}
|
|
4823
4989
|
catch {
|
|
@@ -4827,8 +4993,24 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
4827
4993
|
const { loadInstalledPlugins, syncPluginPresets, listInstalledPlugins } = await import('../plugins/host.js');
|
|
4828
4994
|
await loadInstalledPlugins();
|
|
4829
4995
|
const plugins = listInstalledPlugins();
|
|
4830
|
-
|
|
4831
|
-
|
|
4996
|
+
// An engine-INCOMPATIBLE package is not a broken one: it is on disk,
|
|
4997
|
+
// it is listed as disabled, and it becomes usable in place once the
|
|
4998
|
+
// matching side is updated. Discarding it would only make the operator
|
|
4999
|
+
// upload the same file again after that update, so the discard /
|
|
5000
|
+
// rollback path below stays reserved for packages that genuinely fail
|
|
5001
|
+
// to load. The test is the ROW'S OWN flag, never `disabled && !loaded`
|
|
5002
|
+
// — an operator-disabled package satisfies that shape too, and a
|
|
5003
|
+
// failed load of one must still be discarded and rolled back.
|
|
5004
|
+
//
|
|
5005
|
+
// An UPLOAD is normally refused before it ever lands
|
|
5006
|
+
// (`installPluginPackage` → `assertSupportedPluginApi`), so a 400 with
|
|
5007
|
+
// the core sentence is the common answer. This branch covers the case
|
|
5008
|
+
// that reaches the disk anyway (a package that became incompatible
|
|
5009
|
+
// under a downgraded gateway), where the refusal must be reported and
|
|
5010
|
+
// NOT followed by a discard.
|
|
5011
|
+
const view = plugins.find((p) => p.id === installed);
|
|
5012
|
+
const incompatible = view?.incompatible === true;
|
|
5013
|
+
if (!view?.loaded && !incompatible) {
|
|
4832
5014
|
// a package that cannot load would re-fail every boot — discard it;
|
|
4833
5015
|
// discard BEFORE preset sync / pool refresh so a broken package
|
|
4834
5016
|
// registers nothing
|
|
@@ -4858,10 +5040,24 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
4858
5040
|
}
|
|
4859
5041
|
// presets register at install time (same contract as boot/reload) —
|
|
4860
5042
|
// after a verified successful load, BEFORE the pool refresh so the
|
|
4861
|
-
//
|
|
5043
|
+
// defs are routable immediately on the next dispatch. An engine-refused
|
|
5044
|
+
// package reaches this line too: it loaded nothing, so `syncPluginPresets`
|
|
5045
|
+
// has nothing of it to register, and its row stays DISABLED in `plugins`.
|
|
4862
5046
|
const registered = await syncPluginPresets();
|
|
4863
5047
|
await refreshDirectPool(registry);
|
|
4864
|
-
return {
|
|
5048
|
+
return {
|
|
5049
|
+
status: 'ok',
|
|
5050
|
+
id: installed,
|
|
5051
|
+
version: installedVersion,
|
|
5052
|
+
replacedVersion,
|
|
5053
|
+
plugins,
|
|
5054
|
+
registered,
|
|
5055
|
+
// Kept in the 200 body so the console can toast the honest outcome:
|
|
5056
|
+
// the bytes landed, but the package answers nothing until one side
|
|
5057
|
+
// is updated. A green "installed" toast over a red row is the one
|
|
5058
|
+
// reading an operator must not be left with.
|
|
5059
|
+
...(incompatible ? { incompatible: true, error: view.error } : {}),
|
|
5060
|
+
};
|
|
4865
5061
|
}
|
|
4866
5062
|
catch (err) {
|
|
4867
5063
|
return reply.code(400).send({ status: 'error', error: err instanceof Error ? err.message : String(err) });
|
|
@@ -5152,7 +5348,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
5152
5348
|
// offer ONLY these — anything else would be clamped right back by
|
|
5153
5349
|
// downgradeReasoning. `[]` is a REAL answer ("no explicit level
|
|
5154
5350
|
// control", e.g. a toggle-only model), never "unknown".
|
|
5155
|
-
efforts: modelSupportsEfforts(m.supportedReasoningEfforts, m.supportsReasoningEffort) ?? [],
|
|
5351
|
+
efforts: modelSupportsEfforts(m.supportedReasoningEfforts, m.supportsReasoningEffort, m.reasoningDisableable) ?? [],
|
|
5156
5352
|
// Resolved upstream wire (model-level npm beats provider npm, see
|
|
5157
5353
|
// providers/wire.ts). Console pickers MUST read it from here instead of
|
|
5158
5354
|
// 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 };
|