@north-light/crouter-api 0.3.156

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.
Files changed (50) hide show
  1. package/README.md +51 -0
  2. package/dist/__tests__/client.test.d.ts +1 -0
  3. package/dist/__tests__/client.test.js +274 -0
  4. package/dist/client.d.ts +246 -0
  5. package/dist/client.js +611 -0
  6. package/dist/dto/attach.d.ts +16 -0
  7. package/dist/dto/attach.js +13 -0
  8. package/dist/dto/broker.d.ts +45 -0
  9. package/dist/dto/broker.js +20 -0
  10. package/dist/dto/canvas.d.ts +253 -0
  11. package/dist/dto/canvas.js +2 -0
  12. package/dist/dto/common.d.ts +27 -0
  13. package/dist/dto/common.js +15 -0
  14. package/dist/dto/config.d.ts +19 -0
  15. package/dist/dto/config.js +3 -0
  16. package/dist/dto/crons.d.ts +124 -0
  17. package/dist/dto/crons.js +10 -0
  18. package/dist/dto/files.d.ts +11 -0
  19. package/dist/dto/files.js +7 -0
  20. package/dist/dto/focus.d.ts +24 -0
  21. package/dist/dto/focus.js +10 -0
  22. package/dist/dto/health.d.ts +41 -0
  23. package/dist/dto/health.js +2 -0
  24. package/dist/dto/human.d.ts +57 -0
  25. package/dist/dto/human.js +4 -0
  26. package/dist/dto/inbox.d.ts +105 -0
  27. package/dist/dto/inbox.js +10 -0
  28. package/dist/dto/lifecycle.d.ts +79 -0
  29. package/dist/dto/lifecycle.js +3 -0
  30. package/dist/dto/messages.d.ts +55 -0
  31. package/dist/dto/messages.js +2 -0
  32. package/dist/dto/modelauth.d.ts +41 -0
  33. package/dist/dto/modelauth.js +3 -0
  34. package/dist/dto/nodes.d.ts +194 -0
  35. package/dist/dto/nodes.js +3 -0
  36. package/dist/dto/profiles.d.ts +14 -0
  37. package/dist/dto/profiles.js +3 -0
  38. package/dist/dto/reports.d.ts +41 -0
  39. package/dist/dto/reports.js +2 -0
  40. package/dist/dto/subscriptions.d.ts +14 -0
  41. package/dist/dto/subscriptions.js +2 -0
  42. package/dist/dto/worktree.d.ts +19 -0
  43. package/dist/dto/worktree.js +6 -0
  44. package/dist/errors.d.ts +19 -0
  45. package/dist/errors.js +30 -0
  46. package/dist/index.d.ts +24 -0
  47. package/dist/index.js +25 -0
  48. package/dist/routes.d.ts +63 -0
  49. package/dist/routes.js +91 -0
  50. package/package.json +33 -0
@@ -0,0 +1,19 @@
1
+ import type { NodeIdDTO } from './common.js';
2
+ /** `POST /v1/nodes/{id}/worktree/close` result. */
3
+ export interface CloseWorktreeResultDTO {
4
+ node_id: NodeIdDTO;
5
+ /** The worktree branch fast-forwarded into its recorded local base branch. */
6
+ branch: string;
7
+ worktree_path: string;
8
+ /** The commit SHA the recorded local base branch was fast-forwarded onto. */
9
+ landed_sha: string;
10
+ /** False when the landing happened but the checkout could not be removed
11
+ * automatically — the close still counts as done (state is closed);
12
+ * `worktree_remove_error` carries the manual-cleanup note. */
13
+ worktree_removed: boolean;
14
+ worktree_remove_error?: string;
15
+ /** False when the landing happened but the local branch could not be deleted
16
+ * automatically — same non-fatal treatment as `worktree_removed`. */
17
+ branch_deleted: boolean;
18
+ branch_delete_error?: string;
19
+ }
@@ -0,0 +1,6 @@
1
+ // Worktree DTOs (spec §6.2 — `node worktree close`). Landing + closing a
2
+ // node-managed git worktree is a canvas WRITE interleaved with a git land
3
+ // transaction, so it runs server-side (crtrd is the repo host — same principle
4
+ // as spawnChild's server-side creation git). This is the projected result of
5
+ // core's `CloseManagedWorktreeResult` — already snake_case, so a 1:1 mirror.
6
+ export {};
@@ -0,0 +1,19 @@
1
+ /** The uniform JSON body crtrd returns on any non-2xx response. */
2
+ export interface ErrorBody {
3
+ error: {
4
+ code: string;
5
+ message: string;
6
+ details?: unknown;
7
+ };
8
+ }
9
+ /** Thrown by `CrtrClient` on a non-2xx response (or a synthesized transport
10
+ * failure such as an unreachable daemon). Carries the HTTP status, the stable
11
+ * machine `code` from the `ErrorBody`, and optional structured `details`. */
12
+ export declare class ApiError extends Error {
13
+ readonly status: number;
14
+ readonly code: string;
15
+ readonly details?: unknown;
16
+ constructor(status: number, code: string, message: string, details?: unknown);
17
+ }
18
+ /** Type guard for an `ErrorBody`-shaped parsed payload. */
19
+ export declare function isErrorBody(value: unknown): value is ErrorBody;
package/dist/errors.js ADDED
@@ -0,0 +1,30 @@
1
+ // API error contract (spec §8). Uniform JSON error body on any non-2xx; the
2
+ // client parses it and throws `ApiError`.
3
+ //
4
+ // PURITY (spec §3.1): Node built-ins + `src/api/*` only.
5
+ /** Thrown by `CrtrClient` on a non-2xx response (or a synthesized transport
6
+ * failure such as an unreachable daemon). Carries the HTTP status, the stable
7
+ * machine `code` from the `ErrorBody`, and optional structured `details`. */
8
+ export class ApiError extends Error {
9
+ status;
10
+ code;
11
+ details;
12
+ constructor(status, code, message, details) {
13
+ super(message);
14
+ this.name = 'ApiError';
15
+ this.status = status;
16
+ this.code = code;
17
+ if (details !== undefined)
18
+ this.details = details;
19
+ }
20
+ }
21
+ /** Type guard for an `ErrorBody`-shaped parsed payload. */
22
+ export function isErrorBody(value) {
23
+ if (typeof value !== 'object' || value === null)
24
+ return false;
25
+ const err = value.error;
26
+ if (typeof err !== 'object' || err === null)
27
+ return false;
28
+ const { code, message } = err;
29
+ return typeof code === 'string' && typeof message === 'string';
30
+ }
@@ -0,0 +1,24 @@
1
+ export { CrtrClient } from './client.js';
2
+ export type { CrtrClientOptions } from './client.js';
3
+ export { ApiError, isErrorBody } from './errors.js';
4
+ export type { ErrorBody } from './errors.js';
5
+ export { API_VERSION, routes } from './routes.js';
6
+ export * from './dto/common.js';
7
+ export * from './dto/health.js';
8
+ export * from './dto/nodes.js';
9
+ export * from './dto/messages.js';
10
+ export * from './dto/reports.js';
11
+ export * from './dto/lifecycle.js';
12
+ export * from './dto/subscriptions.js';
13
+ export * from './dto/focus.js';
14
+ export * from './dto/crons.js';
15
+ export * from './dto/config.js';
16
+ export * from './dto/attach.js';
17
+ export * from './dto/broker.js';
18
+ export * from './dto/profiles.js';
19
+ export * from './dto/modelauth.js';
20
+ export * from './dto/canvas.js';
21
+ export * from './dto/worktree.js';
22
+ export * from './dto/human.js';
23
+ export * from './dto/files.js';
24
+ export * from './dto/inbox.js';
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ // `@crouton-kit/crouter/api` — the single source of truth for crtrd's API DTOs,
2
+ // route constants, error contract, and the typed `CrtrClient`. Dependency-light
3
+ // by design (spec §3.1): Node built-ins + `src/api/*` only.
4
+ export { CrtrClient } from './client.js';
5
+ export { ApiError, isErrorBody } from './errors.js';
6
+ export { API_VERSION, routes } from './routes.js';
7
+ export * from './dto/common.js';
8
+ export * from './dto/health.js';
9
+ export * from './dto/nodes.js';
10
+ export * from './dto/messages.js';
11
+ export * from './dto/reports.js';
12
+ export * from './dto/lifecycle.js';
13
+ export * from './dto/subscriptions.js';
14
+ export * from './dto/focus.js';
15
+ export * from './dto/crons.js';
16
+ export * from './dto/config.js';
17
+ export * from './dto/attach.js';
18
+ export * from './dto/broker.js';
19
+ export * from './dto/profiles.js';
20
+ export * from './dto/modelauth.js';
21
+ export * from './dto/canvas.js';
22
+ export * from './dto/worktree.js';
23
+ export * from './dto/human.js';
24
+ export * from './dto/files.js';
25
+ export * from './dto/inbox.js';
@@ -0,0 +1,63 @@
1
+ /** The single API version constant; every versioned path prepends it. */
2
+ export declare const API_VERSION = "v1";
3
+ /** Route path builders. Keys mirror the spec §6 route table. */
4
+ export declare const routes: {
5
+ readonly healthz: () => string;
6
+ readonly status: () => string;
7
+ readonly daemonRestart: () => string;
8
+ readonly nodes: () => string;
9
+ readonly reviveAll: () => string;
10
+ readonly node: (id: string) => string;
11
+ readonly nodeSnapshot: (id: string) => string;
12
+ readonly nodeTranscript: (id: string) => string;
13
+ readonly nodeContext: (id: string) => string;
14
+ readonly nodeArtifacts: (id: string) => string;
15
+ readonly nodeReports: (id: string) => string;
16
+ readonly nodeMessages: (id: string) => string;
17
+ readonly nodeInterrupt: (id: string) => string;
18
+ readonly nodeFork: (id: string) => string;
19
+ readonly nodeRevive: (id: string) => string;
20
+ readonly nodeRelaunchRoot: (id: string) => string;
21
+ readonly nodeClose: (id: string) => string;
22
+ readonly nodeRecycle: (id: string) => string;
23
+ readonly nodeDemote: (id: string) => string;
24
+ readonly nodePromote: (id: string) => string;
25
+ readonly nodeYield: (id: string) => string;
26
+ readonly nodeWait: (id: string) => string;
27
+ readonly nodeConfig: (id: string) => string;
28
+ readonly nodeWorktreeClose: (id: string) => string;
29
+ readonly nodeAttach: (id: string) => string;
30
+ readonly focuses: () => string;
31
+ readonly focusByNode: () => string;
32
+ readonly focusByPane: () => string;
33
+ readonly focus: (focusId: string) => string;
34
+ readonly nodeSubscriptions: (id: string) => string;
35
+ readonly nodeSubscription: (id: string, target: string) => string;
36
+ readonly crons: () => string;
37
+ readonly cron: (cronId: string) => string;
38
+ readonly cronPause: (cronId: string) => string;
39
+ readonly cronResume: (cronId: string) => string;
40
+ readonly cronRun: (cronId: string) => string;
41
+ readonly canvasAttention: () => string;
42
+ readonly canvasAttentionCounts: () => string;
43
+ readonly canvasHistorySearch: () => string;
44
+ readonly canvasHistoryGrep: () => string;
45
+ readonly canvasHistoryRead: () => string;
46
+ readonly canvasSnapshot: () => string;
47
+ readonly canvasRoster: () => string;
48
+ readonly canvasPrune: () => string;
49
+ readonly canvasRebuildIndex: () => string;
50
+ readonly canvasConsults: () => string;
51
+ readonly humanBridge: () => string;
52
+ readonly humanDeliver: () => string;
53
+ readonly humanConsult: () => string;
54
+ readonly humanVisual: () => string;
55
+ readonly humanInbox: () => string;
56
+ readonly humanInboxTicket: (ticketId: string) => string;
57
+ readonly humanInboxRespond: (ticketId: string) => string;
58
+ readonly humanInboxCancel: (ticketId: string) => string;
59
+ readonly profiles: () => string;
60
+ readonly profile: (name: string) => string;
61
+ readonly modelAuth: (provider: string) => string;
62
+ readonly filePeek: () => string;
63
+ };
package/dist/routes.js ADDED
@@ -0,0 +1,91 @@
1
+ // API version + route path builders (spec §4.1). Every route is prefixed `/v1`
2
+ // EXCEPT `GET /healthz`, which stays unversioned so any-version probes (incl.
3
+ // the P2 provisioning ladder) can reach it. A version mismatch surfaces as a
4
+ // 404 — there is no negotiation, no Accept-header versioning, no compat shim.
5
+ //
6
+ // These builders carry NO logic — they are pure string constructors. Every
7
+ // interpolated param (node id, target, cron id, profile name, provider) MUST
8
+ // be a pre-validated single path segment (e.g. `isSafeNodeId`-gated ids;
9
+ // upstream-constrained names) — nothing here parses, encodes, or branches, so a
10
+ // param carrying `/` or `..` would corrupt the path.
11
+ //
12
+ // PURITY (spec §3.1): Node built-ins + `src/api/*` only.
13
+ /** The single API version constant; every versioned path prepends it. */
14
+ export const API_VERSION = 'v1';
15
+ const V = `/${API_VERSION}`;
16
+ /** Route path builders. Keys mirror the spec §6 route table. */
17
+ export const routes = {
18
+ // Health / status
19
+ healthz: () => '/healthz',
20
+ status: () => `${V}/status`,
21
+ daemonRestart: () => `${V}/daemon/restart`,
22
+ // Nodes — collection + item
23
+ nodes: () => `${V}/nodes`,
24
+ reviveAll: () => `${V}/nodes/revive-all`,
25
+ node: (id) => `${V}/nodes/${id}`,
26
+ // Node reads
27
+ nodeSnapshot: (id) => `${V}/nodes/${id}/snapshot`,
28
+ nodeTranscript: (id) => `${V}/nodes/${id}/transcript`,
29
+ nodeContext: (id) => `${V}/nodes/${id}/context`,
30
+ nodeArtifacts: (id) => `${V}/nodes/${id}/artifacts`,
31
+ nodeReports: (id) => `${V}/nodes/${id}/reports`,
32
+ // Node messages / feed
33
+ nodeMessages: (id) => `${V}/nodes/${id}/messages`,
34
+ nodeInterrupt: (id) => `${V}/nodes/${id}/interrupt`,
35
+ // Node lifecycle actions
36
+ nodeFork: (id) => `${V}/nodes/${id}/fork`,
37
+ nodeRevive: (id) => `${V}/nodes/${id}/revive`,
38
+ nodeRelaunchRoot: (id) => `${V}/nodes/${id}/relaunch-root`,
39
+ nodeClose: (id) => `${V}/nodes/${id}/close`,
40
+ nodeRecycle: (id) => `${V}/nodes/${id}/recycle`,
41
+ nodeDemote: (id) => `${V}/nodes/${id}/demote`,
42
+ nodePromote: (id) => `${V}/nodes/${id}/promote`,
43
+ nodeYield: (id) => `${V}/nodes/${id}/yield`,
44
+ nodeWait: (id) => `${V}/nodes/${id}/wait`,
45
+ nodeConfig: (id) => `${V}/nodes/${id}/config`,
46
+ nodeWorktreeClose: (id) => `${V}/nodes/${id}/worktree/close`,
47
+ nodeAttach: (id) => `${V}/nodes/${id}/attach`,
48
+ // Focuses (viewer registry — the canvas.db `focuses` table)
49
+ focuses: () => `${V}/focuses`,
50
+ focusByNode: () => `${V}/focuses/by-node`,
51
+ focusByPane: () => `${V}/focuses/by-pane`,
52
+ focus: (focusId) => `${V}/focuses/${focusId}`,
53
+ // Subscriptions
54
+ nodeSubscriptions: (id) => `${V}/nodes/${id}/subscriptions`,
55
+ nodeSubscription: (id, target) => `${V}/nodes/${id}/subscriptions/${target}`,
56
+ // Crons (the cron-spec scheduler)
57
+ crons: () => `${V}/crons`,
58
+ cron: (cronId) => `${V}/crons/${cronId}`,
59
+ cronPause: (cronId) => `${V}/crons/${cronId}/pause`,
60
+ cronResume: (cronId) => `${V}/crons/${cronId}/resume`,
61
+ cronRun: (cronId) => `${V}/crons/${cronId}/run`,
62
+ // Canvas maintenance / reads
63
+ canvasAttention: () => `${V}/canvas/attention`,
64
+ canvasAttentionCounts: () => `${V}/canvas/attention/counts`,
65
+ canvasHistorySearch: () => `${V}/canvas/history/search`,
66
+ canvasHistoryGrep: () => `${V}/canvas/history/grep`,
67
+ canvasHistoryRead: () => `${V}/canvas/history/read`,
68
+ canvasSnapshot: () => `${V}/canvas/snapshot`,
69
+ canvasRoster: () => `${V}/canvas/roster`,
70
+ canvasPrune: () => `${V}/canvas/prune`,
71
+ canvasRebuildIndex: () => `${V}/canvas/rebuild-index`,
72
+ canvasConsults: () => `${V}/canvas/consults`,
73
+ // Human bridge + completion-handler forwarding (spec §6.5)
74
+ humanBridge: () => `${V}/human/bridge`,
75
+ humanDeliver: () => `${V}/human/deliver`,
76
+ humanConsult: () => `${V}/human/consult`,
77
+ humanVisual: () => `${V}/human/visual`,
78
+ // Humanloop inbox (Northlight crouter-inbox v1, inbox-contract.md §A)
79
+ humanInbox: () => `${V}/human/inbox`,
80
+ humanInboxTicket: (ticketId) => `${V}/human/inbox/${ticketId}`,
81
+ humanInboxRespond: (ticketId) => `${V}/human/inbox/${ticketId}/respond`,
82
+ humanInboxCancel: (ticketId) => `${V}/human/inbox/${ticketId}/cancel`,
83
+ // Profiles (server-side for P2 Core; CLI profile verbs stay fs-local)
84
+ profiles: () => `${V}/profiles`,
85
+ profile: (name) => `${V}/profiles/${name}`,
86
+ // Model auth
87
+ modelAuth: (provider) => `${V}/model-auth/${provider}`,
88
+ // Host file read (browser file-peek panel). The absolute path rides as a
89
+ // `path` query param, not a path segment — it is not a single safe segment.
90
+ filePeek: () => `${V}/files/peek`,
91
+ };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@north-light/crouter-api",
3
+ "version": "0.3.156",
4
+ "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, and the CrtrClient. Zero runtime dependencies.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "sideEffects": false,
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.json"
23
+ },
24
+ "publishConfig": {
25
+ "access": "restricted"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/vallum-security/crouter.git",
30
+ "directory": "packages/crouter-api"
31
+ },
32
+ "license": "UNLICENSED"
33
+ }