codex-copilot-dx 1.3.27 → 1.4.0
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 +7 -2
- package/bin/cli.mjs +4 -1
- package/docs/ARCHITECTURE.md +32 -3
- package/docs/REFERENCE.md +51 -5
- package/package.json +1 -1
- package/src/adapter.mjs +17 -5
- package/src/antigravity-handler.mjs +38 -13
- package/src/antigravity-runtime.mjs +22 -2
- package/src/claude-app-contract.mjs +96 -0
- package/src/claude-capability-config.mjs +28 -11
- package/src/claude-client-config.mjs +58 -9
- package/src/claude-gateway.mjs +25 -7
- package/src/claude-models.mjs +4 -2
- package/src/cli-command-spec.mjs +13 -3
- package/src/cli-management.mjs +47 -6
- package/src/cli-options.mjs +1 -1
- package/src/connection-client-sync.mjs +1 -0
- package/src/connection-management.mjs +5 -0
- package/src/connection-policy.mjs +2 -2
- package/src/connection-routing.mjs +3 -1
- package/src/connection-runtime.mjs +37 -2
- package/src/connection-view.mjs +11 -2
- 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 +1 -1
- package/src/conversation-source-guard.mjs +15 -5
- package/src/dashboard/connections.js +33 -3
- package/src/dashboard/index.html +9 -1
- package/src/dashboard/language.js +28 -0
- package/src/dashboard/preferences.js +1 -1
- package/src/dashboard/ui.js +3 -0
- package/src/dashboard-api.mjs +2 -2
- package/src/doctor-compat.mjs +1 -1
- package/src/http-transport.mjs +1 -1
- package/src/local-privacy.mjs +15 -7
- package/src/lock.mjs +9 -2
- package/src/model-capabilities.mjs +17 -4
- package/src/privacy-detection.mjs +4 -3
- package/src/privacy-transform.mjs +20 -6
- package/src/provider-cooldown.mjs +43 -0
- package/src/provider-runtime.mjs +8 -5
- package/src/providers/api-model-metadata.mjs +7 -0
- package/src/providers/api.mjs +44 -12
- package/src/request-context.mjs +5 -0
- package/src/response-failures.mjs +4 -2
- package/src/responses-bridge.mjs +12 -5
- package/src/responses-handler.mjs +79 -1
- package/src/responses-proxy.mjs +18 -5
- package/src/responses-request.mjs +11 -4
- package/src/safe-upstream-error.mjs +59 -9
- package/src/service-control.mjs +8 -1
- package/src/settings-preferences.mjs +3 -3
- package/src/source-import.mjs +51 -0
- package/src/stream-performance.mjs +8 -5
- package/src/upstream-body.mjs +1 -1
- package/src/upstream-error-capture.mjs +29 -0
- package/src/usage-analysis.mjs +2 -2
- package/src/usage-query.mjs +5 -2
- package/src/usage-store.mjs +2 -1
- package/src/user-settings.mjs +1 -1
package/src/cli-management.mjs
CHANGED
|
@@ -12,6 +12,8 @@ import { hiddenQuestion } from "./cli-secret.mjs";
|
|
|
12
12
|
import { readBoundedFileSync } from "./bounded-file.mjs";
|
|
13
13
|
import { deploymentModelId } from "./model-capabilities.mjs";
|
|
14
14
|
import { TERMINAL_COLOR_THEMES } from "./terminal-colors.mjs";
|
|
15
|
+
import { previewSourceImport } from "./source-import.mjs";
|
|
16
|
+
import { readAccessSettings } from "./access-settings.mjs";
|
|
15
17
|
|
|
16
18
|
async function readSecretInput(input) {
|
|
17
19
|
const chunks = [];let bytes = 0;
|
|
@@ -109,26 +111,47 @@ export async function runManagementCommand(command, options = {}) {
|
|
|
109
111
|
...(sourceNames ? [sourceNames] : []), "", print(view.clients, [["name", "Client"], ["setup", "Setup"], ["active", "Active"]]), "",
|
|
110
112
|
`Model requests: ${view.requests ?? "unknown"} total · ${view.active ?? "unknown"} active · ${view.outcomes.failed} failed`].join("\n");
|
|
111
113
|
}
|
|
114
|
+
if (group === "compact") {
|
|
115
|
+
const live = await request({ path: "settings" });
|
|
116
|
+
if (action === "status") return print(live.compaction || { enabled: false, state: "unsupported" });
|
|
117
|
+
if (!live.compaction) throw new Error("This command needs the updated running service; no settings changed.");
|
|
118
|
+
const enabled = action === "enable";
|
|
119
|
+
if (flags.preview) return print({ enabled, saved: false, source_policy: "current source and model", uses_quota: enabled });
|
|
120
|
+
await confirm(enabled ? "Enable bounded compression recovery using the current source and model? It can use quota." : "Disable gateway compression fallback?");
|
|
121
|
+
const result = await request({ path: "settings", body: { action: "preference", key: "context_compaction_enabled", value: enabled } });
|
|
122
|
+
return print(result.compaction);
|
|
123
|
+
}
|
|
112
124
|
if (group === "requests") {
|
|
125
|
+
if (action === "diagnose") {
|
|
126
|
+
if (flags.source || flags.model || flags.cancel) {
|
|
127
|
+
if (!flags.cancel && (!flags.source || !flags.model)) throw new Error("Use --source ID and --model ID together.");
|
|
128
|
+
if (flags.cancel && (flags.source || flags.model)) throw new Error("Use --cancel alone.");
|
|
129
|
+
if (flags.preview) return print({ source: flags.source, model: flags.model, operation: flags.cancel ? "cancel" : "arm", saved: false, error_limit: 512, expires_minutes: 10 });
|
|
130
|
+
await confirm(flags.cancel ? "Cancel the pending capture?" : "Capture one redacted technical error (up to 512 characters)? It may contain a request fragment; no prompt body is saved.");
|
|
131
|
+
const result = await request({ path: "settings", body: { action: "error_capture", operation: flags.cancel ? "cancel" : "arm", ...(flags.cancel ? {} : { source: flags.source, model: flags.model }) } });
|
|
132
|
+
return print(result.error_capture);
|
|
133
|
+
}
|
|
134
|
+
return print((await request({ path: "settings" })).error_capture || { state: "unsupported" });
|
|
135
|
+
}
|
|
113
136
|
let rows = retainedRequests((await readStatus()).data);
|
|
114
137
|
if (ids.request) {
|
|
115
138
|
const found = rows.find(row => row.request_id === ids.request);if (!found) throw new Error("Request not retained. No full-history lookup is available.");return print(found);
|
|
116
139
|
}
|
|
117
140
|
rows = rows.filter(row => (!flags.active || row.active) && (!flags.failed || row.state !== "cancelled" && (row.state === "failed" || row.error))
|
|
118
|
-
&& (!flags.source || row.provider === flags.source) && (!flags.app || (flags.app === "codex" ? ["codex", "codex_app", "codex_cli"].includes(row.application) : row.application === (flags.app === "antigravity" ? "gemini_app" : CLI_CLIENTS[flags.app])))).slice(-(flags.limit || 20));
|
|
141
|
+
&& (!flags.purpose || (row.purpose || "unknown") === flags.purpose) && (!flags.source || row.provider === flags.source) && (!flags.app || (flags.app === "codex" ? ["codex", "codex_app", "codex_cli"].includes(row.application) : row.application === (flags.app === "antigravity" ? "gemini_app" : CLI_CLIENTS[flags.app])))).slice(-(flags.limit || 20));
|
|
119
142
|
return print(flags.format === "json" ? rows : rows.map(row => ({ ...row, state_label: terminalRequestState(row) })), [["request_id", "Request"], ["application", "Client"], ["provider", "Source"], ["model", "Model"], ["route", "Route"], ["state_label", "State"]]);
|
|
120
143
|
}
|
|
121
144
|
if (group === "usage") {
|
|
122
145
|
if (flags.scope === "run") {
|
|
123
|
-
if (flags.model || flags.days || flags.from || flags.to || flags.time_zone) throw new Error("Model and date filters require --scope all; current-run totals support only --provider.");
|
|
146
|
+
if (flags.purpose || flags.model || flags.days || flags.from || flags.to || flags.time_zone) throw new Error("Model and date filters require --scope all; current-run totals support only --provider.");
|
|
124
147
|
const usage = (await readStatus()).data.runtime_usage;
|
|
125
148
|
if (!usage) throw new Error("Current-run usage is unavailable.");
|
|
126
149
|
return print(flags.provider ? usage.by_provider?.[flags.provider] || { records: 0 } : usage);
|
|
127
150
|
}
|
|
128
151
|
const { summarizeUsageLogs } = await import("./usage-store.mjs");
|
|
129
152
|
const { createUsageQuery } = await import("./usage-query.mjs");
|
|
130
|
-
const selection = createUsageQuery({ provider: flags.provider, model: flags.model, days: flags.days, from: flags.from, to: flags.to, timeZone: flags.time_zone });
|
|
131
|
-
const filtered = selection.filters.model || selection.filters.from || selection.filters.to;
|
|
153
|
+
const selection = createUsageQuery({ provider: flags.provider, model: flags.model, purpose: flags.purpose, days: flags.days, from: flags.from, to: flags.to, timeZone: flags.time_zone });
|
|
154
|
+
const filtered = selection.filters.purpose || selection.filters.model || selection.filters.from || selection.filters.to;
|
|
132
155
|
const summary = await summarizeUsageLogs(undefined, { ...(flags.provider ? { provider: flags.provider } : {}), ...(filtered ? { recordFilter: selection.matches } : {}) });
|
|
133
156
|
summary.filters = selection.filters;
|
|
134
157
|
if (flags.format === "json") return print(summary);
|
|
@@ -241,7 +264,7 @@ export async function runManagementCommand(command, options = {}) {
|
|
|
241
264
|
return print({ id: ids.app, access: client.enabled ? clientSetup(client) === "Paused" ? "Paused" : "Enabled" : "Disabled", setup: view.clients.find(row => row.id === id)?.setup || clientSetup(client),
|
|
242
265
|
selected_models: Array.isArray(client.deployments) ? client.deployments.length : modelPlan?.models.length ?? null, unavailable_selection: (modelPlan?.unavailable || []).filter(model => !modelPlan?.available.some(candidate => candidate.source === model.source && candidate.id === model.id)),
|
|
243
266
|
app_adoption: view.clients.find(row => row.id === id)?.active > 0 ? "Active gateway request observed; process liveness not checked" : observed ? `Gateway request observed${observed.at || observed.time ? ` at ${observed.at || observed.time}` : ""}; process liveness not checked` : client.observed_at ? `Gateway request observed at ${client.observed_at}; process liveness not checked` : "Not observed",
|
|
244
|
-
active: view.clients.find(row => row.id === id)?.active ?? null, ...(id === "codex" && flags.details ? { features: details, chatgpt_sign_in: "Managed by Codex; not inferred from GitHub credentials" } : {}) });
|
|
267
|
+
active: view.clients.find(row => row.id === id)?.active ?? null, ...(id.startsWith("claude_") && flags.details ? { capability_support: modelPlan?.support, capability_adoption: client.capability_adoption, capability_sync: modelPlan?.sync } : {}), ...(id === "codex" && flags.details ? { features: details, chatgpt_sign_in: "Managed by Codex; not inferred from GitHub credentials" } : {}) });
|
|
245
268
|
}
|
|
246
269
|
if (action === "models" && !flags.edit) {
|
|
247
270
|
if (flags.format === "json") return print(modelPlan);
|
|
@@ -313,6 +336,24 @@ export async function runManagementCommand(command, options = {}) {
|
|
|
313
336
|
const result = await save(imageOnly ? { operation: "image_model", id: "codex", model: body.image_model, client_revision: client.revision } : body);return print({ client: ids.app, setup: getClient(result, id).setup, saved: true, app_adoption: "Not verified" });
|
|
314
337
|
}
|
|
315
338
|
if (group !== "source") throw new Error("Unknown management command.");
|
|
339
|
+
if (action === "import") {
|
|
340
|
+
if (!flags.file) throw new Error("Supply one explicit JSON file with --file.");
|
|
341
|
+
const preview = previewSourceImport(readFile(), readAccessSettings(options).apis);
|
|
342
|
+
if (!flags.apply || flags.preview) return print(preview);
|
|
343
|
+
const selected = preview.drafts[(flags.select || 0) - 1];
|
|
344
|
+
if (!selected) throw new Error("Review the preview, then use --select NUMBER --apply for one source.");
|
|
345
|
+
output.write(print(selected) + "\n");
|
|
346
|
+
const graph = await connection();requireManagement();
|
|
347
|
+
if (graph.providers.some(source => source.name?.trim().toLowerCase() === selected.config.name.trim().toLowerCase())) throw new Error("A source with this name exists. Edit its settings explicitly, or rename the imported draft.");
|
|
348
|
+
let key;
|
|
349
|
+
if (!selected.config.key_env) {
|
|
350
|
+
if (!flags.key_stdin) throw new Error("Use --key-stdin or a configured key_env; foreign credential values are not copied.");
|
|
351
|
+
key = await readSecretInput(input);
|
|
352
|
+
}
|
|
353
|
+
await confirm("Save this one API without granting client access or selecting models?");
|
|
354
|
+
const result = await save({ operation: "save_api", config: selected.config, allowed: [], ...(key ? { key } : {}) });key = undefined;
|
|
355
|
+
return print({ saved: true, source: result.providers.find(source => source.name === selected.config.name)?.id, authorized_clients: [] });
|
|
356
|
+
}
|
|
316
357
|
let graph = await connection();
|
|
317
358
|
if (!flags.preview && (flags.edit || ["add", "edit", "enable", "disable", "remove"].includes(action))) requireManagement();
|
|
318
359
|
if (action === "list") return print(graph.providers.map(source => ({ id: source.id, name: source.name, enabled: source.enabled, key_saved: source.builtin ? undefined : source.key_saved })), [["id", "ID"], ["name", "Source"], ["enabled", "Enabled"]]);
|
|
@@ -325,7 +366,7 @@ export async function runManagementCommand(command, options = {}) {
|
|
|
325
366
|
if (action === "models") return print({ source: id, evidence: "Saved API model selection; access not checked", models: source.models });
|
|
326
367
|
const diagnostics = await request({ path: "providers" }), observed = diagnostics.providers.find(provider => provider.id === id);
|
|
327
368
|
return print({ id, name: source.name, saved_enabled: source.enabled, runtime_state: observed?.state || "Not observed", credentials: source.builtin ? observed?.auth : { key_saved: source.key_saved },
|
|
328
|
-
catalog: observed?.models || source.discovery || { count: source.models?.length ?? null, source: "configured" }, access: "Not inferred from saved credentials or configuration", diagnostic: observed?.catalog_diagnostic || null });
|
|
369
|
+
catalog: observed?.models || source.discovery || { count: source.models?.length ?? null, source: "configured" }, health: observed?.health || source.discovery?.health || null, access: "Not inferred from saved credentials or configuration", diagnostic: observed?.catalog_diagnostic || null });
|
|
329
370
|
}
|
|
330
371
|
if (action === "check" || action === "models" && flags.refresh) {
|
|
331
372
|
if (!source.enabled || id === "m365" && graph.m365_state === "disabled") throw new Error("Source is disabled; it was not enabled automatically.");
|
package/src/cli-options.mjs
CHANGED
|
@@ -20,7 +20,7 @@ export function parseCliArgs(input = []) {
|
|
|
20
20
|
throw new Error(`Unknown help topic: ${help.join(" ")}`);
|
|
21
21
|
return base({ command: "help", helpTopic: help.join(" ") });
|
|
22
22
|
}
|
|
23
|
-
if (["app", "config", "source"].includes(args[0]) && args.length === 1)
|
|
23
|
+
if (["app", "config", "source", "compact"].includes(args[0]) && args.length === 1)
|
|
24
24
|
return base({ command: "help", helpTopic: args[0] });
|
|
25
25
|
const parsed = parseManagedCommand(args);
|
|
26
26
|
return base(parsed.dispatch || parsed);
|
|
@@ -105,6 +105,7 @@ export function createConnectionClientSync({ options, corePort, configureCodex,
|
|
|
105
105
|
client: id,
|
|
106
106
|
profileName: "CCDX",
|
|
107
107
|
desktopAliases: id === "claude_app" && source?.id.startsWith("api_"),
|
|
108
|
+
appContract: capabilitySupport.app_contract,
|
|
108
109
|
disableExperimentalBetas: m365Only,
|
|
109
110
|
desktopManaged: id === "claude_app" ? desktopManaged : false,
|
|
110
111
|
baseUrl: `http://127.0.0.1:${corePort}/anthropic`,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { previewSourceImport } from "./source-import.mjs";
|
|
1
2
|
import { prepareSourceAccess, accessError, CLIENT_IDS } from "./access-settings.mjs";
|
|
2
3
|
import { publicModelCatalog } from "./provider-metadata.mjs";
|
|
3
4
|
import { createConnectionPolicy } from "./connection-policy.mjs";
|
|
@@ -138,6 +139,10 @@ export function createConnectionManagement({ binding, catalogRefresh, save, disc
|
|
|
138
139
|
if (binding("codex").enabled) void memoryModel.refresh();
|
|
139
140
|
return snapshot();
|
|
140
141
|
}
|
|
142
|
+
if (validObject(input, ["operation", "content"]) && input.operation === "preview_import") {
|
|
143
|
+
try { return previewSourceImport(input.content, getSettings().apis); }
|
|
144
|
+
catch (error) { throw accessError(/^ccdx_import_[a-z_]+$/.test(error.message) ? error.message : "ccdx_import_metadata_invalid"); }
|
|
145
|
+
}
|
|
141
146
|
if (validObject(input, ["operation", "id"]) && input.operation === "source_catalog") {
|
|
142
147
|
if (!["github", "m365", ...getSettings().apis.map(api => api.id)].includes(input.id))
|
|
143
148
|
throw accessError("ccdx_connections_action_invalid");
|
|
@@ -176,7 +176,7 @@ export function createConnectionPolicy({ validObject, binding, catalogRefresh, s
|
|
|
176
176
|
source: getSource,
|
|
177
177
|
enabled,
|
|
178
178
|
names,
|
|
179
|
-
desktopEffortAliases: capabilitySupport.app,
|
|
179
|
+
desktopEffortAliases: capabilitySupport.app && capabilitySupport.app_aliases !== false,
|
|
180
180
|
});
|
|
181
181
|
if (c.default_model && !compiled.routes.has(c.default_model))
|
|
182
182
|
throw accessError("ccdx_api_model_unavailable");
|
|
@@ -233,7 +233,7 @@ export function createConnectionPolicy({ validObject, binding, catalogRefresh, s
|
|
|
233
233
|
binding: c,
|
|
234
234
|
source: getSource,
|
|
235
235
|
enabled,
|
|
236
|
-
desktopEffortAliases: capabilitySupport.app,
|
|
236
|
+
desktopEffortAliases: capabilitySupport.app && capabilitySupport.app_aliases !== false,
|
|
237
237
|
});
|
|
238
238
|
const shared =
|
|
239
239
|
input.id === "codex"
|
|
@@ -6,7 +6,7 @@ import { currentRequestContext } from "./request-context.mjs";
|
|
|
6
6
|
|
|
7
7
|
export function createConnectionRouting({ legacy, legacyClaudeAccess, isManaged, getSettings, binding, plan, permitted, getSource,
|
|
8
8
|
resolveDeployment, codexAccessMode, codexRequiresKey, requireCodexKey, identities, track, guardConversation, messagesTransfer,
|
|
9
|
-
acquireClaudeRequest, privacy, env, log, lastClients }) {
|
|
9
|
+
acquireClaudeRequest, privacy, env, log, lastClients, capabilitySupport }) {
|
|
10
10
|
const handlers = new Map();
|
|
11
11
|
function requireSource(clientId, id) {
|
|
12
12
|
if (!permitted(clientId, id)) throw accessError("ccdx_client_source_disabled", 503);
|
|
@@ -147,11 +147,13 @@ export function createConnectionRouting({ legacy, legacyClaudeAccess, isManaged,
|
|
|
147
147
|
acquireRequest: acquireClaudeRequest,
|
|
148
148
|
apiKey: identities()[id],
|
|
149
149
|
privacy,
|
|
150
|
+
compaction: legacy.compaction,
|
|
150
151
|
privacyClient: id,
|
|
151
152
|
env,
|
|
152
153
|
log,
|
|
153
154
|
performance: legacy.claudePerformance,
|
|
154
155
|
desktopAliases: id === "claude_app",
|
|
156
|
+
appContract: id === "claude_app" ? capabilitySupport?.app_contract : undefined,
|
|
155
157
|
messagesSystemMode: id === "claude_app" ? "legacy" : "passthrough",
|
|
156
158
|
resolveRequest(body) {
|
|
157
159
|
const record = resolveDeployment(id, body.model),
|
|
@@ -30,8 +30,10 @@ import { createMessagesHistoryTransfer } from "./messages-history-transfer.mjs";
|
|
|
30
30
|
import { compileClientModels } from "./client-model-plan.mjs";
|
|
31
31
|
import { currentRequestContext } from "./request-context.mjs";
|
|
32
32
|
import { inspectClaudeCapabilitySupport } from "./claude-capability-config.mjs";
|
|
33
|
+
import { inspectClaudeAppContract, watchClaudeAppContract } from "./claude-app-contract.mjs";
|
|
33
34
|
import { deploymentModelId, deploymentRevision } from "./model-capabilities.mjs";
|
|
34
35
|
import { m365Paths } from "./m365-settings.mjs";
|
|
36
|
+
import { createUpstreamErrorCapture } from "./upstream-error-capture.mjs";
|
|
35
37
|
|
|
36
38
|
export function createConnectionRuntime({
|
|
37
39
|
legacy,
|
|
@@ -45,6 +47,7 @@ export function createConnectionRuntime({
|
|
|
45
47
|
restoreClaude = restoreClaudeClients,
|
|
46
48
|
configureCodex = configureCodexApi,
|
|
47
49
|
inspectDesktop = inspectClaudeDesktopPolicy,
|
|
50
|
+
inspectAppContract = inspectClaudeAppContract,
|
|
48
51
|
clientAccessChanged,
|
|
49
52
|
preserveClientConfiguration,
|
|
50
53
|
clientVersionsSnapshot,
|
|
@@ -62,6 +65,7 @@ export function createConnectionRuntime({
|
|
|
62
65
|
});
|
|
63
66
|
const memoryModel = createCodexMemoryModel({ ...options, corePort });
|
|
64
67
|
const privacy = createLocalPrivacy(options);
|
|
68
|
+
const errorCapture = createUpstreamErrorCapture({ now });
|
|
65
69
|
let settings = readAccessSettings(options),
|
|
66
70
|
managed = fs.existsSync(accessSettingsPath(options)),
|
|
67
71
|
serial = Promise.resolve(),
|
|
@@ -86,6 +90,20 @@ export function createConnectionRuntime({
|
|
|
86
90
|
onState: (id, state) => (state ? discoveries.set(id, state) : discoveries.delete(id)),
|
|
87
91
|
});
|
|
88
92
|
const capabilitySupport = inspectClaudeCapabilitySupport(options);
|
|
93
|
+
let capabilityFlight = null, capabilityWatch = null;
|
|
94
|
+
const refreshClientCapabilities = ({ sync = true } = {}) => {
|
|
95
|
+
if(closed||!managed||!binding("claude_app").enabled||!plan("claude_app").models.length)return Promise.resolve(structuredClone(capabilitySupport));
|
|
96
|
+
if (capabilityFlight) return capabilityFlight;
|
|
97
|
+
capabilityFlight = inspectAppContract(options).then(async contract => {
|
|
98
|
+
if(closed)return;
|
|
99
|
+
const next=inspectClaudeCapabilitySupport({...options,appContract:contract});
|
|
100
|
+
const changed=capabilitySupport.app_contract?.fingerprint!==contract.fingerprint||capabilitySupport.app_contract?.installation!==contract.installation||capabilitySupport.app_version!==next.app_version||capabilitySupport.app!==next.app;
|
|
101
|
+
await enqueue(()=>{Object.assign(capabilitySupport,next);if(changed){plans.delete("claude_app");plans.delete("claude_code")}});
|
|
102
|
+
if(changed&&sync&&managed)await clientSync.syncClients(["claude_app","claude_code"]);
|
|
103
|
+
return structuredClone(capabilitySupport);
|
|
104
|
+
}).finally(()=>{capabilityFlight=null});
|
|
105
|
+
return capabilityFlight;
|
|
106
|
+
};
|
|
89
107
|
let operations = 0;
|
|
90
108
|
const identities = () => (keys ||= readClientGatewayKeys(options));
|
|
91
109
|
const enabled = id =>
|
|
@@ -145,6 +163,7 @@ export function createConnectionRuntime({
|
|
|
145
163
|
env: { ...env },
|
|
146
164
|
platform,
|
|
147
165
|
modelDisplay: model => modelDisplay.get(id, revision, model),
|
|
166
|
+
errorCapture,
|
|
148
167
|
});
|
|
149
168
|
instances.set(id, { signature, source, config, revision });
|
|
150
169
|
lifecycle.rememberSource(source, config.secret_ref);
|
|
@@ -180,7 +199,7 @@ export function createConnectionRuntime({
|
|
|
180
199
|
["m365", "Microsoft 365"],
|
|
181
200
|
...settings.apis.map(api => [api.id, api.name]),
|
|
182
201
|
]),
|
|
183
|
-
desktopEffortAliases: capabilitySupport.app,
|
|
202
|
+
desktopEffortAliases: capabilitySupport.app && capabilitySupport.app_aliases !== false,
|
|
184
203
|
});
|
|
185
204
|
plans.set(id, { binding: selected, stamps, value });
|
|
186
205
|
return value;
|
|
@@ -259,7 +278,7 @@ export function createConnectionRuntime({
|
|
|
259
278
|
clientRevision, editable, syncClients, clientAccessChanged, setup, secrets, lifecycle, retire, memoryModel, enqueue, catalogVisibility });
|
|
260
279
|
const { requireSource, methods: routing } = createConnectionRouting({ legacy, legacyClaudeAccess, isManaged: () => managed,
|
|
261
280
|
getSettings: () => settings, binding, plan, permitted, getSource, resolveDeployment, codexAccessMode, codexRequiresKey, requireCodexKey,
|
|
262
|
-
identities, track, guardConversation, messagesTransfer, acquireClaudeRequest, privacy, env, log, lastClients });
|
|
281
|
+
identities, track, guardConversation, messagesTransfer, acquireClaudeRequest, privacy, env, log, lastClients, capabilitySupport });
|
|
263
282
|
|
|
264
283
|
|
|
265
284
|
async function applyCatalog(id, models, revision, checkedAt, active) {
|
|
@@ -324,6 +343,14 @@ export function createConnectionRuntime({
|
|
|
324
343
|
},
|
|
325
344
|
source: getSource,
|
|
326
345
|
connections: snapshot,
|
|
346
|
+
errorCaptureSnapshot: () => errorCapture.snapshot(),
|
|
347
|
+
captureUpstreamError({ operation, source, model }) {
|
|
348
|
+
if (operation === "cancel") return errorCapture.cancel();
|
|
349
|
+
const config = settings.apis.find(api => api.id === source && api.enabled);
|
|
350
|
+
if (operation !== "arm" || !config?.models.some(entry => entry.id === model && entry.protocols.includes("messages")))
|
|
351
|
+
throw accessError("ccdx_connections_action_invalid");
|
|
352
|
+
return errorCapture.arm(source, model);
|
|
353
|
+
},
|
|
327
354
|
privateScopes: id =>
|
|
328
355
|
[...new Set(plan(id).models.map(model => model.source_id))]
|
|
329
356
|
.sort()
|
|
@@ -358,6 +385,7 @@ export function createConnectionRuntime({
|
|
|
358
385
|
),
|
|
359
386
|
privacy,
|
|
360
387
|
busy: () => privacy.busy() ||
|
|
388
|
+
Boolean(capabilityFlight) ||
|
|
361
389
|
operations > 0 ||
|
|
362
390
|
lifecycle.busy() ||
|
|
363
391
|
clientSync.busy() ||
|
|
@@ -365,11 +393,15 @@ export function createConnectionRuntime({
|
|
|
365
393
|
legacy.snapshot().m365.account_change_in_flight === true ||
|
|
366
394
|
legacy.snapshot().m365.state === "checking",
|
|
367
395
|
syncClients,
|
|
396
|
+
refreshClientCapabilities,
|
|
368
397
|
manageConnections: management.manageConnections,
|
|
369
398
|
imageModels,
|
|
370
399
|
async start() {
|
|
400
|
+
const capabilities = refreshClientCapabilities({sync:false});
|
|
401
|
+
capabilityWatch ||= watchClaudeAppContract({ ...options, onChange: refreshClientCapabilities });
|
|
371
402
|
if (binding("codex").enabled) void memoryModel.refresh();
|
|
372
403
|
const old = legacy.start();
|
|
404
|
+
await capabilities;
|
|
373
405
|
if (managed) await syncClients();
|
|
374
406
|
const result = await old;
|
|
375
407
|
if (managed) await syncClients();
|
|
@@ -377,6 +409,7 @@ export function createConnectionRuntime({
|
|
|
377
409
|
return result;
|
|
378
410
|
},
|
|
379
411
|
async refresh() {
|
|
412
|
+
await refreshClientCapabilities();
|
|
380
413
|
const result = await Promise.allSettled([
|
|
381
414
|
!managed || settings.providers.m365 ? legacy.refresh() : Promise.resolve(),
|
|
382
415
|
refreshApis(),
|
|
@@ -403,6 +436,8 @@ export function createConnectionRuntime({
|
|
|
403
436
|
action: management.action,
|
|
404
437
|
async close() {
|
|
405
438
|
closed = true;
|
|
439
|
+
capabilityWatch?.close();
|
|
440
|
+
await capabilityFlight;
|
|
406
441
|
privacy.close();
|
|
407
442
|
await memoryModel.close();
|
|
408
443
|
await catalogRefresh.close();
|
package/src/connection-view.mjs
CHANGED
|
@@ -38,6 +38,12 @@ export function createConnectionView({ legacy, env, binding, plan, getSource, en
|
|
|
38
38
|
return {
|
|
39
39
|
...base,
|
|
40
40
|
revision,
|
|
41
|
+
...(id.startsWith("claude_") ? { capability_adoption: (() => {
|
|
42
|
+
const rows = legacy.claudePerformance?.snapshot?.().recent_requests || [];
|
|
43
|
+
const observed = rows.findLast(row => row.application === id && row.context?.reasoning_effort_sent);
|
|
44
|
+
return observed ? { state: "effort_observed", effort: observed.context.reasoning_effort_sent, source: observed.provider, model: observed.model, request_id: observed.request_id, at: observed.at }
|
|
45
|
+
: { state: "not_observed" };
|
|
46
|
+
})() } : {}),
|
|
41
47
|
model_plan: {
|
|
42
48
|
...(id === "codex" ? { image: imageModels() } : {}),
|
|
43
49
|
default_model: compiled.defaultModel,
|
|
@@ -117,7 +123,9 @@ export function createConnectionView({ legacy, env, binding, plan, getSource, en
|
|
|
117
123
|
},
|
|
118
124
|
...config.apis.map(api => {
|
|
119
125
|
const { secret_ref, ...publicApi } = api,
|
|
120
|
-
revision = compact ? null : deploymentRevision(api, env)
|
|
126
|
+
revision = compact ? null : deploymentRevision(api, env),
|
|
127
|
+
health = compact ? null : getSource(api.id)?.health?.(),
|
|
128
|
+
cooling = health && Object.values(health).some(item => item.state !== "ready");
|
|
121
129
|
return {
|
|
122
130
|
...(compact ? { id: api.id, name: api.name, enabled: api.enabled } : publicApi),
|
|
123
131
|
...summary(api),
|
|
@@ -129,7 +137,7 @@ export function createConnectionView({ legacy, env, binding, plan, getSource, en
|
|
|
129
137
|
api.models.map(model => [model.id, modelDisplay.get(api.id, revision, model.id)])
|
|
130
138
|
),
|
|
131
139
|
}),
|
|
132
|
-
discovery: discoveries.get(api.id) || null,
|
|
140
|
+
discovery: cooling ? { ...discoveries.get(api.id), health } : discoveries.get(api.id) || null,
|
|
133
141
|
builtin: false,
|
|
134
142
|
key_saved: api.key_env ? Boolean(env[api.key_env]) : Boolean(secret_ref),
|
|
135
143
|
};
|
|
@@ -288,6 +296,7 @@ export function createConnectionView({ legacy, env, binding, plan, getSource, en
|
|
|
288
296
|
enabled: true,
|
|
289
297
|
generation: old?.generation || source?.registry.generation || 1,
|
|
290
298
|
state: old?.state || "configured",
|
|
299
|
+
...(source?.health ? { health: source.health() } : {}),
|
|
291
300
|
auth: old?.auth || { state: "saved", token_cached: false },
|
|
292
301
|
selection: {
|
|
293
302
|
codex: clients.some(client => client.id === "codex"),
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const MAX_CHUNKS = 4;
|
|
4
|
+
const MAX_CHUNK_BYTES = 1024 * 1024;
|
|
5
|
+
const fail = (code, message) => Object.assign(new Error(message), { code, statusCode: 422 });
|
|
6
|
+
const textParts = parts => Array.isArray(parts) && parts.every(part => ["text", "input_text", "output_text"].includes(part?.type) && typeof part.text === "string");
|
|
7
|
+
|
|
8
|
+
function describe(item, protocol, index, pendingNames) {
|
|
9
|
+
const calls = [], results = [];let human = false, opaque = false, record = item;
|
|
10
|
+
if (!item || typeof item !== "object") return { human: false, opaque: true, calls, results, record };
|
|
11
|
+
if (protocol === "responses") {
|
|
12
|
+
human = item.role === "user" || ["system", "developer"].includes(item.role);
|
|
13
|
+
if (item.type === "function_call" || item.type === "custom_tool_call") {
|
|
14
|
+
if (typeof item.call_id === "string" && item.call_id) calls.push(item.call_id);else opaque = true;
|
|
15
|
+
} else if (item.type === "function_call_output" || item.type === "custom_tool_call_output") {
|
|
16
|
+
if (typeof item.call_id === "string" && item.call_id) results.push(item.call_id);else opaque = true;
|
|
17
|
+
if (typeof item.output !== "string") opaque ||= !textParts(item.output);
|
|
18
|
+
} else if (item.type === "reasoning") {
|
|
19
|
+
opaque = Boolean(item.encrypted_content) || !Array.isArray(item.summary);
|
|
20
|
+
} else if (item.type === "compaction" || item.type === "compaction_trigger") opaque = true;
|
|
21
|
+
else if (item.type !== "message" && item.type !== undefined) opaque = true;
|
|
22
|
+
else if (typeof item.content !== "string") opaque = !textParts(item.content);
|
|
23
|
+
} else if (protocol === "messages") {
|
|
24
|
+
human = ["system", "developer"].includes(item.role) || item.role === "user" && (typeof item.content === "string" || !Array.isArray(item.content)
|
|
25
|
+
|| item.content.some(part => part?.type !== "tool_result"));
|
|
26
|
+
if (Array.isArray(item.content)) {
|
|
27
|
+
for (const part of item.content) {
|
|
28
|
+
if (part?.type === "tool_use") { if (typeof part.id === "string" && part.id) calls.push(part.id);else opaque = true; }
|
|
29
|
+
else if (part?.type === "tool_result") {
|
|
30
|
+
if (typeof part.tool_use_id === "string" && part.tool_use_id) results.push(part.tool_use_id);else opaque = true;
|
|
31
|
+
if (typeof part.content !== "string") opaque ||= !textParts(part.content);
|
|
32
|
+
} else if (part?.type === "thinking") opaque ||= Boolean(part.signature);
|
|
33
|
+
else if (part?.type !== "text") opaque = true;
|
|
34
|
+
}
|
|
35
|
+
record = { ...item, content: item.content.filter(part => part?.type !== "thinking" || part.signature) };
|
|
36
|
+
} else opaque ||= typeof item.content !== "string";
|
|
37
|
+
} else if (protocol === "chat") {
|
|
38
|
+
human = ["user", "system", "developer"].includes(item.role);
|
|
39
|
+
for (const call of item.tool_calls || []) { if (typeof call?.id === "string" && call.id) calls.push(call.id);else opaque = true; }
|
|
40
|
+
if (item.role === "tool") { if (typeof item.tool_call_id === "string" && item.tool_call_id) results.push(item.tool_call_id);else opaque = true; }
|
|
41
|
+
opaque ||= item.content !== null && typeof item.content !== "string" && !textParts(item.content);
|
|
42
|
+
if (item.reasoning_content !== undefined) { const { reasoning_content, ...visible } = item;record = visible; }
|
|
43
|
+
} else if (protocol === "gemini") {
|
|
44
|
+
human = item.role === "user" && (!Array.isArray(item.parts) || item.parts.some(part => !part?.functionResponse));
|
|
45
|
+
if (!Array.isArray(item.parts)) opaque = true;
|
|
46
|
+
for (const [partIndex, part] of (item.parts || []).entries()) {
|
|
47
|
+
opaque ||= Boolean(part?.thoughtSignature) || !part || !["text", "functionCall", "functionResponse"].some(key => Object.hasOwn(part, key));
|
|
48
|
+
if (part?.functionCall) {
|
|
49
|
+
const key = part.functionCall.id || `gemini:${index}:${partIndex}`;calls.push(key);
|
|
50
|
+
const name = part.functionCall.name, queue = pendingNames.get(name) || [];queue.push(key);pendingNames.set(name, queue);
|
|
51
|
+
}
|
|
52
|
+
if (part?.functionResponse) {
|
|
53
|
+
const key = part.functionResponse.id || pendingNames.get(part.functionResponse.name)?.shift();
|
|
54
|
+
if (typeof key === "string" && key) results.push(key);else opaque = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
record = { ...item, parts: item.parts?.filter(part => !part?.thought) };
|
|
58
|
+
} else throw fail("ccdx_compaction_protocol_unknown", "This interface has no verified compression adapter.");
|
|
59
|
+
return { human, opaque, calls, results, record };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function compactionItems(body, protocol) {
|
|
63
|
+
const items = protocol === "responses" ? body.input : protocol === "gemini" ? body.request?.contents : body.messages;
|
|
64
|
+
if (!Array.isArray(items)) throw fail("ccdx_compaction_history_unavailable", "A complete structured conversation is required for compression.");
|
|
65
|
+
return items;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function compactionMessage(protocol, text) {
|
|
69
|
+
const content = "[Earlier assistant and tool activity, compressed by CCDX]\n" + text;
|
|
70
|
+
if (protocol === "responses") return { type: "message", role: "assistant", content: [{ type: "output_text", text: content }] };
|
|
71
|
+
if (protocol === "gemini") return { role: "model", parts: [{ text: content }] };
|
|
72
|
+
return { role: "assistant", content };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function replaceCompactionItems(body, protocol, items) {
|
|
76
|
+
return protocol === "responses" ? { ...body, input: items } : protocol === "gemini"
|
|
77
|
+
? { ...body, request: { ...body.request, contents: items } } : { ...body, messages: items };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function planContextCompaction(body, { protocol, inputLimit, outputAllowance = 0 } = {}) {
|
|
81
|
+
if (!Number.isSafeInteger(inputLimit) || inputLimit <= 0) throw fail("ccdx_compaction_limit_unknown", "The source input window is unknown; native compression remains available.");
|
|
82
|
+
const budget = Math.min(MAX_CHUNK_BYTES, inputLimit - outputAllowance - 4096);
|
|
83
|
+
if (budget < 1024) throw fail("ccdx_compaction_budget_unavailable", "The source window leaves insufficient room for a compression request.");
|
|
84
|
+
const items = compactionItems(body, protocol), pendingNames = new Map(), facts = items.map((item, index) => describe(item, protocol, index, pendingNames));
|
|
85
|
+
const parents = items.map((_, index) => index), protectedItems = new Set(), references = new Map();
|
|
86
|
+
const root = index => { while (parents[index] !== index) { parents[index] = parents[parents[index]];index = parents[index]; }return index; };
|
|
87
|
+
const join = (a, b) => { parents[root(a)] = root(b); };
|
|
88
|
+
facts.forEach((fact, index) => {
|
|
89
|
+
if (fact.human || fact.opaque || index === items.length - 1) protectedItems.add(index);
|
|
90
|
+
for (const [kind, ids] of [["calls", fact.calls], ["results", fact.results]]) for (const id of ids) {
|
|
91
|
+
const entry = references.get(id) || { calls: [], results: [] };entry[kind].push(index);references.set(id, entry);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
for (const { calls, results } of references.values()) {
|
|
95
|
+
const linked = [...calls, ...results];for (const index of linked.slice(1)) join(linked[0], index);
|
|
96
|
+
if (calls.length !== 1 || results.length !== 1) for (const index of linked) protectedItems.add(index);
|
|
97
|
+
}
|
|
98
|
+
const protectedRoots = new Set([...protectedItems].map(root)), selected = new Set();
|
|
99
|
+
facts.forEach((_fact, index) => { if (!protectedRoots.has(root(index))) selected.add(index); });
|
|
100
|
+
if (!selected.size) throw fail("ccdx_compaction_protected_history", "No completed history can be compressed while preserving user content, signed state and unfinished tools.");
|
|
101
|
+
const transcript = [...selected].map(index => JSON.stringify({ position: index, record: facts[index].record })).join("\n"), bytes = Buffer.from(transcript);
|
|
102
|
+
if (bytes.length > budget * MAX_CHUNKS) throw fail("ccdx_compaction_work_limit", "The history exceeds the bounded compression workload; the original conversation was kept.");
|
|
103
|
+
const chunks = [];let offset = 0;
|
|
104
|
+
while (offset < bytes.length) {
|
|
105
|
+
let end = Math.min(bytes.length, offset + budget);
|
|
106
|
+
while (end < bytes.length && (bytes[end] & 0xc0) === 0x80) end--;
|
|
107
|
+
chunks.push(bytes.subarray(offset, end).toString("utf8"));offset = end;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
chunks, selected_items: selected.size, preserved_items: items.length - selected.size, bytes: bytes.length,
|
|
111
|
+
fingerprint: createHash("sha256").update(bytes).digest("hex"), sizing: "utf8_bytes_not_token_count",
|
|
112
|
+
rewriteItem(summaryItem) {
|
|
113
|
+
const output = [];let inserted = false;
|
|
114
|
+
for (const [index, item] of items.entries()) {
|
|
115
|
+
if (selected.has(index)) { if (!inserted) { output.push(summaryItem);inserted = true; } }
|
|
116
|
+
else if (item?.type !== "compaction_trigger") output.push(item);
|
|
117
|
+
}
|
|
118
|
+
return replaceCompactionItems(body, protocol, output);
|
|
119
|
+
},
|
|
120
|
+
rewrite(summary) { return this.rewriteItem(compactionMessage(protocol, summary)); },
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
export const CCDX_COMPACTION_PREFIX = "ccdx-compaction-v1:";
|
|
4
|
+
export const CCDX_NATIVE_COMPACTION_PREFIX = "ccdx-native-compaction-v1:";
|
|
5
|
+
const MAX_TEXT_BYTES = 512 * 1024, MAX_MAPPING_BYTES = 8 * 1024 * 1024;
|
|
6
|
+
const fail = () => Object.assign(new Error("The CCDX compression state is invalid or belongs to another connection; the original conversation was kept."), { code: "ccdx_compaction_state_invalid", statusCode: 409 });
|
|
7
|
+
const keyFor = key => {
|
|
8
|
+
if (typeof key !== "string" || key.length < 32) throw fail();
|
|
9
|
+
return createHash("sha256").update("ccdx-context-compaction-v1\0").update(key).digest();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function sealContextCompaction(text, { key, scope, maxBytes = MAX_TEXT_BYTES } = {}) {
|
|
13
|
+
if (typeof text !== "string" || !text.trim() || Buffer.byteLength(text) > Math.min(maxBytes, MAX_MAPPING_BYTES) || typeof scope !== "string" || !scope) throw fail();
|
|
14
|
+
const nonce = randomBytes(12), cipher = createCipheriv("aes-256-gcm", keyFor(key), nonce);cipher.setAAD(Buffer.from(scope));
|
|
15
|
+
const encoded = Buffer.concat([nonce, cipher.update(text, "utf8"), cipher.final(), cipher.getAuthTag()]);
|
|
16
|
+
return CCDX_COMPACTION_PREFIX + encoded.toString("base64url");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function openContextCompaction(value, { key, scope, maxBytes = MAX_TEXT_BYTES } = {}) {
|
|
20
|
+
try {
|
|
21
|
+
if (typeof value !== "string" || !value.startsWith(CCDX_COMPACTION_PREFIX) || value.length > (Math.min(maxBytes, MAX_MAPPING_BYTES) + 28) * 4 / 3 + CCDX_COMPACTION_PREFIX.length + 4
|
|
22
|
+
|| typeof scope !== "string" || !scope) throw fail();
|
|
23
|
+
const payload = value.slice(CCDX_COMPACTION_PREFIX.length);
|
|
24
|
+
if (!/^[\w-]+$/.test(payload)) throw fail();
|
|
25
|
+
const encoded = Buffer.from(payload, "base64url");if (encoded.length <= 28 || encoded.toString("base64url") !== payload) throw fail();
|
|
26
|
+
const decipher = createDecipheriv("aes-256-gcm", keyFor(key), encoded.subarray(0, 12));decipher.setAAD(Buffer.from(scope));decipher.setAuthTag(encoded.subarray(-16));
|
|
27
|
+
const text = Buffer.concat([decipher.update(encoded.subarray(12, -16)), decipher.final()]).toString("utf8");if (!text.trim()) throw fail();return text;
|
|
28
|
+
} catch { throw fail(); }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function checkedMappings(mappings) {
|
|
32
|
+
if (!Array.isArray(mappings) || mappings.length > 8192) throw fail();
|
|
33
|
+
const seen = new Map();let bytes = 0;
|
|
34
|
+
for (const entry of mappings) {
|
|
35
|
+
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || !/^\{\{CCDX_[a-f0-9]{24}\}\}$/.test(entry[0]) || typeof entry[1] !== "string"
|
|
36
|
+
|| seen.has(entry[0]) && seen.get(entry[0]) !== entry[1]) throw fail();
|
|
37
|
+
bytes += Buffer.byteLength(entry[1]);if (bytes > 4 * 1024 * 1024) throw fail();seen.set(...entry);
|
|
38
|
+
}
|
|
39
|
+
return mappings;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function sealNativeCompaction(encryptedContent, mappings, options) {
|
|
43
|
+
if (typeof encryptedContent !== "string" || !encryptedContent || encryptedContent.length > 100 * 1024 * 1024) throw fail();checkedMappings(mappings);
|
|
44
|
+
const digest = createHash("sha256").update(encryptedContent).digest("hex"), scope = options.scope + "\0native\0" + digest;
|
|
45
|
+
const sealed = sealContextCompaction(JSON.stringify(mappings), { ...options, scope, maxBytes: MAX_MAPPING_BYTES }).slice(CCDX_COMPACTION_PREFIX.length);
|
|
46
|
+
const result = CCDX_NATIVE_COMPACTION_PREFIX + sealed + ":" + encryptedContent;
|
|
47
|
+
if (result.length > 100 * 1024 * 1024) throw fail();return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function openNativeCompaction(value, options) {
|
|
51
|
+
if (typeof value !== "string" || !value.startsWith(CCDX_NATIVE_COMPACTION_PREFIX) || value.length > 100 * 1024 * 1024) throw fail();
|
|
52
|
+
const separator = value.indexOf(":", CCDX_NATIVE_COMPACTION_PREFIX.length);if (separator < 0) throw fail();
|
|
53
|
+
const encrypted_content = value.slice(separator + 1), digest = createHash("sha256").update(encrypted_content).digest("hex");
|
|
54
|
+
const text = openContextCompaction(CCDX_COMPACTION_PREFIX + value.slice(CCDX_NATIVE_COMPACTION_PREFIX.length, separator), { ...options, scope: options.scope + "\0native\0" + digest, maxBytes: MAX_MAPPING_BYTES });
|
|
55
|
+
let mappings;try { mappings = JSON.parse(text); } catch { throw fail(); }return { encrypted_content, mappings: checkedMappings(mappings) };
|
|
56
|
+
}
|