@hanzo/dev 4.0.1 → 4.2.0

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 (371) hide show
  1. package/LICENSE +21 -0
  2. package/dist/{BinaryViewer-qn8xfPZp.js → BinaryViewer-CmFUK4zZ.js} +2 -2
  3. package/dist/{ChatMarkdown-Cyujn3JJ.js → ChatMarkdown-nvEI7iCv.js} +4 -4
  4. package/dist/{DiffCommentAnnotation-BZu1TP6E.js → DiffCommentAnnotation-BPTN_2a6.js} +1 -1
  5. package/dist/{DiffFileTree-CcJ91zOM.js → DiffFileTree-B_br90vY.js} +2 -2
  6. package/dist/{DiffPanel-BXC88NMs.js → DiffPanel-V5R5TPuK.js} +5 -5
  7. package/dist/{ExpandedImageDialog-BZnGRBJR.js → ExpandedImageDialog-CAorLacL.js} +1 -1
  8. package/dist/{FileExplorerPane-vBJS6V75.js → FileExplorerPane-CeHulcPz.js} +1 -1
  9. package/dist/{FilePreviewPanel-jJHWsMzm.js → FilePreviewPanel-BVNLvWOc.js} +8 -8
  10. package/dist/{MermaidDiagram-paNwQY33.js → MermaidDiagram-CTolIzQD.js} +1 -1
  11. package/dist/{MermaidFilePreview-B9KxfnIN.js → MermaidFilePreview-CP2zP4FU.js} +1 -1
  12. package/dist/{MermaidViewer-CAEGpLyD.js → MermaidViewer-BDfYkS9E.js} +2 -2
  13. package/dist/{NotebookPreview-D01mMCpR.js → NotebookPreview-Cybs5uM0.js} +1 -1
  14. package/dist/{OfficeFilePreview-DWaRgfQU.js → OfficeFilePreview-7JsmSoKU.js} +1 -1
  15. package/dist/{OfficeViewer-BudrZbBA.js → OfficeViewer-CJoojlJK.js} +1 -1
  16. package/dist/{OpenInPicker-Dd3ifHa1.js → OpenInPicker-BIMWUxBP.js} +7 -7
  17. package/dist/{OpenXmlOfficeViewer-CXcKdq7k.js → OpenXmlOfficeViewer-C24Kj8DM.js} +1 -1
  18. package/dist/{PreviewImage-C4Ku4z7v.js → PreviewImage-oY5YnuTr.js} +1 -1
  19. package/dist/{PreviewImageContent-BwOB9Lyd.js → PreviewImageContent-n6eLzY99.js} +1 -1
  20. package/dist/{PullRequestCodeTab-BcwyMk7d.js → PullRequestCodeTab-Dv_0kVad.js} +7 -7
  21. package/dist/{PullRequestReviewAnnotation-BU5t_1fC.js → PullRequestReviewAnnotation-LeuwO-iH.js} +4 -4
  22. package/dist/builder/activity.d.ts +16 -0
  23. package/dist/builder/activity.js +51 -0
  24. package/dist/builder/address.d.ts +11 -0
  25. package/dist/builder/address.js +50 -0
  26. package/dist/builder/ago.d.ts +2 -0
  27. package/dist/builder/ago.js +18 -0
  28. package/dist/builder/api/agents.d.ts +139 -0
  29. package/dist/builder/api/agents.js +253 -0
  30. package/dist/builder/api/auto.d.ts +166 -0
  31. package/dist/builder/api/auto.js +300 -0
  32. package/dist/builder/api/billing.d.ts +263 -0
  33. package/dist/builder/api/billing.js +401 -0
  34. package/dist/builder/api/call.d.ts +53 -0
  35. package/dist/builder/api/call.js +123 -0
  36. package/dist/builder/api/capabilities.d.ts +14 -0
  37. package/dist/builder/api/capabilities.js +41 -0
  38. package/dist/builder/api/changes.d.ts +74 -0
  39. package/dist/builder/api/changes.js +75 -0
  40. package/dist/builder/api/chat.d.ts +12 -0
  41. package/dist/builder/api/chat.js +28 -0
  42. package/dist/builder/api/cli.d.ts +59 -0
  43. package/dist/builder/api/cli.js +133 -0
  44. package/dist/builder/api/codebases.d.ts +46 -0
  45. package/dist/builder/api/codebases.js +100 -0
  46. package/dist/builder/api/coding.d.ts +117 -0
  47. package/dist/builder/api/coding.js +222 -0
  48. package/dist/builder/api/connectors.d.ts +76 -0
  49. package/dist/builder/api/connectors.js +111 -0
  50. package/dist/builder/api/consent.d.ts +22 -0
  51. package/dist/builder/api/consent.js +28 -0
  52. package/dist/builder/api/conversations.d.ts +20 -0
  53. package/dist/builder/api/conversations.js +23 -0
  54. package/dist/builder/api/draft.d.ts +38 -0
  55. package/dist/builder/api/draft.js +87 -0
  56. package/dist/builder/api/environment.d.ts +55 -0
  57. package/dist/builder/api/environment.js +126 -0
  58. package/dist/builder/api/gallery.d.ts +32 -0
  59. package/dist/builder/api/gallery.js +85 -0
  60. package/dist/builder/api/git.d.ts +59 -0
  61. package/dist/builder/api/git.js +117 -0
  62. package/dist/builder/api/github.d.ts +230 -0
  63. package/dist/builder/api/github.js +373 -0
  64. package/dist/builder/api/keys.d.ts +35 -0
  65. package/dist/builder/api/keys.js +72 -0
  66. package/dist/builder/api/library.d.ts +116 -0
  67. package/dist/builder/api/library.js +214 -0
  68. package/dist/builder/api/limits.d.ts +69 -0
  69. package/dist/builder/api/limits.js +86 -0
  70. package/dist/builder/api/links.d.ts +51 -0
  71. package/dist/builder/api/links.js +75 -0
  72. package/dist/builder/api/machines.d.ts +122 -0
  73. package/dist/builder/api/machines.js +238 -0
  74. package/dist/builder/api/mcp.d.ts +10 -0
  75. package/dist/builder/api/mcp.js +47 -0
  76. package/dist/builder/api/members.d.ts +35 -0
  77. package/dist/builder/api/members.js +95 -0
  78. package/dist/builder/api/memory.d.ts +14 -0
  79. package/dist/builder/api/memory.js +35 -0
  80. package/dist/builder/api/models.d.ts +17 -0
  81. package/dist/builder/api/models.js +20 -0
  82. package/dist/builder/api/places.d.ts +32 -0
  83. package/dist/builder/api/places.js +29 -0
  84. package/dist/builder/api/platform.d.ts +68 -0
  85. package/dist/builder/api/platform.js +87 -0
  86. package/dist/builder/api/plugins.d.ts +42 -0
  87. package/dist/builder/api/plugins.js +175 -0
  88. package/dist/builder/api/pref.d.ts +77 -0
  89. package/dist/builder/api/pref.js +93 -0
  90. package/dist/builder/api/profile.d.ts +11 -0
  91. package/dist/builder/api/profile.js +41 -0
  92. package/dist/builder/api/projects.d.ts +99 -0
  93. package/dist/builder/api/projects.js +166 -0
  94. package/dist/builder/api/provider.d.ts +49 -0
  95. package/dist/builder/api/provider.js +96 -0
  96. package/dist/builder/api/sandbox.d.ts +90 -0
  97. package/dist/builder/api/sandbox.js +223 -0
  98. package/dist/builder/api/sessions.d.ts +123 -0
  99. package/dist/builder/api/sessions.js +255 -0
  100. package/dist/builder/api/skills.d.ts +82 -0
  101. package/dist/builder/api/skills.js +117 -0
  102. package/dist/builder/api/sse.d.ts +24 -0
  103. package/dist/builder/api/sse.js +68 -0
  104. package/dist/builder/api/studio.d.ts +59 -0
  105. package/dist/builder/api/studio.js +91 -0
  106. package/dist/builder/api/talk.d.ts +48 -0
  107. package/dist/builder/api/talk.js +81 -0
  108. package/dist/builder/api/tools.d.ts +34 -0
  109. package/dist/builder/api/tools.js +37 -0
  110. package/dist/builder/api/turn.d.ts +202 -0
  111. package/dist/builder/api/turn.js +772 -0
  112. package/dist/builder/api/verdict.d.ts +3 -0
  113. package/dist/builder/api/verdict.js +21 -0
  114. package/dist/builder/api/webhooks.d.ts +47 -0
  115. package/dist/builder/api/webhooks.js +82 -0
  116. package/dist/builder/api/work.d.ts +110 -0
  117. package/dist/builder/api/work.js +218 -0
  118. package/dist/builder/ask.d.ts +51 -0
  119. package/dist/builder/ask.js +147 -0
  120. package/dist/builder/automations.d.ts +33 -0
  121. package/dist/builder/automations.js +453 -0
  122. package/dist/builder/awake.d.ts +24 -0
  123. package/dist/builder/awake.js +68 -0
  124. package/dist/builder/back.d.ts +30 -0
  125. package/dist/builder/back.js +105 -0
  126. package/dist/builder/builder.d.ts +12 -0
  127. package/dist/builder/builder.js +162 -0
  128. package/dist/builder/carry.d.ts +48 -0
  129. package/dist/builder/carry.js +278 -0
  130. package/dist/builder/choice.d.ts +134 -0
  131. package/dist/builder/choice.js +152 -0
  132. package/dist/builder/claims.d.ts +13 -0
  133. package/dist/builder/claims.js +35 -0
  134. package/dist/builder/clipboard.d.ts +2 -0
  135. package/dist/builder/clipboard.js +10 -0
  136. package/dist/builder/customize/agents.d.ts +11 -0
  137. package/dist/builder/customize/agents.js +513 -0
  138. package/dist/builder/customize/connectors.d.ts +2 -0
  139. package/dist/builder/customize/connectors.js +319 -0
  140. package/dist/builder/customize/drafted.d.ts +4 -0
  141. package/dist/builder/customize/drafted.js +92 -0
  142. package/dist/builder/customize/index.d.ts +8 -0
  143. package/dist/builder/customize/index.js +127 -0
  144. package/dist/builder/customize/inventory.d.ts +14 -0
  145. package/dist/builder/customize/inventory.js +127 -0
  146. package/dist/builder/customize/load.d.ts +9 -0
  147. package/dist/builder/customize/load.js +22 -0
  148. package/dist/builder/customize/ocean.d.ts +41 -0
  149. package/dist/builder/customize/ocean.js +332 -0
  150. package/dist/builder/customize/plugins.d.ts +2 -0
  151. package/dist/builder/customize/plugins.js +136 -0
  152. package/dist/builder/customize/roles.d.ts +4 -0
  153. package/dist/builder/customize/roles.js +105 -0
  154. package/dist/builder/customize/say.d.ts +13 -0
  155. package/dist/builder/customize/say.js +32 -0
  156. package/dist/builder/customize/skills.d.ts +2 -0
  157. package/dist/builder/customize/skills.js +208 -0
  158. package/dist/builder/customize/ui.d.ts +152 -0
  159. package/dist/builder/customize/ui.js +208 -0
  160. package/dist/builder/data.d.ts +57 -0
  161. package/dist/builder/data.js +322 -0
  162. package/dist/builder/design.d.ts +140 -0
  163. package/dist/builder/design.js +175 -0
  164. package/dist/builder/desk.d.ts +48 -0
  165. package/dist/builder/desk.js +449 -0
  166. package/dist/builder/dev-mode.d.ts +43 -0
  167. package/dist/builder/dev-mode.js +120 -0
  168. package/dist/builder/door.d.ts +11 -0
  169. package/dist/builder/door.js +126 -0
  170. package/dist/builder/environment.d.ts +23 -0
  171. package/dist/builder/environment.js +193 -0
  172. package/dist/builder/files.d.ts +23 -0
  173. package/dist/builder/files.js +175 -0
  174. package/dist/builder/find.d.ts +7 -0
  175. package/dist/builder/find.js +80 -0
  176. package/dist/builder/foot.d.ts +30 -0
  177. package/dist/builder/foot.js +79 -0
  178. package/dist/builder/forge.d.ts +4 -0
  179. package/dist/builder/forge.js +639 -0
  180. package/dist/builder/gear.d.ts +60 -0
  181. package/dist/builder/gear.js +180 -0
  182. package/dist/builder/git.d.ts +21 -0
  183. package/dist/builder/git.js +118 -0
  184. package/dist/builder/github-sync.d.ts +70 -0
  185. package/dist/builder/github-sync.js +435 -0
  186. package/dist/builder/gutter.d.ts +17 -0
  187. package/dist/builder/gutter.js +25 -0
  188. package/dist/builder/handoff.d.ts +8 -0
  189. package/dist/builder/handoff.js +22 -0
  190. package/dist/builder/host.d.ts +189 -0
  191. package/dist/builder/host.js +46 -0
  192. package/dist/builder/index.d.ts +108 -0
  193. package/dist/builder/index.js +99 -0
  194. package/dist/builder/landing.d.ts +34 -0
  195. package/dist/builder/landing.js +725 -0
  196. package/dist/builder/library.d.ts +21 -0
  197. package/dist/builder/library.js +526 -0
  198. package/dist/builder/local.d.ts +80 -0
  199. package/dist/builder/local.js +124 -0
  200. package/dist/builder/make.d.ts +10 -0
  201. package/dist/builder/make.js +120 -0
  202. package/dist/builder/markdown.d.ts +49 -0
  203. package/dist/builder/markdown.js +125 -0
  204. package/dist/builder/marks.d.ts +15 -0
  205. package/dist/builder/marks.js +18 -0
  206. package/dist/builder/merge.d.ts +223 -0
  207. package/dist/builder/merge.js +380 -0
  208. package/dist/builder/meter.d.ts +31 -0
  209. package/dist/builder/meter.js +54 -0
  210. package/dist/builder/mind.d.ts +107 -0
  211. package/dist/builder/mind.js +335 -0
  212. package/dist/builder/names.d.ts +40 -0
  213. package/dist/builder/names.js +189 -0
  214. package/dist/builder/nav.d.ts +28 -0
  215. package/dist/builder/nav.js +218 -0
  216. package/dist/builder/out.d.ts +16 -0
  217. package/dist/builder/out.js +24 -0
  218. package/dist/builder/page.d.ts +55 -0
  219. package/dist/builder/page.js +217 -0
  220. package/dist/builder/pane.d.ts +30 -0
  221. package/dist/builder/pane.js +21 -0
  222. package/dist/builder/panel.d.ts +101 -0
  223. package/dist/builder/panel.js +408 -0
  224. package/dist/builder/pdf.d.ts +139 -0
  225. package/dist/builder/pdf.js +847 -0
  226. package/dist/builder/pick.d.ts +10 -0
  227. package/dist/builder/pick.js +38 -0
  228. package/dist/builder/plain.d.ts +59 -0
  229. package/dist/builder/plain.js +209 -0
  230. package/dist/builder/plan.d.ts +63 -0
  231. package/dist/builder/plan.js +155 -0
  232. package/dist/builder/plans.d.ts +1 -0
  233. package/dist/builder/plans.js +157 -0
  234. package/dist/builder/plugin.d.ts +60 -0
  235. package/dist/builder/plugin.js +1 -0
  236. package/dist/builder/plugins/design.d.ts +8 -0
  237. package/dist/builder/plugins/design.js +71 -0
  238. package/dist/builder/plugins/index.d.ts +46 -0
  239. package/dist/builder/plugins/index.js +117 -0
  240. package/dist/builder/plugins/pdf.d.ts +18 -0
  241. package/dist/builder/plugins/pdf.js +83 -0
  242. package/dist/builder/plugins/project.d.ts +5 -0
  243. package/dist/builder/plugins/project.js +68 -0
  244. package/dist/builder/plugins/research.d.ts +24 -0
  245. package/dist/builder/plugins/research.js +147 -0
  246. package/dist/builder/plugins/sketch.d.ts +9 -0
  247. package/dist/builder/plugins/sketch.js +101 -0
  248. package/dist/builder/plugins/slides.d.ts +14 -0
  249. package/dist/builder/plugins/slides.js +55 -0
  250. package/dist/builder/plugins/template.d.ts +13 -0
  251. package/dist/builder/plugins/template.js +95 -0
  252. package/dist/builder/prefs.d.ts +29 -0
  253. package/dist/builder/prefs.js +91 -0
  254. package/dist/builder/preview-url.d.ts +47 -0
  255. package/dist/builder/preview-url.js +107 -0
  256. package/dist/builder/project.d.ts +18 -0
  257. package/dist/builder/project.js +604 -0
  258. package/dist/builder/prose.d.ts +4 -0
  259. package/dist/builder/prose.js +57 -0
  260. package/dist/builder/publish.d.ts +18 -0
  261. package/dist/builder/publish.js +141 -0
  262. package/dist/builder/question.d.ts +33 -0
  263. package/dist/builder/question.js +64 -0
  264. package/dist/builder/redesign.d.ts +32 -0
  265. package/dist/builder/redesign.js +117 -0
  266. package/dist/builder/removal.d.ts +71 -0
  267. package/dist/builder/removal.js +73 -0
  268. package/dist/builder/reply.d.ts +50 -0
  269. package/dist/builder/reply.js +196 -0
  270. package/dist/builder/roles.d.ts +10 -0
  271. package/dist/builder/roles.js +28 -0
  272. package/dist/builder/route.d.ts +85 -0
  273. package/dist/builder/route.js +126 -0
  274. package/dist/builder/run.d.ts +4 -0
  275. package/dist/builder/run.js +804 -0
  276. package/dist/builder/runmeta.d.ts +16 -0
  277. package/dist/builder/runmeta.js +69 -0
  278. package/dist/builder/say.d.ts +2 -0
  279. package/dist/builder/say.js +7 -0
  280. package/dist/builder/scheduled.d.ts +3 -0
  281. package/dist/builder/scheduled.js +328 -0
  282. package/dist/builder/section.d.ts +27 -0
  283. package/dist/builder/section.js +60 -0
  284. package/dist/builder/settings/account.d.ts +1 -0
  285. package/dist/builder/settings/account.js +111 -0
  286. package/dist/builder/settings/billing.d.ts +1 -0
  287. package/dist/builder/settings/billing.js +210 -0
  288. package/dist/builder/settings/capabilities.d.ts +1 -0
  289. package/dist/builder/settings/capabilities.js +66 -0
  290. package/dist/builder/settings/card.d.ts +31 -0
  291. package/dist/builder/settings/card.js +140 -0
  292. package/dist/builder/settings/code.d.ts +1 -0
  293. package/dist/builder/settings/code.js +70 -0
  294. package/dist/builder/settings/credits.d.ts +10 -0
  295. package/dist/builder/settings/credits.js +123 -0
  296. package/dist/builder/settings/environments.d.ts +1 -0
  297. package/dist/builder/settings/environments.js +60 -0
  298. package/dist/builder/settings/general.d.ts +1 -0
  299. package/dist/builder/settings/general.js +58 -0
  300. package/dist/builder/settings/index.d.ts +4 -0
  301. package/dist/builder/settings/index.js +25 -0
  302. package/dist/builder/settings/integrations.d.ts +8 -0
  303. package/dist/builder/settings/integrations.js +138 -0
  304. package/dist/builder/settings/keys.d.ts +1 -0
  305. package/dist/builder/settings/keys.js +114 -0
  306. package/dist/builder/settings/list.d.ts +10 -0
  307. package/dist/builder/settings/list.js +28 -0
  308. package/dist/builder/settings/machines.d.ts +4 -0
  309. package/dist/builder/settings/machines.js +243 -0
  310. package/dist/builder/settings/members.d.ts +1 -0
  311. package/dist/builder/settings/members.js +77 -0
  312. package/dist/builder/settings/memory.d.ts +1 -0
  313. package/dist/builder/settings/memory.js +62 -0
  314. package/dist/builder/settings/notifications.d.ts +1 -0
  315. package/dist/builder/settings/notifications.js +111 -0
  316. package/dist/builder/settings/plan.d.ts +17 -0
  317. package/dist/builder/settings/plan.js +131 -0
  318. package/dist/builder/settings/privacy.d.ts +1 -0
  319. package/dist/builder/settings/privacy.js +76 -0
  320. package/dist/builder/settings/sections.d.ts +16 -0
  321. package/dist/builder/settings/sections.js +34 -0
  322. package/dist/builder/settings/shared.d.ts +6 -0
  323. package/dist/builder/settings/shared.js +58 -0
  324. package/dist/builder/settings/ui.d.ts +50 -0
  325. package/dist/builder/settings/ui.js +53 -0
  326. package/dist/builder/settings/usage.d.ts +1 -0
  327. package/dist/builder/settings/usage.js +24 -0
  328. package/dist/builder/shared.d.ts +26 -0
  329. package/dist/builder/shared.js +15 -0
  330. package/dist/builder/shelf.d.ts +16 -0
  331. package/dist/builder/shelf.js +219 -0
  332. package/dist/builder/side.d.ts +40 -0
  333. package/dist/builder/side.js +208 -0
  334. package/dist/builder/site.d.ts +75 -0
  335. package/dist/builder/site.js +138 -0
  336. package/dist/builder/spend.d.ts +21 -0
  337. package/dist/builder/spend.js +80 -0
  338. package/dist/builder/standing.d.ts +36 -0
  339. package/dist/builder/standing.js +66 -0
  340. package/dist/builder/suggest.d.ts +238 -0
  341. package/dist/builder/suggest.js +463 -0
  342. package/dist/builder/suggestions.d.ts +49 -0
  343. package/dist/builder/suggestions.js +260 -0
  344. package/dist/builder/summary.d.ts +60 -0
  345. package/dist/builder/summary.js +81 -0
  346. package/dist/builder/sync.d.ts +1 -0
  347. package/dist/builder/sync.js +187 -0
  348. package/dist/builder/tabs.d.ts +85 -0
  349. package/dist/builder/tabs.js +288 -0
  350. package/dist/builder/talk.d.ts +5 -0
  351. package/dist/builder/talk.js +108 -0
  352. package/dist/builder/thread.d.ts +60 -0
  353. package/dist/builder/thread.js +302 -0
  354. package/dist/builder/tools.d.ts +22 -0
  355. package/dist/builder/tools.js +52 -0
  356. package/dist/builder/transcript.d.ts +47 -0
  357. package/dist/builder/transcript.js +108 -0
  358. package/dist/builder/voice.d.ts +8 -0
  359. package/dist/builder/voice.js +24 -0
  360. package/dist/{changedFileKind-DqgCCDUs.js → changedFileKind-D6QYvIez.js} +1 -1
  361. package/dist/core.js +1 -0
  362. package/dist/{decodeImagePreview-CesVZYP4.js → decodeImagePreview-DnfFEjhw.js} +1 -1
  363. package/dist/{embed-DYP-OUlb.js → embed-c030vUqM.js} +11 -11
  364. package/dist/index.d.ts +2 -0
  365. package/dist/index.js +2 -1
  366. package/dist/{micromark-util-decode-string-NQjVkmZH.js → micromark-util-decode-string-C-5AXkOV.js} +5 -3
  367. package/dist/{readBinaryPreview-D2X4Uahu.js → readBinaryPreview-BAQ4fFjm.js} +1 -1
  368. package/dist/{useTextFieldSpeech-CyOZZPrV.js → useTextFieldSpeech-COa9XcRx.js} +1 -1
  369. package/package.json +101 -11
  370. /package/{index.d.ts → dist/core.d.ts} +0 -0
  371. /package/{keymap.d.ts → dist/keymap.d.ts} +0 -0
@@ -0,0 +1,401 @@
1
+ /**
2
+ * The organization's money: its plan, the cards it pays with, its invoices, its
3
+ * balance and credits, what it has spent this month, and the caps on that spend.
4
+ *
5
+ * GET /v1/billing/plans the catalog the serving brand sells (public)
6
+ * GET /v1/billing/subscriptions {count, subscriptions}
7
+ * POST /v1/billing/subscribe/card buy a plan with a saved card; one paid plan at a time (409)
8
+ * POST /v1/billing/subscriptions/{id}/cancel at the end of the paid period
9
+ * POST /v1/billing/subscriptions/{id}/reactivate
10
+ * GET /v1/billing/methods saved cards, newest first
11
+ * POST /v1/billing/methods save a card from the processor's single-use token
12
+ * DELETE /v1/billing/methods/{id}
13
+ * GET /v1/billing/settings the processor a browser tokenizes a card against
14
+ * GET /v1/billing/invoices {count, cursor, invoices}
15
+ * GET /v1/billing/invoices/{id}/pdf the invoice as a PDF
16
+ * GET /v1/billing/balance prepaid balance, whole cents
17
+ * GET /v1/billing/credit-balance granted credit, per currency
18
+ * GET /v1/billing/credits {grants}: every grant, spent and lapsed included
19
+ * GET /v1/billing/tier the rung served and its tier class
20
+ * GET /v1/billing/recharge the auto-reload rule
21
+ * PUT /v1/billing/recharge arm it (a card on file) or disarm it
22
+ * POST /v1/billing/topup charge a saved card into the balance
23
+ * GET /v1/billing/usage/rollup the plan's month: included spend and request windows
24
+ * GET /v1/usage/summary?range=month this month's spend, by category
25
+ * GET /v1/allowance the Free plan's allowance, and the pool it is served from
26
+ * GET /v1/billing/alerts spend caps (bare array)
27
+ * POST /v1/billing/alerts open a cap (org admin)
28
+ * PATCH /v1/billing/alerts/{id} change one (org admin)
29
+ * DELETE /v1/billing/alerts/{id} lift one (org admin)
30
+ *
31
+ * Every figure is whole cents. The wallet, the caps and the cards are the
32
+ * caller's own, resolved by the platform from the credential; nothing here names
33
+ * an org or a subject. No card number passes through this file: a card is saved
34
+ * from the token the processor's own form returns.
35
+ */
36
+ import { phrase } from '@hanzo/i18n';
37
+ import { call, headers, reason, Refusal, seg } from './call.js';
38
+ const str = (v) => (typeof v === 'string' ? v : '');
39
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
40
+ const obj = (v) => (v && typeof v === 'object' ? v : {});
41
+ const arr = (v) => (Array.isArray(v) ? v : []);
42
+ const words = (v) => arr(v).filter((s) => typeof s === 'string' && s !== '');
43
+ /** `$1,234.56` from whole cents; whole dollars drop the cents. */
44
+ export function money(cents, currency = 'usd') {
45
+ const whole = cents % 100 === 0;
46
+ try {
47
+ return new Intl.NumberFormat('en-US', {
48
+ style: 'currency',
49
+ currency: (currency || 'usd').toUpperCase(),
50
+ minimumFractionDigits: whole ? 0 : 2,
51
+ maximumFractionDigits: 2,
52
+ }).format(cents / 100);
53
+ }
54
+ catch {
55
+ return `${(cents / 100).toFixed(whole ? 0 : 2)} ${currency.toUpperCase()}`;
56
+ }
57
+ }
58
+ /** Whole cents from what a person typed as dollars — `25`, `$25.50` — or null. */
59
+ export function cents(typed) {
60
+ const s = typed.replace(/[$,\s]/g, '');
61
+ if (!/^\d+(\.\d{1,2})?$/.test(s))
62
+ return null;
63
+ const c = Math.round(Number(s) * 100);
64
+ return c > 0 ? c : null;
65
+ }
66
+ export function plan(raw) {
67
+ const p = obj(raw);
68
+ return {
69
+ id: str(p.slug) || str(p.id),
70
+ name: str(p.name),
71
+ description: str(p.description),
72
+ category: str(p.category),
73
+ monthly: num(p.price),
74
+ yearly: num(p.priceAnnual),
75
+ currency: str(p.currency) || 'usd',
76
+ perSeat: p.perSeat === true,
77
+ sales: p.contactSales === true,
78
+ popular: p.popular === true,
79
+ features: words(p.features),
80
+ };
81
+ }
82
+ /** The plans a person can hold. The catalog also carries add-ons (DNS, storage) that are not. */
83
+ const HELD = ['personal', 'team', 'enterprise'];
84
+ export async function plans(t) {
85
+ const raw = await call(t, 'GET', '/v1/billing/plans');
86
+ const rows = Array.isArray(raw) ? raw : arr(obj(raw).plans);
87
+ return rows.map(plan).filter((p) => p.id && p.name && (!p.category || HELD.includes(p.category)));
88
+ }
89
+ export function subscription(raw) {
90
+ const s = obj(raw);
91
+ const p = obj(s.plan);
92
+ return {
93
+ id: str(s.id),
94
+ plan: str(s.planId) || str(p.id),
95
+ name: str(p.name) || str(s.planId),
96
+ price: num(p.price),
97
+ interval: str(p.interval) || 'month',
98
+ currency: str(p.currency) || 'usd',
99
+ seats: num(s.quantity) || 1,
100
+ status: str(s.status),
101
+ ends: str(s.currentPeriodEnd),
102
+ ending: s.cancelAtPeriodEnd === true,
103
+ method: str(s.defaultPaymentMethod),
104
+ };
105
+ }
106
+ /** Only these confer the plan. */
107
+ const LIVE = ['active', 'trialing', 'past_due'];
108
+ /** The plan the org is on, or null for none (the free tier). */
109
+ export function current(list) {
110
+ return list.find((s) => LIVE.includes(s.status)) ?? null;
111
+ }
112
+ export async function subscriptions(t) {
113
+ const raw = obj(await call(t, 'GET', '/v1/billing/subscriptions'));
114
+ return arr(raw.subscriptions).map(subscription).filter((s) => s.id);
115
+ }
116
+ /** Buy a plan. No amount is sent: the catalog prices it, and the platform charges that. */
117
+ export async function subscribe(t, p) {
118
+ if (!p.method)
119
+ throw new Error(phrase('Add a card before choosing a paid plan'));
120
+ const raw = obj(await call(t, 'POST', '/v1/billing/subscribe/card', { planId: p.plan, paymentMethodId: p.method, interval: p.interval }));
121
+ return { subscription: str(raw.subscriptionId), charged: num(raw.amountCents) };
122
+ }
123
+ /** End a plan when its paid period does, not before. */
124
+ export async function cancel(t, id) {
125
+ return subscription(await call(t, 'POST', `/v1/billing/subscriptions/${seg(id)}/cancel`, { atPeriodEnd: true }));
126
+ }
127
+ export async function reactivate(t, id) {
128
+ return subscription(await call(t, 'POST', `/v1/billing/subscriptions/${seg(id)}/reactivate`, {}));
129
+ }
130
+ export function method(raw) {
131
+ const m = obj(raw);
132
+ const c = obj(m.card);
133
+ const a = obj(m.billingAddress);
134
+ const month = num(c.expMonth);
135
+ const year = num(c.expYear);
136
+ return {
137
+ id: str(m.id),
138
+ type: str(m.type) || 'card',
139
+ brand: str(c.brand),
140
+ last4: str(c.last4),
141
+ expires: month && year ? `${String(month).padStart(2, '0')}/${String(year % 100).padStart(2, '0')}` : '',
142
+ default: m.isDefault === true,
143
+ name: str(m.name),
144
+ billingAddress: a && (a.line1 || a.city || a.country || a.name || a.postalCode || a.state)
145
+ ? {
146
+ name: str(a.name),
147
+ line1: str(a.line1),
148
+ line2: str(a.line2),
149
+ city: str(a.city),
150
+ state: str(a.state),
151
+ postalCode: str(a.postalCode),
152
+ country: str(a.country),
153
+ }
154
+ : undefined,
155
+ };
156
+ }
157
+ /** Formats a billing address as a readable line: `Acme Inc · 123 Main St · San Francisco CA 94105 · US`. */
158
+ export function formatAddress(a) {
159
+ if (!a)
160
+ return '';
161
+ const parts = [
162
+ a.name,
163
+ [a.line1, a.line2].filter(Boolean).join(', '),
164
+ [a.city, a.state, a.postalCode].filter(Boolean).join(' '),
165
+ a.country,
166
+ ].filter(Boolean);
167
+ return parts.join(' · ');
168
+ }
169
+ /** How a saved method reads in a row: `Visa •••• 4242`. */
170
+ export function label(m) {
171
+ if (m.last4)
172
+ return `${m.brand ? m.brand.charAt(0).toUpperCase() + m.brand.slice(1) : 'Card'} •••• ${m.last4}`;
173
+ return m.name || m.type;
174
+ }
175
+ export async function methods(t) {
176
+ const raw = await call(t, 'GET', '/v1/billing/methods');
177
+ const rows = Array.isArray(raw) ? raw : arr(obj(raw).data);
178
+ return rows.map(method).filter((m) => m.id);
179
+ }
180
+ /** The card a charge uses: the default, or the newest. */
181
+ export function chosen(list) {
182
+ return list.find((m) => m.default) ?? list[0] ?? null;
183
+ }
184
+ /** Save a card from the single-use token the processor's form returned, optionally with billing info. */
185
+ export async function save(t, token, billingAddress) {
186
+ if (!token)
187
+ throw new Error(phrase('The card form returned no token'));
188
+ const body = { type: 'card', providerRef: token };
189
+ if (billingAddress && Object.values(billingAddress).some(Boolean)) {
190
+ body.billingAddress = billingAddress;
191
+ }
192
+ return method(await call(t, 'POST', '/v1/billing/methods', body));
193
+ }
194
+ export async function updateMethod(t, id, what) {
195
+ return method(await call(t, 'PATCH', `/v1/billing/methods/${seg(id)}`, what));
196
+ }
197
+ export async function detach(t, id) {
198
+ await call(t, 'DELETE', `/v1/billing/methods/${seg(id)}`);
199
+ }
200
+ export async function makeDefault(t, id) {
201
+ return method(await call(t, 'POST', `/v1/billing/methods/${seg(id)}/default`));
202
+ }
203
+ export async function processor(t) {
204
+ const p = obj(await call(t, 'GET', '/v1/billing/settings'));
205
+ return {
206
+ provider: str(p.provider),
207
+ application: str(p.applicationId),
208
+ location: str(p.locationId),
209
+ environment: str(p.environment),
210
+ live: p.live === true,
211
+ };
212
+ }
213
+ export function invoice(raw) {
214
+ const i = obj(raw);
215
+ const subtotal = num(i.subtotal);
216
+ const tax = num(i.tax);
217
+ const discount = num(i.discount);
218
+ return {
219
+ id: str(i.id),
220
+ number: str(i.numberStr) || (num(i.number) ? String(num(i.number)) : ''),
221
+ date: str(i.createdAt),
222
+ status: str(i.status),
223
+ currency: str(i.currency) || 'usd',
224
+ subtotal,
225
+ tax,
226
+ discount,
227
+ credit: num(i.creditApplied),
228
+ paid: num(i.amountPaid),
229
+ due: num(i.amountDue),
230
+ total: subtotal - discount + tax,
231
+ start: str(i.periodStart),
232
+ end: str(i.periodEnd),
233
+ lines: arr(i.lineItems)
234
+ .map(obj)
235
+ .map((l) => ({ description: str(l.description) || str(l.planName), amount: num(l.amount) })),
236
+ };
237
+ }
238
+ export async function invoices(t) {
239
+ const raw = obj(await call(t, 'GET', '/v1/billing/invoices'));
240
+ return arr(raw.invoices).map(invoice).filter((i) => i.id);
241
+ }
242
+ /** The invoice as a PDF, read with the caller's bearer. */
243
+ export async function pdf(t, id) {
244
+ const res = await fetch(`${t.api}/v1/billing/invoices/${seg(id)}/pdf`, { headers: headers(t), cache: 'no-store' });
245
+ if (!res.ok)
246
+ throw new Refusal(res.status, (await reason(res)) || `The invoice answered ${res.status}`);
247
+ return res.blob();
248
+ }
249
+ // ── balance, credit, spend ───────────────────────────────────────────────────
250
+ /** What the org can still spend from its prepaid balance, in cents. */
251
+ export async function balance(t) {
252
+ const b = obj(await call(t, 'GET', '/v1/billing/balance'));
253
+ return num(b.available ?? b.balance);
254
+ }
255
+ /**
256
+ * What can pay for another maker's models, whole cents: cash and the credit line, never
257
+ * granted credit (`GET /v1/billing/balance` `prepaid`). Null where the answer carries no
258
+ * such figure, so a caller does not assume it.
259
+ */
260
+ export async function prepaid(t) {
261
+ const b = obj(await call(t, 'GET', '/v1/billing/balance'));
262
+ return typeof b.prepaid === 'number' && Number.isFinite(b.prepaid) ? b.prepaid : null;
263
+ }
264
+ /** Granted credit the org can spend, in US cents. */
265
+ export async function credit(t) {
266
+ const raw = obj(await call(t, 'GET', '/v1/billing/credit-balance'));
267
+ return arr(raw.balances)
268
+ .map(obj)
269
+ .filter((b) => (str(b.currency) || 'usd').toLowerCase() === 'usd')
270
+ .reduce((sum, b) => sum + num(b.available), 0);
271
+ }
272
+ export async function grants(t) {
273
+ const raw = obj(await call(t, 'GET', '/v1/billing/credits'));
274
+ return arr(raw.grants)
275
+ .map(obj)
276
+ .map((g) => ({
277
+ id: str(g.id),
278
+ name: str(g.name),
279
+ amount: num(g.amountCents),
280
+ remaining: num(g.remainingCents),
281
+ currency: str(g.currency) || 'usd',
282
+ expires: str(g.expiresAt),
283
+ active: g.active === true && g.voided !== true,
284
+ }))
285
+ .filter((g) => g.id);
286
+ }
287
+ export async function tier(t) {
288
+ const r = obj(await call(t, 'GET', '/v1/billing/tier'));
289
+ return { plan: str(r.plan), tier: str(obj(r.tier).name), name: str(r.planName) };
290
+ }
291
+ function recharged(raw) {
292
+ const r = obj(raw);
293
+ return {
294
+ enabled: r.enabled === true,
295
+ threshold: num(r.thresholdCents),
296
+ amount: num(r.amountCents),
297
+ currency: str(r.currency) || 'usd',
298
+ last: str(r.lastRechargedAt),
299
+ };
300
+ }
301
+ /** The rule as stored; one never set reads as off. */
302
+ export async function recharge(t) {
303
+ return recharged(await call(t, 'GET', '/v1/billing/recharge'));
304
+ }
305
+ /** Arm or disarm the rule. Turning it on needs a card on file, and the platform says so when there is none. */
306
+ export async function arm(t, rule) {
307
+ return recharged(await call(t, 'PUT', '/v1/billing/recharge', { enabled: rule.enabled, thresholdCents: rule.threshold, amountCents: rule.amount, currency: 'usd' }));
308
+ }
309
+ /** Charge a saved card and add the amount to the balance; answers the balance after. */
310
+ export async function topup(t, amount, card) {
311
+ if (!Number.isInteger(amount) || amount <= 0)
312
+ throw new Error(phrase('Enter an amount to add'));
313
+ if (!card)
314
+ throw new Error(phrase('Add a card before buying more'));
315
+ const r = obj(await call(t, 'POST', '/v1/billing/topup', { amountCents: amount, paymentMethodId: card }));
316
+ return num(r.balanceCents);
317
+ }
318
+ export async function month(t) {
319
+ const r = obj(await call(t, 'GET', '/v1/billing/usage/rollup'));
320
+ const inc = obj(r.included);
321
+ return {
322
+ plan: str(r.plan),
323
+ period: str(r.period),
324
+ included: num(inc.monthlyCents) + num(inc.grantedCents),
325
+ used: num(inc.consumedCents),
326
+ overage: num(r.overageCents),
327
+ windows: arr(r.windows)
328
+ .map(obj)
329
+ .map((w) => ({ span: str(w.span), limit: num(w.limit), used: num(w.used), resets: str(w.resets) }))
330
+ .filter((w) => w.span),
331
+ };
332
+ }
333
+ export async function spend(t) {
334
+ const r = obj(await call(t, 'GET', '/v1/usage/summary?range=month'));
335
+ const s = obj(r.spend);
336
+ return {
337
+ known: s.available === true,
338
+ total: num(s.mtdCents) || num(s.totalCents),
339
+ categories: arr(s.byCategory)
340
+ .map(obj)
341
+ .map((c) => ({ name: str(c.category) || 'Uncategorized', cents: num(c.cents) }))
342
+ .filter((c) => c.cents > 0),
343
+ };
344
+ }
345
+ const stamp = (unix) => (num(unix) > 0 ? new Date(num(unix) * 1000).toISOString() : '');
346
+ export async function allowance(t) {
347
+ const r = obj(await call(t, 'GET', '/v1/allowance'));
348
+ const p = r.pool && typeof r.pool === 'object' ? obj(r.pool) : null;
349
+ return {
350
+ plan: str(r.plan),
351
+ limit: num(r.limit),
352
+ used: num(r.used),
353
+ spent: r.spent === true,
354
+ window: str(r.window),
355
+ resets: stamp(r.resets),
356
+ pooled: r.pooled === true,
357
+ pool: p && str(p.state) ? { state: str(p.state), resets: stamp(p.resets) } : null,
358
+ };
359
+ }
360
+ export function cap(raw) {
361
+ const a = obj(raw);
362
+ return {
363
+ id: str(a.id),
364
+ title: str(a.title),
365
+ threshold: num(a.threshold),
366
+ enforce: a.enforce === true,
367
+ project: str(a.project),
368
+ service: str(a.service),
369
+ spent: typeof a.periodSpentCents === 'number' ? a.periodSpentCents : null,
370
+ resets: str(a.resetsAt),
371
+ };
372
+ }
373
+ export async function caps(t) {
374
+ const raw = await call(t, 'GET', '/v1/billing/alerts');
375
+ return arr(raw).map(cap).filter((c) => c.id);
376
+ }
377
+ /** The org-wide monthly cap: no project, no service, a ceiling. */
378
+ export function monthly(list) {
379
+ return list.find((c) => !c.project && !c.service && c.threshold > 0) ?? null;
380
+ }
381
+ /** Set the org's monthly cap: change the one there is, or open one that refuses spend past it. */
382
+ export async function limit(t, list, threshold) {
383
+ if (!Number.isInteger(threshold) || threshold <= 0)
384
+ throw new Error(phrase('Enter a monthly limit'));
385
+ const was = monthly(list);
386
+ if (was)
387
+ return cap(await call(t, 'PATCH', `/v1/billing/alerts/${seg(was.id)}`, { threshold }));
388
+ return cap(await call(t, 'POST', '/v1/billing/alerts', {
389
+ title: 'Monthly limit',
390
+ threshold,
391
+ currency: 'usd',
392
+ project: '',
393
+ service: '',
394
+ enforce: true,
395
+ softPct: 80,
396
+ rateLimitRpm: 0,
397
+ }));
398
+ }
399
+ export async function lift(t, id) {
400
+ await call(t, 'DELETE', `/v1/billing/alerts/${seg(id)}`);
401
+ }
@@ -0,0 +1,53 @@
1
+ import type { Say } from '@hanzo/i18n/react';
2
+ /** Where the platform is and who is asking. The host supplies it. */
3
+ export interface Target {
4
+ /** The platform origin, no trailing slash: calls are `${api}/v1/…`. */
5
+ api: string;
6
+ /** The signed-in person's bearer, or null for nobody. */
7
+ token: () => string | null;
8
+ /** The org every call is scoped to, sent as `X-Org-Id`. */
9
+ org: string | null;
10
+ }
11
+ /** A refusal: the status, the platform's own sentence for it, and the code it names the refusal by ('' for none). */
12
+ export declare class Refusal extends Error {
13
+ readonly status: number;
14
+ readonly code: string;
15
+ constructor(status: number, message: string, code?: string);
16
+ }
17
+ /**
18
+ * A sentence this client wrote with something of the moment in it (a file's
19
+ * name, an address), thrown where no `t` is at hand: its message is the
20
+ * English, filled, and a screen says it from its source and values.
21
+ */
22
+ export declare class Sentence extends Error {
23
+ readonly source: string;
24
+ readonly values: Readonly<Record<string, string | number>>;
25
+ constructor(source: string, values?: Readonly<Record<string, string | number>>);
26
+ }
27
+ /**
28
+ * An error's own sentence, as the screen that caught it says it: one this
29
+ * client wrote, in the reader's language; the platform's, which is no key, as given.
30
+ */
31
+ export declare function told(e: unknown, t?: Say): string;
32
+ export type Query = Record<string, string | number | boolean | null | undefined>;
33
+ /** `?a=1&b=2` from the defined, non-empty entries of `q`, or ''. */
34
+ export declare function query(q?: Query): string;
35
+ /** The headers every call carries: the bearer and the org, when there are ones. */
36
+ export declare function headers(t: Target, extra?: HeadersInit): Headers;
37
+ /** The sentence a refusal carries, whichever envelope it arrived in. */
38
+ export declare function reason(res: Response): Promise<string>;
39
+ /** A path segment, escaped. Ids and names from a row never compose a path raw. */
40
+ export declare const seg: (s: string) => string;
41
+ /**
42
+ * One JSON call. Throws `Refusal` on any non-2xx, with the platform's reason, or
43
+ * the status when it gave none. A 204 answers `undefined`.
44
+ */
45
+ export declare function call<T>(t: Target, method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', path: string, body?: unknown, init?: {
46
+ signal?: AbortSignal;
47
+ }): Promise<T>;
48
+ /**
49
+ * The `{status, msg, data}` envelope IAM and the model service answer with. A
50
+ * refusal there is `status: "error"` with its sentence in `msg`, whatever the
51
+ * HTTP status was — often 200 — so it is read here and thrown like any other.
52
+ */
53
+ export declare function unwrap(raw: unknown): unknown;
@@ -0,0 +1,123 @@
1
+ /**
2
+ * One request path to the platform.
3
+ *
4
+ * Every typed op below goes through `call`, so the bearer, the org scope, the
5
+ * no-store cache rule and the reading of a refusal are decided once. The
6
+ * platform answers a refusal as RFC 9457 problem details; older handlers still
7
+ * answer `{error:{message}}` or `{msg}`, and all three read the same way here.
8
+ *
9
+ * A sentence this client writes is English, marked (`phrase`) for the
10
+ * translator: a module is not a component and asks no `t`, so a screen says
11
+ * what a module threw through its own (`told`), and a module that builds text
12
+ * takes the screen's `t` as its last argument, English (../say.ts `english`)
13
+ * when none is handed.
14
+ */
15
+ import { phrase, translate } from '@hanzo/i18n';
16
+ import { english } from '../say.js';
17
+ /** A refusal: the status, the platform's own sentence for it, and the code it names the refusal by ('' for none). */
18
+ export class Refusal extends Error {
19
+ status;
20
+ code;
21
+ constructor(status, message, code = '') {
22
+ super(message);
23
+ this.status = status;
24
+ this.code = code;
25
+ this.name = 'Refusal';
26
+ }
27
+ }
28
+ /**
29
+ * A sentence this client wrote with something of the moment in it (a file's
30
+ * name, an address), thrown where no `t` is at hand: its message is the
31
+ * English, filled, and a screen says it from its source and values.
32
+ */
33
+ export class Sentence extends Error {
34
+ source;
35
+ values;
36
+ constructor(source, values = {}) {
37
+ super(translate({}, source, values));
38
+ this.source = source;
39
+ this.values = values;
40
+ }
41
+ }
42
+ /**
43
+ * An error's own sentence, as the screen that caught it says it: one this
44
+ * client wrote, in the reader's language; the platform's, which is no key, as given.
45
+ */
46
+ export function told(e, t = english) {
47
+ if (e instanceof Sentence)
48
+ return t(e.source, e.values);
49
+ return t(e instanceof Error ? e.message : String(e));
50
+ }
51
+ /** `?a=1&b=2` from the defined, non-empty entries of `q`, or ''. */
52
+ export function query(q = {}) {
53
+ const s = new URLSearchParams();
54
+ for (const [k, v] of Object.entries(q)) {
55
+ if (v === undefined || v === null || v === '')
56
+ continue;
57
+ s.set(k, String(v));
58
+ }
59
+ const out = s.toString();
60
+ return out ? `?${out}` : '';
61
+ }
62
+ /** The headers every call carries: the bearer and the org, when there are ones. */
63
+ export function headers(t, extra) {
64
+ const h = new Headers(extra);
65
+ const token = t.token();
66
+ if (token && !h.has('Authorization'))
67
+ h.set('Authorization', `Bearer ${token}`);
68
+ if (t.org && !h.has('X-Org-Id'))
69
+ h.set('X-Org-Id', t.org);
70
+ return h;
71
+ }
72
+ /** The sentence a refusal carries, whichever envelope it arrived in, and the problem's `code` when it names one. */
73
+ async function problem(res) {
74
+ try {
75
+ const body = (await res.json());
76
+ const err = typeof body.error === 'string' ? body.error : body.error?.message;
77
+ return { why: body.detail || err || body.msg || body.message || body.title || '', code: typeof body.code === 'string' ? body.code : '' };
78
+ }
79
+ catch {
80
+ return { why: '', code: '' };
81
+ }
82
+ }
83
+ /** The sentence a refusal carries, whichever envelope it arrived in. */
84
+ export async function reason(res) {
85
+ return (await problem(res)).why;
86
+ }
87
+ /** A path segment, escaped. Ids and names from a row never compose a path raw. */
88
+ export const seg = (s) => encodeURIComponent(s);
89
+ /**
90
+ * One JSON call. Throws `Refusal` on any non-2xx, with the platform's reason, or
91
+ * the status when it gave none. A 204 answers `undefined`.
92
+ */
93
+ export async function call(t, method, path, body, init) {
94
+ const h = headers(t, body === undefined ? undefined : { 'Content-Type': 'application/json' });
95
+ const res = await fetch(`${t.api}${path}`, {
96
+ method,
97
+ headers: h,
98
+ body: body === undefined ? undefined : JSON.stringify(body),
99
+ // A run, a repo list and a status are facts about now. A cached refusal
100
+ // outlives the fix.
101
+ cache: 'no-store',
102
+ signal: init?.signal,
103
+ });
104
+ if (!res.ok) {
105
+ const { why, code } = await problem(res);
106
+ throw new Refusal(res.status, why || `${method} ${path.split('?')[0]} answered ${res.status}`, code);
107
+ }
108
+ if (res.status === 204)
109
+ return undefined;
110
+ const text = await res.text();
111
+ return (text ? JSON.parse(text) : undefined);
112
+ }
113
+ /**
114
+ * The `{status, msg, data}` envelope IAM and the model service answer with. A
115
+ * refusal there is `status: "error"` with its sentence in `msg`, whatever the
116
+ * HTTP status was — often 200 — so it is read here and thrown like any other.
117
+ */
118
+ export function unwrap(raw) {
119
+ const r = (raw && typeof raw === 'object' ? raw : {});
120
+ if (r.status === 'error')
121
+ throw new Refusal(400, typeof r.msg === 'string' && r.msg ? r.msg : phrase('The platform refused that'));
122
+ return r.data;
123
+ }
@@ -0,0 +1,14 @@
1
+ import { type Target } from './call.ts';
2
+ /** Where a tool comes from, in the order the platform ranks them. */
3
+ export declare const SOURCES: readonly ['connector', 'function', 'zap-service', 'agent', 'skill', 'mcp'];
4
+ export type Source = (typeof SOURCES)[number];
5
+ export interface Tool {
6
+ name: string;
7
+ source: Source;
8
+ description: string;
9
+ activated: boolean;
10
+ }
11
+ export declare function toolOf(raw: unknown): Tool | null;
12
+ export declare function tools(t: Target): Promise<Tool[]>;
13
+ /** Switch every tool in `names` on (or off), and answer the org's activated set. */
14
+ export declare function activate(t: Target, names: string[], on: boolean): Promise<string[]>;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * What the agent may use: every tool the org can reach, and which of them are
3
+ * switched on.
4
+ *
5
+ * GET /v1/tool → {tools: [{name, source, description, dispatchable, activated}]}
6
+ * PUT /v1/tool/activation {activate: [], deactivate: []} → {enabled: []}
7
+ *
8
+ * Activation is per org (and project): a tool that is off is listed but
9
+ * refused when an agent calls it. At most 256 names go in one request, so a
10
+ * larger change is sent in turns.
11
+ */
12
+ import { phrase } from '@hanzo/i18n';
13
+ import { call } from './call.js';
14
+ /** Where a tool comes from, in the order the platform ranks them. */
15
+ export const SOURCES = ['connector', 'function', 'zap-service', 'agent', 'skill', 'mcp'];
16
+ const BATCH = 256;
17
+ const str = (v) => (typeof v === 'string' ? v : '');
18
+ export function toolOf(raw) {
19
+ const o = (raw && typeof raw === 'object' ? raw : {});
20
+ const name = str(o.name);
21
+ const source = str(o.source);
22
+ if (!name || !SOURCES.includes(source))
23
+ return null;
24
+ return { name, source, description: str(o.description), activated: o.activated === true };
25
+ }
26
+ export async function tools(t) {
27
+ const r = await call(t, 'GET', '/v1/tool');
28
+ return (Array.isArray(r?.tools) ? r.tools : []).map(toolOf).filter((x) => x !== null);
29
+ }
30
+ /** Switch every tool in `names` on (or off), and answer the org's activated set. */
31
+ export async function activate(t, names, on) {
32
+ if (!names.length)
33
+ throw new Error(phrase('There is nothing to switch'));
34
+ let enabled = [];
35
+ for (let i = 0; i < names.length; i += BATCH) {
36
+ const part = names.slice(i, i + BATCH);
37
+ const r = await call(t, 'PUT', '/v1/tool/activation', on ? { activate: part, deactivate: [] } : { activate: [], deactivate: part });
38
+ enabled = Array.isArray(r?.enabled) ? r.enabled.filter((n) => typeof n === 'string') : [];
39
+ }
40
+ return enabled;
41
+ }