@b3os/cli 0.0.0-stage → 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,112 @@
1
- # Temporary Holding Version
1
+ # @b3os/cli (B3OS CLI)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The B3OS command line, built on `@b3os/sdk`. Every command takes `--json` (machine-readable stdout), `--yes`
4
+ (skip confirmations), `--quiet`, `--api-key`, `--base-url`, `--timeout MS` and `--help`. Without a terminal it never
5
+ prompts: a destructive command without `--yes` exits 2.
6
+
7
+ The npm package is `@b3os/cli`; its executable is `b3os`. Run it without a global installation:
8
+
9
+ ```sh
10
+ npx --yes --package @b3os/cli b3os --help
11
+ ```
12
+
13
+ For repeated use, install the package globally:
14
+
15
+ ```sh
16
+ npm install --global @b3os/cli
17
+ b3os login # device login; stores a CLI token
18
+ b3os scrape https://example.com # Markdown on stdout
19
+ b3os screenshot https://example.com --out shot.png --frame browser-dark
20
+ SBX=$(b3os sandbox create --template base)
21
+ b3os sandbox exec "$SBX" -- python3 -c 'print(2 + 2)'
22
+ b3os sandbox shell "$SBX"
23
+ b3os sandbox rm "$SBX" --yes
24
+ b3os mcp install --client claude
25
+ ```
26
+
27
+ ## Credentials
28
+
29
+ `--api-key`, else `B3OS_API_KEY`, else the token from `b3os login` (`$XDG_CONFIG_HOME/b3os/credentials.json`, default
30
+ `~/.config/b3os/`, mode 0600). `b3os whoami` shows which one is in use, its org, project and scopes, and where node
31
+ operations go. Inside a B3OS sandbox node operations use `B3OS_API_URL`. On a node they use b3osd's Unix socket
32
+ when `B3OS_SOCKET` is set, or when no key and no base URL are configured; over the socket the command acts as the
33
+ principal your uid maps to, not as a key's (see the SDK README for the routing rules).
34
+
35
+ `b3os login` runs the RFC 8628 device flow: it prints the dashboard URL and the code to confirm (and opens a browser
36
+ when there is a terminal), then polls until you approve. The token is never printed. `--scope 'vision:run
37
+ sandboxes:*'` asks for fewer scopes.
38
+
39
+ ## Commands
40
+
41
+ | Command | What it does |
42
+ |---|---|
43
+ | `login`, `logout`, `whoami` | device login, remove the stored token, show the credential in use |
44
+ | `keys list\|create\|get\|update\|revoke` | API keys (`create --name ci --scope vision:run,sandboxes:*` prints the secret once) |
45
+ | `scrape <url>` | `vision.scrape`; `--format markdown\|html\|raw_html\|text\|links\|json`, `--all-content`, `--engine`, `--no-cache`, `--header K=V`, `--out` |
46
+ | `screenshot <url>` | `render.createScreenshot`; saves the image (`--out`, `--format png\|webp\|jpeg`, `--width`/`--height`, `--dpr`, `--full-page`, `--selector`, `--background`, `--frame`, `--theme`, `--hide`, `--html FILE`) |
47
+ | `video <script.json>` | `render.createVideo`; streams progress, saves the MP4 (`--kind mp4\|gif\|poster\|vtt`, `--no-wait`) |
48
+ | `sandbox create` | `--template`, `--snapshot`, `--vcpu`, `--memory`, `--disk`, `--lifetime S`, `--on-idle`, `--env K=V`, `--port N[:public]`, `--grant SCOPES` |
49
+ | `sandbox exec <id> -- <cmd…>` | streams stdout and stderr; exits 0 when the command exits 0, else 10 with the remote code on stderr (`--exit-code` passes the remote code through instead); `--json` prints the buffered result; `--stdin` sends local stdin; `--background` |
50
+ | `sandbox shell <id>` | a terminal over the ticketed PTY WebSocket (raw mode, resize follows your window) |
51
+ | `sandbox ls\|get\|logs\|url\|rm` | list, inspect, follow background logs, get a port URL, delete |
52
+ | `routine deploy <file>` | publishes YAML or JSON by its `name` (`PUT /v1/routines/{name}` creates on first deploy) |
53
+ | `routine run <routine>` | `--input JSON\|@file`; waits and prints the output; `--follow` streams step events; `--no-wait` prints the run id |
54
+ | `routine logs <run_id>` | the run's steps, or `--follow` its events |
55
+ | `action search\|describe\|run` | marketplace actions (`run io.b3os/github/create-issue@1 --input @issue.json`) |
56
+ | `mcp install --client claude\|cursor\|codex` | adds the B3OS MCP server to the client (below) |
57
+ | `mcp serve [--packs a,b]` | the stdio MCP server in this process |
58
+ | `bench [ping\|scrape\|exec]` | a client-side latency probe from where you run it (below) |
59
+ | `api <METHOD> <path>` | any operation, with `--data JSON\|@file`, `--query k=v`, `--header k=v`, `--edge`/`--node` |
60
+
61
+ ## Exit codes
62
+
63
+ | Code | Meaning |
64
+ |---|---|
65
+ | 0 | success |
66
+ | 1 | an error not listed here |
67
+ | 2 | usage error, or a confirmation refused without `--yes` |
68
+ | 3 | authentication or authorization (401, 403) |
69
+ | 4 | not found (404) |
70
+ | 5 | invalid request, conflict or state error (other 4xx, including 421 `edge_only`) |
71
+ | 6 | rate limited, quota or credits (429, 402) |
72
+ | 7 | server error or unavailable (5xx) |
73
+ | 8 | timeout |
74
+ | 9 | connection error |
75
+ | 10 | a job or routine run failed, or a remote command (`sandbox exec`, `sandbox shell`) exited non-zero or was killed |
76
+ | 130 | interrupted |
77
+
78
+ `sandbox exec` and `sandbox shell` keep these codes: a remote exit code of 3 must not read as an auth error. Pass
79
+ `--exit-code` to exit with the remote command's own code (as `ssh` does) when a script needs it. Errors go to stderr: one
80
+ line plus validation items, or with `--json` a `{"error": {code, status, title, detail, type, request_id, errors}}`
81
+ object.
82
+
83
+ ## MCP install
84
+
85
+ `b3os mcp install --client claude|cursor|codex [--scope user|project] [--packs github,slack]` adds an entry that runs
86
+ `npx -y @b3os/mcp`. The server reads `B3OS_API_KEY` or the `b3os login` token itself, so the client's config holds no
87
+ secret. Claude Code is configured through `claude mcp add` (or `.mcp.json` with `--scope project` when the `claude`
88
+ CLI is missing), Cursor through `~/.cursor/mcp.json` (or `.cursor/mcp.json`), Codex through
89
+ `~/.codex/config.toml` (or `.codex/config.toml`; only the `[mcp_servers.b3os]` table is replaced). `--print` prints
90
+ the entry instead of writing it. `--remote` points Claude or Cursor at the edge's `/mcp` endpoint with an
91
+ `Authorization: Bearer` header that refers to `B3OS_API_KEY` (`${B3OS_API_KEY}` for Claude Code, `${env:B3OS_API_KEY}`
92
+ for Cursor; the client expands it when it connects), so no key is written to a config file (project files such as
93
+ `.mcp.json` are often committed), printed, or put on the `claude mcp add` command line. Start the client with
94
+ `B3OS_API_KEY` in its environment. New user-scope config files are created mode 0600. The expansion is the
95
+ clients' documented behavior; it has not been tried against a running Claude Code or Cursor here.
96
+
97
+ ## bench
98
+
99
+ `b3os bench ping -n 30` (also `scrape --url URL`, `exec --sandbox sbx_…`) times sequential calls from your machine and
100
+ prints client-side p50/p95/p99 next to the server's own `Server-Timing` total and phases, so the difference
101
+ (network, TLS, edge, client) is visible. It is a closed-loop probe labeled `dev`, not the published harness
102
+ (`bench/harness`, ARCHITECTURE §6). `--interval-ms` spaces calls to see idle-gap latency; `--json` includes every
103
+ sample.
104
+
105
+ ## Development
106
+
107
+ ```sh
108
+ pnpm --filter @b3os/cli typecheck
109
+ pnpm --filter @b3os/cli test
110
+ node --conditions=b3os-source packages/cli/src/main.ts --help # run from source
111
+ pnpm --filter @b3os/cli build # dist/, used by bin/b3os.js
112
+ ```
package/bin/b3os.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ // `b3os` launcher for the built CLI. From a checkout without a build:
3
+ // node --conditions=b3os-source packages/cli/src/main.ts <args>
4
+ import { run } from "../dist/main.js";
5
+
6
+ process.exitCode = await run(process.argv.slice(2));
@@ -0,0 +1,2 @@
1
+ import { type Ctx } from "../ctx.ts";
2
+ export declare function api(ctx: Ctx, argv: string[]): Promise<number>;
@@ -0,0 +1,48 @@
1
+ // b3os api <METHOD> <path>: any operation, with the CLI's credentials and routing (for endpoints newer than the
2
+ // CLI and for scripting). Prints the response body.
3
+ import { readFileSync } from "node:fs";
4
+ import { EXIT, jsonFlag, pairs, parse, UsageError } from "../ctx.js";
5
+ const METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
6
+ export async function api(ctx, argv) {
7
+ const a = parse(argv, {
8
+ data: { type: "string", short: "d" },
9
+ query: { type: "string", multiple: true },
10
+ header: { type: "string", multiple: true },
11
+ edge: { type: "boolean" },
12
+ node: { type: "boolean" },
13
+ });
14
+ ctx.applyGlobals(a.values);
15
+ const [m, path] = a.positionals;
16
+ if (!m || !path || a.values.help) {
17
+ ctx.out("usage: b3os api <METHOD> </v1/path> [--data JSON|@file] [--query k=v ...] [--header k=v ...] [--edge|--node]");
18
+ return m && path ? EXIT.OK : EXIT.USAGE;
19
+ }
20
+ const method = m.toUpperCase();
21
+ if (!METHODS.includes(method))
22
+ throw new UsageError(`unknown method ${m}`);
23
+ if (!path.startsWith("/"))
24
+ throw new UsageError("the path starts with /v1/ or /compat/");
25
+ const raw = typeof a.values.data === "string" ? a.values.data : undefined;
26
+ const body = raw === undefined ? undefined : jsonFlag(raw.startsWith("@") ? readFileSync(raw.slice(1), "utf8") : raw, "--data");
27
+ const edge = a.values.edge ? true : a.values.node ? false : undefined;
28
+ const res = await ctx
29
+ .client()
30
+ .request({
31
+ method: method,
32
+ path,
33
+ query: a.values.query ? pairs(a.values.query, "--query") : undefined,
34
+ headers: a.values.header ? pairs(a.values.header, "--header") : undefined,
35
+ body,
36
+ edge,
37
+ })
38
+ .withResponse();
39
+ if (typeof res.data === "string")
40
+ ctx.out(res.data);
41
+ else if (res.data instanceof Uint8Array)
42
+ ctx.io.stdout.write(res.data);
43
+ else if (res.data !== undefined)
44
+ ctx.printJson(res.data);
45
+ ctx.info(`${res.response.status} ${res.response.requestId ?? ""} ${res.response.timing.total_ms ?? "-"} ms`.trim());
46
+ return EXIT.OK;
47
+ }
48
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/commands/api.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,oDAAoD;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAY,IAAI,EAAE,QAAQ,EAAE,KAAK,E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C;SAC/C,IAAI,GAAG,CAAC,IAAI,YAAY,UAAU;QAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SAClE,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS;QAAE,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACzD,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACpH,OAAO,IAAI,CAAC,EAAE,CAAC;AACjB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type Ctx } from "../ctx.ts";
2
+ export declare function login(ctx: Ctx, argv: string[]): Promise<number>;
3
+ export declare function logout(ctx: Ctx, argv: string[]): Promise<number>;
4
+ export declare function whoami(ctx: Ctx, argv: string[]): Promise<number>;
@@ -0,0 +1,141 @@
1
+ // b3os login | logout | whoami. Login is the RFC 8628 device flow (platform.yaml platformCreateDeviceCode and
2
+ // platformExchangeDeviceCode): show the code, the user approves it in the dashboard, the CLI polls for a
3
+ // `b3os_pat_` token and stores it. It never asks anything on the terminal.
4
+ import { spawn } from "node:child_process";
5
+ import { B3OS, B3OSError, DEFAULT_BASE_URL } from "@b3os/sdk";
6
+ import { credentialsPath, deleteCredentials, saveCredentials } from "../config.js";
7
+ import { EXIT, parse } from "../ctx.js";
8
+ function openBrowser(url) {
9
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
10
+ const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
11
+ try {
12
+ const p = spawn(cmd, args, { stdio: "ignore", detached: true });
13
+ p.on("error", () => { });
14
+ p.unref();
15
+ }
16
+ catch {
17
+ // No browser here; the printed URL is enough.
18
+ }
19
+ }
20
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
21
+ export async function login(ctx, argv) {
22
+ const a = parse(argv, { "no-browser": { type: "boolean" }, scope: { type: "string" } });
23
+ ctx.applyGlobals(a.values);
24
+ if (a.values.help) {
25
+ ctx.out("usage: b3os login [--scope 'vision:run sandboxes:*'] [--no-browser] [--base-url URL]");
26
+ return EXIT.OK;
27
+ }
28
+ const baseUrl = ctx.baseUrl ?? process.env.B3OS_BASE_URL ?? DEFAULT_BASE_URL;
29
+ // Device login is public: no credential is sent, whatever the environment holds.
30
+ const anon = new B3OS({ apiKey: null, baseUrl, transport: "http", socketPath: false });
31
+ const scope = typeof a.values.scope === "string" ? a.values.scope : undefined;
32
+ const code = await anon.request({
33
+ method: "POST",
34
+ path: "/v1/auth/device/code",
35
+ body: scope ? { client_id: "b3os-cli", scope } : { client_id: "b3os-cli" },
36
+ bodyType: "form",
37
+ edge: true,
38
+ errorFormat: "oauth2",
39
+ });
40
+ if (ctx.json) {
41
+ ctx.printJsonLine({
42
+ verification_uri: code.verification_uri,
43
+ verification_uri_complete: code.verification_uri_complete,
44
+ user_code: code.user_code,
45
+ expires_in: code.expires_in,
46
+ });
47
+ }
48
+ else {
49
+ ctx.warn(`Open ${code.verification_uri_complete}`);
50
+ ctx.warn(`and check that it shows the code ${code.user_code}. Waiting for approval...`);
51
+ }
52
+ if (ctx.isTTY && !a.values["no-browser"])
53
+ openBrowser(code.verification_uri_complete);
54
+ // RFC 8628 §3.5: wait `interval` seconds between polls (5 when absent).
55
+ let interval = (typeof code.interval === "number" && code.interval >= 0 ? code.interval : 5) * 1000;
56
+ const deadline = Date.now() + code.expires_in * 1000;
57
+ for (;;) {
58
+ if (Date.now() > deadline)
59
+ throw new B3OSError({ code: "expired_token", detail: "The login code expired; run b3os login again" });
60
+ await sleep(interval);
61
+ try {
62
+ const tok = await anon.request({
63
+ method: "POST",
64
+ path: "/v1/auth/device/token",
65
+ body: {
66
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
67
+ device_code: code.device_code,
68
+ client_id: "b3os-cli",
69
+ },
70
+ bodyType: "form",
71
+ edge: true,
72
+ errorFormat: "oauth2",
73
+ }, { maxRetries: 0 });
74
+ const expires_at = tok.expires_in ? new Date(Date.now() + tok.expires_in * 1000).toISOString() : null;
75
+ const path = saveCredentials({
76
+ token: tok.access_token,
77
+ base_url: baseUrl,
78
+ org_id: tok.org_id,
79
+ project_id: tok.project_id,
80
+ scope: tok.scope,
81
+ expires_at,
82
+ created_at: new Date().toISOString(),
83
+ });
84
+ const summary = {
85
+ logged_in: true,
86
+ org_id: tok.org_id,
87
+ project_id: tok.project_id,
88
+ scope: tok.scope,
89
+ expires_at,
90
+ credentials: path,
91
+ };
92
+ ctx.result(summary, () => ctx.out(`Logged in: org ${tok.org_id}, project ${tok.project_id} (token saved in ${path})`));
93
+ return EXIT.OK;
94
+ }
95
+ catch (e) {
96
+ if (!(e instanceof B3OSError))
97
+ throw e;
98
+ if (e.code === "authorization_pending")
99
+ continue;
100
+ if (e.code === "slow_down") {
101
+ interval += 5000;
102
+ continue;
103
+ }
104
+ if (e.code === "rate_limited") {
105
+ interval = Math.max(interval, e.retryAfterMs ?? 10_000);
106
+ continue;
107
+ }
108
+ throw e;
109
+ }
110
+ }
111
+ }
112
+ export async function logout(ctx, argv) {
113
+ const a = parse(argv);
114
+ ctx.applyGlobals(a.values);
115
+ const removed = deleteCredentials();
116
+ ctx.result({ logged_out: removed, credentials: credentialsPath() }, () => ctx.out(removed ? `Removed ${credentialsPath()}` : "Not logged in"));
117
+ return EXIT.OK;
118
+ }
119
+ export async function whoami(ctx, argv) {
120
+ const a = parse(argv);
121
+ ctx.applyGlobals(a.values);
122
+ const c = ctx.credential();
123
+ const b3 = ctx.client();
124
+ const me = await b3.keys.getCurrentKey();
125
+ const info = { ...me, credential: c.source, routes: b3.routes };
126
+ ctx.result(info, () => {
127
+ ctx.out(`${me.kind} ${me.key_id ?? ""}`.trim());
128
+ if (me.user)
129
+ ctx.out(`user ${JSON.stringify(me.user)}`);
130
+ ctx.out(`org ${me.org_id}`);
131
+ ctx.out(`project ${me.project_id}`);
132
+ ctx.out(`scopes ${me.scopes.join(" ")}`);
133
+ if (me.spend_cap_usd !== null)
134
+ ctx.out(`spend cap $${me.spend_cap_usd}`);
135
+ if (me.expires_at)
136
+ ctx.out(`expires ${me.expires_at}`);
137
+ ctx.out(`via ${c.source}; node operations go to ${b3.routes.node}`);
138
+ });
139
+ return EXIT.OK;
140
+ }
141
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,yGAAyG;AACzG,2EAA2E;AAE3E,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAY,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAoBlD,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;IACvG,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC7E,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,Q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CAAC;QACzD,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,MAAM,2BAA2B,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,EAAE,CAAC;AACjB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type Ctx } from "../ctx.ts";
2
+ export declare function percentile(sorted: number[], p: number): number | null;
3
+ export declare function summarize(values: number[]): {
4
+ n: number;
5
+ min: number | null;
6
+ p50: number | null;
7
+ p95: number | null;
8
+ p99: number | null;
9
+ max: number | null;
10
+ mean: number | null;
11
+ };
12
+ export declare function bench(ctx: Ctx, argv: string[]): Promise<number>;