codex-copilot-dx 1.4.13 → 1.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/ARCHITECTURE.md +6 -0
- package/docs/REFERENCE.md +7 -6
- package/package.json +1 -1
- package/src/adapter.mjs +2 -0
- package/src/antigravity-bindings.mjs +83 -0
- package/src/antigravity-handler.mjs +24 -11
- package/src/antigravity-models.mjs +32 -1
- package/src/antigravity-runtime.mjs +24 -68
- package/src/cli-management-app.mjs +169 -0
- package/src/cli-management.mjs +5 -164
- package/src/dashboard/index.html +5 -4
- package/src/dashboard/language.js +2 -0
- package/src/dashboard/status.js +38 -20
- package/src/dashboard/tool-activity-machines.js +841 -319
- package/src/dashboard/tool-activity.js +6 -6
- package/src/dashboard/ui.css +37 -11
- package/src/dashboard/ui.js +3 -3
- package/src/local-privacy.mjs +3 -3
- package/src/management-routes.mjs +3 -3
- package/src/observability.mjs +9 -4
- package/src/privacy-transform.mjs +21 -6
- package/src/providers/api.mjs +4 -1
- package/src/source-admission.mjs +33 -8
- package/src/status-summary.mjs +13 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const root = document.getElementById("tool-activity");if (!root) return;
|
|
3
3
|
const el = id => document.getElementById(id), canvas = el("tool-canvas"), ctx = canvas.getContext?.("2d");
|
|
4
|
-
const styles = new Set(["assembly", "sorter", "gantry", "rotary", "off"]), storageKey = "ccdx.dashboard.toolMotionStyle";
|
|
4
|
+
const styles = new Set(["production", "clock", "assembly", "sorter", "gantry", "rotary", "off"]), storageKey = "ccdx.dashboard.toolMotionStyle";
|
|
5
5
|
const pending = state => ["preparing", "waiting"].includes(state);
|
|
6
6
|
const phrase = (key, values = {}) => globalThis.ccdxLanguage.format(key, values);
|
|
7
7
|
const text = (id, key, values) => globalThis.ccdxLanguage.set(el(id), key, values);
|
|
8
|
-
const state = { scene: "idle", style: "
|
|
8
|
+
const state = { scene: "idle", style: "production" };
|
|
9
9
|
const drawMachine = ctx && globalThis.ccdxToolMachines(ctx);
|
|
10
10
|
try { const saved = localStorage.getItem(storageKey);if (styles.has(saved)) state.style = saved; } catch {}
|
|
11
11
|
const motion = globalThis.matchMedia?.("(prefers-reduced-motion: reduce)") || { matches: false, addEventListener() {} };
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
if (canvas.width !== w || canvas.height !== h) { canvas.width = w;canvas.height = h; }
|
|
28
28
|
ctx.setTransform(1, 0, 0, 1, 0, 0);ctx.clearRect(0, 0, w, h);
|
|
29
29
|
if (animating() && !motion.matches) drawnTime = (now - start) / 1000;
|
|
30
|
-
drawMachine(state.style, { time:
|
|
30
|
+
drawMachine(state.style, { time: motion.matches ? 0 : drawnTime ?? 0, width, height, dpr, ink: color, surface });
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function animate(now) {
|
|
@@ -100,9 +100,9 @@
|
|
|
100
100
|
el("tool-technical").replaceChildren();
|
|
101
101
|
for (const row of rows) {
|
|
102
102
|
const line = document.createElement("tr");
|
|
103
|
-
for (const value of [appName(row.application), sourceName(row.provider), row.model,
|
|
104
|
-
row.name || phrase("tool_action_generic"), phrase(`tool_row_${row.state}`)]) {
|
|
105
|
-
const cell = document.createElement("td");cell.textContent = value;line.append(cell);
|
|
103
|
+
for (const [label, value] of [["client", appName(row.application)], ["source", sourceName(row.provider)], ["model", row.model],
|
|
104
|
+
["tool_name", row.name || phrase("tool_action_generic")], ["outcome", phrase(`tool_row_${row.state}`)]]) {
|
|
105
|
+
const cell = document.createElement("td");cell.textContent = value;cell.dataset.label = phrase(label);line.append(cell);
|
|
106
106
|
}
|
|
107
107
|
el("tool-technical").append(line);
|
|
108
108
|
}
|
package/src/dashboard/ui.css
CHANGED
|
@@ -269,9 +269,18 @@ main { align-self: start; }
|
|
|
269
269
|
.chart-heading { flex-wrap: wrap; align-items: end; }
|
|
270
270
|
.chart-heading .analytics-controls { margin: 0; }
|
|
271
271
|
.chart-heading label { display: grid; gap: 6px; color: var(--muted); }
|
|
272
|
-
.request-
|
|
273
|
-
.request-
|
|
274
|
-
.request-
|
|
272
|
+
.request-detail-cell { padding: 9px 12px 12px; background: var(--surface); }
|
|
273
|
+
.request-detail-fields { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(240px,100%),1fr)); gap:5px 20px; margin:0; }
|
|
274
|
+
.request-detail-fields > div { display:grid; grid-template-columns:minmax(0,max-content) minmax(0,1fr); align-items:baseline; gap:6px 10px; min-width:0; }
|
|
275
|
+
.request-detail-fields .request-detail-wide { grid-column:1 / -1; }
|
|
276
|
+
.request-detail-fields dt { color:var(--muted); }
|
|
277
|
+
.request-detail-fields dd { margin:0; overflow-wrap:anywhere; min-width:0; }
|
|
278
|
+
.request-disclosure { min-height:0; padding:4px 8px; white-space:nowrap; }
|
|
279
|
+
.recent-requests-table th.recent-request-time { width:13ch; }
|
|
280
|
+
.recent-requests-table th.recent-request-duration { width:15ch; }
|
|
281
|
+
.recent-requests-table th.recent-request-app { width:17%; }
|
|
282
|
+
.recent-requests-table th.recent-request-result { width:17%; }
|
|
283
|
+
.recent-requests-table th:last-child { width:10ch; }
|
|
275
284
|
.snapshot-meta { justify-content: flex-start; margin-top: 14px; line-height: 1.7; }
|
|
276
285
|
.overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
277
286
|
.client-overview { grid-template-columns: 1fr; }
|
|
@@ -693,28 +702,40 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
693
702
|
|
|
694
703
|
.tool-style { display:flex;align-items:center;gap:8px;font-size:12px;color:var(--muted);white-space:nowrap; }
|
|
695
704
|
.tool-style select { max-width:160px; }
|
|
696
|
-
.tool-stage { display:grid;grid-template-columns:minmax(
|
|
705
|
+
.tool-stage { display:grid;grid-template-columns:minmax(0,2fr) minmax(180px,1fr);align-items:start;gap:18px; }
|
|
697
706
|
.tool-visual,.tool-content { min-width:0; }
|
|
698
|
-
.tool-orbit { width:100%;height:
|
|
707
|
+
.tool-orbit { width:100%;height:clamp(260px,29vw,360px);position:relative; }
|
|
699
708
|
.tool-orbit canvas { display:block;width:100%;height:100%; }
|
|
700
709
|
.tool-stage[data-style="off"] { grid-template-columns:1fr;min-height:110px; }
|
|
701
710
|
.tool-stage[data-style="off"] .tool-orbit { display:none; }
|
|
702
711
|
.tool-stage[data-style="off"] .tool-narration { text-align:left; }
|
|
703
712
|
.tool-narration { margin:0;min-height:24px;text-align:center;color:var(--text);font-size:12px;line-height:1.7; }
|
|
704
|
-
.tool-context { color:var(--muted);font-size:11px;line-height:1.6;margin:0 0
|
|
705
|
-
.tool-entry { display:grid;grid-template-columns:
|
|
713
|
+
.tool-context { color:var(--muted);font-size:11px;line-height:1.6;margin:0 0 8px;overflow-wrap:anywhere; }
|
|
714
|
+
.tool-entry { display:grid;grid-template-columns:12px minmax(0,1fr) minmax(0,max-content);gap:7px;align-items:center;min-height:34px;padding-block:4px;border-bottom:1px solid var(--border); }
|
|
706
715
|
.tool-entry:last-child { border-bottom:0; }
|
|
707
716
|
.tool-name { font-size:12px; }
|
|
708
|
-
.tool-entry > span:last-child { color:var(--muted);font-size:11px;
|
|
717
|
+
.tool-entry > span:last-child { color:var(--muted);font-size:11px;text-align:right;overflow-wrap:anywhere; }
|
|
709
718
|
.tool-mark { display:inline-block;width:7px;height:7px;border:1px solid var(--accent);border-radius:50%; }
|
|
710
719
|
.tool-entry[data-state="preparing"] .tool-mark { background:var(--accent); }
|
|
711
720
|
.tool-entry[data-state="returned"] .tool-mark { width:9px;height:5px;border-top:0;border-right:0;border-radius:0;transform:rotate(-45deg); }
|
|
712
721
|
.tool-technical { margin:12px 0 0;color:var(--muted);font-size:11px; }
|
|
713
722
|
.tool-technical p { overflow-wrap:anywhere;line-height:1.7;margin:6px 0; }
|
|
723
|
+
.tool-technical th:nth-child(3), .tool-technical th:nth-child(4) { width:26%; }
|
|
714
724
|
#tool-cursor { display:inline-block;animation:tool-cursor 1s steps(1) infinite; }
|
|
715
725
|
#tool-activity[data-paused="true"] #tool-cursor { animation:none; }
|
|
716
726
|
@keyframes tool-cursor { 50% { opacity:0; } }
|
|
717
|
-
@media(max-width:
|
|
727
|
+
@media(max-width:760px) {
|
|
728
|
+
.tool-stage { grid-template-columns:1fr;gap:8px; }
|
|
729
|
+
.tool-orbit { height:clamp(200px,52vw,320px); }
|
|
730
|
+
.tool-context { margin-bottom:4px; }
|
|
731
|
+
}
|
|
732
|
+
@media(max-width:620px) {
|
|
733
|
+
.tool-technical :is(table,tbody,tr) { display:block; }
|
|
734
|
+
.tool-technical thead { position:absolute; clip-path:inset(50%); width:1px; height:1px; overflow:hidden; }
|
|
735
|
+
.tool-technical tbody tr { padding-block:6px; border-bottom:1px solid var(--border); }
|
|
736
|
+
.tool-technical tbody td { display:grid; grid-template-columns:70px minmax(0,1fr); gap:8px; padding:2px 0; border:0; }
|
|
737
|
+
.tool-technical tbody td::before { content:attr(data-label); color:var(--muted); }
|
|
738
|
+
}
|
|
718
739
|
@media(prefers-reduced-motion:reduce) { #tool-cursor { animation:none; } }
|
|
719
740
|
|
|
720
741
|
/* Compact request statistics in the existing diagnostics panel. */
|
|
@@ -759,8 +780,13 @@ input[role="switch"]:disabled { opacity: .5; cursor: wait; }
|
|
|
759
780
|
.usage-table :is(th,td):not(:first-child):not(:nth-child(7)):not([colspan]) { display: none; }
|
|
760
781
|
.usage-table th:first-child { width: 70%; }
|
|
761
782
|
.usage-row-details { display: block; }
|
|
762
|
-
.recent-requests-table
|
|
763
|
-
.recent-requests-table th:
|
|
783
|
+
.recent-requests-table { table-layout:auto; }
|
|
784
|
+
.recent-requests-table :is(th,td):is(.recent-request-time,.recent-request-app) { display:none; }
|
|
785
|
+
.recent-requests-table th.recent-request-duration { width:11ch; }
|
|
786
|
+
.recent-requests-table th.recent-request-result { width:1%; }
|
|
787
|
+
.recent-requests-table th:last-child { width:1%; }
|
|
788
|
+
.recent-requests-table .recent-request-duration { white-space:nowrap; }
|
|
789
|
+
.recent-requests-table .recent-request-result { overflow-wrap:normal; }
|
|
764
790
|
.failure-table th:last-child { width: 40%; }
|
|
765
791
|
}
|
|
766
792
|
#action-confirm-apply { background:var(--accent); color:var(--page); border-color:var(--accent); }
|
package/src/dashboard/ui.js
CHANGED
|
@@ -405,13 +405,13 @@ const dashboardRefresh = globalThis.ccdxRefresh.createController({
|
|
|
405
405
|
variant: () => {
|
|
406
406
|
const mode = (element("usage-analytics").open || Boolean(usageView.selectedDate)) ? "analytics" : "summary";
|
|
407
407
|
const provider = element("usage-provider")?.value || "";
|
|
408
|
-
return JSON.stringify({ mode, provider, model: element("analytics-model").value || "", days: element("analytics-range").value || "all", date: usageView.selectedDate });
|
|
408
|
+
return JSON.stringify({ mode, provider, model: element("analytics-model").value || "", days: element("analytics-range").value || "all", date: usageView.selectedDate, purpose: element("usage-purpose")?.value || "" });
|
|
409
409
|
},
|
|
410
410
|
load: async ({ variant, signal }) => {
|
|
411
|
-
const { mode, provider, model, days, date } = JSON.parse(variant), query = new URLSearchParams();
|
|
411
|
+
const { mode, provider, model, days, date, purpose } = JSON.parse(variant), query = new URLSearchParams();
|
|
412
412
|
if (mode === "analytics") { query.set("analytics", "1");query.set("time_zone", Intl.DateTimeFormat().resolvedOptions().timeZone); }
|
|
413
413
|
if (provider) query.set("provider", provider);
|
|
414
|
-
if (
|
|
414
|
+
if (purpose) query.set("purpose", purpose);
|
|
415
415
|
if (model) query.set("model", model);
|
|
416
416
|
if (date?.startsWith("<")) query.set("to", new Date(Date.parse(date.slice(1)) - 86400000).toISOString().slice(0, 10));
|
|
417
417
|
else if (date) { query.set("from", date);query.set("to", date); }
|
package/src/local-privacy.mjs
CHANGED
|
@@ -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
|
|
36
|
-
res.end(JSON.stringify(
|
|
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
|
|
package/src/observability.mjs
CHANGED
|
@@ -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
|
|
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
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
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
|
|
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);
|
package/src/providers/api.mjs
CHANGED
|
@@ -46,6 +46,8 @@ export function createApiProvider({ config, secrets, env = process.env, platform
|
|
|
46
46
|
endpoint: config.endpoints[protocol] ? new URL(config.endpoints[protocol]).href : null, key: config.secret_ref || fingerprint, auth: protocol === "messages" ? config.auth_header : protocol === "gemini" ? "x-goog-api-key" : "bearer",
|
|
47
47
|
})).digest("hex").slice(0, 24)}`]));
|
|
48
48
|
const profile = profiles.responses;
|
|
49
|
+
const admissionAccount = `api:${config.id}:${config.secret_ref || fingerprint}`;
|
|
50
|
+
const admissionRevision = createHash("sha256").update(JSON.stringify(profiles)).digest("hex");
|
|
49
51
|
const modelsUrl = config.base_url.replace(/\/+$/, "") + "/models", geminiModelsUrl = config.endpoints.gemini && new URL(config.endpoints.gemini).href;
|
|
50
52
|
const targets = [...Object.values(config.endpoints), modelsUrl];
|
|
51
53
|
if (config.endpoints.messages) targets.push(config.endpoints.messages.replace(/\/+$/, "") + "/count_tokens");
|
|
@@ -235,7 +237,8 @@ export function createApiProvider({ config, secrets, env = process.env, platform
|
|
|
235
237
|
},
|
|
236
238
|
};
|
|
237
239
|
return {
|
|
238
|
-
id: config.id, name: config.name, client, registry, configuredModels: true, defaultReviewEffort: null,
|
|
240
|
+
id: config.id, name: config.name, client, registry, configuredModels: true, defaultReviewEffort: null,
|
|
241
|
+
admissionAccount, admissionRevision, profileId: (protocol = "responses") => profiles[protocol] || profile,
|
|
239
242
|
models: family => catalog.filter(model => model.supported_endpoints.includes(family === "claude" ? paths.messages : family === "gemini" ? paths.gemini : paths.responses))
|
|
240
243
|
.map(model => ({ ...model, ...modelDisplay(model.id), capability: model.protocol_capabilities[family === "claude" ? "messages" : family === "gemini" ? "gemini" : "responses"] })),
|
|
241
244
|
catalog: () => catalog,
|
package/src/source-admission.mjs
CHANGED
|
@@ -27,7 +27,13 @@ export function observeSourceStreamFailure(response, error) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
export function admittedSource(source, scheduler) {
|
|
30
|
-
|
|
30
|
+
if (!source?.client || !scheduler) return source;
|
|
31
|
+
if (!source.admissionRevision) {
|
|
32
|
+
return { ...source, client: scheduler.wrap(source.client, () => ({ source: source.id, account: source.profileId() })) };
|
|
33
|
+
}
|
|
34
|
+
const descriptor = { source: source.id, account: source.admissionAccount, revision: source.admissionRevision };
|
|
35
|
+
scheduler.registerDeployment(descriptor);
|
|
36
|
+
return { ...source, client: scheduler.wrap(source.client, () => descriptor) };
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
export function sourceLimitFeedback(status, headers, body, now = Date.now()) {
|
|
@@ -65,8 +71,9 @@ export function sourceLimitFeedback(status, headers, body, now = Date.now()) {
|
|
|
65
71
|
export function createSourceAdmission({ now = Date.now, initialLimit = MAX_LIMIT, maxQueued = 16,
|
|
66
72
|
maxQueuedBytes = MAX_QUEUE_BYTES, waitTimeoutMs = 30000, stableMs = 60000, onStable = () => {}, learned = {} } = {}) {
|
|
67
73
|
const groups = new Map(), limits = new Map(), clients = new WeakMap();
|
|
74
|
+
const deployments = new Map();
|
|
68
75
|
let closed = false, queuedBytes = 0;
|
|
69
|
-
const groupFor = ({ source, account = source }) => {
|
|
76
|
+
const groupFor = ({ source, account = source, revision }) => {
|
|
70
77
|
const identity = source + "\0" + account;
|
|
71
78
|
let group = groups.get(identity);
|
|
72
79
|
if (!group) {
|
|
@@ -75,8 +82,11 @@ export function createSourceAdmission({ now = Date.now, initialLimit = MAX_LIMIT
|
|
|
75
82
|
if (!idle) throw failure("ccdx_source_capacity", "Source scheduler is busy. Retry shortly.");
|
|
76
83
|
clearTimeout(idle[1].timer);groups.delete(idle[0]);
|
|
77
84
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
85
|
+
const deployment = revision && deployments.get(source);
|
|
86
|
+
const activeRevision = deployment?.account === account ? deployment.revision : revision;
|
|
87
|
+
const key = fingerprint(activeRevision ? identity + "\0" + activeRevision : identity);
|
|
88
|
+
const saved = learned[key], restored = validLimit(saved?.limit) && saved?.limit !== null && now() >= saved.at && now() - saved.at < 86400000;
|
|
89
|
+
group = { source, key, revision: activeRevision, limit: restored ? saved.limit : initialLimit, active: 0, queue: [], models: new Map(), lastClient: null,
|
|
80
90
|
epoch: 0, stableAt: now(), successes: 0, readyToGrow: false, lastStableNotice: now(), pausedUntil: 0, reason: null, timer: null, completed: 0, rejected: 0 };
|
|
81
91
|
groups.set(identity, group);
|
|
82
92
|
}
|
|
@@ -116,7 +126,7 @@ export function createSourceAdmission({ now = Date.now, initialLimit = MAX_LIMIT
|
|
|
116
126
|
arm(group);
|
|
117
127
|
}
|
|
118
128
|
function feedback(group, entry, value) {
|
|
119
|
-
if (!value) return;
|
|
129
|
+
if (!value || entry.revision !== group.revision) return;
|
|
120
130
|
const until = now() + Math.min(7 * 86400000, value.delay);
|
|
121
131
|
const model = modelState(group, entry.model);
|
|
122
132
|
if (value.scope === "source") { group.pausedUntil = Math.max(group.pausedUntil, until);group.reason = value.kind; }
|
|
@@ -137,11 +147,12 @@ export function createSourceAdmission({ now = Date.now, initialLimit = MAX_LIMIT
|
|
|
137
147
|
arm(group);
|
|
138
148
|
}
|
|
139
149
|
class Lease {
|
|
140
|
-
constructor(group, model, client) { this.group = group;this.model = model;this.client = client;this.epoch = group.epoch;this.bytes = 0;this.released = false;this.observed = false; }
|
|
150
|
+
constructor(group, model, client, revision) { this.group = group;this.model = model;this.client = client;this.revision = revision;this.epoch = group.epoch;this.bytes = 0;this.released = false;this.observed = false; }
|
|
141
151
|
limit(value) { this.observed = true;feedback(this.group, this, value); }
|
|
142
152
|
streamFailure(error, headers) { const value = sourceLimitFeedback(429, headers, { error }, now());if (value?.kind !== "unknown") this.limit(value); }
|
|
143
153
|
observe(status, headers, body) {
|
|
144
154
|
const group = this.group, entry = this;
|
|
155
|
+
if (entry.revision !== group.revision) return;
|
|
145
156
|
if (!this.headersObserved) {
|
|
146
157
|
this.headersObserved = true;
|
|
147
158
|
const declared = headers?.get?.("x-ratelimit-concurrency-limit");
|
|
@@ -159,7 +170,7 @@ export function createSourceAdmission({ now = Date.now, initialLimit = MAX_LIMIT
|
|
|
159
170
|
release(success = false) {
|
|
160
171
|
if (this.released) return;this.released = true;
|
|
161
172
|
const group = this.group, entry = this, model = this.modelState;group.active--;if (model) model.active--;group.completed++;
|
|
162
|
-
if (success && !this.observed) {
|
|
173
|
+
if (success && !this.observed && entry.revision === group.revision) {
|
|
163
174
|
group.successes = Math.min(8, group.successes + 1);
|
|
164
175
|
const mature = group.successes >= 8 && now() - group.stableAt >= stableMs;
|
|
165
176
|
group.readyToGrow ||= mature;
|
|
@@ -192,7 +203,7 @@ export function createSourceAdmission({ now = Date.now, initialLimit = MAX_LIMIT
|
|
|
192
203
|
function acquire(descriptor, { signal, model = "unknown", client = "other", bytes, bodyText } = {}) {
|
|
193
204
|
if (closed) throw failure("ccdx_source_closed", "The source scheduler is stopping.");
|
|
194
205
|
if (signal?.aborted) throw abortError(signal);
|
|
195
|
-
const group = groupFor(descriptor), entry = new Lease(group, model, client);
|
|
206
|
+
const group = groupFor(descriptor), entry = new Lease(group, model, client, descriptor.revision);
|
|
196
207
|
if (!group.queue.length && fits(group, entry)) { entry.resolve = immediate;return activate(group, entry); }
|
|
197
208
|
const delay = Math.max(0, readyAt(group, entry) - now());
|
|
198
209
|
if (delay >= waitTimeoutMs) throw failure("ccdx_source_limited", "The source is limited. Retry after its recovery time.", delay, 429);
|
|
@@ -279,6 +290,20 @@ export function createSourceAdmission({ now = Date.now, initialLimit = MAX_LIMIT
|
|
|
279
290
|
}
|
|
280
291
|
return {
|
|
281
292
|
run,
|
|
293
|
+
registerDeployment(descriptor) {
|
|
294
|
+
const { source, account, revision } = descriptor;
|
|
295
|
+
if (!deployments.has(source) && deployments.size >= 64) deployments.delete(deployments.keys().next().value);
|
|
296
|
+
deployments.set(source, descriptor);
|
|
297
|
+
const identity = source + "\0" + account, group = groups.get(identity);
|
|
298
|
+
if (!group || group.revision === revision) return;
|
|
299
|
+
// Keep leases in the account pool while discarding evidence from the replaced endpoints.
|
|
300
|
+
const time = now();
|
|
301
|
+
Object.assign(group, { key: fingerprint(identity + "\0" + revision), revision, limit: initialLimit,
|
|
302
|
+
epoch: 0, stableAt: time, successes: 0, readyToGrow: false, lastStableNotice: time,
|
|
303
|
+
pausedUntil: 0, reason: null, advertised: undefined, advertisedUntil: 0 });
|
|
304
|
+
group.models.clear();
|
|
305
|
+
drain(group);
|
|
306
|
+
},
|
|
282
307
|
wrap(client, descriptor) {
|
|
283
308
|
if (!client || clients.has(client) || client[SOURCE_ADMISSION]?.scheduler === this) return clients.get(client) || client;
|
|
284
309
|
const wrapped = { ...client };
|
package/src/status-summary.mjs
CHANGED
|
@@ -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) {
|