@chibitek/chibi 0.1.188 → 0.1.190

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.
Files changed (85) hide show
  1. package/dist/assets/{abnfDiagram-O67JEVCF-CKDXgnYw.js → abnfDiagram-O67JEVCF-Bz3wlNsQ.js} +1 -1
  2. package/dist/assets/{arc--VPK-xet.js → arc-CX0dJSa0.js} +1 -1
  3. package/dist/assets/{architectureDiagram-NJMV4G6O-DSVjpq7n.js → architectureDiagram-NJMV4G6O-APIM9yGf.js} +1 -1
  4. package/dist/assets/{blockDiagram-BEXU5L5S-BiQ1JgSl.js → blockDiagram-BEXU5L5S-DNmNNaVY.js} +1 -1
  5. package/dist/assets/{c4Diagram-YGBWAQC7-kWWEc-NZ.js → c4Diagram-YGBWAQC7-CAPPUeMU.js} +1 -1
  6. package/dist/assets/channel-CnfDal05.js +1 -0
  7. package/dist/assets/{chunk-2Q5K7J3B-QJYqMtWJ.js → chunk-2Q5K7J3B-DfCDsQgU.js} +1 -1
  8. package/dist/assets/{chunk-3FUC2YCW-C7oGYTZS.js → chunk-3FUC2YCW-vdffwGmy.js} +2 -2
  9. package/dist/assets/{chunk-5VM5RSS4-MahQWTzh.js → chunk-5VM5RSS4-BazIL_2e.js} +1 -1
  10. package/dist/assets/{chunk-GTNCS2PH-CQfOvr7l.js → chunk-GTNCS2PH-GpKjNZ-V.js} +1 -1
  11. package/dist/assets/{chunk-GWA4HPMP-b0lt02Pi.js → chunk-GWA4HPMP-BuRq21LZ.js} +1 -1
  12. package/dist/assets/{chunk-JWPE2WC7-J1_ylbx8.js → chunk-JWPE2WC7-CqNGOyHV.js} +1 -1
  13. package/dist/assets/{chunk-NETBCI7D-AWcL9tld.js → chunk-NETBCI7D-B1DpzVCP.js} +1 -1
  14. package/dist/assets/{chunk-WEXAMYUT-DpTrAXJV.js → chunk-WEXAMYUT-DcH1Euc6.js} +1 -1
  15. package/dist/assets/{chunk-XXDRQBXY-2_DCjtc9.js → chunk-XXDRQBXY-M1JLd_cm.js} +1 -1
  16. package/dist/assets/{classDiagram-v2-NBCMYWYE-BBQMtHHs.js → classDiagram-v2-NBCMYWYE-C8mBZ7i2.js} +1 -1
  17. package/dist/assets/{cose-bilkent-JH36ORCC-CmxRmDe8.js → cose-bilkent-JH36ORCC-Cr3TqHDz.js} +1 -1
  18. package/dist/assets/{cynefin-OW5HDTMX-DjlothXK.js → cynefin-OW5HDTMX-BKPr6l0I.js} +1 -1
  19. package/dist/assets/{cynefinDiagram-VND7K2PF-D6HfzP26.js → cynefinDiagram-VND7K2PF-Cbg5mrIM.js} +1 -1
  20. package/dist/assets/{dagre-6A5THRUB-BtzaxY50.js → dagre-6A5THRUB-9I9X1J3r.js} +1 -1
  21. package/dist/assets/{diagram-22UHCM2B-DsyCiGJD.js → diagram-22UHCM2B-B43b8pqQ.js} +1 -1
  22. package/dist/assets/{diagram-3UASUU5V-CjjvxIr3.js → diagram-3UASUU5V-CIehgEkZ.js} +1 -1
  23. package/dist/assets/{diagram-ATOU4E4O-DDu2iVRb.js → diagram-ATOU4E4O-gx8nkXLZ.js} +1 -1
  24. package/dist/assets/{diagram-CDSNMT55-BBTViw3h.js → diagram-CDSNMT55-BZzWgYHa.js} +1 -1
  25. package/dist/assets/{diagram-MLGK6HIB-D83j4C6w.js → diagram-MLGK6HIB-BqoCqkZD.js} +1 -1
  26. package/dist/assets/{diagram-MPIPVDR6-DTpmpL8Q.js → diagram-MPIPVDR6-Bsc7x0UT.js} +1 -1
  27. package/dist/assets/{ebnfDiagram-ZINNZB2B-D3B4hz_Y.js → ebnfDiagram-ZINNZB2B-8HjdD_s8.js} +1 -1
  28. package/dist/assets/{elk-276RUBZZ-CbNicGf_.js → elk-276RUBZZ-bmxiEFtT.js} +1 -1
  29. package/dist/assets/{erDiagram-OPXOYQCR-DeSwxwFC.js → erDiagram-OPXOYQCR-BU-sRLe3.js} +1 -1
  30. package/dist/assets/{flowDiagram-KWPJA3E3-3n_Hk-ZR.js → flowDiagram-KWPJA3E3-D45vn40U.js} +1 -1
  31. package/dist/assets/{ganttDiagram-FUAMR5RP-BsadEPTf.js → ganttDiagram-FUAMR5RP-CArB98Hu.js} +1 -1
  32. package/dist/assets/{gitGraphDiagram-X574FWY7-DOvqN3Jh.js → gitGraphDiagram-X574FWY7-fPB1k-W7.js} +1 -1
  33. package/dist/assets/{index-B9LCl5y3.js → index-QsXeEMxJ.js} +71 -71
  34. package/dist/assets/{index-BmYLMFD8.js → index-u1wvoacp.js} +1 -1
  35. package/dist/assets/{infoDiagram-VRGFBTTK-CI3tfMt9.js → infoDiagram-VRGFBTTK-ZRVWXAr4.js} +1 -1
  36. package/dist/assets/{ishikawaDiagram-OU5B5YK6-BE7AjZYf.js → ishikawaDiagram-OU5B5YK6-DOaurRbX.js} +1 -1
  37. package/dist/assets/{journeyDiagram-ZHPQQLJL-DplNZPox.js → journeyDiagram-ZHPQQLJL-Ca9B-09w.js} +1 -1
  38. package/dist/assets/{kanban-definition-PNTS6WVX-Cos64we-.js → kanban-definition-PNTS6WVX-CA2XswEJ.js} +1 -1
  39. package/dist/assets/{linear-DDfQb-jo.js → linear-B-F7icip.js} +1 -1
  40. package/dist/assets/{mermaid.core-BekbnuLb.js → mermaid.core-ymtCpbZ5.js} +5 -5
  41. package/dist/assets/{mindmap-definition-NLK3R4M7-DJ0MbzMW.js → mindmap-definition-NLK3R4M7-02vIazCi.js} +1 -1
  42. package/dist/assets/{pegDiagram-GJSIUBJH-DZNZCZ4O.js → pegDiagram-GJSIUBJH-DRb7Pn72.js} +1 -1
  43. package/dist/assets/{pieDiagram-5QR66LMP-COD5v2yC.js → pieDiagram-5QR66LMP-B2YwP3S_.js} +1 -1
  44. package/dist/assets/{quadrantDiagram-O4NWA36T-D4dlLWfv.js → quadrantDiagram-O4NWA36T-CbR573mu.js} +1 -1
  45. package/dist/assets/{railroadDiagram-XR7U4H2S-CEpVYFKl.js → railroadDiagram-XR7U4H2S-CqHuDCnM.js} +1 -1
  46. package/dist/assets/{requirementDiagram-PLB6GJNP-DYD5GX0G.js → requirementDiagram-PLB6GJNP-BSeC-H1j.js} +1 -1
  47. package/dist/assets/{sankeyDiagram-IPEJSGJF-C9bPeTfK.js → sankeyDiagram-IPEJSGJF-BMFuhoh1.js} +1 -1
  48. package/dist/assets/{sequenceDiagram-PO4LG4MO-eXpmPg9C.js → sequenceDiagram-PO4LG4MO-DRT_EI9u.js} +1 -1
  49. package/dist/assets/{sizeCapture-INFHLROL-DfqKWBhp.js → sizeCapture-INFHLROL-BLFT4fV7.js} +1 -1
  50. package/dist/assets/{stateDiagram-v2-GCMORJYK-DkIf90iA.js → stateDiagram-v2-GCMORJYK-C8vB_69H.js} +1 -1
  51. package/dist/assets/{swimlanes-2SLR337P-Ds64cQxN.js → swimlanes-2SLR337P-T6BBolT8.js} +1 -1
  52. package/dist/assets/swimlanesDiagram-TC7HE7FX-BIY4fGCv.js +8 -0
  53. package/dist/assets/{timeline-definition-EJHVYXUP-Ci3-31qT.js → timeline-definition-EJHVYXUP-DjdjBRQV.js} +1 -1
  54. package/dist/assets/{usecaseDiagram-POWQR4AR-DQUGgfBf.js → usecaseDiagram-POWQR4AR-CDGccZMN.js} +1 -1
  55. package/dist/assets/{vennDiagram-UO4OBE2U-DV5_nmWl.js → vennDiagram-UO4OBE2U-CgYSihtW.js} +1 -1
  56. package/dist/assets/{wardleyDiagram-VNRHLVJA-DatPTthc.js → wardleyDiagram-VNRHLVJA-Bub5ScM8.js} +1 -1
  57. package/dist/assets/{xychartDiagram-PMCCYNJV-ADaxt1QH.js → xychartDiagram-PMCCYNJV-DK5iMX67.js} +1 -1
  58. package/dist/index.html +1 -1
  59. package/dist-server/drivers/agents-proxy.js +14 -4
  60. package/dist-server/index.js +3545 -3026
  61. package/dist-server/openmausbot.js +1378 -844
  62. package/dist-server/pair-cli.js +1378 -844
  63. package/dist-server/server/browser-runtime.js +41 -5
  64. package/dist-server/server/chibi-defaults.js +96 -0
  65. package/dist-server/server/cli-login.js +4 -0
  66. package/dist-server/server/connection-cap-failover.js +0 -2
  67. package/dist-server/server/drivers/agents-vault.js +4 -3
  68. package/dist-server/server/engine-tiers.js +4 -4
  69. package/dist-server/server/hidden-ai-text.js +56 -0
  70. package/dist-server/server/index.js +21 -27
  71. package/dist-server/server/system-prompt.js +17 -2
  72. package/dist-server/server/vault/fill.js +338 -0
  73. package/dist-server/server/vault/request.js +6 -2
  74. package/dist-server/server/vault/routes.js +14 -2
  75. package/dist-server/server/vault/runtime.js +14 -0
  76. package/dist-server/server/vault/store.js +40 -3
  77. package/dist-server/shared/engine-tiers.js +23 -1
  78. package/dist-server/shared/provider-accounts.js +5 -3
  79. package/dist-server/shared/subscription-bots.js +14 -6
  80. package/dist-server/shared/vault-api-providers.js +48 -0
  81. package/dist-server/shared/vault-csv.js +62 -14
  82. package/dist-server/shared/vault.js +14 -3
  83. package/package.json +1 -1
  84. package/dist/assets/channel-CQdxuHwI.js +0 -1
  85. package/dist/assets/swimlanesDiagram-TC7HE7FX-bO3Klz6Z.js +0 -8
@@ -0,0 +1,338 @@
1
+ // Trusted login fill for the built-in browser. A bot names a Vault login;
2
+ // Atomic checks the grant against the page's real address, finds the sign-in
3
+ // fields itself and types the username and password. The bot never receives
4
+ // the password, and for as long as that browser session lives every way it
5
+ // could read the page back is guarded:
6
+ //
7
+ // - page JavaScript (eval) and copy/cut shortcuts are refused;
8
+ // - the password is removed from every text result (snapshot, read, text,
9
+ // url, title), in plain and URL-encoded form;
10
+ // - a screenshot is withheld while the password is readable on the page,
11
+ // and is never written to a path the bot chose;
12
+ // - a password field the bot edited is emptied before anything else runs,
13
+ // so an edited copy of the password can never be shown and read;
14
+ // - while the password is readable on the page, only looking and clicking
15
+ // work, so it cannot be edited or probed there either.
16
+ //
17
+ // This guards Atomic's browser tools. An engine with a shell on this
18
+ // computer can reach the browser by other means; that is the limit the Vault
19
+ // spec states, not one this module removes.
20
+ import { randomBytes } from "node:crypto";
21
+ import { mkdirSync, readFileSync } from "node:fs";
22
+ import { dirname } from "node:path";
23
+ import { writeFileAtomic } from "../atomic.js";
24
+ import { vaultOrigin } from "../../shared/vault.js";
25
+ import { VaultError } from "./store.js";
26
+ export const VAULT_FILL_TOOL = "vault_fill_login";
27
+ export const vaultFillTool = {
28
+ name: VAULT_FILL_TOOL,
29
+ description: "Sign in with a login saved in the person's Atomic Vault. Atomic types the username and password into the sign-in form on the current page itself, so you never see the password. Open the site's sign-in page first; it must be on the item's website. Item ids come from vault_request with no arguments. Then click the sign-in button. After a fill, eval and copy shortcuts are off in this browser.",
30
+ inputSchema: {
31
+ type: "object",
32
+ properties: { item_id: { type: "string", description: "The login's id from vault_request." } },
33
+ required: ["item_id"],
34
+ additionalProperties: false,
35
+ },
36
+ };
37
+ /** Advertise the fill tool beside the engine's own. */
38
+ export function withVaultFillTool(list) {
39
+ if (!list || typeof list !== "object" || !Array.isArray(list.tools))
40
+ return list;
41
+ return { ...list, tools: [...list.tools, vaultFillTool] };
42
+ }
43
+ const REFUSED = "This bot may not use that Vault login on this page. vault_request with no arguments lists each login's website.";
44
+ const EVAL_OFF = "Page JavaScript is off in this browser because a Vault password was filled. Use snapshot, click, fill and the other browser tools, or close the browser to start clean.";
45
+ const COPY_OFF = "Copy and cut shortcuts are off in this browser because a Vault password was filled.";
46
+ const SHOT_WITHHELD = "Screenshot withheld: a Vault password is readable on this page. Hide the password field's text, or use snapshot, which has it removed.";
47
+ const VALUE_SELECTOR_OFF = "Selectors that match on a field's value are off in this browser because a Vault password was filled. Select by id, name, role or label.";
48
+ const VALUE_SELECTOR = /\[\s*value\b|@value\b/i;
49
+ export const SCREENSHOT_WITHHELD = { content: [{ type: "text", text: SHOT_WITHHELD }], isError: true };
50
+ const ALTERED = "The password field was changed after Atomic filled it, so Atomic emptied it. Call vault_fill_login again to sign in. Until this browser is closed, a password field on this site only accepts a Vault fill.";
51
+ const SHOWN = "A Vault password is readable on this page, so only looking and clicking work here: snapshot, get_text, click and scroll by @ref or CSS selector, navigation, tabs and close. Hide the password, sign in or leave the page to continue.";
52
+ const UNREADABLE = "Atomic could not check this page for a filled Vault password, so only looking and clicking work until it can: snapshot, get_text, click and scroll by @ref or CSS selector, navigation, tabs and close.";
53
+ /** What a bot may still call while the password is readable on the page.
54
+ * Nothing here types, presses a key or matches on the page's text. */
55
+ const LOOK_ONLY = new Set(["snapshot", "get_text", "get_url", "get_title", "click", "scroll", "wait_ms", "wait_for_selector", "wait_for_load", "open", "back", "forward", "reload", "tab_new", "tab_list", "tab_switch", "tab_close", "tools_profiles"].map((name) => `agent_browser_${name}`));
56
+ /** A selector that matches on text answers yes or no about what the page shows. */
57
+ const TEXT_SELECTOR = /text|contains\s*\(/i;
58
+ const STALE = "This browser still holds a Vault password from before Atomic restarted. Close the browser with agent_browser_close, then open the page again.";
59
+ const COPY_KEYS = /^(?:(?:meta|control|ctrl|cmd|command)\+(?:shift\+)?(?:c|x|insert)|copy|cut)$/i;
60
+ const text = (value, isError = false) => ({ content: [{ type: "text", text: value }], ...(isError ? { isError: true } : {}) });
61
+ const textOf = (result) => (Array.isArray(result.content) ? result.content : [])
62
+ .map((part) => part && typeof part === "object" && typeof part.text === "string" ? part.text : "").join("\n");
63
+ /** Run a script that reports through one base64 marker, so the answer reads
64
+ * the same however the engine quotes or wraps an eval result. */
65
+ async function pageReport(call, body) {
66
+ const script = `(() => { const report = (value) => "af1:" + btoa(encodeURIComponent(JSON.stringify(value))) + ":1fa"; try { ${body} } catch (error) { return report({ failed: true }); } })()`;
67
+ const result = await call("agent_browser_eval", { script });
68
+ if (result.isError)
69
+ return null;
70
+ const match = /af1:([A-Za-z0-9+/=]+):1fa/.exec(textOf(result));
71
+ if (!match)
72
+ return null;
73
+ try {
74
+ return JSON.parse(decodeURIComponent(Buffer.from(match[1], "base64").toString("latin1")));
75
+ }
76
+ catch {
77
+ return null;
78
+ }
79
+ }
80
+ /** Find the sign-in fields in the top document and tag them for one fill.
81
+ * Only a real password field receives the password: a bot cannot point it at
82
+ * a field whose text it could read. Fields inside frames are never used. */
83
+ const locate = (tag) => `
84
+ const visible = (el) => { const box = el.getBoundingClientRect(); const style = getComputedStyle(el);
85
+ return box.width > 0 && box.height > 0 && style.visibility !== "hidden" && style.display !== "none" && !el.disabled && !el.readOnly; };
86
+ const inputs = [...document.querySelectorAll("input")].filter(visible);
87
+ const named = (el) => (el.getAttribute("autocomplete") || "") + " " + (el.getAttribute("name") || "") + " " + (el.id || "");
88
+ const textual = (el) => ["text", "email", "tel", ""].includes((el.getAttribute("type") || "").toLowerCase());
89
+ const passwords = inputs.filter((el) => el.type === "password");
90
+ const password = passwords.length === 1 ? passwords[0] : null;
91
+ let user = null;
92
+ if (password) {
93
+ const scope = password.form ? [...password.form.querySelectorAll("input")].filter(visible) : inputs;
94
+ const before = scope.filter((el) => textual(el) && (el.compareDocumentPosition(password) & Node.DOCUMENT_POSITION_FOLLOWING));
95
+ user = before.find((el) => /username|email/i.test(el.getAttribute("autocomplete") || "")) || before[before.length - 1] || null;
96
+ } else if (passwords.length === 0) {
97
+ const candidates = inputs.filter(textual);
98
+ user = candidates.find((el) => /user|email|login|ident|account/i.test(named(el))) || (candidates.length === 1 ? candidates[0] : null);
99
+ }
100
+ const form = (password || user) ? (password || user).form : null;
101
+ let action = location.origin;
102
+ if (form && form.getAttribute("action")) { try { action = new URL(form.getAttribute("action"), location.href).origin; } catch (error) { action = "invalid"; } }
103
+ for (const el of document.querySelectorAll("[data-atomic-vault]")) el.removeAttribute("data-atomic-vault");
104
+ if (user) user.setAttribute("data-atomic-vault", ${JSON.stringify(`${tag}-u`)});
105
+ if (password) password.setAttribute("data-atomic-vault", ${JSON.stringify(`${tag}-p`)});
106
+ return report({ passwords: passwords.length, user: Boolean(user), password: Boolean(password), action, top: window.top === window });`;
107
+ const untag = `for (const el of document.querySelectorAll("[data-atomic-vault]")) el.removeAttribute("data-atomic-vault"); return report({ ok: true });`;
108
+ /** What Atomic reads from the page to judge it: everything a screenshot
109
+ * could show as readable text (the page's text and the values of fields that
110
+ * are not password fields), and the values held by the top document's
111
+ * password fields. The password is never sent into the page to be compared
112
+ * there, because a page the bot opened later could be built to catch it; the
113
+ * comparison happens in Atomic. */
114
+ const READABLE_CAP = 3_000_000;
115
+ const inspect = `
116
+ const out = []; const fields = []; let size = 0; let cut = false;
117
+ const add = (value) => { if (typeof value !== "string" || !value) return; size += value.length; if (size > ${READABLE_CAP}) { cut = true; return; } out.push(value); };
118
+ const scan = (doc) => {
119
+ for (const el of doc.querySelectorAll("input, textarea")) {
120
+ if (el.type !== "password") add(el.value);
121
+ else if (doc === document && el.value) fields.push(String(el.value).slice(0, 10000));
122
+ }
123
+ add(doc.documentElement ? doc.documentElement.innerText : "");
124
+ for (const frame of doc.querySelectorAll("iframe, frame")) { try { if (frame.contentDocument) scan(frame.contentDocument); } catch (error) { /* another origin */ } }
125
+ };
126
+ scan(document);
127
+ return report({ origin: location.origin, texts: out, fields, cut });`;
128
+ /** Empty every password field in the top document the way typing would, so
129
+ * a page that keeps its own copy of the value forgets it too. */
130
+ const empty = `
131
+ const set = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value").set;
132
+ for (const el of document.querySelectorAll("input")) {
133
+ if (el.type !== "password" || !el.value) continue;
134
+ set.call(el, "");
135
+ el.dispatchEvent(new Event("input", { bubbles: true }));
136
+ el.dispatchEvent(new Event("change", { bubbles: true }));
137
+ }
138
+ return report({ ok: true });`;
139
+ export class VaultFill {
140
+ /** Browser session → the passwords filled into it, kept in memory only. */
141
+ filled = new Map();
142
+ /** Browser session → the websites a password was filled on. */
143
+ origins = new Map();
144
+ stateFile;
145
+ /** `stateFile` names where tainted session names (never passwords) are
146
+ * kept, so a browser that outlives an Atomic crash stays guarded. */
147
+ constructor(stateFile = () => null) { this.stateFile = stateFile; }
148
+ remembered() {
149
+ const file = this.stateFile();
150
+ if (!file)
151
+ return [];
152
+ try {
153
+ const value = JSON.parse(readFileSync(file, "utf8"));
154
+ return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
155
+ }
156
+ catch {
157
+ return [];
158
+ }
159
+ }
160
+ remember(session, held) {
161
+ const file = this.stateFile();
162
+ if (!file)
163
+ return;
164
+ const sessions = new Set(this.remembered());
165
+ if (held === sessions.has(session))
166
+ return;
167
+ if (held)
168
+ sessions.add(session);
169
+ else
170
+ sessions.delete(session);
171
+ try {
172
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
173
+ writeFileAtomic(file, JSON.stringify([...sessions]), { mode: 0o600 });
174
+ }
175
+ catch { /* The in-memory guard still holds for this run. */ }
176
+ }
177
+ tainted(session) { return this.filled.has(session) || this.remembered().includes(session); }
178
+ /** A password was filled before Atomic restarted and the browser may still
179
+ * hold it. Atomic no longer knows the value, so nothing can be checked. */
180
+ stale(session) { return !this.filled.has(session) && this.remembered().includes(session); }
181
+ /** The browser session ended: its pages, and the passwords in them, are gone. */
182
+ clear(session) { this.filled.delete(session); this.origins.delete(session); this.remember(session, false); }
183
+ /** Each filled password as a page or an address could carry it: as typed,
184
+ * percent-encoded, form-encoded with "+" or "%20" for a space, and escaped
185
+ * for JSON or HTML. */
186
+ secrets(session) {
187
+ const out = new Set();
188
+ for (const secret of this.filled.get(session) ?? []) {
189
+ if (!secret)
190
+ continue;
191
+ const form = new URLSearchParams({ v: secret }).toString().slice(2);
192
+ const html = secret.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
193
+ for (const variant of [secret, encodeURIComponent(secret), encodeURI(secret), form, form.replace(/\+/g, "%20"), JSON.stringify(secret).slice(1, -1),
194
+ html, html.replace(/"/g, "&quot;"), html.replace(/"/g, "&quot;").replace(/'/g, "&#39;")])
195
+ out.add(variant);
196
+ }
197
+ return [...out].sort((x, y) => y.length - x.length);
198
+ }
199
+ /** Before a bot's call reaches the engine: a refusal, or the arguments to send. */
200
+ before(session, name, args) {
201
+ if (!this.tainted(session))
202
+ return { args };
203
+ if (this.stale(session) && name !== "agent_browser_close")
204
+ return { refuse: text(STALE, true) };
205
+ if (name === "agent_browser_eval")
206
+ return { refuse: text(EVAL_OFF, true) };
207
+ if (name === "agent_browser_press" && typeof args.key === "string" && COPY_KEYS.test(args.key.replace(/\s+/g, "")))
208
+ return { refuse: text(COPY_OFF, true) };
209
+ // A selector that tests a field's value answers yes or no, which reads
210
+ // the password out one character at a time.
211
+ if (Object.entries(args).some(([key, value]) => /selector/i.test(key) && typeof value === "string" && VALUE_SELECTOR.test(value)))
212
+ return { refuse: text(VALUE_SELECTOR_OFF, true) };
213
+ if (name === "agent_browser_screenshot") {
214
+ const { path: _path, screenshotDir: _dir, ...rest } = args;
215
+ return { args: rest };
216
+ }
217
+ return { args };
218
+ }
219
+ /** Read the page and judge it. A password field on a filled website that
220
+ * holds anything but a filled password was edited: it is emptied here,
221
+ * before the bot's next call, because an edited copy would pass every
222
+ * comparison once the site showed it as text. */
223
+ async state(session, call) {
224
+ const report = await pageReport(call, inspect).catch(() => null);
225
+ if (!report || report.failed || report.cut || !Array.isArray(report.texts) || !Array.isArray(report.fields))
226
+ return "unknown";
227
+ const filled = this.filled.get(session) ?? new Set();
228
+ const here = typeof report.origin === "string" && this.origins.get(session)?.has(report.origin) === true;
229
+ const altered = here && report.fields.some((value) => typeof value !== "string" || !filled.has(value));
230
+ if (altered)
231
+ await pageReport(call, empty).catch(() => null);
232
+ const secrets = this.secrets(session);
233
+ const shown = report.texts.some((value) => typeof value === "string" && secrets.some((secret) => value.includes(secret)));
234
+ return shown ? "shown" : altered ? "altered" : "clean";
235
+ }
236
+ /** Before a bot's call reaches the engine, after `before`: a refusal when
237
+ * the page's state does not allow the call, or null to let it through. */
238
+ async guard(session, name, args, call) {
239
+ if (!this.tainted(session) || name === "agent_browser_close")
240
+ return null;
241
+ const state = await this.state(session, call);
242
+ if (state === "clean")
243
+ return null;
244
+ if (state === "altered")
245
+ return text(ALTERED, true);
246
+ if (name === "agent_browser_screenshot")
247
+ return SCREENSHOT_WITHHELD;
248
+ const probing = Object.entries(args).some(([key, value]) => /selector/i.test(key) && typeof value === "string" && TEXT_SELECTOR.test(value));
249
+ return LOOK_ONLY.has(name) && !probing ? null : text(state === "shown" ? SHOWN : UNREADABLE, true);
250
+ }
251
+ /** The result with every filled password removed from its text. Runs
252
+ * before a long result is cut to size, so a cut can never leave part of a
253
+ * password behind. */
254
+ scrub(session, result) {
255
+ if (!this.filled.has(session) || !result || typeof result !== "object" || !Array.isArray(result.content))
256
+ return result;
257
+ const secrets = this.secrets(session);
258
+ const clean = (value) => secrets.reduce((out, secret) => out.split(secret).join("[redacted]"), value);
259
+ return {
260
+ ...result,
261
+ content: result.content.map((part) => part && typeof part === "object" && typeof part.text === "string"
262
+ ? { ...part, text: clean(part.text) } : part),
263
+ };
264
+ }
265
+ /** After the engine answered a bot's call: the result the bot may see. */
266
+ async after(session, result, call) {
267
+ if (!this.tainted(session) || !result || typeof result !== "object")
268
+ return result;
269
+ const state = await this.state(session, call);
270
+ if (state === "altered")
271
+ return text(ALTERED, true);
272
+ const image = (Array.isArray(result.content) ? result.content : []).some((part) => part && typeof part === "object" && part.type !== "text");
273
+ if (image && state !== "clean")
274
+ return SCREENSHOT_WITHHELD;
275
+ return this.scrub(session, result);
276
+ }
277
+ /** The vault_fill_login tool. Every refusal about the item reads the same
278
+ * whether it is missing, not granted, expired, not a login or for another site. */
279
+ async fill(session, access, args, call, now = Date.now()) {
280
+ if (this.stale(session))
281
+ return text(STALE, true);
282
+ if (!access)
283
+ return text("Vault is locked on this computer. It unlocks when the Atomic desktop app is open.", true);
284
+ const itemId = typeof args.item_id === "string" ? args.item_id : "";
285
+ if (!/^[0-9a-f-]{36}$/.test(itemId))
286
+ return text("vault_fill_login needs item_id from vault_request.", true);
287
+ const pageOrigin = async () => vaultOrigin(textOf(await call("agent_browser_get_url", {})).match(/https:\/\/[^\s"'<>]+/)?.[0] ?? "");
288
+ const destination = await pageOrigin();
289
+ if (!destination)
290
+ return text("Open the site's sign-in page (an https:// address) before filling a login.", true);
291
+ let login;
292
+ try {
293
+ login = access.store.loginFor({ ownerId: access.ownerId, botId: access.botId, destination }, itemId, now);
294
+ }
295
+ catch (error) {
296
+ return text(error instanceof VaultError ? error.message : "Vault could not complete the request.", true);
297
+ }
298
+ if (!login)
299
+ return text(REFUSED, true);
300
+ const tag = randomBytes(8).toString("hex");
301
+ const found = await pageReport(call, locate(tag));
302
+ if (!found || found.failed)
303
+ return text("The sign-in form could not be read on this page.", true);
304
+ try {
305
+ if (!found.top)
306
+ return text("The sign-in form is inside a frame. Open the sign-in page directly.", true);
307
+ if (found.passwords > 1)
308
+ return text("This page has more than one password field, so it looks like a sign-up or change-password form. A saved login is only filled into a sign-in form.", true);
309
+ if (!found.user && !found.password)
310
+ return text("No sign-in field was found on this page. Open the sign-in form first.", true);
311
+ if (found.action !== destination)
312
+ return text("This form sends what is typed to a different website, so the login was not filled.", true);
313
+ if (found.user) {
314
+ const typed = await call("agent_browser_fill", { selector: `[data-atomic-vault="${tag}-u"]`, text: login.username });
315
+ if (typed.isError)
316
+ return text("The username field could not be filled.", true);
317
+ }
318
+ if (!found.password)
319
+ return text("Filled the username. Continue to the password step, then call vault_fill_login again.");
320
+ // The page may have moved while the username was typed.
321
+ if (await pageOrigin() !== destination)
322
+ return text("The page changed before the password was typed, so it was not filled.", true);
323
+ // From here the password is in the page: guard the session first.
324
+ const set = this.filled.get(session) ?? new Set();
325
+ set.add(login.password);
326
+ this.filled.set(session, set);
327
+ this.origins.set(session, (this.origins.get(session) ?? new Set()).add(destination));
328
+ this.remember(session, true);
329
+ const typed = await call("agent_browser_fill", { selector: `[data-atomic-vault="${tag}-p"]`, text: login.password });
330
+ if (typed.isError)
331
+ return text("The password field could not be filled.", true);
332
+ return text(found.user ? "Filled the username and password. Click the sign-in button to continue." : "Filled the password. Click the sign-in button to continue.");
333
+ }
334
+ finally {
335
+ await pageReport(call, untag).catch(() => null);
336
+ }
337
+ }
338
+ }
@@ -150,9 +150,13 @@ export function createVaultBotRoutes(deps) {
150
150
  return json(res, 503, { error: "Vault is locked on this computer. It unlocks when the Atomic desktop app is open." });
151
151
  try {
152
152
  if (path === "/api/internal/vault/keys" && method === "GET") {
153
- const items = store.apiKeysFor(ownerId, botId, (deps.now ?? Date.now)())
153
+ const now = (deps.now ?? Date.now)();
154
+ const items = store.apiKeysFor(ownerId, botId, now)
154
155
  .map(({ id, label, hints, origins, header, expiresAt }) => ({ id, label, hints, origins, header, expiresAt }));
155
- return json(res, 200, { items });
156
+ // Logins are filled by the browser's vault_fill_login tool, on their website only.
157
+ const logins = store.loginsFor(ownerId, botId, now)
158
+ .map(({ id, label, hints, origins, username, expiresAt }) => ({ id, label, hints, website: origins[0], username, expiresAt }));
159
+ return json(res, 200, { items, logins });
156
160
  }
157
161
  if (path === "/api/internal/vault/request" && method === "POST") {
158
162
  const body = await readBody(req, MAX_REQUEST_BODY + 200_000).catch(() => null);
@@ -23,8 +23,8 @@ export function createVaultRoutes(deps) {
23
23
  if (typeof body?.csv !== "string")
24
24
  return json(res, 400, { error: "Choose a CSV file exported from your password manager." });
25
25
  try {
26
- const { logins, skipped } = vaultLoginsFromCsv(body.csv, typeof body.group === "string" && body.group ? body.group : undefined);
27
- return json(res, 200, { ...store.importLogins(ownerId, logins), skipped });
26
+ const { logins, apiKeys, skipped, needAddress } = vaultLoginsFromCsv(body.csv, typeof body.group === "string" && body.group ? body.group : undefined);
27
+ return json(res, 200, { ...store.importLogins(ownerId, [...logins, ...apiKeys]), skipped, needAddress });
28
28
  }
29
29
  catch (error) {
30
30
  // Neither message echoes anything from a row.
@@ -33,6 +33,18 @@ export function createVaultRoutes(deps) {
33
33
  return json(res, 503, { error: "Vault could not complete the request." });
34
34
  }
35
35
  }
36
+ if (path === "/api/vault/allow-all-bots") {
37
+ if (method !== "POST")
38
+ return json(res, 405, { error: "Method not allowed." });
39
+ try {
40
+ return json(res, 200, { changed: store.allowAllBots(ownerId) });
41
+ }
42
+ catch (error) {
43
+ if (error instanceof VaultError)
44
+ return json(res, 400, { error: error.message });
45
+ return json(res, 503, { error: "Vault could not complete the request." });
46
+ }
47
+ }
36
48
  const item = /^\/api\/vault\/([0-9a-f-]{36})$/.exec(path);
37
49
  if (path !== "/api/vault" && !item)
38
50
  return json(res, 404, { error: "Vault item is unavailable." });
@@ -48,11 +48,25 @@ export class NativeVaultRuntime {
48
48
  * of a bot's own turn on this computer, never an external runtime. */
49
49
  export function installNativeVault(dataDir, port, desktopToken, caller) {
50
50
  const runtime = new NativeVaultRuntime(join(dataDir, "providers", "native-vault"));
51
+ installed = runtime;
52
+ fillState = join(dataDir, "providers", "native-vault", "filled-sessions.json");
51
53
  port?.on("message", (event) => { runtime.receive(event?.data); });
52
54
  ROUTES.push(createVaultRoutes({ store: () => runtime.store(), owner: (req, auth) => caller(req) ? null : runtime.owner(req, auth, desktopToken()) }));
53
55
  ROUTES.push(createVaultBotRoutes({ store: () => runtime.store(), ownerId: () => runtime.ownerId(),
54
56
  bot: (req) => vaultBot(caller(req)), downloadDir: (botId) => join(dataDir, "vault-downloads", botId) }));
55
57
  }
58
+ let fillState = null;
59
+ /** Where the browser sessions holding a filled password are remembered
60
+ * across a restart. Session names only, never a password. */
61
+ export function vaultFillStateFile() { return fillState; }
62
+ let installed = null;
63
+ /** The unlocked vault, for the browser's trusted login fill. Null while the
64
+ * vault is locked or this server has none. */
65
+ export function unlockedVault() {
66
+ const store = installed?.store();
67
+ const ownerId = installed?.ownerId();
68
+ return store && ownerId ? { store, ownerId } : null;
69
+ }
56
70
  export function vaultBot(caller) {
57
71
  return caller && caller.kind === "agents" && !caller.externalRuntime ? caller.botId : null;
58
72
  }
@@ -7,7 +7,7 @@ import { createCipheriv, createDecipheriv, randomBytes, randomUUID } from "node:
7
7
  import { lstatSync, mkdirSync, readFileSync, rmdirSync } from "node:fs";
8
8
  import { join } from "node:path";
9
9
  import { z } from "zod";
10
- import { vaultInputSchema, vaultMetadata, vaultUseAllowed } from "../../shared/vault.js";
10
+ import { vaultGranted, vaultInputSchema, vaultMetadata, vaultUseAllowed } from "../../shared/vault.js";
11
11
  import { writeFileAtomic } from "../atomic.js";
12
12
  const MAX_BYTES = 16 * 1024 * 1024;
13
13
  const MAX_ITEMS = 3000;
@@ -134,9 +134,25 @@ export class VaultStore {
134
134
  /** The API keys this bot may use now: granted to it and not expired. */
135
135
  apiKeysFor(ownerId, botId, now) {
136
136
  owner(ownerId);
137
- return this.read().filter((item) => item.kind === "apiKey" && item.ownerId === ownerId && item.botIds.includes(botId)
137
+ return this.read().filter((item) => item.kind === "apiKey" && item.ownerId === ownerId && vaultGranted(item, botId)
138
138
  && (item.expiresAt === null || now < item.expiresAt)).map(vaultMetadata);
139
139
  }
140
+ /** The logins this bot may have filled for it now. Never the password. */
141
+ loginsFor(ownerId, botId, now) {
142
+ owner(ownerId);
143
+ return this.read().filter((item) => item.kind === "login" && item.ownerId === ownerId && vaultGranted(item, botId)
144
+ && (item.expiresAt === null || now < item.expiresAt)).map(vaultMetadata);
145
+ }
146
+ /** The username and password for one fill, or null when this bot may not
147
+ * use this login on this website now. For the trusted fill only: the
148
+ * password must never reach a response, a log or a model. */
149
+ loginFor(actor, id, now) {
150
+ owner(actor.ownerId);
151
+ const item = this.read().find((candidate) => candidate.id === id);
152
+ if (!item || item.kind !== "login" || !vaultUseAllowed(item, actor, now))
153
+ return null;
154
+ return { username: item.username, password: item.password };
155
+ }
140
156
  /** The header to send for one use, or null when this bot may not use this
141
157
  * item at this destination now. For the request executor only: the value
142
158
  * must never reach a response, a log or a model. */
@@ -163,13 +179,34 @@ export class VaultStore {
163
179
  }
164
180
  /** Adds logins in one write. A login already saved for the same website
165
181
  * and username is left as it is and counted in `duplicates`. */
182
+ /** One click for items saved before "every bot" existed: every login and
183
+ * API key of this owner becomes usable by all of the owner's bots, still
184
+ * only on its own website or addresses. Cards and contact details are
185
+ * left alone (bots cannot use them). Returns how many changed. */
186
+ allowAllBots(ownerId) {
187
+ owner(ownerId);
188
+ return this.mutate((items) => {
189
+ const now = Date.now();
190
+ let changed = 0;
191
+ for (const item of items) {
192
+ if (item.ownerId !== ownerId || item.allBots === true || (item.kind !== "login" && item.kind !== "apiKey"))
193
+ continue;
194
+ item.allBots = true;
195
+ item.updatedAt = now;
196
+ changed++;
197
+ }
198
+ return changed;
199
+ });
200
+ }
166
201
  importLogins(ownerId, logins) {
167
202
  owner(ownerId);
168
203
  const parsed = logins.map((input) => vaultInputSchema.safeParse(input));
169
204
  if (parsed.some((result) => !result.success))
170
205
  throw new VaultError("Invalid Vault item.");
171
206
  return this.mutate((items) => {
172
- const key = (item) => item.kind === "login" ? `${item.website}\n${item.username}` : "";
207
+ // A login is the same login by website and username; an API token by where it is sent, how, and its name.
208
+ const key = (item) => item.kind === "login" ? `${item.website}\n${item.username}`
209
+ : item.kind === "apiKey" ? `key\n${item.origins.join(",")}\n${item.header.toLowerCase()}\n${item.label}` : `${item.kind}\n${item.label}`;
173
210
  const seen = new Set(items.filter((item) => item.ownerId === ownerId).map(key));
174
211
  const now = Date.now();
175
212
  let added = 0;
@@ -47,8 +47,19 @@ 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
+ /** Chibi's default on every install (Erick, 2026-11-13): Automatic, the
51
+ * Plata class, starting on Claude Sonnet 5.5. It is the first rung of the
52
+ * Orchestrator's ladder, hand-written or generated, and the model Chibi is
53
+ * made on. The rung carries its class, so failover treats it as Plata
54
+ * whatever a leaderboard scores it. */
55
+ export const CHIBI_DEFAULT_RUNG = Object.freeze({ engine: "claudeAgent", model: "claude-sonnet-5-5", modelClass: "Plata" });
56
+ /** Raised whenever Chibi's default changes: each install whose Chibi holds
57
+ * an older number is put back on the default once, whatever it was set to
58
+ * (BotRecord.chibiDefaults, server/store.ts applyChibiDefaults). */
59
+ export const CHIBI_DEFAULTS_VERSION = 1;
50
60
  export const DEFAULT_LADDERS = {
51
61
  orchestrator: [
62
+ { ...CHIBI_DEFAULT_RUNG },
52
63
  { engine: "claudeAgent", model: "claude-opus-5-5", modelClass: "Plata" },
53
64
  { engine: "codex", model: "gpt-6-sol" },
54
65
  { engine: "opencodeGo", model: "opencode-go/gemini-4-argon" },
@@ -122,7 +133,7 @@ export function classForScore(score, bands = DEFAULT_CLASS_BANDS) {
122
133
  * Settings (config.json `engineTiers.classes`). */
123
134
  export const DEFAULT_TIER_CLASSES = {
124
135
  // Chibi runs on Claude at Plata (Erick, 2026-10-13); server/engine-tiers.ts
125
- // puts Claude's rungs first in its ladder.
136
+ // puts CHIBI_DEFAULT_RUNG, then Claude's other rungs, first in its ladder.
126
137
  orchestrator: "Plata",
127
138
  engineering: "Mezcal",
128
139
  // Research and Routine ask for the cheapest class (Erick, 2026-10-25).
@@ -178,3 +189,14 @@ export function effortShort(effort) {
178
189
  default: return undefined;
179
190
  }
180
191
  }
192
+ /** The subscription accounts one rung may use, from those matching it (the
193
+ * bot's own first). A rung naming an instance, or one a person set to "Any
194
+ * account", keeps them all. Any other rung names a provider and gets one:
195
+ * the first that is not refused for this turn (the personal line, policy),
196
+ * so a turn never moves to another account of the provider unasked. Keys
197
+ * are not decided here: they join every ladder's last band by themselves. */
198
+ export function rungAccounts(entry, accounts, refused) {
199
+ if (entry.anyAccount || accounts.length < 2 || accounts.some((account) => account.instanceId === entry.engine))
200
+ return accounts;
201
+ return [accounts.find((account) => !refused?.(account)) ?? accounts[0]];
202
+ }
@@ -65,9 +65,11 @@ export const ACCOUNT_PROVIDERS = [
65
65
  config: {}, keyTest: { provider: "ollamaCloud" }, keyUrl: "https://ollama.com/settings/keys", signupUrl: "https://ollama.com/pricing",
66
66
  },
67
67
  {
68
- // Nous Portal's OpenAI-compatible API, signed in with a portal key. No
69
- // Hermes needed (Erick, 2026-11-08).
70
- id: "nous", kind: "apiKey", label: "Nous Research", billing: "subscription", driver: "openai-compat", envVar: "NOUS_API_KEY",
68
+ // Nous Portal's OpenAI-compatible API with a portal key: no Hermes needed
69
+ // (Erick, 2026-11-08). Charged per use: Nous Portal states that API keys
70
+ // always use credits, never the plan's included usage (checked
71
+ // 2026-11-13). The subscription is the sign-in, through Hermes.
72
+ id: "nous", kind: "apiKey", label: "Nous Research", billing: "payPerUse", driver: "openai-compat", envVar: "NOUS_API_KEY",
71
73
  config: { url: "https://inference-api.nousresearch.com/v1", apiKeyEnv: "NOUS_API_KEY", model: "Hermes-4-405B", provider: "" },
72
74
  keyTest: { provider: "openaiCompat", url: "https://inference-api.nousresearch.com/v1" }, keyUrl: "https://portal.nousresearch.com/", signupUrl: "https://portal.nousresearch.com/",
73
75
  },
@@ -24,7 +24,12 @@ import { modelHost } from "./engine-choices.js";
24
24
  * - The Atomic Engine and the company connection (the Chibitek gateway):
25
25
  * they are Atomic's own routing, which these bots never use. */
26
26
  export const SUBSCRIPTION_PROVIDERS = Object.freeze([
27
- { id: "claude", name: "Claude", drivers: ["claudeAgent"], generic: ["claude", "claude code", "claude subscription", "anthropic"], signInUrl: "https://claude.ai/login" },
27
+ // Claude Code also lists models it can be pointed at (a leftover API slug,
28
+ // a settings.json custom model): only Anthropic's own count.
29
+ {
30
+ id: "claude", name: "Claude", drivers: ["claudeAgent"], generic: ["claude", "claude code", "claude subscription", "anthropic"],
31
+ ownModels: /^claude-/i, signInUrl: "https://claude.ai/login",
32
+ },
28
33
  { id: "chatgpt", name: "ChatGPT", drivers: ["codex"], generic: ["chatgpt", "codex", "chatgpt (codex)", "openai"], signInUrl: "https://chatgpt.com/auth/login" },
29
34
  {
30
35
  id: "gemini", name: "Gemini", drivers: ["antigravityAgent", "geminiAgent"], generic: ["gemini", "antigravity", "google", "google gemini"],
@@ -83,14 +88,17 @@ export function subscriptionProviderForEngine(engine) {
83
88
  return SUBSCRIPTION_PROVIDERS.find((provider) => provider.host && provider.drivers.includes(engine.driverKind)
84
89
  && engine.models.options.some((option) => modelHost(engine.driverKind, option) === provider.host));
85
90
  }
86
- /** Whether a model on this engine is the provider's own (always, except on
87
- * an engine that also serves other companies' models). */
91
+ /** Whether a model on this engine is the provider's own. A `host::model` id
92
+ * is another host's model run through the harness (a local inject: Ollama,
93
+ * Ollama Cloud, LM Studio), so it is never the provider's, whoever made the
94
+ * model: a Claude bot runs Anthropic's Claude, not Claude from another host
95
+ * (Erick, 2026-11-13). Otherwise always, except on an engine that also
96
+ * serves other companies' models (`ownModels`). */
88
97
  export function isProviderModel(provider, model) {
98
+ if (model.includes("::"))
99
+ return false;
89
100
  return provider.ownModels ? provider.ownModels.test(model) : true;
90
101
  }
91
- /** Turns one conversation of a company subscription bot may run on another
92
- * provider's subscription when its own has no account free (server/session-fallback.ts). */
93
- export const SESSION_FALLBACK_TURNS = 50;
94
102
  export function isSubscriptionBot(bot) {
95
103
  const value = bot?.subscription;
96
104
  return Boolean(value && typeof value.instanceId === "string" && subscriptionProvider(value.provider));
@@ -0,0 +1,48 @@
1
+ const bearer = (name, ...origins) => ({ name, origins, header: "Authorization", prefix: "Bearer " });
2
+ const keyed = (name, header, ...origins) => ({ name, origins, header, prefix: "" });
3
+ // Order matters where names overlap: the first match wins.
4
+ export const API_PROVIDERS = [
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"),
8
+ bearer(/\breplicate\b/i, "https://api.replicate.com"),
9
+ // Model providers and routers
10
+ bearer(/\bopen\s*router\b/i, "https://openrouter.ai"),
11
+ bearer(/\bollama\b/i, "https://ollama.com"),
12
+ bearer(/\b(?:hugging\s*face|hf)\b/i, "https://huggingface.co", "https://router.huggingface.co", "https://api-inference.huggingface.co"),
13
+ bearer(/\b(?:nous(?:\s*research)?|hermes)\b/i, "https://inference-api.nousresearch.com"),
14
+ keyed(/\b(?:anthropic|claude)\b/i, "x-api-key", "https://api.anthropic.com"),
15
+ keyed(/\b(?:gemini|google\s+ai|ai\s+studio)\b/i, "x-goog-api-key", "https://generativelanguage.googleapis.com"),
16
+ bearer(/\b(?:openai|chatgpt)\b/i, "https://api.openai.com"),
17
+ bearer(/\bgroq\b/i, "https://api.groq.com"),
18
+ bearer(/\bmistral\b/i, "https://api.mistral.ai"),
19
+ bearer(/\bdeepseek\b/i, "https://api.deepseek.com"),
20
+ bearer(/\b(?:xai|x\.ai|grok)\b/i, "https://api.x.ai"),
21
+ bearer(/\bperplexity\b/i, "https://api.perplexity.ai"),
22
+ bearer(/\b(?:kimi|moonshot)\b/i, "https://api.moonshot.ai"),
23
+ bearer(/\bminimax\b/i, "https://api.minimax.io"),
24
+ bearer(/\b(?:z\.ai|zai|zhipu|glm)\b/i, "https://api.z.ai"),
25
+ bearer(/\btogether(?:\s*ai)?\b/i, "https://api.together.xyz"),
26
+ bearer(/\bfireworks\b/i, "https://api.fireworks.ai"),
27
+ bearer(/\bcohere\b/i, "https://api.cohere.com"),
28
+ // Hosting and developer platforms
29
+ bearer(/\bvercel\b/i, "https://api.vercel.com"),
30
+ bearer(/\bsupabase\b/i, "https://api.supabase.com"),
31
+ bearer(/\brailway\b/i, "https://backboard.railway.com"),
32
+ bearer(/\bgithub\b/i, "https://api.github.com"),
33
+ bearer(/\bcloudflare\b/i, "https://api.cloudflare.com"),
34
+ // Business services
35
+ bearer(/\bstripe\b/i, "https://api.stripe.com"),
36
+ bearer(/\bresend\b/i, "https://api.resend.com"),
37
+ bearer(/\bsendgrid\b/i, "https://api.sendgrid.com"),
38
+ bearer(/\bnotion\b/i, "https://api.notion.com"),
39
+ bearer(/\bslack\b/i, "https://slack.com"),
40
+ // Search and web
41
+ bearer(/\btavily\b/i, "https://api.tavily.com"),
42
+ bearer(/\bfirecrawl\b/i, "https://api.firecrawl.dev"),
43
+ keyed(/\bbrave\b/i, "X-Subscription-Token", "https://api.search.brave.com"),
44
+ ];
45
+ /** The provider an item's name points at, or undefined. */
46
+ export function apiProviderFor(name) {
47
+ return API_PROVIDERS.find((provider) => provider.name.test(name));
48
+ }