codex-copilot-dx 0.9.31 → 0.9.34
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 +8 -8
- package/bin/cli.mjs +37 -29
- package/docs/ARCHITECTURE.md +50 -2
- package/docs/REFERENCE.md +77 -8
- package/package.json +3 -2
- package/src/adapter.mjs +14 -7
- package/src/auth-credentials.mjs +242 -0
- package/src/auth-device-flow.mjs +210 -0
- package/src/auth-profile.mjs +2 -2
- package/src/auth.mjs +10 -450
- package/src/bounded-file.mjs +28 -0
- package/src/cli-status.mjs +2 -0
- package/src/client-integration.mjs +10 -3
- package/src/config.mjs +3 -2
- package/src/copilot.mjs +1 -1
- package/src/credential-permissions.mjs +21 -0
- package/src/dashboard/index.html +2 -0
- package/src/dashboard/language.js +3 -0
- package/src/dashboard/status.js +192 -0
- package/src/dashboard/ui.js +6 -343
- package/src/dashboard/usage.js +161 -0
- package/src/dashboard-api.mjs +5 -4
- package/src/dashboard.mjs +2 -0
- package/src/doctor.mjs +20 -0
- package/src/http-transport.mjs +7 -0
- package/src/image-provider-config.mjs +2 -2
- package/src/launcher.mjs +26 -16
- package/src/live-models.mjs +16 -0
- package/src/model-cache.mjs +2 -1
- package/src/native-prediction-profile.mjs +2 -1
- package/src/native-prediction-recovery.mjs +39 -0
- package/src/native-prediction-route.mjs +94 -0
- package/src/native-prediction-state.mjs +7 -1
- package/src/native-prediction-transport.mjs +6 -0
- package/src/native-prediction.mjs +42 -4
- package/src/package-update.mjs +44 -7
- package/src/profile-model-runtime.mjs +1 -1
- package/src/response-failures.mjs +7 -0
- package/src/startup-ui.mjs +54 -0
- package/src/status.mjs +1 -1
- package/src/stream-performance.mjs +4 -0
- package/src/user-settings.mjs +2 -2
- package/src/windows-prediction-network.mjs +1 -1
|
@@ -65,6 +65,7 @@ export async function startPredictionTransport({
|
|
|
65
65
|
const sockets = new Set();
|
|
66
66
|
const upstreams = new Set();
|
|
67
67
|
let closing = false;
|
|
68
|
+
let listenerError = false;
|
|
68
69
|
const gateway = https.createServer({ key, cert, minVersion: "TLSv1.2" }, (req, res) => {
|
|
69
70
|
let target;
|
|
70
71
|
try {
|
|
@@ -240,11 +241,16 @@ export async function startPredictionTransport({
|
|
|
240
241
|
gateway.emit("connection", socket);
|
|
241
242
|
});
|
|
242
243
|
proxy.on("clientError", (_error, socket) => socket.destroy());
|
|
244
|
+
proxy.on("error", (error) => {
|
|
245
|
+
listenerError = true;
|
|
246
|
+
onEvent({ type: "bridge_error", error: operationErrorDetails(error) });
|
|
247
|
+
});
|
|
243
248
|
let port;
|
|
244
249
|
try { port = await listen(proxy, listenPort); }
|
|
245
250
|
catch (error) { agent?.destroy();gateway.close();throw error; }
|
|
246
251
|
return {
|
|
247
252
|
port, pacUrl: `http://127.0.0.1:${port}/proxy.pac`,
|
|
253
|
+
healthy() { return !closing && !listenerError && proxy.listening; },
|
|
248
254
|
async close() {
|
|
249
255
|
closing = true;
|
|
250
256
|
for (const upstream of upstreams) upstream.destroy();
|
|
@@ -8,6 +8,7 @@ import { retirePredictionIntegration } from "./prediction-retirement.mjs";
|
|
|
8
8
|
import { networkRouteSnapshot } from "./network-route.mjs";
|
|
9
9
|
import { withFileLock } from "./lock.mjs";
|
|
10
10
|
import { windowsSystemProxy, windowsProxySettings, windowsProxyText } from "./native-prediction-windows.mjs";
|
|
11
|
+
import { updatePredictionRoute } from "./native-prediction-route.mjs";
|
|
11
12
|
|
|
12
13
|
function systemProxy(exec = execFileSync, { platform = process.platform, env = process.env } = {}) {
|
|
13
14
|
if (platform === "win32") return windowsSystemProxy({ exec, env });
|
|
@@ -49,12 +50,14 @@ async function runPredictionCommandUnlocked({ action = "status", env = process.e
|
|
|
49
50
|
if (action === "status") {
|
|
50
51
|
output(`Native prediction preference: ${settings.enabled ? "on" : "off"} (default: off)`);
|
|
51
52
|
output("Uses the conversation's model. No prediction MCP, Hook, or panel.");
|
|
52
|
-
if (settings.enabled && !predictionAppMatches(settings.app)) output("Codex App changed;
|
|
53
|
+
if (settings.enabled && !predictionAppMatches(settings.app)) output("Codex App changed; bridge startup will recheck compatibility. Unsupported changes still require explicit setup.");
|
|
53
54
|
if (runtimeSnapshot) {
|
|
54
55
|
try {
|
|
55
56
|
const runtime = (await runtimeSnapshot())?.client_integrations?.prediction;
|
|
56
57
|
if (runtime) {
|
|
57
58
|
output(`Bridge: ${runtime.bridge}; client route: ${runtime.client_route}; visible candidate: ${runtime.candidate}`);
|
|
59
|
+
if (runtime.launch_route) output(`App launch route: ${runtime.launch_route}; persistent route: ${runtime.persistence || "unknown"}`);
|
|
60
|
+
if (runtime.recovery) output(`Bridge recovery: ${runtime.recovery.recovered} recovered; ${runtime.recovery.attempts}/3 attempts used`);
|
|
58
61
|
if (runtime.reason) output(runtime.reason);
|
|
59
62
|
for (const [name, event] of Object.entries(runtime.configuration || {})) output(`${name}: HTTP ${event.status}${event.modified ? " (local compatibility)" : " (upstream)"}`);
|
|
60
63
|
} else output("Runtime prediction state: unavailable; status is a saved preference, not proof of a visible suggestion.");
|
|
@@ -71,6 +74,7 @@ async function runPredictionCommandUnlocked({ action = "status", env = process.e
|
|
|
71
74
|
if (settings.certificateHash && settings.store) {
|
|
72
75
|
try {
|
|
73
76
|
assertCodexClosed(opts);
|
|
77
|
+
await updatePredictionRoute({ ...paths, remove: true, assertClosed: () => assertCodexClosed(opts) });
|
|
74
78
|
const certificate = readPredictionCertificate(certificateDirectory(settings, paths), { ...opts, allowExpired: true });
|
|
75
79
|
if (certificate.hash !== settings.certificateHash) throw new Error("Prediction certificate changed; trust cleanup was skipped");
|
|
76
80
|
await updatePredictionTrust(settings.store, certificate, { remove: true });
|
|
@@ -150,7 +154,22 @@ export async function startNativePrediction({ env = process.env, platform = proc
|
|
|
150
154
|
&& (!Number.isInteger(settings.bridgePort) || settings.bridgePort < 1024 || settings.bridgePort > 65535)) {
|
|
151
155
|
throw new Error("Saved prediction bridge port is invalid; no route was replaced");
|
|
152
156
|
}
|
|
153
|
-
if (
|
|
157
|
+
if (options.expectedPort !== undefined && settings.bridgePort !== options.expectedPort) throw new Error("Prediction route changed; automatic recovery was skipped");
|
|
158
|
+
if (!predictionAppMatches(settings.app)) {
|
|
159
|
+
const current = (options.resolveApp || installedPredictionApp)({ ...opts,
|
|
160
|
+
...(platform === "win32" && settings.app?.profile ? { preferredProfile: settings.app.profile } : {}) });
|
|
161
|
+
if (current.app !== settings.app?.app || (platform === "win32" && current.profile !== settings.app?.profile)) {
|
|
162
|
+
throw new Error("Codex App identity/profile changed; run ccdx prediction on after quitting it to recheck compatibility");
|
|
163
|
+
}
|
|
164
|
+
const settingsFile = predictionPaths(opts).settings;
|
|
165
|
+
await withFileLock(`${settingsFile}.lock`, () => {
|
|
166
|
+
const latest = readPredictionSettings(opts);
|
|
167
|
+
if (JSON.stringify(latest) !== JSON.stringify(settings)) throw new Error("Prediction setup changed during App compatibility recheck");
|
|
168
|
+
writePredictionSettings({ ...latest, app: current }, opts);
|
|
169
|
+
}, { timeoutMs: 2000 });
|
|
170
|
+
settings.app = current;
|
|
171
|
+
warning("Codex App compatibility rechecked; prediction port and trust were preserved");
|
|
172
|
+
}
|
|
154
173
|
const paths = predictionPaths({ ...opts, app: settings.app });
|
|
155
174
|
if (settings.store !== paths.store || !fs.existsSync(paths.store)) throw new Error("Prediction profile trust is unavailable; run ccdx prediction on after quitting Codex");
|
|
156
175
|
const certificate = readPredictionCertificate(certificateDirectory(settings, paths), opts);
|
|
@@ -214,12 +233,31 @@ export async function startNativePrediction({ env = process.env, platform = proc
|
|
|
214
233
|
throw error;
|
|
215
234
|
}
|
|
216
235
|
state?.running(windowsNetwork ? { source: "system", type: "auto", bypass_rules: null, proxy_credentials: false } : networkRouteSnapshot(networkRoute));
|
|
217
|
-
warning("Native prediction bridge enabled; only the two configuration hosts use its App-only route.");
|
|
218
|
-
warning("If Codex uses a different or missing prediction route, fully quit it and run ccdx again.");
|
|
219
236
|
return {
|
|
220
237
|
app: settings.app.app,
|
|
221
238
|
...(platform === "win32" ? { profile: paths.profile } : {}),
|
|
222
239
|
pacUrl: transport.pacUrl,
|
|
240
|
+
enabled() { return enabled; },
|
|
241
|
+
healthy() { return transport.healthy() && (!windowsNetwork || windowsNetwork.healthy()); },
|
|
242
|
+
async prepareRoute() {
|
|
243
|
+
try {
|
|
244
|
+
const direct = !windowsNetwork && !networkRoute?.http && !networkRoute?.https && !networkRoute?.bypass?.length;
|
|
245
|
+
if (!direct) {
|
|
246
|
+
// A profile previously configured on a direct network must not pin
|
|
247
|
+
// that local PAC after the environment switches to company routing.
|
|
248
|
+
await updatePredictionRoute({ ...paths, remove: true, assertClosed: () => assertCodexClosed(opts) });
|
|
249
|
+
}
|
|
250
|
+
const result = await updatePredictionRoute({ ...paths, pacUrl: transport.pacUrl, direct,
|
|
251
|
+
assertClosed: () => assertCodexClosed(opts) });
|
|
252
|
+
state?.persistence(result);
|
|
253
|
+
if (result.status === "preserved") warning(`Prediction route persistence skipped: ${result.reason}`);
|
|
254
|
+
return result;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
state?.persistence({ status: "pending" });
|
|
257
|
+
if (!error.message.startsWith("Quit Codex App")) warning(`Prediction route persistence deferred: ${error.message}`);
|
|
258
|
+
return { status: "pending" };
|
|
259
|
+
}
|
|
260
|
+
},
|
|
223
261
|
args: [...(platform === "win32" ? [`--user-data-dir=${paths.profile}`] : []), `--proxy-pac-url=${transport.pacUrl}`],
|
|
224
262
|
async close() { clearInterval(timer); await transport.close(); windowsNetwork?.close(); state?.stopped(); },
|
|
225
263
|
};
|
package/src/package-update.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
1
|
+
import { spawn, execFileSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
3
5
|
import { createInterface } from "node:readline/promises";
|
|
4
6
|
import { lookupLatestRelease, githubReleaseVersion } from "./version.mjs";
|
|
7
|
+
import { terminalCell } from "./terminal-text.mjs";
|
|
5
8
|
|
|
6
9
|
const PACKAGE_NAME = "codex-copilot-dx";
|
|
7
10
|
const UPDATE_SPECS = {
|
|
@@ -9,6 +12,38 @@ const UPDATE_SPECS = {
|
|
|
9
12
|
github: "github:DaleXiao/codex-copilot-dx",
|
|
10
13
|
};
|
|
11
14
|
|
|
15
|
+
function npmLaunch(args, { platform, env }) {
|
|
16
|
+
if (platform !== "win32") return { command: "npm", args, options: {} };
|
|
17
|
+
return { command: path.win32.join(env.SystemRoot || env.WINDIR || "C:\\Windows", "System32", "cmd.exe"),
|
|
18
|
+
args: ["/d", "/s", "/v:off", "/c", `"npm.cmd ${args.join(" ")}"`],
|
|
19
|
+
options: { windowsVerbatimArguments: true, windowsHide: true } };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function inspectPackageUpdateEnvironment({ env = process.env, platform = process.platform,
|
|
23
|
+
packageRoot = fileURLToPath(new URL("../", import.meta.url)), nodePath = process.execPath, exec = execFileSync } = {}) {
|
|
24
|
+
const paths = platform === "win32" ? path.win32 : path;
|
|
25
|
+
const commandName = platform === "win32" ? "npm.cmd" : "npm";
|
|
26
|
+
const searchPath = Object.entries(env).find(([key]) => key.toLowerCase() === "path")?.[1] || "";
|
|
27
|
+
const npmPath = searchPath.split(platform === "win32" ? ";" : ":")
|
|
28
|
+
.filter(Boolean).map(directory => paths.join(directory.replace(/^"|"$/g, ""), commandName))
|
|
29
|
+
.find(file => { try { return fs.statSync(file).isFile(); } catch { return false; } });
|
|
30
|
+
const result = { node: nodePath, package_root: paths.resolve(packageRoot), npm: npmPath || null,
|
|
31
|
+
prefix: null, target: null, state: "unavailable" };
|
|
32
|
+
if (!npmPath) return result;
|
|
33
|
+
try {
|
|
34
|
+
const launch = npmLaunch(["prefix", "--global"], { platform, env });
|
|
35
|
+
const value = exec(launch.command, launch.args, { env, shell: false, stdio: ["ignore", "pipe", "pipe"], encoding: "utf8", timeout: 3000,
|
|
36
|
+
maxBuffer: 64 * 1024, ...launch.options }).trim();
|
|
37
|
+
if (!paths.isAbsolute(value) || /[\r\n\0]/.test(value)) return result;
|
|
38
|
+
result.prefix = paths.normalize(value);
|
|
39
|
+
result.target = paths.join(value, ...(platform === "win32" ? [] : ["lib"]), "node_modules", PACKAGE_NAME);
|
|
40
|
+
const normalize = file => platform === "win32" ? paths.resolve(file).toLowerCase() : paths.resolve(file);
|
|
41
|
+
const ownedGlobal = result.package_root.endsWith(paths.join("node_modules", PACKAGE_NAME));
|
|
42
|
+
result.state = !ownedGlobal ? "checkout" : normalize(result.package_root) === normalize(result.target) ? "matched" : "different";
|
|
43
|
+
return result;
|
|
44
|
+
} catch { return result; } // Preflight cannot replace the installer's normal error handling.
|
|
45
|
+
}
|
|
46
|
+
|
|
12
47
|
export function normalizeUpdateSource(value) {
|
|
13
48
|
const source = String(value || "").trim().toLowerCase();
|
|
14
49
|
if (source === "gh") return "github";
|
|
@@ -59,6 +94,7 @@ export async function runPackageUpdateCommand({
|
|
|
59
94
|
source,
|
|
60
95
|
spawnImpl = spawn,
|
|
61
96
|
fetchImpl = fetch,
|
|
97
|
+
inspectEnvironmentFn = inspectPackageUpdateEnvironment,
|
|
62
98
|
} = {}) {
|
|
63
99
|
let selectedSource = normalizeUpdateSource(source);
|
|
64
100
|
if (source && !selectedSource) throw new Error(`Update source must be npm or github: ${source}`);
|
|
@@ -101,17 +137,18 @@ export async function runPackageUpdateCommand({
|
|
|
101
137
|
const update = globalUpdateCommand(selectedSource, { platform, releaseTag: release?.tagName });
|
|
102
138
|
const sourceLabel = selectedSource === "npm" ? "npm registry" : `GitHub release ${release.tagName}`;
|
|
103
139
|
output.write(`Updating ${PACKAGE_NAME} from ${sourceLabel}...\n`);
|
|
104
|
-
const
|
|
140
|
+
const environment = inspectEnvironmentFn({ env, platform });
|
|
141
|
+
if (environment?.state === "different") {
|
|
142
|
+
output.write(`Warning: npm targets ${terminalCell(environment.target)}, not the running package at ${terminalCell(environment.package_root)}. Existing PATH and prefix choices were preserved.\n`);
|
|
143
|
+
}
|
|
105
144
|
// npm.cmd needs cmd.exe. Only fixed install arguments and a validated stable
|
|
106
145
|
// release tag enter this command line; no user-supplied command is evaluated.
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const args = windows ? ["/d", "/s", "/v:off", "/c", `"${[update.command, ...update.args].join(" ")}"`] : update.args;
|
|
110
|
-
const child = spawnImpl(command, args, {
|
|
146
|
+
const launch = npmLaunch(update.args, { platform, env });
|
|
147
|
+
const child = spawnImpl(launch.command, launch.args, {
|
|
111
148
|
env,
|
|
112
149
|
shell: false,
|
|
113
150
|
stdio: "inherit",
|
|
114
|
-
...
|
|
151
|
+
...launch.options,
|
|
115
152
|
});
|
|
116
153
|
await waitForExit(child);
|
|
117
154
|
output.write(`Updated ${PACKAGE_NAME} from ${sourceLabel}. Restart the running adapter to use the new version.\n`);
|
|
@@ -122,7 +122,7 @@ export function createProfileModelRuntime({
|
|
|
122
122
|
}
|
|
123
123
|
const gptModelIds = gptModelIdsFromCopilotModels(models);
|
|
124
124
|
if (gptModelIds.length) {
|
|
125
|
-
emit("ok", `Refreshed GPT models from GitHub Copilot: ${gptModelIds.
|
|
125
|
+
emit("ok", `Refreshed GPT models from GitHub Copilot: ${gptModelIds.length} available; run ${commandName} models for the list`);
|
|
126
126
|
} else {
|
|
127
127
|
emit("warn", "Copilot models response contained no GPT models");
|
|
128
128
|
}
|
|
@@ -99,3 +99,10 @@ export function createResponseFailureDiagnostics({
|
|
|
99
99
|
},
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
export function buildHttpFailureDetails({ statusCode, route, requestId, model, code, origin, headers }) {
|
|
104
|
+
const details = responseFailureDetails({ model, error: { code: typeof code === "string" && /^[a-z\d_.:-]{1,80}$/i.test(code) ? code : `http_${statusCode}`,
|
|
105
|
+
message: "HTTP request failed; original response was preserved." } }, "http.error", { headers });
|
|
106
|
+
return { ...details, request_id: requestId, http_status: statusCode, route,
|
|
107
|
+
origin: origin || (route === "not_found" ? "route" : "unclassified"), local_message: true };
|
|
108
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { status } from "./status.mjs";
|
|
2
|
+
import { terminalCell } from "./terminal-text.mjs";
|
|
3
|
+
|
|
4
|
+
// The favicon's three ellipses, rasterized as terminal half-blocks. No runtime
|
|
5
|
+
// graphics library or terminal cursor control is needed.
|
|
6
|
+
const ATOM = [
|
|
7
|
+
" ▄█▀█▄▄ ▄▄█▀█▄ ",
|
|
8
|
+
" █ ███ █ ",
|
|
9
|
+
" █ ▄▄▄█▄█▄▄▄ █ ",
|
|
10
|
+
" ▄▄▀▀█▀█▀ ▀█▀█▀▀▄▄ ",
|
|
11
|
+
" █▀ ▀█ ▄█▄ █▀ ▀█ ",
|
|
12
|
+
" ▀█▄ █▀▄ ▀ ▄▀█ ▄█▀ ",
|
|
13
|
+
" ▀█▀███▄▄▄███▀█▀ ",
|
|
14
|
+
" █ █▄█ █ ",
|
|
15
|
+
" █▄ ▄▄█▀█▄▄ ▄█ ",
|
|
16
|
+
" ▀▀▀ ▀▀▀ ",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export function startupBanner({ commandName = "ccdx", version, stream = process.stdout, env = process.env } = {}) {
|
|
20
|
+
const title = `${terminalCell(commandName)} v${terminalCell(version)} by Dale Xiao`;
|
|
21
|
+
const color = stream.isTTY === true && !Object.hasOwn(env, "NO_COLOR") && env.TERM !== "dumb";
|
|
22
|
+
if (!color || Number(stream.columns || 80) < 72) return `${title}\nUse Codex App with GitHub Copilot`;
|
|
23
|
+
const labels = new Map([[3, `${terminalCell(commandName).toUpperCase()} v${terminalCell(version)}`], [4, "by Dale Xiao"], [6, "Codex App + GitHub Copilot"]]);
|
|
24
|
+
return ATOM.map((line, i) => `\x1b[38;2;166;245;168m${line}\x1b[0m${labels.has(i) ? ` ${labels.get(i)}` : ""}`).join("\n");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function startupCheck(kind, name, detail) {
|
|
28
|
+
const prefix = status(kind, "").trimEnd();
|
|
29
|
+
return `${prefix.padEnd(8)}${terminalCell(name).padEnd(12)}${terminalCell(detail)}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function startupReady({ baseUrl, commandName = "ccdx", reused = false } = {}) {
|
|
33
|
+
return ["", startupCheck("ok", "Ready", reused ? "Using the existing CCDX adapter" : "Core service available"), "",
|
|
34
|
+
`Web UI ${baseUrl}`, `Help ${commandName} help`, ...(!reused ? ["Stop Ctrl+C"] : []), ""].join("\n");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function startupLogger(name, output = console.log) {
|
|
38
|
+
return value => {
|
|
39
|
+
for (const line of String(value).split("\n")) {
|
|
40
|
+
const match = /^\[(OK|INFO|WARN|ERR|WAIT|DEBUG)\]\s+(.*)$/.exec(line);
|
|
41
|
+
output(match ? startupCheck(match[1].toLowerCase(), name, match[2]) : line);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function predictionStartupCheck(prediction) {
|
|
47
|
+
if (!prediction?.configured) return startupCheck("info", "Prediction", "Off");
|
|
48
|
+
if (prediction.bridge !== "running") return startupCheck("warn", "Prediction", prediction.reason || "Bridge unavailable; core service is available");
|
|
49
|
+
const route = prediction.launch_route;
|
|
50
|
+
const summary = startupCheck(route === "unverified" ? "warn" : "info", "Prediction", route === "verified"
|
|
51
|
+
? "Bridge running; App route verified; suggestion not checked"
|
|
52
|
+
: "Bridge running; App route not verified; suggestion not checked");
|
|
53
|
+
return prediction.recovery ? `${summary}\n${startupCheck("info", "Recovery", `${prediction.recovery.attempts}/3 attempts used; persistent route ${prediction.persistence || "unknown"}`)}` : summary;
|
|
54
|
+
}
|
package/src/status.mjs
CHANGED
|
@@ -13,5 +13,5 @@ export function status(kind, message) {
|
|
|
13
13
|
const requestContext = currentRequestContext();
|
|
14
14
|
const requestId = requestContext?.showRequestId ? requestContext.requestId : "";
|
|
15
15
|
const context = requestId ? ` request_id=${requestId}` : "";
|
|
16
|
-
return `${LABELS[kind] || LABELS.info}${context} ${message}`;
|
|
16
|
+
return `${(LABELS[kind] || LABELS.info).padEnd(8)}${context ? `${context.trimStart()} ` : ""}${message}`;
|
|
17
17
|
}
|
|
@@ -381,10 +381,14 @@ export function markStreamFailure() {
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
export function markResponseModel(model) {
|
|
384
|
+
const context = currentRequestContext();
|
|
385
|
+
if (context) context.model = model;
|
|
384
386
|
tracker()?.setModel?.(model);
|
|
385
387
|
}
|
|
386
388
|
|
|
387
389
|
export function markResponseErrorOrigin(origin) {
|
|
390
|
+
const context = currentRequestContext();
|
|
391
|
+
if (context) context.errorOrigin = origin;
|
|
388
392
|
tracker()?.setErrorOrigin?.(origin);
|
|
389
393
|
}
|
|
390
394
|
|
package/src/user-settings.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { readBoundedFileSync } from "./bounded-file.mjs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { atomicWriteFileIfChangedSync } from "./atomic-file.mjs";
|
|
@@ -39,7 +39,7 @@ function invalidSettings(filePath, reason) {
|
|
|
39
39
|
export function readUserSettings({ env = process.env, home = os.homedir(), strict = false } = {}) {
|
|
40
40
|
const filePath = userSettingsPath({ env, home });
|
|
41
41
|
try {
|
|
42
|
-
const parsed = JSON.parse(
|
|
42
|
+
const parsed = JSON.parse(readBoundedFileSync(filePath, { encoding: "utf8" }));
|
|
43
43
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
44
44
|
throw invalidSettings(filePath, "expected a JSON object");
|
|
45
45
|
}
|
|
@@ -119,5 +119,5 @@ export async function startWindowsPredictionNetwork({ settings, env = process.en
|
|
|
119
119
|
if(stopped)queueMicrotask(()=>req.destroy(failure("proxy_worker_closed")));
|
|
120
120
|
return req;
|
|
121
121
|
};
|
|
122
|
-
return {script,requestImpl,pac:port=>companyPredictionPac(script,port),close(){closing=true;stop(failure("proxy_worker_closed"));}};
|
|
122
|
+
return {script,requestImpl,pac:port=>companyPredictionPac(script,port),healthy:()=>!stopped,close(){closing=true;stop(failure("proxy_worker_closed"));}};
|
|
123
123
|
}
|