@b3os/cli 0.2.0 → 0.2.2

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 (217) hide show
  1. package/README.md +87 -7
  2. package/assets/b3os-run.py +137 -0
  3. package/assets/skill/b3os/SKILL.md +111 -0
  4. package/dist/commands/_agents.d.ts +14 -0
  5. package/dist/commands/_agents.js +33 -0
  6. package/dist/commands/_agents.js.map +1 -0
  7. package/dist/commands/_common.js +6 -2
  8. package/dist/commands/_common.js.map +1 -1
  9. package/dist/commands/_context.d.ts +49 -0
  10. package/dist/commands/_context.js +260 -0
  11. package/dist/commands/_context.js.map +1 -0
  12. package/dist/commands/_next.d.ts +39 -0
  13. package/dist/commands/_next.js +77 -0
  14. package/dist/commands/_next.js.map +1 -0
  15. package/dist/commands/agent.d.ts +42 -0
  16. package/dist/commands/agent.js +218 -0
  17. package/dist/commands/agent.js.map +1 -0
  18. package/dist/commands/app.d.ts +2 -0
  19. package/dist/commands/app.js +559 -54
  20. package/dist/commands/app.js.map +1 -1
  21. package/dist/commands/auth.d.ts +88 -2
  22. package/dist/commands/auth.js +354 -44
  23. package/dist/commands/auth.js.map +1 -1
  24. package/dist/commands/docs.d.ts +54 -0
  25. package/dist/commands/docs.js +202 -0
  26. package/dist/commands/docs.js.map +1 -0
  27. package/dist/commands/doctor.d.ts +23 -0
  28. package/dist/commands/doctor.js +313 -0
  29. package/dist/commands/doctor.js.map +1 -0
  30. package/dist/commands/init.d.ts +38 -1
  31. package/dist/commands/init.js +259 -60
  32. package/dist/commands/init.js.map +1 -1
  33. package/dist/commands/listen.d.ts +30 -0
  34. package/dist/commands/listen.js +194 -0
  35. package/dist/commands/listen.js.map +1 -0
  36. package/dist/commands/manifest.d.ts +13 -1
  37. package/dist/commands/manifest.js +81 -18
  38. package/dist/commands/manifest.js.map +1 -1
  39. package/dist/commands/mcp.d.ts +25 -2
  40. package/dist/commands/mcp.js +120 -11
  41. package/dist/commands/mcp.js.map +1 -1
  42. package/dist/commands/sandbox.d.ts +35 -6
  43. package/dist/commands/sandbox.js +208 -9
  44. package/dist/commands/sandbox.js.map +1 -1
  45. package/dist/commands/setup.d.ts +39 -0
  46. package/dist/commands/setup.js +203 -0
  47. package/dist/commands/setup.js.map +1 -0
  48. package/dist/commands/tool.d.ts +154 -0
  49. package/dist/commands/tool.js +785 -0
  50. package/dist/commands/tool.js.map +1 -0
  51. package/dist/config.d.ts +30 -6
  52. package/dist/config.js +39 -8
  53. package/dist/config.js.map +1 -1
  54. package/dist/ctx.d.ts +5 -45
  55. package/dist/ctx.js +25 -160
  56. package/dist/ctx.js.map +1 -1
  57. package/dist/docs/index.json +1 -0
  58. package/dist/docs/pages/actions/call.md +300 -0
  59. package/dist/docs/pages/actions/catalog/airtable.md +737 -0
  60. package/dist/docs/pages/actions/catalog/arxiv.md +166 -0
  61. package/dist/docs/pages/actions/catalog/chainalysis-sanctions.md +125 -0
  62. package/dist/docs/pages/actions/catalog/coingecko.md +1558 -0
  63. package/dist/docs/pages/actions/catalog/deps-dev.md +465 -0
  64. package/dist/docs/pages/actions/catalog/dexscreener.md +568 -0
  65. package/dist/docs/pages/actions/catalog/discord.md +784 -0
  66. package/dist/docs/pages/actions/catalog/finnhub.md +776 -0
  67. package/dist/docs/pages/actions/catalog/frankfurter.md +438 -0
  68. package/dist/docs/pages/actions/catalog/github.md +1853 -0
  69. package/dist/docs/pages/actions/catalog/gmail.md +575 -0
  70. package/dist/docs/pages/actions/catalog/google-calendar.md +654 -0
  71. package/dist/docs/pages/actions/catalog/google-drive.md +502 -0
  72. package/dist/docs/pages/actions/catalog/google-sheets.md +700 -0
  73. package/dist/docs/pages/actions/catalog/hacker-news.md +542 -0
  74. package/dist/docs/pages/actions/catalog/http.md +824 -0
  75. package/dist/docs/pages/actions/catalog/hyperliquid.md +942 -0
  76. package/dist/docs/pages/actions/catalog/jira.md +920 -0
  77. package/dist/docs/pages/actions/catalog/kalshi.md +917 -0
  78. package/dist/docs/pages/actions/catalog/linear.md +1030 -0
  79. package/dist/docs/pages/actions/catalog/markets.md +21 -0
  80. package/dist/docs/pages/actions/catalog/morpho.md +247 -0
  81. package/dist/docs/pages/actions/catalog/notion.md +1077 -0
  82. package/dist/docs/pages/actions/catalog/nws.md +485 -0
  83. package/dist/docs/pages/actions/catalog/open-meteo.md +559 -0
  84. package/dist/docs/pages/actions/catalog/polymarket.md +1523 -0
  85. package/dist/docs/pages/actions/catalog/pushbullet.md +220 -0
  86. package/dist/docs/pages/actions/catalog/resend.md +307 -0
  87. package/dist/docs/pages/actions/catalog/s3.md +513 -0
  88. package/dist/docs/pages/actions/catalog/sec-edgar.md +487 -0
  89. package/dist/docs/pages/actions/catalog/slack.md +2629 -0
  90. package/dist/docs/pages/actions/catalog/stripe.md +1405 -0
  91. package/dist/docs/pages/actions/catalog/wikipedia.md +379 -0
  92. package/dist/docs/pages/actions/catalog.md +46 -0
  93. package/dist/docs/pages/actions/limits.md +50 -0
  94. package/dist/docs/pages/actions/model-tools.md +225 -0
  95. package/dist/docs/pages/actions/packs.md +148 -0
  96. package/dist/docs/pages/actions/settings.md +69 -0
  97. package/dist/docs/pages/actions/tools.md +244 -0
  98. package/dist/docs/pages/actions/triggers.md +149 -0
  99. package/dist/docs/pages/actions.md +88 -0
  100. package/dist/docs/pages/compat/anthropic.md +168 -0
  101. package/dist/docs/pages/compat/e2b.md +194 -0
  102. package/dist/docs/pages/compat/firecrawl.md +138 -0
  103. package/dist/docs/pages/compat/openai.md +168 -0
  104. package/dist/docs/pages/concepts/auth.md +151 -0
  105. package/dist/docs/pages/concepts/beta.md +55 -0
  106. package/dist/docs/pages/concepts/glossary.md +71 -0
  107. package/dist/docs/pages/concepts/ids.md +98 -0
  108. package/dist/docs/pages/concepts/jobs.md +229 -0
  109. package/dist/docs/pages/concepts/latency.md +138 -0
  110. package/dist/docs/pages/concepts/limits.md +191 -0
  111. package/dist/docs/pages/concepts/stack.md +59 -0
  112. package/dist/docs/pages/concepts/timing.md +86 -0
  113. package/dist/docs/pages/concepts/usage.md +110 -0
  114. package/dist/docs/pages/design/b3os-yaml.md +370 -0
  115. package/dist/docs/pages/design/deploy-from-github.md +122 -0
  116. package/dist/docs/pages/design/observability.md +134 -0
  117. package/dist/docs/pages/errors.md +1824 -0
  118. package/dist/docs/pages/infer/chat.md +570 -0
  119. package/dist/docs/pages/infer/limits.md +55 -0
  120. package/dist/docs/pages/infer/messages.md +185 -0
  121. package/dist/docs/pages/infer/responses.md +173 -0
  122. package/dist/docs/pages/infer/settings.md +154 -0
  123. package/dist/docs/pages/infer/speech.md +323 -0
  124. package/dist/docs/pages/infer.md +154 -0
  125. package/dist/docs/pages/introduction.md +162 -0
  126. package/dist/docs/pages/platform/addresses.md +174 -0
  127. package/dist/docs/pages/platform/call-log.md +99 -0
  128. package/dist/docs/pages/platform/custom-domains.md +104 -0
  129. package/dist/docs/pages/platform/keys.md +79 -0
  130. package/dist/docs/pages/platform/limits.md +57 -0
  131. package/dist/docs/pages/platform/members.md +101 -0
  132. package/dist/docs/pages/platform/requests.md +116 -0
  133. package/dist/docs/pages/platform/settings.md +129 -0
  134. package/dist/docs/pages/platform/webhooks.md +68 -0
  135. package/dist/docs/pages/platform.md +67 -0
  136. package/dist/docs/pages/quickstart/mcp.md +94 -0
  137. package/dist/docs/pages/quickstart/sandbox-agent.md +205 -0
  138. package/dist/docs/pages/quickstart/scrape.md +134 -0
  139. package/dist/docs/pages/quickstart.md +45 -0
  140. package/dist/docs/pages/render/inspections.md +162 -0
  141. package/dist/docs/pages/render/limits.md +72 -0
  142. package/dist/docs/pages/render/screenshots.md +179 -0
  143. package/dist/docs/pages/render/settings.md +431 -0
  144. package/dist/docs/pages/render/styles.md +342 -0
  145. package/dist/docs/pages/render/videos.md +272 -0
  146. package/dist/docs/pages/render.md +118 -0
  147. package/dist/docs/pages/routines/callables.md +174 -0
  148. package/dist/docs/pages/routines/definitions.md +361 -0
  149. package/dist/docs/pages/routines/limits.md +117 -0
  150. package/dist/docs/pages/routines/runs.md +328 -0
  151. package/dist/docs/pages/routines/settings.md +104 -0
  152. package/dist/docs/pages/routines/triggers.md +339 -0
  153. package/dist/docs/pages/routines.md +216 -0
  154. package/dist/docs/pages/sandboxes/agents.md +217 -0
  155. package/dist/docs/pages/sandboxes/commands.md +272 -0
  156. package/dist/docs/pages/sandboxes/images.md +166 -0
  157. package/dist/docs/pages/sandboxes/limits.md +143 -0
  158. package/dist/docs/pages/sandboxes/ports.md +260 -0
  159. package/dist/docs/pages/sandboxes/settings.md +358 -0
  160. package/dist/docs/pages/sandboxes/snapshots.md +423 -0
  161. package/dist/docs/pages/sandboxes/swarms.md +146 -0
  162. package/dist/docs/pages/sandboxes/volumes.md +131 -0
  163. package/dist/docs/pages/sandboxes.md +231 -0
  164. package/dist/docs/pages/sdks/cli.md +121 -0
  165. package/dist/docs/pages/sdks/mcp.md +169 -0
  166. package/dist/docs/pages/sdks/python.md +146 -0
  167. package/dist/docs/pages/sdks/typescript.md +202 -0
  168. package/dist/docs/pages/sdks.md +282 -0
  169. package/dist/docs/pages/settings.md +33 -0
  170. package/dist/docs/pages/vault/limits.md +46 -0
  171. package/dist/docs/pages/vault.md +133 -0
  172. package/dist/docs/pages/vision/agent-browser.md +115 -0
  173. package/dist/docs/pages/vision/crawl.md +333 -0
  174. package/dist/docs/pages/vision/extract.md +152 -0
  175. package/dist/docs/pages/vision/fetcher.md +15 -0
  176. package/dist/docs/pages/vision/limits.md +79 -0
  177. package/dist/docs/pages/vision/profiles.md +111 -0
  178. package/dist/docs/pages/vision/proxy.md +131 -0
  179. package/dist/docs/pages/vision/scrape.md +356 -0
  180. package/dist/docs/pages/vision/sessions.md +311 -0
  181. package/dist/docs/pages/vision/settings.md +656 -0
  182. package/dist/docs/pages/vision.md +175 -0
  183. package/dist/errors.d.ts +129 -0
  184. package/dist/errors.js +326 -0
  185. package/dist/errors.js.map +1 -0
  186. package/dist/main.d.ts +1 -1
  187. package/dist/main.js +26 -13
  188. package/dist/main.js.map +1 -1
  189. package/dist/manifest/apply.d.ts +4 -0
  190. package/dist/manifest/apply.js +2 -0
  191. package/dist/manifest/apply.js.map +1 -1
  192. package/dist/manifest/domains.d.ts +50 -0
  193. package/dist/manifest/domains.js +159 -0
  194. package/dist/manifest/domains.js.map +1 -0
  195. package/dist/manifest/link.d.ts +20 -0
  196. package/dist/manifest/link.js +24 -0
  197. package/dist/manifest/link.js.map +1 -0
  198. package/dist/manifest/record.d.ts +1 -1
  199. package/dist/tool/archive.d.ts +33 -0
  200. package/dist/tool/archive.js +174 -0
  201. package/dist/tool/archive.js.map +1 -0
  202. package/dist/tool/calls.d.ts +46 -0
  203. package/dist/tool/calls.js +274 -0
  204. package/dist/tool/calls.js.map +1 -0
  205. package/dist/tool/checks.d.ts +21 -0
  206. package/dist/tool/checks.js +145 -0
  207. package/dist/tool/checks.js.map +1 -0
  208. package/dist/tool/elf.d.ts +19 -0
  209. package/dist/tool/elf.js +107 -0
  210. package/dist/tool/elf.js.map +1 -0
  211. package/dist/tool/predict.d.ts +8 -0
  212. package/dist/tool/predict.js +38 -0
  213. package/dist/tool/predict.js.map +1 -0
  214. package/dist/tool/ustar.d.ts +5 -0
  215. package/dist/tool/ustar.js +220 -0
  216. package/dist/tool/ustar.js.map +1 -0
  217. package/package.json +6 -5
@@ -0,0 +1,169 @@
1
+ # MCP server
2
+
3
+ > Connect any MCP client to B3OS through the local stdio server or the remote endpoint, which tools each one lists, and how agents reach marketplace actions.
4
+
5
+ Source: https://docs.beta.b3os.org/sdks/mcp.md
6
+
7
+ B3OS has two MCP servers that take the same key:
8
+
9
+ | Server | How a client reaches it | Credential |
10
+ |---|---|---|
11
+ | Local, `@b3os/mcp` | The client starts `npx -y @b3os/mcp@0.2` and talks to it over stdio | The server reads `B3OS_API_KEY`, else your `b3os login` token; the client's config holds no secret |
12
+ | Remote | `https://beta-api.b3os.org/mcp`, stateless Streamable HTTP | An `Authorization: Bearer` header whose value the client fills in from `B3OS_API_KEY` in its environment |
13
+
14
+ The tools act with the key's scopes, so an agent can do only what its key allows. Give it a key made for the job.
15
+
16
+ ## Connect
17
+
18
+ ```bash
19
+ npx -y @b3os/cli@0.2 mcp install --client claude # or cursor, codex
20
+ ```
21
+
22
+ This registers the local server; add `--remote` to register the remote one instead. Either way no key is written to a config file. [Install the MCP server](https://docs.beta.b3os.org/quickstart/mcp#configure-it-by-hand) shows both configurations written by hand.
23
+
24
+ ## Tools
25
+
26
+ Both servers keep the list short and in a fixed order, so prompt caches stay warm, and name tools after the product they call. Both serve one tool table (`packages/mcp/table/table.json` in the repository, generated from the API spec), and this list is generated from it. The core tools are always there; the local server adds other toolsets with `--toolsets sandboxes,vision` (or `B3OS_MCP_TOOLSETS`, or `all`), and the remote server with `?toolsets=sandboxes,vision` (or `all`) on its URL:
27
+
28
+ | Tool | Does | Local `@b3os/mcp` | Remote `/mcp` |
29
+ |---|---|---|---|
30
+ | `vision_scrape` | Scrape a web page | Yes | Yes |
31
+ | `vision_map` | List a site's URLs | Yes | Yes |
32
+ | `vision_crawl` | Crawl a site | Yes | Yes |
33
+ | `vision_act` | Drive a browser | Yes | Yes |
34
+ | `render_screenshot` | Take a screenshot | Yes | Yes |
35
+ | `render_video` | Render a product video | Yes | Yes |
36
+ | `sandbox_create` | Create a sandbox | Yes | Yes |
37
+ | `sandbox_exec` | Run a command in a sandbox | Yes | Yes |
38
+ | `sandbox_read_file` | Read a file in a sandbox | Yes | Yes |
39
+ | `sandbox_write_file` | Write a file in a sandbox | Yes | Yes |
40
+ | `sandbox_delete` | Delete a sandbox | Yes | Yes |
41
+ | `routine_run` | Run a routine | Yes | Yes |
42
+ | `actions_search` | Search catalog actions | Yes | Yes |
43
+ | `actions_describe` | Describe an action | Yes | Yes |
44
+ | `actions_call` | Call an action | Yes | Yes |
45
+ | `sandbox_run_code` | Run code in a sandbox kernel | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
46
+ | `sandbox_pause` | Pause a sandbox | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
47
+ | `sandbox_resume` | Resume a sandbox | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
48
+ | `sandbox_list` | List sandboxes | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
49
+ | `sandbox_get` | Get a sandbox | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
50
+ | `sandbox_fork` | Fork a sandbox | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
51
+ | `sandbox_snapshot` | Snapshot a sandbox | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
52
+ | `sandbox_list_snapshots` | List snapshots | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
53
+ | `sandbox_get_snapshot` | Get a snapshot | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
54
+ | `sandbox_delete_snapshot` | Delete a snapshot | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
55
+ | `sandbox_list_templates` | List sandbox templates | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
56
+ | `sandbox_get_template` | Get a sandbox template | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
57
+ | `sandbox_set_timeout` | Change a sandbox's timeout | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
58
+ | `sandbox_port_url` | Get a preview URL for a port | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
59
+ | `sandbox_port_host` | Give a port its own host | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
60
+ | `sandbox_logs` | Read background process output | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
61
+ | `sandbox_list_processes` | List sandbox processes | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
62
+ | `sandbox_kill_process` | Stop a sandbox process | With `--toolsets sandboxes` | With `?toolsets=sandboxes` |
63
+ | `vision_search` | Search the web | With `--toolsets vision` | With `?toolsets=vision` |
64
+ | `vision_batch` | Scrape many URLs | With `--toolsets vision` | With `?toolsets=vision` |
65
+ | `vision_cancel_batch` | Cancel a batch | With `--toolsets vision` | With `?toolsets=vision` |
66
+ | `vision_cancel_crawl` | Cancel a crawl | With `--toolsets vision` | With `?toolsets=vision` |
67
+ | `vision_create_session` | Open a browser session | With `--toolsets vision` | With `?toolsets=vision` |
68
+ | `vision_list_sessions` | List browser sessions | With `--toolsets vision` | With `?toolsets=vision` |
69
+ | `vision_get_session` | Get a browser session | With `--toolsets vision` | With `?toolsets=vision` |
70
+ | `vision_close_session` | Close a browser session | With `--toolsets vision` | With `?toolsets=vision` |
71
+ | `vision_save_profile` | Save a session as a profile | With `--toolsets vision` | With `?toolsets=vision` |
72
+ | `vision_list_profiles` | List browser profiles | With `--toolsets vision` | With `?toolsets=vision` |
73
+ | `vision_get_profile` | Get a browser profile | With `--toolsets vision` | With `?toolsets=vision` |
74
+ | `vision_update_profile` | Update a browser profile | With `--toolsets vision` | With `?toolsets=vision` |
75
+ | `vision_delete_profile` | Delete a browser profile | With `--toolsets vision` | With `?toolsets=vision` |
76
+ | `routine_list_runs` | List a routine's runs | With `--toolsets routines` | With `?toolsets=routines` |
77
+ | `routine_get_run` | Get a routine run | With `--toolsets routines` | With `?toolsets=routines` |
78
+ | `routine_run_events` | Read a run's events | With `--toolsets routines` | With `?toolsets=routines` |
79
+ | `routine_validate` | Check a routine definition | With `--toolsets routines` | With `?toolsets=routines` |
80
+ | `routine_signal` | Signal a routine run | With `--toolsets routines` | With `?toolsets=routines` |
81
+ | `infer_chat` | Chat with the node's model | With `--toolsets infer` | With `?toolsets=infer` |
82
+ | `infer_models` | List the node's models | With `--toolsets infer` | With `?toolsets=infer` |
83
+ | `infer_voices` | List narration voices | With `--toolsets infer` | With `?toolsets=infer` |
84
+ | `usage_get` | Summarize usage | With `--toolsets platform` | With `?toolsets=platform` |
85
+ | `limits_get` | Get your limits | With `--toolsets platform` | With `?toolsets=platform` |
86
+ | `requests_list` | List API requests | With `--toolsets platform` | With `?toolsets=platform` |
87
+ | `requests_get` | Get an API request | With `--toolsets platform` | With `?toolsets=platform` |
88
+ | `traces_list` | List traces | With `--toolsets platform` | With `?toolsets=platform` |
89
+ | `traces_get` | Get a trace | With `--toolsets platform` | With `?toolsets=platform` |
90
+ | `llm_calls_list` | List kept model calls | With `--toolsets platform` | With `?toolsets=platform` |
91
+ | `llm_calls_get` | Get a kept model call | With `--toolsets platform` | With `?toolsets=platform` |
92
+ | `llm_calls_get_prompt_and_answer` | Read a model call's prompt and answer | With `--toolsets platform` | With `?toolsets=platform` |
93
+ | `webhooks_list_deliveries` | List webhook deliveries | With `--toolsets platform` | With `?toolsets=platform` |
94
+ | `webhooks_send_test` | Send a test webhook | With `--toolsets platform` | With `?toolsets=platform` |
95
+ | `render_inspect` | Inspect a page frame by frame | With `--toolsets render` | With `?toolsets=render` |
96
+ | `render_get` | Get a video | With `--toolsets render` | With `?toolsets=render` |
97
+ | `render_restyle` | Restyle a video | With `--toolsets render` | With `?toolsets=render` |
98
+ | `render_presets` | List render presets | With `--toolsets render` | With `?toolsets=render` |
99
+ | `render_share` | Share a video | With `--toolsets render` | With `?toolsets=render` |
100
+
101
+ Both servers take the same inputs: a tool's arguments are its operation's request fields (the scrape request's, profile included), and the tools that start long work (`vision_crawl`, `render_video` and `routine_run`) wait up to `wait_s` seconds, then return the job's ID to pass back as `job_id`. Your client's tool list (`tools/list`) shows each tool's exact input schema.
102
+
103
+ API errors come back as tool results marked as errors, with the problem's code, detail, validation pointers and request ID, so the model can correct its call. A client that cancels a call (`notifications/cancelled`) stops it on the local server, scrapes and commands included.
104
+
105
+ ## Server instructions
106
+
107
+ Each server sends an `instructions` string with its handshake, which clients pass to the model so it knows when to reach for B3OS tools. The current text:
108
+
109
+ | Server | Instructions |
110
+ |---|---|
111
+ | Both | B3OS tools run on a B3OS node, next to a served model: web pages, browsers, sandboxes, screenshots, routines and marketplace actions. Prefer vision_scrape over a built-in web fetch whenever you read a web page: it returns the page's main content as Markdown, uses a real browser when the page needs JavaScript, can answer from a recent cached copy. Use vision_map to list a site's URLs, vision_crawl to read many pages of one site, and vision_act to click, type or sign in on a page. Run code, shell commands, package installs and file processing in a sandbox rather than on the user's machine: sandbox_create starts an isolated microVM that stops by itself after timeout_s; then use sandbox_exec, sandbox_write_file and sandbox_read_file on its id, and sandbox_delete when you are done. render_screenshot captures a page as an image; render_video takes a goal instead of beats; the render toolset restyles, shares and lists presets. To use a third-party service (GitHub, Slack, Linear, Notion and others) call actions_search, then actions_describe for the input schema, then actions_call; credentials come from the user's stored connections, never from tool arguments. Tools that start long jobs (vision_crawl, render_video, routine_run) wait up to wait_s seconds, then return the job id: call the same tool with job_id to keep waiting. Calls count against the API key's organization limits. |
112
+
113
+ Calls record usage against the key's organization; every price is zero during the beta ([pricing](https://docs.beta.b3os.org/concepts/usage#pricing)).
114
+
115
+ ## Marketplace actions
116
+
117
+ Pack actions are not listed one by one; there are too many. An agent reaches them in three calls:
118
+
119
+ 1. `actions_search` finds actions by what they do.
120
+ 2. `actions_describe` returns the chosen action's input schema and the connections it needs.
121
+ 3. `actions_call` runs it.
122
+
123
+ To give an agent a pack's actions as direct tools, name the packs: `--packs github,slack` (or `B3OS_MCP_PACKS`) for the local server, `?packs=github,slack` on the remote URL. Each of their actions then appears as its own tool, named `<pack name>__<action key>`, such as `github__create-issue`, with annotations such as `readOnlyHint` and `destructiveHint` taken from the action's effect class.
124
+
125
+ Two filters narrow that list. `--effects read` (`?effects=read`) serves only the actions that do at most that: `pure` and `read` here, so an agent gets no tool that writes. `--actions github/create-issue,slack/post-message` (`?actions=...`) serves only the named actions of their packs; a bare key such as `create-issue` applies to every pack you named. Both servers read each pack's tools with one request (`GET /v1/actions/packs/{namespace}/{name}/tools`) and keep the list for as long as its `ttlMs` says.
126
+
127
+ A pack that serves no tools, because the name is not in the catalog or its list could not be read, is reported rather than left out without a word: the local server writes a line to stderr, both servers put the lines in the `tools/list` result's `_meta.warnings` (and send them as `notifications/message` warnings to a client that asked for log messages, with `logging/setLevel` or a request's `logLevel`), and the server instructions name the packs this session cannot serve. Their actions still work through `actions_search` and `actions_call`.
128
+
129
+ ## Routines
130
+
131
+ An agent runs any routine you published with `routine_run`, passing the routine's name and an `input` object, so a whole workflow with its retries and durability is one tool call. Neither server lists each routine as a tool of its own yet. See [routines](https://docs.beta.b3os.org/routines).
132
+
133
+ ## Read traces, requests and runs
134
+
135
+ An agent can read what its own calls did. The `platform` toolset reads traces, the [request log](https://docs.beta.b3os.org/platform/requests) and the model calls [prompt logging](https://docs.beta.b3os.org/platform/call-log) kept; the `routines` toolset reads a routine's runs and their events. Start the local server with `--toolsets platform,routines`, or add `?toolsets=platform,routines` to the remote URL.
136
+
137
+ Note:
138
+ The remote server serves every tool below since 2026-11-17. On the local server, `traces_list`, `traces_get`, `llm_calls_list`, `llm_calls_get`, `llm_calls_get_prompt_and_answer`, `routine_list_runs` and `routine_run_events` come with MCP server 0.2.2, the **next** release. `requests_list`, `requests_get` and `routine_get_run` are in 0.2.1 already, where the two request tools answer with the whole records.
139
+
140
+ | Tool | What it reads | Scope |
141
+ |---|---|---|
142
+ | `traces_list` | Recent traces, newest first. A trace is the calls that shared one trace ID, such as one turn of your agent; each line gives its start, duration, calls by kind and first error | `platform:read`; with `app`, also `sandboxes:read` |
143
+ | `traces_get` | One trace as a waterfall: each call's start offset, duration, status, model and tokens, and the error of a failed call | `platform:read` |
144
+ | `requests_list`, `requests_get` | The request log, one line per request; one request with its timing phases, its error and the usage it was charged | `platform:read` |
145
+ | `llm_calls_list`, `llm_calls_get` | Kept model calls: model, tokens, timing and the tools the model chose. Never the prompt | `platform:read` |
146
+ | `llm_calls_get_prompt_and_answer` | A kept call's prompt and answer. Known key shapes read `[redacted:<kind>]` | `platform:content:read` |
147
+ | `routine_list_runs` | A routine's recent runs, and the step and error of each failed one | `routines:read` |
148
+ | `routine_get_run` | One run's steps and their errors | `routines:read` |
149
+ | `routine_run_events` | A finished run's events: each step's start, retries, waits and end, and the `run.log` lines | `routines:read` |
150
+
151
+ Each answer is a few lines per record and says how to read more. Lists return 10 records unless you pass `limit` (`requests_list` returns 20, as the API does), a trace shows its first 25 calls (`from_span` reads on), a run's events show the last 40, and a prompt and answer stop at 12,000 characters, with any one string over 2,000 characters cut in the middle. A run still in progress has no event log yet; `routine_run_events` answers with its steps so far.
152
+
153
+ Only `llm_calls_get_prompt_and_answer` returns a prompt or an answer, and only to a key with `platform:content:read`, which no wildcard grants. A key without a tool's scope gets the API's [`forbidden`](https://docs.beta.b3os.org/errors#forbidden) error as the tool's result, naming the scope.
154
+
155
+ For example, you ask your agent "why did my last nightly-digest run fail?":
156
+
157
+ 1. It calls `routine_list_runs` with `routine: "nightly-digest"`, `status: "failed"` and `limit: 1`. One line comes back: the run's ID, when it ran, its trigger, and `failed at step fetch: upstream_error` with the error's detail.
158
+ 2. To see whether B3OS retried the step, it calls `routine_run_events` with that run ID. The events show `step.retrying fetch (attempt 2)` and `step.failed fetch (attempt 3)`, each with the same error.
159
+ 3. It tells you that the run stopped at its `fetch` step after three attempts because the site it fetches kept failing, and which run to look at.
160
+
161
+ The same works for a harness that wraps each turn in `b3os.traces.turn`: `traces_list` with `status: "error"` finds the failed turns, and `traces_get` shows which call in a turn failed and why.
162
+
163
+ ## Credentials
164
+
165
+ Actions that need a credential get it from a [vault connection](https://docs.beta.b3os.org/vault), injected at the egress proxy. The agent sees only the connection's ID, never the secret, and `actions_call` accepts no credential in its input.
166
+
167
+ ## Protocol
168
+
169
+ The local server answers clients of the MCP 2026-07-28 revision, which send the protocol version with every request, and clients that open with `initialize` for 2024-11-05, 2025-03-26, 2025-06-18 or 2025-11-25. The remote server answers 2026-07-28 and the `initialize`-based 2025-03-26, 2025-06-18 and 2025-11-25, without sessions.
@@ -0,0 +1,146 @@
1
+ # Python SDK
2
+
3
+ > Install the b3os package and call every B3OS product from Python with a typed sync or async client, with jobs, streams, typed errors and timing.
4
+
5
+ Source: https://docs.beta.b3os.org/sdks/python.md
6
+
7
+ The `b3os` package has the same namespaces and methods as the TypeScript SDK, in snake_case, with a sync client (`B3OS`) and an async one (`AsyncB3OS`, for asyncio or trio). It is built on httpx, needs Python 3.10 or later, and types every request and response as a `TypedDict`, so mypy and your editor check field names.
8
+
9
+ ```bash
10
+ pip install 'b3os>=0.2,<0.3'
11
+ ```
12
+
13
+ ## Create a client
14
+
15
+ ```python
16
+ from b3os import B3OS
17
+
18
+ b3os = B3OS() # reads B3OS_API_KEY
19
+ ```
20
+
21
+ Constructor arguments: `api_key` (`B3OS_API_KEY`), `base_url` (`B3OS_BASE_URL`), `node_url` (`B3OS_API_URL`), `socket_path` (`B3OS_SOCKET`), `transport`, `timeout`, `max_retries` (2), `max_retry_delay` (60 seconds), `headers`, `on_response` and `http_client`.
22
+
23
+ Calls go where the [TypeScript SDK](https://docs.beta.b3os.org/sdks/typescript#create-a-client) sends them. Inside a B3OS sandbox, `B3OS_API_URL` is set to `http://127.0.0.1:7700` and the client calls the node with no key, as the sandbox's grant; account operations (keys, usage, limits, organizations, projects, the pack registry) still go to the API host. On a B3OS node itself, a client with no key (a stored `b3os login` counts as one) and no base URL uses the node's Unix socket and runs as the principal your operating-system user maps to; that is for B3OS's own tools, and a client with a key never picks the socket by itself.
24
+
25
+ ## Call a product
26
+
27
+ Path parameters are positional, the request body is a positional `dict`, and query and header parameters are keyword arguments. Results are plain dicts, lists, `str` or `bytes`:
28
+
29
+ ```python
30
+ page = b3os.vision.scrape({"url": "https://example.com", "formats": ["markdown"]})
31
+ print(page["markdown"])
32
+
33
+ sandbox = b3os.sandboxes.create_sandbox({"template": "base"})
34
+ b3os.sandboxes.write_file(sandbox["id"], b"print(2 + 2)\n", path="/workspace/main.py", mkdir=1)
35
+ result = b3os.sandboxes.exec(sandbox["id"], {"cmd": "python3 /workspace/main.py"})
36
+ if result["object"] == "exec_result": # a background command returns its process instead
37
+ print(result["stdout"])
38
+ b3os.sandboxes.delete_sandbox(sandbox["id"])
39
+ ```
40
+
41
+ Every method also takes the request options `idempotency_key`, `timeout`, `max_retries`, `extra_headers` and `traceparent`. The [method index](https://docs.beta.b3os.org/sdks#method-index) lists every method under its TypeScript name; the Python name is the same in snake_case (`createSandbox` is `create_sandbox`). For an operation the client does not wrap, `b3os.request("GET", "/v1/...")` sends it with the same key, retries and errors.
42
+
43
+ ## Lists
44
+
45
+ A list method returns one page, a dict with `data` and `next_cursor`; `auto_paging_iter()` walks every item across pages:
46
+
47
+ ```python
48
+ for s in b3os.sandboxes.list_sandboxes(status="running").auto_paging_iter():
49
+ print(s["id"])
50
+ ```
51
+
52
+ ## Async
53
+
54
+ ```python
55
+ import asyncio
56
+ from b3os import AsyncB3OS
57
+
58
+ async def main() -> None:
59
+ b3os = AsyncB3OS()
60
+ try:
61
+ pages = await asyncio.gather(*[
62
+ b3os.vision.scrape({"url": url, "formats": ["markdown"]})
63
+ for url in ["https://example.com/a", "https://example.com/b"]
64
+ ])
65
+ print([p["tier"] for p in pages])
66
+ finally:
67
+ await b3os.aclose()
68
+
69
+ asyncio.run(main())
70
+ ```
71
+
72
+ ## Jobs and streams
73
+
74
+ Methods that start a job take `wait` and `stream`:
75
+
76
+ ```python
77
+ job = b3os.vision.create_crawl({"url": "https://docs.example.com", "limit": 50}) # the job as created
78
+ done = b3os.vision.create_crawl({"url": "https://docs.example.com", "limit": 50}, wait=True) # until it ends
79
+ print(done["status"], done.get("result"))
80
+
81
+ for event in b3os.vision.create_crawl({"url": "https://docs.example.com"}, stream=True):
82
+ print(event["type"])
83
+
84
+ b3os.jobs.wait(job["id"], on_event=print) # any job ID; jobs also has get, events and cancel
85
+ ```
86
+
87
+ `wait=True` sends `?wait` on the create and then follows the job's event stream to its end; `wait=30.0` waits at most that many seconds. A job that fails or is canceled raises `B3OSJobError`, with the job on `.job`. `b3os.jobs` takes a job object or its ID; pass the object for `job_` IDs, a prefix several kinds of job share. Command output streams the same way, with `stream=True` on `sandboxes.exec`, and so do model calls: `stream=True` on `infer.create_chat_completion`, `infer.create_response` and `infer.create_message` returns their events until the last one. Job and log streams resume after a dropped connection with `Last-Event-ID`.
88
+
89
+ ## Errors
90
+
91
+ A failed call raises `B3OSError` with the problem's `code`, `status`, `type`, `title`, `detail`, `request_id`, `errors`, `problem`, `retry_after`, `retryable` and `timing`:
92
+
93
+ ```python
94
+ from b3os import B3OSError
95
+
96
+ try:
97
+ b3os.sandboxes.get_sandbox("sbx_01m5t68q1b590rj801nbzsqzkk")
98
+ except B3OSError as error:
99
+ if error.code != "sandbox_not_found":
100
+ raise
101
+ print("gone", error.request_id)
102
+ ```
103
+
104
+ Failures no server reported raise `B3OSConnectionError` (`connection_error`) or `B3OSTimeoutError` (`timeout`), or carry the codes `invalid_response`, `stream_interrupted` and `unsupported_transport`; none of them is on the errors page.
105
+
106
+ ## Retries, idempotency and timing
107
+
108
+ Retries follow the same rules as the [TypeScript SDK](https://docs.beta.b3os.org/sdks/typescript#retries-and-idempotency): always when B3OS refused the request before doing any work, for calls that are safe to repeat also retryable `5xx` answers (a proxy's error page without a problem body counts here, never as a refusal), never after a timeout. Operations that accept an `Idempotency-Key` get one per call, reused by every retry; pass `idempotency_key=` to choose it.
109
+
110
+ `response_of(result)` returns the response behind any result: `status`, `headers`, `request_id`, `attempts`, `idempotent_replayed`, `elapsed_ms`, and `timing`, the parsed `Server-Timing` header:
111
+
112
+ ```python
113
+ from b3os import response_of
114
+
115
+ page = b3os.vision.scrape({"url": "https://example.com"})
116
+ info = response_of(page)
117
+ if info is not None:
118
+ print(info.request_id, info.timing)
119
+ ```
120
+
121
+ ## Turns and traces
122
+
123
+ Note:
124
+ `traces.turn` and `traces.span` are new in SDK 0.2.0; [traces, evals and alerts](https://docs.beta.b3os.org/design/observability) is a design preview.
125
+
126
+ Every call sends a W3C `traceparent`. Wrap one turn of your agent in `traces.turn` and every B3OS call inside the block joins one trace (`async with` on `AsyncB3OS`):
127
+
128
+ ```python
129
+ with b3os.traces.turn("answer", conversation=thread_id, subject=user_id, metadata={"plan": "pro"}) as turn:
130
+ page = b3os.vision.scrape({"url": url}) # joins the turn
131
+ with b3os.traces.span("rank", kind="harness"):
132
+ ranked = rank(page)
133
+ print(turn.trace_id) # GET /v1/traces/{trace_id} reads it back
134
+ ```
135
+
136
+ The rules are the TypeScript SDK's: calls in a turn carry `tracestate: b3os=turn` and the turn's `baggage`, calls outside one get a trace each marked `tracestate: b3os=call`, and a `traceparent=` you pass is sent unmarked. `turn.headers()` gives the trace headers for another client (`baggage=True` adds the baggage, for B3OS hosts only), `turn.env()` gives `TRACEPARENT` and `TRACESTATE` for a command in another sandbox, and `on_span=` on the client receives each span. See [Traces](https://docs.beta.b3os.org/design/observability).
137
+
138
+ ## Terminals, CDP and webhooks
139
+
140
+ `open_pty(sandbox_id, cols=120, rows=40)` mints a stream ticket and returns a connected terminal (`AsyncPtySession` on `AsyncB3OS`): `write()` sends keystrokes, `resize(cols, rows)` follows a window, iterating it reads the output, and `wait()` returns the exit. It needs the optional WebSocket client:
141
+
142
+ ```bash
143
+ pip install 'b3os[pty]>=0.2,<0.3'
144
+ ```
145
+
146
+ Without the extra, `open_pty` raises `unsupported_transport` naming it; everything else needs only httpx. `pty_url(sandbox_id)` returns the ticketed `url` and `protocols` instead, for another WebSocket library. `connect_cdp(session_id)` returns a CDP endpoint whose URL carries a ticket, for Playwright's `connect_over_cdp`. `verify_webhook(raw_body, header, secret)` checks a delivery and returns the event; see [verify the signature](https://docs.beta.b3os.org/concepts/jobs#verify-the-signature). It does not refuse an empty `secret` yet, so stop your receiver when the secret is empty or missing before you call it, as that page does.
@@ -0,0 +1,202 @@
1
+ # TypeScript SDK
2
+
3
+ > Install @b3os/sdk, call every B3OS product from Node, Bun or Workers, wait on jobs, stream events, handle typed errors and read timing.
4
+
5
+ Source: https://docs.beta.b3os.org/sdks/typescript.md
6
+
7
+ `@b3os/sdk` is one client with a namespace per product, generated from the OpenAPI document on top of a hand-written runtime. It ships ESM and CommonJS with type declarations and no runtime dependencies. It needs Node 22.3 or later, Bun, or Cloudflare Workers.
8
+
9
+ ```bash
10
+ npm install @b3os/sdk@0.2
11
+ ```
12
+
13
+ ## Create a client
14
+
15
+ ```ts
16
+ import { B3OS } from "@b3os/sdk";
17
+
18
+ const b3os = new B3OS(); // reads B3OS_API_KEY
19
+ ```
20
+
21
+ | Option | Environment | Meaning |
22
+ |---|---|---|
23
+ | `apiKey` | `B3OS_API_KEY` | A `b3os_sk_` API key or a `b3os_pat_` CLI token |
24
+ | `baseUrl` | `B3OS_BASE_URL` | The API host, `https://beta-api.b3os.org` by default |
25
+ | `nodeUrl` | `B3OS_API_URL` | The node's own URL, set for you inside a sandbox; node operations go there without the key |
26
+ | `timeoutMs`, `maxRetries`, `maxRetryDelayMs`, `headers`, `fetch`, `onResponse` | | Per-client defaults (2 retries, at most 60 seconds between them); `onResponse` sees every response head |
27
+
28
+ Where a call goes:
29
+
30
+ | Where the client runs | Node operations (products) | Account operations |
31
+ |---|---|---|
32
+ | Anywhere | `https://beta-api.b3os.org` with your key | The same |
33
+ | Inside a B3OS sandbox (`B3OS_API_URL` is set to `http://127.0.0.1:7700`) | That URL with no key: the sandbox's [grant](https://docs.beta.b3os.org/sandboxes/agents#grant-access) decides | `https://beta-api.b3os.org`, with the key if one is set |
34
+ | On a B3OS node itself, with `B3OS_SOCKET` set, or with no key (a stored `b3os login` counts as one) and no base URL configured | The node's Unix socket with no key: the node maps your operating-system user to a principal | `https://beta-api.b3os.org` with the key |
35
+
36
+ Account operations (keys, usage, limits, organizations, projects and the pack registry) are served only at the API host; a node answers them with `421 edge_only`. The last row is for B3OS's own tools on the node, so your code meets the first two. A client that has a key never picks the socket by itself, so its calls always run as that key.
37
+
38
+ ## Call a product
39
+
40
+ ```ts
41
+ const page = await b3os.vision.scrape({ url: "https://example.com", formats: ["markdown"] });
42
+ console.log(page.markdown);
43
+
44
+ const sandbox = await b3os.sandboxes.createSandbox({ template: "base" });
45
+ await b3os.sandboxes.writeFile(sandbox.id, { path: "/workspace/main.py", mkdir: 1 }, "print(2 + 2)\n");
46
+ const result = await b3os.sandboxes.exec(sandbox.id, { cmd: "python3 /workspace/main.py" });
47
+ console.log(result.stdout);
48
+ await b3os.sandboxes.deleteSandbox(sandbox.id);
49
+ ```
50
+
51
+ A method takes, in order: the path parameters, an object of query and header parameters when the operation has any, the request body, and request options. Namespaces are `vision`, `render`, `sandboxes`, `routines`, `actions`, `vault` and `infer`, and for your account `keys`, `usage`, `limits`, `requests`, `webhooks`, `orgs` and `projects`. The [method index](https://docs.beta.b3os.org/sdks#method-index) lists every method.
52
+
53
+ Request options, the last argument of every method: `idempotencyKey`, `timeoutMs`, `maxRetries`, `signal`, `headers` and `traceparent`. Every type in the API is exported, for example `import type { ScrapeRequest } from "@b3os/sdk"`. Take the sandbox object's type from `@b3os/sdk/types` (`import type { Sandbox } from "@b3os/sdk/types"`).
54
+
55
+ For an operation the client does not wrap, `b3os.request({ method, path, query, body })` sends it with the same key, retries and errors.
56
+
57
+ ## Lists
58
+
59
+ Awaiting a list method returns one page (`data` and `next_cursor`); `for await` walks every item across pages:
60
+
61
+ ```ts
62
+ for await (const s of b3os.sandboxes.listSandboxes({ status: "running" })) console.log(s.id);
63
+ ```
64
+
65
+ ## Jobs
66
+
67
+ Methods that start a job (crawls, batch scrapes, videos, routine runs) return a handle. Awaited on its own, it gives the job as created. `.wait()` and `.events()`, called on the handle before you await it, shape the creating request itself:
68
+
69
+ ```ts
70
+ // Wait: ?wait on the create, then the job's event stream until it ends
71
+ const crawl = await b3os.vision.createCrawl({ url: "https://docs.example.com", limit: 50 }).wait();
72
+ console.log(crawl.status, crawl.result);
73
+
74
+ // Or follow its events from the creating request on; the stream resumes after a dropped connection
75
+ for await (const event of b3os.vision.createCrawl({ url: "https://docs.example.com" }).events()) {
76
+ if (event.type === "page.succeeded") console.log(event.page?.url);
77
+ }
78
+
79
+ // Any job by its ID
80
+ const run = await b3os.jobs.wait("run_01m5t5fr06dx6azc42f4wbzf5s");
81
+ console.log(run.status);
82
+ ```
83
+
84
+ `.wait()` throws `B3OSJobError`, with the job on `.job`, when the job fails or is canceled; pass `{ throwOnFailure: false }` to get the job back instead. `b3os.jobs` also has `get`, `events` and `cancel`, for a job object or its ID. Several kinds of job share the `job_` prefix, so pass the job object for those: its `kind` tells the client which operations serve it, and a bare `job_` ID is refused.
85
+
86
+ ## Streams
87
+
88
+ Streams are async iterables:
89
+
90
+ ```ts
91
+ for await (const event of b3os.sandboxes.exec(sandbox.id, { cmd: "npm test" }, { stream: true })) {
92
+ if (event.type === "exec.stdout") process.stdout.write(event.data ?? "");
93
+ }
94
+ ```
95
+
96
+ Model calls stream the same way when the body says `stream: true`: `infer.createChatCompletion`, `infer.createResponse` and `infer.createMessage` then return the event stream instead of one JSON answer, typed by the operation's events, and the loop ends at the last event (`[DONE]`, `response.completed`, `message_stop`).
97
+
98
+ Job and log streams resume after a dropped connection with `Last-Event-ID`. Command output and model streams cannot resume, so a drop ends them with the client error `stream_interrupted`. `stream.close()` ends a loop early.
99
+
100
+ ## Errors
101
+
102
+ A failed call throws `B3OSError`, carrying the problem's `code`, `status`, `type` (the link to its entry on the [errors page](https://docs.beta.b3os.org/errors)), `title`, `detail`, `requestId`, `errors` (validation pointers), `problem` (the whole body), `retryAfterMs`, `retryable` and `timing`:
103
+
104
+ ```ts
105
+ import { B3OSError } from "@b3os/sdk";
106
+
107
+ try {
108
+ await b3os.sandboxes.getSandbox("sbx_01m5t68q1b590rj801nbzsqzkk");
109
+ } catch (error) {
110
+ if (B3OSError.is(error, "sandbox_not_found")) console.log("gone", error.requestId);
111
+ else throw error;
112
+ }
113
+ ```
114
+
115
+ Branch on `code`, and keep `requestId` for support and for the [request log](https://docs.beta.b3os.org/platform/requests).
116
+
117
+ Failures no server reported carry codes of their own, which are not on the errors page: `connection_error` (`B3OSConnectionError`), `timeout` (`B3OSTimeoutError`), `aborted` (`B3OSAbortError`), `invalid_response`, `stream_interrupted` and `unsupported_transport`.
118
+
119
+ ## Retries and idempotency
120
+
121
+ The client retries at most `maxRetries` times, with exponential backoff and jitter, or after `Retry-After`:
122
+
123
+ - always, when B3OS refused the request before doing any work and says so in a problem body: `rate_limited`, `concurrency_limited`, `ticket_limit`, `node_unavailable`, `product_unavailable`, `capacity_unavailable`, `auth_unavailable`, `idempotency_request_in_progress`; also a `429` or a Cloudflare `521`, `522`, `523` or `530` without a body (the request never reached the node), and refused connections;
124
+ - for calls that are safe to repeat (`GET`, `PUT`, `DELETE`, or a call with an idempotency key), also retryable `5xx` answers and dropped connections. A `502`, `503` or `520` page without a problem body comes from a proxy in between, so the node may already have run the request: it becomes the code `internal` and a call that is not safe to repeat is not sent again;
125
+ - never after a timeout, and never when `Retry-After` is longer than `maxRetryDelayMs`.
126
+
127
+ Operations that accept an `Idempotency-Key` get one generated per call, and every retry of that call reuses it. Pass your own to make your own retries safe too:
128
+
129
+ ```ts
130
+ await b3os.actions.call(
131
+ { ref: "io.b3os/github/create-issue@1", input: { owner: "acme", repo: "web", title: "Flaky test" } },
132
+ { idempotencyKey: crypto.randomUUID() },
133
+ );
134
+ ```
135
+
136
+ ## Timing
137
+
138
+ `.withResponse()` returns the result together with the response, including its parsed `Server-Timing`:
139
+
140
+ ```ts
141
+ const { data, response } = await b3os.vision.scrape({ url: "https://example.com" }).withResponse();
142
+ console.log(data.tier, response.requestId, response.timing?.total_ms, response.timing?.phases);
143
+ ```
144
+
145
+ `responseOf(result)` returns the same for any object a call returned, and `response.attempts` counts retries.
146
+
147
+ ## Turns and traces
148
+
149
+ Note:
150
+ `traces.turn` and `traces.span` are new in SDK 0.2.0; [traces, evals and alerts](https://docs.beta.b3os.org/design/observability) is a design preview.
151
+
152
+ Every call sends a W3C `traceparent`. Wrap one turn of your agent in `traces.turn` and every B3OS call inside it, across `await`, joins one trace:
153
+
154
+ ```ts
155
+ const answer = await b3os.traces.turn(
156
+ "answer",
157
+ async (turn) => {
158
+ const page = await b3os.vision.scrape({ url }); // joins the turn
159
+ const run = await b3os.routines.createRun("summarize", { input: { page } });
160
+ await b3os.traces.span("rank", () => rank(page), { kind: "harness" });
161
+ return turn.traceId; // GET /v1/traces/{trace_id} reads it back
162
+ },
163
+ { conversation: thread.id, subject: user.id, metadata: { plan: "pro" } },
164
+ );
165
+ ```
166
+
167
+ Calls inside the turn carry `tracestate: b3os=turn` and a `baggage` header with the turn's name, conversation, subject and metadata. Calls outside a turn get a trace each, marked `tracestate: b3os=call`, so B3OS never takes them for a turn. A `traceparent` you pass yourself is sent as is, unmarked.
168
+
169
+ For another client, `turn.headers()` gives the trace headers (`turn.headers({ baggage: true })` adds the baggage; send that only to B3OS, since it holds your end user's id), and `b3os.traces.wrapFetch()` adds them to every request a model SDK sends inside the turn: `new OpenAI({ fetch: b3os.traces.wrapFetch() })`. For a command in another sandbox, `turn.env()` gives `TRACEPARENT` and `TRACESTATE`.
170
+
171
+ `traces.span` times a step of your harness and is the parent of the calls made inside it. The SDK keeps spans on `turn.spans` and hands each to the `onSpan` client option; it does not send them anywhere yet. See [Traces](https://docs.beta.b3os.org/design/observability).
172
+
173
+ ## Terminals and CDP
174
+
175
+ ```ts
176
+ const pty = await b3os.sandboxes.openPty(sandbox.id, { cols: 120, rows: 40 });
177
+ pty.onData((bytes) => process.stdout.write(bytes));
178
+ pty.write("ls -la\n");
179
+ const { code } = await pty.exit;
180
+
181
+ const cdp = await b3os.vision.connectCdp("brs_01m5t6vhkw4a8fa4tb5w4ffz37"); // URL with a single-use ticket
182
+ console.log(code, cdp.url);
183
+ ```
184
+
185
+ `openPty` mints a single-use stream ticket and opens the terminal WebSocket; `pty.resize(cols, rows)` follows a window. These open WebSockets, so they need a global `WebSocket` (Node 22 or later, Bun, Workers). Pass `cdp.url` to Playwright's `chromium.connectOverCDP` or Puppeteer's `connect`; see [browser sessions](https://docs.beta.b3os.org/vision/sessions#connect-over-cdp).
186
+
187
+ ## Webhooks
188
+
189
+ `verifyWebhook` from `@b3os/sdk/webhooks` checks a delivery's `B3OS-Signature` and returns the event; see [verify the signature](https://docs.beta.b3os.org/concepts/jobs#verify-the-signature). Check the secret when your receiver starts, as that page does: with an empty secret the call throws Web Crypto's `DataError` rather than `WebhookVerificationError`.
190
+
191
+ ## Smaller bundles
192
+
193
+ Each namespace is also a subpath, so a bundle can carry one product:
194
+
195
+ ```ts
196
+ import { B3OSCore } from "@b3os/sdk/core";
197
+ import { SandboxesAPI } from "@b3os/sdk/sandboxes";
198
+
199
+ const sandboxes = new SandboxesAPI(new B3OSCore({ apiKey: process.env.B3OS_API_KEY }));
200
+ ```
201
+
202
+ The package has no side effects, and a bundle for Workers or browsers contains no `node:` imports.