codex-copilot-dx 1.3.21 → 1.3.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/docs/ARCHITECTURE.md +48 -1
- package/docs/REFERENCE.md +60 -2
- package/package.json +3 -2
- package/src/adapter.mjs +41 -10
- package/src/antigravity-chat-bridge.mjs +240 -0
- package/src/antigravity-handler.mjs +141 -0
- package/src/antigravity-images.mjs +28 -0
- package/src/antigravity-models.mjs +34 -0
- package/src/antigravity-runtime.mjs +72 -0
- package/src/carbon-search.mjs +37 -0
- package/src/carbon-tool-bridge.mjs +384 -0
- package/src/claude-gateway.mjs +40 -3
- package/src/cli-command-spec.mjs +2 -0
- package/src/cli-management.mjs +14 -1
- package/src/clients/codex-models.mjs +6 -2
- package/src/copilot-responses-compat.mjs +9 -1
- package/src/copilot-web-fetch.mjs +75 -0
- package/src/copilot-web.mjs +225 -0
- package/src/dashboard/console.js +1 -1
- package/src/dashboard/flow.js +2 -2
- package/src/dashboard/gemini.js +27 -0
- package/src/dashboard/index.html +14 -20
- package/src/dashboard/language.js +10 -0
- package/src/dashboard/status.js +4 -0
- package/src/dashboard/ui.js +3 -0
- package/src/dashboard-api.mjs +13 -0
- package/src/dashboard.mjs +17 -13
- package/src/gemini-app.mjs +34 -0
- package/src/http-transport.mjs +3 -2
- package/src/local-privacy.mjs +7 -1
- package/src/messages-tool-schema.mjs +155 -0
- package/src/native-images.mjs +2 -1
- package/src/observability.mjs +5 -1
- package/src/optional-routes.mjs +4 -0
- package/src/privacy-stream.mjs +2 -0
- package/src/privacy-transform.mjs +1 -0
- package/src/providers/api-network.mjs +1 -1
- package/src/providers/api.mjs +27 -3
- package/src/providers/github.mjs +8 -5
- package/src/proxy-tunnel.mjs +17 -1
- package/src/request-application.mjs +1 -1
- package/src/responses-bridge.mjs +74 -9
- package/src/responses-chat-payload.mjs +6 -5
- package/src/responses-handler.mjs +29 -6
- package/src/responses-tool-output.mjs +42 -0
- package/src/safe-upstream-error.mjs +8 -2
- package/src/stream-performance.mjs +1 -1
- package/src/terminal-state.mjs +6 -5
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { readSavedGithubToken } from "./auth-credentials.mjs";
|
|
2
|
+
import { githubTokenFingerprint } from "./github-identity.mjs";
|
|
3
|
+
import { httpError, readBoundedResponseText } from "./http-transport.mjs";
|
|
4
|
+
import { localPackageVersion } from "./version.mjs";
|
|
5
|
+
|
|
6
|
+
const trustedHosts = new Set(["api.githubcopilot.com", "api.enterprise.githubcopilot.com"]);
|
|
7
|
+
const unsupported = ["image_query", "literature_search_query", "screenshot", "finance", "weather", "sports", "time"];
|
|
8
|
+
|
|
9
|
+
function failure(message, code = "ccdx_copilot_search_unavailable", statusCode = 502) {
|
|
10
|
+
return Object.assign(httpError(message, statusCode), { code });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function url(value, base) {
|
|
14
|
+
try {
|
|
15
|
+
const parsed = new URL(value, base);
|
|
16
|
+
if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password) return null;
|
|
17
|
+
return parsed.href;
|
|
18
|
+
} catch { return null; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function domainMatch(host, domain) {
|
|
22
|
+
return host === domain || host.endsWith("." + domain);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function rpc(endpoint, headers, method, id, params, signal, session, fetchImpl) {
|
|
26
|
+
const response = await fetchImpl(endpoint, { method: "POST", redirect: "error", signal,
|
|
27
|
+
headers: { ...headers, ...(session ? { "Mcp-Session-Id": session } : {}) },
|
|
28
|
+
body: JSON.stringify({ jsonrpc: "2.0", ...(id ? { id } : {}), method, params }) });
|
|
29
|
+
const sessionId = response.headers.get("mcp-session-id");
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
await response.body?.cancel();
|
|
32
|
+
const error = failure("GitHub Copilot search was refused (HTTP " + response.status + ")", "ccdx_copilot_search_http", response.status);
|
|
33
|
+
const retryAfter = response.headers.get("retry-after");
|
|
34
|
+
if (retryAfter && /^(?:\d{1,8}|[A-Za-z0-9,: ]{10,40})$/.test(retryAfter)) error.retryAfter = retryAfter;
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
const raw = await readBoundedResponseText(response, { maxBytes: 4 * 1024 * 1024, signal, label: "Copilot search" });
|
|
38
|
+
if (!id) return { sessionId };
|
|
39
|
+
let value;
|
|
40
|
+
try { value = JSON.parse(raw); } catch {
|
|
41
|
+
for (const line of raw.split(/\r?\n/)) if (line.startsWith("data:")) {
|
|
42
|
+
try { const event = JSON.parse(line.slice(5).trim());if (event.id === id) value = event; } catch {}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!value || value.error || value.id !== id) throw failure("GitHub Copilot returned an invalid search response");
|
|
46
|
+
return { sessionId, value: value.result };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function copilotQuery(query, { endpoint, credential, signal, fetchImpl }) {
|
|
50
|
+
const headers = { Authorization: "Bearer " + credential, Accept: "application/json, text/event-stream",
|
|
51
|
+
"Content-Type": "application/json", "X-MCP-Toolsets": "web_search" };
|
|
52
|
+
const init = await rpc(endpoint, headers, "initialize", 1, {
|
|
53
|
+
protocolVersion: "2025-03-26", capabilities: {}, clientInfo: { name: "ccdx", version: localPackageVersion() },
|
|
54
|
+
}, signal, null, fetchImpl);
|
|
55
|
+
await rpc(endpoint, headers, "notifications/initialized", null, {}, signal, init.sessionId, fetchImpl);
|
|
56
|
+
const call = await rpc(endpoint, headers, "tools/call", 2, { name: "web_search", arguments: { query } }, signal, init.sessionId, fetchImpl);
|
|
57
|
+
if (call.value?.isError) throw failure("GitHub Copilot web search failed");
|
|
58
|
+
const texts = (call.value?.content || []).filter(item => item?.type === "text" && typeof item.text === "string");
|
|
59
|
+
let data;
|
|
60
|
+
for (const item of texts) {
|
|
61
|
+
try { const parsed = JSON.parse(item.text);if (Array.isArray(parsed.search_result_groups)) { data = parsed;break; } } catch {}
|
|
62
|
+
}
|
|
63
|
+
if (!data) throw failure("GitHub Copilot returned an unrecognized search result");
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function referenceStore() {
|
|
68
|
+
const sessions = new Map();
|
|
69
|
+
return {
|
|
70
|
+
session(id) {
|
|
71
|
+
let state = sessions.get(id);
|
|
72
|
+
if (!state) state = { next: 0, refs: new Map(), bytes: 0 };
|
|
73
|
+
sessions.delete(id);sessions.set(id, state);
|
|
74
|
+
if (sessions.size > 16) sessions.delete(sessions.keys().next().value);
|
|
75
|
+
return state;
|
|
76
|
+
},
|
|
77
|
+
add(state, key, value) {
|
|
78
|
+
const bytes = Buffer.byteLength(JSON.stringify(value));
|
|
79
|
+
const previous = state.refs.get(key);if (previous) state.bytes -= previous.bytes;
|
|
80
|
+
state.refs.delete(key);state.refs.set(key, { ...value, bytes });state.bytes += bytes;
|
|
81
|
+
while (state.refs.size > 128 || state.bytes > 1024 * 1024) {
|
|
82
|
+
const oldest = state.refs.keys().next().value;state.bytes -= state.refs.get(oldest).bytes;state.refs.delete(oldest);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
clear() { sessions.clear(); },
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function pageLinks(text, base) {
|
|
90
|
+
const links = [];
|
|
91
|
+
for (const match of text.matchAll(/\[([^\]\n]{1,200})\]\(([^)\s]+)(?:\s+"[^"]*")?\)/g)) {
|
|
92
|
+
const href = url(match[2], base);
|
|
93
|
+
if (href && links.length < 150) links.push({ title: match[1], url: href });
|
|
94
|
+
}
|
|
95
|
+
return links;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function createCopilotWeb({ client, query = copilotQuery, readToken = readSavedGithubToken, fetchImpl = fetch,
|
|
99
|
+
pageReader = async options => (await import("./copilot-web-fetch.mjs")).createCopilotPageReader(options) } = {}) {
|
|
100
|
+
const store = referenceStore();
|
|
101
|
+
async function search(body, { signal, providerProfile } = {}) {
|
|
102
|
+
if (typeof body.id !== "string" || !body.id || body.id.length > 160 || !body.commands || typeof body.commands !== "object"
|
|
103
|
+
|| Array.isArray(body.commands)) throw failure("Invalid Copilot search request", "ccdx_copilot_search_invalid", 400);
|
|
104
|
+
const commands = body.commands, filters = body.settings?.filters, access = body.settings?.external_web_access;
|
|
105
|
+
if (filters && (typeof filters !== "object" || Array.isArray(filters)
|
|
106
|
+
|| Object.keys(filters).some(key => !["allowed_domains", "blocked_domains"].includes(key))
|
|
107
|
+
|| Object.values(filters).some(value => !Array.isArray(value) || value.length))) {
|
|
108
|
+
throw failure("Copilot search cannot enforce configured domain policy", "ccdx_copilot_search_policy", 400);
|
|
109
|
+
}
|
|
110
|
+
if (access !== undefined && ![true, false, "cached", "indexed", "live"].includes(access)) {
|
|
111
|
+
throw failure("Unsupported web access mode", "ccdx_copilot_search_invalid", 400);
|
|
112
|
+
}
|
|
113
|
+
const queries = commands.search_query || [];
|
|
114
|
+
if (!Array.isArray(queries) || queries.length > 4) throw failure("Copilot supports at most four search queries", "ccdx_copilot_search_invalid", 400);
|
|
115
|
+
for (const name of ["open", "find", "click"]) if (commands[name] !== undefined && !Array.isArray(commands[name])) {
|
|
116
|
+
throw failure("Invalid Copilot page request", "ccdx_copilot_search_invalid", 400);
|
|
117
|
+
}
|
|
118
|
+
const credential = readToken();
|
|
119
|
+
if (!credential) throw failure("The GitHub Copilot sign-in is unavailable", "ccdx_copilot_search_auth", 401);
|
|
120
|
+
if (providerProfile?.startsWith("codex:") && providerProfile !== "codex:" + githubTokenFingerprint(credential)) {
|
|
121
|
+
throw failure("The GitHub sign-in changed; restart CCDX before searching", "ccdx_copilot_search_account_changed", 409);
|
|
122
|
+
}
|
|
123
|
+
await client.getCopilotToken({ signal });
|
|
124
|
+
const base = new URL(client.getApiBase());
|
|
125
|
+
if (base.protocol !== "https:" || !trustedHosts.has(base.hostname) || base.port || base.username || base.password) {
|
|
126
|
+
throw failure("The Copilot search host is not supported", "ccdx_copilot_search_host", 503);
|
|
127
|
+
}
|
|
128
|
+
const endpoint = new URL("/mcp/readonly", base);
|
|
129
|
+
const state = store.session(body.id), turn = state.next++, output = [], results = [];
|
|
130
|
+
let refIndex = 0;
|
|
131
|
+
for (const item of queries) {
|
|
132
|
+
if (!item || typeof item.q !== "string" || !item.q.trim() || item.q.length > 4096
|
|
133
|
+
|| item.domains !== undefined && (!Array.isArray(item.domains) || item.domains.some(d => typeof d !== "string" || !/^[a-z0-9.-]+$/i.test(d)))
|
|
134
|
+
|| item.recency !== undefined && (!Number.isSafeInteger(item.recency) || item.recency < 1)) {
|
|
135
|
+
throw failure("Invalid Copilot search query", "ccdx_copilot_search_invalid", 400);
|
|
136
|
+
}
|
|
137
|
+
const domains = (item.domains || []).map(value => value.toLowerCase().replace(/^\.+|\.+$/g, ""));
|
|
138
|
+
const constraints = [domains.length ? "Limit results to these domains: " + domains.join(", ") + "." : "",
|
|
139
|
+
item.recency ? "Prefer sources from the past " + item.recency + " days." : ""].filter(Boolean).join(" ");
|
|
140
|
+
const data = await query(item.q + (constraints ? "\n" + constraints : ""), { endpoint, credential, signal, fetchImpl });
|
|
141
|
+
output.push("GitHub Copilot search: " + item.q);
|
|
142
|
+
let count = 0;
|
|
143
|
+
for (const group of data.search_result_groups || []) {
|
|
144
|
+
for (const result of group.items || []) {
|
|
145
|
+
const href = url(result?.url);if (!href) continue;
|
|
146
|
+
const host = new URL(href).hostname.toLowerCase();
|
|
147
|
+
if (domains.length && !domains.some(domain => domainMatch(host, domain))) continue;
|
|
148
|
+
const updated = Date.parse(result.last_updated_date);
|
|
149
|
+
if (item.recency && Number.isFinite(updated) && updated < Date.now() - item.recency * 86400000) continue;
|
|
150
|
+
const title = typeof result.title === "string" ? result.title.slice(0, 400) : href;
|
|
151
|
+
const snippets = (Array.isArray(result.snippets) ? result.snippets : []).filter(value => typeof value === "string").join("\n").slice(0, 2500);
|
|
152
|
+
const ref = "turn" + turn + "search" + refIndex++;
|
|
153
|
+
store.add(state, ref, { url: href, snippets });
|
|
154
|
+
const dateNote = item.recency ? Number.isFinite(updated)
|
|
155
|
+
? " [last updated " + new Date(updated).toISOString().slice(0, 10) + "; publication date not verified]"
|
|
156
|
+
: " [publication date not verified]" : "";
|
|
157
|
+
output.push(title + " (" + href + ")\n【" + ref + "】" + dateNote
|
|
158
|
+
+ (snippets ? "\n" + snippets : ""));
|
|
159
|
+
results.push({ type: "text_result", ref_id: ref, url: href, title });count++;
|
|
160
|
+
if (count >= 10) break;
|
|
161
|
+
}
|
|
162
|
+
if (count >= 10) break;
|
|
163
|
+
}
|
|
164
|
+
if (!count) output.push("No matching Copilot search results.");
|
|
165
|
+
}
|
|
166
|
+
const pending = [];
|
|
167
|
+
for (const operation of commands.open || []) pending.push({ type: "open", operation });
|
|
168
|
+
for (const operation of commands.find || []) pending.push({ type: "find", operation });
|
|
169
|
+
for (const operation of commands.click || []) pending.push({ type: "click", operation });
|
|
170
|
+
if (pending.length > 8) throw failure("Copilot supports at most eight page operations", "ccdx_copilot_search_invalid", 400);
|
|
171
|
+
const pages = [];
|
|
172
|
+
for (const entry of pending) {
|
|
173
|
+
const op = entry.operation;
|
|
174
|
+
if (!op || typeof op.ref_id !== "string") throw failure("Invalid Copilot page request", "ccdx_copilot_search_invalid", 400);
|
|
175
|
+
if (entry.type === "open" && op.lineno !== undefined && (!Number.isSafeInteger(op.lineno) || op.lineno < 0)
|
|
176
|
+
|| entry.type === "click" && (!Number.isSafeInteger(op.id) || op.id < 0)) {
|
|
177
|
+
throw failure("Invalid Copilot page request", "ccdx_copilot_search_invalid", 400);
|
|
178
|
+
}
|
|
179
|
+
const stored = state.refs.get(op.ref_id);
|
|
180
|
+
let href = stored?.url || url(op.ref_id);
|
|
181
|
+
if (entry.type === "click") href = stored?.links?.[op.id]?.url || null;
|
|
182
|
+
if (!href) { output.push("Reference unavailable: " + op.ref_id);continue; }
|
|
183
|
+
if (entry.type === "find" && (typeof op.pattern !== "string" || !op.pattern)) throw failure("Invalid page search pattern", "ccdx_copilot_search_invalid", 400);
|
|
184
|
+
pages.push({ ...entry, href, stored });
|
|
185
|
+
}
|
|
186
|
+
const cachedOnly = access !== true && access !== "live";
|
|
187
|
+
if (pages.length && cachedOnly) {
|
|
188
|
+
for (const page of pages) {
|
|
189
|
+
const snippet = page.stored?.snippets;
|
|
190
|
+
if (!snippet) { output.push("Live page reading is unavailable in cached-only mode: " + page.href);continue; }
|
|
191
|
+
const match = page.type === "find" ? snippet.toLowerCase().includes(page.operation.pattern.toLowerCase()) : null;
|
|
192
|
+
output.push("Cached Copilot search excerpt (" + page.href + "):"
|
|
193
|
+
+ (match === null ? "" : match ? " Pattern found in excerpt." : " Pattern not found in excerpt; the full page was not searched.")
|
|
194
|
+
+ "\n" + snippet);
|
|
195
|
+
}
|
|
196
|
+
} else if (pages.length) {
|
|
197
|
+
const reader = await pageReader({ credential, urls: pages.map(page => page.href), signal });
|
|
198
|
+
try {
|
|
199
|
+
for (const page of pages) {
|
|
200
|
+
const text = await reader.read(page.href);
|
|
201
|
+
const ref = "turn" + turn + "view" + refIndex++, links = pageLinks(text, page.href);
|
|
202
|
+
store.add(state, ref, { url: page.href, links });
|
|
203
|
+
const lines = text.split("\n");
|
|
204
|
+
if (page.type === "find") {
|
|
205
|
+
const at = lines.findIndex(line => line.toLowerCase().includes(page.operation.pattern.toLowerCase()));
|
|
206
|
+
output.push(at < 0 ? "Pattern not found in the retrieved page excerpt: " + page.href
|
|
207
|
+
: page.href + "\n【" + ref + "】\n" + lines.slice(Math.max(0, at - 2), at + 3).map((line, i) => "L" + (Math.max(0, at - 2) + i + 1) + ": " + line).join("\n"));
|
|
208
|
+
} else {
|
|
209
|
+
const start = Number.isSafeInteger(page.operation.lineno) ? Math.max(0, page.operation.lineno - 1) : 0;
|
|
210
|
+
output.push(page.href + "\n【" + ref + "】\n"
|
|
211
|
+
+ (start >= lines.length ? "Requested line is outside the retrieved page excerpt." : lines.slice(start, start + 200).map((line, i) => "L" + (start + i + 1) + ": " + line).join("\n"))
|
|
212
|
+
+ (links.length ? "\nLinks:\n" + links.map((link, index) => "【" + index + "†" + link.title + "】 " + link.url).join("\n") : ""));
|
|
213
|
+
}
|
|
214
|
+
results.push({ type: "text_result", ref_id: ref, url: page.href, title: page.href });
|
|
215
|
+
}
|
|
216
|
+
} finally { await reader.close(); }
|
|
217
|
+
}
|
|
218
|
+
for (const name of unsupported) if (Array.isArray(commands[name]) && commands[name].length) {
|
|
219
|
+
output.push("Copilot search does not support " + name + " in this preview.");
|
|
220
|
+
}
|
|
221
|
+
if (!output.length) output.push("No supported Copilot search operation was requested.");
|
|
222
|
+
return Response.json({ output: output.join("\n\n"), results });
|
|
223
|
+
}
|
|
224
|
+
return { search, close: () => store.clear() };
|
|
225
|
+
}
|
package/src/dashboard/console.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const el = id => document.getElementById(id);
|
|
3
3
|
const label = (node, key, values = {}) => globalThis.ccdxLanguage.set(node, key, values);
|
|
4
|
-
const titles = { overview: "overview", codex: "Codex", claude: "Claude", models: "model_services", usage: "usage_and_diagnostics", requests: "request_records", checks: "tools_checks_title", system: "system_and_settings" };
|
|
4
|
+
const titles = { overview: "overview", codex: "Codex", claude: "Claude", gemini: "Gemini", models: "model_services", usage: "usage_and_diagnostics", requests: "request_records", checks: "tools_checks_title", system: "system_and_settings" };
|
|
5
5
|
const settingsViews = ["codex", "claude", "models", "system", "checks"];
|
|
6
6
|
let current = "overview", settings = null, settingsPending = false, stopped = false, timer = null, ticks = 0;
|
|
7
7
|
let sourceDirty = false, reviewDirty = false, sourceModels = [], modelsPreference = null, sourceGeneration = 0, modelsSource = null;
|
package/src/dashboard/flow.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const root = document.getElementById("request-flow");
|
|
3
3
|
if (!root) return;
|
|
4
4
|
const el = id => document.getElementById(id), ns = "http://www.w3.org/2000/svg";
|
|
5
|
-
const clients = new Set(["codex_app", "codex_cli", "codex", "claude_app", "claude_code", "claude", "api"]);
|
|
5
|
+
const clients = new Set(["codex_app", "codex_cli", "codex", "claude_app", "claude_code", "claude", "gemini_app", "api"]);
|
|
6
6
|
const label = (node, key, values = {}) => globalThis.ccdxLanguage.set(node, key, values);
|
|
7
7
|
const format = (key, values = {}) => globalThis.ccdxLanguage.format(key, values);
|
|
8
8
|
const nodes = { apps: new Map(), models: new Map() };
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
if (!map.has(id)) map.set(id, { id, provider: row.provider, model: row.model, rows: [] });
|
|
45
45
|
map.get(id).rows.push(row);
|
|
46
46
|
}
|
|
47
|
-
const order = ["codex_app", "codex_cli", "codex", "claude_code", "claude_app", "claude", "api"];
|
|
47
|
+
const order = ["codex_app", "codex_cli", "codex", "claude_code", "claude_app", "claude", "gemini_app", "api"];
|
|
48
48
|
return [...map.values()].sort((a, b) => type === "apps" ? order.indexOf(a.id) - order.indexOf(b.id) : a.id.localeCompare(b.id));
|
|
49
49
|
}
|
|
50
50
|
function project(type, groups) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const el=id=>document.getElementById(id),language=globalThis.ccdxLanguage;
|
|
3
|
+
let busy=false;
|
|
4
|
+
const words=(id,key)=>language.set(el(id),key);
|
|
5
|
+
async function load(action){
|
|
6
|
+
if(busy)return;busy=true;
|
|
7
|
+
for(const id of ["gemini-enable","gemini-disable","gemini-open","gemini-refresh"])el(id).disabled=true;
|
|
8
|
+
try{
|
|
9
|
+
const response=await fetch("/_ccdx/ui/gemini",{method:action?"POST":"GET",headers:{"X-CCDX-Dashboard":"1",...(action?{"Content-Type":"application/json"}:{})},
|
|
10
|
+
cache:"no-store",signal:AbortSignal.timeout(20000),...(action?{body:JSON.stringify({action,...(action==="enable"?{accept_background_copilot:true}:{})})}:{})});
|
|
11
|
+
const state=await response.json();if(!response.ok)throw new Error(state.error||"Gemini setup failed");
|
|
12
|
+
globalThis.ccdxGeminiStatus=state;window.dispatchEvent(new Event("ccdx-gemini-state"));
|
|
13
|
+
words("gemini-state",state.enabled?"gemini_enabled":"gemini_disabled");
|
|
14
|
+
el("gemini-version").textContent=state.app.version||"—";
|
|
15
|
+
words("gemini-app-state",state.app.status==="running"?"gemini_running":state.app.status==="stopped"?"gemini_stopped":state.app.status==="starting"?"gemini_starting":"gemini_unavailable");
|
|
16
|
+
el("gemini-reopen").hidden=state.app.status!=="running";
|
|
17
|
+
const list=el("gemini-models");list.replaceChildren();for(const model of state.models){const item=document.createElement("li");item.textContent=model.name;list.append(item)}
|
|
18
|
+
const status=state.last_operation?.status;
|
|
19
|
+
const notice=status==="needs_app_relaunch"?"gemini_reopen":status==="opened"?"gemini_opened":status==="route_conflict"?"gemini_conflict":null;
|
|
20
|
+
if(notice)words("gemini-note",notice);else el("gemini-note").textContent="";
|
|
21
|
+
}catch(error){el("gemini-note").textContent=error.message}
|
|
22
|
+
finally{busy=false;for(const id of ["gemini-enable","gemini-disable","gemini-open","gemini-refresh"])el(id).disabled=false}
|
|
23
|
+
}
|
|
24
|
+
for(const action of ["enable","disable","open"])el("gemini-"+action).addEventListener("click",()=>void load(action));
|
|
25
|
+
el("gemini-refresh").addEventListener("click",()=>void load());
|
|
26
|
+
const navigate=()=>{if(location.hash==="#gemini")void load()};window.addEventListener("hashchange",navigate);navigate();
|
|
27
|
+
})();
|
package/src/dashboard/index.html
CHANGED
|
@@ -8,26 +8,7 @@
|
|
|
8
8
|
<script src="/language.js"></script>
|
|
9
9
|
<script src="/theme.js"></script>
|
|
10
10
|
<link rel="stylesheet" href="/ui.css">
|
|
11
|
-
<script src="/
|
|
12
|
-
<script src="/live.js" defer></script>
|
|
13
|
-
<script src="/icons.js" defer></script>
|
|
14
|
-
<script src="/disclosure.js" defer></script>
|
|
15
|
-
<script src="/time.js" defer></script>
|
|
16
|
-
<script src="/view-boundary.js" defer></script>
|
|
17
|
-
<script src="/status.js" defer></script>
|
|
18
|
-
<script src="/activity.js" defer></script>
|
|
19
|
-
<script src="/flow.js" defer></script>
|
|
20
|
-
<script src="/usage.js" defer></script>
|
|
21
|
-
<script src="/context.js" defer></script>
|
|
22
|
-
<script src="/updates.js" defer></script>
|
|
23
|
-
<script src="/animation.js" defer></script>
|
|
24
|
-
<script src="/ui.js" defer></script>
|
|
25
|
-
<script src="/preferences.js" defer></script>
|
|
26
|
-
<script src="/features.js" defer></script>
|
|
27
|
-
<script src="/console.js" defer></script>
|
|
28
|
-
<script src="/tools.js" defer></script>
|
|
29
|
-
<script src="/connections.js" defer></script>
|
|
30
|
-
<script src="/privacy.js" defer></script>
|
|
11
|
+
<script src="/dashboard.js" defer></script>
|
|
31
12
|
<title data-i18n="ccdx_local_dashboard">CCDX · Dashboard</title>
|
|
32
13
|
</head>
|
|
33
14
|
<body>
|
|
@@ -39,6 +20,7 @@
|
|
|
39
20
|
<span class="nav-group" data-i18n="clients">Apps</span>
|
|
40
21
|
<a class="nav-child" href="#codex" data-route="codex"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="m7 8 4 4-4 4m7 0h3"/></svg><span>Codex</span></a>
|
|
41
22
|
<a class="nav-child" href="#claude" data-route="claude"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M21 15a3 3 0 0 1-3 3H8l-5 3V6a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3Z"/></svg><span>Claude</span></a>
|
|
23
|
+
<a class="nav-child" href="#gemini" data-route="gemini"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2c1 6 4 9 10 10-6 1-9 4-10 10C11 16 8 13 2 12c6-1 9-4 10-10Z"/></svg><span>Gemini</span></a>
|
|
42
24
|
<a href="#models" data-route="models"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m12 3 10 5-10 5L2 8Zm-10 9 10 5 10-5M2 16l10 5 10-5"/></svg><span data-i18n="model_services">Model sources</span></a>
|
|
43
25
|
<a href="#usage" data-route="usage"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M3 3v18h18M7 16v-5m5 5V7m5 9V4"/></svg><span data-i18n="usage_and_diagnostics">Usage</span></a>
|
|
44
26
|
<a href="#requests" data-route="requests"><svg class="nav-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"/></svg><span data-i18n="request_records">Requests</span></a>
|
|
@@ -180,6 +162,18 @@
|
|
|
180
162
|
<a class="section-link" href="#requests" data-i18n="view_request_details">View request details</a>
|
|
181
163
|
</details>
|
|
182
164
|
</div>
|
|
165
|
+
<div data-view="gemini" hidden>
|
|
166
|
+
<section class="panel dashboard-section">
|
|
167
|
+
<h2>Gemini · Antigravity</h2>
|
|
168
|
+
<p id="gemini-state" data-i18n="gemini_disabled">Copilot integration is off</p>
|
|
169
|
+
<p id="gemini-app-state">—</p><p><span data-i18n="gemini_version">Version</span>: <span id="gemini-version">—</span></p>
|
|
170
|
+
<p class="hint" data-i18n="gemini_scope">Antigravity summaries, searches and image generation use Copilot. Ordinary Gemini chat keeps Google.</p>
|
|
171
|
+
<div class="connection-actions"><button id="gemini-enable" type="button" data-i18n="gemini_enable">Enable Antigravity</button><button id="gemini-disable" type="button" data-i18n="gemini_disable">Pause Copilot</button><button id="gemini-open" type="button" data-i18n="gemini_open">Open Gemini</button><button id="gemini-refresh" type="button" data-i18n="refresh">Refresh</button></div>
|
|
172
|
+
<p id="gemini-reopen" class="hint" data-i18n="gemini_reopen" hidden>Quit Gemini, then open it here. Active apps are never restarted automatically.</p>
|
|
173
|
+
<ul id="gemini-models"></ul><p id="gemini-note" class="hint" role="status"></p>
|
|
174
|
+
</section>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
183
177
|
<div data-view="models" hidden>
|
|
184
178
|
<section class="panel dashboard-section" id="connection-sources">
|
|
185
179
|
<div class="panel-heading"><h2 data-i18n="source_accounts">Accounts & APIs</h2><button id="connection-add" type="button" data-i18n="api_add">Add API</button></div>
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const translations = {
|
|
3
|
+
gemini_version: ["Version", "版本"],
|
|
4
|
+
gemini_enabled: ["Copilot integration is on", "Copilot 接入已启用"], gemini_disabled: ["Copilot integration is off", "Copilot 接入未启用"],
|
|
5
|
+
gemini_scope: ["Antigravity summaries, searches and image generation use Copilot. Ordinary Gemini chat keeps Google.", "Antigravity 的摘要、搜索和图像生成使用 Copilot;Gemini 普通聊天保留 Google。"],
|
|
6
|
+
gemini_enable: ["Enable Antigravity", "启用 Antigravity"], gemini_disable: ["Pause Copilot", "停用 Copilot"], gemini_open: ["Open Gemini", "打开 Gemini"],
|
|
7
|
+
gemini_reopen: ["Quit Gemini, then open it here. Active apps are never restarted automatically.", "请先退出 Gemini,再从这里打开。CCDX 不会自动重启正在运行的应用。"],
|
|
8
|
+
gemini_opened: ["Gemini opened. Route adoption awaits an Antigravity request.", "已打开 Gemini,等待 Antigravity 请求确认接入。"],
|
|
9
|
+
gemini_starting: ["Gemini is starting", "Gemini 正在启动"],
|
|
10
|
+
gemini_conflict: ["An existing gateway route was preserved. Resolve the conflict before opening.", "已保留原有网关路由,请先处理配置冲突。"],
|
|
11
|
+
gemini_running: ["Gemini is running", "Gemini 正在运行"], gemini_stopped: ["Gemini is closed", "Gemini 已退出"], gemini_unavailable: ["Gemini installation could not be verified", "尚未确认 Gemini 安装状态"],
|
|
3
12
|
limit_default: ["Use default", "使用默认值"],
|
|
4
13
|
ccdx_prediction_app_open: ["Quit Codex, then continue setup here.", "请退出 Codex,再在此继续配置。"], feature_read_failed: ["Settings could not be read. Existing files were preserved.", "无法读取设置,原有文件已保留。"],
|
|
5
14
|
prediction_setup_again: ["Set up again", "重新配置"], prediction_bridge_missing: ["Not ready. Check and repair, or quit Codex and set up again.", "尚未就绪。请检查修复,或退出 Codex 后重新配置。"],
|
|
@@ -472,6 +481,7 @@
|
|
|
472
481
|
"flow_app_codex_cli": ["Codex CLI", "Codex CLI"],
|
|
473
482
|
"flow_app_claude_app": ["Claude App", "Claude App"],
|
|
474
483
|
"flow_app_claude_code": ["Claude Code", "Claude Code"],
|
|
484
|
+
"flow_app_gemini_app": ["Gemini · Antigravity", "Gemini · Antigravity"],
|
|
475
485
|
"flow_app_claude": ["Claude (app unspecified)", "Claude(未区分应用)"],
|
|
476
486
|
"flow_app_api": ["Unidentified app", "未识别应用"],
|
|
477
487
|
"flow_source_unknown": ["Source unknown", "来源未知"],
|
package/src/dashboard/status.js
CHANGED
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
claudeClients?.append(detail);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
if (data.gemini || globalThis.ccdxGeminiStatus) {
|
|
77
|
+
const gemini=data.gemini || globalThis.ccdxGeminiStatus;
|
|
78
|
+
clients.append(tableRow(["Gemini · Antigravity",gemini.enabled?"Google + Copilot":"Google",gemini.enabled?"configured":"access_paused",gemini.activity?.active>0?"active":gemini.route_observed?"observed":"unknown","—"],{labels:[2,3]}));
|
|
79
|
+
}
|
|
76
80
|
if (element("claude-client-state")) element("claude-client-state").hidden = Boolean(claudeClients?.children.length);
|
|
77
81
|
text("source-summary", "count_providers", { count: providers.length });
|
|
78
82
|
element("source-detail").replaceChildren(...providers.map(provider => {
|
package/src/dashboard/ui.js
CHANGED
|
@@ -26,6 +26,9 @@ const loadAuth = () => dashboardRefresh.refresh("auth", { force: true });
|
|
|
26
26
|
const statusResourceKey = () => ["codex", "claude", "models", "usage", "requests", "checks"].includes((globalThis.location?.hash || "").slice(1)) ? "status" : "status-summary";
|
|
27
27
|
const refreshStatus = () => dashboardRefresh.refresh(statusResourceKey(), { force: true });
|
|
28
28
|
const refresh = refreshStatus;
|
|
29
|
+
globalThis.addEventListener?.("ccdx-gemini-state", () => {
|
|
30
|
+
const auth=dashboardRefresh.state("auth").value;if(auth)renderProviders({...auth,gemini:globalThis.ccdxGeminiStatus});
|
|
31
|
+
});
|
|
29
32
|
|
|
30
33
|
function animateLogo() {
|
|
31
34
|
const icon = element("status-icon");
|
package/src/dashboard-api.mjs
CHANGED
|
@@ -154,6 +154,7 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
154
154
|
providerStateFn,
|
|
155
155
|
providerAccountsFn,
|
|
156
156
|
connectionsFn,
|
|
157
|
+
geminiFn,
|
|
157
158
|
contextSnapshotFn,
|
|
158
159
|
updateStatusFn,
|
|
159
160
|
serviceControl,
|
|
@@ -171,6 +172,18 @@ export async function handleDashboardApi(req, res, pathname, {
|
|
|
171
172
|
sendJson(res, 403, { error: "Dashboard API requires a same-origin page request" });
|
|
172
173
|
return;
|
|
173
174
|
}
|
|
175
|
+
if (pathname === "/_ccdx/ui/gemini") {
|
|
176
|
+
if (!geminiFn) { sendJson(res, 503, { error: "Gemini integration is unavailable" });return; }
|
|
177
|
+
if (req.headers.origin && !sameOrigin(req)) { sendJson(res, 403, { error: "Gemini setup requires the same-origin dashboard" });return; }
|
|
178
|
+
if (!["GET", "POST"].includes(req.method)) { sendJson(res, 405, { error: "Use GET or POST" });return; }
|
|
179
|
+
if (req.method === "POST" && (!sameOrigin(req) || !/^application\/json(?:\s*;|$)/i.test(req.headers["content-type"] || ""))) { sendJson(res, 403, { error: "Gemini setup requires same-origin JSON" });return; }
|
|
180
|
+
const abort = createRequestAbort(req, res);abort.setTimeout(5000, "request_body_timeout");
|
|
181
|
+
try {
|
|
182
|
+
const input = req.method === "POST" ? await readJsonBody(req, { maxBodyBytes: 8192, maxDecodedBodyBytes: 8192, signal: abort.signal }) : {};
|
|
183
|
+
abort.clearTimeout();sendJson(res, 200, await geminiFn(input, `http://${req.headers.host}`));
|
|
184
|
+
} catch (error) { sendJson(res, error.statusCode || 400, { error: error.message }); }
|
|
185
|
+
finally { abort.cleanup(); }return;
|
|
186
|
+
}
|
|
174
187
|
|
|
175
188
|
if (pathname === "/_ccdx/ui/privacy") {
|
|
176
189
|
if (!privacy) { sendJson(res, 503, { code: "ccdx_privacy_unavailable" });return; }
|
package/src/dashboard.mjs
CHANGED
|
@@ -4,17 +4,14 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import { ADAPTER_VERSION } from "./running-adapter.mjs";
|
|
5
5
|
|
|
6
6
|
const ASSETS = new Map([
|
|
7
|
-
["/privacy.js", ["./dashboard/privacy.js", "text/javascript; charset=utf-8"]],
|
|
8
7
|
["/", ["./dashboard/index.html", "text/html; charset=utf-8"]],
|
|
9
8
|
["/ui.css", ["./dashboard/ui.css", "text/css; charset=utf-8"]],
|
|
10
|
-
["/theme.js", ["./dashboard/theme.js", "text/javascript; charset=utf-8"]],
|
|
11
9
|
["/language.js", ["./dashboard/language.js", "text/javascript; charset=utf-8"]],
|
|
12
|
-
["/
|
|
13
|
-
["/
|
|
14
|
-
["/
|
|
15
|
-
["/
|
|
16
|
-
["/
|
|
17
|
-
["/preferences.js", ["./dashboard/preferences.js", "text/javascript; charset=utf-8"]],
|
|
10
|
+
["/theme.js", ["./dashboard/theme.js", "text/javascript; charset=utf-8"]],
|
|
11
|
+
["/refresh.js", ["./dashboard/refresh.js", "text/javascript; charset=utf-8"]],
|
|
12
|
+
["/live.js", ["./dashboard/live.js", "text/javascript; charset=utf-8"]],
|
|
13
|
+
["/icons.js", ["./dashboard/icons.js", "text/javascript; charset=utf-8"]],
|
|
14
|
+
["/disclosure.js", ["./dashboard/disclosure.js", "text/javascript; charset=utf-8"]],
|
|
18
15
|
["/time.js", ["./dashboard/time.js", "text/javascript; charset=utf-8"]],
|
|
19
16
|
["/view-boundary.js", ["./dashboard/view-boundary.js", "text/javascript; charset=utf-8"]],
|
|
20
17
|
["/status.js", ["./dashboard/status.js", "text/javascript; charset=utf-8"]],
|
|
@@ -22,12 +19,16 @@ const ASSETS = new Map([
|
|
|
22
19
|
["/flow.js", ["./dashboard/flow.js", "text/javascript; charset=utf-8"]],
|
|
23
20
|
["/usage.js", ["./dashboard/usage.js", "text/javascript; charset=utf-8"]],
|
|
24
21
|
["/context.js", ["./dashboard/context.js", "text/javascript; charset=utf-8"]],
|
|
25
|
-
["/
|
|
26
|
-
["/
|
|
27
|
-
["/
|
|
28
|
-
["/
|
|
22
|
+
["/updates.js", ["./dashboard/updates.js", "text/javascript; charset=utf-8"]],
|
|
23
|
+
["/animation.js", ["./dashboard/animation.js", "text/javascript; charset=utf-8"]],
|
|
24
|
+
["/ui.js", ["./dashboard/ui.js", "text/javascript; charset=utf-8"]],
|
|
25
|
+
["/preferences.js", ["./dashboard/preferences.js", "text/javascript; charset=utf-8"]],
|
|
26
|
+
["/features.js", ["./dashboard/features.js", "text/javascript; charset=utf-8"]],
|
|
27
|
+
["/console.js", ["./dashboard/console.js", "text/javascript; charset=utf-8"]],
|
|
29
28
|
["/tools.js", ["./dashboard/tools.js", "text/javascript; charset=utf-8"]],
|
|
30
29
|
["/connections.js", ["./dashboard/connections.js", "text/javascript; charset=utf-8"]],
|
|
30
|
+
["/privacy.js", ["./dashboard/privacy.js", "text/javascript; charset=utf-8"]],
|
|
31
|
+
["/gemini.js", ["./dashboard/gemini.js", "text/javascript; charset=utf-8"]],
|
|
31
32
|
]);
|
|
32
33
|
let bundle;
|
|
33
34
|
function assets() {
|
|
@@ -38,7 +39,10 @@ function assets() {
|
|
|
38
39
|
})).then(async entries => {
|
|
39
40
|
const installed = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
|
|
40
41
|
if (installed.version !== ADAPTER_VERSION) throw new Error("Dashboard files changed; restart CCDX before loading the new dashboard");
|
|
41
|
-
|
|
42
|
+
// Shared globals and their consumers execute together, without partial script loading.
|
|
43
|
+
const scripts = entries.filter(([name, asset]) => asset.type.startsWith("text/javascript") && !["/language.js", "/theme.js"].includes(name));
|
|
44
|
+
const body = Buffer.concat(scripts.flatMap(([name, asset]) => [Buffer.from("// " + name + "\n"), asset.body, Buffer.from("\n;\n")]));
|
|
45
|
+
return new Map([...entries, ["/dashboard.js", { body, type: "text/javascript; charset=utf-8", etag: `"${createHash("sha256").update(body).digest("hex")}"` }]]);
|
|
42
46
|
}).catch(error => { bundle = null;throw error; });
|
|
43
47
|
return bundle;
|
|
44
48
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {execFile} from "node:child_process";
|
|
4
|
+
import {promisify} from "node:util";
|
|
5
|
+
|
|
6
|
+
const execute=promisify(execFile);
|
|
7
|
+
|
|
8
|
+
export async function inspectGeminiApp({platform=process.platform,app="/Applications/Gemini.app",exec=execute,exists=fs.existsSync}={}) {
|
|
9
|
+
if(platform!=="darwin")return {status:"unsupported"};
|
|
10
|
+
const metadata=path.join(app,"Contents/Info.plist");
|
|
11
|
+
if(!exists(metadata))return {status:"not_installed"};
|
|
12
|
+
const result=await exec("/usr/bin/plutil",["-convert","json","-o","-",metadata],{encoding:"utf8",timeout:3000,maxBuffer:65536});
|
|
13
|
+
const info=JSON.parse(String(result.stdout??result));
|
|
14
|
+
if(info.CFBundleIdentifier!=="com.google.GeminiMacOS"||info.CFBundleExecutable!=="Gemini")throw new Error("Unrecognized Gemini App identity");
|
|
15
|
+
const helper=path.join(app,"Contents/Helpers/agy");
|
|
16
|
+
if(!exists(helper))return {status:"antigravity_unavailable"};
|
|
17
|
+
await exec("/usr/bin/codesign",["--verify","--deep","--strict","-R",'=identifier "com.google.GeminiMacOS" and anchor apple generic',app],{encoding:"utf8",timeout:15000,maxBuffer:65536});
|
|
18
|
+
const executable=path.join(app,"Contents/MacOS/Gemini");
|
|
19
|
+
const processes=await exec("/bin/ps",["-axo","pid=,comm="],{encoding:"utf8",timeout:3000,maxBuffer:4*1024*1024});
|
|
20
|
+
const pids=String(processes.stdout??processes).split("\n").flatMap(line=>{const match=/^\s*(\d+)\s+(.+?)\s*$/.exec(line);return match?.[2]===executable?[Number(match[1])]:[]});
|
|
21
|
+
return {status:pids.length>1?"multiple":pids.length?"running":"stopped",app,executable,helper,version:info.CFBundleShortVersionString,pids};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// A launch plan is reviewable without changing files, credentials, or running apps.
|
|
25
|
+
// A prepared environment is not evidence that the App has adopted the route.
|
|
26
|
+
export function planGeminiAppLaunch(state,{cloudCodeUrl,env=process.env,managedGateway=false}={}) {
|
|
27
|
+
if(!["running","stopped","multiple"].includes(state?.status))return {status:state?.status||"unknown"};
|
|
28
|
+
if(state.status==="stopped"&&state.app!=="/Applications/Gemini.app")throw new Error("Unrecognized Gemini App location");
|
|
29
|
+
const url=new URL(cloudCodeUrl);
|
|
30
|
+
if(url.protocol!=="http:"||url.hostname!=="127.0.0.1"||!url.port||Number(url.port)<1||url.username||url.password||url.search||url.hash)throw new Error("Gemini route must use a local CCDX endpoint");
|
|
31
|
+
if(managedGateway||Object.entries(env).some(([key,value])=>key.startsWith("AGY_LLM_GATEWAY_")&&value)||env.CLOUD_CODE_URL&&env.CLOUD_CODE_URL!==url.href)return {status:"route_conflict"};
|
|
32
|
+
if(state.status!=="stopped")return {status:state.status==="multiple"?"multiple":"needs_app_relaunch",pids:[...state.pids]};
|
|
33
|
+
return {status:"prepared",command:"/usr/bin/open",args:["-a",state.app,"--env","CLOUD_CODE_URL="+url.href]};
|
|
34
|
+
}
|
package/src/http-transport.mjs
CHANGED
|
@@ -193,11 +193,12 @@ export async function readJsonBody(req, {
|
|
|
193
193
|
maxBodyBytes = MAX_BODY_BYTES,
|
|
194
194
|
maxDecodedBodyBytes = MAX_DECODED_BODY_BYTES,
|
|
195
195
|
signal,
|
|
196
|
+
parse = parseRequestJson,
|
|
196
197
|
} = {}) {
|
|
197
198
|
if (signal?.aborted) throw admissionAbortError(signal);
|
|
198
199
|
const encodings = contentEncodings(req.headers?.["content-encoding"]);
|
|
199
200
|
if (encodings.every((encoding) => encoding === "identity")) {
|
|
200
|
-
return
|
|
201
|
+
return parse(await readIdentityText(req, maxBodyBytes, maxDecodedBodyBytes, signal));
|
|
201
202
|
}
|
|
202
203
|
const buffer = await readRequestBuffer(req, maxBodyBytes, signal);
|
|
203
204
|
let releaseDecompression = () => {};
|
|
@@ -251,7 +252,7 @@ export async function readJsonBody(req, {
|
|
|
251
252
|
if (supportsResizableReservation) decodedReservation.resize(decoded.length);
|
|
252
253
|
else decodedReservation = await admission?.reserveDecodedBody?.(decoded.length, { signal });
|
|
253
254
|
}
|
|
254
|
-
const parsed =
|
|
255
|
+
const parsed = parse(decoded.toString("utf8"));
|
|
255
256
|
retainDecodedReservation = true;
|
|
256
257
|
return parsed;
|
|
257
258
|
} finally {
|
package/src/local-privacy.mjs
CHANGED
|
@@ -43,7 +43,7 @@ export function createLocalPrivacy(options = {}) {
|
|
|
43
43
|
});changes.changed();
|
|
44
44
|
}
|
|
45
45
|
const find = (texts, options) => detection.find(texts, options);
|
|
46
|
-
async function prepare(body, { protocol, client, signal, res, policy } = {}) {
|
|
46
|
+
async function prepare(body, { protocol, client, signal, res, policy, onSession } = {}) {
|
|
47
47
|
const saved = policy || settings();if (!saved.enabled) return body;
|
|
48
48
|
if (disposed) throw privacyFailure("engine_unavailable");
|
|
49
49
|
loadKey();
|
|
@@ -72,6 +72,7 @@ export function createLocalPrivacy(options = {}) {
|
|
|
72
72
|
if (signal?.aborted) { session.release();throw signal.reason; }
|
|
73
73
|
markRequestObservation({ privacy_count: session.count, privacy_ms: Math.round(performance.now() - start), privacy_state: "checked" });
|
|
74
74
|
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();
|
|
75
|
+
if (onSession) { onSession(session);return session.body; }
|
|
75
76
|
if (res && session.count) {
|
|
76
77
|
let current = responses.get(res);
|
|
77
78
|
if (!current) {
|
|
@@ -119,6 +120,11 @@ export function createLocalPrivacy(options = {}) {
|
|
|
119
120
|
function warm() { const current = generation;if (settings().enabled) void model.load().catch(error => { if (current !== generation || !settings().enabled) return;actionError = /^ccdx_privacy_[a-z_]+$/.test(error.code || "") ? error.code : "ccdx_privacy_unavailable";changes.changed(); }); }
|
|
120
121
|
try { warm(); } catch { /* Invalid preferences remain visible and are never rewritten. */ }
|
|
121
122
|
return { snapshot, action, prepare, subscribe: changes.subscribe, busy: () => Boolean(pending || detection.busy() || model.busy()),
|
|
123
|
+
async prepareSession(body, context) {
|
|
124
|
+
let session;
|
|
125
|
+
const masked = await prepare(body, { ...context, onSession: value => { session = value; } });
|
|
126
|
+
return session || { body: masked, count: 0, restoreText: value => value, restoreValue: value => value, restoreToolValue: value => value, release() {} };
|
|
127
|
+
},
|
|
122
128
|
wrap(fn, context) {
|
|
123
129
|
if (!fn) return fn;
|
|
124
130
|
const policy = context.res && policies.get(context.res) || settings();if (context.res) policies.set(context.res, policy);
|