@chibitek/chibi 0.1.191 → 0.1.193
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-BtDirrJJ.js} +1 -1
- package/dist/assets/{abnfDiagram-O67JEVCF-CPvuUneJ.js → abnfDiagram-O67JEVCF-C37-IeyR.js} +1 -1
- package/dist/assets/{arc-aMP_0t5b.js → arc-glzbadrM.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-yyXrFi66.js → architectureDiagram-NJMV4G6O-Bcx1rmTd.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-BQN3ZvRc.js → blockDiagram-BEXU5L5S-B6KUNaLE.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-BieilTo4.js → c4Diagram-YGBWAQC7-DZ__tNnZ.js} +1 -1
- package/dist/assets/channel-C2UiHr1q.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-Df4lxXIM.js → chunk-2Q5K7J3B-Dn-yLeEA.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-su_KXf5y.js → chunk-3FUC2YCW-BB0MhLD8.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-DL3rM5tY.js → chunk-5VM5RSS4-B0MU1Lq4.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-53Ovfw1t.js → chunk-GTNCS2PH-BmT88VI9.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-BkeiDfwS.js → chunk-GWA4HPMP-hgdMCsOk.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-CvsdGjCO.js → chunk-JWPE2WC7-zlkz0m7Z.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-BngSjMee.js → chunk-NETBCI7D-Dz15-399.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-DitKn6fq.js → chunk-WEXAMYUT-CrWvQLTH.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-Czjvl52d.js → chunk-XXDRQBXY-BRuLbyd6.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-COr4Qzpk.js → classDiagram-v2-NBCMYWYE-BoexnyNG.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-Eg0tlzqp.js → cose-bilkent-JH36ORCC-CPTjVRUh.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-BjtG84WL.js → cynefin-OW5HDTMX-DtqtEAnC.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-BzZtwDD4.js → cynefinDiagram-VND7K2PF-BVP8JLg8.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-TrLQ507j.js → dagre-6A5THRUB-BBDMxGXp.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-BDQDC-33.js → diagram-22UHCM2B-BRZ8cAsI.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-Cm_mzSfE.js → diagram-3UASUU5V-D3lhs7ty.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-CAI_i4oy.js → diagram-ATOU4E4O-n8v1YvKt.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-9GjNyQXn.js → diagram-CDSNMT55-B6jeaO-z.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-ETDg4UN-.js → diagram-MLGK6HIB-BLmKtNgD.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-8_8dZKgW.js → diagram-MPIPVDR6-CNWlEkJQ.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-BiYh2ZYM.js → ebnfDiagram-ZINNZB2B-C0uBXIgJ.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-5u6sMYIg.js → elk-276RUBZZ-DCjvJpgP.js} +1 -1
- package/dist/assets/{erDiagram-OPXOYQCR-Dm6semJ3.js → erDiagram-OPXOYQCR-BryVWOsq.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-DbQ12CeV.js → flowDiagram-KWPJA3E3-Cq-t83b3.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP-C12s51S6.js → ganttDiagram-FUAMR5RP-4vyfI4a8.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-BhkwBL2T.js → gitGraphDiagram-X574FWY7-DxZIWlPq.js} +1 -1
- package/dist/assets/{index-D4BfC2Zf.js → index-C2Rnf5Lg.js} +1 -1
- package/dist/assets/{index-WT8Xwc4G.js → index-DtMmBnv1.js} +163 -163
- package/dist/assets/{infoDiagram-VRGFBTTK-IvWqyiSM.js → infoDiagram-VRGFBTTK-CdS4oDZm.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-N2ZxLyoE.js → ishikawaDiagram-OU5B5YK6-7FJ6XPAt.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-UWy3ala_.js → journeyDiagram-ZHPQQLJL-DK5jSuP5.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-Cutk-kDA.js → kanban-definition-PNTS6WVX-LSLVTPp1.js} +1 -1
- package/dist/assets/{linear-dPnV_-aA.js → linear-C8T48PcW.js} +1 -1
- package/dist/assets/{mermaid.core-QdldWb2L.js → mermaid.core-CajU6Pki.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-pkXW8CYn.js → mindmap-definition-NLK3R4M7-26gQ6jip.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-DhKkEQzV.js → pegDiagram-GJSIUBJH-rvhqKdDP.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-DMehGrxw.js → pieDiagram-5QR66LMP-BOFsvwEp.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-oNzYf4fg.js → quadrantDiagram-O4NWA36T-BGd_kb8s.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-pkMOwYja.js → railroadDiagram-XR7U4H2S-DROi1ea2.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-J29GrlJj.js → requirementDiagram-PLB6GJNP-BLFC_C4R.js} +1 -1
- package/dist/assets/{sankeyDiagram-IPEJSGJF-YuyCeGY6.js → sankeyDiagram-IPEJSGJF-bCdrWFYF.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-BjxLu0JW.js → sequenceDiagram-PO4LG4MO-CaCPCA52.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-BESOD3ec.js → sizeCapture-INFHLROL-DZr2YdGO.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-DF2yvbZA.js → stateDiagram-v2-GCMORJYK-BymY8iLv.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-Bzp4ze7n.js → swimlanes-2SLR337P-NumTJ1tl.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-CjJ-nT3Z.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-CnLbXs4R.js → timeline-definition-EJHVYXUP-d9-CUPKk.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-nuJhbhCv.js → usecaseDiagram-POWQR4AR-CGvoockc.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-D_hzVg9h.js → vennDiagram-UO4OBE2U-CUkwrnK7.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-hgmpI4iu.js → wardleyDiagram-VNRHLVJA-DALQej81.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-DwnJWdDn.js → xychartDiagram-PMCCYNJV-2oukzPo1.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/container-mcp.js +2 -1
- package/dist-server/index.js +642 -207
- package/dist-server/mcp-server.js +36 -1
- package/dist-server/openmausbot.js +257 -66
- package/dist-server/pair-cli.js +257 -66
- package/dist-server/server/atomic-engine-accounts.js +64 -12
- package/dist-server/server/atomic-engine-classes.js +30 -0
- package/dist-server/server/atomic-engine-local.js +41 -0
- package/dist-server/server/chibi-defaults.js +14 -8
- package/dist-server/server/config.js +1 -1
- package/dist-server/server/default-model-selection.js +7 -0
- package/dist-server/server/drivers/acp/custom.js +7 -2
- package/dist-server/server/editor-connect.js +39 -2
- package/dist-server/server/engine-tiers.js +19 -19
- package/dist-server/server/harness-import/engine-policy.js +4 -3
- package/dist-server/server/index.js +13 -13
- package/dist-server/server/model-gateway/failover.js +44 -0
- package/dist-server/server/model-gateway/ladder.js +29 -0
- package/dist-server/server/model-gateway/route.js +104 -0
- 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/plan-credit.js +67 -0
- package/dist-server/server/provider-accounts.js +3 -0
- package/dist-server/server/request-auth.js +3 -0
- package/dist-server/server/routes/provider-accounts.js +46 -5
- package/dist-server/server/vault/store.js +8 -4
- package/dist-server/shared/atomic-auto.js +10 -0
- package/dist-server/shared/engine-tiers.js +24 -8
- package/dist-server/shared/harness-weights.js +3 -1
- package/dist-server/shared/provider-accounts.js +42 -5
- package/dist-server/shared/vault-api-providers.js +23 -2
- package/dist-server/shared/vault.js +3 -2
- package/dist-server/vps-container-mcp.js +2 -1
- 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() {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Included monthly credit on a provider account (shared/provider-accounts.ts,
|
|
2
|
+
// PlanTerms "includedCredit"). Ollama's Team plan includes $1,000 a month;
|
|
3
|
+
// unused credit is lost at month end and use past it is billed by Ollama
|
|
4
|
+
// (Erick, 2026-11-15). Atomic tracks the credit against its own usage ledger
|
|
5
|
+
// (server/usage-ledger.ts): the reported or estimated cost of every turn that
|
|
6
|
+
// account ran this calendar month (UTC, like the spend cap in server/spend.ts).
|
|
7
|
+
// While credit is left the account is a subscription. Once it is used up an
|
|
8
|
+
// overage plan walks with the pay-per-use keys, so the one-time pay-per-use
|
|
9
|
+
// notice opens before any overage is spent. The month rolls over on its own:
|
|
10
|
+
// nothing carries over.
|
|
11
|
+
import { accountProvider, billingWithCredit, planTerms } from "../shared/provider-accounts.js";
|
|
12
|
+
import { readUsage } from "./usage-ledger.js";
|
|
13
|
+
const CACHE_MS = 15_000;
|
|
14
|
+
const cache = new Map();
|
|
15
|
+
const monthOf = (now) => now.toISOString().slice(0, 7);
|
|
16
|
+
const costOf = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0);
|
|
17
|
+
/** Cost booked this month per engine instance, read at most every CACHE_MS. */
|
|
18
|
+
export function monthToDateByInstance(dataDir, now = new Date()) {
|
|
19
|
+
const month = monthOf(now);
|
|
20
|
+
const hit = cache.get(dataDir);
|
|
21
|
+
if (hit && hit.month === month && now.getTime() - hit.at < CACHE_MS)
|
|
22
|
+
return hit.byInstance;
|
|
23
|
+
const from = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
24
|
+
const byInstance = new Map();
|
|
25
|
+
for (const row of readUsage(dataDir, { from, to: now })) {
|
|
26
|
+
byInstance.set(row.instanceId, (byInstance.get(row.instanceId) ?? 0) + costOf(row.costUsd));
|
|
27
|
+
}
|
|
28
|
+
cache.set(dataDir, { at: now.getTime(), month, byInstance });
|
|
29
|
+
return byInstance;
|
|
30
|
+
}
|
|
31
|
+
/** Forget the cached month (tests, and after a ledger restore). */
|
|
32
|
+
export function resetPlanCreditCache() {
|
|
33
|
+
cache.clear();
|
|
34
|
+
}
|
|
35
|
+
/** The provider an instance is paid through: its added account, else the
|
|
36
|
+
* key-based provider whose driver it runs (the Ollama Cloud main key). */
|
|
37
|
+
function providerOf(entry) {
|
|
38
|
+
if (entry.account !== undefined)
|
|
39
|
+
return accountProvider(entry.account);
|
|
40
|
+
return accountProvider(entry.driver === "ollamaCloud" ? "ollamaCloud" : undefined);
|
|
41
|
+
}
|
|
42
|
+
/** This account's credit this month, when it has an included-credit plan and
|
|
43
|
+
* a monthly figure (the account's own, else the plan's). Undefined otherwise:
|
|
44
|
+
* then the account is paid exactly as its provider row says. */
|
|
45
|
+
export function planCredit(instanceId, entry, spent) {
|
|
46
|
+
const provider = providerOf(entry);
|
|
47
|
+
if (!provider)
|
|
48
|
+
return undefined;
|
|
49
|
+
const terms = planTerms(provider);
|
|
50
|
+
if (terms.kind !== "includedCredit")
|
|
51
|
+
return undefined;
|
|
52
|
+
const monthlyCreditUsd = entry.planCreditUsd ?? terms.monthlyCreditUsd;
|
|
53
|
+
if (monthlyCreditUsd === undefined || !(monthlyCreditUsd > 0))
|
|
54
|
+
return undefined;
|
|
55
|
+
const spentUsd = spent.get(instanceId) ?? 0;
|
|
56
|
+
const leftUsd = Math.max(0, monthlyCreditUsd - spentUsd);
|
|
57
|
+
return { monthlyCreditUsd, spentUsd, leftUsd, billing: billingWithCredit(terms, monthlyCreditUsd - spentUsd) };
|
|
58
|
+
}
|
|
59
|
+
/** How an engine is paid now: its included credit while that decides, else
|
|
60
|
+
* the billing of the provider account it was added as. Undefined for an
|
|
61
|
+
* engine that is not an account and has no credit (its driver decides). */
|
|
62
|
+
export function accountBilling(instanceId, entry, dataDir) {
|
|
63
|
+
if (!entry)
|
|
64
|
+
return undefined;
|
|
65
|
+
const credit = planCredit(instanceId, entry, monthToDateByInstance(dataDir));
|
|
66
|
+
return credit?.billing ?? (entry.account === undefined ? undefined : accountProvider(entry.account)?.billing);
|
|
67
|
+
}
|
|
@@ -26,6 +26,9 @@ export const addAccountSchema = z.object({
|
|
|
26
26
|
owner: z.enum(["company", "personal"]).optional(),
|
|
27
27
|
}).strict();
|
|
28
28
|
export const renameAccountSchema = z.object({ displayName }).strict();
|
|
29
|
+
/** PATCH body that sets (a number) or clears (null) an account's included
|
|
30
|
+
* monthly credit. */
|
|
31
|
+
export const planCreditSchema = z.object({ planCreditUsd: z.number().positive().max(1_000_000).nullable() }).strict();
|
|
29
32
|
export const accountKeySchema = z.object({ key }).strict();
|
|
30
33
|
const DEFAULT_HOME = {
|
|
31
34
|
CODEX_HOME: ".codex",
|
|
@@ -338,6 +338,9 @@ export const ASSISTANT_ALLOW = [
|
|
|
338
338
|
{ methods: ["POST"], path: /^\/api\/groups\/[\w-]+\/messages$/ },
|
|
339
339
|
{ methods: ["POST"], path: /^\/api\/bots$/, create: true },
|
|
340
340
|
{ methods: ["POST"], path: /^\/api\/groups$/, create: true },
|
|
341
|
+
// Atomic as a model source, `atomic/auto` (server/model-gateway/route.ts).
|
|
342
|
+
{ methods: ["GET"], path: /^\/api\/v1\/models$/ },
|
|
343
|
+
{ methods: ["POST"], path: /^\/api\/v1\/(?:responses|chat\/completions|messages)$/ },
|
|
341
344
|
];
|
|
342
345
|
export function assistantAllowed(method, path, assistant) {
|
|
343
346
|
const upper = method.toUpperCase();
|
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import { ACCOUNT_PROVIDERS, accountProvider } from "../../shared/provider-accounts.js";
|
|
1
|
+
import { ACCOUNT_PROVIDERS, accountProvider, planTerms } from "../../shared/provider-accounts.js";
|
|
2
|
+
import { monthToDateByInstance, planCredit, resetPlanCreditCache } from "../plan-credit.js";
|
|
2
3
|
import { persistableInstanceConfigs } from "../config.js";
|
|
3
4
|
import { instanceKeys, removeInstanceKey, saveInstanceKey } from "../instance-keys.js";
|
|
4
|
-
import { accountHome, accountKeySchema, accountProviderFor, addAccountSchema, homeSignInCommand, newApiKeyAccount, newSignInAccount, renameAccountSchema, } from "../provider-accounts.js";
|
|
5
|
+
import { accountHome, accountKeySchema, accountProviderFor, addAccountSchema, homeSignInCommand, newApiKeyAccount, newSignInAccount, planCreditSchema, renameAccountSchema, } from "../provider-accounts.js";
|
|
5
6
|
import { PASS } from "./table.js";
|
|
6
7
|
const ACCOUNT = /^\/api\/provider-accounts\/([\w.-]+)(?:\/(key|test))?$/;
|
|
7
8
|
function removable(instanceId, entry) {
|
|
8
9
|
// Claude accounts added before this registry carry no marker.
|
|
9
10
|
return entry.account !== undefined || (entry.driver === "claudeAgent" && instanceId !== "claude");
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
/** An included-credit account's figure and this month's use of it. */
|
|
13
|
+
function creditFields(instanceId, entry, spent) {
|
|
14
|
+
const credit = planCredit(instanceId, entry, spent);
|
|
15
|
+
return {
|
|
16
|
+
...(entry.planCreditUsd !== undefined ? { planCreditUsd: entry.planCreditUsd } : {}),
|
|
17
|
+
...(credit ? { planCredit: credit } : {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function account(provider, instanceId, entry, described, owner, spent) {
|
|
12
21
|
const tag = owner?.(instanceId);
|
|
13
22
|
const base = {
|
|
23
|
+
...(planTerms(provider).kind === "includedCredit" ? creditFields(instanceId, entry, spent) : {}),
|
|
14
24
|
instanceId,
|
|
15
25
|
...(tag ? { owner: tag.owner, ownerLocked: tag.locked } : {}),
|
|
16
26
|
displayName: described?.displayName ?? entry.displayName ?? provider.label,
|
|
@@ -44,6 +54,10 @@ function account(provider, instanceId, entry, described, owner) {
|
|
|
44
54
|
async function listing(deps) {
|
|
45
55
|
const instances = persistableInstanceConfigs(deps.config());
|
|
46
56
|
const described = new Map((await deps.describe()).map((instance) => [instance.instanceId, instance]));
|
|
57
|
+
const spent = monthToDateByInstance(deps.dataDir);
|
|
58
|
+
// The Ollama Cloud key saved before accounts existed runs the built-in
|
|
59
|
+
// ollamaCloud engine, not an added account: its credit is listed here.
|
|
60
|
+
const mainOllama = Object.entries(instances).find(([, entry]) => entry.driver === "ollamaCloud" && entry.account === undefined);
|
|
47
61
|
return {
|
|
48
62
|
providers: ACCOUNT_PROVIDERS.map((provider) => ({
|
|
49
63
|
id: provider.id,
|
|
@@ -56,7 +70,10 @@ async function listing(deps) {
|
|
|
56
70
|
...(provider.signupUrl ? { signupUrl: provider.signupUrl } : {}),
|
|
57
71
|
accounts: Object.entries(instances)
|
|
58
72
|
.filter(([, entry]) => accountProviderFor(entry)?.id === provider.id)
|
|
59
|
-
.map(([instanceId, entry]) => account(provider, instanceId, entry, described.get(instanceId), deps.owner)),
|
|
73
|
+
.map(([instanceId, entry]) => account(provider, instanceId, entry, described.get(instanceId), deps.owner, spent)),
|
|
74
|
+
...(provider.id === "ollamaCloud" && mainOllama
|
|
75
|
+
? { main: { instanceId: mainOllama[0], ...creditFields(mainOllama[0], mainOllama[1], spent) } }
|
|
76
|
+
: {}),
|
|
60
77
|
})),
|
|
61
78
|
};
|
|
62
79
|
}
|
|
@@ -186,7 +203,31 @@ export function createProviderAccountRoutes(deps) {
|
|
|
186
203
|
if (!entry || (!provider && method !== "PATCH"))
|
|
187
204
|
return json(res, 404, { error: "unknown account" });
|
|
188
205
|
if (method === "PATCH") {
|
|
189
|
-
const
|
|
206
|
+
const body = await readBody(req, 8_192);
|
|
207
|
+
if (body && typeof body === "object" && Object.hasOwn(body, "planCreditUsd")) {
|
|
208
|
+
const credit = planCreditSchema.safeParse(body);
|
|
209
|
+
if (!credit.success)
|
|
210
|
+
return json(res, 400, { error: "Enter the plan's monthly credit in dollars, more than 0." });
|
|
211
|
+
const paidThrough = entry.account !== undefined ? provider : entry.driver === "ollamaCloud" ? accountProvider("ollamaCloud") : undefined;
|
|
212
|
+
if (!paidThrough || planTerms(paidThrough).kind !== "includedCredit") {
|
|
213
|
+
return json(res, 400, { error: "This account's plan has no included monthly credit." });
|
|
214
|
+
}
|
|
215
|
+
if (!deps.lock())
|
|
216
|
+
return json(res, 409, { error: "Provider settings are already being updated." });
|
|
217
|
+
try {
|
|
218
|
+
if (credit.data.planCreditUsd === null)
|
|
219
|
+
delete entry.planCreditUsd;
|
|
220
|
+
else
|
|
221
|
+
entry.planCreditUsd = credit.data.planCreditUsd;
|
|
222
|
+
await deps.persist(instanceId, instances);
|
|
223
|
+
resetPlanCreditCache(); // show this month's use as of now
|
|
224
|
+
return json(res, 200, await listing(deps));
|
|
225
|
+
}
|
|
226
|
+
finally {
|
|
227
|
+
deps.unlock();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const parsed = renameAccountSchema.safeParse(body);
|
|
190
231
|
if (!parsed.success)
|
|
191
232
|
return json(res, 400, { error: "Enter an account name (up to 80 characters)." });
|
|
192
233
|
if (deps.busy(instanceId))
|
|
@@ -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)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// "Atomic Engine (Auto)" (Erick, 2026-11-15): Automatic and Atomic Engine's
|
|
2
|
+
// own Auto are one choice. In Atomic's picker it is the top row of the class
|
|
3
|
+
// menu (a bot or thread on its tier's ladder, which Atomic Engine leads);
|
|
4
|
+
// other harnesses (Claude Code, Codex) see it as the model id `atomic/auto`.
|
|
5
|
+
// The short form "Atomic Engine Auto" is for tight spaces; the Atomic Engine
|
|
6
|
+
// name is never dropped.
|
|
7
|
+
export const ATOMIC_AUTO_MODEL = "atomic/auto";
|
|
8
|
+
/** Atomic Engine's model id before 2026-11-15; a saved one still means Auto. */
|
|
9
|
+
export const LEGACY_ATOMIC_ENGINE_MODEL = "agent-default";
|
|
10
|
+
export const isAtomicAuto = (model) => model === ATOMIC_AUTO_MODEL || model === LEGACY_ATOMIC_ENGINE_MODEL;
|
|
@@ -47,18 +47,30 @@ export const DEFAULT_CLASS_BANDS = { Mezcal: 50, Plata: 44, Reposado: 38 };
|
|
|
47
47
|
* ("claude-<uuid>") reduced to its driver kind so a fresh install matches
|
|
48
48
|
* whatever account it has (matchesEngine); the exact engine+model
|
|
49
49
|
* duplicates that collapse created are dropped. */
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
|
|
50
|
+
/** Atomic Engine (Auto): the first rung of every tier's ladder, hand-written
|
|
51
|
+
* or generated, and the model Chibi and new bots are made on (Erick,
|
|
52
|
+
* 2026-11-15, replacing 2026-10-13's "Chibi runs on Claude"). The engine
|
|
53
|
+
* walks its own accounts (subscriptions, then local models, then pay per
|
|
54
|
+
* use) and fails over by itself; the rungs after it are the fallback when
|
|
55
|
+
* Atomic Engine is not installed, signed out or refused. */
|
|
56
|
+
export const ATOMIC_AUTO_RUNG = Object.freeze({ engine: "atomic-engine", model: "atomic/auto" });
|
|
57
|
+
/** Chibi's fallback on an install without Atomic Engine (Erick, 2026-11-13):
|
|
58
|
+
* Automatic, the Plata class, on Claude. It is the Orchestrator's rung right
|
|
59
|
+
* after Atomic Engine (Auto), hand-written or generated. The rung carries its
|
|
60
|
+
* class, so it must be a Plata model: Claude Opus 5 (Artificial Analysis
|
|
61
|
+
* medium 44.8, high 48.1: 46.5). It was Claude Sonnet 5.5 until 2026-11-15,
|
|
62
|
+
* which grades Reposado by Atomic's own rule (medium 40.8, high 46.8 on
|
|
63
|
+
* Intelligence Index v4.3.2: 43.8, under Plata's 44) and was only labelled
|
|
64
|
+
* Plata here. */
|
|
65
|
+
export const CHIBI_DEFAULT_RUNG = Object.freeze({ engine: "claudeAgent", model: "claude-opus-5", modelClass: "Plata" });
|
|
56
66
|
/** Raised whenever Chibi's default changes: each install whose Chibi holds
|
|
57
67
|
* an older number is put back on the default once, whatever it was set to
|
|
58
|
-
* (BotRecord.chibiDefaults, server/store.ts applyChibiDefaults).
|
|
59
|
-
|
|
68
|
+
* (BotRecord.chibiDefaults, server/store.ts applyChibiDefaults). 2: Atomic
|
|
69
|
+
* Engine (Auto) (2026-11-15). */
|
|
70
|
+
export const CHIBI_DEFAULTS_VERSION = 2;
|
|
60
71
|
export const DEFAULT_LADDERS = {
|
|
61
72
|
orchestrator: [
|
|
73
|
+
{ ...ATOMIC_AUTO_RUNG },
|
|
62
74
|
{ ...CHIBI_DEFAULT_RUNG },
|
|
63
75
|
{ engine: "claudeAgent", model: "claude-opus-5-5", modelClass: "Plata" },
|
|
64
76
|
{ engine: "codex", model: "gpt-6-sol" },
|
|
@@ -77,6 +89,7 @@ export const DEFAULT_LADDERS = {
|
|
|
77
89
|
{ engine: "hermesAgent", model: "openai-codex:gpt-6.1-sol", modelClass: "Plata" },
|
|
78
90
|
],
|
|
79
91
|
engineering: [
|
|
92
|
+
{ ...ATOMIC_AUTO_RUNG },
|
|
80
93
|
{ engine: "codex", model: "gpt-6-astra", modelClass: "Mezcal" },
|
|
81
94
|
{ engine: "claude", model: "claude-opus-5-5" },
|
|
82
95
|
{ engine: "claudeAgent", model: "claude-opus-5-5" },
|
|
@@ -92,6 +105,7 @@ export const DEFAULT_LADDERS = {
|
|
|
92
105
|
{ engine: "cursorAgent", model: "auto" },
|
|
93
106
|
],
|
|
94
107
|
research: [
|
|
108
|
+
{ ...ATOMIC_AUTO_RUNG },
|
|
95
109
|
{ engine: "openai-compat", model: "MiniMax-M2.5" },
|
|
96
110
|
{ engine: "vibe", model: "mistral-medium-3.5" },
|
|
97
111
|
{ engine: "antigravityAgent", model: "gemini-3.8-flash-low" },
|
|
@@ -105,6 +119,7 @@ export const DEFAULT_LADDERS = {
|
|
|
105
119
|
{ engine: "opencodeGo", model: "opencode/claude-opus-5", modelClass: "Plata" },
|
|
106
120
|
],
|
|
107
121
|
writing: [
|
|
122
|
+
{ ...ATOMIC_AUTO_RUNG },
|
|
108
123
|
{ engine: "claudeAgent", model: "claude-sonnet-5-5" },
|
|
109
124
|
{ engine: "claude", model: "claude-sonnet-5-5" },
|
|
110
125
|
{ engine: "codex", model: "gpt-5.6-luna" },
|
|
@@ -113,6 +128,7 @@ export const DEFAULT_LADDERS = {
|
|
|
113
128
|
{ engine: "hermes", model: "nous:moonshotai/kimi-k3" },
|
|
114
129
|
],
|
|
115
130
|
routine: [
|
|
131
|
+
{ ...ATOMIC_AUTO_RUNG },
|
|
116
132
|
{ engine: "antigravityAgent", model: "gemini-3.8-flash-low" },
|
|
117
133
|
{ engine: "antigravity", model: "gemini-3.8-flash-low" },
|
|
118
134
|
{ engine: "openai-compat", model: "MiniMax-M2.5" },
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* wrapper with no agent loop of its own is lowest. */
|
|
13
13
|
export const DEFAULT_HARNESS_WEIGHTS = {
|
|
14
14
|
claudeAgent: 1, codex: 1, grokAgent: 1, antigravityAgent: 1, museCode: 1, kimiAgent: 1, vibeAgent: 1, qwenAgent: 1,
|
|
15
|
-
|
|
15
|
+
// Atomic Engine is Hermes under the hood, run on the person's Atomic
|
|
16
|
+
// accounts: the same weight (Erick, 2026-11-15).
|
|
17
|
+
hermesAgent: 0.9, atomicEngine: 0.9,
|
|
16
18
|
cursorAgent: 0.8, opencodeGo: 0.8, droidAgent: 0.8,
|
|
17
19
|
ollamaCloud: 0.5, "openai-compat": 0.5, mistral: 0.5, minimax: 0.5,
|
|
18
20
|
};
|
|
@@ -60,16 +60,20 @@ export const ACCOUNT_PROVIDERS = [
|
|
|
60
60
|
config: {}, keyTest: { provider: "mistral" }, keyUrl: "https://console.mistral.ai/api-keys",
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
|
-
// Ollama's Free, Pro and
|
|
63
|
+
// Ollama's Free, Pro, Max and Team plans each include a monthly credit.
|
|
64
|
+
// Unused credit does not carry over (use it or lose it); use past it is
|
|
65
|
+
// billed by Ollama (Erick, 2026-11-15).
|
|
64
66
|
id: "ollamaCloud", kind: "apiKey", label: "Ollama Cloud", billing: "subscription", driver: "ollamaCloud", envVar: "OLLAMA_API_KEY", icon: "ollama",
|
|
65
67
|
config: {}, keyTest: { provider: "ollamaCloud" }, keyUrl: "https://ollama.com/settings/keys", signupUrl: "https://ollama.com/pricing",
|
|
68
|
+
plan: { kind: "includedCredit", unusedCredit: "expires", afterCredit: "overage" },
|
|
66
69
|
},
|
|
67
70
|
{
|
|
68
71
|
// Nous Portal's OpenAI-compatible API with a portal key: no Hermes needed
|
|
69
|
-
// (Erick, 2026-11-08).
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
|
|
72
|
+
// (Erick, 2026-11-08). Counted as the person's Nous subscription, not pay
|
|
73
|
+
// per use (Erick, 2026-11-15, reversing the 2026-11-13 per-use reading of
|
|
74
|
+
// Portal's terms): it walks with the subscriptions and Atomic Engine uses
|
|
75
|
+
// it as the `nous-api` provider (server/atomic-engine-accounts.ts).
|
|
76
|
+
id: "nous", kind: "apiKey", label: "Nous Research", billing: "subscription", driver: "openai-compat", envVar: "NOUS_API_KEY",
|
|
73
77
|
config: { url: "https://inference-api.nousresearch.com/v1", apiKeyEnv: "NOUS_API_KEY", model: "Hermes-4-405B", provider: "" },
|
|
74
78
|
keyTest: { provider: "openaiCompat", url: "https://inference-api.nousresearch.com/v1" }, keyUrl: "https://portal.nousresearch.com/", signupUrl: "https://portal.nousresearch.com/",
|
|
75
79
|
},
|
|
@@ -108,6 +112,39 @@ export const ACCOUNT_PROVIDERS = [
|
|
|
108
112
|
keyTest: { provider: "openaiCompat", url: "https://integrate.api.nvidia.com/v1" }, keyUrl: "https://build.nvidia.com/settings/api-keys", signupUrl: "https://build.nvidia.com/",
|
|
109
113
|
},
|
|
110
114
|
];
|
|
115
|
+
/** A provider's plan terms: its own `plan` when it names one, else read
|
|
116
|
+
* from `billing` (a sign-in is `signIn`, a subscription key a `flatPlan`). */
|
|
117
|
+
export function planTerms(provider) {
|
|
118
|
+
if (provider.kind === "signIn")
|
|
119
|
+
return { kind: "signIn" };
|
|
120
|
+
if (provider.plan)
|
|
121
|
+
return provider.plan;
|
|
122
|
+
if (provider.billing === "subscription")
|
|
123
|
+
return { kind: "flatPlan" };
|
|
124
|
+
return provider.billing === "free" ? { kind: "free" } : { kind: "perToken" };
|
|
125
|
+
}
|
|
126
|
+
/** The band an account is in this month. An included-credit plan is a
|
|
127
|
+
* subscription while credit is left (or while Atomic cannot tell); once the
|
|
128
|
+
* credit is used up, an `overage` plan bills per use and so walks with the
|
|
129
|
+
* pay-per-use keys, which opens the one-time notice. A `stops` plan stays a
|
|
130
|
+
* subscription and simply runs out like any other. Other terms keep their
|
|
131
|
+
* plain billing. */
|
|
132
|
+
export function billingWithCredit(terms, creditLeftUsd) {
|
|
133
|
+
switch (terms.kind) {
|
|
134
|
+
case "includedCredit":
|
|
135
|
+
return creditLeftUsd !== undefined && creditLeftUsd <= 0 && terms.afterCredit === "overage" ? "payPerUse" : "subscription";
|
|
136
|
+
case "perToken":
|
|
137
|
+
return "payPerUse";
|
|
138
|
+
case "free":
|
|
139
|
+
return "free";
|
|
140
|
+
default:
|
|
141
|
+
return "subscription";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Ollama's Team plan includes this much credit each month (Erick,
|
|
145
|
+
* 2026-11-15). Free, Pro and Max differ and are not tracked unless the person
|
|
146
|
+
* enters their own figure. */
|
|
147
|
+
export const OLLAMA_TEAM_MONTHLY_CREDIT_USD = 1000;
|
|
111
148
|
export function accountProvider(id) {
|
|
112
149
|
return ACCOUNT_PROVIDERS.find((provider) => provider.id === id);
|
|
113
150
|
}
|
|
@@ -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,24 @@ 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
|
+
const origin = new URL(destination).origin;
|
|
59
|
+
const provider = API_PROVIDERS.find((candidate) => candidate.automatic && candidate.origins.includes(origin));
|
|
60
|
+
// Changing the old Authorization default to a vendor key header could
|
|
61
|
+
// leave its Bearer prefix behind. These verified key headers take raw keys,
|
|
62
|
+
// including when the saved item explicitly uses custom mode.
|
|
63
|
+
if (provider?.prefix === "" && saved.header.toLowerCase() === provider.header.toLowerCase() && saved.prefix === "Bearer ") {
|
|
64
|
+
return { header: saved.header, prefix: "" };
|
|
65
|
+
}
|
|
66
|
+
if (vaultAuthMode(saved) === "custom")
|
|
67
|
+
return saved;
|
|
68
|
+
return provider ?? saved;
|
|
69
|
+
}
|