# @north-light/crouter-api

The low-level typed client and contract for `crtrd`'s `/v1` API. It exports `CrtrClient`, routes, API errors, DTOs, and the command-plugin manifest types. [`@north-light/crouter-sdk`](https://www.npmjs.com/package/@north-light/crouter-sdk) is built on this package and is the better choice for most applications.

## Install

```bash
npm install @north-light/crouter-api
```

The package is ESM-only. Import it from an ES module or use dynamic `import()` from CommonJS.

## Connect to a daemon

`CrtrClient` is the typed HTTP client. Give it a TCP base URL and any required bearer header.

```ts
import { CrtrClient } from '@north-light/crouter-api';

const client = new CrtrClient({
  baseUrl: 'https://my-crtrd.example.com',
  headers: { authorization: 'Bearer a-daemon-token' },
});

const nodes = await client.listNodes();
console.log(nodes.map((node) => node.node_id));
```

For the local unix socket, import the Node-only entry point:

```ts
import { localClient } from '@north-light/crouter-api/node';

const client = localClient();
const health = await client.healthz();
console.log(health);
```

## Exports

- `CrtrClient` and `waitForDaemonAvailability` for typed `/v1` requests.
- `routes` and `API_VERSION` for route construction.
- `ApiError`, `APIError`, `ErrorBody`, and `isErrorBody` for the API error contract.
- DTOs for canvas, nodes, reports, lifecycle, files, bash, memory, models, human requests, crons, reviews, and related routes.
- `@north-light/crouter-api/node` for `defaultSocketPath`, `socketFetch`, and `localClient`.
- `@north-light/crouter-api/plugin-manifest` and `@north-light/crouter-api/command-manifest` for the plugin command-manifest schema and validation types.
- `@north-light/crouter-api/cards` for generated context types.

The package has no runtime dependencies or install scripts. Its [source](https://github.com/vallum-security/crouter/tree/main/src/api) and the [SDK reference](https://github.com/vallum-security/crouter/tree/main/docs/sdk) are in the crouter repository.
