codex-copilot-dx 1.2.14 → 1.2.15
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 +3 -3
- package/docs/ARCHITECTURE.md +10 -2
- package/docs/REFERENCE.md +15 -3
- package/package.json +1 -1
- package/src/claude-gateway.mjs +8 -3
- package/src/operation-error.mjs +17 -0
- package/src/providers/api-network.mjs +47 -11
- package/src/providers/api.mjs +16 -3
package/README.md
CHANGED
|
@@ -11,13 +11,13 @@ npm install -g codex-copilot-dx@latest
|
|
|
11
11
|
ccdx
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
No Node or Git? Download [install.sh](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.
|
|
14
|
+
No Node or Git? Download [install.sh](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.15/install.sh) (macOS/Linux) or [install.ps1](https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.15/install.ps1) (Windows), then run `sh install.sh` or `./install.ps1` under your current shell policy. The bootstrap reuses compatible Node/npm or installs verified official Node 24.22.0 privately for CCDX. It adds no Git, compiler or system package manager. It keeps registry/proxy/certificate policy, verifies the Release package and installed runtime, and restores the prior CCDX package if installation fails. Dependencies still need your configured registry. See [installation limits and private command paths](docs/REFERENCE.md#install-without-node-or-git).
|
|
15
15
|
|
|
16
16
|
CCDX reuses a compatible local credential or starts GitHub Device Flow, listens on `127.0.0.1:2026`, configures Codex, and opens the App. Interactive desktop starts also open the local WebUI once; use `ccdx --no-browser` or disable this in WebUI settings. No client binary patch is needed. On Windows, open the App manually unless native prediction setup is enabled. In restricted Windows PowerShell, use `npm.cmd` to install and `ccdx.cmd` for the first launch, or run `ccdx.cmd doctor --fix`. Startup, updates and explicit repair remove only CCDX's exact npm-generated `.ps1` launchers so later calls can use `ccdx`. The npm package adds no install hook or policy change; custom launchers are preserved. npm's own script is untouched. The configured `dummy` API key is a placeholder, not a credential.
|
|
17
17
|
|
|
18
18
|
The [local control console](http://127.0.0.1:2026/) separates Overview, Codex/Claude, Model sources, Usage, Requests, Checks & repairs and Settings, with a stable sticky header. Settings owns API/client access, independent web/terminal colors (classic green, Klein blue or Soft pink), startup and updates. Accounts and model catalogs stay with Model sources; client-specific tools stay with their application. CLI remains English; WebUI supports English/Chinese. An interactive terminal shows bounded startup checks, source/client state, a usage table with approximate cache hit rate, notices and animation. Plain/NO_COLOR/narrow output remains supported; `--verbose` retains request detail.
|
|
19
19
|
|
|
20
|
-
Requests shows live app/source/model flow above existing summaries and finished records. Usage offers animated bars or curves; reduced motion stays static. Hidden pages stop scheduled reads; status refreshes about every two seconds and source/settings evidence about every 16 seconds. Catalogs and retained usage load on demand or every 30 minutes while open. The UI does not add inference calls. Ready means local service availability, not verified model access. First output uses ms, speed token/s, and partial/unknown usage remains explicit. Images/predictions stay opt-in; their first setup uses CLI. See the [control reference](docs/REFERENCE.md#control-console-and-online-settings), [1.2.
|
|
20
|
+
Requests shows live app/source/model flow above existing summaries and finished records. Usage offers animated bars or curves; reduced motion stays static. Hidden pages stop scheduled reads; status refreshes about every two seconds and source/settings evidence about every 16 seconds. Catalogs and retained usage load on demand or every 30 minutes while open. The UI does not add inference calls. Ready means local service availability, not verified model access. First output uses ms, speed token/s, and partial/unknown usage remains explicit. Images/predictions stay opt-in; their first setup uses CLI. See the [control reference](docs/REFERENCE.md#control-console-and-online-settings), [1.2.15 changes and verification](https://github.com/DaleXiao/codex-copilot-dx/blob/main/docs/RELEASE_1.2.15.md) and [copy inventory](https://github.com/DaleXiao/codex-copilot-dx/blob/main/docs/UX_COPY.md).
|
|
21
21
|
|
|
22
22
|
## Commands
|
|
23
23
|
| Command | Purpose |
|
|
@@ -56,7 +56,7 @@ Run `ccdx web` without GitHub sign-in. In **Settings → Model sources → Add A
|
|
|
56
56
|
|
|
57
57
|
Keys use system credential protection or an explicit environment reference; clients receive separate local credentials. Saving does not probe models or select routes. Disabled sources/clients leave normal views and can be restored from **Disabled**, retaining grants/configuration without selecting a source. Closing client access does not quit its app. In-use sources require explicit replacements or pauses; pinned API requests finish on their original source. Existing user/managed app settings remain protected.
|
|
58
58
|
|
|
59
|
-
There is no automatic fallback, cross-source replay or Chat-only protocol conversion. Configured models
|
|
59
|
+
There is no automatic fallback, cross-source replay or Chat-only protocol conversion. Failed transports recover on a later request while active responses finish. Configured models do not prove online access or client compatibility: Claude App may reject non-Anthropic model IDs despite Messages support. Unknown capabilities remain conservative. No runtime dependency or enterprise policy exception is added. See the [complete API, credential and client reference](docs/REFERENCE.md#manual-apis-and-client-access).
|
|
60
60
|
|
|
61
61
|
## Microsoft 365 access
|
|
62
62
|
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -31,8 +31,16 @@ Copilot/M365 retry or request-body policy. Its lazy transport is retained per
|
|
|
31
31
|
configuration, not rebuilt or serialized against the whole catalog per request.
|
|
32
32
|
`providers/api-network.mjs` preserves enterprise routing/TLS and pins exact HTTPS
|
|
33
33
|
targets. The WinHTTP API mode checks its allowlist in JS and C#; prediction/M365
|
|
34
|
-
retain their original host restrictions. A
|
|
35
|
-
|
|
34
|
+
retain their original host restrictions. A failure before response headers marks
|
|
35
|
+
the transport unhealthy. The next request replaces it without replaying the
|
|
36
|
+
failed call; retirement waits for unrelated active responses to drain. Shutdown
|
|
37
|
+
still closes all current/retiring transports. HTTP error statuses and intentional
|
|
38
|
+
cancellation do not invalidate the transport. Node response streams are pulled
|
|
39
|
+
on demand to avoid eager delivery into an already-cancelled Web stream.
|
|
40
|
+
`operation-error.mjs` projects fixed transport phases, a local error-code
|
|
41
|
+
allowlist and socket-reuse evidence. API errors preserve their private cause,
|
|
42
|
+
but client diagnostics/logs expose only those bounded fields, not raw causes,
|
|
43
|
+
addresses, credentials, headers or prompts.
|
|
36
44
|
|
|
37
45
|
The API editor separates catalog candidates from selected models. Only selected
|
|
38
46
|
models enter the strict saved graph, with a required native protocol; unused
|
package/docs/REFERENCE.md
CHANGED
|
@@ -28,8 +28,15 @@ key. Display hints do not authorize requests. API addresses require HTTPS, no
|
|
|
28
28
|
userinfo/query/fragment, and endpoint overrides on the base address's origin.
|
|
29
29
|
Redirects are refused. Existing proxy/bypass/private-CA rules remain; unsupported
|
|
30
30
|
dynamic macOS routing fails without a direct fallback. Windows delegates system
|
|
31
|
-
routing to a target-pinned WinHTTP worker. Failed calls are not replayed
|
|
32
|
-
|
|
31
|
+
routing to a target-pinned WinHTTP worker. Failed calls are not replayed. A
|
|
32
|
+
transport failure before response headers marks that transport unhealthy; a
|
|
33
|
+
later request creates a new transport and rereads the existing routing policy.
|
|
34
|
+
Other responses already using the old transport finish before it is released.
|
|
35
|
+
HTTP denials and deliberate cancellation do not trigger this recovery.
|
|
36
|
+
Network failures retain `ccdx_api_network_unavailable` and include a bounded
|
|
37
|
+
`error.diagnostic`: a recognized local error `code`, observed `phase`, and
|
|
38
|
+
`reused_socket` (boolean or unknown). Unknown codes/phases remain `unknown`.
|
|
39
|
+
Diagnostics omit raw error text, endpoints, headers, keys and request content.
|
|
33
40
|
|
|
34
41
|
Up to 16 uniquely named manual APIs and 500 unique models per API are supported. Model IDs are limited to 160 characters; `codex-auto-review` remains an internal alias. Custom model
|
|
35
42
|
IDs are not filtered by a GPT/Claude prefix. Each model declares Messages,
|
|
@@ -41,6 +48,11 @@ or inference call. **Read models** performs one explicit catalog read, with a
|
|
|
41
48
|
support until reviewed. Opening normal views reads saved models rather than
|
|
42
49
|
probing every API. `ccdx models` labels manual models as configured, not live.
|
|
43
50
|
|
|
51
|
+
These are CCDX's routing rules, not a guarantee that every installed client
|
|
52
|
+
accepts arbitrary model names. Some Claude App versions reject non-Anthropic
|
|
53
|
+
model route IDs even when their upstream supports Messages. A saved connection
|
|
54
|
+
or successful model-list read does not prove an App conversation works.
|
|
55
|
+
|
|
44
56
|
`connections.json` beside user settings (respecting `XDG_CONFIG_HOME`) stores a
|
|
45
57
|
strict version-one graph of provider switches, API metadata and each client's
|
|
46
58
|
allowed/current sources. It stores only credential references or an environment
|
|
@@ -1127,7 +1139,7 @@ Unknown support prevents an explicitly requested exception from starting.
|
|
|
1127
1139
|
For an older updater that still requires Git, install the Release tarball directly:
|
|
1128
1140
|
|
|
1129
1141
|
```sh
|
|
1130
|
-
npm install -g https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.
|
|
1142
|
+
npm install -g https://github.com/DaleXiao/codex-copilot-dx/releases/download/v1.2.15/codex-copilot-dx-1.2.15.tgz
|
|
1131
1143
|
# Windows PowerShell: use npm.cmd instead of npm.
|
|
1132
1144
|
```
|
|
1133
1145
|
|
package/package.json
CHANGED
package/src/claude-gateway.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { createStreamPerformanceMetrics, isMessagesOutputDelta } from "./stream-
|
|
|
12
12
|
import { buildMessagesUsageRecord, recordUsage } from "./usage-store.mjs";
|
|
13
13
|
import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
14
14
|
import { decodedBodyLimitPreference } from "./user-settings.mjs";
|
|
15
|
-
import { operationErrorDetails } from "./operation-error.mjs";
|
|
15
|
+
import { operationErrorDetails, transportErrorDetails } from "./operation-error.mjs";
|
|
16
16
|
import { requestApplication } from "./request-application.mjs";
|
|
17
17
|
|
|
18
18
|
function send(res, code, value) {
|
|
@@ -151,10 +151,15 @@ export function createClaudeGatewayHandler({ provider, apiKey, log = () => {}, o
|
|
|
151
151
|
const statusCode = detail.status || (abort.reason ? abortErrorStatusCode(abort.reason) : 502);
|
|
152
152
|
failureStatus = statusCode;terminalOrigin = outcome === "cancelled" ? "client_disconnect" : statusCode < 500 && statusCode !== 429 ? "client_validation" : "transport";
|
|
153
153
|
const message = redactDiagnosticText(error.message).split(apiKey).join("[redacted]").slice(0, 240);
|
|
154
|
-
|
|
154
|
+
const diagnostic = error.code === "ccdx_api_network_unavailable" ? transportErrorDetails(error) : null;
|
|
155
|
+
log(outcome === "cancelled" ? "info" : "warn", `Claude request ${requestId}: ${detail.code}${diagnostic ? ` (${diagnostic.code}, ${diagnostic.phase})` : ""}`);
|
|
155
156
|
tracker?.setErrorOrigin(terminalOrigin);
|
|
156
157
|
if (outcome === "cancelled") return;
|
|
157
|
-
if (!res.headersSent)
|
|
158
|
+
if (!res.headersSent) {
|
|
159
|
+
const value = apiError(error.code || abort.reason || "ccdx_gateway_error", message);
|
|
160
|
+
if (diagnostic) value.error.diagnostic = diagnostic;
|
|
161
|
+
send(res, statusCode, value);
|
|
162
|
+
}
|
|
158
163
|
else if (!res.destroyed && !res.writableEnded) res.end(`event: error\ndata: ${JSON.stringify(apiError("ccdx_gateway_error", message))}\n\n`);
|
|
159
164
|
} finally {
|
|
160
165
|
release();abort.cleanup();
|
package/src/operation-error.mjs
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { redactDiagnosticText } from "./diagnostic-text.mjs";
|
|
2
2
|
|
|
3
|
+
const TRANSPORT_CODES = new Set([
|
|
4
|
+
"ECONNRESET", "ECONNREFUSED", "ECONNABORTED", "EPIPE", "ETIMEDOUT", "ENOTFOUND", "EAI_AGAIN", "EHOSTUNREACH", "ENETUNREACH", "EPERM", "EACCES",
|
|
5
|
+
"EPROTO", "ERR_SSL_WRONG_VERSION_NUMBER", "ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR", "ERR_TLS_CERT_ALTNAME_INVALID", "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
6
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY", "SELF_SIGNED_CERT_IN_CHAIN", "DEPTH_ZERO_SELF_SIGNED_CERT", "CERT_HAS_EXPIRED", "CERT_NOT_YET_VALID",
|
|
7
|
+
"ERR_INVALID_ARG_TYPE", "ERR_INVALID_CHAR", "ERR_INVALID_PROTOCOL", "ERR_HTTP_INVALID_HEADER_VALUE", "ERR_HTTP_CONTENT_LENGTH_MISMATCH", "ERR_STREAM_PREMATURE_CLOSE",
|
|
8
|
+
"HPE_INVALID_CONSTANT", "HPE_INVALID_STATUS", "HPE_INVALID_HEADER_TOKEN", "HPE_UNEXPECTED_CONTENT_LENGTH", "HPE_INVALID_CONTENT_LENGTH", "HPE_INVALID_CHUNK_SIZE", "HPE_HEADER_OVERFLOW",
|
|
9
|
+
]);
|
|
10
|
+
const TRANSPORT_PHASES = new Set(["request", "dns", "connect", "tls", "response", "unknown"]);
|
|
11
|
+
|
|
12
|
+
// Project only local error codes and fixed phases, never raw errors, URLs or headers.
|
|
13
|
+
export function transportErrorDetails(error) {
|
|
14
|
+
const value = error?.transport;
|
|
15
|
+
const code = [value?.code, error?.code, error?.cause?.code].find(code => TRANSPORT_CODES.has(code)) || "unknown";
|
|
16
|
+
return { code, phase: TRANSPORT_PHASES.has(value?.phase) ? value.phase : "unknown",
|
|
17
|
+
reused_socket: typeof value?.reused_socket === "boolean" ? value.reused_socket : null };
|
|
18
|
+
}
|
|
19
|
+
|
|
3
20
|
export function operationError(code, message, { status = null, retryAt = null } = {}) {
|
|
4
21
|
return Object.assign(new Error(message), { code, status, retryAt });
|
|
5
22
|
}
|
|
@@ -6,6 +6,7 @@ import { resolveNetworkRoute, networkProxyFor, bypassNetworkProxy } from "../net
|
|
|
6
6
|
import { createProxyAgent } from "../proxy-tunnel.mjs";
|
|
7
7
|
import { apiUrl, accessError } from "../access-settings.mjs";
|
|
8
8
|
import { privateHelperEnvironment } from "../private-helper-environment.mjs";
|
|
9
|
+
import { transportErrorDetails } from "../operation-error.mjs";
|
|
9
10
|
|
|
10
11
|
export async function createApiNetwork({ targets, env = process.env, platform = process.platform, signal,
|
|
11
12
|
requestImpl = https.request, exec = promisify(execFile), startWindowsNetwork } = {}) {
|
|
@@ -22,30 +23,65 @@ export async function createApiNetwork({ targets, env = process.env, platform =
|
|
|
22
23
|
requestImpl = worker.requestImpl;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
const agent = worker ? undefined : createProxyAgent(plan);let closed = false;
|
|
26
|
+
const agent = worker ? undefined : createProxyAgent(plan);let closed = false, broken = false, retiring = false, active = 0, finishRetiring;
|
|
27
|
+
const close = () => { if (closed) return;closed = true;agent?.destroy();worker?.close();finishRetiring?.(); };
|
|
26
28
|
return {
|
|
27
|
-
healthy: () => !closed && (!worker || worker.healthy()),
|
|
29
|
+
healthy: () => !closed && !broken && !retiring && (!worker || worker.healthy()),
|
|
28
30
|
fetch(raw, init = {}) {
|
|
29
31
|
return new Promise((resolve, reject) => {
|
|
30
32
|
let url;try { url = new URL(raw); } catch { reject(accessError("ccdx_api_url_invalid"));return; }
|
|
31
|
-
if (closed || !urls.has(url.href) || !["GET", "POST"].includes(init.method || "GET")) { reject(accessError("ccdx_api_url_invalid"));return; }
|
|
33
|
+
if (closed || retiring || !urls.has(url.href) || !["GET", "POST"].includes(init.method || "GET")) { reject(accessError("ccdx_api_url_invalid"));return; }
|
|
32
34
|
if (init.signal?.aborted) { reject(init.signal.reason);return; }
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
active++;
|
|
36
|
+
let req, incoming, socket, phase = "request", handedOff = false, released = false;
|
|
37
|
+
const release = () => { if (released) return;released = true;active--;if (retiring && !active) close(); };
|
|
38
|
+
const lookup = error => { phase = error ? "dns" : "connect"; };
|
|
39
|
+
const connected = () => { phase = "tls"; };
|
|
40
|
+
const secure = () => { phase = "request"; };
|
|
41
|
+
const cleanup = () => {
|
|
42
|
+
init.signal?.removeEventListener("abort", abort);
|
|
43
|
+
socket?.off("lookup", lookup);socket?.off("connect", connected);socket?.off("secureConnect", secure);
|
|
44
|
+
};
|
|
45
|
+
const failed = error => {
|
|
46
|
+
if (!handedOff && !init.signal?.aborted) broken = true;
|
|
47
|
+
cleanup();
|
|
48
|
+
const failure = new Error("API transport failed", { cause: error });
|
|
49
|
+
failure.transport = { ...transportErrorDetails(error), phase, reused_socket: typeof req?.reusedSocket === "boolean" ? req.reusedSocket : null };
|
|
50
|
+
release();
|
|
51
|
+
reject(failure);
|
|
52
|
+
};
|
|
35
53
|
const abort = () => { req?.destroy(init.signal.reason || accessError("ccdx_api_cancelled"));incoming?.destroy(); };
|
|
36
54
|
try {
|
|
37
55
|
req = requestImpl({ hostname: worker ? url.hostname : url.hostname.replace(/^\[|\]$/g, ""), port: Number(url.port || 443), protocol: "https:", path: url.pathname,
|
|
38
56
|
method: init.method || "GET", headers: { ...Object.fromEntries(new Headers(init.headers)), "accept-encoding": "identity" }, agent, rejectUnauthorized: true }, res => {
|
|
39
|
-
|
|
57
|
+
phase = "response";incoming = res;
|
|
58
|
+
const finished = () => { cleanup();release(); };
|
|
59
|
+
res.once("end", finished);res.once("close", finished);res.on("error", failed);
|
|
40
60
|
const headers = new Headers();for (const [key, value] of Object.entries(res.headers)) for (const item of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(key, String(item));
|
|
41
|
-
try {
|
|
42
|
-
|
|
61
|
+
try {
|
|
62
|
+
const empty = [204, 205, 304].includes(res.statusCode);if (empty) res.resume();
|
|
63
|
+
// Pull only when the consumer reads; eager Node 22 delivery can enqueue after cancellation.
|
|
64
|
+
const response = new Response(empty ? null : Readable.toWeb(res, { strategy: { highWaterMark: 0 } }), { status: res.statusCode, headers });
|
|
65
|
+
handedOff = true;resolve(response);
|
|
66
|
+
}
|
|
67
|
+
catch (error) { failed(error);res.destroy(); }
|
|
43
68
|
});
|
|
44
|
-
req.
|
|
69
|
+
req.once("socket", value => {
|
|
70
|
+
socket = value;
|
|
71
|
+
if (!value.connecting || req.reusedSocket) return;
|
|
72
|
+
phase = "connect";value.once("lookup", lookup);value.once("connect", connected);value.once("secureConnect", secure);
|
|
73
|
+
});
|
|
74
|
+
req.on("error", failed);init.signal?.addEventListener("abort", abort, { once: true });
|
|
45
75
|
if (init.signal?.aborted) { abort();return; }req.end(init.body);
|
|
46
|
-
} catch (error) {
|
|
76
|
+
} catch (error) { failed(error);req?.destroy(); }
|
|
47
77
|
});
|
|
48
78
|
},
|
|
49
|
-
|
|
79
|
+
retire() {
|
|
80
|
+
retiring = true;
|
|
81
|
+
if (closed) return Promise.resolve();
|
|
82
|
+
if (!active) { close();return Promise.resolve(); }
|
|
83
|
+
return new Promise(resolve => { finishRetiring = resolve; });
|
|
84
|
+
},
|
|
85
|
+
close,
|
|
50
86
|
};
|
|
51
87
|
}
|
package/src/providers/api.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { MAX_UPSTREAM_MODEL_CATALOG_BYTES, readBoundedResponseText } from "../ht
|
|
|
9
9
|
import { markUpstreamHeaders } from "../stream-performance.mjs";
|
|
10
10
|
import { createApiNetwork } from "./api-network.mjs";
|
|
11
11
|
import { checkedApiKey } from "../api-secrets.mjs";
|
|
12
|
+
import { transportErrorDetails } from "../operation-error.mjs";
|
|
12
13
|
|
|
13
14
|
const paths = { messages: "/v1/messages", responses: "/v1/responses", chat: "/v1/chat/completions" };
|
|
14
15
|
export function apiCatalog(config) {
|
|
@@ -28,11 +29,16 @@ export function createApiProvider({ config, secrets, env = process.env, platform
|
|
|
28
29
|
if (config.endpoints.messages) targets.push(config.endpoints.messages.replace(/\/+$/, "") + "/count_tokens");
|
|
29
30
|
if (config.endpoints.responses) targets.push(config.endpoints.responses.replace(/\/+$/, "") + "/compact");
|
|
30
31
|
let network, flight, closed = false;
|
|
32
|
+
const retiring = new Set();
|
|
31
33
|
const registry = { models: { data: catalog.filter(model => model.supported_endpoints.includes(paths.responses)) }, source: "configured", generation };
|
|
32
34
|
const getNetwork = async signal => {
|
|
33
35
|
if (closed) throw accessError("ccdx_api_closed", 503);
|
|
34
36
|
if (network && (network.healthy?.() ?? true)) return network;
|
|
35
|
-
network
|
|
37
|
+
const previous = network;network = null;
|
|
38
|
+
if (previous?.retire) {
|
|
39
|
+
retiring.add(previous);
|
|
40
|
+
void Promise.resolve(previous.retire()).then(() => retiring.delete(previous), () => { previous.close();retiring.delete(previous); });
|
|
41
|
+
} else previous?.close();
|
|
36
42
|
flight ||= networkFactory({ targets, env, platform, signal }).then(value => { if (closed) { value.close();throw accessError("ccdx_api_closed", 503); }network = value;return value; }).finally(() => { flight = null; });
|
|
37
43
|
return flight;
|
|
38
44
|
};
|
|
@@ -63,7 +69,14 @@ export function createApiProvider({ config, secrets, env = process.env, platform
|
|
|
63
69
|
return new Response(JSON.stringify({ type: "error", error: { type: "api_error", code, message: code } }), { status: result.status, headers: safeHeaders });
|
|
64
70
|
}
|
|
65
71
|
return result;
|
|
66
|
-
} catch (error) {
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (options.signal?.aborted) throw error;
|
|
74
|
+
if (error.code === "ccdx_api_redirect_refused") throw error;
|
|
75
|
+
const failure = accessError("ccdx_api_network_unavailable", 502);
|
|
76
|
+
Object.defineProperty(failure, "cause", { value: error });
|
|
77
|
+
failure.transport = transportErrorDetails(error);failure.jsonBody.error.diagnostic = failure.transport;
|
|
78
|
+
throw failure;
|
|
79
|
+
}
|
|
67
80
|
}
|
|
68
81
|
const client = {
|
|
69
82
|
listModels: async () => ({ status: 200, body: JSON.stringify(registry.models) }),
|
|
@@ -124,6 +137,6 @@ export function createApiProvider({ config, secrets, env = process.env, platform
|
|
|
124
137
|
if (!resp.ok) { await resp.body?.cancel();const code = `ccdx_api_http_${resp.status}`;return { resp: new Response(JSON.stringify({ error: { code, message: code } }), { status: resp.status, headers: { "Content-Type": "application/json" } }), reqContext: context, errorText: code, usedRetryPolicies: new Set() }; }
|
|
125
138
|
return { resp, reqContext: context, errorText: undefined, usedRetryPolicies: new Set() };
|
|
126
139
|
} },
|
|
127
|
-
close() { closed = true;network?.close(); },
|
|
140
|
+
close() { closed = true;network?.close();for (const previous of retiring) previous.close();retiring.clear(); },
|
|
128
141
|
};
|
|
129
142
|
}
|