@b3os/sdk 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/cjs/core/sse.d.ts +2 -0
  2. package/dist/cjs/core/sse.js +17 -5
  3. package/dist/cjs/core/sse.js.map +1 -1
  4. package/dist/cjs/core/util.d.ts +1 -1
  5. package/dist/cjs/core/util.js +1 -1
  6. package/dist/cjs/generated/client.d.ts +13 -0
  7. package/dist/cjs/generated/client.js +25 -0
  8. package/dist/cjs/generated/client.js.map +1 -1
  9. package/dist/cjs/generated/errors.d.ts +1 -1
  10. package/dist/cjs/generated/errors.js +95 -0
  11. package/dist/cjs/generated/errors.js.map +1 -1
  12. package/dist/cjs/generated/ids.d.ts +61 -0
  13. package/dist/cjs/generated/ids.js +15 -0
  14. package/dist/cjs/generated/ids.js.map +1 -1
  15. package/dist/cjs/generated/jobs.js +4 -0
  16. package/dist/cjs/generated/jobs.js.map +1 -1
  17. package/dist/cjs/generated/ns/actions.d.ts +303 -4
  18. package/dist/cjs/generated/ns/actions.js +446 -4
  19. package/dist/cjs/generated/ns/actions.js.map +1 -1
  20. package/dist/cjs/generated/ns/agents.d.ts +229 -0
  21. package/dist/cjs/generated/ns/agents.js +402 -0
  22. package/dist/cjs/generated/ns/agents.js.map +1 -0
  23. package/dist/cjs/generated/ns/images.d.ts +81 -0
  24. package/dist/cjs/generated/ns/images.js +122 -0
  25. package/dist/cjs/generated/ns/images.js.map +1 -0
  26. package/dist/cjs/generated/ns/infer.d.ts +71 -3
  27. package/dist/cjs/generated/ns/infer.js +98 -3
  28. package/dist/cjs/generated/ns/infer.js.map +1 -1
  29. package/dist/cjs/generated/ns/keys.d.ts +3 -1
  30. package/dist/cjs/generated/ns/keys.js +3 -1
  31. package/dist/cjs/generated/ns/keys.js.map +1 -1
  32. package/dist/cjs/generated/ns/listeners.d.ts +159 -0
  33. package/dist/cjs/generated/ns/listeners.js +264 -0
  34. package/dist/cjs/generated/ns/listeners.js.map +1 -0
  35. package/dist/cjs/generated/ns/orgs.d.ts +10 -0
  36. package/dist/cjs/generated/ns/orgs.js +26 -1
  37. package/dist/cjs/generated/ns/orgs.js.map +1 -1
  38. package/dist/cjs/generated/ns/projects.d.ts +32 -0
  39. package/dist/cjs/generated/ns/projects.js +66 -0
  40. package/dist/cjs/generated/ns/projects.js.map +1 -1
  41. package/dist/cjs/generated/ns/render.d.ts +192 -21
  42. package/dist/cjs/generated/ns/render.js +267 -24
  43. package/dist/cjs/generated/ns/render.js.map +1 -1
  44. package/dist/cjs/generated/ns/requests.d.ts +3 -1
  45. package/dist/cjs/generated/ns/requests.js +3 -1
  46. package/dist/cjs/generated/ns/requests.js.map +1 -1
  47. package/dist/cjs/generated/ns/routines.d.ts +11 -4
  48. package/dist/cjs/generated/ns/routines.js +11 -4
  49. package/dist/cjs/generated/ns/routines.js.map +1 -1
  50. package/dist/cjs/generated/ns/sandboxes.d.ts +292 -7
  51. package/dist/cjs/generated/ns/sandboxes.js +444 -6
  52. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  53. package/dist/cjs/generated/ns/usage.d.ts +1 -1
  54. package/dist/cjs/generated/ns/usage.js +1 -1
  55. package/dist/cjs/generated/ns/vision.d.ts +59 -17
  56. package/dist/cjs/generated/ns/vision.js +59 -21
  57. package/dist/cjs/generated/ns/vision.js.map +1 -1
  58. package/dist/cjs/generated/types.d.ts +2787 -85
  59. package/dist/cjs/helpers/sandboxes.d.ts +46 -3
  60. package/dist/cjs/helpers/sandboxes.js +127 -14
  61. package/dist/cjs/helpers/sandboxes.js.map +1 -1
  62. package/dist/cjs/index.d.ts +1 -1
  63. package/dist/cjs/index.js +2 -1
  64. package/dist/cjs/index.js.map +1 -1
  65. package/dist/esm/core/sse.d.ts +2 -0
  66. package/dist/esm/core/sse.js +17 -5
  67. package/dist/esm/core/sse.js.map +1 -1
  68. package/dist/esm/core/util.d.ts +1 -1
  69. package/dist/esm/core/util.js +1 -1
  70. package/dist/esm/generated/client.d.ts +13 -0
  71. package/dist/esm/generated/client.js +25 -0
  72. package/dist/esm/generated/client.js.map +1 -1
  73. package/dist/esm/generated/errors.d.ts +1 -1
  74. package/dist/esm/generated/errors.js +95 -0
  75. package/dist/esm/generated/errors.js.map +1 -1
  76. package/dist/esm/generated/ids.d.ts +61 -0
  77. package/dist/esm/generated/ids.js +15 -0
  78. package/dist/esm/generated/ids.js.map +1 -1
  79. package/dist/esm/generated/jobs.js +4 -0
  80. package/dist/esm/generated/jobs.js.map +1 -1
  81. package/dist/esm/generated/ns/actions.d.ts +303 -4
  82. package/dist/esm/generated/ns/actions.js +446 -4
  83. package/dist/esm/generated/ns/actions.js.map +1 -1
  84. package/dist/esm/generated/ns/agents.d.ts +229 -0
  85. package/dist/esm/generated/ns/agents.js +398 -0
  86. package/dist/esm/generated/ns/agents.js.map +1 -0
  87. package/dist/esm/generated/ns/images.d.ts +81 -0
  88. package/dist/esm/generated/ns/images.js +118 -0
  89. package/dist/esm/generated/ns/images.js.map +1 -0
  90. package/dist/esm/generated/ns/infer.d.ts +71 -3
  91. package/dist/esm/generated/ns/infer.js +98 -3
  92. package/dist/esm/generated/ns/infer.js.map +1 -1
  93. package/dist/esm/generated/ns/keys.d.ts +3 -1
  94. package/dist/esm/generated/ns/keys.js +3 -1
  95. package/dist/esm/generated/ns/keys.js.map +1 -1
  96. package/dist/esm/generated/ns/listeners.d.ts +159 -0
  97. package/dist/esm/generated/ns/listeners.js +260 -0
  98. package/dist/esm/generated/ns/listeners.js.map +1 -0
  99. package/dist/esm/generated/ns/orgs.d.ts +10 -0
  100. package/dist/esm/generated/ns/orgs.js +26 -1
  101. package/dist/esm/generated/ns/orgs.js.map +1 -1
  102. package/dist/esm/generated/ns/projects.d.ts +32 -0
  103. package/dist/esm/generated/ns/projects.js +66 -0
  104. package/dist/esm/generated/ns/projects.js.map +1 -1
  105. package/dist/esm/generated/ns/render.d.ts +192 -21
  106. package/dist/esm/generated/ns/render.js +267 -24
  107. package/dist/esm/generated/ns/render.js.map +1 -1
  108. package/dist/esm/generated/ns/requests.d.ts +3 -1
  109. package/dist/esm/generated/ns/requests.js +3 -1
  110. package/dist/esm/generated/ns/requests.js.map +1 -1
  111. package/dist/esm/generated/ns/routines.d.ts +11 -4
  112. package/dist/esm/generated/ns/routines.js +11 -4
  113. package/dist/esm/generated/ns/routines.js.map +1 -1
  114. package/dist/esm/generated/ns/sandboxes.d.ts +292 -7
  115. package/dist/esm/generated/ns/sandboxes.js +444 -6
  116. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  117. package/dist/esm/generated/ns/usage.d.ts +1 -1
  118. package/dist/esm/generated/ns/usage.js +1 -1
  119. package/dist/esm/generated/ns/vision.d.ts +59 -17
  120. package/dist/esm/generated/ns/vision.js +59 -21
  121. package/dist/esm/generated/ns/vision.js.map +1 -1
  122. package/dist/esm/generated/types.d.ts +2787 -85
  123. package/dist/esm/helpers/sandboxes.d.ts +46 -3
  124. package/dist/esm/helpers/sandboxes.js +126 -13
  125. package/dist/esm/helpers/sandboxes.js.map +1 -1
  126. package/dist/esm/index.d.ts +1 -1
  127. package/dist/esm/index.js +1 -1
  128. package/dist/esm/index.js.map +1 -1
  129. package/package.json +1 -1
  130. package/src/core/sse.ts +17 -5
  131. package/src/core/util.ts +1 -1
  132. package/src/generated/client.ts +28 -0
  133. package/src/generated/errors.ts +190 -0
  134. package/src/generated/ids.ts +15 -0
  135. package/src/generated/jobs.ts +4 -0
  136. package/src/generated/ns/actions.ts +483 -4
  137. package/src/generated/ns/agents.ts +461 -0
  138. package/src/generated/ns/images.ts +128 -0
  139. package/src/generated/ns/infer.ts +100 -3
  140. package/src/generated/ns/keys.ts +3 -1
  141. package/src/generated/ns/listeners.ts +296 -0
  142. package/src/generated/ns/orgs.ts +27 -1
  143. package/src/generated/ns/projects.ts +74 -0
  144. package/src/generated/ns/render.ts +277 -24
  145. package/src/generated/ns/requests.ts +3 -1
  146. package/src/generated/ns/routines.ts +11 -4
  147. package/src/generated/ns/sandboxes.ts +492 -7
  148. package/src/generated/ns/usage.ts +1 -1
  149. package/src/generated/ns/vision.ts +59 -21
  150. package/src/generated/types.ts +3511 -575
  151. package/src/helpers/sandboxes.ts +167 -14
  152. package/src/index.ts +1 -0
@@ -29,6 +29,7 @@ const createChatCompletionOp: Op = {
29
29
  id: "inferCreateChatCompletion",
30
30
  method: "POST",
31
31
  path: "/v1/infer/chat/completions",
32
+ headerParams: { capture_content: "X-B3OS-Capture-Content", replay_of: "X-B3OS-Replay-Of" },
32
33
  body: "json",
33
34
  stream: "sse",
34
35
  timeoutMs: 600000,
@@ -63,10 +64,21 @@ const getModelOp: Op = {
63
64
  errorFormat: "openai",
64
65
  scope: "infer:read",
65
66
  };
67
+ const createRerankOp: Op = {
68
+ id: "inferCreateRerank",
69
+ method: "POST",
70
+ path: "/v1/infer/rerank",
71
+ body: "json",
72
+ timeoutMs: 65000,
73
+ errorFormat: "openai",
74
+ stretch: true,
75
+ scope: "infer:run",
76
+ };
66
77
  const createResponseOp: Op = {
67
78
  id: "inferCreateResponse",
68
79
  method: "POST",
69
80
  path: "/v1/infer/responses",
81
+ headerParams: { capture_content: "X-B3OS-Capture-Content", replay_of: "X-B3OS-Replay-Of" },
70
82
  body: "json",
71
83
  stream: "sse",
72
84
  timeoutMs: 600000,
@@ -77,6 +89,7 @@ const createMessageOp: Op = {
77
89
  id: "inferCreateMessage",
78
90
  method: "POST",
79
91
  path: "/v1/infer/v1/messages",
92
+ headerParams: { capture_content: "X-B3OS-Capture-Content", replay_of: "X-B3OS-Replay-Of" },
80
93
  body: "json",
81
94
  stream: "sse",
82
95
  timeoutMs: 600000,
@@ -92,6 +105,16 @@ const countMessageTokensOp: Op = {
92
105
  errorFormat: "anthropic",
93
106
  scope: "infer:run",
94
107
  };
108
+ const createRerankV2Op: Op = {
109
+ id: "inferCreateRerankV2",
110
+ method: "POST",
111
+ path: "/v1/infer/v2/rerank",
112
+ body: "json",
113
+ timeoutMs: 65000,
114
+ errorFormat: "openai",
115
+ stretch: true,
116
+ scope: "infer:run",
117
+ };
95
118
 
96
119
  /** Descriptors of every infer operation, keyed by method name (for tooling and custom clients). */
97
120
  export const inferOps = {
@@ -101,9 +124,11 @@ export const inferOps = {
101
124
  createEmbeddings: createEmbeddingsOp,
102
125
  listModels: listModelsOp,
103
126
  getModel: getModelOp,
127
+ createRerank: createRerankOp,
104
128
  createResponse: createResponseOp,
105
129
  createMessage: createMessageOp,
106
130
  countMessageTokens: countMessageTokensOp,
131
+ createRerankV2: createRerankV2Op,
107
132
  } as const;
108
133
 
109
134
  /** Models on the node: OpenAI-compatible chat, embeddings and speech (`/v1/infer`). */
@@ -273,8 +298,33 @@ export class InferAPI extends Namespace {
273
298
  /**
274
299
  * Create embeddings
275
300
  *
276
- * The OpenAI Embeddings API, for embedding models the node serves (`b3os.kind` is `embedding`). Other models
277
- * return `404 model_not_available`; the beta node serves no embedding model yet. Bills input tokens.
301
+ * The OpenAI Embeddings API, for embedding models the node serves (`b3os.kind` is `embedding` in
302
+ * `GET /v1/infer/models`). Other models return `404 model_not_available`; the beta node serves no embedding
303
+ * model yet. An embedding model has no alias: name its own ID, so stored vectors always come from the model
304
+ * that made them.
305
+ *
306
+ * `input` is a string or 1 to 2,048 strings, none of them empty (`400 invalid_request` pointing at it). Arrays
307
+ * of token IDs are `400 unsupported_parameter`: the node reads text only, and token IDs from another tokenizer
308
+ * would give wrong vectors (LangChain's `OpenAIEmbeddings` sends them unless it is created with
309
+ * `check_embedding_ctx_length=False`). An input may have as many tokens as the model's `context_length`,
310
+ * query prompt included; a longer one is `400 context_length_exceeded` pointing at it, unless `truncate` is
311
+ * `end`, which cuts it at the end to fit.
312
+ *
313
+ * `encoding_format` is `float` (the default) or `base64` (little-endian float32, what the OpenAI SDKs ask for
314
+ * by default); both carry the same numbers. Every vector has length 1. `dimensions` shortens the vectors, from
315
+ * the model's `b3os.min_dimensions` to its `b3os.dimensions` values (`400 unsupported_parameter` outside it):
316
+ * the node cuts each vector and scales it back to length 1. `user` is accepted and ignored.
317
+ *
318
+ * B3OS extensions: `input_type: "query"` puts the model's query prompt before each input, for text you search
319
+ * with (`document`, the default, embeds the input as it is), and `instruction` replaces the task the prompt
320
+ * describes (with `input_type: "query"` only, at most 512 characters). The prompt's tokens are billed with the
321
+ * input. The node sends a large request to the model in parts of at most 8,192 tokens and answers in input
322
+ * order.
323
+ *
324
+ * Bills `infer.embed_tokens`, the tokens the model read; a request that fails is not billed. Requests are
325
+ * admitted against your organization's per-minute token and request limits on the model, and against 8
326
+ * embedding and rerank requests in flight per organization (`429 concurrency_limited`, limit
327
+ * `infer.pool.concurrent`). Embeddings are never kept by the model call log. No streaming.
278
328
  *
279
329
  * `POST /v1/infer/embeddings` · scope `infer:run` · served by the node
280
330
  *
@@ -291,7 +341,8 @@ export class InferAPI extends Namespace {
291
341
  * quantization, whether it supports tools, JSON Schema output and image input, the largest accepted request,
292
342
  * and your per-model token and request limits. Chat models are listed while the node's model runtime is
293
343
  * configured (one that is restarting is still listed; requests get `503` with `Retry-After`); speech models
294
- * while the voice service answers.
344
+ * while the voice service answers. Embedding and rerank models, where a node serves them, are listed the same
345
+ * way, each with its own engine.
295
346
  *
296
347
  * `GET /v1/infer/models` · scope `infer:read` · served by the node
297
348
  */
@@ -310,6 +361,37 @@ export class InferAPI extends Namespace {
310
361
  return this._client._call<T.Model>(getModelOp, { path: [model] }, options);
311
362
  }
312
363
 
364
+ /**
365
+ * Rerank documents
366
+ *
367
+ * Ranks documents by how well they answer a query, in the shape of Cohere's v2 rerank API, for rerank models
368
+ * the node serves (`b3os.kind` is `rerank` in `GET /v1/infer/models`). Other models return
369
+ * `404 model_not_available`; the beta node serves no rerank model yet. The same operation answers at
370
+ * `POST /v1/infer/v2/rerank`, so Cohere's SDK works with its base URL set to
371
+ * `https://beta-api.b3os.org/v1/infer`.
372
+ *
373
+ * `documents` holds 1 to 1,000 strings or `{text}` objects, none of them empty. `query` may have 2,048 tokens
374
+ * (`400 context_length_exceeded` past it). Each document is cut at the end to `max_tokens_per_doc` tokens
375
+ * (default 4,096, at most 8,000), and further where the query and the document together would pass the
376
+ * model's `context_length`. `results` lists the `top_n` best documents (default: all of them), highest
377
+ * `relevance_score` (0 to 1) first, each with its `index` in `documents`; with `return_documents: true` each
378
+ * also carries its document as sent. B3OS extension: `instruction` replaces the task the model's query prompt
379
+ * describes (at most 512 characters). The node sends a large request to the model in parts of at most 8,192
380
+ * tokens.
381
+ *
382
+ * Bills `infer.rerank_tokens`, the tokens of every query and document pair the model read
383
+ * (`usage.total_tokens`, also in `meta.billed_units.input_tokens`); a request that fails is not billed. Limits
384
+ * as for embeddings: per-minute tokens and requests on the model, and 8 embedding and rerank requests in
385
+ * flight per organization. Rerank calls are never kept by the model call log. No streaming.
386
+ *
387
+ * `POST /v1/infer/rerank` · scope `infer:run` · served by the node
388
+ *
389
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
390
+ */
391
+ createRerank(body: T.RerankRequest, options?: RequestOptions): APIPromise<T.RerankList> {
392
+ return this._client._call<T.RerankList>(createRerankOp, { body }, options);
393
+ }
394
+
313
395
  /**
314
396
  * Create a response (OpenAI Responses API)
315
397
  *
@@ -497,4 +579,19 @@ export class InferAPI extends Namespace {
497
579
  ): APIPromise<T.AnthropicCountTokens> {
498
580
  return this._client._call<T.AnthropicCountTokens>(countMessageTokensOp, { body }, options);
499
581
  }
582
+
583
+ /**
584
+ * Rerank documents at Cohere's path
585
+ *
586
+ * `POST /v1/infer/rerank` at the path Cohere's v2 SDK calls (`<base URL>/v2/rerank`), so
587
+ * `cohere.ClientV2(base_url="https://beta-api.b3os.org/v1/infer")` works unchanged. The request, the answer,
588
+ * the limits and the meter are those of `POST /v1/infer/rerank`.
589
+ *
590
+ * `POST /v1/infer/v2/rerank` · scope `infer:run` · served by the node
591
+ *
592
+ * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
593
+ */
594
+ createRerankV2(body: T.RerankRequest, options?: RequestOptions): APIPromise<T.RerankList> {
595
+ return this._client._call<T.RerankList>(createRerankV2Op, { body }, options);
596
+ }
500
597
  }
@@ -99,7 +99,9 @@ export class KeysAPI extends Namespace {
99
99
  *
100
100
  * Creates a key in your project (or `project`, in the same organization). `scopes` and `spend_cap_usd` may not
101
101
  * exceed the caller's own, and when the caller expires, `expires_at` must be set and no later than the caller's
102
- * expiry (`forbidden`, reason `scope_escalation`). The response is the only time `secret` is returned.
102
+ * expiry (`forbidden`, reason `scope_escalation`). The response is the only time `secret` is returned. An
103
+ * organization holds at most `platform.keys.max` active API keys (1,000 in the beta; revoked and expired ones are
104
+ * not counted, nor CLI tokens); a create past it is 422 `limit_exceeded`.
103
105
  *
104
106
  * `POST /v1/keys` · scope `platform:write` · served by beta-api.b3os.org
105
107
  */
@@ -0,0 +1,296 @@
1
+ // Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
2
+
3
+ import type { RequestOptions, StreamOptions } from "../../core/client.ts";
4
+ import { Namespace } from "../../core/namespace.ts";
5
+ import type { Op } from "../../core/op.ts";
6
+ import type { APIPromise, ListPromise } from "../../core/promise.ts";
7
+ import type { EventStream } from "../../core/sse.ts";
8
+ import type * as T from "../types.ts";
9
+
10
+ const listListenersOp: Op = {
11
+ id: "listenersListListeners",
12
+ method: "GET",
13
+ path: "/v1/listeners",
14
+ timeoutMs: 10000,
15
+ scope: "listeners:read",
16
+ };
17
+ const createListenerOp: Op = {
18
+ id: "listenersCreateListener",
19
+ method: "POST",
20
+ path: "/v1/listeners",
21
+ body: "json",
22
+ idem: true,
23
+ timeoutMs: 15000,
24
+ scope: "listeners:write",
25
+ };
26
+ const deleteListenerOp: Op = {
27
+ id: "listenersDeleteListener",
28
+ method: "DELETE",
29
+ path: "/v1/listeners/{listener_id}",
30
+ params: ["listener_id"],
31
+ timeoutMs: 10000,
32
+ scope: "listeners:write",
33
+ };
34
+ const getListenerOp: Op = {
35
+ id: "listenersGetListener",
36
+ method: "GET",
37
+ path: "/v1/listeners/{listener_id}",
38
+ params: ["listener_id"],
39
+ timeoutMs: 10000,
40
+ scope: "listeners:read",
41
+ };
42
+ const updateListenerOp: Op = {
43
+ id: "listenersUpdateListener",
44
+ method: "PATCH",
45
+ path: "/v1/listeners/{listener_id}",
46
+ params: ["listener_id"],
47
+ body: "json",
48
+ timeoutMs: 10000,
49
+ scope: "listeners:write",
50
+ };
51
+ const listEventsOp: Op = {
52
+ id: "listenersListEvents",
53
+ method: "GET",
54
+ path: "/v1/listeners/{listener_id}/events",
55
+ params: ["listener_id"],
56
+ timeoutMs: 10000,
57
+ scope: "listeners:read",
58
+ };
59
+ const ingestEventsOp: Op = {
60
+ id: "listenersIngestEvents",
61
+ method: "POST",
62
+ path: "/v1/listeners/{listener_id}/events",
63
+ params: ["listener_id"],
64
+ body: "json",
65
+ timeoutMs: 10000,
66
+ scope: "listeners:write",
67
+ };
68
+ const redeliverEventOp: Op = {
69
+ id: "listenersRedeliverEvent",
70
+ method: "POST",
71
+ path: "/v1/listeners/{listener_id}/events/{event_id}/redeliver",
72
+ params: ["listener_id", "event_id"],
73
+ timeoutMs: 10000,
74
+ scope: "listeners:write",
75
+ };
76
+ const streamEventsOp: Op = {
77
+ id: "listenersStreamEvents",
78
+ method: "GET",
79
+ path: "/v1/listeners/{listener_id}/stream",
80
+ params: ["listener_id"],
81
+ stream: "sse",
82
+ timeoutMs: 3600000,
83
+ scope: "listeners:read",
84
+ };
85
+ const testListenerOp: Op = {
86
+ id: "listenersTestListener",
87
+ method: "POST",
88
+ path: "/v1/listeners/{listener_id}/test",
89
+ params: ["listener_id"],
90
+ body: "json",
91
+ timeoutMs: 10000,
92
+ scope: "listeners:write",
93
+ };
94
+
95
+ /** Descriptors of every listeners operation, keyed by method name (for tooling and custom clients). */
96
+ export const listenersOps = {
97
+ listListeners: listListenersOp,
98
+ createListener: createListenerOp,
99
+ deleteListener: deleteListenerOp,
100
+ getListener: getListenerOp,
101
+ updateListener: updateListenerOp,
102
+ listEvents: listEventsOp,
103
+ ingestEvents: ingestEventsOp,
104
+ redeliverEvent: redeliverEventOp,
105
+ streamEvents: streamEventsOp,
106
+ testListener: testListenerOp,
107
+ } as const;
108
+
109
+ /**
110
+ * Persistent subscriptions: a polled, streamed or pushed source, a CEL filter and a routine or webhook sink (`/v1/listeners`).
111
+ */
112
+ export class ListenersAPI extends Namespace {
113
+ /**
114
+ * List listeners
115
+ *
116
+ * Lists this project's listeners, newest first, in every status. Deleted listeners are not listed.
117
+ *
118
+ * `GET /v1/listeners` · scope `listeners:read` · served by the node
119
+ */
120
+ listListeners(
121
+ params?: T.ListenersListListenersParams,
122
+ options?: RequestOptions,
123
+ ): ListPromise<T.ListenerList, T.Listener> {
124
+ return this._client._list<T.ListenerList, T.Listener>(listListenersOp, { query: params }, options);
125
+ }
126
+
127
+ /**
128
+ * Create a listener
129
+ *
130
+ * Validates the definition, compiles its CEL expressions and starts the source; the answer is `201` with the
131
+ * listener in status `starting`, and `active` follows once the first connect or poll succeeds. A source that
132
+ * cannot be reached does not fail the create: the listener goes `reconnecting` and retries with backoff, and
133
+ * after 24 hours of failures it ends `failed` with the reason in `error`.
134
+ *
135
+ * The routine named in a `routine` sink must exist in this project and needs `routines:run` on top of
136
+ * `listeners:write`; a `source.connection` needs `vault:run`, and the URL's host must be one of the
137
+ * connection's `hosts` (otherwise `422 listener_invalid`, reason `connection_host`). Without `ttl_s` or
138
+ * `expires_at` the listener lives until it is deleted. Without `budget.events_per_day` it gets the
139
+ * organization's share, `listeners.events.daily` divided by `listeners.active.max`; the object always shows the
140
+ * budget in force.
141
+ *
142
+ * A `filter.model` asks the small model one question about each event CEL kept, as the listener's owner, so it
143
+ * needs `infer:run` and bills infer tokens, within `budget.model_tokens_per_day`. The question is the system
144
+ * message and the event its own delimited user message; no tools are offered and the answer is parsed strictly.
145
+ * An event's content can still try to steer the model: at worst it makes the answer `true` for that event,
146
+ * which `budget.events_per_day` and `budget.model_tokens_per_day` bound, so do not rely on the model filter
147
+ * alone to keep untrusted events from a sink that acts on them. When the model cannot answer (an error, a
148
+ * timeout, output that does not parse, the token budget spent), `on_error` decides (`drop` by default, or
149
+ * `pass`), and the event's `filter.model` says what happened.
150
+ *
151
+ * A `pack` source is checked by the actions trigger manager at create (the trigger exists, `with` is valid,
152
+ * its connections are usable) and is held there as a trigger subscription the listener owns; it is removed
153
+ * when the listener is paused, deleted or ends.
154
+ *
155
+ * A `webhook` source's listener is `active` at once, and its answer carries `source.hook_id` and
156
+ * `source.hook_url` to give the provider; with the `b3os` scheme it also carries `source.secret`, which no
157
+ * later answer shows. A `verify.secret` connection needs `vault:run`. A `websocket` source is held by the
158
+ * node's socket holder; while that unit is down the listener stays `starting` or `reconnecting`.
159
+ *
160
+ * The listener belongs to the creating key (`owner.kind: key`): when that key is revoked or expires the
161
+ * listener ends `revoked`. One created from a sandbox belongs to the key that created the sandbox and also
162
+ * ends when the sandbox's root sandbox ends.
163
+ *
164
+ * `POST /v1/listeners` · scope `listeners:write` · served by the node
165
+ */
166
+ createListener(body: T.ListenerCreateRequest, options?: RequestOptions): APIPromise<T.Listener> {
167
+ return this._client._call<T.Listener>(createListenerOp, { body }, options);
168
+ }
169
+
170
+ /**
171
+ * Delete a listener
172
+ *
173
+ * Closes the source and stops delivery at once; an event already handed to its sink is not recalled. The
174
+ * event history stays readable for its 7 days through `GET /v1/listeners/{listener_id}/events` and is then
175
+ * deleted.
176
+ *
177
+ * `DELETE /v1/listeners/{listener_id}` · scope `listeners:write` · served by the node
178
+ */
179
+ deleteListener(listenerId: string, options?: RequestOptions): APIPromise<T.Deleted> {
180
+ return this._client._call<T.Deleted>(deleteListenerOp, { path: [listenerId] }, options);
181
+ }
182
+
183
+ /**
184
+ * Get a listener
185
+ *
186
+ * Returns one of this project's listeners: its status, the source's state (cursor, connected since, next
187
+ * attempt), the budget in force and what it used today (UTC), and its counters.
188
+ *
189
+ * `GET /v1/listeners/{listener_id}` · scope `listeners:read` · served by the node
190
+ */
191
+ getListener(listenerId: string, options?: RequestOptions): APIPromise<T.Listener> {
192
+ return this._client._call<T.Listener>(getListenerOp, { path: [listenerId] }, options);
193
+ }
194
+
195
+ /**
196
+ * Change, pause or resume a listener
197
+ *
198
+ * Changes the lifetime (`ttl_s` counts from now; `expires_at: null` removes it), the filter, the sink, the
199
+ * budget, `redact` and `metadata`. `paused: true` closes the source and stops delivery, keeping the cursor;
200
+ * `false` opens it again where it stopped. A listener paused by its budget resumes by itself when the UTC day
201
+ * ends, or now if the PATCH raises the budget above what it used. The source cannot change: create a new
202
+ * listener. A new filter or `redact` applies to events received after the answer. A listener that ended
203
+ * (`failed`, `expired`, `revoked`) answers `409 listener_not_active`, except that a `failed` one can be
204
+ * resumed with `paused: false`, which starts its source again.
205
+ *
206
+ * `PATCH /v1/listeners/{listener_id}` · scope `listeners:write` · served by the node
207
+ */
208
+ updateListener(listenerId: string, body: T.ListenerUpdateRequest, options?: RequestOptions): APIPromise<T.Listener> {
209
+ return this._client._call<T.Listener>(updateListenerOp, { path: [listenerId], body }, options);
210
+ }
211
+
212
+ /**
213
+ * List a listener's events
214
+ *
215
+ * The listener's history, newest first: every event it kept (duplicates within the dedupe window are only
216
+ * counted, in `stats.duplicates`) with its payload, the filter's verdict, its status and its delivery, and a
217
+ * `gap` record for each time the source was down with events possibly missed. Kept 7 days. Payloads larger
218
+ * than 64 KiB are cut to their first 64 KiB with `payload_truncated: true`. Values at the listener's `redact`
219
+ * paths read `"[redacted]"`.
220
+ *
221
+ * `GET /v1/listeners/{listener_id}/events` · scope `listeners:read` · served by the node
222
+ */
223
+ listEvents(
224
+ listenerId: string,
225
+ params?: T.ListenersListEventsParams,
226
+ options?: RequestOptions,
227
+ ): ListPromise<T.ListenerEventList, T.ListenerEvent> {
228
+ return this._client._list<T.ListenerEventList, T.ListenerEvent>(
229
+ listEventsOp,
230
+ { path: [listenerId], query: params },
231
+ options,
232
+ );
233
+ }
234
+
235
+ /**
236
+ * Send events to a push listener
237
+ *
238
+ * Sends up to 100 events to a listener whose source is `push`. Each goes through dedupe (its `dedupe_key`, or
239
+ * the listener's `dedupe.key` expression, or a hash of the payload), the filter and the sink, as an event from
240
+ * any other source would. The answer comes once every event is in the listener's log (`202`); delivery
241
+ * follows. A listener of another source type answers `409 listener_wrong_source`; one that is not active,
242
+ * `409 listener_not_active`; one whose backlog is full, `429 listener_backlog_full` with `Retry-After`.
243
+ * Code in a sandbox calls it at `B3OS_API_URL` when its grant holds `listeners:write`.
244
+ *
245
+ * `POST /v1/listeners/{listener_id}/events` · scope `listeners:write` · served by the node
246
+ */
247
+ ingestEvents(
248
+ listenerId: string,
249
+ body: T.ListenerIngestRequest,
250
+ options?: RequestOptions,
251
+ ): APIPromise<T.ListenerIngestResult> {
252
+ return this._client._call<T.ListenerIngestResult>(ingestEventsOp, { path: [listenerId], body }, options);
253
+ }
254
+
255
+ /**
256
+ * Deliver an event again
257
+ *
258
+ * Hands a kept event (`delivered` or `failed`) to the sink again, with the same `dedupe_key`, so a sink that
259
+ * already has it can drop it. The filter does not run again. The answer is the event, `pending`.
260
+ *
261
+ * `POST /v1/listeners/{listener_id}/events/{event_id}/redeliver` · scope `listeners:write` · served by the node
262
+ */
263
+ redeliverEvent(listenerId: string, eventId: string, options?: RequestOptions): APIPromise<T.ListenerEvent> {
264
+ return this._client._call<T.ListenerEvent>(redeliverEventOp, { path: [listenerId, eventId] }, options);
265
+ }
266
+
267
+ /**
268
+ * Stream a listener's events
269
+ *
270
+ * Server-sent events as the listener keeps events, records gaps and changes status. Reconnect with
271
+ * `Last-Event-ID` (the `seq` of the last frame you read) to resume: frames still in the 7-day history are sent
272
+ * again from there. `: ping` every 15 seconds.
273
+ *
274
+ * `GET /v1/listeners/{listener_id}/stream` · scope `listeners:read` · served by the node
275
+ */
276
+ streamEvents(listenerId: string, options?: StreamOptions): EventStream<T.ListenerStreamFrame> {
277
+ return this._client._stream<T.ListenerStreamFrame>(streamEventsOp, { path: [listenerId] }, options, {});
278
+ }
279
+
280
+ /**
281
+ * Test a listener on a sample event
282
+ *
283
+ * Runs a sample payload through the listener's dedupe key and filter and returns what happened, without
284
+ * touching the dedupe window or the history. With `deliver: true` the sample, if the filter keeps it, is also
285
+ * written to the log and delivered like any event, marked `test: true` in the sink's copy.
286
+ *
287
+ * `POST /v1/listeners/{listener_id}/test` · scope `listeners:write` · served by the node
288
+ */
289
+ testListener(
290
+ listenerId: string,
291
+ body: T.ListenerTestRequest,
292
+ options?: RequestOptions,
293
+ ): APIPromise<T.ListenerTestResult> {
294
+ return this._client._call<T.ListenerTestResult>(testListenerOp, { path: [listenerId], body }, options);
295
+ }
296
+ }
@@ -32,9 +32,23 @@ const listMembersOp: Op = {
32
32
  timeoutMs: 10000,
33
33
  scope: "platform:read",
34
34
  };
35
+ const getOrgSettingsOp: Op = {
36
+ id: "platformGetOrgSettings",
37
+ method: "GET",
38
+ path: "/v1/orgs/{org_id}/settings",
39
+ params: ["org_id"],
40
+ edge: true,
41
+ timeoutMs: 10000,
42
+ scope: "authenticated",
43
+ };
35
44
 
36
45
  /** Descriptors of every orgs operation, keyed by method name (for tooling and custom clients). */
37
- export const orgsOps = { listOrgs: listOrgsOp, getOrg: getOrgOp, listMembers: listMembersOp } as const;
46
+ export const orgsOps = {
47
+ listOrgs: listOrgsOp,
48
+ getOrg: getOrgOp,
49
+ listMembers: listMembersOp,
50
+ getOrgSettings: getOrgSettingsOp,
51
+ } as const;
38
52
 
39
53
  /** Organizations and members (`/v1/orgs`; served by beta-api.b3os.org). */
40
54
  export class OrgsAPI extends Namespace {
@@ -74,4 +88,16 @@ export class OrgsAPI extends Namespace {
74
88
  ): ListPromise<T.MemberList, T.Member> {
75
89
  return this._client._list<T.MemberList, T.Member>(listMembersOp, { path: [orgId], query: params }, options);
76
90
  }
91
+
92
+ /**
93
+ * List an organization's settings
94
+ *
95
+ * The settings stored for the organization, which apply to every project that sets nothing itself. Members
96
+ * and the organization's keys may read them.
97
+ *
98
+ * `GET /v1/orgs/{org_id}/settings` · scope `authenticated` · served by beta-api.b3os.org
99
+ */
100
+ getOrgSettings(orgId: string, options?: RequestOptions): APIPromise<T.StoredSettingList> {
101
+ return this._client._call<T.StoredSettingList>(getOrgSettingsOp, { path: [orgId] }, options);
102
+ }
77
103
  }
@@ -52,6 +52,34 @@ const updateProjectOp: Op = {
52
52
  timeoutMs: 10000,
53
53
  scope: "platform:write",
54
54
  };
55
+ const getProjectSettingsOp: Op = {
56
+ id: "platformGetProjectSettings",
57
+ method: "GET",
58
+ path: "/v1/projects/{project_id}/settings",
59
+ params: ["project_id"],
60
+ edge: true,
61
+ timeoutMs: 10000,
62
+ scope: "authenticated",
63
+ };
64
+ const unsetProjectSettingOp: Op = {
65
+ id: "platformUnsetProjectSetting",
66
+ method: "DELETE",
67
+ path: "/v1/projects/{project_id}/settings/{option}",
68
+ params: ["project_id", "option"],
69
+ edge: true,
70
+ timeoutMs: 10000,
71
+ scope: "authenticated",
72
+ };
73
+ const setProjectSettingOp: Op = {
74
+ id: "platformSetProjectSetting",
75
+ method: "PUT",
76
+ path: "/v1/projects/{project_id}/settings/{option}",
77
+ params: ["project_id", "option"],
78
+ body: "json",
79
+ edge: true,
80
+ timeoutMs: 10000,
81
+ scope: "authenticated",
82
+ };
55
83
 
56
84
  /** Descriptors of every projects operation, keyed by method name (for tooling and custom clients). */
57
85
  export const projectsOps = {
@@ -60,6 +88,9 @@ export const projectsOps = {
60
88
  deleteProject: deleteProjectOp,
61
89
  getProject: getProjectOp,
62
90
  updateProject: updateProjectOp,
91
+ getProjectSettings: getProjectSettingsOp,
92
+ unsetProjectSetting: unsetProjectSettingOp,
93
+ setProjectSetting: setProjectSettingOp,
63
94
  } as const;
64
95
 
65
96
  /** Projects (`/v1/projects`; served by beta-api.b3os.org). */
@@ -119,4 +150,47 @@ export class ProjectsAPI extends Namespace {
119
150
  updateProject(projectId: string, body: T.ProjectUpdateRequest, options?: RequestOptions): APIPromise<T.Project> {
120
151
  return this._client._call<T.Project>(updateProjectOp, { path: [projectId], body }, options);
121
152
  }
153
+
154
+ /**
155
+ * List a project's settings
156
+ *
157
+ * The settings stored for the project, without inherited values (`GET /v1/settings` resolves those). Any valid
158
+ * credential may read its own project's; another project of the organization needs `platform:read`.
159
+ *
160
+ * `GET /v1/projects/{project_id}/settings` · scope `authenticated` · served by beta-api.b3os.org
161
+ */
162
+ getProjectSettings(projectId: string, options?: RequestOptions): APIPromise<T.StoredSettingList> {
163
+ return this._client._call<T.StoredSettingList>(getProjectSettingsOp, { path: [projectId] }, options);
164
+ }
165
+
166
+ /**
167
+ * Unset a project setting
168
+ *
169
+ * Removes the project's own value, so the organization's or the default applies again. Who may call it is as
170
+ * for setting it. Unsetting an option the project does not set succeeds too.
171
+ *
172
+ * `DELETE /v1/projects/{project_id}/settings/{option}` · scope `authenticated` · served by beta-api.b3os.org
173
+ */
174
+ unsetProjectSetting(projectId: string, option: string, options?: RequestOptions): APIPromise<T.Deleted> {
175
+ return this._client._call<T.Deleted>(unsetProjectSettingOp, { path: [projectId, option] }, options);
176
+ }
177
+
178
+ /**
179
+ * Set a project setting
180
+ *
181
+ * Sets `option` for the project. A credential with `settings:write` sets its own project's; `platform:write`
182
+ * sets any project's in the organization. The value must be one the option serves: an unknown option or a
183
+ * value outside its catalog is `422 invalid_option`, a reserved value `422 option_not_allowed`. Nodes apply
184
+ * it within a few seconds; work already running keeps what it started with.
185
+ *
186
+ * `PUT /v1/projects/{project_id}/settings/{option}` · scope `authenticated` · served by beta-api.b3os.org
187
+ */
188
+ setProjectSetting(
189
+ projectId: string,
190
+ option: string,
191
+ body: T.SettingRequest,
192
+ options?: RequestOptions,
193
+ ): APIPromise<T.StoredSetting> {
194
+ return this._client._call<T.StoredSetting>(setProjectSettingOp, { path: [projectId, option], body }, options);
195
+ }
122
196
  }