@chibitek/chibi 0.1.209 → 0.1.210
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-CHGq3udb.js → TerminalPanel-DxQoOfkY.js} +1 -1
- package/dist/assets/{abnfDiagram-O67JEVCF-BMaKhJ-b.js → abnfDiagram-O67JEVCF-Ds2qYdjS.js} +1 -1
- package/dist/assets/{arc-CYAiNWN8.js → arc-1O9tchZk.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-CxJFFlbO.js → architectureDiagram-NJMV4G6O-CWuQ1x2F.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-C7AbPjRB.js → blockDiagram-BEXU5L5S-CNcEkXEx.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-DfVnCJmT.js → c4Diagram-YGBWAQC7-BKI_wi9I.js} +1 -1
- package/dist/assets/channel-CT5xRPK0.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-CzAUFkgv.js → chunk-2Q5K7J3B-gO88emfN.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-BgeBXphm.js → chunk-3FUC2YCW-DbKNT_-r.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-DPRdTAXc.js → chunk-5VM5RSS4-BbJCoZVg.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-BS-_dIVl.js → chunk-GTNCS2PH-DXurSCcp.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-D6I7xMmd.js → chunk-GWA4HPMP-BWyt0I_m.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-BKSKe7C9.js → chunk-JWPE2WC7-6iWSsogl.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-R48UYTRN.js → chunk-NETBCI7D-CFoqO9Hw.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-C8z4mL-2.js → chunk-WEXAMYUT-BZEzAlNi.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-Bml3ZRJ5.js → chunk-XXDRQBXY-W4hfC50f.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-w5wo22FO.js → classDiagram-v2-NBCMYWYE-BsGmL9e7.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-Cum9v--4.js → cose-bilkent-JH36ORCC-CYtTgIzk.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-BzN0-KsP.js → cynefin-OW5HDTMX-DLOi2Q2V.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-CkOpm32D.js → cynefinDiagram-VND7K2PF-BXcXJ3hv.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-BItQkKZD.js → dagre-6A5THRUB-BdBOiuzt.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-BI0zDn7c.js → diagram-22UHCM2B-DCf3M4WE.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-jwcDxsu6.js → diagram-3UASUU5V-CzdF-UXi.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-2RnY9egJ.js → diagram-ATOU4E4O-_UmmlMOD.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-eVdEZmEF.js → diagram-CDSNMT55-DrQODVuX.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-BCDGCJJ0.js → diagram-MLGK6HIB-CE16iJlJ.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-DtN5uO5w.js → diagram-MPIPVDR6-DJuTbhbP.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-B9GpXSEs.js → ebnfDiagram-ZINNZB2B-f1VEI2Po.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-Bk_eaK4T.js → elk-276RUBZZ-BRbs9WzY.js} +1 -1
- package/dist/assets/{erDiagram-OPXOYQCR-BiGoW6C6.js → erDiagram-OPXOYQCR-DvMp_cQr.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-ZW5w0BaJ.js → flowDiagram-KWPJA3E3-CYS1A0fu.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP-yyrKgsx1.js → ganttDiagram-FUAMR5RP-qya_JE9x.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-CeiDikzD.js → gitGraphDiagram-X574FWY7-ChMUJ3hH.js} +1 -1
- package/dist/assets/{index-CZGnshrJ.js → index-COH7BlyH.js} +196 -196
- package/dist/assets/index-H8vkXbLq.css +1 -0
- package/dist/assets/{index-DUFlRZuA.js → index-xE4Li_H2.js} +1 -1
- package/dist/assets/{infoDiagram-VRGFBTTK-q2B-KJFm.js → infoDiagram-VRGFBTTK-B2VudqsE.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-D8gXFuc0.js → ishikawaDiagram-OU5B5YK6-Bdk47y0t.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-BmHL2mbq.js → journeyDiagram-ZHPQQLJL-A4StgNQ9.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-B9Ll2WkA.js → kanban-definition-PNTS6WVX-DZo45dQw.js} +1 -1
- package/dist/assets/{linear-CMVGYrKx.js → linear-D_rK-Ord.js} +1 -1
- package/dist/assets/{mermaid.core-qO11n1kV.js → mermaid.core-C7CvDDvz.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-CxLGFX45.js → mindmap-definition-NLK3R4M7-6fmVPMyc.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-CxK1MJG4.js → pegDiagram-GJSIUBJH-CD4Qg24h.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-H5jiF5Eu.js → pieDiagram-5QR66LMP-DmzQ883B.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-CKaqCruv.js → quadrantDiagram-O4NWA36T-BW37utPZ.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-BCzKiQOd.js → railroadDiagram-XR7U4H2S-CWXiMlAb.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-Cqtr43DT.js → requirementDiagram-PLB6GJNP-DHSfr9U3.js} +1 -1
- package/dist/assets/{sankeyDiagram-IPEJSGJF-B2tQewX8.js → sankeyDiagram-IPEJSGJF-PebTt4eq.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-nggwQyrw.js → sequenceDiagram-PO4LG4MO-DPwp8fia.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-qSPXJBv2.js → sizeCapture-INFHLROL-BX_46o3S.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-DraPbL2T.js → stateDiagram-v2-GCMORJYK-W2e0RRrZ.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-C6HVkIDA.js → swimlanes-2SLR337P-CkyXpQX9.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-BH9Yry0J.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-DZmPRTsx.js → timeline-definition-EJHVYXUP-BS-sCjlN.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-CsVuROW_.js → usecaseDiagram-POWQR4AR-BQre-k6x.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-B9IRbuhp.js → vennDiagram-UO4OBE2U-CEWCsi_s.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-CGmVK53n.js → wardleyDiagram-VNRHLVJA-CXUxqghG.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-BAw-x9Y1.js → xychartDiagram-PMCCYNJV-DBgVMpwp.js} +1 -1
- package/dist/index.html +4 -2
- package/dist-server/accounts-proxy.js +19 -12
- package/dist-server/browser-proxy.js +19 -14
- package/dist-server/container-mcp.js +84 -12
- package/dist-server/drivers/agents-proxy.js +28 -13
- package/dist-server/drivers/phone-proxy.js +21 -13
- package/dist-server/index.js +3990 -2815
- package/dist-server/local-computer-proxy.js +77 -11
- package/dist-server/local-computer.js +2 -1
- package/dist-server/mcp-gate.js +53 -4
- package/dist-server/mcp-server.js +1 -1
- package/dist-server/openmausbot.js +443 -74
- package/dist-server/pair-cli.js +443 -74
- package/dist-server/server/accounts-proxy.js +3 -17
- package/dist-server/server/atomic-engine-release.js +7 -0
- package/dist-server/server/browser-proxy.js +3 -17
- package/dist-server/server/child-env.js +79 -0
- package/dist-server/server/config.js +11 -5
- package/dist-server/server/container-computer.js +1 -1
- package/dist-server/server/container-mcp.js +3 -2
- package/dist-server/server/control-client.js +7 -6
- package/dist-server/server/delegated-full-access.js +98 -0
- package/dist-server/server/desktop-loopback-gate.js +57 -0
- package/dist-server/server/drivers/acp/core.js +4 -4
- package/dist-server/server/drivers/acp/session-key.js +8 -0
- package/dist-server/server/drivers/agents-client.js +2 -14
- package/dist-server/server/drivers/gcloud-token.js +28 -0
- package/dist-server/server/drivers/github-copilot.js +152 -0
- package/dist-server/server/drivers/openai-chat-protocol.js +8 -0
- package/dist-server/server/drivers/openai-chat.js +10 -8
- package/dist-server/server/drivers/openai-compat.js +44 -9
- package/dist-server/server/drivers/phone-proxy.js +5 -18
- package/dist-server/server/engine-tiers.js +9 -9
- package/dist-server/server/harness/http.js +47 -1
- package/dist-server/server/index.js +54 -54
- package/dist-server/server/ladder-pick.js +18 -0
- package/dist-server/server/local-computer-proxy.js +3 -2
- package/dist-server/server/local-computer.js +1 -0
- package/dist-server/server/mcp-bridge.js +3 -2
- package/dist-server/server/mcp-gate.js +2 -1
- package/dist-server/server/mcp-registry.js +5 -1
- package/dist-server/server/model-gateway/failover.js +4 -1
- package/dist-server/server/model-gateway/route.js +64 -14
- package/dist-server/server/model-gateway/usage.js +66 -0
- package/dist-server/server/model-levels/aa-scale.js +42 -0
- package/dist-server/server/model-levels/aliases.js +16 -3
- package/dist-server/server/model-levels/index.js +8 -3
- package/dist-server/server/model-levels/rankings-build.js +76 -0
- package/dist-server/server/model-prices.js +6 -0
- package/dist-server/server/nexus-memory/index.js +5 -13
- package/dist-server/server/nexus-memory/policy.js +5 -17
- package/dist-server/server/oauth-account-vault.js +7 -2
- package/dist-server/server/provider-accounts.js +20 -1
- package/dist-server/server/provider-key-check.js +31 -1
- package/dist-server/server/registry-load.js +88 -0
- package/dist-server/server/request-auth.js +6 -28
- package/dist-server/server/routes/provider-accounts.js +124 -6
- package/dist-server/server/routine-daily-schedule.js +20 -0
- package/dist-server/server/routine-prompt-escape.js +18 -0
- package/dist-server/server/routine-tick-guard.js +16 -0
- package/dist-server/server/routine-tool-problems.js +36 -0
- package/dist-server/server/routines.js +36 -38
- package/dist-server/server/shutdown-triggers.js +18 -0
- package/dist-server/server/spend.js +23 -13
- package/dist-server/server/store.js +4 -13
- package/dist-server/server/terminal.js +2 -1
- package/dist-server/server/turn-token-file.js +79 -0
- package/dist-server/server/turn-token.js +23 -0
- package/dist-server/server/vps-container-mcp.js +3 -2
- package/dist-server/server/webhook-ingress.js +11 -1
- package/dist-server/server/webhook-prompt.js +82 -0
- package/dist-server/server/webhooks.js +8 -65
- package/dist-server/server/workspace-backup-policy.js +3 -3
- package/dist-server/server/workspace-backup.js +1 -1
- package/dist-server/server/workspace-time-zone.js +47 -0
- package/dist-server/shared/engine-choices.js +12 -1
- package/dist-server/shared/provider-accounts.js +114 -2
- package/dist-server/shared/zoned-time.js +55 -0
- package/dist-server/vps-container-mcp.js +84 -12
- package/package.json +1 -1
- package/dist/assets/channel-DxL_mLhm.js +0 -1
- package/dist/assets/index-Bi3hprmz.css +0 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-gQUGsELo.js +0 -8
|
@@ -5,24 +5,10 @@
|
|
|
5
5
|
// the harness decides, per call, which accounts this bot may use.
|
|
6
6
|
//
|
|
7
7
|
// stdout is the MCP transport. Never log there.
|
|
8
|
-
import { readFileSync } from "node:fs";
|
|
9
8
|
import readline from "node:readline";
|
|
9
|
+
import { turnTokenReader } from "./turn-token.js";
|
|
10
10
|
const HARNESS = process.env.OMB_HARNESS_URL ?? "http://127.0.0.1:8799";
|
|
11
|
-
const
|
|
12
|
-
const SPAWN_TOKEN = process.env.OMB_ACCOUNTS_TOKEN ?? "";
|
|
13
|
-
// Read per call: the harness rewrites the file each turn, and a pooled engine
|
|
14
|
-
// keeps this process across turns, so the spawn-time token is revoked by turn
|
|
15
|
-
// two and every call would answer "this turn's tool access has expired".
|
|
16
|
-
const token = () => {
|
|
17
|
-
if (!TOKEN_FILE)
|
|
18
|
-
return SPAWN_TOKEN;
|
|
19
|
-
try {
|
|
20
|
-
return readFileSync(TOKEN_FILE, "utf8").trim() || SPAWN_TOKEN;
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return SPAWN_TOKEN;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
11
|
+
const currentToken = turnTokenReader(process.env, "OMB_ACCOUNTS_TOKEN");
|
|
26
12
|
const TIMEOUT_MS = 3 * 60_000;
|
|
27
13
|
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
28
14
|
const send = (message) => process.stdout.write(`${JSON.stringify(message)}\n`);
|
|
@@ -32,7 +18,7 @@ const textResult = (text, isError = false) => ({ content: [{ type: "text", text
|
|
|
32
18
|
async function harness(path, init = {}) {
|
|
33
19
|
const response = await fetch(`${HARNESS}${path}`, {
|
|
34
20
|
...init,
|
|
35
|
-
headers: { "content-type": "application/json", authorization: `Bearer ${
|
|
21
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${currentToken()}` },
|
|
36
22
|
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
37
23
|
});
|
|
38
24
|
const text = await response.text();
|
|
@@ -21,6 +21,13 @@ const ASSETS = [
|
|
|
21
21
|
bytes: 103356325,
|
|
22
22
|
sha512: "a2bb1c23194ca63168a855daee719a851d5213c79b6db083ca676b0aaff26ac55f0e2086e36395f86a677379e8cc0cf53113122b6695b841e12e3619857fc08c",
|
|
23
23
|
},
|
|
24
|
+
{
|
|
25
|
+
version: "0.21.4-68432dd",
|
|
26
|
+
platform: "darwin-x64",
|
|
27
|
+
url: "https://ugmbfkqvogfuvufzjxtb.supabase.co/storage/v1/object/public/atomic-updates/atomic/K_5FMcrZFZ5AE2K-Lydn-Tis/atomic-engine-0.21.4-68432dd-darwin-x64.tar.gz",
|
|
28
|
+
bytes: 107288371,
|
|
29
|
+
sha512: "8f42c9411363df6969aeea1768f85e2699b3f074d336d8040b8ff4fc3bce798b2727c8071e9a079a00318e60ceab21ef0b752af5e32a073a6d43c8a4d98481fb",
|
|
30
|
+
},
|
|
24
31
|
];
|
|
25
32
|
/** The package for this computer, or null when none is published for it. */
|
|
26
33
|
export function atomicEngineAsset(platform = process.platform, arch = process.arch) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Per-turn MCP entry point. Only a scoped browser capability crosses into the
|
|
2
2
|
// agent process; engine commands, session names, and credentials stay in OMB.
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { turnTokenReader } from "./turn-token.js";
|
|
5
5
|
const MAX_INPUT_BYTES = 1_048_576;
|
|
6
6
|
const MAX_OUTPUT_BYTES = 16_777_216;
|
|
7
7
|
const MAX_PENDING = 16;
|
|
@@ -77,21 +77,7 @@ export async function browserProxyRequest(frame, connection) {
|
|
|
77
77
|
}
|
|
78
78
|
function run() {
|
|
79
79
|
const url = process.env.OMB_HARNESS_URL ?? "";
|
|
80
|
-
const
|
|
81
|
-
const tokenFile = process.env.OMB_BROWSER_TOKEN_FILE ?? "";
|
|
82
|
-
// Read per call: the harness rewrites the file each turn, and a pooled
|
|
83
|
-
// engine keeps this process across turns, so the spawn-time token is
|
|
84
|
-
// revoked by turn two.
|
|
85
|
-
const connection = () => {
|
|
86
|
-
let token = spawnToken;
|
|
87
|
-
if (tokenFile) {
|
|
88
|
-
try {
|
|
89
|
-
token = readFileSync(tokenFile, "utf8").trim() || spawnToken;
|
|
90
|
-
}
|
|
91
|
-
catch { /* fall back */ }
|
|
92
|
-
}
|
|
93
|
-
return { url, token };
|
|
94
|
-
};
|
|
80
|
+
const currentToken = turnTokenReader(process.env, "OMB_BROWSER_TOKEN");
|
|
95
81
|
let input = Buffer.alloc(0);
|
|
96
82
|
let pending = 0;
|
|
97
83
|
const output = (message) => {
|
|
@@ -134,7 +120,7 @@ function run() {
|
|
|
134
120
|
continue;
|
|
135
121
|
}
|
|
136
122
|
pending++;
|
|
137
|
-
void browserProxyRequest(frame,
|
|
123
|
+
void browserProxyRequest(frame, { url, token: currentToken() }).then(output).finally(() => { pending--; });
|
|
138
124
|
}
|
|
139
125
|
if (input.length > MAX_INPUT_BYTES) {
|
|
140
126
|
process.stdin.destroy();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// The environment handed to a process the harness does not own: a bot's own
|
|
2
|
+
// MCP server, a runtime CLI behind a bridge, the in-app terminal.
|
|
3
|
+
//
|
|
4
|
+
// A denylist on purpose. People's MCP servers rely on their shell environment
|
|
5
|
+
// (GITHUB_TOKEN, AWS_PROFILE, proxies, PATH, HOME), so an allowlist would
|
|
6
|
+
// break them. What must not ride along in `...process.env` is what belongs to
|
|
7
|
+
// the harness: its own tokens and token files, and the provider keys it was
|
|
8
|
+
// given for its engines.
|
|
9
|
+
//
|
|
10
|
+
// Standalone (no config.ts import) because mcp-gate.ts and the bridges run as
|
|
11
|
+
// their own small processes. child-env.test.ts keeps the lists below in step
|
|
12
|
+
// with the credential lists in config.ts.
|
|
13
|
+
const HARNESS_PREFIX = /^(OMB|ATOMIC|OPENMAUSBOT)_/;
|
|
14
|
+
const SECRET_WORD = /TOKEN|SECRET|KEY|CAPABILIT|AUTH|PASSWORD|CREDENTIAL|LICENSE|BEARER/;
|
|
15
|
+
/** Harness variables that hold or point at secrets without saying so in their name. */
|
|
16
|
+
const HARNESS_INTERNAL_EXACT = new Set([
|
|
17
|
+
"OMB_ANTHROPIC_API_URL",
|
|
18
|
+
"OMB_HOSTED_MODELS",
|
|
19
|
+
"OMB_BROWSER_CONNECTION",
|
|
20
|
+
"OMB_USER_DATA",
|
|
21
|
+
]);
|
|
22
|
+
/** Hosting control-plane secrets, and other servers' header credentials (drivers/codex.ts). */
|
|
23
|
+
const HARNESS_INTERNAL_PREFIXES = ["OMB_CLOUD_", "OMB_MCP_HEADER_"];
|
|
24
|
+
/** Keys the harness holds for its own engines and features, under names a
|
|
25
|
+
* third-party tool would also read. Mirrors PROVIDER_CREDENTIAL_ENV and the
|
|
26
|
+
* unprefixed names of WORKSPACE_CREDENTIAL_ENV in config.ts. */
|
|
27
|
+
const PROVIDER_KEY_ENV = new Set([
|
|
28
|
+
"ANTHROPIC_API_KEY",
|
|
29
|
+
"FACTORY_API_KEY",
|
|
30
|
+
"GEMINI_API_KEY",
|
|
31
|
+
"GOOGLE_API_KEY",
|
|
32
|
+
"KIMI_API_KEY",
|
|
33
|
+
"MOONSHOT_API_KEY",
|
|
34
|
+
"MINIMAX_API_KEY",
|
|
35
|
+
"OPENAI_API_KEY",
|
|
36
|
+
"OPENCODE_API_KEY",
|
|
37
|
+
"XAI_API_KEY",
|
|
38
|
+
"MISTRAL_API_KEY",
|
|
39
|
+
"OLLAMA_API_KEY",
|
|
40
|
+
"CURSOR_API_KEY",
|
|
41
|
+
"CURSOR_AUTH_TOKEN",
|
|
42
|
+
"META_API_KEY",
|
|
43
|
+
"OPENAI_COMPAT_API_KEY",
|
|
44
|
+
"OPENAI_COMPAT_URL",
|
|
45
|
+
"OPENAI_COMPAT_ORGANIZATION",
|
|
46
|
+
"OPENAI_COMPAT_PROJECT",
|
|
47
|
+
"BOX_TOKEN",
|
|
48
|
+
]);
|
|
49
|
+
/** Names compare case-insensitively because Windows environments do. */
|
|
50
|
+
export function isHarnessInternalEnv(key) {
|
|
51
|
+
const name = key.toUpperCase();
|
|
52
|
+
if (HARNESS_INTERNAL_EXACT.has(name) || HARNESS_INTERNAL_PREFIXES.some((prefix) => name.startsWith(prefix)))
|
|
53
|
+
return true;
|
|
54
|
+
return HARNESS_PREFIX.test(name) && SECRET_WORD.test(name);
|
|
55
|
+
}
|
|
56
|
+
export function isProviderKeyEnv(key) {
|
|
57
|
+
return PROVIDER_KEY_ENV.has(key.toUpperCase());
|
|
58
|
+
}
|
|
59
|
+
/** A copy of `env` without the harness's own secrets. Provider keys stay: this
|
|
60
|
+
* is for the person's own interactive shell on their own computer. */
|
|
61
|
+
export function withoutHarnessSecrets(env) {
|
|
62
|
+
const clean = { ...env };
|
|
63
|
+
for (const key of Object.keys(clean))
|
|
64
|
+
if (isHarnessInternalEnv(key))
|
|
65
|
+
delete clean[key];
|
|
66
|
+
return clean;
|
|
67
|
+
}
|
|
68
|
+
/** Environment for a third-party child: `base` without harness secrets and
|
|
69
|
+
* provider keys, then `extra` on top. `extra` is what the person configured
|
|
70
|
+
* for that one server, so it always wins, even for a name the denylist drops. */
|
|
71
|
+
export function childEnv(base, extra = {}) {
|
|
72
|
+
const clean = {};
|
|
73
|
+
for (const [key, value] of Object.entries(base)) {
|
|
74
|
+
if (value === undefined || isHarnessInternalEnv(key) || isProviderKeyEnv(key))
|
|
75
|
+
continue;
|
|
76
|
+
clean[key] = value;
|
|
77
|
+
}
|
|
78
|
+
return Object.assign(clean, extra);
|
|
79
|
+
}
|
|
@@ -491,8 +491,8 @@ const appConfigSchema = z.object({
|
|
|
491
491
|
localSource: z.string().trim().max(4096).refine((value) => !["\r", "\n", "\0"].some((character) => value.includes(character)), "Use a folder path without control characters").optional(),
|
|
492
492
|
}).strict().optional(),
|
|
493
493
|
/** UI language override (BCP-47, lowercase). Empty/absent = follow the
|
|
494
|
-
* system language. Unknown tags degrade to English in the renderer. */
|
|
495
|
-
language: optionalText,
|
|
494
|
+
* system language. Unknown tags degrade to English in the renderer. timeZone: see server/workspace-time-zone.ts. */
|
|
495
|
+
language: optionalText, timeZone: z.string().max(64).optional(),
|
|
496
496
|
rooms: roomConfigSchema.optional(),
|
|
497
497
|
context: z.object({
|
|
498
498
|
rebuildBytes: z.number().int().min(1_024).max(1_000_000).optional(),
|
|
@@ -557,7 +557,12 @@ const storedAppConfigSchema = appConfigSchema.extend({
|
|
|
557
557
|
// nexusMemory is written only through /api/nexus-memory/settings, which
|
|
558
558
|
// refuses to turn off what the organization locked on.
|
|
559
559
|
const appConfigPatchSchema = appConfigSchema.omit({ instances: true, mcpServers: true, cliStartup: true, customDomain: true, godMode: true, engineTiers: true, jevAnswerChecks: true, hipaa: true, personal: true, subscriptionBots: true, nexusMemory: true })
|
|
560
|
-
.extend({ threads: threadsPatchSchema.optional(), newBots: newBotsPatchSchema.optional()
|
|
560
|
+
.extend({ threads: threadsPatchSchema.optional(), newBots: newBotsPatchSchema.optional(), timeZone: z.string().max(64).refine((value) => { try {
|
|
561
|
+
return value === "" || Boolean(new Intl.DateTimeFormat("en-US", { timeZone: value }));
|
|
562
|
+
}
|
|
563
|
+
catch {
|
|
564
|
+
return false;
|
|
565
|
+
} }, "Choose a time zone from the list.").optional() });
|
|
561
566
|
const jsonObjectSchema = z.record(z.string(), z.json());
|
|
562
567
|
/** Resolve a canonical profile record to its exact durable Electron
|
|
563
568
|
* partition identity. Callers must never substitute the display/API id. */
|
|
@@ -1160,8 +1165,9 @@ export function saveConfig(patch, options = {}) {
|
|
|
1160
1165
|
// scalar, not a section: the merge loop above only walks objects
|
|
1161
1166
|
if (checkedPatch.workspaceName !== undefined)
|
|
1162
1167
|
disk.workspaceName = checkedPatch.workspaceName;
|
|
1163
|
-
|
|
1164
|
-
|
|
1168
|
+
for (const key of ["language", "timeZone"])
|
|
1169
|
+
if (checkedPatch[key] !== undefined)
|
|
1170
|
+
disk[key] = checkedPatch[key];
|
|
1165
1171
|
if (checkedPatch.customDomain !== undefined)
|
|
1166
1172
|
disk.customDomain = checkedPatch.customDomain;
|
|
1167
1173
|
if (checkedPatch.godMode !== undefined)
|
|
@@ -933,7 +933,7 @@ export function containerComputerMcp(runtime, control, target = SHARED_LOCAL_VM_
|
|
|
933
933
|
...(runtime === "docker" && process.platform === "darwin"
|
|
934
934
|
? { DOCKER_HOST: dockerEnvForColima(process.env, "darwin").DOCKER_HOST ?? "" }
|
|
935
935
|
: {}),
|
|
936
|
-
...(control ? { OMB_CONTROL_URL: control.url, OMB_CONTROL_TOKEN: control.token } : {}),
|
|
936
|
+
...(control ? { OMB_CONTROL_URL: control.url, OMB_CONTROL_TOKEN: control.token, ...(control.tokenFile ? { OMB_CONTROL_TOKEN_FILE: control.tokenFile } : {}) } : {}),
|
|
937
937
|
// Where the bridge remembers Cua Driver's tool list, and whether it
|
|
938
938
|
// must stand in for Cua Driver until the first tool call (the VM is
|
|
939
939
|
// created by that call's claim).
|
|
@@ -6,6 +6,7 @@ import { cuaExecArgs } from "./container-computer.js";
|
|
|
6
6
|
import { dockerEnvForColima } from "./colima-docker.js";
|
|
7
7
|
import { augmentedPath } from "./env-path.js";
|
|
8
8
|
import { runMcpBridge } from "./mcp-bridge.js";
|
|
9
|
+
import { turnTokenReader } from "./turn-token.js";
|
|
9
10
|
const [runtime, container, socket] = process.argv.slice(2);
|
|
10
11
|
if (!runtime || !["docker", "podman", "container"].includes(runtime)) {
|
|
11
12
|
process.stderr.write("invalid Local VM runtime\n");
|
|
@@ -18,7 +19,7 @@ if (!container || !/^[a-zA-Z0-9_.-]+$/.test(container) || !socket?.startsWith("/
|
|
|
18
19
|
// The who-is-driving pair rides in env, not argv — argv is world-readable
|
|
19
20
|
// through `ps`, and the token guards a loopback endpoint.
|
|
20
21
|
const controlUrl = process.env.OMB_CONTROL_URL ?? "";
|
|
21
|
-
const controlToken = process.env
|
|
22
|
+
const controlToken = turnTokenReader(process.env, "OMB_CONTROL_TOKEN");
|
|
22
23
|
// A Local VM that must be created or recreated first is started by the
|
|
23
24
|
// turn's claim on its first screen call, so the bridge cannot reach Cua
|
|
24
25
|
// Driver at launch; it answers the handshake from the remembered tool list
|
|
@@ -34,6 +35,6 @@ runMcpBridge({
|
|
|
34
35
|
...(runtime === "docker" ? { env: dockerEnvForColima({ ...process.env, PATH: augmentedPath() }) } : {}),
|
|
35
36
|
// No liveness watchdog: the runtime CLI talks to a local daemon and fails
|
|
36
37
|
// fast on its own — there is no silent WAN peer to wedge on.
|
|
37
|
-
...(controlUrl && controlToken ? { gate: { url: controlUrl, token: controlToken } } : {}),
|
|
38
|
+
...(controlUrl && controlToken() ? { gate: { url: controlUrl, token: controlToken } } : {}),
|
|
38
39
|
...(toolCache ? { toolCache, deferConnect } : {}),
|
|
39
40
|
});
|
|
@@ -16,16 +16,17 @@ const DISENGAGED = { held: false, helpOpen: false };
|
|
|
16
16
|
const UNAVAILABLE = { held: true, helpOpen: false };
|
|
17
17
|
export function createControlClient(options) {
|
|
18
18
|
const url = options?.url ?? process.env.OMB_CONTROL_URL ?? "";
|
|
19
|
-
const
|
|
19
|
+
const given = options?.token ?? process.env.OMB_CONTROL_TOKEN ?? "";
|
|
20
|
+
const token = typeof given === "function" ? given : () => given;
|
|
20
21
|
const cacheMs = options?.cacheMs ?? 750;
|
|
21
22
|
const fetchImpl = options?.fetchImpl ?? fetch;
|
|
22
|
-
const configured = Boolean(url && token);
|
|
23
|
-
const headers = { authorization: `Bearer ${token}`, "content-type": "application/json" };
|
|
23
|
+
const configured = Boolean(url && token());
|
|
24
|
+
const headers = () => ({ authorization: `Bearer ${token()}`, "content-type": "application/json" });
|
|
24
25
|
let cachedAt = 0;
|
|
25
26
|
let cached = DISENGAGED;
|
|
26
27
|
async function read() {
|
|
27
28
|
try {
|
|
28
|
-
const res = await fetchImpl(url, { headers, signal: AbortSignal.timeout(2_000) });
|
|
29
|
+
const res = await fetchImpl(url, { headers: headers(), signal: AbortSignal.timeout(2_000) });
|
|
29
30
|
if (!res.ok)
|
|
30
31
|
return UNAVAILABLE;
|
|
31
32
|
const body = await res.json().catch(() => null);
|
|
@@ -60,7 +61,7 @@ export function createControlClient(options) {
|
|
|
60
61
|
try {
|
|
61
62
|
const res = await fetchImpl(url, {
|
|
62
63
|
method: "POST",
|
|
63
|
-
headers,
|
|
64
|
+
headers: headers(),
|
|
64
65
|
body: JSON.stringify({ reason }),
|
|
65
66
|
signal: AbortSignal.timeout(2_000),
|
|
66
67
|
});
|
|
@@ -79,7 +80,7 @@ export function createControlClient(options) {
|
|
|
79
80
|
try {
|
|
80
81
|
await fetchImpl(url, {
|
|
81
82
|
method: "DELETE",
|
|
82
|
-
headers,
|
|
83
|
+
headers: headers(),
|
|
83
84
|
body: JSON.stringify({ requestId }),
|
|
84
85
|
signal: AbortSignal.timeout(2_000),
|
|
85
86
|
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Full access a Chief of Staff passes to a teammate's thread is never saved
|
|
2
|
+
// on that thread. Only where it came from is recorded; each turn and each
|
|
3
|
+
// permission answer asks whether that source still has Full access right now
|
|
4
|
+
// (SECURITY.md: Full access is a standing decision the person made, and must
|
|
5
|
+
// never silently broaden or outlive it).
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { writeFileAtomic } from "./atomic.js";
|
|
8
|
+
/** The activity line older builds wrote when they saved Full on the thread. */
|
|
9
|
+
export const LEGACY_DELEGATED_LABEL = "GOD MODE: delegated by ";
|
|
10
|
+
export function delegatedFullAccessLabel(chiefName) {
|
|
11
|
+
return `Full access from ${chiefName}, a Chief of Staff, for as long as ${chiefName} has it`;
|
|
12
|
+
}
|
|
13
|
+
/** Whether a thread runs Full because of a delegation, decided from live
|
|
14
|
+
* state: the recorded source must exist and must still pass Full on. */
|
|
15
|
+
export function delegatedFullAccessActive(threadId, lookups) {
|
|
16
|
+
const source = lookups.source(threadId);
|
|
17
|
+
return Boolean(source && lookups.stillGrants(source));
|
|
18
|
+
}
|
|
19
|
+
/** Threads still carrying a Full that an older build saved for a delegation.
|
|
20
|
+
* A bot whose every thread is Full got that from the person, so it is left. */
|
|
21
|
+
export function legacyDelegatedThreads(bots, messagesFor) {
|
|
22
|
+
const stale = [];
|
|
23
|
+
for (const bot of bots) {
|
|
24
|
+
const tasks = bot.tasks ?? [];
|
|
25
|
+
if (tasks.length > 1 && tasks.every(task => task.approvalMode === "full"))
|
|
26
|
+
continue;
|
|
27
|
+
for (const task of tasks) {
|
|
28
|
+
if (task.approvalMode !== "full")
|
|
29
|
+
continue;
|
|
30
|
+
const marked = messagesFor(task.threadId).some(message => message.kind === "activity" && (message.tool?.name ?? "").startsWith(LEGACY_DELEGATED_LABEL));
|
|
31
|
+
if (marked)
|
|
32
|
+
stale.push({ botId: bot.id, threadId: task.threadId });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return stale;
|
|
36
|
+
}
|
|
37
|
+
export class DelegatedFullAccess {
|
|
38
|
+
sources = {};
|
|
39
|
+
legacySwept = false;
|
|
40
|
+
file;
|
|
41
|
+
constructor(file) {
|
|
42
|
+
this.file = file;
|
|
43
|
+
if (!existsSync(file))
|
|
44
|
+
return;
|
|
45
|
+
try {
|
|
46
|
+
const data = JSON.parse(readFileSync(file, "utf8"));
|
|
47
|
+
this.legacySwept = data.legacySwept === true;
|
|
48
|
+
for (const [threadId, entry] of Object.entries(data.sources ?? {})) {
|
|
49
|
+
const source = entry;
|
|
50
|
+
if (source && typeof source.botId === "string" && typeof source.threadId === "string") {
|
|
51
|
+
this.sources[threadId] = { botId: source.botId, threadId: source.threadId };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// An unreadable file grants nothing.
|
|
57
|
+
this.sources = {};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
save() {
|
|
61
|
+
writeFileAtomic(this.file, JSON.stringify({ legacySwept: this.legacySwept, sources: this.sources }));
|
|
62
|
+
}
|
|
63
|
+
source(threadId) {
|
|
64
|
+
return this.sources[threadId];
|
|
65
|
+
}
|
|
66
|
+
/** Record the newest delegation into a thread. True when the thread had no
|
|
67
|
+
* source from this Chief yet, so the caller says so in the thread once. */
|
|
68
|
+
record(threadId, source) {
|
|
69
|
+
const previous = this.sources[threadId];
|
|
70
|
+
if (previous?.botId === source.botId && previous.threadId === source.threadId)
|
|
71
|
+
return false;
|
|
72
|
+
this.sources[threadId] = { ...source };
|
|
73
|
+
this.save();
|
|
74
|
+
return previous?.botId !== source.botId;
|
|
75
|
+
}
|
|
76
|
+
/** The newest delegation into this thread passed nothing on. */
|
|
77
|
+
clear(threadId) {
|
|
78
|
+
if (!this.sources[threadId])
|
|
79
|
+
return;
|
|
80
|
+
delete this.sources[threadId];
|
|
81
|
+
this.save();
|
|
82
|
+
}
|
|
83
|
+
/** Once per data directory: drop sources for threads that are gone and
|
|
84
|
+
* return the threads whose saved Full came from an old delegation, for the
|
|
85
|
+
* caller to put back to Ask. Later runs only prune. */
|
|
86
|
+
reconcile(bots, messagesFor) {
|
|
87
|
+
const live = new Set(bots.flatMap(bot => (bot.tasks ?? []).map(task => task.threadId)));
|
|
88
|
+
const gone = Object.keys(this.sources).filter(threadId => !live.has(threadId));
|
|
89
|
+
for (const threadId of gone)
|
|
90
|
+
delete this.sources[threadId];
|
|
91
|
+
const stale = this.legacySwept ? [] : legacyDelegatedThreads(bots, messagesFor);
|
|
92
|
+
if (gone.length || !this.legacySwept) {
|
|
93
|
+
this.legacySwept = true;
|
|
94
|
+
this.save();
|
|
95
|
+
}
|
|
96
|
+
return stale;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
export const DESKTOP_OWNER_HEADER = "x-chibi-desktop-owner";
|
|
3
|
+
export const COMPANION_AUTH_HEADER = "x-openmausbot-companion-auth";
|
|
4
|
+
export const DESKTOP_WRITE_REFUSAL = "forbidden: this change must come from the desktop app or a paired device";
|
|
5
|
+
export const DESKTOP_READ_REFUSAL = "forbidden: reading this needs the desktop app, a paired device or a connected assistant";
|
|
6
|
+
export function secureTokenMatch(actual, expected) {
|
|
7
|
+
if (!actual || !expected)
|
|
8
|
+
return false;
|
|
9
|
+
const left = Buffer.from(actual);
|
|
10
|
+
const right = Buffer.from(expected);
|
|
11
|
+
return left.length === right.length && timingSafeEqual(left, right);
|
|
12
|
+
}
|
|
13
|
+
function header(req, name) {
|
|
14
|
+
const value = req.headers[name];
|
|
15
|
+
return Array.isArray(value) ? value[0] : value;
|
|
16
|
+
}
|
|
17
|
+
/** Routes with an authorization of their own: agent integrations carry a
|
|
18
|
+
* high-entropy per-turn capability the handler checks, and a pairing-code
|
|
19
|
+
* exchange is authorized by possession of the one-time code. */
|
|
20
|
+
function selfAuthorizedRoute(path) {
|
|
21
|
+
return path.startsWith("/api/internal/") ||
|
|
22
|
+
path === "/api/testing/internal-capability" ||
|
|
23
|
+
path === "/api/auth/pair" ||
|
|
24
|
+
// The same exchange under the shape the companion apps send.
|
|
25
|
+
path === "/api/pair";
|
|
26
|
+
}
|
|
27
|
+
/** What a process on this computer may still read with no credential. Every
|
|
28
|
+
* bot's shell is such a process, so this holds nothing a bot should not see:
|
|
29
|
+
* liveness (Electron's boot probe keys on its pid before any token exists),
|
|
30
|
+
* the brand, and the two secret-free lists the `chibi` command prints
|
|
31
|
+
* (paired devices, open pairing invitations: labels and times, never a code
|
|
32
|
+
* or a token). */
|
|
33
|
+
const ANONYMOUS_READS = new Set(["/api/health", "/api/brand", "/api/auth/sessions", "/api/auth/pairing"]);
|
|
34
|
+
/** The phone relay's own read (the workspace name it advertises), as opposed
|
|
35
|
+
* to one it forwards for a paired phone, which also names that device. */
|
|
36
|
+
export function companionOwnRead(req, method, path, companionToken) {
|
|
37
|
+
return method.toUpperCase() === "GET" && path === "/api/config" &&
|
|
38
|
+
header(req, "x-openmausbot-companion-device") === undefined &&
|
|
39
|
+
secureTokenMatch(header(req, COMPANION_AUTH_HEADER), companionToken ?? "");
|
|
40
|
+
}
|
|
41
|
+
/** The packaged desktop's rule for a loopback request that carries no
|
|
42
|
+
* session: why it is refused, or null. Electron adds the per-launch owner
|
|
43
|
+
* capability to everything its own windows and main process send, so a
|
|
44
|
+
* request without it comes from some other local process. That process may
|
|
45
|
+
* neither change nor read the workspace. */
|
|
46
|
+
export function desktopLoopbackRefusal(req, method, path, tokens) {
|
|
47
|
+
const upper = method.toUpperCase();
|
|
48
|
+
if (upper === "OPTIONS" || selfAuthorizedRoute(path))
|
|
49
|
+
return null;
|
|
50
|
+
if (secureTokenMatch(header(req, DESKTOP_OWNER_HEADER), tokens.desktop))
|
|
51
|
+
return null;
|
|
52
|
+
if (upper !== "GET" && upper !== "HEAD")
|
|
53
|
+
return DESKTOP_WRITE_REFUSAL;
|
|
54
|
+
if (ANONYMOUS_READS.has(path) || companionOwnRead(req, upper, path, tokens.companion))
|
|
55
|
+
return null;
|
|
56
|
+
return DESKTOP_READ_REFUSAL;
|
|
57
|
+
}
|
|
@@ -31,6 +31,7 @@ import { basename, dirname, isAbsolute, relative, resolve } from "node:path";
|
|
|
31
31
|
import { createHash } from "node:crypto";
|
|
32
32
|
import { PROVIDER_CREDENTIAL_ENV, stripControlPlaneEnv, WORKSPACE_CREDENTIAL_ENV } from "../../config.js";
|
|
33
33
|
import { decodeInjectId } from "../local-inject.js";
|
|
34
|
+
import { mcpSessionKey } from "./session-key.js";
|
|
34
35
|
import { isChoicePrompt } from "../prompt-shape.js";
|
|
35
36
|
import { describeProbeFailure, describeSpawnFailure, killCliTree, probeCli, spawnCli } from "../../procs.js";
|
|
36
37
|
/**
|
|
@@ -1004,9 +1005,8 @@ export function createAcpDriver(support) {
|
|
|
1004
1005
|
// session, so the model is not a separate axis; fullAuto covers the
|
|
1005
1006
|
// transformEnv-policy supports (opencode). mcpServers are session
|
|
1006
1007
|
// establishment inputs — they ride session/new and session/load over
|
|
1007
|
-
// the wire —
|
|
1008
|
-
//
|
|
1009
|
-
// re-establishes the session below (see sessionKey).
|
|
1008
|
+
// the wire — so they must not respawn the process; a change instead
|
|
1009
|
+
// re-establishes the session below (see sessionKey, session-key.ts).
|
|
1010
1010
|
// The env the spawned child actually receives is part of the
|
|
1011
1011
|
// contract too, and arrives hashed as envFingerprint for the same
|
|
1012
1012
|
// reason.
|
|
@@ -1018,7 +1018,7 @@ export function createAcpDriver(support) {
|
|
|
1018
1018
|
// never sit in the key itself.
|
|
1019
1019
|
const envFingerprint = createHash("sha256").update(JSON.stringify(spawnEnv)).digest("hex").slice(0, 16);
|
|
1020
1020
|
const contractKey = JSON.stringify([launch.command, launch.args ?? [], spawnArgs, cwd, turnConfig.fullAuto === true, envFingerprint]);
|
|
1021
|
-
const sessionKey =
|
|
1021
|
+
const sessionKey = mcpSessionKey(mcpServers);
|
|
1022
1022
|
if (turn.sessionReset) {
|
|
1023
1023
|
closeSession(threadId, "reset");
|
|
1024
1024
|
sessionAllows.delete(threadId);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function mcpSessionKey(servers) {
|
|
2
|
+
return JSON.stringify(servers.map((server) => {
|
|
3
|
+
if (!server.env)
|
|
4
|
+
return server;
|
|
5
|
+
const names = new Set(server.env.map((entry) => entry.name));
|
|
6
|
+
return { ...server, env: server.env.filter((entry) => !names.has(`${entry.name}_FILE`)) };
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { turnTokenReader } from "../turn-token.js";
|
|
2
2
|
export function createHarnessClient(baseUrl, token) {
|
|
3
3
|
const bearer = typeof token === "function" ? token : () => token;
|
|
4
4
|
async function api(path, init) {
|
|
@@ -26,17 +26,5 @@ export function createHarnessClient(baseUrl, token) {
|
|
|
26
26
|
* OMB_COMMS_TOKEN the spawn-time token, for runtimes with no file
|
|
27
27
|
* (cloud boxes, external runtimes, tests) */
|
|
28
28
|
export function harnessClientFromEnv(env) {
|
|
29
|
-
|
|
30
|
-
const fallback = env.OMB_COMMS_TOKEN ?? "";
|
|
31
|
-
const token = () => {
|
|
32
|
-
if (!file)
|
|
33
|
-
return fallback;
|
|
34
|
-
try {
|
|
35
|
-
return readFileSync(file, "utf8").trim() || fallback;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return fallback;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
return createHarnessClient(env.OMB_HARNESS_URL ?? "http://127.0.0.1:8799", token);
|
|
29
|
+
return createHarnessClient(env.OMB_HARNESS_URL ?? "http://127.0.0.1:8799", turnTokenReader(env, "OMB_COMMS_TOKEN"));
|
|
42
30
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Google Vertex AI's OpenAI-compatible endpoint takes only a Google Cloud
|
|
2
|
+
// OAuth access token (Vertex express-mode API keys work only on the native
|
|
3
|
+
// generateContent API). Atomic borrows the token the person's own gcloud
|
|
4
|
+
// sign-in already holds, `gcloud auth print-access-token`, and keeps it
|
|
5
|
+
// 45 minutes (Google issues them for 60). Nothing is stored: the token stays
|
|
6
|
+
// in memory, and signing out of gcloud stops Atomic too.
|
|
7
|
+
import { execFile } from "node:child_process";
|
|
8
|
+
export const GCLOUD_SIGNED_OUT = "Vertex AI needs the Google Cloud CLI signed in on this computer. Run \"gcloud auth login\", then try again.";
|
|
9
|
+
const KEEP_MS = 45 * 60_000;
|
|
10
|
+
const runGcloud = () => new Promise((resolve, reject) => {
|
|
11
|
+
execFile("gcloud", ["auth", "print-access-token"], { timeout: 20_000, windowsHide: true }, (error, stdout) => {
|
|
12
|
+
const token = String(stdout ?? "").trim();
|
|
13
|
+
if (error || !token)
|
|
14
|
+
return reject(new Error(GCLOUD_SIGNED_OUT));
|
|
15
|
+
resolve(token);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
/** One cached token per account; a renewal in flight is shared. */
|
|
19
|
+
export function gcloudTokenCache(run = runGcloud, now = Date.now) {
|
|
20
|
+
let held = null;
|
|
21
|
+
let renewing = null;
|
|
22
|
+
return async () => {
|
|
23
|
+
if (held && held.until > now())
|
|
24
|
+
return held.token;
|
|
25
|
+
renewing ??= run().then((token) => { held = { token, until: now() + KEEP_MS }; return token; }).finally(() => { renewing = null; });
|
|
26
|
+
return renewing;
|
|
27
|
+
};
|
|
28
|
+
}
|