@north-light/api 0.3.730 → 0.3.731
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/dist/api/errors.d.ts +5 -0
- package/dist/api/errors.js +11 -0
- package/dist/core/canvas/history.d.ts +1 -1
- package/dist/core/canvas/history.js +3 -3
- package/dist/core/conversation-store/row-store.js +7 -2
- package/dist/core/environment-starter-script.d.ts +1 -1
- package/dist/core/environment-starter-script.js +4 -1
- package/dist/core/runtime/runner/blaxel/image-build.d.ts +3 -0
- package/dist/core/runtime/runner/blaxel/image-build.js +4 -1
- package/package.json +1 -1
package/dist/api/errors.d.ts
CHANGED
|
@@ -43,6 +43,11 @@ export { APIError as ApiError };
|
|
|
43
43
|
/** A local API transport failure has stable status/code identity, independent
|
|
44
44
|
* of message prose. */
|
|
45
45
|
export declare function isDaemonTransportApiError(error: unknown): error is APIError;
|
|
46
|
+
/** A daemon answer that says nothing about the caller's data: the daemon was unreachable, starting, draining for a
|
|
47
|
+
* restart (503 `startup_blocked`), overloaded, or failed server-side. Retrying the same request later can succeed, so a
|
|
48
|
+
* long-lived caller (a broker's inbox poll) retries it rather than treating it as corrupt state. A 4xx other than
|
|
49
|
+
* 408/429 is about the request itself and is not transient. */
|
|
50
|
+
export declare function isTransientDaemonApiError(error: unknown): error is APIError;
|
|
46
51
|
/** The daemon refused the caller's node token. A teardown revokes the broker's token before its process stops, so a broker
|
|
47
52
|
* that sees this on a poll is being shut down, not hitting a corrupt state. */
|
|
48
53
|
export declare function isTokenRevokedApiError(error: unknown): error is APIError;
|
package/dist/api/errors.js
CHANGED
|
@@ -55,6 +55,17 @@ export function isDaemonTransportApiError(error) {
|
|
|
55
55
|
|| error.code === 'northlight_unreachable')) || (error.status === 504 && (error.code === 'request_timeout' || error.code === 'deadline_exceeded'))
|
|
56
56
|
|| (error.status >= 500 && error.code === 'daemon_health_unavailable');
|
|
57
57
|
}
|
|
58
|
+
/** A daemon answer that says nothing about the caller's data: the daemon was unreachable, starting, draining for a
|
|
59
|
+
* restart (503 `startup_blocked`), overloaded, or failed server-side. Retrying the same request later can succeed, so a
|
|
60
|
+
* long-lived caller (a broker's inbox poll) retries it rather than treating it as corrupt state. A 4xx other than
|
|
61
|
+
* 408/429 is about the request itself and is not transient. */
|
|
62
|
+
export function isTransientDaemonApiError(error) {
|
|
63
|
+
if (!(error instanceof APIError))
|
|
64
|
+
return false;
|
|
65
|
+
const { status, code, retryable } = error;
|
|
66
|
+
return isDaemonTransportApiError(error) || retryable === true || code === 'startup_blocked'
|
|
67
|
+
|| status === 408 || status === 429 || status >= 500;
|
|
68
|
+
}
|
|
58
69
|
/** The daemon refused the caller's node token. A teardown revokes the broker's token before its process stops, so a broker
|
|
59
70
|
* that sees this on a poll is being shut down, not hitting a corrupt state. */
|
|
60
71
|
export function isTokenRevokedApiError(error) {
|
|
@@ -95,7 +95,7 @@ export interface ResolvedRef {
|
|
|
95
95
|
/** Rendered body. */
|
|
96
96
|
body: string;
|
|
97
97
|
/** The verbatim record (session bytes or jsonl line); null for an inbox entry. */
|
|
98
|
-
raw: string | null;
|
|
98
|
+
raw: (() => Promise<string | null>) | null;
|
|
99
99
|
path: string | null;
|
|
100
100
|
}
|
|
101
101
|
/** Resolve a `<node-id>:inbox/<n>`, `<node-id>:session` or
|
|
@@ -454,10 +454,10 @@ export async function resolveRef(ref) {
|
|
|
454
454
|
ts: messages[messages.length - 1]?.ts ?? node.created,
|
|
455
455
|
nodeName: node.name,
|
|
456
456
|
body: rendered,
|
|
457
|
-
raw:
|
|
457
|
+
raw: async () => {
|
|
458
458
|
const { header, entries } = await conversationStore().read(conversationIdFromPath(file));
|
|
459
459
|
return [header, ...entries].map((entry) => `${JSON.stringify(entry)}\n`).join('');
|
|
460
|
-
}
|
|
460
|
+
},
|
|
461
461
|
path: file,
|
|
462
462
|
};
|
|
463
463
|
}
|
|
@@ -472,7 +472,7 @@ export async function resolveRef(ref) {
|
|
|
472
472
|
ts: msg.ts,
|
|
473
473
|
nodeName: node.name,
|
|
474
474
|
body: msg.text,
|
|
475
|
-
raw:
|
|
475
|
+
raw: () => rawSessionLine(file, index),
|
|
476
476
|
path: file,
|
|
477
477
|
};
|
|
478
478
|
}
|
|
@@ -265,8 +265,13 @@ export function createRowStore() {
|
|
|
265
265
|
lines.shift();
|
|
266
266
|
return { header, entries: entriesOf(lines.join('\n')), path };
|
|
267
267
|
}
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
// Line by line: a conversation over V8's string limit (~512 MB) cannot be decoded as one string.
|
|
269
|
+
if (!window || size <= window.head + window.tail) {
|
|
270
|
+
const entries = [];
|
|
271
|
+
for await (const line of linesOf(snap))
|
|
272
|
+
entries.push(...entriesOf(line));
|
|
273
|
+
return { header, entries, path };
|
|
274
|
+
}
|
|
270
275
|
const front = (await bytesOf(snap, 0, Math.max(0, window.head))).toString('utf8').split('\n');
|
|
271
276
|
front.pop();
|
|
272
277
|
// One byte before the tail window says whether it begins on a line boundary.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const STARTER_SETUP_SCRIPT = "#!/usr/bin/env bash\n# Setup script for a crtr cloud environment.\n#\n# How it runs\n# - Once per image build, as root, in /work, on Alpine Linux (use apk, not apt). Every sandbox of the profile starts from the result.\n# - Your repositories are already checked out at /work/<repo name> before this runs.\n# - The sandbox user is \"crtr\"
|
|
1
|
+
export declare const STARTER_SETUP_SCRIPT = "#!/usr/bin/env bash\n# Setup script for a crtr cloud environment.\n#\n# How it runs\n# - Once per image build, as root, in /work, on Alpine Linux (use apk, not apt). Every sandbox of the profile starts from the result.\n# - Your repositories are already checked out at /work/<repo name> before this runs.\n# - The sandbox user is \"crtr\". Files you create for it must be chowned to it. A node runs with HOME set to its app's home\n# (/var/lib/crtr/apps/<app>/home, created at run time), not /home/crtr, so dotfiles written to /home/crtr are not read through ~.\n# - Private GitHub Packages (@northlight-systems) already work: /home/crtr/.npmrc holds the auth line and NPM_CONFIG_USERCONFIG points at it,\n# with the token filled in from NODE_AUTH_TOKEN at run time. pnpm 12 ignores a token in a repository's own .npmrc, so do not rely on one.\n# - Already done for you: git, gh, curl, ripgrep, Node 24, pnpm. Packages are not pre-installed: run `pnpm install` in a sandbox,\n# or install at build time below.\n# - Output goes to /work/.crtr/setup.log in the image. If this script exits non-zero, sandboxes refuse to start and point at that log.\n# - The image keeps /work, /home/crtr, /usr, /etc and /lib. Anything written to /root or /tmp is lost.\n#\n# Secrets (API keys, database URLs) do not belong here: anything written by this script is baked into the image. Store them on the profile\n# instead and every sandbox gets them as environment variables:\n# printf '%s' \"<value>\" | crtr profile env set <profile> --name OPENAI_API_KEY\n#\n# Apply this file with:\n# crtr profile environment set --profile <profile> --setup-script-file ./setup.sh\n# then watch the build with `crtr profile environment show --profile <profile>` (ready when image_revision equals recipe_revision).\n#\n# Uncomment the sections you need. Delete the rest.\n\nset -euo pipefail\n\n# \u2500\u2500 1. System packages \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# Alpine package names: https://pkgs.alpinelinux.org/packages\n# apk add --no-cache build-base python3 # native npm modules (node-gyp)\n# apk add --no-cache jq sqlite # command-line tools your agents use\n# apk add --no-cache chromium # headless browser tests\n\n# \u2500\u2500 2. A local Postgres \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# Creates a database cluster owned by crtr. Section 5 starts it on the agent's first shell command.\n# apk add --no-cache postgresql postgresql-contrib\n# mkdir -p /run/postgresql && chown crtr /run/postgresql\n# su crtr -c 'initdb -D /home/crtr/pg -U postgres --auth=trust'\n\n# \u2500\u2500 3. App dependencies \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# To install a repository's packages at build time:\n# (cd /work/<repo name> && npm ci)\n# (cd /work/<repo name> && pnpm install --frozen-lockfile)\n# Each full install can take 0.5-1.5 GB of the sandbox disk. Install only the repositories agents work in most.\n\n# \u2500\u2500 4. Global CLIs \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# npm install -g typescript tsx\n# curl -fsSL https://example.com/install.sh | sh\n\n# \u2500\u2500 5. Start services on the agent's first command \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# The agent's shell is non-interactive bash, which runs the file named by $BASH_ENV before each command. Write a start script here, then\n# set BASH_ENV on the profile: printf '%s' /home/crtr/.services-up.sh | crtr profile env set <profile> --name BASH_ENV\n# cat > /home/crtr/.services-up.sh <<'UP'\n# pg_ctl -D /home/crtr/pg status >/dev/null 2>&1 || pg_ctl -D /home/crtr/pg -o \"-k /tmp -h localhost\" -l /tmp/pg.log -w start >/dev/null 2>&1 || true\n# UP\n# chown crtr /home/crtr/.services-up.sh\n\n# \u2500\u2500 6. Seed files and config \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# cp /work/<repo name>/.env.example /work/<repo name>/.env # placeholders only; real values come from `crtr profile env`\n# chown -R crtr /work/<repo name>\n";
|
|
@@ -7,7 +7,10 @@ export const STARTER_SETUP_SCRIPT = `#!/usr/bin/env bash
|
|
|
7
7
|
# How it runs
|
|
8
8
|
# - Once per image build, as root, in /work, on Alpine Linux (use apk, not apt). Every sandbox of the profile starts from the result.
|
|
9
9
|
# - Your repositories are already checked out at /work/<repo name> before this runs.
|
|
10
|
-
# - The sandbox user is "crtr"
|
|
10
|
+
# - The sandbox user is "crtr". Files you create for it must be chowned to it. A node runs with HOME set to its app's home
|
|
11
|
+
# (/var/lib/crtr/apps/<app>/home, created at run time), not /home/crtr, so dotfiles written to /home/crtr are not read through ~.
|
|
12
|
+
# - Private GitHub Packages (@northlight-systems) already work: /home/crtr/.npmrc holds the auth line and NPM_CONFIG_USERCONFIG points at it,
|
|
13
|
+
# with the token filled in from NODE_AUTH_TOKEN at run time. pnpm 12 ignores a token in a repository's own .npmrc, so do not rely on one.
|
|
11
14
|
# - Already done for you: git, gh, curl, ripgrep, Node 24, pnpm. Packages are not pre-installed: run \`pnpm install\` in a sandbox,
|
|
12
15
|
# or install at build time below.
|
|
13
16
|
# - Output goes to /work/.crtr/setup.log in the image. If this script exits non-zero, sandboxes refuse to start and point at that log.
|
|
@@ -25,6 +25,9 @@ export declare const SETUP_SCRIPT_FILE = "recipe-setup.sh";
|
|
|
25
25
|
/** The run user's npmrc. pnpm 12 ignores an env-expanded `_authToken` in a repository's `.npmrc`, so the GitHub Packages auth line lives here; it names the
|
|
26
26
|
* variable, never its value. `store-dir` pins one pnpm store in the image that every repository's `pnpm install` links from. */
|
|
27
27
|
export declare const RUN_USER_NPMRC: string[];
|
|
28
|
+
/** A node runs with HOME set to its app's home (`/var/lib/crtr/apps/<app>/home`), not `/home/crtr`, so npm and pnpm would never read the npmrc above;
|
|
29
|
+
* this pins their user config to it for every app. pnpm 12 reads credentials from no other non-repository file (not npm's or pnpm's global config). */
|
|
30
|
+
export declare const RUN_USER_NPMRC_ENV = "ENV NPM_CONFIG_USERCONFIG=/home/crtr/.npmrc";
|
|
28
31
|
export declare const REPOS_DIR = "repos";
|
|
29
32
|
/** Where the image keeps the setup script's output, and its exit status when it failed. `sandbox-start.mjs` reads both (it derives them from `/work/.crtr`). */
|
|
30
33
|
export declare const SETUP_LOG_FILE = "/work/.crtr/setup.log";
|
|
@@ -30,6 +30,9 @@ export const RUN_USER_NPMRC = [
|
|
|
30
30
|
'//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}',
|
|
31
31
|
`store-dir=/home/${RUN_USER}/.local/share/pnpm/store`,
|
|
32
32
|
];
|
|
33
|
+
/** A node runs with HOME set to its app's home (`/var/lib/crtr/apps/<app>/home`), not `/home/crtr`, so npm and pnpm would never read the npmrc above;
|
|
34
|
+
* this pins their user config to it for every app. pnpm 12 reads credentials from no other non-repository file (not npm's or pnpm's global config). */
|
|
35
|
+
export const RUN_USER_NPMRC_ENV = `ENV NPM_CONFIG_USERCONFIG=/home/${RUN_USER}/.npmrc`;
|
|
33
36
|
const writeRunUserNpmrc = () => `printf '%s\\n' ${RUN_USER_NPMRC.map((l) => `'${l}'`).join(' ')} > /home/${RUN_USER}/.npmrc`;
|
|
34
37
|
export const REPOS_DIR = 'repos';
|
|
35
38
|
/** Where the image keeps the setup script's output, and its exit status when it failed. `sandbox-start.mjs` reads both (it derives them from `/work/.crtr`). */
|
|
@@ -93,7 +96,7 @@ export function recipeDockerfile(recipe, revision, packagesToken = false) {
|
|
|
93
96
|
// A setup script may have written a resolved token into an npmrc; the run user's npmrc is rewritten to the token-free lines.
|
|
94
97
|
if (packagesToken)
|
|
95
98
|
out.push('RUN rm -f /work/.npmrc', `RUN ${writeRunUserNpmrc()} && chown ${RUN_USER}:${RUN_USER} /home/${RUN_USER}/.npmrc`);
|
|
96
|
-
out.push(`USER ${RUN_USER}`, 'WORKDIR /work', 'ENTRYPOINT ["/usr/local/bin/sandbox-api"]', '');
|
|
99
|
+
out.push(RUN_USER_NPMRC_ENV, `USER ${RUN_USER}`, 'WORKDIR /work', 'ENTRYPOINT ["/usr/local/bin/sandbox-api"]', '');
|
|
97
100
|
return out.join('\n');
|
|
98
101
|
}
|
|
99
102
|
const runGit = (args, env, cwd) => new Promise((resolve, reject) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.731",
|
|
4
4
|
"description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/api/index.js",
|