codex-copilot-dx 1.3.28 → 1.4.1
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 +4 -1
- package/docs/ARCHITECTURE.md +23 -1
- package/docs/REFERENCE.md +34 -3
- package/package.json +1 -1
- package/src/adapter.mjs +13 -3
- package/src/antigravity-handler.mjs +44 -15
- package/src/antigravity-runtime.mjs +22 -2
- package/src/claude-capability-config.mjs +3 -2
- package/src/claude-client-config.mjs +2 -2
- package/src/claude-gateway.mjs +22 -4
- package/src/cli-command-spec.mjs +9 -4
- package/src/cli-management.mjs +28 -0
- package/src/cli-options.mjs +1 -1
- package/src/connection-routing.mjs +1 -0
- package/src/connection-runtime.mjs +11 -0
- package/src/context-compaction-plan.mjs +122 -0
- package/src/context-compaction-seal.mjs +56 -0
- package/src/context-compaction-wire.mjs +137 -0
- package/src/context-compaction.mjs +161 -0
- package/src/context-metrics.mjs +3 -2
- package/src/conversation-source-guard.mjs +15 -5
- package/src/dashboard/console.js +1 -1
- package/src/dashboard/index.html +14 -1
- package/src/dashboard/language.js +33 -0
- package/src/dashboard/preferences.js +1 -1
- package/src/dashboard/status.js +2 -2
- package/src/dashboard/tool-activity.js +153 -0
- package/src/dashboard/ui.css +26 -0
- package/src/dashboard/ui.js +2 -2
- package/src/dashboard.mjs +1 -0
- package/src/http-transport.mjs +1 -1
- package/src/local-privacy.mjs +15 -7
- package/src/lock.mjs +9 -2
- package/src/privacy-detection.mjs +4 -3
- package/src/privacy-transform.mjs +20 -6
- package/src/provider-runtime.mjs +8 -5
- package/src/providers/api.mjs +15 -4
- package/src/request-context.mjs +1 -1
- package/src/responses-bridge.mjs +14 -5
- package/src/responses-handler.mjs +81 -1
- package/src/responses-proxy.mjs +22 -5
- package/src/responses-request.mjs +11 -4
- package/src/safe-upstream-error.mjs +29 -11
- package/src/service-control.mjs +8 -1
- package/src/settings-preferences.mjs +3 -3
- package/src/stream-performance.mjs +19 -2
- package/src/tool-activity.mjs +135 -0
- package/src/upstream-body.mjs +1 -1
- package/src/upstream-error-capture.mjs +29 -0
- package/src/user-settings.mjs +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { planContextCompaction, compactionItems, compactionMessage, replaceCompactionItems } from "./context-compaction-plan.mjs";
|
|
3
|
+
import { CCDX_COMPACTION_PREFIX, CCDX_NATIVE_COMPACTION_PREFIX, sealContextCompaction, openContextCompaction, sealNativeCompaction, openNativeCompaction } from "./context-compaction-seal.mjs";
|
|
4
|
+
import { readSafeUpstreamReason } from "./safe-upstream-error.mjs";
|
|
5
|
+
import { currentRequestContext, runWithRequestContext } from "./request-context.mjs";
|
|
6
|
+
import { recordUsage } from "./usage-store.mjs";
|
|
7
|
+
import { boundedDiagnosticText } from "./diagnostic-text.mjs";
|
|
8
|
+
|
|
9
|
+
export const COMPACTION_USAGE_RECORDED = Symbol("ccdx-compaction-usage-recorded");
|
|
10
|
+
export const compactionScope = (provider, client, protocol) => JSON.stringify([client, provider.id, provider.profileId?.(protocol) || provider.id]);
|
|
11
|
+
const MAX_ACTIVE = 2, MAX_SUPPORT = 128, RECOVERY_MS = 5 * 60 * 1000;
|
|
12
|
+
const fail = (code, message, statusCode = 422) => Object.assign(new Error(message), { code, statusCode });
|
|
13
|
+
const cancel = response => { try { void response?.body?.cancel().catch(() => {}); } catch {} };
|
|
14
|
+
const inputFailure = reason => ["input_length_invalid", "context_length_exceeded", "context_window_exceeded"].includes(reason?.code);
|
|
15
|
+
|
|
16
|
+
export function isCompactionRequest(protocol, body, headers = {}) {
|
|
17
|
+
return protocol === "messages" ? headers["x-claude-code-request-class"] === "compaction"
|
|
18
|
+
: protocol === "gemini" && ["summarization", "checkpoint"].includes(body?.requestType);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function resolveGatewayCompactionItem(item, { key, scope, onMappings = () => {} } = {}) {
|
|
22
|
+
if (item?.type !== "compaction" || typeof item.encrypted_content !== "string") return item;
|
|
23
|
+
const value = item.encrypted_content;
|
|
24
|
+
if (value.startsWith(CCDX_COMPACTION_PREFIX)) return compactionMessage("responses", openContextCompaction(value, { key: typeof key === "function" ? key() : key, scope }));
|
|
25
|
+
if (value.startsWith(CCDX_NATIVE_COMPACTION_PREFIX)) {
|
|
26
|
+
const restored = openNativeCompaction(value, { key: typeof key === "function" ? key() : key, scope });onMappings(restored.mappings);
|
|
27
|
+
return { ...item, encrypted_content: restored.encrypted_content };
|
|
28
|
+
}
|
|
29
|
+
return item;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function expandGatewayCompaction(body, options) {
|
|
33
|
+
let changed = false;
|
|
34
|
+
const input = body.input?.map(item => { const next = resolveGatewayCompactionItem(item, options);changed ||= item !== next;return next; });
|
|
35
|
+
return changed ? { ...body, input } : body;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function protectNativeCompactionResult(response, { key, scope, mappings } = {}) {
|
|
39
|
+
const index = response.output?.findIndex(item => item?.type === "compaction" && typeof item.encrypted_content === "string"
|
|
40
|
+
&& item.encrypted_content.length > 0
|
|
41
|
+
&& !item.encrypted_content.startsWith(CCDX_COMPACTION_PREFIX) && !item.encrypted_content.startsWith(CCDX_NATIVE_COMPACTION_PREFIX));
|
|
42
|
+
if (index === undefined || index < 0) return response;
|
|
43
|
+
const entries = typeof mappings === "function" ? mappings() : mappings;if (!entries?.length) return response;
|
|
44
|
+
return { ...response, output: response.output.map((item, position) => position === index ? { ...item,
|
|
45
|
+
encrypted_content: sealNativeCompaction(item.encrypted_content, entries, { key: typeof key === "function" ? key() : key, scope }) } : item) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createContextCompactionService({ enabled = () => true, now = Date.now, recordUsageFn = recordUsage } = {}) {
|
|
49
|
+
const support = new Map(), stats = { native: 0, gateway: 0, failed: 0, active: 0, summary_calls: 0 };let last = null;
|
|
50
|
+
const remember = (scope, value) => {
|
|
51
|
+
support.delete(scope);support.set(scope, value);while (support.size > MAX_SUPPORT) support.delete(support.keys().next().value);
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
snapshot() { return { enabled: enabled() === true, native_attempts: stats.native, gateway_attempts: stats.gateway, failed_operations: stats.failed,
|
|
55
|
+
active_recoveries: stats.active, summary_calls: stats.summary_calls, last: last ? { ...last } : null, sources: [...support.values()].map(value => ({ ...value })) }; },
|
|
56
|
+
async run({ body, protocol, scope, source, model = body.model, client, key, native, summarize, options = {}, inputLimit,
|
|
57
|
+
outputAllowance = 0, restoreText = value => value, onActivity = () => {}, nativeCompaction, nativeKind = "compact" } = {}) {
|
|
58
|
+
const started = now(), owner = createHash("sha256").update(JSON.stringify([scope, model, protocol, nativeKind])).digest("hex"), cached = support.get(owner);
|
|
59
|
+
const modelLabel = boundedDiagnosticText(model, { maxChars: 160, overflow: "unknown" });
|
|
60
|
+
const allowFallback = enabled() === true;
|
|
61
|
+
let nativeResponse, deferredError, calls = 0, usage = {}, failedUsage = false, missingCached = false, recovering = false;
|
|
62
|
+
const deferredOptions = { ...options, onUpstreamErrorHeaders(status) { deferredError = status; } };
|
|
63
|
+
const forwardError = () => { if (deferredError !== undefined) try { options.onUpstreamErrorHeaders?.(deferredError); } catch {} };
|
|
64
|
+
try {
|
|
65
|
+
const skipNative = protocol === "responses" && allowFallback && (nativeCompaction === false || !native || cached?.native === "unavailable" && now() >= cached.at && now() - cached.at < 60000);
|
|
66
|
+
if (!skipNative) {
|
|
67
|
+
if (!native) throw fail("ccdx_compaction_native_unavailable", "This connection has no native compression operation.");
|
|
68
|
+
stats.native++;nativeResponse = await native(body, allowFallback ? deferredOptions : options);
|
|
69
|
+
if (nativeResponse.ok) { remember(owner, { source, model: modelLabel, protocol, native: "http_accepted", at: now() });return nativeResponse; }
|
|
70
|
+
}
|
|
71
|
+
if (!allowFallback) { forwardError();return nativeResponse; }
|
|
72
|
+
let unsupported = protocol === "responses" && (skipNative || [404, 405, 501].includes(nativeResponse.status));
|
|
73
|
+
const reason = !unsupported && [400, 413, 422].includes(nativeResponse?.status) ? await readSafeUpstreamReason(nativeResponse.clone(), { signal: options.signal }) : null;
|
|
74
|
+
unsupported ||= protocol === "responses" && reason?.code === "compaction_unavailable";
|
|
75
|
+
if (!unsupported && !inputFailure(reason)) { stats.failed++;forwardError();return nativeResponse; }
|
|
76
|
+
if (unsupported) remember(owner, { source, model: modelLabel, protocol, native: "unavailable", at: now() });
|
|
77
|
+
if (stats.active >= MAX_ACTIVE) throw fail("ccdx_compaction_busy", "Compression is busy; the original conversation was kept.", 429);
|
|
78
|
+
const limits = [inputLimit, reason?.maximum].filter(value => Number.isSafeInteger(value) && value > 0);
|
|
79
|
+
const knownLimit = limits.length ? Math.min(...limits) : undefined;
|
|
80
|
+
if (inputFailure(reason) && reason.maximum) remember(owner, { source, model: modelLabel, protocol, native: "input_limited", input_limit: reason.maximum, at: now() });
|
|
81
|
+
const plan = planContextCompaction(body, { protocol, inputLimit: knownLimit, outputAllowance });
|
|
82
|
+
const sealKey = protocol === "responses" ? typeof key === "function" ? key() : key : null;
|
|
83
|
+
if (protocol === "responses" && (typeof sealKey !== "string" || sealKey.length < 32)) throw fail("ccdx_compaction_key_unavailable", "A saved local client identity is required for resumable compression.");
|
|
84
|
+
cancel(nativeResponse);stats.active++;stats.gateway++;recovering = true;
|
|
85
|
+
const controller = new AbortController(), timer = setTimeout(() => controller.abort(fail("ccdx_compaction_timeout", "Compression exceeded its bounded recovery time; the original conversation was kept.")), RECOVERY_MS);
|
|
86
|
+
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
87
|
+
const parent = currentRequestContext();
|
|
88
|
+
const summary = async text => {
|
|
89
|
+
signal.throwIfAborted();calls++;stats.summary_calls++;
|
|
90
|
+
const requestId = randomUUID(), context = { ...parent, requestId, purpose: "compaction", provider: source };
|
|
91
|
+
return runWithRequestContext(context, async () => {
|
|
92
|
+
let counts;
|
|
93
|
+
try {
|
|
94
|
+
const result = await summarize(text, { ...deferredOptions, signal, requestId, onActivity, onUsage: value => { counts = value; } });
|
|
95
|
+
counts = result?.usage || counts || {};signal.throwIfAborted();
|
|
96
|
+
if (!result?.text?.trim() || Buffer.byteLength(result.text) > 512 * 1024) throw fail("ccdx_compaction_result_invalid", "The source returned no usable compression summary.");
|
|
97
|
+
failedUsage ||= !Number.isSafeInteger(counts.input_tokens) || !Number.isSafeInteger(counts.output_tokens);
|
|
98
|
+
for (const field of ["input_tokens", "output_tokens"]) if (Number.isSafeInteger(counts[field]) && counts[field] >= 0) usage[field] = (usage[field] || 0) + counts[field];
|
|
99
|
+
const cachedTokens = counts.input_tokens_details?.cached_tokens;missingCached ||= !Number.isSafeInteger(cachedTokens);
|
|
100
|
+
if (Number.isSafeInteger(cachedTokens) && cachedTokens >= 0) usage.cached_input_tokens = (usage.cached_input_tokens || 0) + cachedTokens;
|
|
101
|
+
return result.text;
|
|
102
|
+
} finally {
|
|
103
|
+
if (counts) {
|
|
104
|
+
const cachedTokens = counts.input_tokens_details?.cached_tokens;
|
|
105
|
+
const record = { ts: new Date(now()).toISOString(), surface: "context_compaction", mode: "internal", provider: source, model,
|
|
106
|
+
client, request_id: requestId, ...(parent?.requestId ? { parent_request_id: parent.requestId } : {}), purpose: "compaction", usage: {
|
|
107
|
+
...(counts.input_tokens === undefined ? {} : { input_tokens: counts.input_tokens }), ...(counts.output_tokens === undefined ? {} : { output_tokens: counts.output_tokens }),
|
|
108
|
+
...(cachedTokens === undefined ? {} : { cached_input_tokens: cachedTokens }),
|
|
109
|
+
...(counts.output_tokens_details?.reasoning_tokens === undefined ? {} : { reasoning_output_tokens: counts.output_tokens_details.reasoning_tokens }),
|
|
110
|
+
} };
|
|
111
|
+
try { void Promise.resolve(recordUsageFn(record)).catch(() => {}); } catch {}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
try {
|
|
117
|
+
const summaries = [];
|
|
118
|
+
for (const [index, chunk] of plan.chunks.entries()) summaries.push(await summary(`Historical records, segment ${index + 1} of ${plan.chunks.length}:\n${chunk}`));
|
|
119
|
+
let text = summaries[0];
|
|
120
|
+
if (summaries.length > 1) text = await summary("Combine these continuation summaries. Preserve all distinct facts, constraints, failures and unresolved work:\n" + summaries.map((value, index) => `[Segment ${index + 1}]\n${value}`).join("\n\n"));
|
|
121
|
+
signal.throwIfAborted();let result;
|
|
122
|
+
if (protocol === "responses") {
|
|
123
|
+
const encrypted_content = sealContextCompaction(restoreText(text), { key: sealKey, scope }), rewritten = plan.rewriteItem({ type: "compaction", id: "cmp_ccdx_" + randomUUID(), encrypted_content });
|
|
124
|
+
const returnedUsage = failedUsage ? undefined : { input_tokens: usage.input_tokens, output_tokens: usage.output_tokens, total_tokens: usage.input_tokens + usage.output_tokens,
|
|
125
|
+
...(missingCached ? {} : { input_tokens_details: { cached_tokens: usage.cached_input_tokens } }) };
|
|
126
|
+
const output = compactionItems(rewritten, protocol).map(item => item && (item.type === "message" || item.type === undefined && item.role)
|
|
127
|
+
? { ...item, type: "message", content: typeof item.content === "string" ? [{ type: item.role === "assistant" ? "output_text" : "input_text", text: item.content }] : item.content } : item);
|
|
128
|
+
const response = { id: "resp_ccdx_" + randomUUID(), object: body.stream === true ? "response" : "response.compaction", status: "completed", created_at: Math.floor(now() / 1000), model,
|
|
129
|
+
output, ...(returnedUsage ? { usage: returnedUsage } : {}) };
|
|
130
|
+
if (body.stream === true) {
|
|
131
|
+
const events = [{ type: "response.created", response: { ...response, status: "in_progress", output: [] } }];
|
|
132
|
+
for (const [output_index, item] of output.entries()) events.push({ type: "response.output_item.added", output_index, item }, { type: "response.output_item.done", output_index, item });
|
|
133
|
+
events.push({ type: "response.completed", response });
|
|
134
|
+
const encoded = events.map((event, sequence_number) => "event: " + event.type + "\ndata: " + JSON.stringify({ ...event, sequence_number }) + "\n\n");
|
|
135
|
+
if (encoded.some(frame => Buffer.byteLength(frame) > 8 * 1024 * 1024)) throw fail("ccdx_compaction_output_limit", "The preserved compression window exceeds the stream budget; the original conversation was kept.");
|
|
136
|
+
result = new Response(encoded.join(""), { headers: { "content-type": "text/event-stream" } });
|
|
137
|
+
} else result = Response.json(response);
|
|
138
|
+
Object.defineProperty(result, COMPACTION_USAGE_RECORDED, { value: true });
|
|
139
|
+
} else {
|
|
140
|
+
signal.throwIfAborted();result = await native(plan.rewrite(text), { ...deferredOptions, signal });
|
|
141
|
+
if (!result.ok) {
|
|
142
|
+
if ([400, 413, 422].includes(result.status) && inputFailure(await readSafeUpstreamReason(result.clone(), { signal }))) {
|
|
143
|
+
cancel(result);throw fail("ccdx_compaction_still_rejected", "The source still rejected the compressed request. The original conversation was kept.");
|
|
144
|
+
}
|
|
145
|
+
stats.failed++;forwardError();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
last = { source, model: modelLabel, protocol, client, result: result.ok ? protocol === "responses" ? "completed" : "response_started" : "source_rejected", summary_calls: calls,
|
|
149
|
+
compressed_items: plan.selected_items, preserved_items: plan.preserved_items, historical_bytes: plan.bytes, elapsed_ms: now() - started, usage_state: failedUsage || missingCached ? "partial" : "reported" };
|
|
150
|
+
return result;
|
|
151
|
+
} finally { clearTimeout(timer);stats.active--; }
|
|
152
|
+
} catch (error) {
|
|
153
|
+
stats.failed++;cancel(nativeResponse);forwardError();last = { source, model: modelLabel, protocol, client, result: options.signal?.aborted ? "cancelled" : "failed", summary_calls: calls, elapsed_ms: now() - started,
|
|
154
|
+
error: /^ccdx_compaction_[a-z_]+$/.test(error.code || "") ? error.code : "ccdx_compaction_failed" };
|
|
155
|
+
if (options.signal?.aborted) throw options.signal.reason;
|
|
156
|
+
if (!recovering) throw error;
|
|
157
|
+
throw typeof error.code === "string" && error.code.startsWith("ccdx_compaction_") ? error : fail("ccdx_compaction_failed", "Compression could not complete; the original conversation was kept.");
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
package/src/context-metrics.mjs
CHANGED
|
@@ -14,7 +14,7 @@ export function observeContextSession(body, headers = {}, provider, protocol = "
|
|
|
14
14
|
try { session = JSON.parse(body.metadata.user_id)?.session_id; }
|
|
15
15
|
catch { session = /(?:^|_)session_([\w-]{8,128})$/.exec(body.metadata.user_id)?.[1]; }
|
|
16
16
|
}
|
|
17
|
-
if (!bounded(session)) return;
|
|
17
|
+
if (!bounded(session)) { tracker.observeToolInput?.(body, protocol);return; }
|
|
18
18
|
try {
|
|
19
19
|
const profile = provider?.profileId?.(protocol);
|
|
20
20
|
if (!bounded(profile)) return;
|
|
@@ -22,6 +22,7 @@ export function observeContextSession(body, headers = {}, provider, protocol = "
|
|
|
22
22
|
const key = createHmac("sha256", salt).update(`${profile}\0${session}\0${bounded(agent) ? agent : ""}`).digest("hex");
|
|
23
23
|
tracker.observeSession(key);
|
|
24
24
|
} catch { /* Optional metadata cannot change request admission or routing. */ }
|
|
25
|
+
tracker.observeToolInput?.(body, protocol);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export function createContextMetrics() {
|
|
@@ -34,7 +35,7 @@ export function createContextMetrics() {
|
|
|
34
35
|
context_window_tokens: count(context.context_window_tokens) || null,
|
|
35
36
|
cached_input_tokens: input !== null && cached !== null && cached <= input ? cached : null,
|
|
36
37
|
elapsed_ms: Math.max(0, finished - started), finished };
|
|
37
|
-
const compact = route === "responses_compact";
|
|
38
|
+
const compact = route === "responses_compact" || context.compaction === 1;
|
|
38
39
|
if (!session) {
|
|
39
40
|
unassigned.push({ id: `request-${++sequence}`, application, provider, model, ...point, compact });
|
|
40
41
|
if (unassigned.length > 20) unassigned.shift();
|
|
@@ -9,7 +9,14 @@ import { withFileLock } from "./lock.mjs";
|
|
|
9
9
|
// Correlation only: retain hashes, never prompts, session IDs or credentials.
|
|
10
10
|
export function createConversationSourceGuard(options = {}) {
|
|
11
11
|
const file = path.join(path.dirname(accessSettingsPath(options)), "conversation-sources.json");let cache;
|
|
12
|
-
|
|
12
|
+
const loadOwners = async () => {
|
|
13
|
+
let owners = {};
|
|
14
|
+
try { owners = JSON.parse(await readBoundedFile(file, { encoding: "utf8", maxBytes: 256 * 1024 })); } catch (error) { if (error.code !== "ENOENT") throw accessError("ccdx_conversation_state_invalid", 409); }
|
|
15
|
+
if (!owners || typeof owners !== "object" || Array.isArray(owners) || Object.keys(owners).length > 1024
|
|
16
|
+
|| Object.entries(owners).some(([key, owner]) => !/^[a-f0-9]{64}$/.test(key) || !/^[a-f0-9]{64}$/.test(owner))) throw accessError("ccdx_conversation_state_invalid", 409);
|
|
17
|
+
return owners;
|
|
18
|
+
};
|
|
19
|
+
const guard = (client, profile, body, headers = {}, salt, transfer, signal) => {
|
|
13
20
|
signal?.throwIfAborted();
|
|
14
21
|
const hash = value => createHmac("sha256", salt).update(value).digest("hex");
|
|
15
22
|
const items = Array.isArray(body.messages) ? body.messages : Array.isArray(body.input) ? body.input : [];
|
|
@@ -39,10 +46,7 @@ export function createConversationSourceGuard(options = {}) {
|
|
|
39
46
|
}
|
|
40
47
|
await fs.mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
41
48
|
try { return await withFileLock(`${file}.lock`, async () => {
|
|
42
|
-
|
|
43
|
-
try { owners = JSON.parse(await readBoundedFile(file, { encoding: "utf8", maxBytes: 256 * 1024 })); } catch (error) { if (error.code !== "ENOENT") throw accessError("ccdx_conversation_state_invalid", 409); }
|
|
44
|
-
if (!owners || typeof owners !== "object" || Array.isArray(owners) || Object.keys(owners).length > 1024
|
|
45
|
-
|| Object.entries(owners).some(([key, owner]) => !/^[a-f0-9]{64}$/.test(key) || !/^[a-f0-9]{64}$/.test(owner))) throw accessError("ccdx_conversation_state_invalid", 409);
|
|
49
|
+
const owners = await loadOwners();
|
|
46
50
|
prepared = await prepare(owners[key]);
|
|
47
51
|
if (prepared?.handled) { cache = owners;return prepared; }
|
|
48
52
|
if (owners[key] && owners[key] !== owner && (identified || hasHistory)) throw accessError("ccdx_conversation_source_changed", 409);
|
|
@@ -55,4 +59,10 @@ export function createConversationSourceGuard(options = {}) {
|
|
|
55
59
|
}, { timeoutMs: 1000, staleMs: 60_000, pollMs: 10, signal }); } catch (error) { prepared?.release();throw error; }
|
|
56
60
|
})();
|
|
57
61
|
};
|
|
62
|
+
guard.owner = async (client, session, salt) => {
|
|
63
|
+
if (typeof session !== "string" || !session || session.length > 512 || /[\u0000-\u001f\u007f]/.test(session)) return null;
|
|
64
|
+
const key = createHmac("sha256", salt).update(client + "\0session\0" + session).digest("hex");
|
|
65
|
+
if (cache?.[key]) return cache[key];cache = await loadOwners();return cache[key] || null;
|
|
66
|
+
};
|
|
67
|
+
return guard;
|
|
58
68
|
}
|
package/src/dashboard/console.js
CHANGED
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
if (snapshot) render(snapshot);
|
|
60
60
|
void refreshStatus();
|
|
61
61
|
globalThis.ccdxDashboardActivity?.visibilityChanged();
|
|
62
|
-
globalThis.ccdxDashboardFlow?.visibilityChanged();
|
|
62
|
+
globalThis.ccdxDashboardFlow?.visibilityChanged();globalThis.ccdxToolActivity?.visibilityChanged();
|
|
63
63
|
for (const item of document.querySelectorAll("[data-route]")) {
|
|
64
64
|
if (item.dataset.route === next) item.setAttribute("aria-current", "page");else item.removeAttribute("aria-current");
|
|
65
65
|
}
|
package/src/dashboard/index.html
CHANGED
|
@@ -321,7 +321,7 @@
|
|
|
321
321
|
<div class="section-actions usage-source-controls"><label><span data-i18n="source_entire_page">Source / entire page</span><select id="usage-provider"><option value="" data-i18n="all_providers">All providers</option></select></label>
|
|
322
322
|
<label><span data-i18n="usage_model_page">Model / entire page</span><select id="analytics-model"><option value="" data-i18n="all_models">All models</option></select></label>
|
|
323
323
|
<label><span data-i18n="usage_range_page">Time / entire page</span><select id="analytics-range"><option value="all" selected data-i18n="usage_all_history">All retained history</option><option value="7" data-i18n="7_days">Last 7 days</option><option value="30" data-i18n="30_days">Last 30 days</option><option value="90" data-i18n="90_days">Last 90 days</option><option value="365" data-i18n="usage_365_days">Last 365 days</option></select></label>
|
|
324
|
-
<label><span data-i18n="request_kind">Request purpose</span><select id="usage-purpose"><option value="" data-i18n="purpose_all">All purposes</option><option value="conversation" data-i18n="purpose_conversation">Conversation</option><option value="diagnostic" data-i18n="purpose_diagnostic">Diagnostic</option><option value="compatibility" data-i18n="purpose_compatibility">Compatibility test</option><option value="unknown" data-i18n="purpose_unknown">Unknown</option></select></label>
|
|
324
|
+
<label><span data-i18n="request_kind">Request purpose</span><select id="usage-purpose"><option value="" data-i18n="purpose_all">All purposes</option><option value="conversation" data-i18n="purpose_conversation">Conversation</option><option value="compaction" data-i18n="purpose_compaction">Compression</option><option value="diagnostic" data-i18n="purpose_diagnostic">Diagnostic</option><option value="compatibility" data-i18n="purpose_compatibility">Compatibility test</option><option value="unknown" data-i18n="purpose_unknown">Unknown</option></select></label>
|
|
325
325
|
<button id="refresh-usage" type="button" data-i18n="refresh_usage">Refresh usage</button></div>
|
|
326
326
|
|
|
327
327
|
<details id="usage-analytics" class="panel dashboard-section analytics-section">
|
|
@@ -369,6 +369,13 @@
|
|
|
369
369
|
<div class="flow-caption"><span id="flow-caption" data-i18n="flow_status_unknown">Status unavailable</span><button id="flow-clear" type="button" data-i18n="flow_show_all" hidden>Show all</button><button id="flow-more" type="button" hidden>More models</button></div>
|
|
370
370
|
<details id="flow-active" class="tool-details"><summary id="flow-active-title" data-i18n="flow_active_requests">Active requests</summary><div class="table-wrap"><table><thead><tr><th data-i18n="client">App</th><th data-i18n="source">Source</th><th data-i18n="model">Model</th><th data-i18n="state">State</th><th data-i18n="flow_elapsed">Elapsed</th><th data-i18n="attempts">Attempts</th></tr></thead><tbody id="flow-active-body"></tbody></table></div></details>
|
|
371
371
|
</section>
|
|
372
|
+
<section id="tool-activity" class="panel dashboard-section" aria-labelledby="tool-title" data-paused="true">
|
|
373
|
+
<div class="panel-heading"><h2 id="tool-title" data-i18n="tool_heading">TOOL CALLS</h2><label class="tool-style" for="tool-style"><span data-i18n="tool_style">Style</span><select id="tool-style"><option value="grid" data-i18n="tool_style_grid">Grid</option><option value="halo" data-i18n="tool_style_halo">Beam ring</option><option value="orbit" data-i18n="tool_style_orbit">Orbit rings</option><option value="weave" data-i18n="tool_style_weave">Woven field</option><option value="off" data-i18n="tool_style_off">Off</option></select></label></div>
|
|
374
|
+
<div id="tool-stage" class="tool-stage" data-style="grid">
|
|
375
|
+
<div class="tool-visual"><div class="tool-orbit"><canvas id="tool-canvas" role="img" data-i18n-label="tool_heading" aria-label="Tool calls"></canvas></div><p class="tool-narration"><span id="tool-state" role="status" aria-live="polite" data-i18n="flow_status_unknown">Waiting for a fresh status</span><span id="tool-cursor" aria-hidden="true" hidden> ···</span></p></div>
|
|
376
|
+
<div class="tool-content"><p id="tool-context" class="tool-context" hidden></p><div id="tool-list"></div><p id="tool-more" class="hint" hidden></p><details id="tool-details" class="tool-details tool-technical" hidden><summary data-i18n="tool_details">Call details</summary><div id="tool-technical"></div></details></div>
|
|
377
|
+
</div>
|
|
378
|
+
</section>
|
|
372
379
|
<details class="panel dashboard-section" id="source-requests" open>
|
|
373
380
|
<summary data-i18n="requests_by_source">REQUESTS BY SOURCE</summary>
|
|
374
381
|
<p class="hint" data-i18n="results_since_startup_partial_usage_is_marked_separately">Results since startup. Partial usage is marked separately.</p>
|
|
@@ -446,6 +453,12 @@
|
|
|
446
453
|
<p id="settings-note" class="hint" role="status" data-i18n="reading_settings">Reading settings…</p>
|
|
447
454
|
</section>
|
|
448
455
|
|
|
456
|
+
<section class="panel dashboard-section" aria-labelledby="context-compaction-heading">
|
|
457
|
+
<h2 id="context-compaction-heading" data-i18n="context_compaction_heading">CONTEXT COMPRESSION</h2>
|
|
458
|
+
<div class="setting-row"><label for="setting-context_compaction_enabled" data-i18n="context_compaction_enabled">Recover failed compression automatically</label><input id="setting-context_compaction_enabled" type="checkbox" role="switch" aria-describedby="context-compaction-note" disabled></div>
|
|
459
|
+
<p id="context-compaction-note" class="hint" data-i18n="context_compaction_note">Use the current source and model when native compression is unavailable or the input is too long. Uses quota.</p>
|
|
460
|
+
</section>
|
|
461
|
+
|
|
449
462
|
<section class="panel dashboard-section" id="version-updates" aria-labelledby="version-updates-title">
|
|
450
463
|
<div class="version-heading"><h2 id="version-updates-title" data-i18n="version_updates">VERSION & UPDATES</h2><button id="check-updates" type="button" data-i18n="check_updates">Check for updates</button></div>
|
|
451
464
|
<dl class="version-list"><div><dt data-i18n="current_version">Current version</dt><dd id="update-current-version">—</dd><dd id="update-current-date" class="hint">—</dd></div><div id="update-latest-row" hidden><dt data-i18n="available_update">Update available</dt><dd id="update-latest-version">—</dd><dd id="update-latest-date" class="hint">—</dd></div></dl>
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const translations = {
|
|
3
|
+
"tool_heading": ["Tool calls","工具调用"],
|
|
4
|
+
"tool_style": ["Style","样式"],
|
|
5
|
+
"tool_style_grid": ["Grid","格子进度条"],
|
|
6
|
+
"tool_style_halo": ["Beam ring","光束圆环"],
|
|
7
|
+
"tool_style_orbit": ["Orbit rings","轨道圆环"],
|
|
8
|
+
"tool_style_weave": ["Woven field","编织光场"],
|
|
9
|
+
"tool_style_off": ["Off","关闭"],
|
|
10
|
+
"tool_preparing": ["Preparing a tool call","正在准备调用"],
|
|
11
|
+
"tool_preparing_many": ["Preparing {count} calls","并行准备 {count} 项调用"],
|
|
12
|
+
"tool_waiting": ["Waiting for tool results","等待工具返回"],
|
|
13
|
+
"tool_returned": ["Tool results received","工具结果已返回"],
|
|
14
|
+
"tool_failed": ["A tool call failed","调用失败"],
|
|
15
|
+
"tool_cancelled": ["Request cancelled","请求已取消"],
|
|
16
|
+
"tool_idle": ["Waiting for the next call","等待下一次调用"],
|
|
17
|
+
"tool_groups": ["{count} app and model groups","{count} 个应用及模型分组"],
|
|
18
|
+
"tool_more": ["{count} more observations in call details","另有 {count} 项观测,见调用详情"],
|
|
19
|
+
"tool_details": ["Call details","调用详情"],
|
|
20
|
+
"tool_action_read": ["Read file","读取文件"],
|
|
21
|
+
"tool_action_search": ["Search files","搜索文件"],
|
|
22
|
+
"tool_action_command": ["Run command","运行命令"],
|
|
23
|
+
"tool_action_edit": ["Edit file","修改文件"],
|
|
24
|
+
"tool_action_web": ["Search web","检索网页"],
|
|
25
|
+
"tool_action_generic": ["Tool call","工具调用"],
|
|
26
|
+
"tool_row_preparing": ["Preparing","准备中"],
|
|
27
|
+
"tool_row_waiting": ["Waiting for result","等待返回"],
|
|
28
|
+
"tool_row_returned": ["Returned","已返回"],
|
|
29
|
+
"tool_row_failed": ["Failed","失败"],
|
|
30
|
+
"tool_row_cancelled": ["Cancelled","已取消"],
|
|
31
|
+
"tool_row_unknown": ["Waiting for a fresh status","状态待更新"],
|
|
3
32
|
gemini_access_title: ["Copilot access", "Copilot 接入"],
|
|
4
33
|
gemini_model_selection: ["Model selection", "模型选择"],
|
|
5
34
|
gemini_route_waiting: ["No Antigravity request observed yet", "尚未观察到 Antigravity 请求"],
|
|
@@ -372,6 +401,10 @@
|
|
|
372
401
|
"cap_field_supported_parameters": ["Supported parameters", "支持的参数"],
|
|
373
402
|
"purpose_all": ["All purposes", "所有用途"],
|
|
374
403
|
"purpose_conversation": ["Conversation", "普通会话"],
|
|
404
|
+
"purpose_compaction": ["Compression", "上下文压缩"],
|
|
405
|
+
"context_compaction_heading": ["CONTEXT COMPRESSION", "上下文压缩"],
|
|
406
|
+
"context_compaction_enabled": ["Recover failed compression automatically", "压缩失败时自动恢复"],
|
|
407
|
+
"context_compaction_note": ["Use the current source and model when native compression is unavailable or the input is too long. Uses quota.", "原生压缩不可用或输入过长时,使用当前来源和模型压缩,会消耗用量。"],
|
|
375
408
|
"purpose_diagnostic": ["Diagnostic", "诊断"],
|
|
376
409
|
"purpose_compatibility": ["Compatibility test", "兼容测试"],
|
|
377
410
|
"purpose_unknown": ["Unknown", "未知"],
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const theme = () => globalThis.ccdxDashboardTheme;
|
|
5
5
|
const backupKey = "ccdx.dashboard.preferences-backup";
|
|
6
6
|
const fields = { terminal_color_theme: "terminal-color-theme", terminal_animation_enabled: "setting-terminal_animation_enabled",
|
|
7
|
-
open_webui: "setting-open_webui", nightly_updates: "nightly-update" };
|
|
7
|
+
open_webui: "setting-open_webui", nightly_updates: "nightly-update", context_compaction_enabled: "setting-context_compaction_enabled" };
|
|
8
8
|
let base, draft = {}, appearance, appearanceBase, pending, timer, error = null, conflict = false, version = 0, dialog, dialogRevision, resetting = false, retrying = false, locks = {}, terminalMode;
|
|
9
9
|
const dirty = () => Object.keys(draft).length + (appearance ? 1 : 0);
|
|
10
10
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
package/src/dashboard/status.js
CHANGED
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
for (const source of data.providers?.connections?.providers || []) sourceNames.set(source.id, source.name);
|
|
236
236
|
globalThis.ccdxConnections?.updateMemory?.(data.providers?.connections);
|
|
237
237
|
globalThis.ccdxDashboardActivity?.update(data.model_activity);
|
|
238
|
-
globalThis.ccdxDashboardFlow?.update(data);
|
|
238
|
+
globalThis.ccdxDashboardFlow?.update(data);globalThis.ccdxToolActivity?.update(data);
|
|
239
239
|
text("version", `v${data.version || "?"}`);
|
|
240
240
|
text("uptime", "pid_pid_uptime_duration", { pid: number(data.pid), duration: duration(data.uptime_ms) });
|
|
241
241
|
|
|
@@ -331,7 +331,7 @@
|
|
|
331
331
|
}
|
|
332
332
|
function renderActivity(data) {
|
|
333
333
|
globalThis.ccdxDashboardActivity?.update(data.model_activity, { live: true });
|
|
334
|
-
globalThis.ccdxDashboardFlow?.update(data, { live: true });
|
|
334
|
+
globalThis.ccdxDashboardFlow?.update(data, { live: true });globalThis.ccdxToolActivity?.update(data);
|
|
335
335
|
text("version", `v${data.version || "?"}`);
|
|
336
336
|
text("uptime", "pid_pid_uptime_duration", { pid: number(data.pid), duration: duration(data.uptime_ms) });
|
|
337
337
|
text("requests", number(data.requests?.total));
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const root = document.getElementById("tool-activity");if (!root) return;
|
|
3
|
+
const el = id => document.getElementById(id), canvas = el("tool-canvas"), ctx = canvas.getContext?.("2d");
|
|
4
|
+
const styles = new Set(["grid", "halo", "orbit", "weave", "off"]), storageKey = "ccdx.dashboard.toolMotionStyle";
|
|
5
|
+
const pending = state => ["preparing", "waiting"].includes(state);
|
|
6
|
+
const phrase = (key, values = {}) => globalThis.ccdxLanguage.format(key, values);
|
|
7
|
+
const text = (id, key, values) => globalThis.ccdxLanguage.set(el(id), key, values);
|
|
8
|
+
const state = { scene: "idle", style: "grid", intensity: .8, reduce: false };
|
|
9
|
+
try { const saved = localStorage.getItem(storageKey);if (styles.has(saved)) state.style = saved; } catch {}
|
|
10
|
+
const motion = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)") || { matches: false, addEventListener() {} };
|
|
11
|
+
let records = [], fresh = false, supported = false, visible = true, raf = 0, last = 0, start = performance.now(), expiry = null;
|
|
12
|
+
let signature = "", box = { width: 0, height: 0 }, color = "", omitted = 0;
|
|
13
|
+
const shown = () => document.visibilityState === "visible" && !root.closest("[hidden]") && visible;
|
|
14
|
+
function measure() {
|
|
15
|
+
box = canvas.getBoundingClientRect();color = getComputedStyle(document.documentElement).getPropertyValue("--accent").trim();
|
|
16
|
+
refreshAnimation();
|
|
17
|
+
}
|
|
18
|
+
function draw(now=performance.now()){
|
|
19
|
+
if(!ctx||!box.width||!box.height)return;
|
|
20
|
+
const dpr=Math.min(devicePixelRatio||1,1.5),w=box.width,h=box.height;
|
|
21
|
+
if(canvas.width!==Math.round(w*dpr)||canvas.height!==Math.round(h*dpr)){canvas.width=Math.round(w*dpr);canvas.height=Math.round(h*dpr);}
|
|
22
|
+
ctx.setTransform(dpr,0,0,dpr,0,0);ctx.clearRect(0,0,w,h);
|
|
23
|
+
const cx=w/2,cy=h/2,r=Math.min(w,h)*.31;
|
|
24
|
+
const reduced=motion.matches||state.reduce,t=reduced?0:(now-start)/1000,active=['calling','parallel'].includes(state.scene),waiting=state.scene==='waiting',returned=state.scene==='returned';
|
|
25
|
+
const quiet=state.scene==='idle'||state.scene==='responding',power=quiet?.12:waiting?.5:returned?.5:state.intensity;
|
|
26
|
+
ctx.strokeStyle=color;ctx.fillStyle=color;ctx.lineWidth=.8;
|
|
27
|
+
function arc(radius,a,b,alpha){ctx.globalAlpha=alpha;ctx.beginPath();ctx.arc(cx,cy,radius,a,b);ctx.stroke();}
|
|
28
|
+
if(state.style==='grid'){
|
|
29
|
+
const cols=12,rows=3,gap=5,size=Math.min(13,(w-32)/cols-gap),left=cx-(cols*size+(cols-1)*gap)/2,top=cy-(rows*size+(rows-1)*gap)/2;
|
|
30
|
+
const head=active||waiting?(t*(waiting?11:19))%(cols*rows):-8;
|
|
31
|
+
for(let row=0;row<rows;row++)for(let col=0;col<cols;col++){
|
|
32
|
+
const index=row*cols+(row%2?cols-col-1:col),distance=(head-index+cols*rows)%(cols*rows),wave=Math.max(0,1-distance/8);
|
|
33
|
+
ctx.globalAlpha=quiet?.1:returned?.16+Math.max(0,1-(now-start)/900)*.42:.1+wave*power;
|
|
34
|
+
ctx.fillRect(left+col*(size+gap),top+row*(size+gap),size,size);
|
|
35
|
+
}
|
|
36
|
+
ctx.globalAlpha=1;return;
|
|
37
|
+
}
|
|
38
|
+
arc(r,0,Math.PI*2,.25);arc(r*.85,0,Math.PI*2,.13);arc(r*1.12,0,Math.PI*2,.1);
|
|
39
|
+
const spin=active?t*1.6:waiting?t*.9:0;
|
|
40
|
+
if(state.style==='halo'){
|
|
41
|
+
for(let i=0;i<64;i++){
|
|
42
|
+
const a=i/64*Math.PI*2+spin,pulse=active||waiting?(Math.sin(t*7+i*.7)*.5+.5):returned?.6:.05;
|
|
43
|
+
const length=3+(i%4===0?8:3)+pulse*(active?20:waiting?9:2)*state.intensity;
|
|
44
|
+
ctx.globalAlpha=(.16+pulse*.55)*power;ctx.lineWidth=i%8===0?1.4:.75;
|
|
45
|
+
ctx.beginPath();ctx.moveTo(cx+Math.cos(a)*r*1.17,cy+Math.sin(a)*r*1.17);ctx.lineTo(cx+Math.cos(a)*(r*1.17+length),cy+Math.sin(a)*(r*1.17+length));ctx.stroke();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if(state.style==='weave'||state.style==='halo'){
|
|
49
|
+
ctx.lineWidth=.65;const strands=state.style==='weave'?62:28;
|
|
50
|
+
for(let i=0;i<strands;i++){
|
|
51
|
+
const a=i/strands*Math.PI*2+spin*.6,b=a+2.35+Math.sin(i*.68+t*1.7)*.48,inner=r*(state.style==='weave'?.84:.68);
|
|
52
|
+
ctx.globalAlpha=(.1+power*.2)*(quiet?.45:1);ctx.beginPath();ctx.moveTo(cx+Math.cos(a)*inner,cy+Math.sin(a)*inner);ctx.quadraticCurveTo(cx+Math.sin(t*1.3+i)*r*.35,cy+Math.cos(i*.5+t*.7)*r*.3,cx+Math.cos(b)*inner,cy+Math.sin(b)*inner);ctx.stroke();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for(let i=0;i<3;i++){
|
|
56
|
+
const a=spin*(i%2?-1:1)+i*2.08,track=r*(state.style==='orbit'?.58+i*.25:.89+i*.06);
|
|
57
|
+
ctx.lineWidth=1.3;arc(track,a,a+(active?1.25:waiting?.75:.18),quiet?.15:.75);
|
|
58
|
+
if(state.style==='orbit'){arc(track,0,Math.PI*2,.12);ctx.globalAlpha=quiet?.2:.8;ctx.beginPath();ctx.arc(cx+Math.cos(a)*track,cy+Math.sin(a)*track,active?2.8:2,0,Math.PI*2);ctx.fill();}
|
|
59
|
+
}
|
|
60
|
+
if(active||waiting){for(let i=0;i<3;i++){const q=(t*.85+i/3)%1;arc(r*(.55+q*.5),0,Math.PI*2,(1-q)*.12*power);}}
|
|
61
|
+
if(returned&&!reduced){const q=Math.min((now-start)/850,1);arc(r*(1+q*.32),0,Math.PI*2,(1-q)*.5);}
|
|
62
|
+
ctx.globalAlpha=1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function animate(now) {
|
|
66
|
+
raf = 0;
|
|
67
|
+
if (!shown() || motion.matches || state.style === "off" || !["calling", "parallel", "waiting"].includes(state.scene) && !(state.scene === "returned" && now - start < 900)) return;
|
|
68
|
+
if (now - last >= 1000 / 30) { last = now;draw(now); }raf = requestAnimationFrame(animate);
|
|
69
|
+
}
|
|
70
|
+
function refreshAnimation() {
|
|
71
|
+
cancelAnimationFrame(raf);raf = 0;root.dataset.paused = String(!shown() || motion.matches);
|
|
72
|
+
if (!shown() || state.style === "off") return;
|
|
73
|
+
draw();if (!motion.matches && (["calling", "parallel", "waiting"].includes(state.scene) || state.scene === "returned" && performance.now() - start < 900)) raf = requestAnimationFrame(animate);
|
|
74
|
+
}
|
|
75
|
+
function category(name) {
|
|
76
|
+
const value = String(name || "").toLowerCase().split(/__|\./).at(-1);
|
|
77
|
+
if (["read_file", "readfile", "view_file", "open_file", "get_file_content"].includes(value)) return "tool_action_read";
|
|
78
|
+
if (["search_files", "file_search", "grep", "rg"].includes(value)) return "tool_action_search";
|
|
79
|
+
if (["exec_command", "run_command", "bash", "shell"].includes(value)) return "tool_action_command";
|
|
80
|
+
if (["write_file", "edit_file", "apply_patch"].includes(value)) return "tool_action_edit";
|
|
81
|
+
if (["web_search", "search_web"].includes(value)) return "tool_action_web";
|
|
82
|
+
return "tool_action_generic";
|
|
83
|
+
}
|
|
84
|
+
function appName(id) { return phrase(`flow_app_${id}`); }
|
|
85
|
+
const sourceName = id => id === "github" ? "GitHub Copilot" : id === "m365" ? "Microsoft 365" : id === "google" ? "Google" : globalThis.ccdxConnectionNames?.[id] || phrase("flow_source_unknown");
|
|
86
|
+
function render(force = false) {
|
|
87
|
+
if (root.closest("[hidden]")) { signature = "";refreshAnimation();return; }
|
|
88
|
+
const time = performance.now();
|
|
89
|
+
for (const row of records) if (row.until <= time && pending(row.state)) { row.state = "unknown";row.until = time + 300000; }
|
|
90
|
+
records = records.filter(row => row.until > time);
|
|
91
|
+
const rows = records.slice(0, 32).map(row => fresh || !pending(row.state) ? row : { ...row, state: "unknown" });
|
|
92
|
+
const next = JSON.stringify([fresh, supported, state.style, omitted, rows.map(({ until, ...row }) => row)]);
|
|
93
|
+
clearTimeout(expiry);expiry = null;
|
|
94
|
+
if (records.length) expiry = setTimeout(() => render(), Math.max(1, Math.min(...records.map(row => row.until - time))));
|
|
95
|
+
if (!force && next === signature) return;
|
|
96
|
+
signature = next;
|
|
97
|
+
const active = rows.filter(row => pending(row.state)), preparing = active.some(row => row.state === "preparing");
|
|
98
|
+
const scene = active.length ? preparing ? active.length > 1 ? "parallel" : "calling" : "waiting"
|
|
99
|
+
: rows.some(row => row.state === "returned") && !rows.some(row => ["failed", "cancelled", "unknown"].includes(row.state)) ? "returned" : "idle";
|
|
100
|
+
if (scene !== state.scene) start = performance.now();state.scene = scene;
|
|
101
|
+
const key = !supported || !fresh ? "flow_status_unknown" : active.length ? preparing ? active.length > 1 ? "tool_preparing_many" : "tool_preparing" : "tool_waiting"
|
|
102
|
+
: rows.some(row => row.state === "failed") ? "tool_failed" : rows.some(row => row.state === "cancelled") ? "tool_cancelled"
|
|
103
|
+
: rows.some(row => row.state === "unknown") ? "flow_status_unknown" : rows.length ? "tool_returned" : "tool_idle";
|
|
104
|
+
text("tool-state", key, { count: active.length });
|
|
105
|
+
canvas.setAttribute("aria-label", phrase(key, { count: active.length }));
|
|
106
|
+
el("tool-style").value = state.style;el("tool-stage").dataset.style = state.style;
|
|
107
|
+
el("tool-cursor").hidden = !active.length || state.style === "off" || !fresh;
|
|
108
|
+
const groups = new Map(rows.map(row => [`${row.application}:${row.provider}:${row.model}`, row]));
|
|
109
|
+
el("tool-context").hidden = !rows.length;
|
|
110
|
+
el("tool-context").textContent = groups.size === 1 ? `${appName(rows[0].application)} · ${rows[0].model === "other" ? phrase("flow_model_pending") : rows[0].model}` : phrase("tool_groups", { count: groups.size });
|
|
111
|
+
const list = el("tool-list");list.replaceChildren();
|
|
112
|
+
for (const row of rows.slice(0, 6)) {
|
|
113
|
+
const item = document.createElement("div");item.className = "tool-entry";item.dataset.state = row.state;
|
|
114
|
+
const mark = document.createElement("span");mark.className = "tool-mark";mark.setAttribute("aria-hidden", "true");
|
|
115
|
+
const name = document.createElement("span");name.className = "tool-name";name.textContent = phrase(category(row.name));
|
|
116
|
+
const status = document.createElement("span");status.textContent = phrase(`tool_row_${row.state}`);
|
|
117
|
+
item.append(mark, name, status);list.append(item);
|
|
118
|
+
}
|
|
119
|
+
el("tool-details").hidden = !rows.length;
|
|
120
|
+
el("tool-technical").replaceChildren();
|
|
121
|
+
for (const row of rows) {
|
|
122
|
+
const line = document.createElement("p");line.textContent = `${appName(row.application)} · ${sourceName(row.provider)} · ${row.model} · ${row.name || phrase("tool_action_generic")} · ${phrase(`tool_row_${row.state}`)}`;el("tool-technical").append(line);
|
|
123
|
+
}
|
|
124
|
+
el("tool-more").hidden = rows.length <= 6 && !omitted;
|
|
125
|
+
text("tool-more", "tool_more", { count: Math.max(0, rows.length - 6) + omitted });
|
|
126
|
+
measure();
|
|
127
|
+
}
|
|
128
|
+
el("tool-style").addEventListener("change", () => {
|
|
129
|
+
const next = el("tool-style").value;if (!styles.has(next)) return;state.style = next;
|
|
130
|
+
try { localStorage.setItem(storageKey, next); } catch {}render(true);
|
|
131
|
+
});
|
|
132
|
+
document.addEventListener("visibilitychange", () => { if (shown()) render();refreshAnimation(); });
|
|
133
|
+
globalThis.addEventListener("pagehide", () => { cancelAnimationFrame(raf);raf = 0;root.dataset.paused = "true"; });
|
|
134
|
+
motion.addEventListener("change", refreshAnimation);
|
|
135
|
+
new ResizeObserver(measure).observe(canvas.parentElement);
|
|
136
|
+
new IntersectionObserver(entries => { visible = entries[0].isIntersecting;refreshAnimation(); }, { threshold: .05 }).observe(canvas);
|
|
137
|
+
new MutationObserver(() => render(true)).observe(document.documentElement, { attributes: true, attributeFilter: ["lang", "data-theme", "data-palette"] });
|
|
138
|
+
globalThis.ccdxToolActivity = {
|
|
139
|
+
update(data) {
|
|
140
|
+
const parts = [data?.stream_performance, (data?.providers?.claude || data?.providers?.m365?.claude)?.requests?.performance].filter(Boolean);
|
|
141
|
+
const views = parts.map(part => part.tool_activity).filter(value => Array.isArray(value?.items));
|
|
142
|
+
supported = views.length > 0;fresh = supported;const time = performance.now();
|
|
143
|
+
const merged = views.flatMap((view, index) => view.items.slice(0, 32).filter(row => row && typeof row.id === "string" && ["preparing", "waiting", "returned", "failed", "cancelled", "unknown"].includes(row.state)
|
|
144
|
+
&& Number.isFinite(row.expires_in_ms) && row.expires_in_ms > 0).map(row => ({ id: `${index}-${row.id}`, application: row.application || "api", provider: row.provider, model: row.model || "other", name: row.name,
|
|
145
|
+
state: row.state, until: time + Math.min(row.expires_in_ms, 300000) })));
|
|
146
|
+
merged.sort((a, b) => Number(pending(b.state)) - Number(pending(a.state)));records = merged.slice(0, 32);
|
|
147
|
+
omitted = Math.max(0, merged.length - records.length) + views.reduce((sum, view) => sum + (Number.isSafeInteger(view.omitted) ? view.omitted : 0), 0);render();
|
|
148
|
+
},
|
|
149
|
+
unavailable() { fresh = false;render(); },
|
|
150
|
+
visibilityChanged() { render();refreshAnimation(); },
|
|
151
|
+
};
|
|
152
|
+
render();
|
|
153
|
+
})();
|
package/src/dashboard/ui.css
CHANGED
|
@@ -671,3 +671,29 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
671
671
|
.image-model-choice { display: flex; align-items: center; gap: 8px; overflow-wrap: anywhere; }
|
|
672
672
|
.image-model-choice input { flex: 0 0 auto; }
|
|
673
673
|
.image-metrics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
|
|
674
|
+
|
|
675
|
+
.tool-style { display:flex;align-items:center;gap:8px;font-size:12px;color:var(--muted);white-space:nowrap; }
|
|
676
|
+
.tool-style select { max-width:160px; }
|
|
677
|
+
.tool-stage { display:grid;grid-template-columns:minmax(180px,250px) minmax(0,1fr);align-items:center;gap:24px;min-height:230px; }
|
|
678
|
+
.tool-visual,.tool-content { min-width:0; }
|
|
679
|
+
.tool-orbit { width:100%;height:190px;position:relative; }
|
|
680
|
+
.tool-orbit canvas { display:block;width:100%;height:100%; }
|
|
681
|
+
.tool-stage[data-style="grid"] .tool-orbit { max-height:140px; }
|
|
682
|
+
.tool-stage[data-style="off"] { grid-template-columns:1fr;min-height:110px; }
|
|
683
|
+
.tool-stage[data-style="off"] .tool-visual { display:none; }
|
|
684
|
+
.tool-narration { margin:0;min-height:24px;text-align:center;color:var(--text);font-size:12px;line-height:1.7; }
|
|
685
|
+
.tool-context { color:var(--muted);font-size:11px;line-height:1.6;margin:0 0 16px; }
|
|
686
|
+
.tool-entry { display:grid;grid-template-columns:18px minmax(0,1fr) auto;gap:10px;align-items:center;min-height:48px;padding-block:8px;border-bottom:1px solid var(--border); }
|
|
687
|
+
.tool-entry:last-child { border-bottom:0; }
|
|
688
|
+
.tool-name { font-size:12px; }
|
|
689
|
+
.tool-entry > span:last-child { color:var(--muted);font-size:11px;white-space:nowrap; }
|
|
690
|
+
.tool-mark { display:inline-block;width:7px;height:7px;border:1px solid var(--accent);border-radius:50%; }
|
|
691
|
+
.tool-entry[data-state="preparing"] .tool-mark { background:var(--accent); }
|
|
692
|
+
.tool-entry[data-state="returned"] .tool-mark { width:9px;height:5px;border-top:0;border-right:0;border-radius:0;transform:rotate(-45deg); }
|
|
693
|
+
.tool-technical { margin:12px 0 0;color:var(--muted);font-size:11px; }
|
|
694
|
+
.tool-technical p { overflow-wrap:anywhere;line-height:1.7;margin:6px 0; }
|
|
695
|
+
#tool-cursor { display:inline-block;animation:tool-cursor 1s steps(1) infinite; }
|
|
696
|
+
#tool-activity[data-paused="true"] #tool-cursor { animation:none; }
|
|
697
|
+
@keyframes tool-cursor { 50% { opacity:0; } }
|
|
698
|
+
@media(max-width:620px) { .tool-stage { grid-template-columns:1fr;gap:8px; }.tool-visual { width:100%;max-width:330px;margin:auto; }.tool-content { padding-bottom:8px; }.tool-context { margin-bottom:4px; } }
|
|
699
|
+
@media(prefers-reduced-motion:reduce) { #tool-cursor { animation:none; } }
|
package/src/dashboard/ui.js
CHANGED
|
@@ -271,7 +271,7 @@ for (const [key, ids] of [["auth", ["account-authorization", "client-features",
|
|
|
271
271
|
const updateView = globalThis.ccdxDashboardUpdates.create(viewHelpers);
|
|
272
272
|
function statusState(state) {
|
|
273
273
|
if (!liveActivity.current && (state.error || !state.value)) globalThis.ccdxDashboardActivity?.unavailable();
|
|
274
|
-
if (!liveActivity.current && (state.error || !state.value) && statusResourceKey() === "status") globalThis.ccdxDashboardFlow?.unavailable();
|
|
274
|
+
if (!liveActivity.current && (state.error || !state.value) && statusResourceKey() === "status") { globalThis.ccdxDashboardFlow?.unavailable();globalThis.ccdxToolActivity?.unavailable(); }
|
|
275
275
|
text("connection", state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable");
|
|
276
276
|
element("connection").className = `badge ${state.pending ? "neutral" : state.error ? "bad" : "good"}`;
|
|
277
277
|
globalThis.ccdxIcons?.set(element("connection"), state.pending && !state.value ? "reading" : state.error ? "unavailable_eb0be" : "service_reachable",
|
|
@@ -457,7 +457,7 @@ const liveActivity = globalThis.ccdxLive.create({
|
|
|
457
457
|
element("connection").className = "badge good";
|
|
458
458
|
globalThis.ccdxIcons?.set(element("connection"), "service_reachable", "connected");
|
|
459
459
|
} else {
|
|
460
|
-
globalThis.ccdxDashboardActivity?.unavailable();globalThis.ccdxDashboardFlow?.unavailable();
|
|
460
|
+
globalThis.ccdxDashboardActivity?.unavailable();globalThis.ccdxDashboardFlow?.unavailable();globalThis.ccdxToolActivity?.unavailable();
|
|
461
461
|
if (value !== "paused") {
|
|
462
462
|
element("connection").className = "badge neutral";
|
|
463
463
|
globalThis.ccdxIcons?.set(element("connection"), "reading", "unknown");
|
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.js", ["./dashboard/tool-activity.js", "text/javascript; charset=utf-8"]],
|
|
20
21
|
["/usage.js", ["./dashboard/usage.js", "text/javascript; charset=utf-8"]],
|
|
21
22
|
["/context.js", ["./dashboard/context.js", "text/javascript; charset=utf-8"]],
|
|
22
23
|
["/updates.js", ["./dashboard/updates.js", "text/javascript; charset=utf-8"]],
|
package/src/http-transport.mjs
CHANGED
|
@@ -26,7 +26,7 @@ export const MAX_DECODED_BODY_BYTES = decodedBodyLimitPreference().bytes;
|
|
|
26
26
|
|
|
27
27
|
export {
|
|
28
28
|
MAX_UPSTREAM_ERROR_BODY_BYTES, MAX_UPSTREAM_MODEL_CATALOG_BYTES, MAX_UPSTREAM_RETRY_DRAIN_BYTES,
|
|
29
|
-
readBoundedResponseBuffer, readBoundedResponseText, discardBoundedResponseBody,
|
|
29
|
+
readBoundedResponseBuffer, readBoundedResponseText, discardBoundedResponseBody, readResponseChunk,
|
|
30
30
|
} from "./upstream-body.mjs";
|
|
31
31
|
export const MAX_UPSTREAM_CHAT_SUCCESS_BODY_BYTES = HTTP_RUNTIME_CONFIG.maxUpstreamChatResponseBytes;
|
|
32
32
|
export const MAX_UPSTREAM_RESPONSES_SUCCESS_BODY_BYTES = HTTP_RUNTIME_CONFIG.maxUpstreamResponsesResponseBytes;
|