@b3os/sdk 0.0.1 → 0.1.3
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/README.md +171 -42
- package/dist/cjs/core/bytes.d.ts +30 -0
- package/dist/cjs/core/bytes.js +115 -0
- package/dist/cjs/core/bytes.js.map +1 -0
- package/dist/cjs/core/client.d.ts +61 -3
- package/dist/cjs/core/client.js +211 -33
- package/dist/cjs/core/client.js.map +1 -1
- package/dist/cjs/core/errors.d.ts +16 -4
- package/dist/cjs/core/errors.js +9 -6
- package/dist/cjs/core/errors.js.map +1 -1
- package/dist/cjs/core/handle.d.ts +31 -0
- package/dist/cjs/core/handle.js +86 -0
- package/dist/cjs/core/handle.js.map +1 -0
- package/dist/cjs/core/index.d.ts +6 -4
- package/dist/cjs/core/index.js +8 -1
- package/dist/cjs/core/index.js.map +1 -1
- package/dist/cjs/core/login.d.ts +24 -0
- package/dist/cjs/core/login.js +93 -0
- package/dist/cjs/core/login.js.map +1 -0
- package/dist/cjs/core/namespace.d.ts +1 -1
- package/dist/cjs/core/namespace.js +1 -1
- package/dist/cjs/core/op.d.ts +11 -1
- package/dist/cjs/core/timing.d.ts +1 -1
- package/dist/cjs/core/timing.js +8 -1
- package/dist/cjs/core/timing.js.map +1 -1
- package/dist/cjs/core/transport.js +1 -1
- package/dist/cjs/core/transport.js.map +1 -1
- package/dist/cjs/core/util.d.ts +15 -3
- package/dist/cjs/core/util.js +54 -2
- package/dist/cjs/core/util.js.map +1 -1
- package/dist/cjs/core/ws.d.ts +4 -0
- package/dist/cjs/core/ws.js +7 -4
- package/dist/cjs/core/ws.js.map +1 -1
- package/dist/cjs/generated/client.d.ts +2 -2
- package/dist/cjs/generated/client.js +2 -2
- package/dist/cjs/generated/errors.d.ts +1 -1
- package/dist/cjs/generated/errors.js +30 -0
- package/dist/cjs/generated/errors.js.map +1 -1
- package/dist/cjs/generated/jobs.js +1 -1
- package/dist/cjs/generated/ns/actions.d.ts +48 -6
- package/dist/cjs/generated/ns/actions.js +59 -6
- package/dist/cjs/generated/ns/actions.js.map +1 -1
- package/dist/cjs/generated/ns/infer.d.ts +185 -54
- package/dist/cjs/generated/ns/infer.js +28 -74
- package/dist/cjs/generated/ns/infer.js.map +1 -1
- package/dist/cjs/generated/ns/keys.d.ts +12 -0
- package/dist/cjs/generated/ns/keys.js +22 -0
- package/dist/cjs/generated/ns/keys.js.map +1 -1
- package/dist/cjs/generated/ns/render.d.ts +95 -6
- package/dist/cjs/generated/ns/render.js +124 -7
- package/dist/cjs/generated/ns/render.js.map +1 -1
- package/dist/cjs/generated/ns/requests.d.ts +3 -1
- package/dist/cjs/generated/ns/requests.js +3 -1
- package/dist/cjs/generated/ns/requests.js.map +1 -1
- package/dist/cjs/generated/ns/routines.d.ts +131 -9
- package/dist/cjs/generated/ns/routines.js +186 -9
- package/dist/cjs/generated/ns/routines.js.map +1 -1
- package/dist/cjs/generated/ns/sandboxes.d.ts +298 -31
- package/dist/cjs/generated/ns/sandboxes.js +368 -29
- package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
- package/dist/cjs/generated/ns/vision.d.ts +133 -14
- package/dist/cjs/generated/ns/vision.js +158 -12
- package/dist/cjs/generated/ns/vision.js.map +1 -1
- package/dist/cjs/generated/ns/webhooks.d.ts +8 -5
- package/dist/cjs/generated/ns/webhooks.js +8 -5
- package/dist/cjs/generated/ns/webhooks.js.map +1 -1
- package/dist/cjs/generated/types.d.ts +1956 -301
- package/dist/cjs/helpers/agents.d.ts +95 -0
- package/dist/cjs/helpers/agents.js +205 -0
- package/dist/cjs/helpers/agents.js.map +1 -0
- package/dist/cjs/helpers/render.d.ts +15 -0
- package/dist/cjs/helpers/render.js +74 -0
- package/dist/cjs/helpers/render.js.map +1 -0
- package/dist/cjs/helpers/routines.d.ts +61 -0
- package/dist/cjs/helpers/routines.js +234 -0
- package/dist/cjs/helpers/routines.js.map +1 -0
- package/dist/cjs/helpers/sandboxes.d.ts +237 -0
- package/dist/cjs/helpers/sandboxes.js +608 -0
- package/dist/cjs/helpers/sandboxes.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.js +8 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/routines.d.ts +1 -0
- package/dist/cjs/routines.js +21 -0
- package/dist/cjs/routines.js.map +1 -0
- package/dist/cjs/webhooks.js.map +1 -1
- package/dist/esm/core/bytes.d.ts +30 -0
- package/dist/esm/core/bytes.js +111 -0
- package/dist/esm/core/bytes.js.map +1 -0
- package/dist/esm/core/client.d.ts +61 -3
- package/dist/esm/core/client.js +208 -31
- package/dist/esm/core/client.js.map +1 -1
- package/dist/esm/core/errors.d.ts +16 -4
- package/dist/esm/core/errors.js +9 -6
- package/dist/esm/core/errors.js.map +1 -1
- package/dist/esm/core/handle.d.ts +31 -0
- package/dist/esm/core/handle.js +82 -0
- package/dist/esm/core/handle.js.map +1 -0
- package/dist/esm/core/index.d.ts +6 -4
- package/dist/esm/core/index.js +4 -2
- package/dist/esm/core/index.js.map +1 -1
- package/dist/esm/core/login.d.ts +24 -0
- package/dist/esm/core/login.js +85 -0
- package/dist/esm/core/login.js.map +1 -0
- package/dist/esm/core/namespace.d.ts +1 -1
- package/dist/esm/core/namespace.js +1 -1
- package/dist/esm/core/op.d.ts +11 -1
- package/dist/esm/core/timing.d.ts +1 -1
- package/dist/esm/core/timing.js +8 -1
- package/dist/esm/core/timing.js.map +1 -1
- package/dist/esm/core/transport.js +1 -1
- package/dist/esm/core/transport.js.map +1 -1
- package/dist/esm/core/util.d.ts +15 -3
- package/dist/esm/core/util.js +48 -1
- package/dist/esm/core/util.js.map +1 -1
- package/dist/esm/core/ws.d.ts +4 -0
- package/dist/esm/core/ws.js +7 -4
- package/dist/esm/core/ws.js.map +1 -1
- package/dist/esm/generated/client.d.ts +2 -2
- package/dist/esm/generated/client.js +2 -2
- package/dist/esm/generated/errors.d.ts +1 -1
- package/dist/esm/generated/errors.js +30 -0
- package/dist/esm/generated/errors.js.map +1 -1
- package/dist/esm/generated/jobs.js +1 -1
- package/dist/esm/generated/ns/actions.d.ts +48 -6
- package/dist/esm/generated/ns/actions.js +59 -6
- package/dist/esm/generated/ns/actions.js.map +1 -1
- package/dist/esm/generated/ns/infer.d.ts +185 -54
- package/dist/esm/generated/ns/infer.js +28 -74
- package/dist/esm/generated/ns/infer.js.map +1 -1
- package/dist/esm/generated/ns/keys.d.ts +12 -0
- package/dist/esm/generated/ns/keys.js +22 -0
- package/dist/esm/generated/ns/keys.js.map +1 -1
- package/dist/esm/generated/ns/render.d.ts +95 -6
- package/dist/esm/generated/ns/render.js +124 -7
- package/dist/esm/generated/ns/render.js.map +1 -1
- package/dist/esm/generated/ns/requests.d.ts +3 -1
- package/dist/esm/generated/ns/requests.js +3 -1
- package/dist/esm/generated/ns/requests.js.map +1 -1
- package/dist/esm/generated/ns/routines.d.ts +131 -9
- package/dist/esm/generated/ns/routines.js +186 -9
- package/dist/esm/generated/ns/routines.js.map +1 -1
- package/dist/esm/generated/ns/sandboxes.d.ts +298 -31
- package/dist/esm/generated/ns/sandboxes.js +368 -29
- package/dist/esm/generated/ns/sandboxes.js.map +1 -1
- package/dist/esm/generated/ns/vision.d.ts +133 -14
- package/dist/esm/generated/ns/vision.js +158 -12
- package/dist/esm/generated/ns/vision.js.map +1 -1
- package/dist/esm/generated/ns/webhooks.d.ts +8 -5
- package/dist/esm/generated/ns/webhooks.js +8 -5
- package/dist/esm/generated/ns/webhooks.js.map +1 -1
- package/dist/esm/generated/types.d.ts +1956 -301
- package/dist/esm/helpers/agents.d.ts +95 -0
- package/dist/esm/helpers/agents.js +199 -0
- package/dist/esm/helpers/agents.js.map +1 -0
- package/dist/esm/helpers/render.d.ts +15 -0
- package/dist/esm/helpers/render.js +70 -0
- package/dist/esm/helpers/render.js.map +1 -0
- package/dist/esm/helpers/routines.d.ts +61 -0
- package/dist/esm/helpers/routines.js +226 -0
- package/dist/esm/helpers/routines.js.map +1 -0
- package/dist/esm/helpers/sandboxes.d.ts +237 -0
- package/dist/esm/helpers/sandboxes.js +600 -0
- package/dist/esm/helpers/sandboxes.js.map +1 -0
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +6 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routines.d.ts +1 -0
- package/dist/esm/routines.js +5 -0
- package/dist/esm/routines.js.map +1 -0
- package/dist/esm/webhooks.js.map +1 -1
- package/package.json +18 -7
- package/src/core/bytes.ts +112 -0
- package/src/core/client.ts +253 -33
- package/src/core/errors.ts +27 -10
- package/src/core/handle.ts +97 -0
- package/src/core/index.ts +7 -2
- package/src/core/login.ts +98 -0
- package/src/core/namespace.ts +1 -1
- package/src/core/op.ts +11 -1
- package/src/core/timing.ts +7 -2
- package/src/core/transport.ts +1 -1
- package/src/core/util.ts +53 -3
- package/src/core/ws.ts +11 -4
- package/src/generated/client.ts +2 -2
- package/src/generated/errors.ts +60 -0
- package/src/generated/jobs.ts +1 -1
- package/src/generated/ns/actions.ts +69 -6
- package/src/generated/ns/infer.ts +229 -61
- package/src/generated/ns/keys.ts +23 -0
- package/src/generated/ns/render.ts +152 -7
- package/src/generated/ns/requests.ts +3 -1
- package/src/generated/ns/routines.ts +205 -9
- package/src/generated/ns/sandboxes.ts +434 -34
- package/src/generated/ns/vision.ts +168 -14
- package/src/generated/ns/webhooks.ts +8 -5
- package/src/generated/types.ts +2211 -422
- package/src/helpers/agents.ts +300 -0
- package/src/helpers/render.ts +91 -0
- package/src/helpers/routines.ts +278 -0
- package/src/helpers/sandboxes.ts +788 -0
- package/src/index.ts +29 -5
- package/src/routines.ts +5 -0
- package/src/webhooks.ts +5 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// The `b3os login` token as the credential of last resort. The CLI keeps it in $XDG_CONFIG_HOME/b3os/credentials.json
|
|
2
|
+
// (default ~/.config/b3os/; B3OS_CREDENTIALS_FILE moves it), and the local MCP server reads the same file
|
|
3
|
+
// (packages/mcp/src/stdio.ts). The SDK reads it only on a developer's machine: never in CI, on a GitHub Actions
|
|
4
|
+
// runner or inside a B3OS sandbox, where code should run on a key made for it. It needs a file system, so Node, Bun
|
|
5
|
+
// and Deno only; nothing here imports a Node module statically.
|
|
6
|
+
|
|
7
|
+
import type * as NodeFs from "node:fs";
|
|
8
|
+
import type * as NodeOs from "node:os";
|
|
9
|
+
import type * as NodePath from "node:path";
|
|
10
|
+
import { builtin, env } from "./util.ts";
|
|
11
|
+
|
|
12
|
+
export interface StoredLogin {
|
|
13
|
+
/** `b3os_pat_…` from the device login. */
|
|
14
|
+
token: string;
|
|
15
|
+
/** The API host the token belongs to (the file's `base_url`), without a trailing slash. */
|
|
16
|
+
baseUrl: string | undefined;
|
|
17
|
+
/** The file it was read from. */
|
|
18
|
+
file: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** CI services that do not set `CI` themselves. */
|
|
22
|
+
const CI_MARKERS = ["JENKINS_URL", "TF_BUILD", "CODEBUILD_BUILD_ID", "TEAMCITY_VERSION"];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Where the stored login is never read: "a B3OS sandbox" (B3OS sets `B3OS_SANDBOX_ID` and `B3OS_API_URL` in every
|
|
26
|
+
* sandbox), "GitHub Actions" (`GITHUB_ACTIONS`), "CI" (`CI` set to anything but `false` or `0`, or a CI service's own
|
|
27
|
+
* variable), or undefined on a developer's machine.
|
|
28
|
+
*/
|
|
29
|
+
export function loginBlockedBy(): string | undefined {
|
|
30
|
+
if (env("B3OS_SANDBOX_ID") || env("B3OS_API_URL")) return "a B3OS sandbox";
|
|
31
|
+
if (env("GITHUB_ACTIONS")) return "GitHub Actions";
|
|
32
|
+
const ci = env("CI")?.toLowerCase();
|
|
33
|
+
if ((ci && ci !== "false" && ci !== "0") || CI_MARKERS.some((v) => env(v))) return "CI";
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The credentials file `b3os login` writes, or undefined where there is no file system. */
|
|
38
|
+
export function credentialsFile(): string | undefined {
|
|
39
|
+
const explicit = env("B3OS_CREDENTIALS_FILE");
|
|
40
|
+
if (explicit) return explicit;
|
|
41
|
+
try {
|
|
42
|
+
const path = builtin<typeof NodePath>("node:path");
|
|
43
|
+
const os = builtin<typeof NodeOs>("node:os");
|
|
44
|
+
if (!path || !os) return undefined;
|
|
45
|
+
return path.join(env("XDG_CONFIG_HOME") ?? path.join(os.homedir(), ".config"), "b3os", "credentials.json");
|
|
46
|
+
} catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** True when this runtime can read the credentials file at all. */
|
|
52
|
+
export function canReadLogin(): boolean {
|
|
53
|
+
return builtin("node:fs") !== undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The stored login when there is one and it has not expired. Never throws. */
|
|
57
|
+
export function readStoredLogin(): StoredLogin | undefined {
|
|
58
|
+
try {
|
|
59
|
+
const fs = builtin<typeof NodeFs>("node:fs");
|
|
60
|
+
const file = credentialsFile();
|
|
61
|
+
if (!fs || !file) return undefined;
|
|
62
|
+
const c = JSON.parse(fs.readFileSync(file, "utf8")) as {
|
|
63
|
+
token?: unknown;
|
|
64
|
+
base_url?: unknown;
|
|
65
|
+
expires_at?: unknown;
|
|
66
|
+
};
|
|
67
|
+
if (typeof c.token !== "string" || !c.token) return undefined;
|
|
68
|
+
if (typeof c.expires_at === "string" && Date.parse(c.expires_at) < Date.now()) return undefined;
|
|
69
|
+
const baseUrl = typeof c.base_url === "string" && c.base_url ? c.base_url.replace(/\/+$/, "") : undefined;
|
|
70
|
+
return { token: c.token, baseUrl, file };
|
|
71
|
+
} catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let announced = false;
|
|
77
|
+
|
|
78
|
+
/** The one stderr line per process that says the stored login is in use, and where it is not. */
|
|
79
|
+
export function announceLogin(login: StoredLogin, shownToken: string): void {
|
|
80
|
+
if (announced) return;
|
|
81
|
+
announced = true;
|
|
82
|
+
let file = login.file;
|
|
83
|
+
try {
|
|
84
|
+
const home = builtin<typeof NodeOs>("node:os")?.homedir();
|
|
85
|
+
if (home && file.startsWith(`${home}/`)) file = `~${file.slice(home.length)}`;
|
|
86
|
+
} catch {
|
|
87
|
+
// the full path is fine
|
|
88
|
+
}
|
|
89
|
+
console.warn(
|
|
90
|
+
`@b3os/sdk: no API key set, so using your b3os login (${shownToken}, ${file}). ` +
|
|
91
|
+
"CI and B3OS sandboxes never read it: set B3OS_API_KEY there.",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Tests only: let the next login announce itself again. */
|
|
96
|
+
export function resetLoginNotice(): void {
|
|
97
|
+
announced = false;
|
|
98
|
+
}
|
package/src/core/namespace.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { B3OSCore } from "./client.ts";
|
|
2
2
|
|
|
3
|
-
/** Base of every generated namespace (`
|
|
3
|
+
/** Base of every generated namespace (`b3os.vision`, `b3os.sandboxes`, …). Construct one on a core client to use a
|
|
4
4
|
* single product without the rest: `new SandboxesAPI(new B3OSCore())`. */
|
|
5
5
|
export abstract class Namespace {
|
|
6
6
|
protected readonly _client: B3OSCore;
|
package/src/core/op.ts
CHANGED
|
@@ -21,6 +21,10 @@ export interface Op {
|
|
|
21
21
|
readonly wildcard?: string;
|
|
22
22
|
/** Header parameters: option key → header name (`format` → `X-B3OS-Format`). */
|
|
23
23
|
readonly headerParams?: Readonly<Record<string, string>>;
|
|
24
|
+
/** Query parameters with `style: deepObject`: an object value is sent as `name[key]=value` pairs. */
|
|
25
|
+
readonly deepObject?: readonly string[];
|
|
26
|
+
/** Query parameters the API takes as 0 or 1 (`list`, `mkdir`, `recursive`): a boolean is sent as `1` or `0`. */
|
|
27
|
+
readonly flags?: readonly string[];
|
|
24
28
|
/** Request body kind. */
|
|
25
29
|
readonly body?: "json" | "bytes" | "yaml";
|
|
26
30
|
/** Content type of a binary body (`application/octet-stream`, `application/gzip`). */
|
|
@@ -29,11 +33,17 @@ export interface Op {
|
|
|
29
33
|
readonly edge?: boolean;
|
|
30
34
|
/** Accepts `Idempotency-Key`; the SDK sends one (generated unless you pass your own), so retries are safe. */
|
|
31
35
|
readonly idem?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* `x-b3os-idempotency: caller` (sandboxesExec): no generated key (yours is sent), and the call is resent only
|
|
38
|
+
* after an answer that shows it did no work, never after a node error, an error page (the edge's 503
|
|
39
|
+
* `node_unavailable` included), a timeout or a connection lost after the request was sent.
|
|
40
|
+
*/
|
|
41
|
+
readonly callerKey?: boolean;
|
|
32
42
|
readonly stream?: "sse" | "ws";
|
|
33
43
|
/** `x-b3os-timeout-ms`. */
|
|
34
44
|
readonly timeoutMs: number;
|
|
35
45
|
/** Error body shape when not RFC 9457. */
|
|
36
|
-
readonly errorFormat?: "openai" | "oauth2" | "firecrawl";
|
|
46
|
+
readonly errorFormat?: "openai" | "anthropic" | "oauth2" | "firecrawl";
|
|
37
47
|
/** Job companions (`x-b3os-job-ops`). */
|
|
38
48
|
readonly job?: JobOps;
|
|
39
49
|
/** `x-b3os-stage: stretch`: in the contract, may answer `501 not_implemented`. */
|
package/src/core/timing.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// W3C Server-Timing parsing (https://www.w3.org/TR/server-timing/). B3OS sends one metric per phase with `dur` in
|
|
2
2
|
// milliseconds; `total` is the node's request-head-to-response-head time for bodies of known size, and the edge
|
|
3
|
-
// prepends `edge_auth` and `edge_upstream` (ARCHITECTURE §4.1, §6).
|
|
3
|
+
// prepends `edge_auth` and `edge_upstream` (ARCHITECTURE §4.1, §6). A response the edge answers itself names the colo
|
|
4
|
+
// in `edge_colo;desc=...` and, when nothing was measured, says `edge;desc="answered at edge"` with no `total`: metrics
|
|
5
|
+
// without a `dur` are annotations, so they appear in `entries` but never as a phase or in `edge_ms`.
|
|
4
6
|
|
|
5
7
|
export interface ServerTimingEntry {
|
|
6
8
|
name: string;
|
|
@@ -12,7 +14,7 @@ export interface ServerTimingEntry {
|
|
|
12
14
|
export interface ServerTiming {
|
|
13
15
|
/** Every metric in header order. */
|
|
14
16
|
entries: ServerTimingEntry[];
|
|
15
|
-
/** `name → dur` for every metric except `total` (later duplicates are summed). */
|
|
17
|
+
/** `name → dur` for every metric that carries a `dur`, except `total` (later duplicates are summed). */
|
|
16
18
|
phases: Record<string, number>;
|
|
17
19
|
/** The `total` metric, or null when the response had none (streams report their totals in the final event). */
|
|
18
20
|
total_ms: number | null;
|
|
@@ -60,6 +62,7 @@ const TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
|
60
62
|
/** Parses one or more `Server-Timing` header values. Malformed metrics are skipped, never thrown. */
|
|
61
63
|
export function parseServerTiming(header: string | string[] | null | undefined): ServerTiming {
|
|
62
64
|
const entries: ServerTimingEntry[] = [];
|
|
65
|
+
const annotations = new Set<ServerTimingEntry>();
|
|
63
66
|
const values = header == null ? [] : Array.isArray(header) ? header : [header];
|
|
64
67
|
for (const value of values) {
|
|
65
68
|
for (const metric of splitOutsideQuotes(value, ",")) {
|
|
@@ -81,6 +84,7 @@ export function parseServerTiming(header: string | string[] | null | undefined):
|
|
|
81
84
|
entry.desc = raw;
|
|
82
85
|
}
|
|
83
86
|
}
|
|
87
|
+
if (!seen.has("dur")) annotations.add(entry);
|
|
84
88
|
entries.push(entry);
|
|
85
89
|
}
|
|
86
90
|
}
|
|
@@ -88,6 +92,7 @@ export function parseServerTiming(header: string | string[] | null | undefined):
|
|
|
88
92
|
let total: number | null = null;
|
|
89
93
|
let edge: number | null = null;
|
|
90
94
|
for (const e of entries) {
|
|
95
|
+
if (annotations.has(e)) continue;
|
|
91
96
|
if (e.name === "total") {
|
|
92
97
|
total = e.dur;
|
|
93
98
|
continue;
|
package/src/core/transport.ts
CHANGED
|
@@ -331,7 +331,7 @@ export class NodeHttpTransport implements Transport {
|
|
|
331
331
|
/** Over a Unix socket (`{socketPath}`) or to a plain-HTTP base URL (`{baseUrl}`). */
|
|
332
332
|
constructor(target: { socketPath: string } | { baseUrl: string }) {
|
|
333
333
|
const http = builtin<typeof NodeHttp>("node:http");
|
|
334
|
-
if (!http) throw new Error("@b3os/sdk: this transport needs node:http (Node
|
|
334
|
+
if (!http) throw new Error("@b3os/sdk: this transport needs node:http (Node 22.3+)");
|
|
335
335
|
this.http = http;
|
|
336
336
|
// Pooled sockets idle for 20-25 s are closed by a sweep, before b3osd's 30 s header-read timeout can close one
|
|
337
337
|
// under a new request. The agent's `timeout` option would do the same, but it costs every request a listener
|
package/src/core/util.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Small runtime helpers shared by the core. Nothing here imports a Node module statically, so the package loads
|
|
2
2
|
// unchanged on Node, Bun, Deno, Cloudflare Workers and browsers.
|
|
3
3
|
|
|
4
|
-
export const SDK_VERSION = "0.
|
|
4
|
+
export const SDK_VERSION = "0.1.3";
|
|
5
5
|
|
|
6
6
|
interface ProcessLike {
|
|
7
7
|
env?: Record<string, string | undefined>;
|
|
@@ -78,6 +78,42 @@ export function uuid(): string {
|
|
|
78
78
|
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/** `n` random bytes as lower-case hex, never all zeros (W3C trace context forbids all-zero ids). */
|
|
82
|
+
function randomHex(n: number): string {
|
|
83
|
+
const c = globalThis.crypto as typeof globalThis.crypto | undefined;
|
|
84
|
+
const b = new Uint8Array(n);
|
|
85
|
+
for (;;) {
|
|
86
|
+
if (c && typeof c.getRandomValues === "function") c.getRandomValues(b);
|
|
87
|
+
// Trace ids identify, they do not authorize: Math.random is enough where no CSPRNG exists.
|
|
88
|
+
else for (let i = 0; i < n; i++) b[i] = Math.floor(Math.random() * 256);
|
|
89
|
+
if (b.some((x) => x !== 0)) return Array.from(b, (x: number) => x.toString(16).padStart(2, "0")).join("");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A W3C trace-id: 32 hex digits. */
|
|
94
|
+
export function newTraceId(): string {
|
|
95
|
+
return randomHex(16);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A W3C parent-id (span id): 16 hex digits. */
|
|
99
|
+
export function newSpanId(): string {
|
|
100
|
+
return randomHex(8);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A sampled W3C `traceparent` (version 00) in trace `traceId`, with a new span id. */
|
|
104
|
+
export function traceparentIn(traceId: string): string {
|
|
105
|
+
return `00-${traceId}-${newSpanId()}-01`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** `traceparent` as W3C Trace Context level 1 defines version 00 (lower-case hex, non-zero ids). */
|
|
109
|
+
export const TRACEPARENT_RE = /^00-(?!0{32})[0-9a-f]{32}-(?!0{16})[0-9a-f]{16}-[0-9a-f]{2}$/;
|
|
110
|
+
|
|
111
|
+
/** The trace-id of a valid version-00 `traceparent`, else undefined. */
|
|
112
|
+
export function traceIdOf(traceparent: string | undefined): string | undefined {
|
|
113
|
+
const t = traceparent?.trim().toLowerCase();
|
|
114
|
+
return t && TRACEPARENT_RE.test(t) ? t.slice(3, 35) : undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
81
117
|
/** Resolves after `ms`, or rejects with the signal's reason when it aborts first. */
|
|
82
118
|
export function sleep(ms: number, signal?: AbortSignal): Promise<void> {
|
|
83
119
|
return new Promise((resolve, reject) => {
|
|
@@ -117,8 +153,11 @@ export function isObject(v: unknown): v is Record<string, unknown> {
|
|
|
117
153
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
118
154
|
}
|
|
119
155
|
|
|
120
|
-
|
|
121
|
-
|
|
156
|
+
// Typed through the global value, which each project's own lib declares: an inferred type would be written into the
|
|
157
|
+
// .d.ts as @types/node's `import("util").TextDecoder`, which a Workers or browser project without @types/node
|
|
158
|
+
// cannot resolve (dx#8).
|
|
159
|
+
export const textDecoder: InstanceType<typeof TextDecoder> = new TextDecoder();
|
|
160
|
+
export const textEncoder: InstanceType<typeof TextEncoder> = new TextEncoder();
|
|
122
161
|
|
|
123
162
|
export function concatBytes(chunks: Uint8Array[], total?: number): Uint8Array {
|
|
124
163
|
if (chunks.length === 1 && chunks[0]) return chunks[0];
|
|
@@ -136,3 +175,14 @@ export function concatBytes(chunks: Uint8Array[], total?: number): Uint8Array {
|
|
|
136
175
|
export function camel(s: string): string {
|
|
137
176
|
return s.replace(/[-_]([a-z0-9])/g, (_, c: string) => c.toUpperCase());
|
|
138
177
|
}
|
|
178
|
+
|
|
179
|
+
/** A transport error as one line: its code and the cause's message when they add something. */
|
|
180
|
+
export function describeErr(err: unknown): string {
|
|
181
|
+
if (err instanceof Error) {
|
|
182
|
+
const cause = (err as Error & { cause?: { code?: string; message?: string } }).cause;
|
|
183
|
+
const code = (err as { code?: string }).code ?? cause?.code;
|
|
184
|
+
const msg = cause?.message && cause.message !== err.message ? `${err.message} (${cause.message})` : err.message;
|
|
185
|
+
return code && !msg.includes(code) ? `${code}: ${msg}` : msg;
|
|
186
|
+
}
|
|
187
|
+
return String(err);
|
|
188
|
+
}
|
package/src/core/ws.ts
CHANGED
|
@@ -94,7 +94,10 @@ export function openSocket(url: string, protocols: string[], signal?: AbortSigna
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
export interface PtyExit {
|
|
97
|
+
/** The shell's exit code; `null` when it was killed by a signal or when no exit message came. */
|
|
97
98
|
code: number | null;
|
|
99
|
+
/** True when the server sent the exit message; false when the socket closed without one (a lost connection). */
|
|
100
|
+
exited: boolean;
|
|
98
101
|
/** WebSocket close code and reason when the socket closed without an exit message. */
|
|
99
102
|
closeCode?: number;
|
|
100
103
|
closeReason?: string;
|
|
@@ -112,6 +115,7 @@ export class PtySession implements AsyncIterable<Uint8Array> {
|
|
|
112
115
|
private iterated = false;
|
|
113
116
|
private queued = 0;
|
|
114
117
|
private exitCode: number | null = null;
|
|
118
|
+
private exited = false;
|
|
115
119
|
private readonly listeners = new Set<(chunk: Uint8Array) => void>();
|
|
116
120
|
readonly socket: WebSocket;
|
|
117
121
|
|
|
@@ -126,7 +130,10 @@ export class PtySession implements AsyncIterable<Uint8Array> {
|
|
|
126
130
|
if (typeof d === "string") {
|
|
127
131
|
try {
|
|
128
132
|
const msg = JSON.parse(d) as { type?: string; code?: number };
|
|
129
|
-
if (msg.type === "exit")
|
|
133
|
+
if (msg.type === "exit") {
|
|
134
|
+
this.exited = true;
|
|
135
|
+
this.exitCode = typeof msg.code === "number" ? msg.code : null;
|
|
136
|
+
}
|
|
130
137
|
} catch {
|
|
131
138
|
this.push(textEncoder.encode(d));
|
|
132
139
|
}
|
|
@@ -140,9 +147,9 @@ export class PtySession implements AsyncIterable<Uint8Array> {
|
|
|
140
147
|
for (const w of this.waiters) w({ value: undefined, done: true });
|
|
141
148
|
this.waiters = [];
|
|
142
149
|
settle(
|
|
143
|
-
this.
|
|
144
|
-
? { code: this.exitCode }
|
|
145
|
-
: { code: null, closeCode: ev.code, closeReason: ev.reason || undefined },
|
|
150
|
+
this.exited
|
|
151
|
+
? { code: this.exitCode, exited: true }
|
|
152
|
+
: { code: null, exited: false, closeCode: ev.code, closeReason: ev.reason || undefined },
|
|
146
153
|
);
|
|
147
154
|
});
|
|
148
155
|
}
|
package/src/generated/client.ts
CHANGED
|
@@ -24,8 +24,8 @@ import { WebhooksAPI } from "./ns/webhooks.ts";
|
|
|
24
24
|
*
|
|
25
25
|
* ```ts
|
|
26
26
|
* import { B3OS } from "@b3os/sdk";
|
|
27
|
-
* const
|
|
28
|
-
* const page = await
|
|
27
|
+
* const b3os = new B3OS();
|
|
28
|
+
* const page = await b3os.vision.scrape({ url: "https://example.com" });
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
export class B3OS extends B3OSCore {
|
package/src/generated/errors.ts
CHANGED
|
@@ -11,12 +11,16 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
|
|
|
11
11
|
not_acceptable: [406, 0, "Not acceptable"],
|
|
12
12
|
payload_too_large: [413, 0, "Payload too large"],
|
|
13
13
|
route_not_found: [404, 0, "Route not found"],
|
|
14
|
+
feature_not_enabled: [404, 0, "Feature not enabled"],
|
|
14
15
|
method_not_allowed: [405, 0, "Method not allowed"],
|
|
15
16
|
edge_only: [421, 0, "Served by beta-api.b3os.org"],
|
|
16
17
|
limit_exceeded: [422, 0, "Limit exceeded"],
|
|
18
|
+
option_not_allowed: [422, 0, "Option not allowed"],
|
|
17
19
|
idempotency_key_invalid: [400, 0, "Invalid idempotency key"],
|
|
18
20
|
idempotency_key_conflict: [409, 0, "Idempotency key conflict"],
|
|
19
21
|
idempotency_request_in_progress: [409, 1, "Request in progress"],
|
|
22
|
+
idempotency_response_evicted: [409, 0, "Stored response evicted"],
|
|
23
|
+
idempotency_outcome_unknown: [409, 0, "Outcome unknown"],
|
|
20
24
|
conflict: [409, 0, "Conflict"],
|
|
21
25
|
resource_not_found: [404, 0, "Not found"],
|
|
22
26
|
not_implemented: [501, 0, "Not implemented"],
|
|
@@ -68,6 +72,10 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
|
|
|
68
72
|
pack_signature_invalid: [422, 0, "Invalid pack signature"],
|
|
69
73
|
org_suspended: [403, 0, "Organization suspended"],
|
|
70
74
|
hook_queue_full: [503, 1, "Webhook queue full"],
|
|
75
|
+
email_unavailable: [503, 1, "Email sign-in unavailable"],
|
|
76
|
+
turnstile_required: [400, 0, "Turnstile token required"],
|
|
77
|
+
turnstile_failed: [403, 0, "Turnstile check failed"],
|
|
78
|
+
turnstile_unavailable: [503, 1, "Turnstile unavailable"],
|
|
71
79
|
authorization_pending: [400, 1, "Authorization pending"],
|
|
72
80
|
slow_down: [400, 1, "Slow down"],
|
|
73
81
|
access_denied: [400, 0, "Access denied"],
|
|
@@ -81,6 +89,7 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
|
|
|
81
89
|
profile_domain_mismatch: [422, 0, "Profile domain mismatch"],
|
|
82
90
|
profile_conflict: [409, 0, "Profile changed since it was loaded"],
|
|
83
91
|
profile_name_taken: [409, 0, "Profile name taken"],
|
|
92
|
+
profile_not_exportable: [403, 0, "Profile not exportable"],
|
|
84
93
|
crawl_not_found: [404, 0, "Crawl not found"],
|
|
85
94
|
batch_not_found: [404, 0, "Batch scrape not found"],
|
|
86
95
|
robots_disallowed: [403, 0, "Disallowed by robots.txt"],
|
|
@@ -88,10 +97,16 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
|
|
|
88
97
|
navigation_failed: [502, 1, "Navigation failed"],
|
|
89
98
|
scrape_timeout: [504, 1, "Scrape timed out"],
|
|
90
99
|
target_not_found: [422, 0, "Target not found"],
|
|
100
|
+
target_covered: [422, 0, "Target covered"],
|
|
101
|
+
stale_ref: [422, 0, "Stale ref"],
|
|
91
102
|
act_step_failed: [422, 0, "Browser action failed"],
|
|
92
103
|
cdp_method_blocked: [403, 0, "CDP method not allowed"],
|
|
93
104
|
extraction_failed: [502, 1, "Extraction failed"],
|
|
94
105
|
scrape_no_cached_data: [404, 0, "No cached copy"],
|
|
106
|
+
scrape_lockdown_cache_miss: [404, 0, "Not in the cache (lockdown)"],
|
|
107
|
+
search_unavailable: [503, 1, "Search unavailable"],
|
|
108
|
+
search_failed: [502, 1, "Search failed"],
|
|
109
|
+
search_answer_too_large: [413, 0, "Search answer too large"],
|
|
95
110
|
screenshot_not_found: [404, 0, "Screenshot not found"],
|
|
96
111
|
video_not_found: [404, 0, "Video not found"],
|
|
97
112
|
artifact_not_found: [404, 0, "Artifact not found"],
|
|
@@ -100,14 +115,19 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
|
|
|
100
115
|
script_invalid: [422, 0, "Invalid video script"],
|
|
101
116
|
script_step_failed: [422, 0, "Script step failed"],
|
|
102
117
|
restyle_unavailable: [409, 0, "Restyle not available"],
|
|
118
|
+
background_unavailable: [503, 1, "Background unavailable"],
|
|
103
119
|
style_invalid: [422, 0, "Invalid style"],
|
|
104
120
|
sandbox_not_found: [404, 0, "Sandbox not found"],
|
|
105
121
|
sandbox_not_running: [409, 0, "Sandbox not running"],
|
|
106
122
|
template_not_found: [404, 0, "Template not found"],
|
|
107
123
|
snapshot_not_found: [404, 0, "Snapshot not found"],
|
|
124
|
+
snapshot_damaged: [409, 0, "Snapshot damaged"],
|
|
108
125
|
file_not_found: [404, 0, "File not found"],
|
|
109
126
|
path_invalid: [422, 0, "Invalid path"],
|
|
110
127
|
not_a_directory: [422, 0, "Not a directory"],
|
|
128
|
+
file_exists: [409, 0, "File exists"],
|
|
129
|
+
directory_not_empty: [409, 0, "Directory not empty"],
|
|
130
|
+
guest_outdated: [409, 0, "Sandbox agent predates the operation"],
|
|
111
131
|
file_too_large: [413, 0, "File too large"],
|
|
112
132
|
port_not_exposed: [404, 0, "Port not exposed"],
|
|
113
133
|
process_not_found: [404, 0, "Process not found"],
|
|
@@ -116,6 +136,7 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
|
|
|
116
136
|
guest_unreachable: [502, 1, "Sandbox agent unreachable"],
|
|
117
137
|
snapshot_failed: [500, 1, "Snapshot failed"],
|
|
118
138
|
fork_unavailable: [409, 0, "Fork not available"],
|
|
139
|
+
envd_token_invalid: [401, 0, "envd access token invalid"],
|
|
119
140
|
routine_not_found: [404, 0, "Routine not found"],
|
|
120
141
|
routine_version_not_found: [404, 0, "Routine version not found"],
|
|
121
142
|
run_not_found: [404, 0, "Run not found"],
|
|
@@ -123,6 +144,14 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
|
|
|
123
144
|
routine_invalid: [422, 0, "Invalid routine"],
|
|
124
145
|
routine_name_taken: [409, 0, "Routine name taken"],
|
|
125
146
|
run_not_waiting: [409, 0, "Run is not waiting for this signal"],
|
|
147
|
+
event_fan_out_too_large: [422, 0, "Event fans out too far"],
|
|
148
|
+
wait_link_invalid: [404, 0, "Wait link not valid"],
|
|
149
|
+
wait_not_ready: [409, 1, "Wait not ready"],
|
|
150
|
+
wait_already_answered: [410, 0, "Wait already answered"],
|
|
151
|
+
wait_link_expired: [410, 0, "Wait link expired"],
|
|
152
|
+
run_not_finished: [409, 0, "Run not finished"],
|
|
153
|
+
run_steps_not_kept: [410, 0, "Run steps not kept"],
|
|
154
|
+
replay_too_large: [422, 0, "Replay too large"],
|
|
126
155
|
run_as_revoked: [403, 0, "Publishing key revoked"],
|
|
127
156
|
webhook_signature_invalid: [401, 0, "Webhook verification failed"],
|
|
128
157
|
step_failed: [422, 0, "Step failed"],
|
|
@@ -130,6 +159,7 @@ export const ERROR_CATALOG: Readonly<Record<string, readonly [status: number, re
|
|
|
130
159
|
run_input_invalid: [422, 0, "Invalid run input"],
|
|
131
160
|
step_timed_out: [504, 1, "Step timed out"],
|
|
132
161
|
step_outcome_unknown: [409, 0, "Step outcome unknown"],
|
|
162
|
+
internal_recovery_failed: [500, 0, "Recovery failed"],
|
|
133
163
|
hook_attestation_unverifiable: [503, 1, "Webhook replay cannot be checked yet"],
|
|
134
164
|
pack_not_found: [404, 0, "Pack not found"],
|
|
135
165
|
pack_version_not_found: [404, 0, "Pack version not found"],
|
|
@@ -166,12 +196,16 @@ export type B3OSServerErrorCode =
|
|
|
166
196
|
| "not_acceptable"
|
|
167
197
|
| "payload_too_large"
|
|
168
198
|
| "route_not_found"
|
|
199
|
+
| "feature_not_enabled"
|
|
169
200
|
| "method_not_allowed"
|
|
170
201
|
| "edge_only"
|
|
171
202
|
| "limit_exceeded"
|
|
203
|
+
| "option_not_allowed"
|
|
172
204
|
| "idempotency_key_invalid"
|
|
173
205
|
| "idempotency_key_conflict"
|
|
174
206
|
| "idempotency_request_in_progress"
|
|
207
|
+
| "idempotency_response_evicted"
|
|
208
|
+
| "idempotency_outcome_unknown"
|
|
175
209
|
| "conflict"
|
|
176
210
|
| "resource_not_found"
|
|
177
211
|
| "not_implemented"
|
|
@@ -223,6 +257,10 @@ export type B3OSServerErrorCode =
|
|
|
223
257
|
| "pack_signature_invalid"
|
|
224
258
|
| "org_suspended"
|
|
225
259
|
| "hook_queue_full"
|
|
260
|
+
| "email_unavailable"
|
|
261
|
+
| "turnstile_required"
|
|
262
|
+
| "turnstile_failed"
|
|
263
|
+
| "turnstile_unavailable"
|
|
226
264
|
| "authorization_pending"
|
|
227
265
|
| "slow_down"
|
|
228
266
|
| "access_denied"
|
|
@@ -236,6 +274,7 @@ export type B3OSServerErrorCode =
|
|
|
236
274
|
| "profile_domain_mismatch"
|
|
237
275
|
| "profile_conflict"
|
|
238
276
|
| "profile_name_taken"
|
|
277
|
+
| "profile_not_exportable"
|
|
239
278
|
| "crawl_not_found"
|
|
240
279
|
| "batch_not_found"
|
|
241
280
|
| "robots_disallowed"
|
|
@@ -243,10 +282,16 @@ export type B3OSServerErrorCode =
|
|
|
243
282
|
| "navigation_failed"
|
|
244
283
|
| "scrape_timeout"
|
|
245
284
|
| "target_not_found"
|
|
285
|
+
| "target_covered"
|
|
286
|
+
| "stale_ref"
|
|
246
287
|
| "act_step_failed"
|
|
247
288
|
| "cdp_method_blocked"
|
|
248
289
|
| "extraction_failed"
|
|
249
290
|
| "scrape_no_cached_data"
|
|
291
|
+
| "scrape_lockdown_cache_miss"
|
|
292
|
+
| "search_unavailable"
|
|
293
|
+
| "search_failed"
|
|
294
|
+
| "search_answer_too_large"
|
|
250
295
|
| "screenshot_not_found"
|
|
251
296
|
| "video_not_found"
|
|
252
297
|
| "artifact_not_found"
|
|
@@ -255,14 +300,19 @@ export type B3OSServerErrorCode =
|
|
|
255
300
|
| "script_invalid"
|
|
256
301
|
| "script_step_failed"
|
|
257
302
|
| "restyle_unavailable"
|
|
303
|
+
| "background_unavailable"
|
|
258
304
|
| "style_invalid"
|
|
259
305
|
| "sandbox_not_found"
|
|
260
306
|
| "sandbox_not_running"
|
|
261
307
|
| "template_not_found"
|
|
262
308
|
| "snapshot_not_found"
|
|
309
|
+
| "snapshot_damaged"
|
|
263
310
|
| "file_not_found"
|
|
264
311
|
| "path_invalid"
|
|
265
312
|
| "not_a_directory"
|
|
313
|
+
| "file_exists"
|
|
314
|
+
| "directory_not_empty"
|
|
315
|
+
| "guest_outdated"
|
|
266
316
|
| "file_too_large"
|
|
267
317
|
| "port_not_exposed"
|
|
268
318
|
| "process_not_found"
|
|
@@ -271,6 +321,7 @@ export type B3OSServerErrorCode =
|
|
|
271
321
|
| "guest_unreachable"
|
|
272
322
|
| "snapshot_failed"
|
|
273
323
|
| "fork_unavailable"
|
|
324
|
+
| "envd_token_invalid"
|
|
274
325
|
| "routine_not_found"
|
|
275
326
|
| "routine_version_not_found"
|
|
276
327
|
| "run_not_found"
|
|
@@ -278,6 +329,14 @@ export type B3OSServerErrorCode =
|
|
|
278
329
|
| "routine_invalid"
|
|
279
330
|
| "routine_name_taken"
|
|
280
331
|
| "run_not_waiting"
|
|
332
|
+
| "event_fan_out_too_large"
|
|
333
|
+
| "wait_link_invalid"
|
|
334
|
+
| "wait_not_ready"
|
|
335
|
+
| "wait_already_answered"
|
|
336
|
+
| "wait_link_expired"
|
|
337
|
+
| "run_not_finished"
|
|
338
|
+
| "run_steps_not_kept"
|
|
339
|
+
| "replay_too_large"
|
|
281
340
|
| "run_as_revoked"
|
|
282
341
|
| "webhook_signature_invalid"
|
|
283
342
|
| "step_failed"
|
|
@@ -285,6 +344,7 @@ export type B3OSServerErrorCode =
|
|
|
285
344
|
| "run_input_invalid"
|
|
286
345
|
| "step_timed_out"
|
|
287
346
|
| "step_outcome_unknown"
|
|
347
|
+
| "internal_recovery_failed"
|
|
288
348
|
| "hook_attestation_unverifiable"
|
|
289
349
|
| "pack_not_found"
|
|
290
350
|
| "pack_version_not_found"
|
package/src/generated/jobs.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const JOB_OPS: Readonly<Record<string, JobOps>> = {
|
|
|
10
10
|
batch: visionOps.createBatch.job as JobOps,
|
|
11
11
|
crawl: visionOps.createCrawl.job as JobOps,
|
|
12
12
|
vid: renderOps.createVideo.job as JobOps,
|
|
13
|
-
run: routinesOps.
|
|
13
|
+
run: routinesOps.replayRun.job as JobOps,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -37,6 +37,15 @@ const getPackOp: Op = {
|
|
|
37
37
|
timeoutMs: 10000,
|
|
38
38
|
scope: "actions:read",
|
|
39
39
|
};
|
|
40
|
+
const getPackToolsOp: Op = {
|
|
41
|
+
id: "actionsGetPackTools",
|
|
42
|
+
method: "GET",
|
|
43
|
+
path: "/v1/actions/packs/{namespace}/{name}/tools",
|
|
44
|
+
params: ["namespace", "name"],
|
|
45
|
+
headerParams: { if_none_match: "If-None-Match" },
|
|
46
|
+
timeoutMs: 10000,
|
|
47
|
+
scope: "actions:read",
|
|
48
|
+
};
|
|
40
49
|
const getPackManifestOp: Op = {
|
|
41
50
|
id: "actionsGetPackManifest",
|
|
42
51
|
method: "GET",
|
|
@@ -126,6 +135,7 @@ export const actionsOps = {
|
|
|
126
135
|
describe: describeOp,
|
|
127
136
|
listPacks: listPacksOp,
|
|
128
137
|
getPack: getPackOp,
|
|
138
|
+
getPackTools: getPackToolsOp,
|
|
129
139
|
getPackManifest: getPackManifestOp,
|
|
130
140
|
listRegistryPacks: listRegistryPacksOp,
|
|
131
141
|
publishPack: publishPackOp,
|
|
@@ -145,10 +155,27 @@ export class ActionsAPI extends Namespace {
|
|
|
145
155
|
*
|
|
146
156
|
* Validates `input` against the action's schema, runs it, validates the result against its output schema and
|
|
147
157
|
* returns it. Credentials come from `connections` (pack connection key to `conn_` ID), or else from your
|
|
148
|
-
* project's most recently created connection for that pack and key
|
|
149
|
-
* user (
|
|
150
|
-
*
|
|
151
|
-
* connection
|
|
158
|
+
* project's most recently created connection for that pack and key that has no `subject`: an unnamed key never
|
|
159
|
+
* uses an end user's connection (one with a `subject`), even when it is newer; name end-user connections
|
|
160
|
+
* explicitly. A call with `subject` (your end user's ID) resolves each unnamed key to that subject's most
|
|
161
|
+
* recently created connection for the pack and key instead, never to another subject's or to one without a
|
|
162
|
+
* `subject`. With no such connection the call is refused with `422 connection_required`. Using a stored
|
|
163
|
+
* connection, named or not, also needs `vault:run`. A credential is sent only over `https`, and only to a host
|
|
164
|
+
* that both the called pack version declares for the connection and the connection is bound to (its `hosts`;
|
|
165
|
+
* a host a later pack version adds needs a new connection). A request to a plain `http` URL whose host would
|
|
166
|
+
* get a credential is refused with `403 egress_denied` (`reason: scheme`) and nothing is sent; after a
|
|
167
|
+
* redirect, a credential bound through a wildcard host (`*.atlassian.net`) goes only back to the host the
|
|
168
|
+
* request started at. A JavaScript action whose credential would be bound only through a wildcard host is
|
|
169
|
+
* refused with `501 not_implemented` on a node whose egress proxy for JavaScript actions cannot yet keep it
|
|
170
|
+
* on one host; nothing runs and nothing is billed. Credential values an upstream echoes are replaced by `*`
|
|
171
|
+
* characters before the response mapping reads the answer, and what a mapping computes, every error text
|
|
172
|
+
* and the output of a JavaScript action are searched again. Found are values as written, with JSON string
|
|
173
|
+
* escapes (`\/`, `\u0073`) or percent escapes in either hex case, also nested (a JSON text in a string, a URL
|
|
174
|
+
* in another URL's query), and for `basic` the `Authorization` value (values of at least 8 characters; error
|
|
175
|
+
* texts also drop shorter ones of at least 4). JavaScript code reads answers through the node's egress proxy:
|
|
176
|
+
* the built-in one replaces all of these spellings, the platform proxy only values written as is. Other
|
|
177
|
+
* encodings, such as base64 of an API key, are not recognized.
|
|
178
|
+
* Only `pure` and `read` actions are retried automatically; send `Idempotency-Key`
|
|
152
179
|
* with `write` actions so a retry of your own does not repeat the effect (packs that declare an
|
|
153
180
|
* idempotency header pass it upstream). `timing` phases: `validate` (input schema), `inject` (connections),
|
|
154
181
|
* `render` (request templates), `upstream` (every HTTP exchange, retries and redirects included), `map`
|
|
@@ -201,6 +228,30 @@ export class ActionsAPI extends Namespace {
|
|
|
201
228
|
return this._client._call<T.Pack>(getPackOp, { path: [namespace, name], query: params }, options);
|
|
202
229
|
}
|
|
203
230
|
|
|
231
|
+
/**
|
|
232
|
+
* List a pack's MCP tools
|
|
233
|
+
*
|
|
234
|
+
* Every action of a pack version that is exposed to MCP, as MCP tool definitions in one response, so an MCP
|
|
235
|
+
* server lists a pack's tools with one request instead of one describe per action. The node builds the list
|
|
236
|
+
* when it loads the pack. Tool names are the registry's (`mcp_name`); each tool also carries the action's `ref`
|
|
237
|
+
* and `effects`, which a server drops from `tools/list`. Cache the response for `ttlMs`; the `ETag` is the
|
|
238
|
+
* version's content hash plus the filters, and `If-None-Match` with it answers `304`.
|
|
239
|
+
*
|
|
240
|
+
* `GET /v1/actions/packs/{namespace}/{name}/tools` · scope `actions:read` · served by the node
|
|
241
|
+
*/
|
|
242
|
+
getPackTools(
|
|
243
|
+
namespace: string,
|
|
244
|
+
name: string,
|
|
245
|
+
params?: T.ActionsGetPackToolsParams,
|
|
246
|
+
options?: RequestOptions,
|
|
247
|
+
): APIPromise<T.PackTools> {
|
|
248
|
+
return this._client._call<T.PackTools>(
|
|
249
|
+
getPackToolsOp,
|
|
250
|
+
{ path: [namespace, name], query: params, headerParams: params },
|
|
251
|
+
options,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
204
255
|
/**
|
|
205
256
|
* Get a pack manifest
|
|
206
257
|
*
|
|
@@ -292,8 +343,20 @@ export class ActionsAPI extends Namespace {
|
|
|
292
343
|
/**
|
|
293
344
|
* Search actions
|
|
294
345
|
*
|
|
295
|
-
* Full-text search over action titles, descriptions and
|
|
296
|
-
* can pass to describe and call. The same results back the `actions_search` MCP tool.
|
|
346
|
+
* Full-text search over action titles, descriptions, pack names and task phrases, ranked for agents. Returns
|
|
347
|
+
* references you can pass to describe and call. The same results back the `actions_search` MCP tool. With
|
|
348
|
+
* `kind=trigger` it searches triggers instead (results have `kind: trigger`, and their refs go in a routine's
|
|
349
|
+
* action trigger), and with `kind=any` both, ranked together, each result with its `kind`.
|
|
350
|
+
*
|
|
351
|
+
* Every answer says whether anything matched: `match` is `found` or `none`. A query that names a pack (`slack`,
|
|
352
|
+
* `google sheets`, or a pack's term such as `email` or `weather`) searches only the packs it names, and its
|
|
353
|
+
* other words are values (`weather in Tokyo`). A query that names no pack matches only an action that carries
|
|
354
|
+
* all of its words. A service the catalog does not have (`telegram message`) matches nothing, and verbs keep
|
|
355
|
+
* the effect class they ask for: `delete` or `send` only actions that write, `read` or `list` only actions
|
|
356
|
+
* that read. A removal, or an action that cannot be undone, must also be about what the query names
|
|
357
|
+
* (`delete the repo` matches nothing, since no GitHub action deletes a repository). With `match: none`,
|
|
358
|
+
* `data` is empty, `unmatched` lists the words the catalog does not know, and `fallback` names the generic
|
|
359
|
+
* HTTP actions to use instead. Never substitute an unrelated action.
|
|
297
360
|
*
|
|
298
361
|
* `GET /v1/actions/search` · scope `actions:read` · served by the node
|
|
299
362
|
*/
|