@north-light/crouter-env-docker 0.3.320 → 0.3.322

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 CHANGED
@@ -1,91 +1,19 @@
1
1
  # @north-light/crouter-env-docker
2
2
 
3
- A Docker `Environment` for the [crouter SDK](https://www.npmjs.com/package/@north-light/crouter-sdk) (`@north-light/crouter-sdk`'s `generate()`): run a [`crtrd`](https://github.com/vallum-security/crouter/tree/main/docker) container, wait for it to come up, and hand back the `{ baseUrl, headers }` shape the SDK needs to talk to it.
4
-
5
- Zero crouter imports — this package depends on nothing but Node built-ins. It shells out to the `docker` CLI via `child_process` and structurally satisfies the SDK's `Environment` interface (copied by hand into this package's own types, not imported).
6
-
7
- ## Install
8
-
9
- ```sh
10
- npm install @north-light/crouter-env-docker
11
- ```
12
-
13
- ## Usage
14
-
15
- ```ts
16
- import { start } from '@north-light/crouter-env-docker';
17
-
18
- const env = await start(); // defaults to ghcr.io/vallum-security/crtrd:latest
19
- const { baseUrl, headers } = await env.daemon();
20
- // baseUrl: http://127.0.0.1:<random free port>
21
- // headers: { Authorization: 'Bearer <randomly generated CRTRD_TOKEN>' }
22
-
23
- await env.stop(); // stops and removes the container
24
- ```
25
-
26
- Named + volume-backed = persistent, addressable by a later `attach()`:
27
-
28
- ```ts
29
- import { start, attach } from '@north-light/crouter-env-docker';
30
-
31
- await start({ image: 'crtrd:local', name: 'my-agent', volume: 'my-agent-home' });
32
- // ... later, possibly from a different process ...
33
- const env = await attach('my-agent');
34
- const { baseUrl, headers } = await env.daemon();
35
- await env.stop(); // stops only — the container and its volume survive
36
- ```
37
-
38
- ### With the crouter SDK
3
+ Run or attach to a `crtrd` Docker container. This package has no dependencies, including on the SDK.
39
4
 
40
5
  ```ts
41
6
  import { start } from '@north-light/crouter-env-docker';
42
- import { generate } from '@north-light/crouter-sdk';
43
- import { z } from 'zod';
44
-
45
- const env = await start({ image: 'crtrd:local', env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! } });
46
-
47
- const result = await generate({
48
- prompt: 'Read package.json and report the package name and version.',
49
- schema: z.object({ name: z.string(), version: z.string() }),
50
- env,
51
- });
7
+ import Crouter from '@north-light/crouter-sdk';
52
8
 
9
+ const env = await start({ volume: 'my-agent-home' });
10
+ const client = new Crouter(env.connection());
11
+ await client.nodes.create({ prompt: 'Read package.json.', root: true });
53
12
  await env.stop();
54
13
  ```
55
14
 
56
- ## API
57
-
58
- ```ts
59
- export interface Environment {
60
- daemon(): Promise<{ baseUrl?: string; socketPath?: string; headers?: Record<string, string> }>;
61
- }
62
-
63
- export interface DockerEnvironment extends Environment {
64
- containerId: string;
65
- name: string;
66
- stop(): Promise<void>; // stop + remove (start()'s container) or just stop (attach()'s)
67
- }
68
-
69
- export function start(opts?: {
70
- image?: string; // default: DEFAULT_IMAGE (ghcr.io/vallum-security/crtrd:<pin> — see below)
71
- env?: Record<string, string>; // forwarded to the container as -e KEY=VALUE (model provider keys, etc)
72
- name?: string; // container name; default: a generated random name
73
- volume?: string; // named volume mounted at CRTR_HOME; default: none (ephemeral home)
74
- port?: number; // host port, always bound to 127.0.0.1; default: a random free port docker assigns
75
- }): Promise<DockerEnvironment>;
76
-
77
- export function attach(name: string): Promise<DockerEnvironment>;
78
- ```
79
-
80
- - `start()` generates a random `CRTRD_TOKEN`, passes it into the container as `-e`, and resolves only once `/healthz` answers `200` with that bearer through the mapped host port.
81
- - `attach(name)` reads the mapped port and `CRTRD_TOKEN` off an already-running container via `docker inspect`. It throws a clear error if the container does not exist, is not running, or was not started with a `CRTRD_TOKEN` env var.
82
- - The token is never logged.
83
- - The container port is published to `127.0.0.1` only, never `0.0.0.0` — the daemon holds whatever provider keys you passed in `env`, and must not be reachable from the LAN.
84
-
85
- ## Default image
86
-
87
- `DEFAULT_IMAGE` is `ghcr.io/vallum-security/crtrd:latest`, which the release workflow pushes alongside each version tag. Pass `image` to pin a version, or to run a locally built tag (`crtrd:local`, see [`docker/README.md`](../../docker/README.md)).
15
+ `connection()` returns `{ baseURL, headers }`, ready for `new Crouter(...)`. `start()` creates a container with a generated bearer token, waits for `/healthz`, and `stop()` removes that container. `attach(name)` reads an existing container's mapped port and token; its `stop()` only stops the container.
88
16
 
89
- ## Requirements
17
+ `start()` accepts `image`, `env`, `name`, `volume`, and `port`. The port is always bound to `127.0.0.1`; a named volume preserves the crouter home across containers.
90
18
 
91
- The `docker` CLI, reachable and authenticated for whatever registry `image` names, on `PATH`.
19
+ The Docker CLI must be on `PATH` and authenticated for the requested image registry.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { DockerEnvironment, Environment, StartOptions } from './types.js';
2
- export type { DockerEnvironment, Environment, StartOptions };
1
+ import type { Connection, DockerEnvironment, StartOptions } from './types.js';
2
+ export type { Connection, DockerEnvironment, StartOptions };
3
3
  /**
4
4
  * Default image tag — the `latest` the release workflow's `publish-image` job
5
5
  * pushes alongside the version tag. Pass `image` to pin a version or to run a
@@ -7,7 +7,7 @@ export type { DockerEnvironment, Environment, StartOptions };
7
7
  */
8
8
  export declare const DEFAULT_IMAGE = "ghcr.io/vallum-security/crtrd:latest";
9
9
  /** Run the crtrd image, wait until `/healthz` answers 200 through the mapped
10
- * port, and return an `Environment` pointed at it. `stop()` stops and
10
+ * port, and return its connection settings. `stop()` stops and
11
11
  * removes the container. */
12
12
  export declare function start(opts?: StartOptions): Promise<DockerEnvironment>;
13
13
  /** Wrap an already-running container by name. Reads its mapped host port and
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ function generateName() {
17
17
  return `crtrd-env-${randomBytes(6).toString('hex')}`;
18
18
  }
19
19
  /** Run the crtrd image, wait until `/healthz` answers 200 through the mapped
20
- * port, and return an `Environment` pointed at it. `stop()` stops and
20
+ * port, and return its connection settings. `stop()` stops and
21
21
  * removes the container. */
22
22
  export async function start(opts = {}) {
23
23
  const image = opts.image ?? DEFAULT_IMAGE;
@@ -55,8 +55,8 @@ export async function start(opts = {}) {
55
55
  return {
56
56
  containerId,
57
57
  name,
58
- async daemon() {
59
- return { baseUrl, headers };
58
+ connection() {
59
+ return { baseURL: baseUrl, headers };
60
60
  },
61
61
  async stop() {
62
62
  await docker(['rm', '-f', containerId]);
@@ -76,8 +76,8 @@ export async function attach(name) {
76
76
  return {
77
77
  containerId,
78
78
  name,
79
- async daemon() {
80
- return { baseUrl, headers };
79
+ connection() {
80
+ return { baseURL: baseUrl, headers };
81
81
  },
82
82
  async stop() {
83
83
  await docker(['stop', containerId]);
package/dist/types.d.ts CHANGED
@@ -1,19 +1,9 @@
1
- /**
2
- * Structural mirror of the crouter SDK's `Environment` interface
3
- * (`packages/crouter-sdk`, `crouter-sdk-design.md` unit B). Copied by hand,
4
- * not imported — this package carries zero crouter/SDK dependencies, so a
5
- * `DockerEnvironment` satisfies the SDK's `Environment` purely by shape. Keep
6
- * this in sync with the SDK's definition if it changes.
7
- */
8
- export interface Environment {
9
- /** Where the crtrd for this run is. Called once per `generate()`. */
10
- daemon(): Promise<{
11
- baseUrl?: string;
12
- socketPath?: string;
13
- headers?: Record<string, string>;
14
- }>;
1
+ export interface Connection {
2
+ baseURL: string;
3
+ headers?: Record<string, string>;
15
4
  }
16
- export interface DockerEnvironment extends Environment {
5
+ export interface DockerEnvironment {
6
+ connection(): Connection;
17
7
  /** The container's full id. */
18
8
  containerId: string;
19
9
  /** The container's name — as passed to `start({ name })` or generated, or the name passed to `attach()`. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@north-light/crouter-env-docker",
3
- "version": "0.3.320",
4
- "description": "Docker Environment for the crouter SDK — start, attach to, and stop a crtrd container over the docker CLI. Zero crouter imports.",
3
+ "version": "0.3.322",
4
+ "description": "Docker connection manager for the crouter SDK — start, attach to, and stop a crtrd container over the docker CLI. Zero crouter imports.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",