@chibitek/chibi 0.1.191 → 0.1.192
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/dist/assets/{TerminalPanel-D8Eovq0F.js → TerminalPanel-PcPGVxjJ.js} +1 -1
- package/dist/assets/{abnfDiagram-O67JEVCF-CPvuUneJ.js → abnfDiagram-O67JEVCF-CrdtKXgW.js} +1 -1
- package/dist/assets/{arc-aMP_0t5b.js → arc-DZp6zTLS.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-yyXrFi66.js → architectureDiagram-NJMV4G6O-By4YaF8p.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-BQN3ZvRc.js → blockDiagram-BEXU5L5S-b9XT0BEX.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-BieilTo4.js → c4Diagram-YGBWAQC7-ClDc6UCa.js} +1 -1
- package/dist/assets/channel-CP6zTF5h.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-Df4lxXIM.js → chunk-2Q5K7J3B-D8FDC39i.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-su_KXf5y.js → chunk-3FUC2YCW-_Lb0IVFX.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-DL3rM5tY.js → chunk-5VM5RSS4-f7re7-dy.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-53Ovfw1t.js → chunk-GTNCS2PH-Cl4oAWQ1.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-BkeiDfwS.js → chunk-GWA4HPMP-CLO3k8zE.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-CvsdGjCO.js → chunk-JWPE2WC7-kXWDfQP-.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-BngSjMee.js → chunk-NETBCI7D-DPtewwHN.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-DitKn6fq.js → chunk-WEXAMYUT-B17lA9FX.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-Czjvl52d.js → chunk-XXDRQBXY-B6RbRjkG.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-COr4Qzpk.js → classDiagram-v2-NBCMYWYE-BrZPolTO.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-Eg0tlzqp.js → cose-bilkent-JH36ORCC-DAvSQrfJ.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-BjtG84WL.js → cynefin-OW5HDTMX-BBEKoW-B.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-BzZtwDD4.js → cynefinDiagram-VND7K2PF-DTeD9b7A.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-TrLQ507j.js → dagre-6A5THRUB-7Lem_oJB.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-BDQDC-33.js → diagram-22UHCM2B-BBMu1DQ4.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-Cm_mzSfE.js → diagram-3UASUU5V-wTBd45sT.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-CAI_i4oy.js → diagram-ATOU4E4O-DejXVMcb.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-9GjNyQXn.js → diagram-CDSNMT55-CqYId1m8.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-ETDg4UN-.js → diagram-MLGK6HIB-DrOnQ-Zt.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-8_8dZKgW.js → diagram-MPIPVDR6-CHDvidFk.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-BiYh2ZYM.js → ebnfDiagram-ZINNZB2B-BzwpPn5m.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-5u6sMYIg.js → elk-276RUBZZ-E1HDqzYH.js} +1 -1
- package/dist/assets/{erDiagram-OPXOYQCR-Dm6semJ3.js → erDiagram-OPXOYQCR-D5E6uaT3.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-DbQ12CeV.js → flowDiagram-KWPJA3E3-R1exlkB4.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP-C12s51S6.js → ganttDiagram-FUAMR5RP-B5kjMGRd.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-BhkwBL2T.js → gitGraphDiagram-X574FWY7-BqkJtDvq.js} +1 -1
- package/dist/assets/{index-WT8Xwc4G.js → index-D_WPT1i-.js} +33 -33
- package/dist/assets/{index-D4BfC2Zf.js → index-DvEhLbPJ.js} +1 -1
- package/dist/assets/{infoDiagram-VRGFBTTK-IvWqyiSM.js → infoDiagram-VRGFBTTK-LXwGqqoO.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-N2ZxLyoE.js → ishikawaDiagram-OU5B5YK6-D_E17iEV.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-UWy3ala_.js → journeyDiagram-ZHPQQLJL-BkKKJrLR.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-Cutk-kDA.js → kanban-definition-PNTS6WVX-y6rjCvyW.js} +1 -1
- package/dist/assets/{linear-dPnV_-aA.js → linear-BYdFcAFG.js} +1 -1
- package/dist/assets/{mermaid.core-QdldWb2L.js → mermaid.core-BZnTzEV7.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-pkXW8CYn.js → mindmap-definition-NLK3R4M7-HPM-ymN0.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-DhKkEQzV.js → pegDiagram-GJSIUBJH-X2YHQQDC.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-DMehGrxw.js → pieDiagram-5QR66LMP-FQ47RvEb.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-oNzYf4fg.js → quadrantDiagram-O4NWA36T-CZok45i-.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-pkMOwYja.js → railroadDiagram-XR7U4H2S-CkzgSbiA.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-J29GrlJj.js → requirementDiagram-PLB6GJNP-B96vOB2k.js} +1 -1
- package/dist/assets/{sankeyDiagram-IPEJSGJF-YuyCeGY6.js → sankeyDiagram-IPEJSGJF-C3OzzNBk.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-BjxLu0JW.js → sequenceDiagram-PO4LG4MO-UEjwqc9C.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-BESOD3ec.js → sizeCapture-INFHLROL-CYlsATAn.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-DF2yvbZA.js → stateDiagram-v2-GCMORJYK-i3kPrA1F.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-Bzp4ze7n.js → swimlanes-2SLR337P-CwxGl-A-.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-BxG6JDb-.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-CnLbXs4R.js → timeline-definition-EJHVYXUP-B-CIp72A.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-nuJhbhCv.js → usecaseDiagram-POWQR4AR-CvI2j7z-.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-D_hzVg9h.js → vennDiagram-UO4OBE2U--l2Nr666.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-hgmpI4iu.js → wardleyDiagram-VNRHLVJA-C_WERxNO.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-DwnJWdDn.js → xychartDiagram-PMCCYNJV-VoRUD4V6.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/container-mcp.js +81 -81
- package/dist-server/drivers/agents-proxy.js +81 -81
- package/dist-server/index.js +593 -532
- package/dist-server/openmausbot.js +605 -603
- package/dist-server/pair-cli.js +605 -603
- package/dist-server/server/nexus-memory/backoff.js +41 -0
- package/dist-server/server/nexus-memory/client.js +55 -11
- package/dist-server/server/nexus-memory/index.js +4 -23
- package/dist-server/server/vault/store.js +8 -4
- package/dist-server/shared/vault-api-providers.js +16 -2
- package/dist-server/shared/vault.js +3 -2
- package/dist-server/vps-container-mcp.js +81 -81
- package/package.json +1 -1
- package/dist/assets/channel-Bw54wjTR.js +0 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-B6y4ZZ5q.js +0 -8
- package/dist-server/server/session-fallback.js +0 -76
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NexusInitializeError, NexusUnavailableError } from "./client.js";
|
|
1
2
|
// One shared wait after Nexus fails: 1, 5, 15, then 30 minutes while the
|
|
2
3
|
// outage lasts (unreachable, or signed out, which makes the bridge open a
|
|
3
4
|
// sign-in page). A failure more than an hour after the previous one is a
|
|
@@ -25,3 +26,43 @@ export class UnavailableBackoff {
|
|
|
25
26
|
this.until = 0;
|
|
26
27
|
}
|
|
27
28
|
}
|
|
29
|
+
/** One failed initialize is retried and does not count. The retry failing
|
|
30
|
+
* trips the breaker. Any other outage trips immediately. */
|
|
31
|
+
export function guardNexusClient(client, backoff, now, log) {
|
|
32
|
+
const finish = async (tool, args, timeoutMs) => {
|
|
33
|
+
try {
|
|
34
|
+
const result = await client.call(tool, args, timeoutMs);
|
|
35
|
+
backoff.succeeded();
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (!(error instanceof NexusInitializeError) && error instanceof NexusUnavailableError)
|
|
40
|
+
backoff.failed(now());
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
call: async (tool, args, timeoutMs) => {
|
|
46
|
+
const remaining = backoff.remainingMs(now());
|
|
47
|
+
if (remaining > 0)
|
|
48
|
+
throw new NexusUnavailableError(`waiting before trying Nexus again (next try in ${Math.ceil(remaining / 60_000)} min)`);
|
|
49
|
+
try {
|
|
50
|
+
return await finish(tool, args, timeoutMs);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (!(error instanceof NexusInitializeError))
|
|
54
|
+
throw error;
|
|
55
|
+
log("Nexus initialize failed; retrying once");
|
|
56
|
+
try {
|
|
57
|
+
return await finish(tool, args, timeoutMs);
|
|
58
|
+
}
|
|
59
|
+
catch (again) {
|
|
60
|
+
if (again instanceof NexusInitializeError)
|
|
61
|
+
backoff.failed(now());
|
|
62
|
+
throw again;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
close: () => client.close(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -17,6 +17,13 @@ export class NexusUnavailableError extends Error {
|
|
|
17
17
|
this.name = "NexusUnavailableError";
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
/** The MCP initialize handshake failed. One of these is retried; the next trips the breaker. */
|
|
21
|
+
export class NexusInitializeError extends NexusUnavailableError {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "NexusInitializeError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
20
27
|
/** Nexus answered and refused this call (bad input): retrying will not help. */
|
|
21
28
|
export class NexusRejectedError extends Error {
|
|
22
29
|
constructor(message) {
|
|
@@ -29,6 +36,18 @@ const PROTOCOL_VERSION = "2025-06-18";
|
|
|
29
36
|
/** Messages that mean "try again later", not "this input is wrong". */
|
|
30
37
|
const PRIVATE_SCOPE_ANSWER = /\b(?:private_scope_\w+|private_proof_invalid|personal_scope_requires_private_bot|personal_memory_cannot_be_shared)\b/;
|
|
31
38
|
const TRANSIENT = /unauthori[sz]ed|sign ?in|token|timed? ?out|timeout|ECONN|ENOTFOUND|EAI_AGAIN|fetch failed|network|socket|503|502|504|429|temporar|unavailable|not provisioned/i;
|
|
39
|
+
const BRIDGE_URL = /https?:\/\/[^\s"'<>]+/gi;
|
|
40
|
+
const BRIDGE_SECRET = /\b(bearer|token|access_token|refresh_token|id_token|authorization|client_secret|api[_-]?key|password|code)\b(\s*[:=]\s*)\S+/gi;
|
|
41
|
+
const BRIDGE_JWT = /\beyJ[A-Za-z0-9_-]{8,}(?:\.[A-Za-z0-9_-]{8,}){2}\b/g;
|
|
42
|
+
/** Bridge stderr, safe to log: no URLs, tokens, or sign-in links. */
|
|
43
|
+
function redactBridgeLine(line) {
|
|
44
|
+
return line
|
|
45
|
+
.replace(BRIDGE_URL, "[url]")
|
|
46
|
+
.replace(BRIDGE_SECRET, "$1$2[redacted]")
|
|
47
|
+
.replace(BRIDGE_JWT, "[jwt]")
|
|
48
|
+
.trim()
|
|
49
|
+
.slice(0, 240);
|
|
50
|
+
}
|
|
32
51
|
function isRecord(value) {
|
|
33
52
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
34
53
|
}
|
|
@@ -69,12 +88,18 @@ class HttpNexusClient {
|
|
|
69
88
|
connect(signal) {
|
|
70
89
|
this.ready ??= (async () => {
|
|
71
90
|
const client = new RemoteMcpClient(this.spec);
|
|
72
|
-
|
|
91
|
+
try {
|
|
92
|
+
await client.initialize("Atomic Nexus writeback", signal);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
await client.close().catch(() => undefined);
|
|
96
|
+
throw new NexusInitializeError(error instanceof Error ? error.message : "Nexus initialize failed");
|
|
97
|
+
}
|
|
73
98
|
this.client = client;
|
|
74
99
|
return client;
|
|
75
100
|
})().catch((error) => {
|
|
76
101
|
this.ready = null;
|
|
77
|
-
throw error;
|
|
102
|
+
throw error instanceof NexusInitializeError ? error : new NexusInitializeError(error instanceof Error ? error.message : "Nexus initialize failed");
|
|
78
103
|
});
|
|
79
104
|
return this.ready;
|
|
80
105
|
}
|
|
@@ -115,8 +140,10 @@ class StdioNexusClient {
|
|
|
115
140
|
idle;
|
|
116
141
|
spec;
|
|
117
142
|
idleMs;
|
|
118
|
-
|
|
143
|
+
log;
|
|
144
|
+
constructor(spec, log, idleMs = 60_000) {
|
|
119
145
|
this.spec = spec;
|
|
146
|
+
this.log = log;
|
|
120
147
|
this.idleMs = idleMs;
|
|
121
148
|
}
|
|
122
149
|
env() {
|
|
@@ -196,19 +223,36 @@ class StdioNexusClient {
|
|
|
196
223
|
entry.resolve(frame.result);
|
|
197
224
|
});
|
|
198
225
|
child.stdout.on("data", (chunk) => splitter.push(chunk));
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
226
|
+
let logged = 0;
|
|
227
|
+
let handshook = false;
|
|
228
|
+
const errSplit = createLineSplitter((line) => {
|
|
229
|
+
const redacted = redactBridgeLine(line);
|
|
230
|
+
// ponytail: 20 lines per child; raise if a handshake needs more of the log
|
|
231
|
+
if (!redacted || logged >= 20)
|
|
232
|
+
return;
|
|
233
|
+
logged += 1;
|
|
234
|
+
this.log?.(`bridge: ${redacted}`);
|
|
235
|
+
});
|
|
236
|
+
child.stderr.on("data", (chunk) => errSplit.push(chunk));
|
|
237
|
+
const gone = (message) => {
|
|
238
|
+
errSplit.flush();
|
|
239
|
+
if (this.child !== child)
|
|
240
|
+
return;
|
|
241
|
+
this.fail(handshook ? new NexusUnavailableError(message) : new NexusInitializeError(message));
|
|
242
|
+
};
|
|
243
|
+
child.once("error", () => gone("Nexus bridge failed"));
|
|
244
|
+
child.once("close", () => gone("Nexus bridge stopped"));
|
|
203
245
|
await this.send("initialize", {
|
|
204
246
|
protocolVersion: PROTOCOL_VERSION,
|
|
205
247
|
capabilities: {},
|
|
206
248
|
clientInfo: { name: "Atomic Nexus writeback", version: "1" },
|
|
207
249
|
}, timeoutMs);
|
|
208
250
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" })}\n`);
|
|
251
|
+
handshook = true;
|
|
209
252
|
})().catch((error) => {
|
|
210
|
-
|
|
211
|
-
|
|
253
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
254
|
+
this.fail(error instanceof Error ? error : new Error(message));
|
|
255
|
+
throw error instanceof NexusInitializeError ? error : new NexusInitializeError(message);
|
|
212
256
|
});
|
|
213
257
|
return this.ready;
|
|
214
258
|
}
|
|
@@ -231,8 +275,8 @@ class StdioNexusClient {
|
|
|
231
275
|
}
|
|
232
276
|
}
|
|
233
277
|
/** A client for the configured `nexus` MCP server, or null when there is none. */
|
|
234
|
-
export function nexusClientFor(spec) {
|
|
278
|
+
export function nexusClientFor(spec, log) {
|
|
235
279
|
if (!spec)
|
|
236
280
|
return null;
|
|
237
|
-
return isRemoteMcpServer(spec) ? new HttpNexusClient(spec) : new StdioNexusClient(spec);
|
|
281
|
+
return isRemoteMcpServer(spec) ? new HttpNexusClient(spec) : new StdioNexusClient(spec, log);
|
|
238
282
|
}
|
|
@@ -29,7 +29,7 @@ import { existsSync, mkdirSync, readFileSync, statSync } from "node:fs";
|
|
|
29
29
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
30
30
|
import { writeFileAtomic } from "../atomic.js";
|
|
31
31
|
import { customMcpServers } from "../config.js";
|
|
32
|
-
import { UnavailableBackoff } from "./backoff.js";
|
|
32
|
+
import { guardNexusClient, UnavailableBackoff } from "./backoff.js";
|
|
33
33
|
import { nexusClientFor, NexusRejectedError, NexusUnavailableError } from "./client.js";
|
|
34
34
|
import { buildSessionOutcome, promptText } from "./outcome.js";
|
|
35
35
|
import { NexusOutbox } from "./outbox.js";
|
|
@@ -175,36 +175,17 @@ export class NexusMemory {
|
|
|
175
175
|
const key = JSON.stringify(spec ?? null);
|
|
176
176
|
if (key !== this.clientKey) {
|
|
177
177
|
void this.client?.close();
|
|
178
|
-
this.client = nexusClientFor(spec);
|
|
178
|
+
this.client = nexusClientFor(spec, (message) => this.log(message));
|
|
179
179
|
this.clientKey = key;
|
|
180
180
|
}
|
|
181
181
|
return this.client;
|
|
182
182
|
}
|
|
183
|
-
/** The client behind one shared back-off (see backoff.ts)
|
|
184
|
-
* fails, nothing calls it again until the wait is over. Writes keep
|
|
185
|
-
* queuing on disk meanwhile. */
|
|
183
|
+
/** The client behind one shared back-off (see backoff.ts). */
|
|
186
184
|
getClient() {
|
|
187
185
|
const client = this.rawClient();
|
|
188
186
|
if (!client)
|
|
189
187
|
return null;
|
|
190
|
-
return
|
|
191
|
-
call: async (tool, args, timeoutMs) => {
|
|
192
|
-
const remaining = this.backoff.remainingMs(this.now());
|
|
193
|
-
if (remaining > 0)
|
|
194
|
-
throw new NexusUnavailableError(`waiting before trying Nexus again (next try in ${Math.ceil(remaining / 60_000)} min)`);
|
|
195
|
-
try {
|
|
196
|
-
const result = await client.call(tool, args, timeoutMs);
|
|
197
|
-
this.backoff.succeeded();
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
if (error instanceof NexusUnavailableError)
|
|
202
|
-
this.backoff.failed(this.now());
|
|
203
|
-
throw error;
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
close: () => client.close(),
|
|
207
|
-
};
|
|
188
|
+
return guardNexusClient(client, this.backoff, this.now, this.log);
|
|
208
189
|
}
|
|
209
190
|
// ── the Private Bot's signed calls ─────────────────────────────────────
|
|
210
191
|
privateKey() {
|
|
@@ -8,6 +8,7 @@ import { lstatSync, mkdirSync, readFileSync, rmdirSync } from "node:fs";
|
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { vaultGranted, vaultInputSchema, vaultMetadata, vaultUseAllowed } from "../../shared/vault.js";
|
|
11
|
+
import { apiAuthFor } from "../../shared/vault-api-providers.js";
|
|
11
12
|
import { writeFileAtomic } from "../atomic.js";
|
|
12
13
|
const MAX_BYTES = 16 * 1024 * 1024;
|
|
13
14
|
const MAX_ITEMS = 3000;
|
|
@@ -161,7 +162,8 @@ export class VaultStore {
|
|
|
161
162
|
const item = this.read().find((candidate) => candidate.id === id);
|
|
162
163
|
if (!item || item.kind !== "apiKey" || !vaultUseAllowed(item, actor, now))
|
|
163
164
|
return null;
|
|
164
|
-
|
|
165
|
+
const { header, prefix } = apiAuthFor(actor.destination, item);
|
|
166
|
+
return { header, value: prefix + item.secret, secret: item.secret };
|
|
165
167
|
}
|
|
166
168
|
create(ownerId, input) {
|
|
167
169
|
owner(ownerId);
|
|
@@ -232,9 +234,11 @@ export class VaultStore {
|
|
|
232
234
|
if (!current)
|
|
233
235
|
throw new VaultError("Vault item is unavailable.");
|
|
234
236
|
const { id: _id, ownerId: _owner, createdAt: _created, updatedAt: _updated, ...previous } = current;
|
|
235
|
-
//
|
|
236
|
-
|
|
237
|
-
|
|
237
|
+
// Blank API key edits preserve the saved value, just like omission.
|
|
238
|
+
const patch = { ...input };
|
|
239
|
+
if (current.kind === "apiKey" && typeof patch.secret === "string" && !patch.secret.trim())
|
|
240
|
+
delete patch.secret;
|
|
241
|
+
const parsed = vaultInputSchema.safeParse({ ...previous, ...patch });
|
|
238
242
|
if (!parsed.success)
|
|
239
243
|
throw new VaultError("Invalid Vault item.");
|
|
240
244
|
if (current.kind !== parsed.data.kind)
|
|
@@ -3,8 +3,8 @@ const keyed = (name, header, ...origins) => ({ name, origins, header, prefix: ""
|
|
|
3
3
|
// Order matters where names overlap: the first match wins.
|
|
4
4
|
export const API_PROVIDERS = [
|
|
5
5
|
// Voice, video and media
|
|
6
|
-
keyed(/\b(?:eleven\s*labs|11\s*labs)\b/i, "xi-api-key", "https://api.elevenlabs.io"),
|
|
7
|
-
keyed(/\bheygen\b/i, "X-Api-Key", "https://api.heygen.com"),
|
|
6
|
+
{ ...keyed(/\b(?:eleven\s*labs|11\s*labs)\b/i, "xi-api-key", "https://api.elevenlabs.io"), automatic: true },
|
|
7
|
+
{ ...keyed(/\bheygen\b/i, "X-Api-Key", "https://api.heygen.com"), automatic: true },
|
|
8
8
|
bearer(/\breplicate\b/i, "https://api.replicate.com"),
|
|
9
9
|
// Model providers and routers
|
|
10
10
|
bearer(/\bopen\s*router\b/i, "https://openrouter.ai"),
|
|
@@ -46,3 +46,17 @@ export const API_PROVIDERS = [
|
|
|
46
46
|
export function apiProviderFor(name) {
|
|
47
47
|
return API_PROVIDERS.find((provider) => provider.name.test(name));
|
|
48
48
|
}
|
|
49
|
+
/** Match only verified HTTPS origins, never labels or host suffixes.
|
|
50
|
+
* Docs: https://elevenlabs.io/docs/api-reference/authentication
|
|
51
|
+
* https://www.heygen.com/integrations */
|
|
52
|
+
// Legacy items have no provenance. Only the exact former default pair is
|
|
53
|
+
// treated as automatic; non-default headers OR prefixes remain custom.
|
|
54
|
+
export function vaultAuthMode(saved) {
|
|
55
|
+
return saved.authMode ?? ((saved.header ?? "Authorization").toLowerCase() === "authorization" && (saved.prefix ?? "Bearer ") === "Bearer " ? "auto" : "custom");
|
|
56
|
+
}
|
|
57
|
+
export function apiAuthFor(destination, saved) {
|
|
58
|
+
if (vaultAuthMode(saved) === "custom")
|
|
59
|
+
return saved;
|
|
60
|
+
const origin = new URL(destination).origin;
|
|
61
|
+
return API_PROVIDERS.find((provider) => provider.automatic && provider.origins.includes(origin)) ?? saved;
|
|
62
|
+
}
|
|
@@ -49,7 +49,8 @@ export const vaultInputSchema = z.discriminatedUnion("kind", [
|
|
|
49
49
|
// with no website): it is stored, and no bot can send it anywhere until
|
|
50
50
|
// its owner adds an address.
|
|
51
51
|
z.object({ ...base, kind: z.literal("apiKey"), origins: z.array(origin).max(50),
|
|
52
|
-
|
|
52
|
+
authMode: z.enum(["auto", "custom"]).optional(),
|
|
53
|
+
header: z.string().regex(/^[A-Za-z0-9-]{1,64}$/).default("Authorization"), prefix: z.string().regex(/^[\x20-\x7E]{0,32}$/).default("Bearer "),
|
|
53
54
|
secret: z.string().regex(/^[\x21-\x7E]{1,8192}$/),
|
|
54
55
|
}).strict(),
|
|
55
56
|
]);
|
|
@@ -62,7 +63,7 @@ export function vaultMetadata(item) {
|
|
|
62
63
|
...(item.kind === "login" ? { username: item.username } : {}),
|
|
63
64
|
...(item.kind === "card" ? { lastFour: item.number.slice(-4), expiryMonth: item.expiryMonth, expiryYear: item.expiryYear, billing: { ...item.billing } } : {}),
|
|
64
65
|
...(item.kind === "contact" ? { address: { ...item.address }, email: item.email, phone: item.phone } : {}),
|
|
65
|
-
...(item.kind === "apiKey" ? { header: item.header, prefix: item.prefix } : {}),
|
|
66
|
+
...(item.kind === "apiKey" ? { header: item.header, prefix: item.prefix, ...(item.authMode ? { authMode: item.authMode } : {}) } : {}),
|
|
66
67
|
createdAt: item.createdAt, updatedAt: item.updatedAt,
|
|
67
68
|
};
|
|
68
69
|
}
|