@crouter/sdk 0.3.377
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 +170 -0
- package/dist/client.d.ts +153 -0
- package/dist/client.js +491 -0
- package/dist/error-codes.d.ts +7 -0
- package/dist/error-codes.js +35 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.js +76 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +13 -0
- package/dist/keygen-cli.d.ts +2 -0
- package/dist/keygen-cli.js +6 -0
- package/dist/keygen-command.d.ts +6 -0
- package/dist/keygen-command.js +157 -0
- package/dist/oauth/index.d.ts +147 -0
- package/dist/oauth/index.js +377 -0
- package/dist/oauth/keygen.d.ts +18 -0
- package/dist/oauth/keygen.js +46 -0
- package/dist/resources/activity.d.ts +22 -0
- package/dist/resources/activity.js +43 -0
- package/dist/resources/attachments.d.ts +15 -0
- package/dist/resources/attachments.js +13 -0
- package/dist/resources/bash.d.ts +9 -0
- package/dist/resources/bash.js +15 -0
- package/dist/resources/canvas/history.d.ts +11 -0
- package/dist/resources/canvas/history.js +20 -0
- package/dist/resources/canvas.d.ts +19 -0
- package/dist/resources/canvas.js +42 -0
- package/dist/resources/crons.d.ts +15 -0
- package/dist/resources/crons.js +33 -0
- package/dist/resources/custom-objects.d.ts +20 -0
- package/dist/resources/custom-objects.js +84 -0
- package/dist/resources/files.d.ts +34 -0
- package/dist/resources/files.js +34 -0
- package/dist/resources/forward.d.ts +7 -0
- package/dist/resources/forward.js +64 -0
- package/dist/resources/human/inbox.d.ts +14 -0
- package/dist/resources/human/inbox.js +30 -0
- package/dist/resources/human/requests.d.ts +13 -0
- package/dist/resources/human/requests.js +26 -0
- package/dist/resources/human.d.ts +8 -0
- package/dist/resources/human.js +10 -0
- package/dist/resources/identifiers.d.ts +8 -0
- package/dist/resources/identifiers.js +33 -0
- package/dist/resources/memory.d.ts +69 -0
- package/dist/resources/memory.js +30 -0
- package/dist/resources/models/config.d.ts +8 -0
- package/dist/resources/models/config.js +9 -0
- package/dist/resources/models/credentials.d.ts +10 -0
- package/dist/resources/models/credentials.js +17 -0
- package/dist/resources/models.d.ts +8 -0
- package/dist/resources/models.js +10 -0
- package/dist/resources/node-stream.d.ts +34 -0
- package/dist/resources/node-stream.js +176 -0
- package/dist/resources/nodes/jobs.d.ts +9 -0
- package/dist/resources/nodes/jobs.js +14 -0
- package/dist/resources/nodes/result.d.ts +8 -0
- package/dist/resources/nodes/result.js +11 -0
- package/dist/resources/nodes/worktree.d.ts +9 -0
- package/dist/resources/nodes/worktree.js +14 -0
- package/dist/resources/nodes.d.ts +23 -0
- package/dist/resources/nodes.js +47 -0
- package/dist/resources/providers.d.ts +51 -0
- package/dist/resources/providers.js +15 -0
- package/dist/resources/questions.d.ts +49 -0
- package/dist/resources/questions.js +21 -0
- package/dist/resources/request.d.ts +3 -0
- package/dist/resources/request.js +11 -0
- package/dist/resources/run-reply.d.ts +79 -0
- package/dist/resources/run-reply.js +84 -0
- package/dist/resources/run-stream.d.ts +40 -0
- package/dist/resources/run-stream.js +206 -0
- package/dist/resources/runs.d.ts +184 -0
- package/dist/resources/runs.js +197 -0
- package/dist/resources/shares.d.ts +40 -0
- package/dist/resources/shares.js +19 -0
- package/dist/resources/uploads.d.ts +27 -0
- package/dist/resources/uploads.js +11 -0
- package/dist/schema.d.ts +7 -0
- package/dist/schema.js +10 -0
- package/dist/stores/postgres.d.ts +29 -0
- package/dist/stores/postgres.js +86 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.js +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# @crouter/sdk — a typed Node and browser client for running crouter agents from your application
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@crouter/sdk"><img alt="npm" src="https://img.shields.io/npm/v/@crouter/sdk?label=npm"></a>
|
|
7
|
+
<a href="https://github.com/crouton-labs/crouter/blob/main/LICENSE"><img alt="license" src="https://img.shields.io/badge/license-GPL--3.0-blue"></a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
`@crouter/sdk` is the application-facing client for a crouter daemon (`crtrd`). Create an agent run, wait for a result checked against a Zod or Standard Schema, stream the run's text and tool calls to a UI, and use the daemon's other APIs: files, bash, documents ("memory"), crons, human requests, and the OAuth connection flow for apps whose users each have their own runtime. It is ESM-only.
|
|
11
|
+
|
|
12
|
+
It is a client, not a runtime. It never runs an agent itself, and it does not bundle a model: the daemon it talks to does, using the provider that daemon is signed in to. In Node, `new Crouter()` connects to the local daemon over its unix socket and starts it on the first request if it is not running. In a browser or from another machine it needs the daemon's TCP URL and a bearer token. The lower-level contract it is built on is [`@crouter/api`](../crouter-api); most applications should install this package instead.
|
|
13
|
+
|
|
14
|
+
[Docs](https://docs.crouter.ai/docs/sdk) · [Client construction](https://docs.crouter.ai/docs/sdk/client) · [Resource map](https://docs.crouter.ai/docs/sdk/resources) · [Recipes](https://docs.crouter.ai/docs/sdk/guides) · [crouter repository](https://github.com/crouton-labs/crouter)
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @crouter/sdk zod # zod is optional; any Standard Schema works for output_schema
|
|
20
|
+
npm install -g crouter # the daemon and the crtr CLI
|
|
21
|
+
crtr sys setup # sign in to a model provider (first run only)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Connect
|
|
25
|
+
|
|
26
|
+
In Node, `new Crouter()` uses the local unix socket and starts the daemon on the first request when the socket is cold. In a browser or a remote process, pass the TCP URL and bearer token returned by `crtr sys connect` — the owner token, or a scoped token from `crtr sys connect --scopes` whose list caps what the application and its runs may do. Call `client.auth.status()` before enabling a run button: its `instructions` tells the user what to do when `next_step` is not `null`.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import Crouter from '@crouter/sdk';
|
|
30
|
+
|
|
31
|
+
const client = new Crouter();
|
|
32
|
+
const status = await client.auth.status();
|
|
33
|
+
|
|
34
|
+
if (status.next_step !== null) {
|
|
35
|
+
console.log(status.instructions);
|
|
36
|
+
} else {
|
|
37
|
+
console.log('The daemon and selected provider are ready.');
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const client = new Crouter({
|
|
43
|
+
baseURL: 'http://127.0.0.1:8787',
|
|
44
|
+
token: 'the-token-from-crtr-sys-connect',
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Run and parse a result
|
|
49
|
+
|
|
50
|
+
`parse()` creates a root run, waits for its outcome, and types `output_parsed` from a Zod or Standard Schema. Pass `scopes` to give a run a per-run allow-list; under a scoped token the list must stay inside the token's ceiling, and omitting it gives the run the ceiling.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import Crouter from '@crouter/sdk';
|
|
54
|
+
import { z } from 'zod';
|
|
55
|
+
|
|
56
|
+
const client = new Crouter();
|
|
57
|
+
const run = await client.nodes.parse({
|
|
58
|
+
prompt: 'Read package.json and return its name and version.',
|
|
59
|
+
cwd: '/absolute/path/to/project',
|
|
60
|
+
scopes: ['crtr:llm', 'crtr:files:read:user:.'],
|
|
61
|
+
output_schema: z.object({ name: z.string(), version: z.string() }),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (run.kind === 'result') console.log(run.output_parsed.name, run.output_parsed.version);
|
|
65
|
+
else if (run.reason === 'declined') console.warn(run.declined?.reason);
|
|
66
|
+
else console.error(run.reason, run.detail);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Stream a run
|
|
70
|
+
|
|
71
|
+
`nodes.stream()` creates a run and opens its event stream. `followActivity()` turns tool-call events into snapshots for an activity view. Disconnecting or calling `stream.abort()` stops the stream, not the run.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { followActivity } from '@crouter/sdk';
|
|
75
|
+
|
|
76
|
+
const stream = client.nodes.stream({
|
|
77
|
+
prompt: 'Inspect the repository and report the failing tests.',
|
|
78
|
+
cwd: '/absolute/path/to/project',
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
for await (const steps of followActivity(stream)) {
|
|
82
|
+
renderActivity(steps);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const outcome = await stream.finalOutcome();
|
|
86
|
+
console.log(outcome.kind);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Follow the reply to a message
|
|
90
|
+
|
|
91
|
+
On a run, `runs.reply(runId, sent)` follows the turn that answers one `runs.message` and ends when that turn completes. `turn.completed.error` reports a refused (`content_refused`) or failed (`model_error`) model call.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const sent = await client.runs.message(runId, 'Hello');
|
|
95
|
+
const text = await client.runs.reply(runId, sent).text();
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
To answer a first message in the run's first turn, pass it to `runs.start`: `message` is stored with the run and always joins the first turn as context ahead of `prompt`, and the result's `message` is what `runs.reply` takes. (A `runs.message(id, text, {start_turn: false})` sent after `runs.start` joins the first turn only if it is stored before the run claims that turn's messages.)
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
const run = await client.runs.start({prompt: instructions, message: 'Hello'});
|
|
102
|
+
const {text, ended, error} = await client.runs.reply(run.run_id, run.message!).collect({onDelta: (delta) => send(delta)});
|
|
103
|
+
// ended: 'completed' | 'error' (see error) | 'waiting_on_user' | 'settled' (see outcome)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`collect` (and `text({onDelta})`) passes each streamed piece to `onDelta`, starting a later assistant message with a blank line, and resolves to the trimmed messages joined by a blank line. The raw `RunReplyEvent` iterator stays available.
|
|
107
|
+
|
|
108
|
+
A run working in the background reports what it is doing on `runs.get(runId).activity` (`starting`, `thinking`, `tool` with `tool.name` and `tool.summary`, `writing`, or `between_turns`; `null` once it is no longer `running`), so a polling page shows progress without reading `runs.trace`.
|
|
109
|
+
|
|
110
|
+
`runs.listAll(filters)` and `memory.listAll(params)` (the person's knowledge and preference documents the caller can read: `public` by default, every privacy level with `crtr:memory:manage:user`) iterate every item across pages with `for await`, fetching the next page only as you go. `runs.delete(runId)` deletes a running run too — it stops the run's turns and sandboxes itself, so there is no need to `cancel` first; deleting a run that is already gone throws `NotFoundError`.
|
|
111
|
+
|
|
112
|
+
## Read files and run bash
|
|
113
|
+
|
|
114
|
+
File paths and the bash working directory are absolute. `bash.run()` returns non-zero exits as values.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const source = await client.files.read('/absolute/path/to/project/package.json');
|
|
118
|
+
const command = await client.bash.run({
|
|
119
|
+
command: 'npm test',
|
|
120
|
+
cwd: '/absolute/path/to/project',
|
|
121
|
+
timeout_s: 60,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
console.log(source.content, command.exit_code);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## PostgreSQL connection store (Node)
|
|
128
|
+
|
|
129
|
+
For a multi-process OAuth app, install `pg` in the app (`npm install pg`) and import the optional `@crouter/sdk/stores/postgres` subpath; the SDK's main entry never loads `pg`. `new PostgresConnectionStore(pool, { table: 'connection' })` implements `load`, `save`, `lock`, and `listStale(before: Date)`. Use one shared database and the same table for all workers. The lock keeps one PostgreSQL transaction and client open across the entire refresh callback (including the token request), so provision the pool for concurrent refreshes and avoid a transaction timeout shorter than the request. The table name accepts one or two lowercase SQL identifiers (schema.table), never SQL fragments.
|
|
130
|
+
|
|
131
|
+
Create the table before using the store (or adapt this schema in your migration):
|
|
132
|
+
|
|
133
|
+
```sql
|
|
134
|
+
CREATE TABLE connection (
|
|
135
|
+
user_id text PRIMARY KEY,
|
|
136
|
+
runtime_url text NOT NULL,
|
|
137
|
+
refresh_token text NOT NULL,
|
|
138
|
+
grant_id text NOT NULL,
|
|
139
|
+
access_token text NOT NULL,
|
|
140
|
+
access_token_expires_at timestamptz NOT NULL,
|
|
141
|
+
id_token text,
|
|
142
|
+
updated_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
|
143
|
+
);
|
|
144
|
+
CREATE INDEX connection_updated_at_idx ON connection (updated_at, user_id);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`save` upserts all fields and sets `updated_at` to the database clock. `listStale(before)` selects connections with `updated_at < before`, oldest first; it is a **last save** timestamp, not necessarily last successful refresh if an app also calls `save` for another reason. For idle-token maintenance, schedule `oauth.refreshIdleConnections(store, {olderThanMs: 30 * 24 * 60 * 60 * 1000})` (for example, daily). It selects stale connections, refreshes under the store lock, reloads there to avoid rotating an already-used token, saves a rotated connection, and reports `{refreshed, failures}` for the worker to inspect; each failure's `reason` is `refreshRefusal(error)`. `refreshRefusal(error)` classifies any refused refresh as `'removed'` (`grant_removed`: the runtime deleted the app's runs; delete what you store for the person), `'paused'` (`grant_suspended`: nothing was deleted; keep the data until they sign in again), `'reconnect'` (`refresh_token_expired`, `refresh_token_reused`, `grant_revoked`: nothing was deleted; ask them to sign in again), or `null` when the error is not the directory refusing a refresh. Load the signing key `crouter-sdk keygen` wrote with `privateKey: await privateKeyFromFile('local/app-key.json')` (Node), or check one from an environment variable with `parsePrivateJwk(text)`; both refuse anything but a private JWK with a `kid`. The SDK does not start a timer. `listStale` returns connections, not timestamps, so a worker needing a strict cutoff recheck must maintain that policy separately. The table contains credentials: restrict database access, encrypt backups, and delete a row when its user disconnects. PostgreSQL `timestamptz` must be returned as a JavaScript `Date` (the `pg` default parser).
|
|
148
|
+
|
|
149
|
+
## Example application
|
|
150
|
+
|
|
151
|
+
See the complete [localhost SDK demo](https://github.com/crouton-labs/crouter/tree/main/examples/localhost-demo) for streaming, structured output, and an HTTP plugin in one local page.
|
|
152
|
+
|
|
153
|
+
## Reference
|
|
154
|
+
|
|
155
|
+
The [SDK guide](https://docs.crouter.ai/docs/sdk) covers [client construction](https://docs.crouter.ai/docs/sdk/client), [nodes and scopes](https://docs.crouter.ai/docs/sdk/nodes), [streaming](https://docs.crouter.ai/docs/sdk/streaming), [files](https://docs.crouter.ai/docs/sdk/files), [bash](https://docs.crouter.ai/docs/sdk/bash), [Docker](https://docs.crouter.ai/docs/sdk/docker), [errors](https://docs.crouter.ai/docs/sdk/errors), and the complete [resource map](https://docs.crouter.ai/docs/sdk/resources).
|
|
156
|
+
|
|
157
|
+
`@crouter/sdk/errors` exports `errorCodes`/`ErrorCode` (the daemon's codes), `sdkErrorCodes`/`SdkErrorCode` (the codes the SDK raises itself, such as `oauth_state_mismatch`; `CrouterError.code` is typed with them), and `mapError`, which turns a plain `APIError` into its status class (`NotFoundError`, …) for app tests.
|
|
158
|
+
|
|
159
|
+
The SDK re-exports its public DTO types, so you do not also install `@crouter/api`.
|
|
160
|
+
|
|
161
|
+
## Related
|
|
162
|
+
|
|
163
|
+
- [`@crouter/api`](../crouter-api): the `/v1` contract this client is built on.
|
|
164
|
+
- [`@crouter/env-docker`](../crouter-env-docker): start a `crtrd` container and get a `Connection` to pass to `new Crouter(...)`.
|
|
165
|
+
- [`@crouter/plugin`](../crouter-plugin): expose your own commands to agents as `crtr` commands.
|
|
166
|
+
- [Main repository](https://github.com/crouton-labs/crouter): the `crtr` CLI, the `crtrd` daemon, and [contributing guidelines](https://github.com/crouton-labs/crouter/blob/main/CONTRIBUTING.md).
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
[GPL-3.0-only](https://github.com/crouton-labs/crouter/blob/main/LICENSE).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type HealthDTO, type MessageResultDTO, type NodeDetailDTO, type ListNodesQuery, type NodeOutcomeDTO, type NodeOutcomeResponseDTO, type NodeSummaryDTO, type ProfileDTO, type ReportDTO, type ReportsQuery, type StatusDTO } from '@crouter/api';
|
|
2
|
+
import { Bash } from './resources/bash.js';
|
|
3
|
+
import { Canvas } from './resources/canvas.js';
|
|
4
|
+
import { Crons } from './resources/crons.js';
|
|
5
|
+
import { CustomObjects } from './resources/custom-objects.js';
|
|
6
|
+
import { Attachments } from './resources/attachments.js';
|
|
7
|
+
import { Files } from './resources/files.js';
|
|
8
|
+
import { Human } from './resources/human.js';
|
|
9
|
+
import { Models } from './resources/models.js';
|
|
10
|
+
import { NodesResource } from './resources/nodes.js';
|
|
11
|
+
import { NodeStream } from './resources/node-stream.js';
|
|
12
|
+
import { Questions } from './resources/questions.js';
|
|
13
|
+
import { Providers } from './resources/providers.js';
|
|
14
|
+
import { Runs } from './resources/runs.js';
|
|
15
|
+
import { Shares } from './resources/shares.js';
|
|
16
|
+
import { Memory } from './resources/memory.js';
|
|
17
|
+
import { Uploads } from './resources/uploads.js';
|
|
18
|
+
import type { AuthStatus, AuthStatusParams, CancelParams, EnsureProfileParams, MessageParams, NodeCreateParams, NodeEventsOptions, NodeOutcomeOptions, OutputSchema, ParsedOutcome, RequestOptions, SchemaOutput } from './types.js';
|
|
19
|
+
import type { AppProfile } from './resources/runs.js';
|
|
20
|
+
type CoreNodes = {
|
|
21
|
+
create: (params: NodeCreateParams, options?: RequestOptions) => Promise<NodeDetailDTO>;
|
|
22
|
+
retrieve: (id: string, options?: RequestOptions) => Promise<NodeDetailDTO>;
|
|
23
|
+
list: (query?: ListNodesQuery, options?: RequestOptions) => Promise<NodeSummaryDTO[]>;
|
|
24
|
+
outcome: (id: string, options?: NodeOutcomeOptions) => Promise<NodeOutcomeResponseDTO>;
|
|
25
|
+
waitForOutcome: (id: string, options?: RequestOptions) => Promise<NodeOutcomeDTO>;
|
|
26
|
+
createAndWait: (params: NodeCreateParams, options?: RequestOptions) => Promise<NodeOutcomeDTO>;
|
|
27
|
+
parse: <TSchema extends OutputSchema>(params: NodeCreateParams & {
|
|
28
|
+
output_schema: TSchema;
|
|
29
|
+
}, options?: RequestOptions) => Promise<ParsedOutcome<SchemaOutput<TSchema>>>;
|
|
30
|
+
message: (id: string, body: string | MessageParams, options?: RequestOptions) => Promise<MessageResultDTO>;
|
|
31
|
+
cancel: (id: string, body?: CancelParams, options?: RequestOptions) => Promise<unknown>;
|
|
32
|
+
interrupt: (id: string, options?: RequestOptions) => Promise<unknown>;
|
|
33
|
+
stream: (params: NodeCreateParams, options?: RequestOptions) => NodeStream;
|
|
34
|
+
events: (id: string, options?: NodeEventsOptions) => NodeStream;
|
|
35
|
+
reports: {
|
|
36
|
+
list: (id: string, query?: ReportsQuery, options?: RequestOptions) => Promise<ReportDTO[]>;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/** Connection settings for a Crouter daemon. `headers` lets a Docker environment's
|
|
40
|
+
* `connection()` result pass directly to this constructor. */
|
|
41
|
+
export interface CrouterOptions {
|
|
42
|
+
/** `http(s)://host:port` of a daemon TCP listener. Defaults to `CRTR_BASE_URL`. */
|
|
43
|
+
baseURL?: string;
|
|
44
|
+
/** Unix socket path. Node only. Defaults to `CRTR_SOCKET`, else `$CRTR_HOME/crtrd.sock`, else `~/.crouter/canvas/crtrd.sock`. */
|
|
45
|
+
socketPath?: string;
|
|
46
|
+
/** Sent as `Authorization: Bearer <token>`. Defaults to `CRTRD_TOKEN`. A unix-socket daemon ignores it. */
|
|
47
|
+
token?: string;
|
|
48
|
+
/** Supplies a directory token per request, including reconnects. Mutually exclusive with token. */
|
|
49
|
+
tokenSource?: () => Promise<string>;
|
|
50
|
+
/** Refreshes a connection-backed token once after a 401. */
|
|
51
|
+
onUnauthorized?: () => Promise<void>;
|
|
52
|
+
/** Per-request wall clock in milliseconds. Defaults to 30000. Does not apply to a stream. */
|
|
53
|
+
timeout?: number;
|
|
54
|
+
/** Transient-failure retries. Defaults to 2. Never applied to `POST` or `PATCH`. */
|
|
55
|
+
maxRetries?: number;
|
|
56
|
+
/** Merged into every request. */
|
|
57
|
+
defaultHeaders?: Record<string, string>;
|
|
58
|
+
/** Merged after `defaultHeaders`; the `Authorization` generated from `token` still wins. */
|
|
59
|
+
headers?: Record<string, string>;
|
|
60
|
+
/** Transport override, for proxies and instrumentation. */
|
|
61
|
+
fetch?: typeof fetch;
|
|
62
|
+
/** On a cold socket, run `crtr sys daemon start` and retry once. Node only. Defaults to true for a socket, false for `baseURL`. */
|
|
63
|
+
autostart?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The client, and the only class an application constructs. Each namespace below wraps a
|
|
67
|
+
* family of daemon routes; `request` is the escape hatch for a route with no wrapper.
|
|
68
|
+
*/
|
|
69
|
+
export declare class Crouter {
|
|
70
|
+
/** Create, inspect, message, stream, and wait on nodes. */
|
|
71
|
+
readonly nodes: NodesResource & CoreNodes;
|
|
72
|
+
/** Run one command in an absolute working directory. */
|
|
73
|
+
readonly bash: Bash;
|
|
74
|
+
/** Canvas-wide views: attention, snapshot, roster, dashboard, prune, and history. */
|
|
75
|
+
readonly canvas: Canvas;
|
|
76
|
+
/** Scheduled commands. */
|
|
77
|
+
readonly crons: Crons;
|
|
78
|
+
/** Register, publish, receive, and acknowledge custom canvas objects. */
|
|
79
|
+
readonly customObjects: CustomObjects;
|
|
80
|
+
/** Human requests and the human inbox. */
|
|
81
|
+
readonly human: Human;
|
|
82
|
+
/** Model credentials and model configuration. */
|
|
83
|
+
readonly models: Models;
|
|
84
|
+
/** Agent profiles. */
|
|
85
|
+
readonly profiles: {
|
|
86
|
+
ensure: (name: string, params?: EnsureProfileParams, options?: RequestOptions) => Promise<ProfileDTO>;
|
|
87
|
+
retrieve: (name: string, options?: RequestOptions) => Promise<ProfileDTO>;
|
|
88
|
+
/** The profiles an app may start runs with (app listener only): its own, and those of other apps its grant covers. `default` marks its default profile. */
|
|
89
|
+
list: (options?: RequestOptions) => Promise<{
|
|
90
|
+
profiles: AppProfile[];
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
/** Daemon status and health. */
|
|
94
|
+
readonly system: {
|
|
95
|
+
status: (options?: RequestOptions) => Promise<StatusDTO>;
|
|
96
|
+
health: (options?: RequestOptions) => Promise<HealthDTO>;
|
|
97
|
+
};
|
|
98
|
+
/** Whether this client can reach a daemon that can run a model. */
|
|
99
|
+
readonly auth: {
|
|
100
|
+
status: (params?: AuthStatusParams, options?: RequestOptions) => Promise<AuthStatus>;
|
|
101
|
+
};
|
|
102
|
+
/** Read, write, and list absolute host paths. */
|
|
103
|
+
readonly files: Files;
|
|
104
|
+
readonly runs: Runs;
|
|
105
|
+
/** Uploads to runtime storage, for files a run prompt or message names (app listener only). */
|
|
106
|
+
readonly uploads: Uploads;
|
|
107
|
+
/** Signed links to files a run received as attachments (app listener only). */
|
|
108
|
+
readonly attachments: Attachments;
|
|
109
|
+
/** Public share links to files (app listener only). */
|
|
110
|
+
readonly shares: Shares;
|
|
111
|
+
/** Questions agents in runs ask the user (app listener only). */
|
|
112
|
+
readonly questions: Questions;
|
|
113
|
+
/** Read the documents the person owns (`store: 'user'`): an app sees their `public` documents, and every privacy level with a `crtr:memory:manage:user` grant. */
|
|
114
|
+
readonly memory: Memory;
|
|
115
|
+
/** Scope-filtered provider tools and daemon-mediated calls. */
|
|
116
|
+
readonly providers: Providers;
|
|
117
|
+
readonly grant: {
|
|
118
|
+
get: (options?: RequestOptions) => Promise<import('@crouter/api').GrantGetDTO>;
|
|
119
|
+
};
|
|
120
|
+
readonly health: {
|
|
121
|
+
get: (options?: RequestOptions) => Promise<{
|
|
122
|
+
status: 'ok';
|
|
123
|
+
api_version: string;
|
|
124
|
+
}>;
|
|
125
|
+
};
|
|
126
|
+
private readonly eventFetch;
|
|
127
|
+
private readonly bearerToken;
|
|
128
|
+
private connectionToken;
|
|
129
|
+
private readonly tokenSource;
|
|
130
|
+
private readonly onUnauthorized;
|
|
131
|
+
private readonly client;
|
|
132
|
+
private readonly timeout;
|
|
133
|
+
private readonly baseURL;
|
|
134
|
+
private readonly socketPath;
|
|
135
|
+
constructor(options?: CrouterOptions);
|
|
136
|
+
/** Establish NDJSON through the JSON client's cold-socket/retry transport; leave the live body unread. */
|
|
137
|
+
private openCustomDeliveries;
|
|
138
|
+
private openRunEvents;
|
|
139
|
+
/** `GET /v1/files/download` as a raw fetch: bytes are not JSON, so it bypasses the JSON client but
|
|
140
|
+
* still goes through `call()`, which supplies the connection token and refreshes it once on a 401. */
|
|
141
|
+
private openDownload;
|
|
142
|
+
/** Sends one request to any daemon route, for routes the namespaces above do not wrap. */
|
|
143
|
+
request<T>(method: string, path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
144
|
+
private authStatus;
|
|
145
|
+
private stream;
|
|
146
|
+
private events;
|
|
147
|
+
private outcome;
|
|
148
|
+
private waitForOutcome;
|
|
149
|
+
private createAndWait;
|
|
150
|
+
private parse;
|
|
151
|
+
private call;
|
|
152
|
+
}
|
|
153
|
+
export {};
|