@b3os/sdk 0.1.3 → 0.2.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.
Files changed (108) hide show
  1. package/README.md +4 -3
  2. package/dist/cjs/core/client.d.ts +21 -2
  3. package/dist/cjs/core/client.js +26 -1
  4. package/dist/cjs/core/client.js.map +1 -1
  5. package/dist/cjs/core/handle.d.ts +5 -0
  6. package/dist/cjs/core/handle.js +13 -2
  7. package/dist/cjs/core/handle.js.map +1 -1
  8. package/dist/cjs/core/index.d.ts +2 -0
  9. package/dist/cjs/core/index.js +7 -1
  10. package/dist/cjs/core/index.js.map +1 -1
  11. package/dist/cjs/core/sse.d.ts +2 -0
  12. package/dist/cjs/core/sse.js +17 -5
  13. package/dist/cjs/core/sse.js.map +1 -1
  14. package/dist/cjs/core/traces-api.d.ts +42 -0
  15. package/dist/cjs/core/traces-api.js +54 -0
  16. package/dist/cjs/core/traces-api.js.map +1 -0
  17. package/dist/cjs/core/traces.d.ts +120 -0
  18. package/dist/cjs/core/traces.js +306 -0
  19. package/dist/cjs/core/traces.js.map +1 -0
  20. package/dist/cjs/core/util.d.ts +1 -1
  21. package/dist/cjs/core/util.js +1 -1
  22. package/dist/cjs/generated/errors.d.ts +1 -1
  23. package/dist/cjs/generated/errors.js +32 -0
  24. package/dist/cjs/generated/errors.js.map +1 -1
  25. package/dist/cjs/generated/ids.d.ts +12 -0
  26. package/dist/cjs/generated/ids.js +3 -0
  27. package/dist/cjs/generated/ids.js.map +1 -1
  28. package/dist/cjs/generated/ns/actions.d.ts +66 -1
  29. package/dist/cjs/generated/ns/actions.js +101 -1
  30. package/dist/cjs/generated/ns/actions.js.map +1 -1
  31. package/dist/cjs/generated/ns/keys.d.ts +2 -1
  32. package/dist/cjs/generated/ns/keys.js +2 -1
  33. package/dist/cjs/generated/ns/keys.js.map +1 -1
  34. package/dist/cjs/generated/ns/render.d.ts +22 -2
  35. package/dist/cjs/generated/ns/render.js +13 -2
  36. package/dist/cjs/generated/ns/render.js.map +1 -1
  37. package/dist/cjs/generated/ns/sandboxes.d.ts +29 -0
  38. package/dist/cjs/generated/ns/sandboxes.js +49 -0
  39. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  40. package/dist/cjs/generated/types.d.ts +1038 -65
  41. package/dist/cjs/helpers/sandboxes.d.ts +26 -2
  42. package/dist/cjs/helpers/sandboxes.js +114 -13
  43. package/dist/cjs/helpers/sandboxes.js.map +1 -1
  44. package/dist/cjs/index.d.ts +1 -1
  45. package/dist/cjs/index.js +2 -1
  46. package/dist/cjs/index.js.map +1 -1
  47. package/dist/esm/core/client.d.ts +21 -2
  48. package/dist/esm/core/client.js +27 -2
  49. package/dist/esm/core/client.js.map +1 -1
  50. package/dist/esm/core/handle.d.ts +5 -0
  51. package/dist/esm/core/handle.js +13 -2
  52. package/dist/esm/core/handle.js.map +1 -1
  53. package/dist/esm/core/index.d.ts +2 -0
  54. package/dist/esm/core/index.js +2 -0
  55. package/dist/esm/core/index.js.map +1 -1
  56. package/dist/esm/core/sse.d.ts +2 -0
  57. package/dist/esm/core/sse.js +17 -5
  58. package/dist/esm/core/sse.js.map +1 -1
  59. package/dist/esm/core/traces-api.d.ts +42 -0
  60. package/dist/esm/core/traces-api.js +50 -0
  61. package/dist/esm/core/traces-api.js.map +1 -0
  62. package/dist/esm/core/traces.d.ts +120 -0
  63. package/dist/esm/core/traces.js +295 -0
  64. package/dist/esm/core/traces.js.map +1 -0
  65. package/dist/esm/core/util.d.ts +1 -1
  66. package/dist/esm/core/util.js +1 -1
  67. package/dist/esm/generated/errors.d.ts +1 -1
  68. package/dist/esm/generated/errors.js +32 -0
  69. package/dist/esm/generated/errors.js.map +1 -1
  70. package/dist/esm/generated/ids.d.ts +12 -0
  71. package/dist/esm/generated/ids.js +3 -0
  72. package/dist/esm/generated/ids.js.map +1 -1
  73. package/dist/esm/generated/ns/actions.d.ts +66 -1
  74. package/dist/esm/generated/ns/actions.js +101 -1
  75. package/dist/esm/generated/ns/actions.js.map +1 -1
  76. package/dist/esm/generated/ns/keys.d.ts +2 -1
  77. package/dist/esm/generated/ns/keys.js +2 -1
  78. package/dist/esm/generated/ns/keys.js.map +1 -1
  79. package/dist/esm/generated/ns/render.d.ts +22 -2
  80. package/dist/esm/generated/ns/render.js +13 -2
  81. package/dist/esm/generated/ns/render.js.map +1 -1
  82. package/dist/esm/generated/ns/sandboxes.d.ts +29 -0
  83. package/dist/esm/generated/ns/sandboxes.js +49 -0
  84. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  85. package/dist/esm/generated/types.d.ts +1038 -65
  86. package/dist/esm/helpers/sandboxes.d.ts +26 -2
  87. package/dist/esm/helpers/sandboxes.js +113 -12
  88. package/dist/esm/helpers/sandboxes.js.map +1 -1
  89. package/dist/esm/index.d.ts +1 -1
  90. package/dist/esm/index.js +1 -1
  91. package/dist/esm/index.js.map +1 -1
  92. package/package.json +1 -1
  93. package/src/core/client.ts +36 -4
  94. package/src/core/handle.ts +12 -2
  95. package/src/core/index.ts +10 -0
  96. package/src/core/sse.ts +17 -5
  97. package/src/core/traces-api.ts +80 -0
  98. package/src/core/traces.ts +375 -0
  99. package/src/core/util.ts +1 -1
  100. package/src/generated/errors.ts +64 -0
  101. package/src/generated/ids.ts +3 -0
  102. package/src/generated/ns/actions.ts +110 -1
  103. package/src/generated/ns/keys.ts +2 -1
  104. package/src/generated/ns/render.ts +22 -2
  105. package/src/generated/ns/sandboxes.ts +59 -0
  106. package/src/generated/types.ts +1057 -63
  107. package/src/helpers/sandboxes.ts +136 -12
  108. package/src/index.ts +1 -0
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ // `b3.traces`: the hand-written turn helpers of observability.md 8.3 (core/traces.ts holds the context and the rules),
3
+ // and the one trace route of phase 2a, `GET /v1/traces/{trace_id}`, which the edge assembles from the request log and
4
+ // usage records.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Traces = void 0;
7
+ const traces_ts_1 = require("./traces.js");
8
+ class Traces {
9
+ #client;
10
+ constructor(client) {
11
+ this.#client = client;
12
+ }
13
+ /**
14
+ * Runs `fn` as one turn: a new trace that every B3OS call inside joins (`tracestate: b3os=turn`), with the turn's
15
+ * conversation, subject and metadata on each call's `baggage`. Resolves with what `fn` returns.
16
+ *
17
+ * ```ts
18
+ * await b3.traces.turn("answer", async (turn) => {
19
+ * const page = await b3.vision.scrape({ url }); // joins the turn
20
+ * const reply = await openai.chat.completions.create(req, { headers: turn.headers({ baggage: true }) });
21
+ * }, { conversation: thread.id, subject: user.id });
22
+ * ```
23
+ */
24
+ turn(name, fn, options = {}) {
25
+ return (0, traces_ts_1.runTurn)(name, fn, options, this.#client._onSpan);
26
+ }
27
+ /** Times a step of the harness inside the current turn; the calls made inside it name it as their parent. */
28
+ span(name, fn, options = {}) {
29
+ return (0, traces_ts_1.runSpan)(name, fn, options);
30
+ }
31
+ /** The turn the calling code runs in, if any. */
32
+ current() {
33
+ return (0, traces_ts_1.currentTurn)();
34
+ }
35
+ /** The current turn's trace headers for another client, or undefined outside a turn. */
36
+ headers(o = {}) {
37
+ return (0, traces_ts_1.currentTurn)()?.headers(o);
38
+ }
39
+ /**
40
+ * A fetch that adds the current turn's trace headers to every request, for a model SDK's `fetch` option. Baggage
41
+ * goes only to B3OS hosts (this client's API host and node URL among them).
42
+ */
43
+ wrapFetch(inner) {
44
+ return (0, traces_ts_1.wrapFetch)(inner, this.#client._origins);
45
+ }
46
+ /** `GET /v1/traces/{trace_id}`: one trace's requests, in start order, with their usage (7 days). */
47
+ get(traceId, options) {
48
+ if (!/^[0-9a-f]{32}$/.test(traceId))
49
+ throw new TypeError("@b3os/sdk: traces.get takes a 32-hex trace id");
50
+ return this.#client.request({ method: "GET", path: `/v1/traces/${traceId}`, edge: true }, options);
51
+ }
52
+ }
53
+ exports.Traces = Traces;
54
+ //# sourceMappingURL=traces-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traces-api.js","sourceRoot":"","sources":["../../../src/core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D,wBAkDC"}
@@ -0,0 +1,120 @@
1
+ /** The `tracestate` list member key B3OS reads (W3C Trace Context: `<key>=<value>`, leftmost is the newest). */
2
+ export declare const TRACESTATE_KEY = "b3os";
3
+ /**
4
+ * The last SDK versions that send no mark (`b3os-sdk-ts/<v>`, `b3os-sdk-python/<v>`): a request from one of these,
5
+ * or an older one, without `tracestate` is treated as `b3os=call` (observability.md 3.3, tier 1).
6
+ */
7
+ export declare const TRACE_MARK_AFTER: {
8
+ readonly ts: "0.1.3";
9
+ readonly python: "0.1.3";
10
+ };
11
+ /** observability.md 2.4 (proposed bounds): a subject of at most 128 characters, 16 metadata keys of 64, values of 512. */
12
+ export declare const SUBJECT_MAX = 128;
13
+ export declare const METADATA_KEYS_MAX = 16;
14
+ export declare const METADATA_KEY_MAX = 64;
15
+ export declare const METADATA_VALUE_MAX = 512;
16
+ /** Harness spans one turn keeps in memory at most; past it they are counted, not kept. */
17
+ export declare const TURN_SPANS_MAX = 1000;
18
+ export type SpanKind = "turn" | "harness" | "tool" | "agent" | "model";
19
+ /** A span the SDK timed: a turn's root, or a step of the harness (`traces.span`). */
20
+ export interface SpanRecord {
21
+ trace_id: string;
22
+ span_id: string;
23
+ parent_span_id: string | null;
24
+ name: string;
25
+ kind: SpanKind;
26
+ started_at: string;
27
+ duration_ms: number;
28
+ status: "ok" | "error";
29
+ /** The error's message, when `status` is `error`. */
30
+ error?: string;
31
+ attributes: Record<string, string | number | boolean>;
32
+ }
33
+ export interface TurnOptions {
34
+ /** Groups turns into a task (`gen_ai.conversation.id`): a session or thread id of yours. */
35
+ conversation?: string;
36
+ /** The end user the turn is for: an opaque id, never an email. */
37
+ subject?: string;
38
+ /** Up to 16 keys of yours, filterable later. */
39
+ metadata?: Record<string, string>;
40
+ /** Join this trace (32 hex digits) instead of minting one, e.g. an incoming request's. */
41
+ traceId?: string;
42
+ }
43
+ export interface SpanOptions {
44
+ kind?: Exclude<SpanKind, "turn">;
45
+ attributes?: Record<string, string | number | boolean>;
46
+ }
47
+ /** The trace headers of one call (`traceparent`, and `tracestate` and `baggage` when there is a mark or a turn). */
48
+ export type TraceHeaders = {
49
+ traceparent: string;
50
+ tracestate?: string;
51
+ baggage?: string;
52
+ };
53
+ /** Whether this runtime carries a turn across `await` (AsyncLocalStorage); without it, only synchronous code does. */
54
+ export declare const asyncContext: boolean;
55
+ /** `tracestate` with `b3os=<mark>` first and any earlier `b3os` member dropped (W3C: one member per key). */
56
+ export declare function withMark(existing: string | undefined, mark: "turn" | "call"): string;
57
+ /** One turn of an agent: a trace id, the turn's root span, and what goes on every call inside it. */
58
+ export declare class Turn {
59
+ #private;
60
+ readonly traceId: string;
61
+ /** The turn's root span: the parent of calls made in the turn outside any `traces.span`. */
62
+ readonly spanId: string;
63
+ readonly name: string;
64
+ readonly conversation: string | undefined;
65
+ readonly subject: string | undefined;
66
+ readonly metadata: Readonly<Record<string, string>>;
67
+ /** The turn's root and the harness spans timed in it, in the order they ended (TURN_SPANS_MAX at most). */
68
+ readonly spans: SpanRecord[];
69
+ /** Spans past TURN_SPANS_MAX, counted only. */
70
+ dropped: number;
71
+ constructor(name: string, o?: TurnOptions, onSpan?: (s: SpanRecord) => void);
72
+ /** `traceparent` for a call made now: this turn's trace, the current span (or the turn's root) as parent. */
73
+ traceparent(parent?: string): string;
74
+ /**
75
+ * The headers that join another client's requests to this turn: `traceparent` and `tracestate: b3os=turn`, plus,
76
+ * with `{ baggage: true }`, the `baggage` header with the turn's name, conversation, subject and metadata. Send the
77
+ * baggage only to B3OS (it holds your end user's id).
78
+ */
79
+ headers(o?: {
80
+ baggage?: boolean;
81
+ }): TraceHeaders;
82
+ /** The baggage header B3OS calls in this turn carry. */
83
+ get baggage(): string | undefined;
84
+ /**
85
+ * The same headers as environment variables for a command in another sandbox (`TRACEPARENT`, `TRACESTATE`), the
86
+ * convention B3OS's SDKs read when they start: pass them as `env` to `sandboxes.exec`, so the hands sandbox's
87
+ * calls join the turn the head runs.
88
+ */
89
+ env(): {
90
+ TRACEPARENT: string;
91
+ TRACESTATE: string;
92
+ };
93
+ /** @internal */
94
+ _record(s: SpanRecord): void;
95
+ }
96
+ /** The turn the calling code runs in, if any. */
97
+ export declare function currentTurn(): Turn | undefined;
98
+ /**
99
+ * The trace headers of one attempt of an SDK call, by the rules above. `own`: the call's own `traceparent`
100
+ * (RequestOptions), `client`: the client's default `traceparent` and `tracestate` headers, `traceId`: the call's
101
+ * per-call trace when it has no other.
102
+ */
103
+ export declare function callTraceHeaders(own: string | undefined, ownState: string | undefined, client: {
104
+ traceparent?: string;
105
+ tracestate?: string;
106
+ }, traceId: string): TraceHeaders;
107
+ /** Runs `fn` as one turn (see the module comment). Nested turns are separate traces. */
108
+ export declare function runTurn<R>(name: string, fn: (turn: Turn) => R | Promise<R>, o?: TurnOptions, onSpan?: (s: SpanRecord) => void): Promise<R>;
109
+ /** Times `fn` as a span of the current turn, the parent of the calls made inside it; outside a turn it only runs fn. */
110
+ export declare function runSpan<R>(name: string, fn: () => R | Promise<R>, o?: SpanOptions): Promise<R>;
111
+ /** Hosts a turn's baggage may go to: B3OS's own (the API host, the dashboard, a node, a sandbox's loopback). */
112
+ export declare function isB3osUrl(url: string, extra?: readonly string[]): boolean;
113
+ type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
114
+ /**
115
+ * A fetch that adds the current turn's trace headers to every request it sends (and nothing outside a turn), for a
116
+ * model SDK's `fetch` option: `new OpenAI({ fetch: b3.traces.wrapFetch() })`. Headers the request already has win.
117
+ * Baggage goes only to B3OS hosts. Model spans for provider hosts are phase 2b.
118
+ */
119
+ export declare function wrapFetch(inner?: FetchLike, b3osOrigins?: string[]): FetchLike;
120
+ export {};
@@ -0,0 +1,306 @@
1
+ "use strict";
2
+ // Turns and trace marks (NOTES/deploy-platform/observability.md 3.3, 3.4, 8.3): the SDK's side of "one trace per turn".
3
+ //
4
+ // - `b3.traces.turn(name, fn, { conversation, subject, metadata })` mints a trace id and runs `fn` with it in
5
+ // async-local context (AsyncLocalStorage, where the runtime has it). Every B3OS call inside joins the turn: its
6
+ // `traceparent` names the turn's trace and the current span as parent, and it sends `tracestate: b3os=turn` plus a
7
+ // W3C `baggage` header with the turn's name, conversation, subject and metadata. `turn.headers()` gives the same
8
+ // trace headers for another client (an OpenAI SDK pointed at B3OS); `turn.env()` gives them as `TRACEPARENT` and
9
+ // `TRACESTATE` for a command in another sandbox (a "hands" sandbox the turn hands work to).
10
+ // - Outside a turn each SDK call keeps its own trace, one span per attempt, as before, and now says so:
11
+ // `tracestate: b3os=call`, so the node never takes an SDK-minted per-call trace for a turn. A caller's own
12
+ // `traceparent` (on the call, or on the client's headers, as an MCP server's per-request client has) carries no
13
+ // mark: that trace is the caller's.
14
+ // - `b3.traces.span(name, fn, { kind })` times a step of the harness's own and makes it the parent of the calls made
15
+ // inside it. Phase 2a has no ingest door, so spans are kept on the turn (`turn.spans`) and handed to
16
+ // `ClientOptions.onSpan`; nothing is exported over the network yet.
17
+ // - `b3.traces.wrapFetch(fetch)` adds the turn's trace headers to every request a model SDK sends inside a turn
18
+ // (baggage only to B3OS hosts, so an end user's id never reaches a third party).
19
+ //
20
+ // The node reads the marks from phase 2b on. Until then the request log keeps only the trace id, so a turn's calls
21
+ // are found with `GET /v1/requests?trace_id=<turn.traceId>` or `GET /v1/traces/{trace_id}`. Older SDKs send no mark;
22
+ // the node and the trace view treat their traces as per-call by their User-Agent (`TRACE_MARK_AFTER`).
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.Turn = exports.asyncContext = exports.TURN_SPANS_MAX = exports.METADATA_VALUE_MAX = exports.METADATA_KEY_MAX = exports.METADATA_KEYS_MAX = exports.SUBJECT_MAX = exports.TRACE_MARK_AFTER = exports.TRACESTATE_KEY = void 0;
25
+ exports.withMark = withMark;
26
+ exports.currentTurn = currentTurn;
27
+ exports.callTraceHeaders = callTraceHeaders;
28
+ exports.runTurn = runTurn;
29
+ exports.runSpan = runSpan;
30
+ exports.isB3osUrl = isB3osUrl;
31
+ exports.wrapFetch = wrapFetch;
32
+ const util_ts_1 = require("./util.js");
33
+ /** The `tracestate` list member key B3OS reads (W3C Trace Context: `<key>=<value>`, leftmost is the newest). */
34
+ exports.TRACESTATE_KEY = "b3os";
35
+ /**
36
+ * The last SDK versions that send no mark (`b3os-sdk-ts/<v>`, `b3os-sdk-python/<v>`): a request from one of these,
37
+ * or an older one, without `tracestate` is treated as `b3os=call` (observability.md 3.3, tier 1).
38
+ */
39
+ exports.TRACE_MARK_AFTER = { ts: "0.1.3", python: "0.1.3" };
40
+ /** observability.md 2.4 (proposed bounds): a subject of at most 128 characters, 16 metadata keys of 64, values of 512. */
41
+ exports.SUBJECT_MAX = 128;
42
+ exports.METADATA_KEYS_MAX = 16;
43
+ exports.METADATA_KEY_MAX = 64;
44
+ exports.METADATA_VALUE_MAX = 512;
45
+ /** Harness spans one turn keeps in memory at most; past it they are counted, not kept. */
46
+ exports.TURN_SPANS_MAX = 1000;
47
+ /**
48
+ * The async-local context: Node's AsyncLocalStorage where it exists (Node, Bun, Deno, Workers with nodejs_compat).
49
+ * Elsewhere a stack that holds while `fn` runs synchronously: calls made after an `await` inside a turn then carry no
50
+ * turn, so pass `turn.headers()` yourself there.
51
+ */
52
+ function makeStore() {
53
+ const g = globalThis;
54
+ const Als = (0, util_ts_1.builtin)("node:async_hooks")?.AsyncLocalStorage ?? g.AsyncLocalStorage ?? null;
55
+ if (Als)
56
+ return { store: new Als(), async: true };
57
+ const stack = [];
58
+ return {
59
+ store: {
60
+ getStore: () => stack.at(-1),
61
+ run: (f, fn) => {
62
+ stack.push(f);
63
+ try {
64
+ return fn();
65
+ }
66
+ finally {
67
+ stack.pop();
68
+ }
69
+ },
70
+ },
71
+ async: false,
72
+ };
73
+ }
74
+ const made = makeStore();
75
+ const store = made.store;
76
+ /** Whether this runtime carries a turn across `await` (AsyncLocalStorage); without it, only synchronous code does. */
77
+ exports.asyncContext = made.async;
78
+ const TRACE_ID = /^(?!0{32})[0-9a-f]{32}$/;
79
+ function checkOptions(o) {
80
+ if (o.traceId !== undefined && !TRACE_ID.test(o.traceId))
81
+ throw new TypeError("@b3os/sdk: traces.turn: traceId must be 32 lower-case hex digits, not all zero");
82
+ if (o.subject !== undefined && (typeof o.subject !== "string" || o.subject.length > exports.SUBJECT_MAX))
83
+ throw new TypeError(`@b3os/sdk: traces.turn: subject is a string of at most ${exports.SUBJECT_MAX} characters`);
84
+ if (o.conversation !== undefined && (typeof o.conversation !== "string" || o.conversation.length > exports.SUBJECT_MAX))
85
+ throw new TypeError(`@b3os/sdk: traces.turn: conversation is a string of at most ${exports.SUBJECT_MAX} characters`);
86
+ const m = o.metadata ?? {};
87
+ const keys = Object.keys(m);
88
+ if (keys.length > exports.METADATA_KEYS_MAX)
89
+ throw new TypeError(`@b3os/sdk: traces.turn: metadata takes at most ${exports.METADATA_KEYS_MAX} keys`);
90
+ for (const k of keys) {
91
+ if (!/^[A-Za-z0-9_.-]+$/.test(k) || k.length > exports.METADATA_KEY_MAX)
92
+ throw new TypeError(`@b3os/sdk: traces.turn: metadata key ${JSON.stringify(k)} must be letters, digits, _ . or -, at most ${exports.METADATA_KEY_MAX}`);
93
+ const v = m[k];
94
+ if (typeof v !== "string" || v.length > exports.METADATA_VALUE_MAX)
95
+ throw new TypeError(`@b3os/sdk: traces.turn: metadata ${k} is a string of at most ${exports.METADATA_VALUE_MAX} characters`);
96
+ }
97
+ }
98
+ /** A W3C baggage value: percent-encoded, so commas, semicolons and spaces survive. */
99
+ const bag = (v) => encodeURIComponent(v);
100
+ /** `tracestate` with `b3os=<mark>` first and any earlier `b3os` member dropped (W3C: one member per key). */
101
+ function withMark(existing, mark) {
102
+ const rest = (existing ?? "")
103
+ .split(",")
104
+ .map((x) => x.trim())
105
+ .filter((x) => x && !x.startsWith(`${exports.TRACESTATE_KEY}=`));
106
+ return [`${exports.TRACESTATE_KEY}=${mark}`, ...rest].slice(0, 32).join(",");
107
+ }
108
+ /** One turn of an agent: a trace id, the turn's root span, and what goes on every call inside it. */
109
+ class Turn {
110
+ traceId;
111
+ /** The turn's root span: the parent of calls made in the turn outside any `traces.span`. */
112
+ spanId;
113
+ name;
114
+ conversation;
115
+ subject;
116
+ metadata;
117
+ /** The turn's root and the harness spans timed in it, in the order they ended (TURN_SPANS_MAX at most). */
118
+ spans = [];
119
+ /** Spans past TURN_SPANS_MAX, counted only. */
120
+ dropped = 0;
121
+ #baggage;
122
+ #onSpan;
123
+ constructor(name, o = {}, onSpan) {
124
+ if (typeof name !== "string" || !name.trim() || name.length > 128)
125
+ throw new TypeError("@b3os/sdk: traces.turn: name is a string of 1 to 128 characters");
126
+ checkOptions(o);
127
+ this.name = name;
128
+ this.traceId = o.traceId ?? (0, util_ts_1.newTraceId)();
129
+ this.spanId = (0, util_ts_1.newSpanId)();
130
+ this.conversation = o.conversation;
131
+ this.subject = o.subject;
132
+ this.metadata = Object.freeze({ ...(o.metadata ?? {}) });
133
+ this.#onSpan = onSpan;
134
+ const members = [`b3os.turn=${bag(name)}`];
135
+ if (o.conversation !== undefined)
136
+ members.push(`b3os.conversation=${bag(o.conversation)}`);
137
+ if (o.subject !== undefined)
138
+ members.push(`b3os.subject=${bag(o.subject)}`);
139
+ for (const [k, v] of Object.entries(this.metadata))
140
+ members.push(`b3os.meta.${k}=${bag(v)}`);
141
+ this.#baggage = members.join(",");
142
+ }
143
+ /** `traceparent` for a call made now: this turn's trace, the current span (or the turn's root) as parent. */
144
+ traceparent(parent = currentSpanIn(this) ?? this.spanId) {
145
+ return `00-${this.traceId}-${parent}-01`;
146
+ }
147
+ /**
148
+ * The headers that join another client's requests to this turn: `traceparent` and `tracestate: b3os=turn`, plus,
149
+ * with `{ baggage: true }`, the `baggage` header with the turn's name, conversation, subject and metadata. Send the
150
+ * baggage only to B3OS (it holds your end user's id).
151
+ */
152
+ headers(o = {}) {
153
+ const h = { traceparent: this.traceparent(), tracestate: withMark(undefined, "turn") };
154
+ if (o.baggage && this.#baggage)
155
+ h.baggage = this.#baggage;
156
+ return h;
157
+ }
158
+ /** The baggage header B3OS calls in this turn carry. */
159
+ get baggage() {
160
+ return this.#baggage;
161
+ }
162
+ /**
163
+ * The same headers as environment variables for a command in another sandbox (`TRACEPARENT`, `TRACESTATE`), the
164
+ * convention B3OS's SDKs read when they start: pass them as `env` to `sandboxes.exec`, so the hands sandbox's
165
+ * calls join the turn the head runs.
166
+ */
167
+ env() {
168
+ return { TRACEPARENT: this.traceparent(), TRACESTATE: withMark(undefined, "turn") };
169
+ }
170
+ /** @internal */
171
+ _record(s) {
172
+ if (this.spans.length < exports.TURN_SPANS_MAX)
173
+ this.spans.push(s);
174
+ else
175
+ this.dropped++;
176
+ try {
177
+ this.#onSpan?.(s);
178
+ }
179
+ catch {
180
+ // A hook must never break the turn.
181
+ }
182
+ }
183
+ }
184
+ exports.Turn = Turn;
185
+ function currentSpanIn(turn) {
186
+ const f = store.getStore();
187
+ return f && f.turn === turn ? f.spanId : undefined;
188
+ }
189
+ /** The turn the calling code runs in, if any. */
190
+ function currentTurn() {
191
+ return store.getStore()?.turn;
192
+ }
193
+ /**
194
+ * The trace headers of one attempt of an SDK call, by the rules above. `own`: the call's own `traceparent`
195
+ * (RequestOptions), `client`: the client's default `traceparent` and `tracestate` headers, `traceId`: the call's
196
+ * per-call trace when it has no other.
197
+ */
198
+ function callTraceHeaders(own, ownState, client, traceId) {
199
+ if (own)
200
+ return ownState ? { traceparent: own, tracestate: ownState } : { traceparent: own };
201
+ if (client.traceparent && util_ts_1.TRACEPARENT_RE.test(client.traceparent.trim().toLowerCase())) {
202
+ const h = { traceparent: `00-${traceId}-${(0, util_ts_1.newSpanId)()}-01` };
203
+ if (client.tracestate)
204
+ h.tracestate = client.tracestate;
205
+ return h;
206
+ }
207
+ const f = store.getStore();
208
+ if (f) {
209
+ const h = {
210
+ traceparent: `00-${f.turn.traceId}-${f.spanId}-01`,
211
+ tracestate: withMark(client.tracestate, "turn"),
212
+ };
213
+ if (f.turn.baggage)
214
+ h.baggage = f.turn.baggage;
215
+ return h;
216
+ }
217
+ return { traceparent: `00-${traceId}-${(0, util_ts_1.newSpanId)()}-01`, tracestate: withMark(client.tracestate, "call") };
218
+ }
219
+ async function timed(turn, span, fn) {
220
+ const t0 = performance.now();
221
+ const startedAt = new Date().toISOString();
222
+ const end = (status, error) => turn._record({
223
+ trace_id: turn.traceId,
224
+ span_id: span.id,
225
+ parent_span_id: span.parent,
226
+ name: span.name,
227
+ kind: span.kind,
228
+ started_at: startedAt,
229
+ duration_ms: Math.round((performance.now() - t0) * 1000) / 1000,
230
+ status,
231
+ ...(error !== undefined ? { error: error instanceof Error ? error.message : String(error) } : {}),
232
+ attributes: span.attributes,
233
+ });
234
+ try {
235
+ const out = await store.run({ turn, spanId: span.id }, fn);
236
+ end("ok");
237
+ return out;
238
+ }
239
+ catch (e) {
240
+ end("error", e);
241
+ throw e;
242
+ }
243
+ }
244
+ /** Runs `fn` as one turn (see the module comment). Nested turns are separate traces. */
245
+ function runTurn(name, fn, o = {}, onSpan) {
246
+ let turn;
247
+ try {
248
+ turn = new Turn(name, o, onSpan);
249
+ }
250
+ catch (e) {
251
+ return Promise.reject(e);
252
+ }
253
+ const attributes = {};
254
+ if (turn.conversation !== undefined)
255
+ attributes["gen_ai.conversation.id"] = turn.conversation;
256
+ if (turn.subject !== undefined)
257
+ attributes["user.id"] = turn.subject;
258
+ for (const [k, v] of Object.entries(turn.metadata))
259
+ attributes[`metadata.${k}`] = v;
260
+ return timed(turn, { id: turn.spanId, parent: null, name, kind: "turn", attributes }, () => fn(turn));
261
+ }
262
+ /** Times `fn` as a span of the current turn, the parent of the calls made inside it; outside a turn it only runs fn. */
263
+ async function runSpan(name, fn, o = {}) {
264
+ const f = store.getStore();
265
+ if (!f)
266
+ return fn();
267
+ return timed(f.turn, { id: (0, util_ts_1.newSpanId)(), parent: f.spanId, name, kind: o.kind ?? "harness", attributes: { ...(o.attributes ?? {}) } }, fn);
268
+ }
269
+ /** Hosts a turn's baggage may go to: B3OS's own (the API host, the dashboard, a node, a sandbox's loopback). */
270
+ function isB3osUrl(url, extra = []) {
271
+ let u;
272
+ try {
273
+ u = new URL(url);
274
+ }
275
+ catch {
276
+ return false;
277
+ }
278
+ const origin = u.origin;
279
+ if (extra.some((e) => e && origin === new URL(e).origin))
280
+ return true;
281
+ const h = u.hostname;
282
+ return (h === "b3os.org" || h.endsWith(".b3os.org") || (u.protocol === "http:" && h === "127.0.0.1" && u.port === "7700"));
283
+ }
284
+ /**
285
+ * A fetch that adds the current turn's trace headers to every request it sends (and nothing outside a turn), for a
286
+ * model SDK's `fetch` option: `new OpenAI({ fetch: b3.traces.wrapFetch() })`. Headers the request already has win.
287
+ * Baggage goes only to B3OS hosts. Model spans for provider hosts are phase 2b.
288
+ */
289
+ function wrapFetch(inner = globalThis.fetch.bind(globalThis), b3osOrigins = []) {
290
+ return (input, init) => {
291
+ const f = store.getStore();
292
+ if (!f)
293
+ return inner(input, init);
294
+ const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
295
+ const base = input instanceof Request ? input.headers : undefined;
296
+ const headers = new Headers(init?.headers ?? base);
297
+ if (!headers.has("traceparent")) {
298
+ headers.set("traceparent", f.turn.traceparent(f.spanId));
299
+ headers.set("tracestate", withMark(headers.get("tracestate") ?? undefined, "turn"));
300
+ }
301
+ if (!headers.has("baggage") && f.turn.baggage && isB3osUrl(url, b3osOrigins))
302
+ headers.set("baggage", f.turn.baggage);
303
+ return inner(input, { ...init, headers });
304
+ };
305
+ }
306
+ //# sourceMappingURL=traces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traces.js","sourceRoot":"","sources":["../../../src/core/traces.ts"],"names":[],"mappings":";AAAA,wHAAwH;AACxH,EAAE;AACF,8GAA8G;AAC9G,kHAAkH;AAClH,qHAAqH;AACrH,mHAAmH;AACnH,mHAAmH;AACnH,8FAA8F;AAC9F,wGAAwG;AACxG,6GAA6G;AAC7G,kHAAkH;AAClH,sCAAsC;AACtC,qHAAqH;AACrH,uGAAuG;AACvG,sEAAsE;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C;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.3";
1
+ export declare const SDK_VERSION = "0.2.1";
2
2
  /** An environment variable, or undefined where there is no process environment (Workers, browsers). */
3
3
  export declare function env(name: string): string | undefined;
4
4
  /**
@@ -19,7 +19,7 @@ exports.isObject = isObject;
19
19
  exports.concatBytes = concatBytes;
20
20
  exports.camel = camel;
21
21
  exports.describeErr = describeErr;
22
- exports.SDK_VERSION = "0.1.3";
22
+ exports.SDK_VERSION = "0.2.1";
23
23
  function proc() {
24
24
  const p = globalThis.process;
25
25
  return p && typeof p === "object" ? p : undefined;
@@ -1,4 +1,4 @@
1
1
  export declare const ERROR_TYPE_BASE = "https://docs.beta.b3os.org/errors#";
2
2
  export declare const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, retryable: 0 | 1, title: string]>>;
3
3
  /** Every code a B3OS server can return. */
4
- export type B3OSServerErrorCode = "invalid_request" | "invalid_url" | "unsupported_media_type" | "not_acceptable" | "payload_too_large" | "route_not_found" | "feature_not_enabled" | "method_not_allowed" | "edge_only" | "limit_exceeded" | "option_not_allowed" | "idempotency_key_invalid" | "idempotency_key_conflict" | "idempotency_request_in_progress" | "idempotency_response_evicted" | "idempotency_outcome_unknown" | "conflict" | "resource_not_found" | "not_implemented" | "unauthorized" | "forbidden" | "ticket_limit" | "auth_unavailable" | "signed_url_invalid" | "rate_limited" | "concurrency_limited" | "quota_exceeded" | "credits_exhausted" | "spend_cap_exceeded" | "egress_denied" | "upstream_error" | "upstream_unreachable" | "upstream_timeout" | "upstream_too_large" | "too_many_redirects" | "cap_invalid" | "node_unavailable" | "product_unavailable" | "capacity_unavailable" | "budgets_unavailable" | "request_timeout" | "invoke_depth_exceeded" | "internal" | "job_not_found" | "job_already_finished" | "job_canceled" | "job_timed_out" | "job_expired" | "stream_resume_unavailable" | "invalid_webhook_url" | "api_key_not_found" | "project_not_found" | "org_not_found" | "request_not_found" | "project_not_empty" | "last_project" | "invite_code_invalid" | "invite_code_used" | "email_code_invalid" | "user_code_not_found" | "device_authorization_finished" | "publisher_not_allowed" | "pack_version_exists" | "pack_invalid" | "pack_signature_invalid" | "org_suspended" | "hook_queue_full" | "email_unavailable" | "turnstile_required" | "turnstile_failed" | "turnstile_unavailable" | "authorization_pending" | "slow_down" | "access_denied" | "expired_token" | "invalid_grant" | "invalid_client" | "unsupported_grant_type" | "session_not_found" | "session_closed" | "profile_not_found" | "profile_domain_mismatch" | "profile_conflict" | "profile_name_taken" | "profile_not_exportable" | "crawl_not_found" | "batch_not_found" | "robots_disallowed" | "content_type_unsupported" | "navigation_failed" | "scrape_timeout" | "target_not_found" | "target_covered" | "stale_ref" | "act_step_failed" | "cdp_method_blocked" | "extraction_failed" | "scrape_no_cached_data" | "scrape_lockdown_cache_miss" | "search_unavailable" | "search_failed" | "search_answer_too_large" | "screenshot_not_found" | "video_not_found" | "artifact_not_found" | "artifact_expired" | "capture_failed" | "script_invalid" | "script_step_failed" | "restyle_unavailable" | "background_unavailable" | "style_invalid" | "sandbox_not_found" | "sandbox_not_running" | "template_not_found" | "snapshot_not_found" | "snapshot_damaged" | "file_not_found" | "path_invalid" | "not_a_directory" | "file_exists" | "directory_not_empty" | "guest_outdated" | "file_too_large" | "port_not_exposed" | "process_not_found" | "kernel_unavailable" | "language_unsupported" | "guest_unreachable" | "snapshot_failed" | "fork_unavailable" | "envd_token_invalid" | "routine_not_found" | "routine_version_not_found" | "run_not_found" | "hook_not_found" | "routine_invalid" | "routine_name_taken" | "run_not_waiting" | "event_fan_out_too_large" | "wait_link_invalid" | "wait_not_ready" | "wait_already_answered" | "wait_link_expired" | "run_not_finished" | "run_steps_not_kept" | "replay_too_large" | "run_as_revoked" | "webhook_signature_invalid" | "step_failed" | "expression_error" | "run_input_invalid" | "step_timed_out" | "step_outcome_unknown" | "internal_recovery_failed" | "hook_attestation_unverifiable" | "pack_not_found" | "pack_version_not_found" | "action_not_found" | "trigger_not_found" | "trigger_subscription_not_found" | "action_ref_invalid" | "action_input_invalid" | "action_output_invalid" | "action_memory_exceeded" | "connection_required" | "connection_mismatch" | "pack_unavailable" | "action_expression_error" | "connection_not_found" | "connection_invalid" | "blob_not_found" | "blob_too_large" | "vault_unavailable" | "model_not_available" | "context_length_exceeded" | "unsupported_parameter" | "voice_not_found" | "infer_backend_unavailable" | "unsupported_endpoint" | "unsupported_option";
4
+ export type B3OSServerErrorCode = "invalid_request" | "invalid_url" | "unsupported_media_type" | "not_acceptable" | "payload_too_large" | "route_not_found" | "feature_not_enabled" | "flags_unavailable" | "method_not_allowed" | "edge_only" | "limit_exceeded" | "option_not_allowed" | "idempotency_key_invalid" | "idempotency_key_conflict" | "idempotency_request_in_progress" | "idempotency_response_evicted" | "idempotency_outcome_unknown" | "conflict" | "resource_not_found" | "not_implemented" | "unauthorized" | "forbidden" | "ticket_limit" | "auth_unavailable" | "signed_url_invalid" | "rate_limited" | "concurrency_limited" | "quota_exceeded" | "credits_exhausted" | "spend_cap_exceeded" | "egress_denied" | "upstream_error" | "upstream_unreachable" | "upstream_timeout" | "upstream_too_large" | "too_many_redirects" | "cap_invalid" | "node_unavailable" | "product_unavailable" | "capacity_unavailable" | "budgets_unavailable" | "request_timeout" | "invoke_depth_exceeded" | "internal" | "job_not_found" | "job_already_finished" | "job_canceled" | "job_timed_out" | "job_expired" | "stream_resume_unavailable" | "invalid_webhook_url" | "api_key_not_found" | "project_not_found" | "org_not_found" | "request_not_found" | "project_not_empty" | "last_project" | "invite_code_invalid" | "invite_code_used" | "email_code_invalid" | "user_code_not_found" | "device_authorization_finished" | "publisher_not_allowed" | "pack_version_exists" | "pack_invalid" | "pack_signature_invalid" | "org_suspended" | "hook_queue_full" | "email_unavailable" | "turnstile_required" | "turnstile_failed" | "turnstile_unavailable" | "github_app_not_configured" | "github_installation_not_found" | "github_repository_not_accessible" | "repository_link_not_found" | "eval_run_not_found" | "alert_destination_not_found" | "trace_not_found" | "deploy_not_found" | "deploy_not_rollbackable" | "deploy_not_updatable" | "app_host_label_taken" | "app_host_label_reserved" | "app_host_conflict" | "app_host_route_conflict" | "app_host_not_found" | "app_host_blocked" | "app_host_public_needs_spend_cap" | "app_host_port_public" | "sandbox_routed" | "app_not_found" | "app_link_required" | "app_deploying" | "app_not_running" | "app_blocked" | "app_unavailable" | "authorization_pending" | "slow_down" | "access_denied" | "expired_token" | "invalid_grant" | "invalid_client" | "unsupported_grant_type" | "session_not_found" | "session_closed" | "profile_not_found" | "profile_domain_mismatch" | "profile_conflict" | "profile_name_taken" | "profile_not_exportable" | "crawl_not_found" | "batch_not_found" | "robots_disallowed" | "content_type_unsupported" | "navigation_failed" | "scrape_timeout" | "target_not_found" | "target_covered" | "stale_ref" | "act_step_failed" | "cdp_method_blocked" | "extraction_failed" | "scrape_no_cached_data" | "scrape_lockdown_cache_miss" | "search_unavailable" | "search_failed" | "search_answer_too_large" | "screenshot_not_found" | "video_not_found" | "artifact_not_found" | "artifact_expired" | "capture_failed" | "script_invalid" | "script_step_failed" | "profile_expired" | "restyle_unavailable" | "background_unavailable" | "style_invalid" | "sandbox_not_found" | "sandbox_not_running" | "template_not_found" | "snapshot_not_found" | "snapshot_damaged" | "file_not_found" | "path_invalid" | "not_a_directory" | "file_exists" | "directory_not_empty" | "guest_outdated" | "file_too_large" | "port_not_exposed" | "app_token_invalid" | "upstream_first_byte_timeout" | "process_not_found" | "kernel_unavailable" | "language_unsupported" | "guest_unreachable" | "snapshot_failed" | "fork_unavailable" | "envd_token_invalid" | "routine_not_found" | "routine_version_not_found" | "run_not_found" | "hook_not_found" | "routine_invalid" | "routine_name_taken" | "run_not_waiting" | "event_fan_out_too_large" | "wait_link_invalid" | "wait_not_ready" | "wait_already_answered" | "wait_link_expired" | "run_not_finished" | "run_steps_not_kept" | "replay_too_large" | "run_as_revoked" | "webhook_signature_invalid" | "step_failed" | "expression_error" | "run_input_invalid" | "step_timed_out" | "step_outcome_unknown" | "internal_recovery_failed" | "hook_attestation_unverifiable" | "pack_not_found" | "pack_version_not_found" | "action_not_found" | "trigger_not_found" | "trigger_subscription_not_found" | "action_ref_invalid" | "action_input_invalid" | "action_output_invalid" | "action_memory_exceeded" | "connection_required" | "connection_mismatch" | "pack_unavailable" | "action_expression_error" | "tool_failed" | "tool_timed_out" | "tool_unavailable" | "connection_not_found" | "connection_invalid" | "blob_not_found" | "blob_too_large" | "vault_unavailable" | "model_not_available" | "context_length_exceeded" | "unsupported_parameter" | "voice_not_found" | "infer_backend_unavailable" | "unsupported_endpoint" | "unsupported_option";
@@ -12,6 +12,7 @@ exports.ERROR_CATALOG = {
12
12
  payload_too_large: [413, 0, "Payload too large"],
13
13
  route_not_found: [404, 0, "Route not found"],
14
14
  feature_not_enabled: [404, 0, "Feature not enabled"],
15
+ flags_unavailable: [503, 1, "Feature flags unavailable"],
15
16
  method_not_allowed: [405, 0, "Method not allowed"],
16
17
  edge_only: [421, 0, "Served by beta-api.b3os.org"],
17
18
  limit_exceeded: [422, 0, "Limit exceeded"],
@@ -76,6 +77,31 @@ exports.ERROR_CATALOG = {
76
77
  turnstile_required: [400, 0, "Turnstile token required"],
77
78
  turnstile_failed: [403, 0, "Turnstile check failed"],
78
79
  turnstile_unavailable: [503, 1, "Turnstile unavailable"],
80
+ github_app_not_configured: [503, 0, "GitHub App not configured"],
81
+ github_installation_not_found: [404, 0, "GitHub installation not found"],
82
+ github_repository_not_accessible: [404, 0, "GitHub repository not accessible"],
83
+ repository_link_not_found: [404, 0, "Repository link not found"],
84
+ eval_run_not_found: [404, 0, "Eval run not found"],
85
+ alert_destination_not_found: [404, 0, "Alert destination not found"],
86
+ trace_not_found: [404, 0, "Trace not found"],
87
+ deploy_not_found: [404, 0, "Deploy not found"],
88
+ deploy_not_rollbackable: [409, 0, "Deploy cannot be rolled back to"],
89
+ deploy_not_updatable: [409, 0, "Deploy cannot change this way"],
90
+ app_host_label_taken: [409, 0, "Address label taken"],
91
+ app_host_label_reserved: [422, 0, "Address label reserved"],
92
+ app_host_conflict: [409, 0, "Address label is fixed"],
93
+ app_host_route_conflict: [409, 1, "Address switched by another call"],
94
+ app_host_not_found: [404, 0, "Address not found"],
95
+ app_host_blocked: [403, 0, "Address blocked"],
96
+ app_host_public_needs_spend_cap: [422, 0, "Public address needs a spend cap"],
97
+ app_host_port_public: [422, 0, "Address port is public"],
98
+ sandbox_routed: [409, 0, "Sandbox serves an address"],
99
+ app_not_found: [404, 0, "No app at this address"],
100
+ app_link_required: [401, 0, "App shared by link"],
101
+ app_deploying: [503, 1, "App not live yet"],
102
+ app_not_running: [503, 1, "App not running"],
103
+ app_blocked: [410, 0, "Address unavailable"],
104
+ app_unavailable: [503, 1, "App unavailable"],
79
105
  authorization_pending: [400, 1, "Authorization pending"],
80
106
  slow_down: [400, 1, "Slow down"],
81
107
  access_denied: [400, 0, "Access denied"],
@@ -114,6 +140,7 @@ exports.ERROR_CATALOG = {
114
140
  capture_failed: [502, 1, "Capture failed"],
115
141
  script_invalid: [422, 0, "Invalid video script"],
116
142
  script_step_failed: [422, 0, "Script step failed"],
143
+ profile_expired: [422, 0, "Profile no longer signs in"],
117
144
  restyle_unavailable: [409, 0, "Restyle not available"],
118
145
  background_unavailable: [503, 1, "Background unavailable"],
119
146
  style_invalid: [422, 0, "Invalid style"],
@@ -130,6 +157,8 @@ exports.ERROR_CATALOG = {
130
157
  guest_outdated: [409, 0, "Sandbox agent predates the operation"],
131
158
  file_too_large: [413, 0, "File too large"],
132
159
  port_not_exposed: [404, 0, "Port not exposed"],
160
+ app_token_invalid: [403, 0, "App address credential refused"],
161
+ upstream_first_byte_timeout: [504, 0, "Upstream first byte timeout"],
133
162
  process_not_found: [404, 0, "Process not found"],
134
163
  kernel_unavailable: [409, 0, "Code kernel unavailable"],
135
164
  language_unsupported: [422, 0, "Language not supported"],
@@ -174,6 +203,9 @@ exports.ERROR_CATALOG = {
174
203
  connection_mismatch: [422, 0, "Connection does not match"],
175
204
  pack_unavailable: [503, 1, "Pack unavailable"],
176
205
  action_expression_error: [422, 0, "Action expression failed"],
206
+ tool_failed: [502, 0, "Hosted tool failed"],
207
+ tool_timed_out: [504, 0, "Hosted tool timed out"],
208
+ tool_unavailable: [503, 1, "Hosted tool unavailable"],
177
209
  connection_not_found: [404, 0, "Connection not found"],
178
210
  connection_invalid: [422, 0, "Invalid connection"],
179
211
  blob_not_found: [404, 0, "Stored object not found"],