codex-copilot-dx 1.4.12 → 1.4.14

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/src/dashboard.mjs CHANGED
@@ -17,6 +17,7 @@ const ASSETS = new Map([
17
17
  ["/status.js", ["./dashboard/status.js", "text/javascript; charset=utf-8"]],
18
18
  ["/activity.js", ["./dashboard/activity.js", "text/javascript; charset=utf-8"]],
19
19
  ["/flow.js", ["./dashboard/flow.js", "text/javascript; charset=utf-8"]],
20
+ ["/tool-activity-machines.js", ["./dashboard/tool-activity-machines.js", "text/javascript; charset=utf-8"]],
20
21
  ["/tool-activity.js", ["./dashboard/tool-activity.js", "text/javascript; charset=utf-8"]],
21
22
  ["/usage.js", ["./dashboard/usage.js", "text/javascript; charset=utf-8"]],
22
23
  ["/context.js", ["./dashboard/context.js", "text/javascript; charset=utf-8"]],
@@ -58,7 +58,7 @@ export function createLocalPrivacy(options = {}) {
58
58
  if (disposed) throw privacyFailure("engine_unavailable");
59
59
  loadKey();
60
60
  const start = performance.now();
61
- const deadline = new AbortController();let session, timer, textKeys, budget = options.checkTimeoutMs ?? 15000;
61
+ const deadline = new AbortController();let session, timer, textKeys, timing, budget = options.checkTimeoutMs ?? 15000;
62
62
  const arm = () => {
63
63
  clearTimeout(timer);timer = setTimeout(() => deadline.abort(privacyFailure("check_timeout", "waiting")), Math.max(1, budget - (performance.now() - start)));
64
64
  timer.unref?.();
@@ -72,7 +72,7 @@ export function createLocalPrivacy(options = {}) {
72
72
  };
73
73
  try { session = await maskPrivacyRequest(body, { protocol, client, personal: saved.personal, secret,
74
74
  find: (texts, context) => detection.find(texts, { ...context, onKey(text, key) { if (text.length >= 256) (textKeys ||= new Map()).set(text, key); } }),
75
- rules: (text, personal) => rules.find(text, personal, textKeys?.get(text)), onPlan,
75
+ rules: (text, personal) => rules.find(text, personal, textKeys?.get(text)), onPlan, onTiming: value => { timing=value; },
76
76
  signal: signal ? AbortSignal.any([signal, deadline.signal]) : deadline.signal }); }
77
77
  catch (error) {
78
78
  const failure = deadline.signal.aborted && !signal?.aborted ? privacyFailure("check_timeout", "waiting") : error;
@@ -83,7 +83,7 @@ export function createLocalPrivacy(options = {}) {
83
83
  } finally { clearTimeout(timer);textKeys?.clear(); }
84
84
  if (signal?.aborted) { session.release();throw signal.reason; }
85
85
  markRequestObservation({ privacy_count: session.count, privacy_ms: Math.round(performance.now() - start), privacy_state: "checked" });
86
- actionError = null;lastCheck = { state: "checked", at: new Date().toISOString(), elapsed_ms: Math.round(performance.now() - start), count: session.count, wait_budget_ms: budget };changes.changed();
86
+ actionError = null;lastCheck = { state: "checked", at: new Date().toISOString(), elapsed_ms: Math.round(performance.now() - start), count: session.count, wait_budget_ms: budget, ...(timing ? {timing} : {}) };changes.changed();
87
87
  if (onSession) { onSession(session);return session.body; }
88
88
  if (res && session.count) attachSession(res, session);
89
89
  return session.body;
@@ -13,7 +13,7 @@ export function isManagementRoute(method, pathname) {
13
13
 
14
14
  // Management retains its own access checks; it receives snapshots and explicit
15
15
  // actions, never an inference client or a second integration lifecycle.
16
- export function createManagementHandler({ statusSnapshot, activityEvents, nativePredictionPac, fixPrediction, requestBodyTimeoutMs } = {}) {
16
+ export function createManagementHandler({ statusSnapshot, summarySnapshot, activityEvents, nativePredictionPac, fixPrediction, requestBodyTimeoutMs } = {}) {
17
17
  const options = { nativePredictionPac, fixPrediction };
18
18
  return async (req, res, pathname) => {
19
19
  if (req.method === "GET" && pathname === ACTIVITY_EVENTS_PATH) {
@@ -32,8 +32,8 @@ export function createManagementHandler({ statusSnapshot, activityEvents, native
32
32
  return;
33
33
  }
34
34
  res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store" });
35
- const snapshot = statusSnapshot();
36
- res.end(JSON.stringify(new URL(req.url, "http://localhost").searchParams.get("scope") === "summary" ? statusSummary(snapshot) : snapshot));
35
+ const summary = new URL(req.url, "http://localhost").searchParams.get("scope") === "summary";
36
+ res.end(JSON.stringify(summary ? (summarySnapshot ? summarySnapshot() : statusSummary(statusSnapshot())) : statusSnapshot()));
37
37
  return;
38
38
  }
39
39
 
@@ -165,6 +165,14 @@ function safeClientRuntimeStatus(client) {
165
165
  };
166
166
  }
167
167
 
168
+ export function activeModels(requests, activeImages) {
169
+ const activityCounts = ["responses", "responses_compact", "messages", "search", "antigravity"].map(route => requests.by_route[route]?.active || 0);
170
+ activityCounts.push(activeImages);
171
+ const active = activityCounts.every(value => Number.isSafeInteger(value) && value >= 0)
172
+ && Number.isSafeInteger(activityCounts.reduce((sum, value) => sum + value, 0)) ? activityCounts.reduce((sum, value) => sum + value, 0) : null;
173
+ return active;
174
+ }
175
+
168
176
  export function runtimeStatusPayload({
169
177
  metrics,
170
178
  streamPerformance,
@@ -200,10 +208,7 @@ export function runtimeStatusPayload({
200
208
  }
201
209
  const history = responseHistoryStats();
202
210
  const requests = metrics?.snapshot?.() || createRequestMetrics().snapshot();
203
- const activityCounts = ["responses", "responses_compact", "messages", "search", "antigravity"].map(route => requests.by_route[route]?.active || 0);
204
- activityCounts.push(imageGeneration?.active ?? 0);
205
- const active = activityCounts.every(value => Number.isSafeInteger(value) && value >= 0)
206
- && Number.isSafeInteger(activityCounts.reduce((sum, value) => sum + value, 0)) ? activityCounts.reduce((sum, value) => sum + value, 0) : null;
211
+ const active = activeModels(requests, imageGeneration?.active ?? 0);
207
212
  return {
208
213
  ...adapterHealthPayload(),
209
214
  uptime_ms: Math.round(process.uptime() * 1000),
@@ -165,10 +165,16 @@ function cloneGemini(value) {
165
165
  if (!value || typeof value !== "object" || JSON.isRawJSON(value)) return value;
166
166
  return Array.isArray(value) ? value.map(cloneGemini) : Object.fromEntries(Object.entries(value).map(([key, item]) => [key, cloneGemini(item)]));
167
167
  }
168
- export async function maskPrivacyRequest(body, { protocol, client = "api", personal = false, secret, find, signal, onPlan, rules = ruleSpans, seedMappings }) {
169
- const copy = protocol === "gemini" ? cloneGemini(body) : structuredClone(body), { items, nested } = requestTexts(copy, protocol), texts = items.map(item => item.text);
170
- if (items.length > 8192 || texts.reduce((n, text) => n + Buffer.byteLength(text), 0) > 8 * 1024 * 1024) throw privacyFailure("request_too_large");
171
- const found = texts.length ? await find(texts, { signal, onPlan }) : [], values = new Map(seedMappings), kinds = {}, total = { count: 0, bytes: 0 };
168
+ export async function maskPrivacyRequest(body, { protocol, client = "api", personal = false, secret, find, signal, onPlan, onTiming, rules = ruleSpans, seedMappings }) {
169
+ const started=onTiming&&performance.now();
170
+ const { items } = requestTexts(body, protocol), texts = items.map(item => item.text);
171
+ let copy=body, target;
172
+ const bytes=texts.reduce((n,text)=>n+Buffer.byteLength(text),0);
173
+ if (items.length > 8192 || bytes > 8 * 1024 * 1024) throw privacyFailure("request_too_large");
174
+ const measure=onTiming&&bytes>=512*1024;
175
+ const scanEnd=measure&&performance.now();
176
+ const found=texts.length?await find(texts,{signal,onPlan}):[];
177
+ const detectionEnd=measure&&performance.now(),values=new Map(seedMappings),kinds={},total={count:0,bytes:0};
172
178
  if (!Array.isArray(found) || found.length !== texts.length) throw privacyFailure("engine_invalid");
173
179
  for (let i = 0; i < items.length; i++) {
174
180
  const item = items[i], spans = rules(item.text, personal);let bytes;
@@ -192,13 +198,22 @@ export async function maskPrivacyRequest(body, { protocol, client = "api", perso
192
198
  if (!values.has(token)) { total.bytes += Buffer.byteLength(value);if (values.size >= 8192 || total.bytes > 4 * 1024 * 1024) throw privacyFailure("mapping_limit");values.set(token, value); }
193
199
  output += item.text.slice(end, span.start) + token;end = span.end;total.count++;kinds[span.kind] = (kinds[span.kind] || 0) + 1;
194
200
  }
195
- if (end) item.parent[item.key] = output + item.text.slice(end);
201
+ if(end){
202
+ if(!target){
203
+ copy=protocol==="gemini"?cloneGemini(body):structuredClone(body);
204
+ target=requestTexts(copy,protocol);
205
+ }
206
+ const field=target.items[i];
207
+ field.parent[field.key]=output+item.text.slice(end);
208
+ }
196
209
  }
197
- if (total.count) for (const item of nested) {
210
+ if(target)for(const item of target.nested){
198
211
  const ordinary = JSON.stringify(item.value), original = item.parent[item.key];
199
212
  item.parent[item.key] = ordinary !== original && possibleLossyNumber.test(original)
200
213
  ? JSON.stringify(overlayToolStrings(parseToolArguments(original), item.value)) : ordinary;
201
214
  }
215
+ if(measure)onTiming({ scan_ms: Math.round(scanEnd-started), detection_ms: Math.round(detectionEnd-scanEnd),
216
+ merge_ms: Math.round(performance.now()-detectionEnd) });
202
217
  const restoreText = text => text.replace(tokenPattern, token => values.get(token) ?? token);
203
218
  function restoreValue(value, inToolData = false) {
204
219
  if (typeof value === "string") return restoreText(value);
@@ -210,14 +210,18 @@ export function buildHttpFailureDetails({ statusCode, route, requestId, model, c
210
210
  : origin === "privacy" ? "Local privacy processing failed. Review its error code and request timeline."
211
211
  : origin === "client_validation" ? "The request was rejected locally before an upstream call."
212
212
  : error_body === "empty" ? "Upstream returned no error details." : "HTTP request failed; original response was preserved.");
213
+ const streamError = model_error === true && origin === "upstream_event";
214
+ const safeReason = safeUpstreamReason(upstream_code, statusCode, { stream: streamError });
213
215
  const details = responseFailureDetails({ model, error: { code: typeof code === "string" && /^[a-z\d_.:-]{1,80}$/i.test(code) ? code : `http_${statusCode}`,
214
- message: model_error ? "The model source reported an error; the original HTTP response was preserved." : message } }, model_error ? "model.error" : "http.error", { headers, provider });
215
- const retryAfter = origin === "upstream_http" && [429, 503].includes(statusCode) ? upstreamRetryAfter(headers) : null;
216
+ message: streamError ? safeReason?.message || "The source reported an error while streaming."
217
+ : model_error ? "The model source reported an error; the original HTTP response was preserved." : message } }, model_error ? "model.error" : "http.error", { headers, provider });
218
+ const retryAfter = (origin === "upstream_http" && [429, 503].includes(statusCode)
219
+ || streamError && safeReason && safeUpstreamReason(safeReason.code, 429)) ? upstreamRetryAfter(headers) : null;
216
220
  return { ...details, request_id: requestId, http_status: statusCode, route,
217
221
  ...(retryAfter === null ? {} : { retry_after: retryAfter }),
218
222
  origin: origin || (route === "not_found" ? "route" : "unclassified"), local_message: true,
219
223
  ...(error_body ? { error_body } : {}), ...(error_type ? { error_type } : {}),
220
- ...(safeUpstreamReason(upstream_code, statusCode) ? { upstream_code } : {}), ...(parameter ? { parameter } : {}),
224
+ ...(safeReason ? { upstream_code: safeReason.code } : {}), ...(parameter ? { parameter } : {}),
221
225
  ...(diagnostic_message ? { diagnostic_message } : {}),
222
226
  ...(method ? { method } : {}), ...(target ? { target } : {}),
223
227
  ...(request_options ? { request_options } : {}),
@@ -27,9 +27,9 @@ const reasons = new Map([
27
27
  const MAX_ACTIVE_READS = 4;
28
28
  let activeReads = 0;
29
29
 
30
- export function safeUpstreamReason(code, status) {
30
+ export function safeUpstreamReason(code, status, { stream = false } = {}) {
31
31
  const reason = typeof code === "string" ? reasons.get(code) : null;
32
- return reason?.statuses.includes(status) ? { code, message: reason.message } : null;
32
+ return reason && (stream || reason.statuses.includes(status)) ? { code, message: reason.message } : null;
33
33
  }
34
34
 
35
35
  export function safeUpstreamParameter(value){
@@ -1,3 +1,16 @@
1
+ import {adapterHealthPayload} from "./running-adapter.mjs";
2
+ import {activeModels} from "./observability.mjs";
3
+ import {runtimeUsageSnapshot} from "./usage.mjs";
4
+
5
+ export function runtimeStatusSummary(requests, activeImages) {
6
+ return statusSummary({
7
+ ...adapterHealthPayload(),
8
+ uptime_ms: Math.round(process.uptime() * 1000),
9
+ model_activity: { active: activeModels(requests, activeImages) },
10
+ runtime_usage: runtimeUsageSnapshot(),
11
+ });
12
+ }
13
+
1
14
  // An explicit projection, never a partial replacement for the full diagnostic
2
15
  // snapshot. Old callers keep the complete status contract by default.
3
16
  export function statusSummary(snapshot) {
@@ -361,7 +361,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
361
361
  if (Number.isSafeInteger(values.source_queue_ms) && values.source_queue_ms >= 0) context.source_queue_ms = values.source_queue_ms;
362
362
  if (values.delivery_cancelled === 1) context.delivery_cancelled = 1;
363
363
  if (Number.isSafeInteger(values.cached_input_tokens) && values.cached_input_tokens >= 0) cachedInput = values.cached_input_tokens;
364
- for (const key of [...Object.keys(context), "compaction", "requested_model", "reasoning_effort_requested", "reasoning_effort_sent", "usage_state", "capability_revision", "capability_constraints", "privacy_count", "privacy_ms", "privacy_state", "privacy_pending_bytes", "privacy_new_bytes", "privacy_pending_windows", "privacy_wait_budget_ms", "privacy_error", "privacy_event_type", "privacy_channel_type", "privacy_buffered_bytes", "privacy_terminal_seen", "client_tool_errors_received"]) {
364
+ for (const key of [...Object.keys(context), "compaction", "requested_model", "routing_reason", "reasoning_effort_requested", "reasoning_effort_sent", "usage_state", "capability_revision", "capability_constraints", "privacy_count", "privacy_ms", "privacy_state", "privacy_pending_bytes", "privacy_new_bytes", "privacy_pending_windows", "privacy_wait_budget_ms", "privacy_error", "privacy_event_type", "privacy_channel_type", "privacy_buffered_bytes", "privacy_terminal_seen", "client_tool_errors_received"]) {
365
365
  const value = values[key];
366
366
  if (["reasoning_effort_requested", "reasoning_effort_sent"].includes(key)) { if (["none", "minimal", "low", "medium", "high", "xhigh", "max"].includes(value)) context[key] = value;continue; }
367
367
  if (key === "requested_model") { if (typeof value === "string" && /^[\w][\w./:@+-]{0,159}$/.test(value) && redactDiagnosticText(value) === value) context[key] = value;continue; }
@@ -8,7 +8,10 @@ export function terminalRequestState(row) {
8
8
  if (row.terminal_outcome) return "Finishing";
9
9
  if (row.first_output_ms != null) return "Responding";
10
10
  if (row.phase === "admission") return "Queued";
11
- if (row.upstream_attempts > 1) return "Retrying";
11
+ const attempt = row.attempts?.at(-1);
12
+ if (attempt?.headers_ms != null || ["upstream_response", "upstream_stream"].includes(row.phase)) return "Reading response";
13
+ if (attempt?.body_sent_ms != null) return "Waiting for response headers";
14
+ if (attempt?.body_written_bytes != null) return "Sending request";
12
15
  return row.upstream_attempts ? "Waiting upstream" : "Processing input";
13
16
  }
14
17
  const labels = { configured: "Configured", paused: "Paused", disabled: "Disabled", not_configured: "Not configured", not_installed: "Not installed",
@@ -72,7 +75,10 @@ export function retainedRequests(data = {}) {
72
75
  }
73
76
  for (const record of data.http_errors?.recent || data.http_errors?.actionable_recent || []) if (record.request_id) {
74
77
  const existing = rows.get(record.request_id);
75
- rows.set(record.request_id, { ...existing, ...record, error: true, active: existing?.active === true, state: ["cancelled", "incomplete"].includes(existing?.state) ? existing.state : "failed" });
78
+ const capability = record.route === "messages_count_tokens" || ["ccdx_model_not_selected", "ccdx_client_source_disabled"].includes(record.reason);
79
+ rows.set(record.request_id, { ...existing, ...record, error: true, active: existing?.active === true,
80
+ ...(capability ? { failure_category: "capability" } : {}),
81
+ state: capability ? "capability" : ["cancelled", "incomplete"].includes(existing?.state) ? existing.state : "failed" });
76
82
  }
77
83
  const time = row => { const value = Date.parse(row.at || row.time || "");return Number.isFinite(value) ? value : 0; };
78
84
  return [...rows.values()].sort((a, b) => Number(a.active) - Number(b.active) || time(a) - time(b));