@b3os/sdk 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +233 -2
- package/dist/cjs/core/client.d.ts +165 -0
- package/dist/cjs/core/client.js +825 -0
- package/dist/cjs/core/client.js.map +1 -0
- package/dist/cjs/core/errors.d.ts +101 -0
- package/dist/cjs/core/errors.js +249 -0
- package/dist/cjs/core/errors.js.map +1 -0
- package/dist/cjs/core/index.d.ts +12 -0
- package/dist/cjs/core/index.js +42 -0
- package/dist/cjs/core/index.js.map +1 -0
- package/dist/cjs/core/jobs.d.ts +31 -0
- package/dist/cjs/core/jobs.js +72 -0
- package/dist/cjs/core/jobs.js.map +1 -0
- package/dist/cjs/core/namespace.d.ts +7 -0
- package/dist/cjs/core/namespace.js +13 -0
- package/dist/cjs/core/namespace.js.map +1 -0
- package/dist/cjs/core/op.d.ts +47 -0
- package/dist/cjs/core/op.js +5 -0
- package/dist/cjs/core/op.js.map +1 -0
- package/dist/cjs/core/promise.d.ts +106 -0
- package/dist/cjs/core/promise.js +200 -0
- package/dist/cjs/core/promise.js.map +1 -0
- package/dist/cjs/core/response.d.ts +54 -0
- package/dist/cjs/core/response.js +92 -0
- package/dist/cjs/core/response.js.map +1 -0
- package/dist/cjs/core/sse.d.ts +79 -0
- package/dist/cjs/core/sse.js +291 -0
- package/dist/cjs/core/sse.js.map +1 -0
- package/dist/cjs/core/timing.d.ts +20 -0
- package/dist/cjs/core/timing.js +96 -0
- package/dist/cjs/core/timing.js.map +1 -0
- package/dist/cjs/core/transport.d.ts +80 -0
- package/dist/cjs/core/transport.js +472 -0
- package/dist/cjs/core/transport.js.map +1 -0
- package/dist/cjs/core/util.d.ts +25 -0
- package/dist/cjs/core/util.js +142 -0
- package/dist/cjs/core/util.js.map +1 -0
- package/dist/cjs/core/ws.d.ts +52 -0
- package/dist/cjs/core/ws.js +181 -0
- package/dist/cjs/core/ws.js.map +1 -0
- package/dist/cjs/generated/client.d.ts +62 -0
- package/dist/cjs/generated/client.js +130 -0
- package/dist/cjs/generated/client.js.map +1 -0
- package/dist/cjs/generated/errors.d.ts +4 -0
- package/dist/cjs/generated/errors.js +160 -0
- package/dist/cjs/generated/errors.js.map +1 -0
- package/dist/cjs/generated/ids.d.ts +114 -0
- package/dist/cjs/generated/ids.js +47 -0
- package/dist/cjs/generated/ids.js.map +1 -0
- package/dist/cjs/generated/jobs.d.ts +10 -0
- package/dist/cjs/generated/jobs.js +24 -0
- package/dist/cjs/generated/jobs.js.map +1 -0
- package/dist/cjs/generated/ns/actions.d.ts +161 -0
- package/dist/cjs/generated/ns/actions.js +304 -0
- package/dist/cjs/generated/ns/actions.js.map +1 -0
- package/dist/cjs/generated/ns/infer.d.ts +190 -0
- package/dist/cjs/generated/ns/infer.js +253 -0
- package/dist/cjs/generated/ns/infer.js.map +1 -0
- package/dist/cjs/generated/ns/keys.d.ts +76 -0
- package/dist/cjs/generated/ns/keys.js +144 -0
- package/dist/cjs/generated/ns/keys.js.map +1 -0
- package/dist/cjs/generated/ns/limits.d.ts +22 -0
- package/dist/cjs/generated/ns/limits.js +32 -0
- package/dist/cjs/generated/ns/limits.js.map +1 -0
- package/dist/cjs/generated/ns/orgs.d.ts +38 -0
- package/dist/cjs/generated/ns/orgs.js +68 -0
- package/dist/cjs/generated/ns/orgs.js.map +1 -0
- package/dist/cjs/generated/ns/projects.d.ts +57 -0
- package/dist/cjs/generated/ns/projects.js +115 -0
- package/dist/cjs/generated/ns/projects.js.map +1 -0
- package/dist/cjs/generated/ns/render.d.ts +159 -0
- package/dist/cjs/generated/ns/render.js +299 -0
- package/dist/cjs/generated/ns/render.js.map +1 -0
- package/dist/cjs/generated/ns/requests.d.ts +36 -0
- package/dist/cjs/generated/ns/requests.js +54 -0
- package/dist/cjs/generated/ns/requests.js.map +1 -0
- package/dist/cjs/generated/ns/routines.d.ts +212 -0
- package/dist/cjs/generated/ns/routines.js +419 -0
- package/dist/cjs/generated/ns/routines.js.map +1 -0
- package/dist/cjs/generated/ns/sandboxes.d.ts +318 -0
- package/dist/cjs/generated/ns/sandboxes.js +549 -0
- package/dist/cjs/generated/ns/sandboxes.js.map +1 -0
- package/dist/cjs/generated/ns/usage.d.ts +30 -0
- package/dist/cjs/generated/ns/usage.js +49 -0
- package/dist/cjs/generated/ns/usage.js.map +1 -0
- package/dist/cjs/generated/ns/vault.d.ts +69 -0
- package/dist/cjs/generated/ns/vault.js +122 -0
- package/dist/cjs/generated/ns/vault.js.map +1 -0
- package/dist/cjs/generated/ns/vision.d.ts +376 -0
- package/dist/cjs/generated/ns/vision.js +736 -0
- package/dist/cjs/generated/ns/vision.js.map +1 -0
- package/dist/cjs/generated/ns/webhooks.d.ts +50 -0
- package/dist/cjs/generated/ns/webhooks.js +91 -0
- package/dist/cjs/generated/ns/webhooks.js.map +1 -0
- package/dist/cjs/generated/types.d.ts +4613 -0
- package/dist/cjs/generated/types.js +4 -0
- package/dist/cjs/generated/types.js.map +1 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.js +81 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/webhooks.d.ts +19 -0
- package/dist/cjs/webhooks.js +85 -0
- package/dist/cjs/webhooks.js.map +1 -0
- package/dist/esm/core/client.d.ts +165 -0
- package/dist/esm/core/client.js +821 -0
- package/dist/esm/core/client.js.map +1 -0
- package/dist/esm/core/errors.d.ts +101 -0
- package/dist/esm/core/errors.js +239 -0
- package/dist/esm/core/errors.js.map +1 -0
- package/dist/esm/core/index.d.ts +12 -0
- package/dist/esm/core/index.js +15 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/core/jobs.d.ts +31 -0
- package/dist/esm/core/jobs.js +66 -0
- package/dist/esm/core/jobs.js.map +1 -0
- package/dist/esm/core/namespace.d.ts +7 -0
- package/dist/esm/core/namespace.js +9 -0
- package/dist/esm/core/namespace.js.map +1 -0
- package/dist/esm/core/op.d.ts +47 -0
- package/dist/esm/core/op.js +4 -0
- package/dist/esm/core/op.js.map +1 -0
- package/dist/esm/core/promise.d.ts +106 -0
- package/dist/esm/core/promise.js +193 -0
- package/dist/esm/core/promise.js.map +1 -0
- package/dist/esm/core/response.d.ts +54 -0
- package/dist/esm/core/response.js +86 -0
- package/dist/esm/core/response.js.map +1 -0
- package/dist/esm/core/sse.d.ts +79 -0
- package/dist/esm/core/sse.js +286 -0
- package/dist/esm/core/sse.js.map +1 -0
- package/dist/esm/core/timing.d.ts +20 -0
- package/dist/esm/core/timing.js +92 -0
- package/dist/esm/core/timing.js.map +1 -0
- package/dist/esm/core/transport.d.ts +80 -0
- package/dist/esm/core/transport.js +465 -0
- package/dist/esm/core/transport.js.map +1 -0
- package/dist/esm/core/util.d.ts +25 -0
- package/dist/esm/core/util.js +128 -0
- package/dist/esm/core/util.js.map +1 -0
- package/dist/esm/core/ws.d.ts +52 -0
- package/dist/esm/core/ws.js +175 -0
- package/dist/esm/core/ws.js.map +1 -0
- package/dist/esm/generated/client.d.ts +62 -0
- package/dist/esm/generated/client.js +126 -0
- package/dist/esm/generated/client.js.map +1 -0
- package/dist/esm/generated/errors.d.ts +4 -0
- package/dist/esm/generated/errors.js +157 -0
- package/dist/esm/generated/errors.js.map +1 -0
- package/dist/esm/generated/ids.d.ts +114 -0
- package/dist/esm/generated/ids.js +42 -0
- package/dist/esm/generated/ids.js.map +1 -0
- package/dist/esm/generated/jobs.d.ts +10 -0
- package/dist/esm/generated/jobs.js +21 -0
- package/dist/esm/generated/jobs.js.map +1 -0
- package/dist/esm/generated/ns/actions.d.ts +161 -0
- package/dist/esm/generated/ns/actions.js +300 -0
- package/dist/esm/generated/ns/actions.js.map +1 -0
- package/dist/esm/generated/ns/infer.d.ts +190 -0
- package/dist/esm/generated/ns/infer.js +249 -0
- package/dist/esm/generated/ns/infer.js.map +1 -0
- package/dist/esm/generated/ns/keys.d.ts +76 -0
- package/dist/esm/generated/ns/keys.js +140 -0
- package/dist/esm/generated/ns/keys.js.map +1 -0
- package/dist/esm/generated/ns/limits.d.ts +22 -0
- package/dist/esm/generated/ns/limits.js +28 -0
- package/dist/esm/generated/ns/limits.js.map +1 -0
- package/dist/esm/generated/ns/orgs.d.ts +38 -0
- package/dist/esm/generated/ns/orgs.js +64 -0
- package/dist/esm/generated/ns/orgs.js.map +1 -0
- package/dist/esm/generated/ns/projects.d.ts +57 -0
- package/dist/esm/generated/ns/projects.js +111 -0
- package/dist/esm/generated/ns/projects.js.map +1 -0
- package/dist/esm/generated/ns/render.d.ts +159 -0
- package/dist/esm/generated/ns/render.js +295 -0
- package/dist/esm/generated/ns/render.js.map +1 -0
- package/dist/esm/generated/ns/requests.d.ts +36 -0
- package/dist/esm/generated/ns/requests.js +50 -0
- package/dist/esm/generated/ns/requests.js.map +1 -0
- package/dist/esm/generated/ns/routines.d.ts +212 -0
- package/dist/esm/generated/ns/routines.js +415 -0
- package/dist/esm/generated/ns/routines.js.map +1 -0
- package/dist/esm/generated/ns/sandboxes.d.ts +318 -0
- package/dist/esm/generated/ns/sandboxes.js +545 -0
- package/dist/esm/generated/ns/sandboxes.js.map +1 -0
- package/dist/esm/generated/ns/usage.d.ts +30 -0
- package/dist/esm/generated/ns/usage.js +45 -0
- package/dist/esm/generated/ns/usage.js.map +1 -0
- package/dist/esm/generated/ns/vault.d.ts +69 -0
- package/dist/esm/generated/ns/vault.js +118 -0
- package/dist/esm/generated/ns/vault.js.map +1 -0
- package/dist/esm/generated/ns/vision.d.ts +376 -0
- package/dist/esm/generated/ns/vision.js +732 -0
- package/dist/esm/generated/ns/vision.js.map +1 -0
- package/dist/esm/generated/ns/webhooks.d.ts +50 -0
- package/dist/esm/generated/ns/webhooks.js +87 -0
- package/dist/esm/generated/ns/webhooks.js.map +1 -0
- package/dist/esm/generated/types.d.ts +4613 -0
- package/dist/esm/generated/types.js +3 -0
- package/dist/esm/generated/types.js.map +1 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.js +28 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/webhooks.d.ts +19 -0
- package/dist/esm/webhooks.js +79 -0
- package/dist/esm/webhooks.js.map +1 -0
- package/package.json +98 -4
- package/src/core/client.ts +1022 -0
- package/src/core/errors.ts +296 -0
- package/src/core/index.ts +45 -0
- package/src/core/jobs.ts +94 -0
- package/src/core/namespace.ts +10 -0
- package/src/core/op.ts +53 -0
- package/src/core/promise.ts +268 -0
- package/src/core/response.ts +115 -0
- package/src/core/sse.ts +305 -0
- package/src/core/timing.ts +106 -0
- package/src/core/transport.ts +489 -0
- package/src/core/util.ts +138 -0
- package/src/core/ws.ts +215 -0
- package/src/generated/client.ts +143 -0
- package/src/generated/errors.ts +313 -0
- package/src/generated/ids.ts +47 -0
- package/src/generated/jobs.ts +25 -0
- package/src/generated/ns/actions.ts +353 -0
- package/src/generated/ns/infer.ts +332 -0
- package/src/generated/ns/keys.ts +152 -0
- package/src/generated/ns/limits.ts +35 -0
- package/src/generated/ns/orgs.ts +77 -0
- package/src/generated/ns/projects.ts +122 -0
- package/src/generated/ns/render.ts +348 -0
- package/src/generated/ns/requests.ts +61 -0
- package/src/generated/ns/routines.ts +474 -0
- package/src/generated/ns/sandboxes.ts +671 -0
- package/src/generated/ns/usage.ts +56 -0
- package/src/generated/ns/vault.ts +136 -0
- package/src/generated/ns/vision.ts +836 -0
- package/src/generated/ns/webhooks.ts +100 -0
- package/src/generated/types.ts +5131 -0
- package/src/index.ts +30 -0
- package/src/webhooks.ts +100 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,234 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @b3os/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for B3OS beta: browsers and web extraction (vision), screenshots and videos (render), microVM
|
|
4
|
+
sandboxes, routines, marketplace actions, the credential vault and inference. One client, one key. Generated from
|
|
5
|
+
`packages/spec/dist/openapi.json` (138 operations in 14 namespaces) with a hand-written runtime. ESM and CommonJS,
|
|
6
|
+
no runtime dependencies. Targets Node 20.16+ (it needs `process.getBuiltinModule`), Bun, Deno, Cloudflare Workers
|
|
7
|
+
and browsers. What has been run so far: the unit and Prism suites on Node 25.8 and 24.22; the live suite against a
|
|
8
|
+
dev b3osd on Node 24.22; the benchmark (same calls, Unix socket and TCP) on Node 24.22 and Bun 1.4.4; a Worker run
|
|
9
|
+
locally in workerd by Wrangler 4.42.0, with and without `nodejs_compat` (JSON call, typed error, Server-Timing, an
|
|
10
|
+
exec event stream, webhook verification); and a unit test that runs a neutral-platform bundle with only web
|
|
11
|
+
globals. Deno and browsers have not been run yet. On Workers, a `fetch` option is called unbound: pass a bound
|
|
12
|
+
function if yours needs its `this` (a service binding's `env.API.fetch.bind(env.API)`).
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { B3OS } from "@b3os/sdk";
|
|
16
|
+
|
|
17
|
+
const b3 = new B3OS(); // B3OS_API_KEY
|
|
18
|
+
|
|
19
|
+
const page = await b3.vision.scrape({ url: "https://example.com", formats: ["markdown"] });
|
|
20
|
+
console.log(page.markdown);
|
|
21
|
+
|
|
22
|
+
const sbx = await b3.sandboxes.createSandbox({ template: "base" });
|
|
23
|
+
const out = await b3.sandboxes.exec(sbx.id, { cmd: "python3 -c 'print(2 + 2)'" });
|
|
24
|
+
console.log(out.stdout); // "4\n"
|
|
25
|
+
await b3.sandboxes.deleteSandbox(sbx.id);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Where requests go
|
|
29
|
+
|
|
30
|
+
Every operation is either served by the node (products) or by beta-api.b3os.org (keys, usage, limits, orgs,
|
|
31
|
+
projects, the pack registry; `x-b3os-served-by: edge`). The client picks the shortest path for node operations:
|
|
32
|
+
|
|
33
|
+
| Situation | Node operations | Account operations |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| Default | `https://beta-api.b3os.org` with `Authorization: Bearer $B3OS_API_KEY` | same |
|
|
36
|
+
| Inside a B3OS sandbox (`B3OS_API_URL=http://127.0.0.1:7700`) | that URL, no key sent; the sandbox's `api` grant decides | beta-api.b3os.org with the key if one is set |
|
|
37
|
+
| On a B3OS node, with `B3OS_SOCKET` set, or with no key and no base URL configured and `/run/b3os/b3osd/b3osd.sock` present | b3osd's Unix socket, no key sent; the node maps your uid to a principal | beta-api.b3os.org with the key |
|
|
38
|
+
|
|
39
|
+
Options and environment:
|
|
40
|
+
|
|
41
|
+
| Option | Environment | Meaning |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| `apiKey` | `B3OS_API_KEY` | `b3os_sk_…` key or `b3os_pat_…` CLI token |
|
|
44
|
+
| `baseUrl` | `B3OS_BASE_URL` | API host (default `https://beta-api.b3os.org`) |
|
|
45
|
+
| `nodeUrl` | `B3OS_API_URL` | node-local URL for node operations, sent without the key |
|
|
46
|
+
| `socketPath` | `B3OS_SOCKET` | b3osd's Unix socket; `false` (or `B3OS_SOCKET=off`) disables it |
|
|
47
|
+
| `transport: "http"` | `B3OS_TRANSPORT=http` | send everything to `baseUrl` with the key |
|
|
48
|
+
| `timeoutMs`, `maxRetries` (2), `maxRetryDelayMs` (60 s), `headers`, `fetch`, `onResponse` | | |
|
|
49
|
+
|
|
50
|
+
The default socket is used only when neither an API key nor a base URL was configured. Over the socket you act as
|
|
51
|
+
the principal b3osd maps your uid to (`[auth.local_peers]`, else the read-only `[auth.local_default]`), not as a
|
|
52
|
+
key's principal, so a client with a key that picked the socket by itself would run node-served calls in one org and
|
|
53
|
+
edge-served calls in another; set `B3OS_SOCKET` (or `socketPath`) to choose the socket explicitly. If the default
|
|
54
|
+
socket exists but refuses the connection, the client switches to the API for the rest of its life. A 403 over the
|
|
55
|
+
socket says which principal it ran as and points at `B3OS_TRANSPORT=http`. When an account operation reaches a node without a key, the node answers `421 edge_only`
|
|
56
|
+
and the error says to set `B3OS_API_KEY`.
|
|
57
|
+
|
|
58
|
+
On Node, the socket and plain-HTTP node URLs use `node:http` keep-alive; HTTPS and every other runtime use `fetch`
|
|
59
|
+
(Bun reaches the socket through `fetch(url, {unix})`).
|
|
60
|
+
|
|
61
|
+
## Calling operations
|
|
62
|
+
|
|
63
|
+
Methods are named as in `packages/spec/dist/routes.json` (`sdk.ns`, `sdk.method`): the operationId without its
|
|
64
|
+
product prefix. Arguments are path parameters in path order, then an object of query and header parameters, then
|
|
65
|
+
the body, then request options:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
await b3.sandboxes.getSandbox("sbx_01m5t68q1b590rj801nbzsqzkk");
|
|
69
|
+
await b3.sandboxes.listSandboxes({ status: "running", limit: 50 });
|
|
70
|
+
await b3.sandboxes.writeFile(id, { path: "/workspace/main.py", mkdir: 1 }, "print(1)\n");
|
|
71
|
+
const bytes = await b3.sandboxes.readFile(id, { path: "/workspace/out.bin" }); // Uint8Array
|
|
72
|
+
const listing = await b3.sandboxes.readFile(id, { path: "/workspace", list: 1 }); // JSON listing
|
|
73
|
+
const md = await b3.vision.readUrl("https://example.com/pricing", { only_main_content: false }); // string
|
|
74
|
+
const png = await b3.render.createScreenshot({ url }, { accept: "image/png" }); // Uint8Array
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Request options (last argument of every method): `idempotencyKey`, `timeoutMs`, `maxRetries`, `signal`, `headers`,
|
|
78
|
+
`traceparent`.
|
|
79
|
+
|
|
80
|
+
Every type in the spec is exported (`import type { Sandbox, ScrapeRequest } from "@b3os/sdk"`).
|
|
81
|
+
|
|
82
|
+
## Responses and timing
|
|
83
|
+
|
|
84
|
+
Every call returns an awaitable with `.withResponse()`:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
const { data, response } = await b3.vision.scrape({ url }).withResponse();
|
|
88
|
+
response.requestId; // req_… (for GET /v1/requests/{id} and support)
|
|
89
|
+
response.timing; // parsed Server-Timing: { total_ms, edge_ms, phases: { edge_auth, claim, navigate, … }, entries }
|
|
90
|
+
response.attempts; // 1 + retries
|
|
91
|
+
response.idempotentReplayed;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`responseOf(result)` returns the same for any object result, and `onResponse` in the client options sees every
|
|
95
|
+
response head. JSON bodies keep their own `timing` field (server phases) untouched.
|
|
96
|
+
|
|
97
|
+
## Errors
|
|
98
|
+
|
|
99
|
+
Non-2xx answers throw `B3OSError` with the stable `code` from the errors catalog, `status`, `type`
|
|
100
|
+
(`https://docs.beta.b3os.org/errors#<code>`), `title`, `detail`, `requestId`, `errors` (validation pointers),
|
|
101
|
+
`problem` (the full body: `reason`, `limit`, `required_scope`, …), `retryAfterMs`, `retryable` and `timing`.
|
|
102
|
+
OpenAI-shaped (infer) and OAuth-shaped (device login) bodies are parsed into the same fields.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
try {
|
|
106
|
+
await b3.sandboxes.exec(id, { cmd: "ls" });
|
|
107
|
+
} catch (e) {
|
|
108
|
+
if (B3OSError.is(e, "sandbox_not_running")) await b3.sandboxes.resumeSandbox(id);
|
|
109
|
+
else throw e;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Client-side failures use codes no server sends: `connection_error` (`B3OSConnectionError`), `timeout`
|
|
114
|
+
(`B3OSTimeoutError`), `aborted` (`B3OSAbortError`, named `AbortError`), `invalid_response`, `stream_interrupted`,
|
|
115
|
+
`unsupported_transport`. A job that ends failed or canceled while you wait for it throws `B3OSJobError` with the
|
|
116
|
+
job's own problem and `.job`.
|
|
117
|
+
|
|
118
|
+
## Retries and idempotency
|
|
119
|
+
|
|
120
|
+
Effectful creates that accept `Idempotency-Key` get one generated per call (or use yours), and every retry of the
|
|
121
|
+
call reuses it. Retries use equal-jitter exponential backoff (0.5 s doubling, at most 8 s) or `Retry-After`, up to
|
|
122
|
+
`maxRetries` (2):
|
|
123
|
+
|
|
124
|
+
- always, for answers that refused the request before any work: `429 rate_limited`, `concurrency_limited`,
|
|
125
|
+
`ticket_limit`, `503 node_unavailable`, `product_unavailable`, `capacity_unavailable`, `auth_unavailable`,
|
|
126
|
+
`409 idempotency_request_in_progress` when B3OS says so in a problem body, a 429 or Cloudflare 521/522/523/530
|
|
127
|
+
without one (the request never reached the origin), and refused connections;
|
|
128
|
+
- for retry-safe calls only (GET, PUT, DELETE, or an idempotency key), also retryable 5xx answers and dropped
|
|
129
|
+
connections. A 502, 503 or 520 page without a problem body (a CDN's error page) becomes `internal` and counts
|
|
130
|
+
here: the origin may already have run the request, so a non-idempotent call is not sent again;
|
|
131
|
+
- never for timeouts (`timeout`, `request_timeout`, `scrape_timeout`, `upstream_timeout`, `job_timed_out`), and never
|
|
132
|
+
when `Retry-After` exceeds `maxRetryDelayMs`.
|
|
133
|
+
|
|
134
|
+
## Jobs
|
|
135
|
+
|
|
136
|
+
Crawls, batch scrapes, extracts, videos and routine runs are jobs (`x-b3os-job`). A job-creating method returns a
|
|
137
|
+
`JobPromise`:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
const job = await b3.vision.createCrawl({ url, limit: 50 }); // the job as created (queued or running)
|
|
141
|
+
const done = await b3.vision.createCrawl({ url, limit: 50 }).wait(); // the finished job
|
|
142
|
+
for await (const ev of b3.vision.createCrawl({ url }).events()) console.log(ev.type); // job.queued … job.succeeded
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`.wait()` sends the create with `?wait` (up to 60 s), then follows the job's event stream to its terminal event,
|
|
146
|
+
polling the job if the deployment has no events operation. It resolves with the succeeded job or throws
|
|
147
|
+
`B3OSJobError` (`{ throwOnFailure: false }` returns the job instead); `timeoutMs`, `signal` and `onEvent` are
|
|
148
|
+
options. Called right away, `.wait()` and `.events()` shape the creating request itself (one request); called later
|
|
149
|
+
they follow up with the job's get and events operations. For any job: `b3.jobs.wait(job)`, `b3.jobs.events(job)`,
|
|
150
|
+
`b3.jobs.get(job)`, `b3.jobs.cancel(job)` with the job object or its id. The platform-wide `job_` prefix (extracts)
|
|
151
|
+
is shared by several job kinds, so those take the job object, whose `kind` says which operations serve it; a bare
|
|
152
|
+
`job_` id is refused.
|
|
153
|
+
|
|
154
|
+
## Streams
|
|
155
|
+
|
|
156
|
+
Event streams are async iterables. Job and log streams resume after a dropped connection with `Last-Event-ID`
|
|
157
|
+
(reconnects back off, give up after 6 failures in a row, and treat 45 s without bytes, three missed pings, as a
|
|
158
|
+
drop). A stream that cannot resume (exec output, chat) fails with `stream_interrupted` or `timeout` instead.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
for await (const ev of b3.sandboxes.exec(id, { cmd: "npm test" }, { stream: true })) {
|
|
162
|
+
if (ev.type === "exec.stdout") process.stdout.write(ev.data ?? "");
|
|
163
|
+
}
|
|
164
|
+
const chunks = b3.infer.createChatCompletion({ model, messages, stream: true });
|
|
165
|
+
for await (const c of chunks) process.stdout.write(c.choices[0]?.delta?.content ?? "");
|
|
166
|
+
for await (const ev of b3.routines.runEvents(runId, { lastEventId: "41" })) console.log(ev);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`stream.close()` ends a loop quietly; `stream.lastEventId` is where to resume later.
|
|
170
|
+
|
|
171
|
+
## Lists
|
|
172
|
+
|
|
173
|
+
List methods return one page when awaited and walk every item across pages with `for await`:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
for await (const s of b3.sandboxes.listSandboxes({ status: "running" })) console.log(s.id);
|
|
177
|
+
for await (const page of b3.vision.listCrawlPages(crawlId).pages()) console.log(page.data.length);
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Terminals and CDP
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
const pty = await b3.sandboxes.openPty(id, { cols: 120, rows: 40 }); // mints a stream ticket, opens the WebSocket
|
|
184
|
+
pty.onData((bytes) => process.stdout.write(bytes));
|
|
185
|
+
pty.write("ls -la\n");
|
|
186
|
+
pty.resize(160, 48);
|
|
187
|
+
const { code } = await pty.exit;
|
|
188
|
+
|
|
189
|
+
const { url } = await b3.vision.connectCdp(sessionId); // wss://…/cdp?ticket=tkt_… (valid 30 s, single use)
|
|
190
|
+
const browser = await chromium.connectOverCDP(url);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
WebSockets need a global `WebSocket` (Node 22+, Bun, Deno, browsers) and do not go over the Unix socket; on a node
|
|
194
|
+
they use the API host when a key is set.
|
|
195
|
+
|
|
196
|
+
## Webhooks
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
import { verifyWebhook } from "@b3os/sdk/webhooks";
|
|
200
|
+
const event = await verifyWebhook(rawBody, req.headers.get("b3os-signature"), process.env.WHSEC!);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
It checks `t=<unix>,v1=<hex HMAC-SHA256(secret, "<t>.<raw body>")>` in constant time, accepts any of several
|
|
204
|
+
secrets during a rotation, and rejects timestamps more than 300 s away.
|
|
205
|
+
|
|
206
|
+
## Smaller bundles
|
|
207
|
+
|
|
208
|
+
The package is side-effect free with one module per source file. To ship one product only:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { B3OSCore } from "@b3os/sdk/core";
|
|
212
|
+
import { SandboxesAPI } from "@b3os/sdk/sandboxes";
|
|
213
|
+
const sandboxes = new SandboxesAPI(new B3OSCore({ apiKey }));
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Every namespace has a subpath (`@b3os/sdk/vision`, `/render`, `/sandboxes`, `/routines`, `/actions`, `/vault`,
|
|
217
|
+
`/infer`, `/keys`, …); `@b3os/sdk/types` has the types alone. Node built-ins are loaded through
|
|
218
|
+
`process.getBuiltinModule` only when a Node transport is used, so bundles for Workers and browsers contain no
|
|
219
|
+
`node:` imports. For any operation not wrapped here (device login, newer endpoints): `b3.request({ method, path,
|
|
220
|
+
query, body })`.
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
```sh
|
|
225
|
+
node packages/sdk/scripts/generate.mjs # regenerate src/generated (and the Python SDK) from packages/spec/dist
|
|
226
|
+
node packages/sdk/scripts/generate.mjs --check # exit 1 when generated code is stale
|
|
227
|
+
pnpm --filter @b3os/sdk typecheck
|
|
228
|
+
pnpm --filter @b3os/sdk test # unit tests + the Prism contract test (B3OS_PRISM=0 skips it)
|
|
229
|
+
pnpm --filter @b3os/sdk build # dist/esm and dist/cjs
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
The contract test starts `@stoplight/prism-cli@5.16.0` on `packages/spec/dist/openapi.json` and calls every
|
|
233
|
+
operation with the spec's own examples; Prism validates each request and the test fails on any violation. The live
|
|
234
|
+
test against a dev b3osd runs on dev-h200: `ops/box.sh sdk -- bash packages/sdk/test/live/run.sh`.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { CallArgs, JobOps, Op } from "./op.ts";
|
|
2
|
+
import { APIPromise, JobEventStream, type JobEventsOptions, type JobLike, JobPromise, type ListPage, ListPromise, type WaitOptions } from "./promise.ts";
|
|
3
|
+
import { ResponseInfo } from "./response.ts";
|
|
4
|
+
import { EventStream, type SSEMessage } from "./sse.ts";
|
|
5
|
+
import { type RequestBody, type Transport, type TransportResponse } from "./transport.ts";
|
|
6
|
+
/** A binary request body (file uploads, pack bundles). */
|
|
7
|
+
export type BinaryInput = RequestBody;
|
|
8
|
+
export declare const DEFAULT_BASE_URL = "https://beta-api.b3os.org";
|
|
9
|
+
/** b3osd's Unix socket on a B3OS node (ARCHITECTURE §1). */
|
|
10
|
+
export declare const DEFAULT_SOCKET_PATH = "/run/b3os/b3osd/b3osd.sock";
|
|
11
|
+
export interface ClientOptions {
|
|
12
|
+
/** API key (`b3os_sk_…`) or CLI token (`b3os_pat_…`). Default: `B3OS_API_KEY`. */
|
|
13
|
+
apiKey?: string | null;
|
|
14
|
+
/** The API host for edge-served operations and remote calls. Default: `B3OS_BASE_URL`, else beta-api.b3os.org. */
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
/**
|
|
17
|
+
* A node-local HTTP URL for node-served operations, sent without the API key. Default: `B3OS_API_URL`, which
|
|
18
|
+
* B3OS sets to `http://127.0.0.1:7700` inside sandboxes (the sandbox's own grant decides what it may call).
|
|
19
|
+
*/
|
|
20
|
+
nodeUrl?: string | null;
|
|
21
|
+
/**
|
|
22
|
+
* b3osd's Unix socket for node-served operations (the same-host fast path; the node maps your uid to a
|
|
23
|
+
* principal, no API key is sent). Default: `B3OS_SOCKET`, else `/run/b3os/b3osd/b3osd.sock` when it exists and
|
|
24
|
+
* neither an API key nor a base URL was configured: with a key, node-served calls would otherwise run as the
|
|
25
|
+
* uid's principal (possibly another org) while edge-served calls run as the key's. `false` disables the socket.
|
|
26
|
+
*/
|
|
27
|
+
socketPath?: string | false | null;
|
|
28
|
+
/**
|
|
29
|
+
* `auto` (default) picks the fastest path as above; `http` sends everything to `baseUrl` with the API key.
|
|
30
|
+
* Default: `B3OS_TRANSPORT`.
|
|
31
|
+
*/
|
|
32
|
+
transport?: "auto" | "http";
|
|
33
|
+
/** Per-attempt timeout. Default: the operation's `x-b3os-timeout-ms` (capped at 65 s) plus 5 s. */
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
/** Retries for retry-safe failures. Default 2. */
|
|
36
|
+
maxRetries?: number;
|
|
37
|
+
/** Longest `Retry-After` the client waits out by itself. Default 60 s. */
|
|
38
|
+
maxRetryDelayMs?: number;
|
|
39
|
+
/** A fetch implementation (tests, proxies, Workers service bindings). */
|
|
40
|
+
fetch?: (input: string, init?: RequestInit) => Promise<Response>;
|
|
41
|
+
/** Headers added to every request. */
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
/** Called after every response head, successful or not. */
|
|
44
|
+
onResponse?: (info: ResponseInfo) => void;
|
|
45
|
+
}
|
|
46
|
+
export interface RequestOptions {
|
|
47
|
+
/** `Idempotency-Key` for this call; generated when the operation takes one and you pass none. */
|
|
48
|
+
idempotencyKey?: string;
|
|
49
|
+
timeoutMs?: number;
|
|
50
|
+
maxRetries?: number;
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
headers?: Record<string, string>;
|
|
53
|
+
/** W3C trace context, propagated into product calls and routine steps. */
|
|
54
|
+
traceparent?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface StreamOptions extends RequestOptions {
|
|
57
|
+
/** Resume after this event id (`seq`). */
|
|
58
|
+
lastEventId?: string;
|
|
59
|
+
idleTimeoutMs?: number;
|
|
60
|
+
maxReconnects?: number;
|
|
61
|
+
}
|
|
62
|
+
/** A request to an operation the generated namespaces do not wrap (`client.request`). */
|
|
63
|
+
export interface RawRequest {
|
|
64
|
+
method: Op["method"];
|
|
65
|
+
path: string;
|
|
66
|
+
query?: object;
|
|
67
|
+
body?: unknown;
|
|
68
|
+
bodyType?: "json" | "bytes" | "yaml" | "form";
|
|
69
|
+
headers?: Record<string, string>;
|
|
70
|
+
/** Send to beta-api.b3os.org (edge-served operations). Default: by path, account paths go to the edge. */
|
|
71
|
+
edge?: boolean;
|
|
72
|
+
/** Error shape of the endpoint. */
|
|
73
|
+
errorFormat?: Op["errorFormat"];
|
|
74
|
+
timeoutMs?: number;
|
|
75
|
+
}
|
|
76
|
+
interface Route {
|
|
77
|
+
kind: "edge" | "node-http" | "uds";
|
|
78
|
+
transport: Transport;
|
|
79
|
+
/** URL prefix without a trailing slash. */
|
|
80
|
+
base: string;
|
|
81
|
+
/** Send `Authorization: Bearer <apiKey>`. */
|
|
82
|
+
auth: boolean;
|
|
83
|
+
/** Auto-detected default socket: fall back to the edge when it refuses connections. */
|
|
84
|
+
auto: boolean;
|
|
85
|
+
}
|
|
86
|
+
interface Sent {
|
|
87
|
+
res: TransportResponse;
|
|
88
|
+
info: ResponseInfo;
|
|
89
|
+
}
|
|
90
|
+
export declare class B3OSCore {
|
|
91
|
+
readonly apiKey: string | null;
|
|
92
|
+
readonly baseUrl: string;
|
|
93
|
+
readonly maxRetries: number;
|
|
94
|
+
readonly maxRetryDelayMs: number;
|
|
95
|
+
readonly timeoutMs: number | undefined;
|
|
96
|
+
private edge;
|
|
97
|
+
private node;
|
|
98
|
+
private readonly headers;
|
|
99
|
+
private readonly onResponse;
|
|
100
|
+
constructor(options?: ClientOptions);
|
|
101
|
+
private udsRoute;
|
|
102
|
+
/** Where node-served and edge-served operations go (`unix:/run/b3os/b3osd/b3osd.sock`, a URL). */
|
|
103
|
+
get routes(): {
|
|
104
|
+
node: string;
|
|
105
|
+
edge: string;
|
|
106
|
+
nodeKind: Route["kind"];
|
|
107
|
+
};
|
|
108
|
+
/** Closes pooled connections (the Unix socket agent). Optional; idle sockets do not keep the process alive. */
|
|
109
|
+
close(): void;
|
|
110
|
+
private headersFor;
|
|
111
|
+
private encodeBody;
|
|
112
|
+
private hint;
|
|
113
|
+
/** Sends one operation with retries. Resolves with a 2xx (or 101) response whose body is still unread. */
|
|
114
|
+
private send;
|
|
115
|
+
private readBody;
|
|
116
|
+
private exec;
|
|
117
|
+
/** @internal One request, parsed by content type. */
|
|
118
|
+
_call<T>(op: Op, args: CallArgs, options?: RequestOptions, accept?: string, expect?: "json" | "bytes" | "text" | "auto"): APIPromise<T>;
|
|
119
|
+
/** @internal A list operation (cursor pagination). */
|
|
120
|
+
_list<P extends ListPage<I>, I>(op: Op, args: CallArgs, options?: RequestOptions): ListPromise<P, I>;
|
|
121
|
+
/** @internal A GET event stream (job events, logs), resumed with Last-Event-ID. */
|
|
122
|
+
_stream<E>(op: Op, args: CallArgs, options?: StreamOptions, behavior?: {
|
|
123
|
+
terminal?: (ev: E) => boolean;
|
|
124
|
+
reconnectOnEnd?: boolean;
|
|
125
|
+
}): EventStream<E>;
|
|
126
|
+
private streamOptions;
|
|
127
|
+
private expectEventStream;
|
|
128
|
+
/** @internal An SSE response to a POST (exec output, chat chunks): not resumable. */
|
|
129
|
+
_postStream<E>(op: Op, args: CallArgs, options?: StreamOptions, behavior?: {
|
|
130
|
+
terminal?: (ev: E) => boolean;
|
|
131
|
+
doneSentinel?: boolean;
|
|
132
|
+
extraQuery?: Record<string, string>;
|
|
133
|
+
}): EventStream<E>;
|
|
134
|
+
/** @internal A job-creating operation (`x-b3os-job`). */
|
|
135
|
+
_job<J extends JobLike, E>(op: Op, args: CallArgs, options?: RequestOptions): JobPromise<J, E>;
|
|
136
|
+
private createStream;
|
|
137
|
+
private finalJobFromEvent;
|
|
138
|
+
private jobEventStream;
|
|
139
|
+
private finishJob;
|
|
140
|
+
/** @internal Waits until a job is terminal: its event stream first, polling as the fallback. */
|
|
141
|
+
waitJob<J, E>(ops: JobOps, jobOrId: J | string, w?: WaitOptions<E>): Promise<J>;
|
|
142
|
+
/** @internal Events of an existing job. */
|
|
143
|
+
_jobEvents<J extends JobLike, E>(ops: JobOps, job: J | string, so?: JobEventsOptions): JobEventStream<E, J>;
|
|
144
|
+
/** @internal Raw send for helpers that need the response (WebSocket tickets, downloads). */
|
|
145
|
+
_send(op: Op, args: CallArgs, options: RequestOptions, accept: string): Promise<Sent>;
|
|
146
|
+
/** @internal The route an operation would use (helpers that open WebSockets need the base URL). */
|
|
147
|
+
_routeFor(op: Op): {
|
|
148
|
+
base: string;
|
|
149
|
+
kind: Route["kind"];
|
|
150
|
+
auth: boolean;
|
|
151
|
+
};
|
|
152
|
+
/** @internal Whether a WebSocket can take the operation's route (not over the Unix socket). */
|
|
153
|
+
_wsRoute(op: Op): {
|
|
154
|
+
base: string;
|
|
155
|
+
kind: Route["kind"];
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Calls any operation by method and path, for endpoints the namespaces do not wrap (device login) or newer than
|
|
159
|
+
* this SDK. Account paths (`/v1/keys`, `/v1/auth`, …) go to the edge unless `edge` says otherwise.
|
|
160
|
+
*/
|
|
161
|
+
request<T = unknown>(req: RawRequest, options?: RequestOptions): APIPromise<T>;
|
|
162
|
+
/** @internal SSE parse helper for namespaces. */
|
|
163
|
+
static parseJsonEvent<E>(msg: SSEMessage): E;
|
|
164
|
+
}
|
|
165
|
+
export {};
|