@bitkyc08/opencodex 2.58.0 → 2.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -10
- package/gui/dist/assets/index-C5IebErG.js +136 -0
- package/gui/dist/assets/{index-C5-RdDmD.css → index-OESInAjC.css} +1 -1
- package/gui/dist/index.html +2 -2
- package/gui/dist/provider-icons/crusoe.svg +1 -0
- package/gui/dist/provider-icons/opper.svg +3 -0
- package/package.json +1 -1
- package/src/adapters/base.ts +11 -1
- package/src/adapters/cursor/catalog.ts +11 -0
- package/src/adapters/cursor/effort-map.ts +16 -2
- package/src/adapters/cursor/envelope-echo.ts +55 -2
- package/src/adapters/cursor/message-mapper.ts +3 -2
- package/src/adapters/cursor/protobuf-request.ts +8 -5
- package/src/adapters/cursor/request-builder.ts +14 -3
- package/src/adapters/cursor/thread-continuity.ts +105 -31
- package/src/adapters/cursor/tool-guidance.ts +5 -4
- package/src/adapters/cursor.ts +42 -1
- package/src/adapters/devin/cloud-direct/chat.ts +11 -2
- package/src/adapters/devin/cloud-direct/index.ts +7 -0
- package/src/adapters/devin/cloud-direct/stated-reset-retry.ts +103 -0
- package/src/adapters/devin.ts +75 -13
- package/src/adapters/google-antigravity-wire.ts +29 -2
- package/src/adapters/google-http.ts +8 -1
- package/src/adapters/google.ts +23 -4
- package/src/adapters/openai-chat/response-events.ts +61 -0
- package/src/adapters/openai-chat.ts +5 -10
- package/src/adapters/openai-responses/passthrough.ts +10 -1
- package/src/adapters/openai-responses/tool-output-recovery.ts +75 -0
- package/src/adapters/openai-responses/tool-schema.ts +19 -7
- package/src/adapters/responses-tool-schema.ts +76 -46
- package/src/adapters/run-turn-queue.ts +17 -4
- package/src/bridge/response-json.ts +1 -1
- package/src/bridge/sse.ts +165 -24
- package/src/claude/context-windows.ts +22 -0
- package/src/claude/outbound.ts +35 -4
- package/src/cli/account-api.ts +4 -3
- package/src/cli/account-extended.ts +22 -2
- package/src/cli/account-orca-import.ts +63 -0
- package/src/cli/account.ts +32 -4
- package/src/cli/capabilities.ts +40 -0
- package/src/cli/claude.ts +29 -1
- package/src/cli/codex-cli-update.ts +97 -2
- package/src/cli/dispatch.ts +54 -0
- package/src/cli/doctor.ts +197 -2
- package/src/cli/help.ts +4 -1
- package/src/cli/index.ts +88 -20
- package/src/cli/models-runtime.ts +33 -4
- package/src/cli/registry.ts +11 -1
- package/src/cli/runtime-api.ts +44 -0
- package/src/cli/start-args.ts +94 -0
- package/src/cli/system-command.ts +2 -0
- package/src/client/machine-api.ts +4 -3
- package/src/client/machine-listener.ts +14 -1
- package/src/clients/config-export/constants.ts +2 -3
- package/src/clients/config-export.ts +5 -5
- package/src/codex/account-store.ts +81 -5
- package/src/codex/auth-api/pool-quota-probe.ts +14 -3
- package/src/codex/auth-api/routes.ts +17 -2
- package/src/codex/auth-context.ts +16 -12
- package/src/codex/catalog/build-entries.ts +25 -4
- package/src/codex/catalog/derive-entry.ts +8 -1
- package/src/codex/catalog/effort.ts +10 -6
- package/src/codex/catalog/gather-capture.ts +1 -0
- package/src/codex/catalog/model-hints.ts +37 -5
- package/src/codex/catalog/parsing.ts +83 -5
- package/src/codex/catalog/reserve-warn.ts +96 -0
- package/src/codex/catalog/retained-sync.ts +19 -0
- package/src/codex/catalog/routed-gather.ts +42 -3
- package/src/codex/cli-installation-identity.ts +210 -0
- package/src/codex/cli-installation-targets.ts +158 -0
- package/src/codex/convergence.ts +5 -0
- package/src/codex/history-provider.ts +4 -1
- package/src/codex/history-state-open.ts +105 -0
- package/src/codex/inject/config-toml.ts +44 -2
- package/src/codex/inject.ts +3 -2
- package/src/codex/lineage.ts +83 -32
- package/src/codex/loopback-target.ts +31 -0
- package/src/codex/main-account-hard-lock.ts +2 -1
- package/src/codex/main-account.ts +10 -3
- package/src/codex/main-device-reauth.ts +17 -9
- package/src/codex/model-entitlements.ts +60 -1
- package/src/codex/observed-model-denials.ts +137 -0
- package/src/codex/orca-auth-source.ts +94 -0
- package/src/codex/orca-import.ts +219 -0
- package/src/codex/prompt-text-probe.ts +282 -12
- package/src/codex/quota-401-recovery.ts +12 -0
- package/src/codex/quota-types.ts +65 -0
- package/src/codex/quota.ts +24 -19
- package/src/codex/routing/cooldown-math.ts +8 -47
- package/src/codex/routing/pin-drain.ts +57 -0
- package/src/codex/routing.ts +13 -15
- package/src/codex/subagent-model-fallback.ts +94 -0
- package/src/codex/windows-installation-files.ts +224 -0
- package/src/combos/failover.ts +122 -5
- package/src/config/diagnostics.ts +21 -0
- package/src/config/load-degrade.ts +15 -0
- package/src/config/pending-teardown.ts +8 -0
- package/src/config/process-state.ts +36 -3
- package/src/config/provider-relative-send-path.ts +16 -0
- package/src/config/proxy-env.ts +23 -5
- package/src/config/schema/config-schema.ts +21 -0
- package/src/config/schema/leaf-validators.ts +64 -17
- package/src/generated/compatibility-version.json +235 -163
- package/src/generated/model-metadata.ts +1 -1
- package/src/lib/bounded-body.ts +4 -2
- package/src/lib/destination-policy.ts +48 -6
- package/src/lib/errors.ts +3 -15
- package/src/lib/local-destinations.ts +32 -5
- package/src/lib/provider-outbound.ts +3 -3
- package/src/lib/proxy-env.ts +70 -3
- package/src/lib/request-execution-budget.ts +11 -3
- package/src/lib/response-body-inactivity.ts +193 -0
- package/src/lib/retry-delay.ts +69 -0
- package/src/lib/socks5-fetch.ts +631 -0
- package/src/lib/spend-reservation-ledger.ts +115 -9
- package/src/lib/workflow-budget.ts +145 -8
- package/src/oauth/account-quota-rank.ts +72 -15
- package/src/oauth/generic-account-failover.ts +40 -27
- package/src/oauth/orcarouter.ts +15 -2
- package/src/oauth/store.ts +8 -0
- package/src/providers/codex-capacity.ts +9 -0
- package/src/providers/devin-provider-merge-migration.ts +33 -12
- package/src/providers/free-directory.ts +20 -2
- package/src/providers/key-failover.ts +261 -7
- package/src/providers/model-rename-migration.ts +1 -0
- package/src/providers/openai-sidecar.ts +4 -0
- package/src/providers/opencode-go-transport.ts +14 -5
- package/src/providers/quota/report-cache.ts +3 -0
- package/src/providers/registry/entries-extended.ts +96 -0
- package/src/providers/registry/model-seeds.ts +78 -21
- package/src/responses/apply-patch-envelope.ts +44 -11
- package/src/responses/bridge-search-replay-cache.ts +152 -0
- package/src/responses/code-mode-helper-compat.ts +26 -16
- package/src/responses/custom-tool-compat.ts +1 -1
- package/src/responses/hosted-tool-policy.ts +85 -2
- package/src/responses/schema.ts +9 -2
- package/src/server/auth-cors.ts +26 -0
- package/src/server/chat-completions.ts +9 -4
- package/src/server/chat-native-sse.ts +26 -9
- package/src/server/chat-native.ts +10 -4
- package/src/server/claude-messages.ts +24 -2
- package/src/server/gui-static.ts +36 -2
- package/src/server/inbound-body-admission.ts +187 -0
- package/src/server/index.ts +15 -19
- package/src/server/management/api-access.ts +3 -4
- package/src/server/management/config-routes.ts +31 -6
- package/src/server/management/provider-capability-config.ts +35 -7
- package/src/server/management/provider-routes.ts +70 -18
- package/src/server/proxy-liveness.ts +97 -2
- package/src/server/relay.ts +17 -24
- package/src/server/request-log.ts +25 -1
- package/src/server/responses/adapter-continuation.ts +71 -27
- package/src/server/responses/adapter-delivery.ts +39 -8
- package/src/server/responses/adapter-dispatch.ts +52 -24
- package/src/server/responses/compact.ts +60 -11
- package/src/server/responses/core-codex-account.ts +83 -22
- package/src/server/responses/core-normalize.ts +12 -5
- package/src/server/responses/fetch-helpers.ts +68 -2
- package/src/server/responses/passthrough-delivery.ts +10 -1
- package/src/server/responses/passthrough-dispatch.ts +113 -48
- package/src/server/responses/passthrough-execution.ts +11 -1
- package/src/server/responses/request-prepare.ts +29 -0
- package/src/server/responses/request-send-budget.ts +84 -7
- package/src/server/responses/request-sidecar-auth.ts +16 -8
- package/src/server/responses/request-spend.ts +38 -9
- package/src/server/responses/request-transport.ts +13 -10
- package/src/server/responses/run-turn-execution.ts +20 -5
- package/src/server/responses/sidecar-execution.ts +2 -0
- package/src/server/responses/ws-upstream.ts +2 -1
- package/src/server/responses-custom-tool-repair.ts +2 -2
- package/src/server/sse-frame-buffer.ts +12 -10
- package/src/server/sse-payload-rewrite.ts +36 -9
- package/src/server/system-env-shell.ts +5 -1
- package/src/server/system-env.ts +7 -1
- package/src/server/workflow-refusal.ts +56 -2
- package/src/service/cli.ts +16 -6
- package/src/service/guards.ts +10 -0
- package/src/service/health.ts +43 -0
- package/src/service/state.ts +7 -2
- package/src/types/accounts.ts +4 -0
- package/src/types/config.ts +100 -3
- package/src/types/provider.ts +19 -0
- package/src/types/request.ts +7 -1
- package/src/types/wire.ts +9 -1
- package/src/usage/expected-prices.ts +28 -0
- package/src/usage/log.ts +87 -4
- package/src/web-search/passthrough-bridge.ts +39 -5
- package/gui/dist/assets/index-BbrHOIY0.js +0 -128
|
@@ -110,7 +110,7 @@ import { filterRequestLogs, getRequestLogEntries, type RequestLogEntry } from ".
|
|
|
110
110
|
import { estimateComboCost, estimateRequestCost, normalizeCostTokens, tokensPerSecond } from "../../usage/cost";
|
|
111
111
|
import type { PersistedUsageAttempt } from "../../usage/log";
|
|
112
112
|
import { isAllowedRequestOrigin, jsonResponse, providerManagementConfigError, publicProviderBaseUrl, safeConfigDTO } from "../auth-cors";
|
|
113
|
-
import {
|
|
113
|
+
import { withProviderCatalogCapabilityDTO } from "./provider-capability-config";
|
|
114
114
|
import { applySystemEnvToggle } from "../system-env";
|
|
115
115
|
import { getCachedStartupHealth, invalidateStartupHealthCache } from "../startup-health-cache";
|
|
116
116
|
import { runWindowsTrayAction } from "../windows-tray-control";
|
|
@@ -186,7 +186,8 @@ interface ClientIntegrationSyncOutcome {
|
|
|
186
186
|
export async function syncEnabledClientIntegrations(
|
|
187
187
|
port: number | undefined,
|
|
188
188
|
config: OcxConfig,
|
|
189
|
-
deps: Pick<ManagementContext["deps"],
|
|
189
|
+
deps: Pick<ManagementContext["deps"],
|
|
190
|
+
"fetchAllModels" | "refreshOwnedCatalogIntegrations" | "writeDesktop3pConfig"> = {},
|
|
190
191
|
): Promise<ClientIntegrationSyncOutcome[]> {
|
|
191
192
|
if (port === undefined) return [];
|
|
192
193
|
const { claudeDesktopIntegrationEnabled, grokIntegrationEnabled } = await import("../../codex/desired-state");
|
|
@@ -235,7 +236,8 @@ export async function syncEnabledClientIntegrations(
|
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
const { refreshOwnedCatalogIntegrations } = await import("../../integrations/catalog-refresh");
|
|
238
|
-
|
|
239
|
+
const refreshOwned = deps.refreshOwnedCatalogIntegrations ?? refreshOwnedCatalogIntegrations;
|
|
240
|
+
out.push(...await refreshOwned({
|
|
239
241
|
models: async () => {
|
|
240
242
|
const { loadExportModels } = await import("./model-rows");
|
|
241
243
|
return loadExportModels(config);
|
|
@@ -266,7 +268,7 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
266
268
|
const { req, url, config, deps, convergeCodexCatalog, syncClaudeAgentDefsBestEffort } = ctx;
|
|
267
269
|
const readStartupHealth = deps.getCachedStartupHealth ?? getCachedStartupHealth;
|
|
268
270
|
if (url.pathname === "/api/config" && req.method === "GET") {
|
|
269
|
-
return jsonResponse(
|
|
271
|
+
return jsonResponse(withProviderCatalogCapabilityDTO(safeConfigDTO(config), config));
|
|
270
272
|
}
|
|
271
273
|
|
|
272
274
|
if (url.pathname === "/api/config" && req.method === "PUT") {
|
|
@@ -324,6 +326,8 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
324
326
|
// Absent means off, same convention: the GUI renders a plain switch without
|
|
325
327
|
// needing to know that `undefined` and `false` mean the same thing here.
|
|
326
328
|
ultraFastTier: config.ultraFastTier === true,
|
|
329
|
+
// Absent means on by default: the GUI renders a switch enabled unless explicit false.
|
|
330
|
+
fastRows: config.fastRows !== false,
|
|
327
331
|
codexMainAccountHardLock: config.codexMainAccountHardLock === true,
|
|
328
332
|
mainAccountHardLock: getMainAccountHardLockStatus(config),
|
|
329
333
|
// Absent means the historical auto-open, so the GUI can render the toggle
|
|
@@ -425,6 +429,7 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
425
429
|
codexQuotaAutoRefresh?: unknown;
|
|
426
430
|
oauthOpenBrowser?: unknown;
|
|
427
431
|
ultraFastTier?: unknown;
|
|
432
|
+
fastRows?: unknown;
|
|
428
433
|
codexMainAccountHardLock?: unknown;
|
|
429
434
|
codexDesktopAuthless?: unknown;
|
|
430
435
|
codexClientCompaction?: unknown;
|
|
@@ -436,10 +441,11 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
436
441
|
&& body.codexQuotaAutoRefresh === undefined
|
|
437
442
|
&& body.oauthOpenBrowser === undefined
|
|
438
443
|
&& body.ultraFastTier === undefined
|
|
444
|
+
&& body.fastRows === undefined
|
|
439
445
|
&& body.codexMainAccountHardLock === undefined
|
|
440
446
|
&& body.codexDesktopAuthless === undefined
|
|
441
447
|
&& body.codexClientCompaction === undefined) {
|
|
442
|
-
return jsonResponse({ error: "provide codexAutoStart, streamMode, appOwnedMemoryBudgetMb, codexAccountPickerEnabled, codexQuotaAutoRefresh, oauthOpenBrowser, ultraFastTier, codexMainAccountHardLock, codexDesktopAuthless, or codexClientCompaction" }, 400);
|
|
448
|
+
return jsonResponse({ error: "provide codexAutoStart, streamMode, appOwnedMemoryBudgetMb, codexAccountPickerEnabled, codexQuotaAutoRefresh, oauthOpenBrowser, ultraFastTier, fastRows, codexMainAccountHardLock, codexDesktopAuthless, or codexClientCompaction" }, 400);
|
|
443
449
|
}
|
|
444
450
|
if (body.codexAutoStart !== undefined && typeof body.codexAutoStart !== "boolean") {
|
|
445
451
|
return jsonResponse({ error: "codexAutoStart boolean is required" }, 400);
|
|
@@ -457,6 +463,9 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
457
463
|
if (body.ultraFastTier !== undefined && typeof body.ultraFastTier !== "boolean") {
|
|
458
464
|
return jsonResponse({ error: "ultraFastTier boolean is required" }, 400);
|
|
459
465
|
}
|
|
466
|
+
if (body.fastRows !== undefined && typeof body.fastRows !== "boolean") {
|
|
467
|
+
return jsonResponse({ error: "fastRows boolean is required" }, 400);
|
|
468
|
+
}
|
|
460
469
|
if (body.codexMainAccountHardLock !== undefined && typeof body.codexMainAccountHardLock !== "boolean") {
|
|
461
470
|
return jsonResponse({ error: "codexMainAccountHardLock boolean is required" }, 400);
|
|
462
471
|
}
|
|
@@ -512,6 +521,8 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
512
521
|
hasOauthOpenBrowser: Object.hasOwn(config, "oauthOpenBrowser"),
|
|
513
522
|
ultraFastTier: config.ultraFastTier,
|
|
514
523
|
hasUltraFastTier: Object.hasOwn(config, "ultraFastTier"),
|
|
524
|
+
fastRows: config.fastRows,
|
|
525
|
+
hasFastRows: Object.hasOwn(config, "fastRows"),
|
|
515
526
|
codexMainAccountHardLock: config.codexMainAccountHardLock,
|
|
516
527
|
hasCodexMainAccountHardLock: Object.hasOwn(config, "codexMainAccountHardLock"),
|
|
517
528
|
codexDesktopAuthless: config.codexDesktopAuthless,
|
|
@@ -523,6 +534,7 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
523
534
|
let pickerIsEnabled = pickerWasEnabled;
|
|
524
535
|
const authlessWasEnabled = config.codexDesktopAuthless === true;
|
|
525
536
|
const clientCompactionWasEnabled = config.codexClientCompaction === true;
|
|
537
|
+
const fastRowsWasEnabled = config.fastRows !== false;
|
|
526
538
|
try {
|
|
527
539
|
if (typeof body.codexAutoStart === "boolean") {
|
|
528
540
|
config.codexAutoStart = body.codexAutoStart;
|
|
@@ -550,6 +562,8 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
550
562
|
// default, and a written `false` would survive as a decision nobody made.
|
|
551
563
|
if (body.ultraFastTier === true) config.ultraFastTier = true;
|
|
552
564
|
else if (body.ultraFastTier === false) deleteConfigTopLevelKey(config, "ultraFastTier");
|
|
565
|
+
if (body.fastRows === false) config.fastRows = false;
|
|
566
|
+
else if (body.fastRows === true) deleteConfigTopLevelKey(config, "fastRows");
|
|
553
567
|
if (body.codexMainAccountHardLock === true) config.codexMainAccountHardLock = true;
|
|
554
568
|
else if (body.codexMainAccountHardLock === false) deleteConfigTopLevelKey(config, "codexMainAccountHardLock");
|
|
555
569
|
if (body.codexDesktopAuthless === true) config.codexDesktopAuthless = true;
|
|
@@ -592,6 +606,9 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
592
606
|
if (previousSettings.hasUltraFastTier) {
|
|
593
607
|
config.ultraFastTier = previousSettings.ultraFastTier;
|
|
594
608
|
} else deleteConfigTopLevelKey(config, "ultraFastTier");
|
|
609
|
+
if (previousSettings.hasFastRows) {
|
|
610
|
+
config.fastRows = previousSettings.fastRows;
|
|
611
|
+
} else deleteConfigTopLevelKey(config, "fastRows");
|
|
595
612
|
if (previousSettings.hasCodexMainAccountHardLock) {
|
|
596
613
|
config.codexMainAccountHardLock = previousSettings.codexMainAccountHardLock;
|
|
597
614
|
} else deleteConfigTopLevelKey(config, "codexMainAccountHardLock");
|
|
@@ -609,6 +626,8 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
609
626
|
}
|
|
610
627
|
const authlessIsEnabled = config.codexDesktopAuthless === true;
|
|
611
628
|
const clientCompactionIsEnabled = config.codexClientCompaction === true;
|
|
629
|
+
const fastRowsIsEnabled = config.fastRows !== false;
|
|
630
|
+
const fastRowsChanged = fastRowsWasEnabled !== fastRowsIsEnabled;
|
|
612
631
|
const desktopSwitchesChanged = authlessWasEnabled !== authlessIsEnabled
|
|
613
632
|
|| clientCompactionWasEnabled !== clientCompactionIsEnabled;
|
|
614
633
|
// Catalog convergence is not config injection, and the comment that used to sit here said
|
|
@@ -616,9 +635,14 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
616
635
|
// injector, which is why flipping either switch left `config.toml` in its old shape until
|
|
617
636
|
// a separate `ocx sync` (#4809). Both halves are needed when a Desktop switch changes; a
|
|
618
637
|
// picker-only update still refreshes just the catalog.
|
|
619
|
-
const catalogRefresh = pickerWasEnabled !== pickerIsEnabled || desktopSwitchesChanged
|
|
638
|
+
const catalogRefresh = pickerWasEnabled !== pickerIsEnabled || desktopSwitchesChanged || fastRowsChanged
|
|
620
639
|
? await convergeCodexCatalog()
|
|
621
640
|
: undefined;
|
|
641
|
+
if (fastRowsChanged) {
|
|
642
|
+
const { readRuntimePort } = await import("../../config/process-state");
|
|
643
|
+
const runtime = (deps.readRuntimePort ?? readRuntimePort)(process.pid);
|
|
644
|
+
await syncEnabledClientIntegrations(runtime?.port, config, deps);
|
|
645
|
+
}
|
|
622
646
|
// Injection second, matching `syncModelsToCodex`: the injected `model_catalog_json` should
|
|
623
647
|
// point at a catalog that has already settled. And it runs here rather than inside the save
|
|
624
648
|
// because coordinated Codex writes acquire the Codex write lock N before the config mutation
|
|
@@ -641,6 +665,7 @@ export async function handleConfigRoutes(ctx: ManagementContext): Promise<Respon
|
|
|
641
665
|
codexQuotaAutoRefresh: quotaAutoRefreshSettings(config),
|
|
642
666
|
oauthOpenBrowser: config.oauthOpenBrowser !== false,
|
|
643
667
|
catalogRefreshPending,
|
|
668
|
+
fastRows: config.fastRows !== false,
|
|
644
669
|
codexDesktopAuthless: authlessIsEnabled,
|
|
645
670
|
codexClientCompaction: clientCompactionIsEnabled,
|
|
646
671
|
codexDesktopSwitches,
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { booleanRecordConfigError } from "../../config/provider-validation";
|
|
2
2
|
import type { OcxConfig } from "../../types";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Provider-management validation that belongs to the provider editor, not the
|
|
6
|
-
* request-authentication/CORS boundary. Keeping this here lets the editor
|
|
7
|
-
* evolve its capability schema without widening the auth-cors security surface.
|
|
8
|
-
*/
|
|
4
|
+
/** Provider-management validation shared by provider editor write paths. */
|
|
9
5
|
export function providerServiceTierConfigError(name: unknown, provider: unknown): string | null {
|
|
10
6
|
if (typeof name !== "string" || !provider || typeof provider !== "object" || Array.isArray(provider)) {
|
|
11
7
|
return null;
|
|
@@ -17,7 +13,20 @@ export function providerServiceTierConfigError(name: unknown, provider: unknown)
|
|
|
17
13
|
return error ? `provider ${name} ${error}` : null;
|
|
18
14
|
}
|
|
19
15
|
|
|
20
|
-
function
|
|
16
|
+
export function providerCatalogCapabilityConfigError(name: unknown, provider: unknown): string | null {
|
|
17
|
+
const serviceTierError = providerServiceTierConfigError(name, provider);
|
|
18
|
+
if (serviceTierError) return serviceTierError;
|
|
19
|
+
if (typeof name !== "string" || !provider || typeof provider !== "object" || Array.isArray(provider)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const error = booleanRecordConfigError(
|
|
23
|
+
(provider as { modelSuppressSyntheticMax?: unknown }).modelSuppressSyntheticMax,
|
|
24
|
+
"modelSuppressSyntheticMax",
|
|
25
|
+
);
|
|
26
|
+
return error ? `provider ${name} ${error}` : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function publicBooleanRecord(value: unknown): Record<string, boolean> | undefined {
|
|
21
30
|
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
22
31
|
const entries = Object.entries(value).filter(([model, supported]) =>
|
|
23
32
|
model.trim().length > 0 && typeof supported === "boolean",
|
|
@@ -40,9 +49,28 @@ export function withProviderServiceTierDTO(dto: unknown, config: OcxConfig): unk
|
|
|
40
49
|
for (const [name, provider] of Object.entries(config.providers)) {
|
|
41
50
|
const dtoProvider = providers[name];
|
|
42
51
|
if (!dtoProvider || typeof dtoProvider !== "object" || Array.isArray(dtoProvider)) continue;
|
|
43
|
-
const capabilities =
|
|
52
|
+
const capabilities = publicBooleanRecord(provider.modelSupportsServiceTier);
|
|
44
53
|
if (capabilities === undefined) continue;
|
|
45
54
|
projectedProviders[name] = { ...(dtoProvider as Record<string, unknown>), modelSupportsServiceTier: capabilities };
|
|
46
55
|
}
|
|
47
56
|
return { ...root, providers: projectedProviders };
|
|
48
57
|
}
|
|
58
|
+
|
|
59
|
+
/** Project all catalog-only model capability maps across the dashboard config boundary. */
|
|
60
|
+
export function withProviderCatalogCapabilityDTO(dto: unknown, config: OcxConfig): unknown {
|
|
61
|
+
const projected = withProviderServiceTierDTO(dto, config);
|
|
62
|
+
if (!projected || typeof projected !== "object" || Array.isArray(projected)) return projected;
|
|
63
|
+
const root = projected as { providers?: unknown };
|
|
64
|
+
if (!root.providers || typeof root.providers !== "object" || Array.isArray(root.providers)) return projected;
|
|
65
|
+
|
|
66
|
+
const providers = root.providers as Record<string, unknown>;
|
|
67
|
+
const projectedProviders: Record<string, unknown> = { ...providers };
|
|
68
|
+
for (const [name, provider] of Object.entries(config.providers)) {
|
|
69
|
+
const dtoProvider = providers[name];
|
|
70
|
+
if (!dtoProvider || typeof dtoProvider !== "object" || Array.isArray(dtoProvider)) continue;
|
|
71
|
+
const capabilities = publicBooleanRecord(provider.modelSuppressSyntheticMax);
|
|
72
|
+
if (capabilities === undefined) continue;
|
|
73
|
+
projectedProviders[name] = { ...(dtoProvider as Record<string, unknown>), modelSuppressSyntheticMax: capabilities };
|
|
74
|
+
}
|
|
75
|
+
return { ...root, providers: projectedProviders };
|
|
76
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { modelCapabilitiesConfigError, mergeModelCapabilities } from "../../config/provider-validation";
|
|
2
|
+
import { DECLARABLE_HOSTED_TOOL_TYPES } from "../../responses/hosted-tool-policy";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { readFileSync } from "node:fs";
|
|
4
5
|
import { isDeepStrictEqual } from "node:util";
|
|
@@ -103,7 +104,7 @@ import {
|
|
|
103
104
|
type ProviderEditorConfigDTO,
|
|
104
105
|
type ProviderEditorProviderDTO,
|
|
105
106
|
} from "../auth-cors";
|
|
106
|
-
import {
|
|
107
|
+
import { providerCatalogCapabilityConfigError } from "./provider-capability-config";
|
|
107
108
|
import { providerEmptyToolOutputConfigError } from "../../config/provider-validation";
|
|
108
109
|
import { applySystemEnvToggle } from "../system-env";
|
|
109
110
|
import {
|
|
@@ -264,7 +265,7 @@ function providerEditorCandidate(
|
|
|
264
265
|
// the seed check must only pin the canonical transport/auth keys.
|
|
265
266
|
const providerError = providerManagementConfigError(name, transportCandidate, { allowOperatorOverlays: true })
|
|
266
267
|
?? providerEmptyToolOutputConfigError(name, transportCandidate)
|
|
267
|
-
??
|
|
268
|
+
?? providerCatalogCapabilityConfigError(name, transportCandidate);
|
|
268
269
|
if (providerError) return { ok: false, status: 400, error: providerError, code: "invalid_provider" };
|
|
269
270
|
providers[name] = merged;
|
|
270
271
|
}
|
|
@@ -516,7 +517,14 @@ function applyProviderPatchFields(
|
|
|
516
517
|
delete next.modelContextWindows;
|
|
517
518
|
} else {
|
|
518
519
|
if (!isPlainRecord(value)) return { error: "modelContextWindows must be a plain object or null" };
|
|
519
|
-
|
|
520
|
+
// A prototype-named model id must survive the merge: assigning
|
|
521
|
+
// "__proto__" on an ordinary object invokes the inherited setter instead
|
|
522
|
+
// of creating an own property, so the PATCH would report success while
|
|
523
|
+
// silently dropping that override.
|
|
524
|
+
const windows: Record<string, number> = Object.assign(
|
|
525
|
+
Object.create(null),
|
|
526
|
+
next.modelContextWindows ?? {},
|
|
527
|
+
);
|
|
520
528
|
for (const [model, window] of Object.entries(value)) {
|
|
521
529
|
if (!model.trim()) return { error: "modelContextWindows keys must be nonblank model ids" };
|
|
522
530
|
if (window === null) {
|
|
@@ -639,6 +647,29 @@ function applyProviderPatchFields(
|
|
|
639
647
|
}
|
|
640
648
|
touched = true;
|
|
641
649
|
}
|
|
650
|
+
if (Object.hasOwn(rawBody, "modelSuppressSyntheticMax")) {
|
|
651
|
+
const value = rawBody.modelSuppressSyntheticMax;
|
|
652
|
+
if (value === null) {
|
|
653
|
+
delete next.modelSuppressSyntheticMax;
|
|
654
|
+
} else {
|
|
655
|
+
if (!isPlainRecord(value)) return { error: "modelSuppressSyntheticMax must be a plain object or null" };
|
|
656
|
+
const capabilities: Record<string, boolean> = { ...(next.modelSuppressSyntheticMax ?? {}) };
|
|
657
|
+
for (const [model, suppressed] of Object.entries(value)) {
|
|
658
|
+
if (!model.trim()) return { error: "modelSuppressSyntheticMax keys must be nonblank model ids" };
|
|
659
|
+
if (suppressed === null) {
|
|
660
|
+
delete capabilities[model];
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
if (typeof suppressed !== "boolean") {
|
|
664
|
+
return { error: "modelSuppressSyntheticMax values must be booleans or null" };
|
|
665
|
+
}
|
|
666
|
+
capabilities[model] = suppressed;
|
|
667
|
+
}
|
|
668
|
+
if (Object.keys(capabilities).length > 0) next.modelSuppressSyntheticMax = capabilities;
|
|
669
|
+
else delete next.modelSuppressSyntheticMax;
|
|
670
|
+
}
|
|
671
|
+
touched = true;
|
|
672
|
+
}
|
|
642
673
|
if (Object.hasOwn(rawBody, "noStructuredOutputModels")) {
|
|
643
674
|
const value = rawBody.noStructuredOutputModels;
|
|
644
675
|
if (value === null) {
|
|
@@ -665,6 +696,26 @@ function applyProviderPatchFields(
|
|
|
665
696
|
}
|
|
666
697
|
touched = true;
|
|
667
698
|
}
|
|
699
|
+
if (Object.hasOwn(rawBody, "unsupportedHostedTools")) {
|
|
700
|
+
const value = rawBody.unsupportedHostedTools;
|
|
701
|
+
if (value === null) {
|
|
702
|
+
delete next.unsupportedHostedTools;
|
|
703
|
+
} else {
|
|
704
|
+
const error = nonBlankStringArrayConfigError(value, "unsupportedHostedTools");
|
|
705
|
+
if (error) return { error };
|
|
706
|
+
const tools = normalizeNonBlankStringArray(value as string[]);
|
|
707
|
+
const unknownTool = tools.find(tool => !DECLARABLE_HOSTED_TOOL_TYPES.has(tool));
|
|
708
|
+
if (unknownTool !== undefined) {
|
|
709
|
+
return {
|
|
710
|
+
error: `unsupportedHostedTools must name only hosted tool types: `
|
|
711
|
+
+ `${[...DECLARABLE_HOSTED_TOOL_TYPES].join(", ")}`,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
if (tools.length > 0) next.unsupportedHostedTools = tools;
|
|
715
|
+
else delete next.unsupportedHostedTools;
|
|
716
|
+
}
|
|
717
|
+
touched = true;
|
|
718
|
+
}
|
|
668
719
|
if (Object.hasOwn(rawBody, "retainModels")) {
|
|
669
720
|
const value = rawBody.retainModels;
|
|
670
721
|
if (value === null) {
|
|
@@ -864,8 +915,10 @@ export async function handleProviderRoutes(ctx: ManagementContext): Promise<Resp
|
|
|
864
915
|
modelPinnedReasoningEfforts: p.modelPinnedReasoningEfforts,
|
|
865
916
|
modelAutoCompactTokenLimits: p.modelAutoCompactTokenLimits,
|
|
866
917
|
modelSupportsServiceTier: p.modelSupportsServiceTier,
|
|
918
|
+
modelSuppressSyntheticMax: p.modelSuppressSyntheticMax,
|
|
867
919
|
noStructuredOutputModels: p.noStructuredOutputModels,
|
|
868
920
|
noJsonSchemaModels: p.noJsonSchemaModels,
|
|
921
|
+
unsupportedHostedTools: p.unsupportedHostedTools,
|
|
869
922
|
retainModels: p.retainModels,
|
|
870
923
|
omitReasoningEffortWithToolsModels: p.omitReasoningEffortWithToolsModels,
|
|
871
924
|
upstreamHttpVersion: p.upstreamHttpVersion,
|
|
@@ -1093,8 +1146,8 @@ export async function handleProviderRoutes(ctx: ManagementContext): Promise<Resp
|
|
|
1093
1146
|
if (rawProvider.upstreamWebsocket !== undefined && typeof rawProvider.upstreamWebsocket !== "boolean") {
|
|
1094
1147
|
return jsonResponse({ error: "upstreamWebsocket must be a boolean" }, 400);
|
|
1095
1148
|
}
|
|
1096
|
-
const
|
|
1097
|
-
if (
|
|
1149
|
+
const catalogCapabilityError = providerCatalogCapabilityConfigError(name, transportCandidate);
|
|
1150
|
+
if (catalogCapabilityError) return jsonResponse({ error: catalogCapabilityError }, 400);
|
|
1098
1151
|
const prov = stripCodexRuntimeProviderFields(transportCandidate as unknown as OcxProviderConfig);
|
|
1099
1152
|
// PATCH already clears on null; POST persisted the body as submitted, so a `null` here
|
|
1100
1153
|
// reached disk and the next loadConfig() refused it. Canonicalize to absent, which is what
|
|
@@ -1257,19 +1310,18 @@ export async function handleProviderRoutes(ctx: ManagementContext): Promise<Resp
|
|
|
1257
1310
|
|| Object.hasOwn(body.provider, "modelPinnedReasoningEfforts")
|
|
1258
1311
|
|| latest?.pinnedReasoningEffort !== undefined || latest?.modelPinnedReasoningEfforts !== undefined;
|
|
1259
1312
|
// New registration also edits discovery/disabled-model state; stage those
|
|
1260
|
-
// side effects with the
|
|
1261
|
-
|
|
1313
|
+
// side effects with the registration draft instead of mutating live state
|
|
1314
|
+
// before validation.
|
|
1315
|
+
const registrationDraft = !latest ? {
|
|
1262
1316
|
...config,
|
|
1263
1317
|
...(config.modelDiscovery === undefined ? {} : { modelDiscovery: structuredClone(config.modelDiscovery) }),
|
|
1264
1318
|
} : undefined;
|
|
1265
1319
|
initializeProviderModelSelection(name, prov, latest, registrationDraft ?? config);
|
|
1266
1320
|
const candidate = stripRegistryOnlyStaticHeaders(name, prov);
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
if (!validation.ok) return jsonResponse({ error: validation.error }, 400);
|
|
1272
|
-
}
|
|
1321
|
+
const draft = { ...(registrationDraft ?? config), providers: { ...config.providers, [name]: candidate },
|
|
1322
|
+
...(body.setDefault === true ? { defaultProvider: name } : {}) };
|
|
1323
|
+
const validation = validateConfigCandidate(draft);
|
|
1324
|
+
if (!validation.ok) return jsonResponse({ error: validation.error }, 400);
|
|
1273
1325
|
const previous = Object.getOwnPropertyDescriptor(config.providers, name);
|
|
1274
1326
|
const rollback = pinsOwned ? captureConfigTopLevelRollback(config, ["defaultProvider", "modelDiscovery", "disabledModels"]) : undefined;
|
|
1275
1327
|
try {
|
|
@@ -1397,8 +1449,8 @@ export async function handleProviderRoutes(ctx: ManagementContext): Promise<Resp
|
|
|
1397
1449
|
?? providerEmptyToolOutputConfigError(name, next);
|
|
1398
1450
|
if (providerError) return jsonResponse({ error: providerError }, 400);
|
|
1399
1451
|
if (!canonicalBudgetOnly) {
|
|
1400
|
-
const
|
|
1401
|
-
if (
|
|
1452
|
+
const catalogCapabilityError = providerCatalogCapabilityConfigError(name, next);
|
|
1453
|
+
if (catalogCapabilityError) return jsonResponse({ error: catalogCapabilityError }, 400);
|
|
1402
1454
|
// Same DNS gate as POST and re-enable: the canonical built-in OpenAI forward
|
|
1403
1455
|
// provider may resolve through Clash/Mihomo fake-IP DNS (198.18.0.0/15), so the
|
|
1404
1456
|
// ordinary PATCH must not reject the very same destination the provider was
|
|
@@ -1444,9 +1496,9 @@ export async function handleProviderRoutes(ctx: ManagementContext): Promise<Resp
|
|
|
1444
1496
|
return;
|
|
1445
1497
|
}
|
|
1446
1498
|
if (!canonicalBudgetOnly) {
|
|
1447
|
-
const
|
|
1448
|
-
if (
|
|
1449
|
-
replayError =
|
|
1499
|
+
const catalogCapabilityError = providerCatalogCapabilityConfigError(name, replay.next);
|
|
1500
|
+
if (catalogCapabilityError) {
|
|
1501
|
+
replayError = catalogCapabilityError;
|
|
1450
1502
|
return;
|
|
1451
1503
|
}
|
|
1452
1504
|
}
|
|
@@ -21,6 +21,12 @@ export interface HealthzIdentity {
|
|
|
21
21
|
uptime?: unknown;
|
|
22
22
|
pid?: unknown;
|
|
23
23
|
port?: unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Which listener answered: the standalone/hub server omits it, and the connected-client
|
|
26
|
+
* machine listener reports `"client"` (src/client/machine-listener.ts). It is the only
|
|
27
|
+
* on-the-wire way to tell those two apart, because both bind `config.port ?? 10100`.
|
|
28
|
+
*/
|
|
29
|
+
role?: unknown;
|
|
24
30
|
restartCapability?: unknown;
|
|
25
31
|
providerReloadCapability?: unknown;
|
|
26
32
|
guiPairCapability?: unknown;
|
|
@@ -63,6 +69,22 @@ export const SERVICE_STOP_LIVENESS: Pick<LivenessIo, "timeoutMs" | "attempts"> =
|
|
|
63
69
|
attempts: 3,
|
|
64
70
|
};
|
|
65
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Probe budget for a decision whose wrong answer starts a DUPLICATE proxy (#5004).
|
|
74
|
+
*
|
|
75
|
+
* `start` used the 750ms single-attempt default for both the pre-bind owner probe and
|
|
76
|
+
* (implicitly) the busy-port question behind the ephemeral hop. On Windows that answered
|
|
77
|
+
* "nothing is listening" for a proxy the previous command had just refused to shadow, and
|
|
78
|
+
* the hop then spawned a second instance that took over this home's pid/runtime records
|
|
79
|
+
* and re-pointed Codex at itself. A single unanswered probe is not evidence of absence
|
|
80
|
+
* when the failure mode is a duplicate instance, so the start path borrows the numbers
|
|
81
|
+
* the stop path already uses for the mirror-image decision.
|
|
82
|
+
*/
|
|
83
|
+
export const START_OWNERSHIP_LIVENESS: Pick<LivenessIo, "timeoutMs" | "attempts"> = {
|
|
84
|
+
timeoutMs: 1500,
|
|
85
|
+
attempts: 3,
|
|
86
|
+
};
|
|
87
|
+
|
|
66
88
|
export interface LiveProxy {
|
|
67
89
|
pid: number | null;
|
|
68
90
|
port: number;
|
|
@@ -78,6 +100,16 @@ export interface LiveProxy {
|
|
|
78
100
|
* healthz body predates the field.
|
|
79
101
|
*/
|
|
80
102
|
version?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Role the live listener reported on `/healthz`, when it reported one: `"client"` for the
|
|
105
|
+
* connected-client machine listener, absent for a standalone or hub proxy.
|
|
106
|
+
*
|
|
107
|
+
* Liveness deliberately still ACCEPTS a client-role listener — see `isOpencodexHealthz`.
|
|
108
|
+
* The role is carried so a caller that needs a management plane (src/cli/runtime-api.ts)
|
|
109
|
+
* can refuse one, while `stop` and orphan cleanup keep finding the process they must act
|
|
110
|
+
* on. Absent for a proxy whose healthz body predates the field.
|
|
111
|
+
*/
|
|
112
|
+
role?: string;
|
|
81
113
|
}
|
|
82
114
|
|
|
83
115
|
/**
|
|
@@ -101,6 +133,13 @@ export function probeHostname(hostname: string | undefined): string {
|
|
|
101
133
|
* `service: "opencodex"` marker, plus the legacy `{status, version, uptime}` trio so a
|
|
102
134
|
* still-running pre-identity proxy (e.g. right after `ocx update`) is not mistaken for a
|
|
103
135
|
* foreign server and shadow-started over.
|
|
136
|
+
*
|
|
137
|
+
* The connected-client machine listener answers with the same `service: "opencodex"` marker
|
|
138
|
+
* and an extra `role: "client"`, and it is accepted here on purpose. Liveness answers "is one
|
|
139
|
+
* of our processes listening on this port", which is exactly what `ocx stop`, orphan cleanup,
|
|
140
|
+
* and duplicate-start avoidance need: rejecting the client role would make those paths blind to
|
|
141
|
+
* a real opencodex process and let them shadow-start over it. Callers that additionally need a
|
|
142
|
+
* management plane discriminate on `LiveProxy.role` instead of narrowing this predicate.
|
|
104
143
|
*/
|
|
105
144
|
export function isOpencodexHealthz(body: HealthzIdentity | null): boolean {
|
|
106
145
|
if (!body) return false;
|
|
@@ -114,7 +153,7 @@ export async function proxyIdentityAt(
|
|
|
114
153
|
port: number,
|
|
115
154
|
opts: { hostname?: string; expectedPid?: number } = {},
|
|
116
155
|
io: LivenessIo = {},
|
|
117
|
-
): Promise<{ pid: number | null; version?: string } | null> {
|
|
156
|
+
): Promise<{ pid: number | null; version?: string; role?: string } | null> {
|
|
118
157
|
const fetchFn = io.fetchFn ?? directLocalHttpFetch;
|
|
119
158
|
const sleepFn = io.sleepFn ?? ((ms: number) => new Promise<void>(r => setTimeout(r, ms)));
|
|
120
159
|
const nowFn = io.nowFn ?? Date.now;
|
|
@@ -139,7 +178,14 @@ export async function proxyIdentityAt(
|
|
|
139
178
|
if (opts.expectedPid !== undefined && pid !== null && pid !== opts.expectedPid) return null;
|
|
140
179
|
// Guarded the same way `pid` is: a non-string version is absent, not coerced.
|
|
141
180
|
const version = typeof body?.version === "string" ? body.version : undefined;
|
|
142
|
-
|
|
181
|
+
// Same guard for the role, for the same reason: absent on a standalone/hub proxy and on
|
|
182
|
+
// a legacy body, and never coerced from a non-string.
|
|
183
|
+
const role = typeof body?.role === "string" ? body.role : undefined;
|
|
184
|
+
return {
|
|
185
|
+
pid,
|
|
186
|
+
...(version === undefined ? {} : { version }),
|
|
187
|
+
...(role === undefined ? {} : { role }),
|
|
188
|
+
};
|
|
143
189
|
} catch {
|
|
144
190
|
// Transport failure (timeout / refused) — retry while budget remains; a proxy that
|
|
145
191
|
// has only just begun listening can miss a single short probe (#764).
|
|
@@ -203,6 +249,7 @@ export async function findLiveProxy(io: LivenessIo = {}): Promise<LiveProxy | nu
|
|
|
203
249
|
hostname: runtime.hostname,
|
|
204
250
|
source: "runtime",
|
|
205
251
|
...(identity.version === undefined ? {} : { version: identity.version }),
|
|
252
|
+
...(identity.role === undefined ? {} : { role: identity.role }),
|
|
206
253
|
};
|
|
207
254
|
}
|
|
208
255
|
}
|
|
@@ -226,6 +273,7 @@ export async function findLiveProxy(io: LivenessIo = {}): Promise<LiveProxy | nu
|
|
|
226
273
|
hostname: record.hostname,
|
|
227
274
|
source: "runtime",
|
|
228
275
|
...(identity.version === undefined ? {} : { version: identity.version }),
|
|
276
|
+
...(identity.role === undefined ? {} : { role: identity.role }),
|
|
229
277
|
};
|
|
230
278
|
}
|
|
231
279
|
}
|
|
@@ -241,11 +289,58 @@ export async function findLiveProxy(io: LivenessIo = {}): Promise<LiveProxy | nu
|
|
|
241
289
|
hostname: config.hostname,
|
|
242
290
|
source: "config",
|
|
243
291
|
...(identity.version === undefined ? {} : { version: identity.version }),
|
|
292
|
+
...(identity.role === undefined ? {} : { role: identity.role }),
|
|
244
293
|
};
|
|
245
294
|
}
|
|
246
295
|
return null;
|
|
247
296
|
}
|
|
248
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Loopback addresses to ask about a port whose holder must be identified before a
|
|
300
|
+
* decision that is destructive when it answers "nobody".
|
|
301
|
+
*
|
|
302
|
+
* A listener and a probe can disagree about what "loopback" means, and on Windows they
|
|
303
|
+
* do. `startServer` canonicalizes a `localhost` bind to 127.0.0.1 precisely because
|
|
304
|
+
* Windows resolves the name IPv6-first (src/server/index.ts), while `probeHostname`
|
|
305
|
+
* hands the literal name back and leaves the family choice to the resolver. A probe that
|
|
306
|
+
* lands on `::1` while the listener holds `127.0.0.1` reports an empty port that another
|
|
307
|
+
* process is demonstrably serving. Both literal addresses are therefore asked, cheapest
|
|
308
|
+
* question first: the extra one costs a refused connection, and skipping it costs a
|
|
309
|
+
* duplicate proxy.
|
|
310
|
+
*
|
|
311
|
+
* A non-loopback bind (a LAN address, a named host) gets exactly one candidate — the
|
|
312
|
+
* address it was configured with. Guessing another interface for it would answer a
|
|
313
|
+
* different question than the caller asked.
|
|
314
|
+
*/
|
|
315
|
+
export function loopbackProbeHosts(hostname: string | undefined): string[] {
|
|
316
|
+
const primary = probeHostname(hostname);
|
|
317
|
+
if (primary === "127.0.0.1" || /^localhost$/i.test(primary)) return ["127.0.0.1", "[::1]"];
|
|
318
|
+
if (primary === "[::1]") return ["[::1]", "127.0.0.1"];
|
|
319
|
+
return [primary];
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Identity-checked answer to "who holds this exact port", independent of the pid file
|
|
324
|
+
* and the runtime-port record.
|
|
325
|
+
*
|
|
326
|
+
* `findLiveProxy` answers "is a proxy of this home alive", and it can only do that from
|
|
327
|
+
* recorded state plus the configured port. This answers the narrower question a start
|
|
328
|
+
* has to ask before it walks away from a busy port: an opencodex listening THERE, right
|
|
329
|
+
* now, whatever this home's records say about it. Returns null only after every
|
|
330
|
+
* candidate address has failed the identity check with the caller's full probe budget.
|
|
331
|
+
*/
|
|
332
|
+
export async function probePortOwner(
|
|
333
|
+
port: number,
|
|
334
|
+
opts: { hostname?: string } = {},
|
|
335
|
+
io: LivenessIo = {},
|
|
336
|
+
): Promise<{ pid: number | null; hostname: string; version?: string; role?: string } | null> {
|
|
337
|
+
for (const hostname of loopbackProbeHosts(opts.hostname)) {
|
|
338
|
+
const identity = await proxyIdentityAt(port, { hostname }, io);
|
|
339
|
+
if (identity) return { ...identity, hostname };
|
|
340
|
+
}
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
|
|
249
344
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
250
345
|
// Readiness (/readyz) strict probe.
|
|
251
346
|
//
|