@chatpanel/sdk 0.1.0

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.
@@ -0,0 +1,384 @@
1
+ /** Every operation in the contract, keyed by operationId — the route table the runtime executes. */
2
+ export const OPERATIONS = {
3
+ "gateway.health": { id: "gateway.health", method: "GET", path: "/health", auth: "open", since: null, stream: null, pathParams: [], queryParams: [] },
4
+ "gateway.whoami": { id: "gateway.whoami", method: "POST", path: "/whoami", auth: "open", since: "0.9.0", stream: null, pathParams: [], queryParams: [] },
5
+ "gateway.pairCode": { id: "gateway.pairCode", method: "POST", path: "/pair/code", auth: "token", since: "0.9.0", stream: null, pathParams: [], queryParams: [] },
6
+ "gateway.pair": { id: "gateway.pair", method: "POST", path: "/pair", auth: "open", since: "0.9.0", stream: null, pathParams: [], queryParams: [] },
7
+ "gateway.audit": { id: "gateway.audit", method: "GET", path: "/audit", auth: "token", since: null, stream: null, pathParams: [], queryParams: [] },
8
+ "models.list": { id: "models.list", method: "GET", path: "/v1/models", auth: "open", since: null, stream: null, pathParams: [], queryParams: [] },
9
+ "chat.completions": { id: "chat.completions", method: "POST", path: "/v1/chat/completions", auth: "open", since: null, stream: "sse-when-stream", pathParams: [], queryParams: [] },
10
+ "redaction.preview": { id: "redaction.preview", method: "POST", path: "/redact", auth: "open", since: "0.6.62", stream: null, pathParams: [], queryParams: [] },
11
+ "history.search": { id: "history.search", method: "POST", path: "/v1/history/search", auth: "open", since: null, stream: null, pathParams: [], queryParams: [] },
12
+ "history.smartSearch": { id: "history.smartSearch", method: "POST", path: "/v1/history/smart-search", auth: "open", since: null, stream: null, pathParams: [], queryParams: [] },
13
+ "history.related": { id: "history.related", method: "GET", path: "/v1/history/related", auth: "open", since: null, stream: null, pathParams: [], queryParams: ["id", "limit"] },
14
+ "history.status": { id: "history.status", method: "GET", path: "/v1/history/status", auth: "open", since: null, stream: null, pathParams: [], queryParams: [] },
15
+ "history.list": { id: "history.list", method: "GET", path: "/v1/history/list", auth: "open", since: null, stream: null, pathParams: [], queryParams: ["limit", "offset", "type"] },
16
+ "history.get": { id: "history.get", method: "GET", path: "/v1/history/get", auth: "open", since: null, stream: null, pathParams: [], queryParams: ["id", "maxChars", "offset"] },
17
+ "history.records": { id: "history.records", method: "GET", path: "/v1/history/records", auth: "open", since: "0.10.0", stream: null, pathParams: [], queryParams: ["since", "cursor", "limit", "kind"] },
18
+ "history.putRecords": { id: "history.putRecords", method: "PUT", path: "/v1/history/records", auth: "token", since: "0.10.0", stream: null, pathParams: [], queryParams: [] },
19
+ "history.stream": { id: "history.stream", method: "GET", path: "/v1/history/stream", auth: "open", since: "0.11.0", stream: "sse", pathParams: [], queryParams: [] },
20
+ "history.ingest": { id: "history.ingest", method: "POST", path: "/v1/history/ingest", auth: "token", since: null, stream: null, pathParams: [], queryParams: [] },
21
+ "memory.list": { id: "memory.list", method: "GET", path: "/v1/memory/list", auth: "open", since: null, stream: null, pathParams: [], queryParams: [] },
22
+ "memory.recall": { id: "memory.recall", method: "POST", path: "/v1/memory/recall", auth: "open", since: null, stream: null, pathParams: [], queryParams: [] },
23
+ "memory.remember": { id: "memory.remember", method: "POST", path: "/v1/memory/remember", auth: "token", since: null, stream: null, pathParams: [], queryParams: [] },
24
+ "memory.forget": { id: "memory.forget", method: "POST", path: "/v1/memory/forget", auth: "token", since: null, stream: null, pathParams: [], queryParams: [] },
25
+ "memory.sync": { id: "memory.sync", method: "POST", path: "/v1/memory/sync", auth: "token", since: null, stream: null, pathParams: [], queryParams: [] },
26
+ "prefs.get": { id: "prefs.get", method: "GET", path: "/v1/prefs", auth: "open", since: "0.6.77", stream: null, pathParams: [], queryParams: ["section", "stamps"] },
27
+ "prefs.put": { id: "prefs.put", method: "POST", path: "/v1/prefs", auth: "open", since: "0.6.77", stream: null, pathParams: [], queryParams: [] },
28
+ "prefs.delete": { id: "prefs.delete", method: "DELETE", path: "/v1/prefs", auth: "open", since: "0.6.77", stream: null, pathParams: [], queryParams: ["section"] },
29
+ "prefs.events": { id: "prefs.events", method: "GET", path: "/v1/prefs/events", auth: "open", since: "0.6.77", stream: "sse", pathParams: [], queryParams: [] },
30
+ "teams.listRuns": { id: "teams.listRuns", method: "GET", path: "/v1/teams/runs", auth: "open", since: "0.6.78", stream: null, pathParams: [], queryParams: ["limit", "team"] },
31
+ "teams.createRun": { id: "teams.createRun", method: "POST", path: "/v1/teams/runs", auth: "open", since: "0.6.78", stream: null, pathParams: [], queryParams: [] },
32
+ "teams.getRun": { id: "teams.getRun", method: "GET", path: "/v1/teams/runs/{runId}", auth: "open", since: "0.6.78", stream: null, pathParams: ["runId"], queryParams: ["events"] },
33
+ "teams.deleteRun": { id: "teams.deleteRun", method: "DELETE", path: "/v1/teams/runs/{runId}", auth: "open", since: "0.6.110", stream: null, pathParams: ["runId"], queryParams: [] },
34
+ "teams.runEvents": { id: "teams.runEvents", method: "GET", path: "/v1/teams/runs/{runId}/events", auth: "open", since: "0.6.78", stream: "sse", pathParams: ["runId"], queryParams: ["after"] },
35
+ "teams.appendRunEvents": { id: "teams.appendRunEvents", method: "POST", path: "/v1/teams/runs/{runId}/events", auth: "open", since: "0.6.78", stream: null, pathParams: ["runId"], queryParams: [] },
36
+ "teams.stopRun": { id: "teams.stopRun", method: "POST", path: "/v1/teams/runs/{runId}/stop", auth: "open", since: "0.6.78", stream: null, pathParams: ["runId"], queryParams: [] },
37
+ "teams.answer": { id: "teams.answer", method: "POST", path: "/v1/teams/runs/{runId}/answer", auth: "open", since: "0.6.81", stream: null, pathParams: ["runId"], queryParams: [] },
38
+ "teams.decide": { id: "teams.decide", method: "POST", path: "/v1/teams/runs/{runId}/decide", auth: "open", since: "0.6.81", stream: null, pathParams: ["runId"], queryParams: [] },
39
+ "teams.post": { id: "teams.post", method: "POST", path: "/v1/teams/runs/{runId}/post", auth: "open", since: "0.6.81", stream: null, pathParams: ["runId"], queryParams: [] },
40
+ "teams.removeThread": { id: "teams.removeThread", method: "DELETE", path: "/v1/teams/runs/{runId}/threads/{threadId}", auth: "open", since: "0.6.106", stream: null, pathParams: ["runId", "threadId"], queryParams: [] },
41
+ "teams.handoff": { id: "teams.handoff", method: "POST", path: "/v1/teams/runs/{runId}/handoff", auth: "open", since: "0.6.85", stream: null, pathParams: ["runId"], queryParams: [] },
42
+ "teams.checkpoint": { id: "teams.checkpoint", method: "GET", path: "/v1/teams/runs/{runId}/checkpoint", auth: "open", since: "0.6.85", stream: null, pathParams: ["runId"], queryParams: [] },
43
+ "teams.claim": { id: "teams.claim", method: "POST", path: "/v1/teams/runs/{runId}/claim", auth: "open", since: "0.6.85", stream: null, pathParams: ["runId"], queryParams: [] },
44
+ "projects.list": { id: "projects.list", method: "GET", path: "/v1/projects", auth: "open", since: "0.6.90", stream: null, pathParams: [], queryParams: ["limit", "status"] },
45
+ "projects.create": { id: "projects.create", method: "POST", path: "/v1/projects", auth: "open", since: "0.6.90", stream: null, pathParams: [], queryParams: [] },
46
+ "projects.jobBoard": { id: "projects.jobBoard", method: "GET", path: "/v1/projects/jobs", auth: "open", since: "0.6.90", stream: null, pathParams: [], queryParams: [] },
47
+ "projects.get": { id: "projects.get", method: "GET", path: "/v1/projects/{projectId}", auth: "open", since: "0.6.90", stream: null, pathParams: ["projectId"], queryParams: ["events"] },
48
+ "projects.delete": { id: "projects.delete", method: "DELETE", path: "/v1/projects/{projectId}", auth: "open", since: "0.6.90", stream: null, pathParams: ["projectId"], queryParams: [] },
49
+ "projects.events": { id: "projects.events", method: "GET", path: "/v1/projects/{projectId}/events", auth: "open", since: "0.6.90", stream: "sse", pathParams: ["projectId"], queryParams: ["after"] },
50
+ "projects.appendEvents": { id: "projects.appendEvents", method: "POST", path: "/v1/projects/{projectId}/events", auth: "open", since: "0.6.90", stream: null, pathParams: ["projectId"], queryParams: [] },
51
+ "projects.postJob": { id: "projects.postJob", method: "POST", path: "/v1/projects/{projectId}/jobs", auth: "open", since: "0.6.90", stream: null, pathParams: ["projectId"], queryParams: [] },
52
+ "projects.patchJob": { id: "projects.patchJob", method: "POST", path: "/v1/projects/{projectId}/jobs/{jobId}", auth: "open", since: "0.6.90", stream: null, pathParams: ["projectId", "jobId"], queryParams: [] },
53
+ "projects.applications": { id: "projects.applications", method: "GET", path: "/v1/projects/{projectId}/jobs/{jobId}/applications", auth: "open", since: "0.6.90", stream: null, pathParams: ["projectId", "jobId"], queryParams: ["reach", "chatModel"] },
54
+ "projects.recruit": { id: "projects.recruit", method: "POST", path: "/v1/projects/{projectId}/jobs/{jobId}/recruit", auth: "open", since: "0.6.90", stream: null, pathParams: ["projectId", "jobId"], queryParams: [] },
55
+ "agents.scorecards": { id: "agents.scorecards", method: "GET", path: "/v1/agents/scorecards", auth: "open", since: "0.6.87", stream: null, pathParams: [], queryParams: [] },
56
+ "agents.scorecard": { id: "agents.scorecard", method: "GET", path: "/v1/agents/{agentId}/scorecard", auth: "open", since: "0.6.87", stream: null, pathParams: ["agentId"], queryParams: [] },
57
+ "agents.rate": { id: "agents.rate", method: "POST", path: "/v1/agents/{agentId}/scorecard", auth: "open", since: "0.6.87", stream: null, pathParams: ["agentId"], queryParams: [] },
58
+ "engines.list": { id: "engines.list", method: "GET", path: "/v1/engines", auth: "open", since: "0.6.89", stream: null, pathParams: [], queryParams: ["minCalls"] },
59
+ "engines.card": { id: "engines.card", method: "GET", path: "/v1/engines/{engineKey}/card", auth: "open", since: "0.6.89", stream: null, pathParams: ["engineKey"], queryParams: ["entries", "minCalls"] },
60
+ "engines.appendEntry": { id: "engines.appendEntry", method: "POST", path: "/v1/engines/{engineKey}/entries", auth: "open", since: "0.6.89", stream: null, pathParams: ["engineKey"], queryParams: [] },
61
+ "skills.list": { id: "skills.list", method: "GET", path: "/skills", auth: "open", since: "0.6.64", stream: null, pathParams: [], queryParams: ["workdir"] },
62
+ "skills.get": { id: "skills.get", method: "GET", path: "/skills/{skillId}", auth: "open", since: "0.6.67", stream: null, pathParams: ["skillId"], queryParams: ["workdir"] },
63
+ };
64
+ /** Liveness, identity and pairing. */
65
+ export class GatewayApi {
66
+ rt;
67
+ constructor(rt) { this.rt = rt; }
68
+ /** Liveness, version and capabilities. Additive fields only. `version` is what every version gate reads. */
69
+ health(opts) {
70
+ return this.rt.request(OPERATIONS["gateway.health"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
71
+ }
72
+ /** What the gateway makes of this caller. — Gateway 0.9.0+. */
73
+ whoami(opts) {
74
+ return this.rt.request(OPERATIONS["gateway.whoami"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
75
+ }
76
+ /** Mint a one-time pairing code (5 minutes, one use, 5 attempts). Only a caller that already holds the token may mint one — pairing widens nothing. — Requires the gateway token. Gateway 0.9.0+. */
77
+ pairCode(opts) {
78
+ return this.rt.request(OPERATIONS["gateway.pairCode"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
79
+ }
80
+ /** Exchange a pairing code for the gateway token. — Gateway 0.9.0+. */
81
+ pair(body, opts) {
82
+ return this.rt.request(OPERATIONS["gateway.pair"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
83
+ }
84
+ /** The egress audit — which hosts this gateway has contacted and which its config allows. The checkable claim behind "nothing leaves the machine". Admin-gated because it names the user's model endpoints. — Requires the gateway token. */
85
+ audit(opts) {
86
+ return this.rt.request(OPERATIONS["gateway.audit"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
87
+ }
88
+ }
89
+ /** What the gateway can route to. */
90
+ export class ModelsApi {
91
+ rt;
92
+ constructor(rt) { this.rt = rt; }
93
+ /** Every model the gateway can route to. Describes the routing table, not the disk: a bridge agent is listed whether or not the CLI is installed. From 0.6.64 each agent carries `available`; from 0.6.66 a cloud model carries `configured: false` when a turn is known to fail for something the user can fix. */
94
+ list(opts) {
95
+ return this.rt.request(OPERATIONS["models.list"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
96
+ }
97
+ }
98
+ /** The OpenAI-compatible chat endpoint, redacted and routed by the gateway. */
99
+ export class ChatApi {
100
+ rt;
101
+ constructor(rt) { this.rt = rt; }
102
+ /** One chat turn through the gateway (OpenAI-compatible). Redacted on the way out, restored on the way back, routed by `model`. With `stream: true` the response is `text/event-stream` of OpenAI chunk objects ending in `data: [DONE]`. Send `tools` so a redacted turn can still act: the gateway relays a tool call back with real arguments and redacts the result. `X-ChatPanel-Redaction: off` is honoured only from a token-bearing caller (0.6.69+) and is recorded in the trace. **Two lanes.** An API destination (a cloud or local model endpoint) is a proxy hop and is open to any local caller. An AGENT destination (`codex`, `claude`, `opencode`, … — `provider_type: agent` in `GET /v1/models`) spawns a process on this machine, so the caller must hold the gateway token (0.9.0+): without it the gateway answers **401** `{ type: 'auth', code: 'agent_lane_token_required' }`. The SDKs surface that as `ForbiddenError` with `status` 401. */
103
+ completions(body, opts) {
104
+ return this.rt.request(OPERATIONS["chat.completions"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
105
+ }
106
+ /** The same call with `stream: true` — one frame per chunk until `[DONE]`. */
107
+ completionsStream(body, opts) {
108
+ return this.rt.stream(OPERATIONS["chat.completions"], { path: {}, query: undefined, headers: opts?.headers, body: { ...body, stream: true }, opts });
109
+ }
110
+ }
111
+ /** Preview what the model would receive. */
112
+ export class RedactionApi {
113
+ rt;
114
+ constructor(rt) { this.rt = rt; }
115
+ /** What the model would receive if this text were sent now. Runs the same redaction path as a real turn. The reply carries placeholder types, never the real values. — Gateway 0.6.62+. */
116
+ preview(body, opts) {
117
+ return this.rt.request(OPERATIONS["redaction.preview"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
118
+ }
119
+ }
120
+ /** The user's searchable history — chats, notes, meetings, briefs. */
121
+ export class HistoryApi {
122
+ rt;
123
+ constructor(rt) { this.rt = rt; }
124
+ /** One keyword query over the warm index. */
125
+ search(body, opts) {
126
+ return this.rt.request(OPERATIONS["history.search"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
127
+ }
128
+ /** Several phrasings at once, rank-fused; briefs lead. */
129
+ smartSearch(body, opts) {
130
+ return this.rt.request(OPERATIONS["history.smartSearch"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
131
+ }
132
+ /** The records most connected to one record. */
133
+ related(query, opts) {
134
+ return this.rt.request(OPERATIONS["history.related"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
135
+ }
136
+ /** Size and freshness of the warm index (and the lossless tier from 0.10.0). */
137
+ status(opts) {
138
+ return this.rt.request(OPERATIONS["history.status"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
139
+ }
140
+ /** A page of the warm index — metadata only, no bodies. */
141
+ list(query, opts) {
142
+ return this.rt.request(OPERATIONS["history.list"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
143
+ }
144
+ /** One full warm record, optionally paged by characters. */
145
+ get(query, opts) {
146
+ return this.rt.request(OPERATIONS["history.get"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
147
+ }
148
+ /** WHOLE records changed after a stamp, oldest first, paged by cursor, tombstones included. The lossless tier. A gateway without the SQLite store answers 501. — Gateway 0.10.0+. */
149
+ records(query, opts) {
150
+ return this.rt.request(OPERATIONS["history.records"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
151
+ }
152
+ /** Push whole records; the gateway derives the searchable text itself. — Requires the gateway token. Gateway 0.10.0+. */
153
+ putRecords(body, opts) {
154
+ return this.rt.request(OPERATIONS["history.putRecords"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
155
+ }
156
+ /** Live record changes — `hello` once, then a `records` event per change. — Gateway 0.11.0+. */
157
+ stream(opts) {
158
+ return this.rt.stream(OPERATIONS["history.stream"], { path: {}, query: undefined, headers: opts?.headers, opts });
159
+ }
160
+ /** Push flattened (lossy) records into the warm index. — Requires the gateway token. */
161
+ ingest(body, opts) {
162
+ return this.rt.request(OPERATIONS["history.ingest"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
163
+ }
164
+ }
165
+ /** Durable facts about the user, carried into every turn on every client. */
166
+ export class MemoryApi {
167
+ rt;
168
+ constructor(rt) { this.rt = rt; }
169
+ /** Every memory. */
170
+ list(opts) {
171
+ return this.rt.request(OPERATIONS["memory.list"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
172
+ }
173
+ /** The memories relevant to a text, and a prompt block that carries them. */
174
+ recall(body, opts) {
175
+ return this.rt.request(OPERATIONS["memory.recall"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
176
+ }
177
+ /** Save a durable fact. Never anonymous — `source` is recorded. — Requires the gateway token. */
178
+ remember(body, opts) {
179
+ return this.rt.request(OPERATIONS["memory.remember"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
180
+ }
181
+ /** Forget memories matching an id or words. — Requires the gateway token. */
182
+ forget(body, opts) {
183
+ return this.rt.request(OPERATIONS["memory.forget"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
184
+ }
185
+ /** Two-way merge in one round trip — push what you have, receive the full set. — Requires the gateway token. */
186
+ sync(body, opts) {
187
+ return this.rt.request(OPERATIONS["memory.sync"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
188
+ }
189
+ }
190
+ /** The settings every client shares. */
191
+ export class PrefsApi {
192
+ rt;
193
+ constructor(rt) { this.rt = rt; }
194
+ /** The shared sections, or only their stamps. — Gateway 0.6.77+. */
195
+ get(query, opts) {
196
+ return this.rt.request(OPERATIONS["prefs.get"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
197
+ }
198
+ /** Write sections; per-section last-writer-wins by stamp. — Gateway 0.6.77+. */
199
+ put(body, opts) {
200
+ return this.rt.request(OPERATIONS["prefs.put"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
201
+ }
202
+ /** Remove one section. — Gateway 0.6.77+. */
203
+ delete(query, opts) {
204
+ return this.rt.request(OPERATIONS["prefs.delete"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
205
+ }
206
+ /** Live — which sections another client wrote. — Gateway 0.6.77+. */
207
+ events(opts) {
208
+ return this.rt.stream(OPERATIONS["prefs.events"], { path: {}, query: undefined, headers: opts?.headers, opts });
209
+ }
210
+ }
211
+ /** Team runs — the board every client can read. */
212
+ export class TeamsApi {
213
+ rt;
214
+ constructor(rt) { this.rt = rt; }
215
+ /** The board — recent runs, newest first. — Gateway 0.6.78+. */
216
+ listRuns(query, opts) {
217
+ return this.rt.request(OPERATIONS["teams.listRuns"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
218
+ }
219
+ /** Open a run record. — Gateway 0.6.78+. */
220
+ createRun(body, opts) {
221
+ return this.rt.request(OPERATIONS["teams.createRun"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
222
+ }
223
+ /** One run, optionally with its events. — Gateway 0.6.78+. */
224
+ getRun(runId, query, opts) {
225
+ return this.rt.request(OPERATIONS["teams.getRun"], { path: { runId }, query: query, headers: opts?.headers, body: undefined, opts });
226
+ }
227
+ /** Remove a run; a live one is stopped first. — Gateway 0.6.110+. */
228
+ deleteRun(runId, opts) {
229
+ return this.rt.request(OPERATIONS["teams.deleteRun"], { path: { runId }, query: undefined, headers: opts?.headers, body: undefined, opts });
230
+ }
231
+ /** Tail a run — the record first, replay from `after`, then live. — Gateway 0.6.78+. */
232
+ runEvents(runId, query, opts) {
233
+ return this.rt.stream(OPERATIONS["teams.runEvents"], { path: { runId }, query: query, headers: opts?.headers, opts });
234
+ }
235
+ /** The running client appends events. — Gateway 0.6.78+. */
236
+ appendRunEvents(runId, body, opts) {
237
+ return this.rt.request(OPERATIONS["teams.appendRunEvents"], { path: { runId }, query: undefined, headers: opts?.headers, body: body, opts });
238
+ }
239
+ /** Ask the running client to stop. — Gateway 0.6.78+. */
240
+ stopRun(runId, opts) {
241
+ return this.rt.request(OPERATIONS["teams.stopRun"], { path: { runId }, query: undefined, headers: opts?.headers, body: undefined, opts });
242
+ }
243
+ /** A person answers an ask on the board. — Gateway 0.6.81+. */
244
+ answer(runId, body, opts) {
245
+ return this.rt.request(OPERATIONS["teams.answer"], { path: { runId }, query: undefined, headers: opts?.headers, body: body, opts });
246
+ }
247
+ /** Approve or reject a post. — Gateway 0.6.81+. */
248
+ decide(runId, body, opts) {
249
+ return this.rt.request(OPERATIONS["teams.decide"], { path: { runId }, query: undefined, headers: opts?.headers, body: body, opts });
250
+ }
251
+ /** Post a note to a thread. — Gateway 0.6.81+. */
252
+ post(runId, body, opts) {
253
+ return this.rt.request(OPERATIONS["teams.post"], { path: { runId }, query: undefined, headers: opts?.headers, body: body, opts });
254
+ }
255
+ /** A person removes a thread from the board. — Gateway 0.6.106+. */
256
+ removeThread(runId, threadId, opts) {
257
+ return this.rt.request(OPERATIONS["teams.removeThread"], { path: { runId, threadId }, query: undefined, headers: opts?.headers, body: undefined, opts });
258
+ }
259
+ /** Continue a task on another model. — Gateway 0.6.85+. */
260
+ handoff(runId, body, opts) {
261
+ return this.rt.request(OPERATIONS["teams.handoff"], { path: { runId }, query: undefined, headers: opts?.headers, body: body, opts });
262
+ }
263
+ /** What a client needs to resume a run whose client went away. — Gateway 0.6.85+. */
264
+ checkpoint(runId, opts) {
265
+ return this.rt.request(OPERATIONS["teams.checkpoint"], { path: { runId }, query: undefined, headers: opts?.headers, body: undefined, opts });
266
+ }
267
+ /** A client takes a stopped or stale run over. — Gateway 0.6.85+. */
268
+ claim(runId, body, opts) {
269
+ return this.rt.request(OPERATIONS["teams.claim"], { path: { runId }, query: undefined, headers: opts?.headers, body: body, opts });
270
+ }
271
+ }
272
+ /** The project record — the page a goal starts on and everything done for it. */
273
+ export class ProjectsApi {
274
+ rt;
275
+ constructor(rt) { this.rt = rt; }
276
+ /** Projects, newest activity first, jobs counted. — Gateway 0.6.90+. */
277
+ list(query, opts) {
278
+ return this.rt.request(OPERATIONS["projects.list"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
279
+ }
280
+ /** Open a record (idempotent) or update the page. — Gateway 0.6.90+. */
281
+ create(body, opts) {
282
+ return this.rt.request(OPERATIONS["projects.create"], { path: {}, query: undefined, headers: opts?.headers, body: body, opts });
283
+ }
284
+ /** Every open posting across projects. — Gateway 0.6.90+. */
285
+ jobBoard(opts) {
286
+ return this.rt.request(OPERATIONS["projects.jobBoard"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
287
+ }
288
+ /** The record — jobs, runs, spend, decisions, report. — Gateway 0.6.90+. */
289
+ get(projectId, query, opts) {
290
+ return this.rt.request(OPERATIONS["projects.get"], { path: { projectId }, query: query, headers: opts?.headers, body: undefined, opts });
291
+ }
292
+ /** Remove a project record. — Gateway 0.6.90+. */
293
+ delete(projectId, opts) {
294
+ return this.rt.request(OPERATIONS["projects.delete"], { path: { projectId }, query: undefined, headers: opts?.headers, body: undefined, opts });
295
+ }
296
+ /** Tail a project — hello, replay, then live. — Gateway 0.6.90+. */
297
+ events(projectId, query, opts) {
298
+ return this.rt.stream(OPERATIONS["projects.events"], { path: { projectId }, query: query, headers: opts?.headers, opts });
299
+ }
300
+ /** The executive loop appends (status, run.linked, run.spent, decision, report). — Gateway 0.6.90+. */
301
+ appendEvents(projectId, body, opts) {
302
+ return this.rt.request(OPERATIONS["projects.appendEvents"], { path: { projectId }, query: undefined, headers: opts?.headers, body: body, opts });
303
+ }
304
+ /** Post a job. — Gateway 0.6.90+. */
305
+ postJob(projectId, body, opts) {
306
+ return this.rt.request(OPERATIONS["projects.postJob"], { path: { projectId }, query: undefined, headers: opts?.headers, body: body, opts });
307
+ }
308
+ /** Move a job along its state machine. — Gateway 0.6.90+. */
309
+ patchJob(projectId, jobId, body, opts) {
310
+ return this.rt.request(OPERATIONS["projects.patchJob"], { path: { projectId, jobId }, query: undefined, headers: opts?.headers, body: body, opts });
311
+ }
312
+ /** The pool applies at once; `prompt` is the evaluator's, for a structured call. — Gateway 0.6.90+. */
313
+ applications(projectId, jobId, query, opts) {
314
+ return this.rt.request(OPERATIONS["projects.applications"], { path: { projectId, jobId }, query: query, headers: opts?.headers, body: undefined, opts });
315
+ }
316
+ /** One pass — fit recomputed, the evaluation read through the schema, the pick landed as events. — Gateway 0.6.90+. */
317
+ recruit(projectId, jobId, body, opts) {
318
+ return this.rt.request(OPERATIONS["projects.recruit"], { path: { projectId, jobId }, query: undefined, headers: opts?.headers, body: body, opts });
319
+ }
320
+ }
321
+ /** Attested per-agent scorecards. */
322
+ export class AgentsApi {
323
+ rt;
324
+ constructor(rt) { this.rt = rt; }
325
+ /** Every agent's scorecard. — Gateway 0.6.87+. */
326
+ scorecards(opts) {
327
+ return this.rt.request(OPERATIONS["agents.scorecards"], { path: {}, query: undefined, headers: opts?.headers, body: undefined, opts });
328
+ }
329
+ /** One agent's attested scorecard. — Gateway 0.6.87+. */
330
+ scorecard(agentId, opts) {
331
+ return this.rt.request(OPERATIONS["agents.scorecard"], { path: { agentId }, query: undefined, headers: opts?.headers, body: undefined, opts });
332
+ }
333
+ /** A person rates the agent's work on a run, task or job. — Gateway 0.6.87+. */
334
+ rate(agentId, body, opts) {
335
+ return this.rt.request(OPERATIONS["agents.rate"], { path: { agentId }, query: undefined, headers: opts?.headers, body: body, opts });
336
+ }
337
+ }
338
+ /** The model ledger — every engine's card. */
339
+ export class EnginesApi {
340
+ rt;
341
+ constructor(rt) { this.rt = rt; }
342
+ /** Every engine's card. — Gateway 0.6.89+. */
343
+ list(query, opts) {
344
+ return this.rt.request(OPERATIONS["engines.list"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
345
+ }
346
+ /** One engine's card, optionally with entries. — Gateway 0.6.89+. */
347
+ card(engineKey, query, opts) {
348
+ return this.rt.request(OPERATIONS["engines.card"], { path: { engineKey }, query: query, headers: opts?.headers, body: undefined, opts });
349
+ }
350
+ /** Append a ledger entry for an engine. — Gateway 0.6.89+. */
351
+ appendEntry(engineKey, body, opts) {
352
+ return this.rt.request(OPERATIONS["engines.appendEntry"], { path: { engineKey }, query: undefined, headers: opts?.headers, body: body, opts });
353
+ }
354
+ }
355
+ /** The skills on this machine (served through the bridge). */
356
+ export class SkillsApi {
357
+ rt;
358
+ constructor(rt) { this.rt = rt; }
359
+ /** The skills on this machine — with a prompt character count, not the prompt. — Gateway 0.6.64+. */
360
+ list(query, opts) {
361
+ return this.rt.request(OPERATIONS["skills.list"], { path: {}, query: query, headers: opts?.headers, body: undefined, opts });
362
+ }
363
+ /** One skill, with its prompt. — Gateway 0.6.67+. */
364
+ get(skillId, query, opts) {
365
+ return this.rt.request(OPERATIONS["skills.get"], { path: { skillId }, query: query, headers: opts?.headers, body: undefined, opts });
366
+ }
367
+ }
368
+ /** The namespaces a client exposes, built on one runtime. */
369
+ export function buildApi(rt) {
370
+ return {
371
+ gateway: new GatewayApi(rt),
372
+ models: new ModelsApi(rt),
373
+ chat: new ChatApi(rt),
374
+ redaction: new RedactionApi(rt),
375
+ history: new HistoryApi(rt),
376
+ memory: new MemoryApi(rt),
377
+ prefs: new PrefsApi(rt),
378
+ teams: new TeamsApi(rt),
379
+ projects: new ProjectsApi(rt),
380
+ agents: new AgentsApi(rt),
381
+ engines: new EnginesApi(rt),
382
+ skills: new SkillsApi(rt),
383
+ };
384
+ }
@@ -0,0 +1,10 @@
1
+ export declare const TOKEN_ENV = "CHATPANEL_GATEWAY_TOKEN";
2
+ export declare const TOKEN_PATH_ENV = "CHATPANEL_GATEWAY_TOKEN_PATH";
3
+ export declare const URL_ENV = "CHATPANEL_GATEWAY_URL";
4
+ /** The base URL from `CHATPANEL_GATEWAY_URL`, else the default. */
5
+ export declare function discoverBaseUrl(): string;
6
+ /**
7
+ * The token from `CHATPANEL_GATEWAY_TOKEN`, else the token file (`CHATPANEL_GATEWAY_TOKEN_PATH`
8
+ * or `~/.chatpanel/gateway-token`). Empty string when neither exists or this is not Node.
9
+ */
10
+ export declare function discoverToken(): Promise<string>;
@@ -0,0 +1,35 @@
1
+ // Where the credential lives, for a client that runs as the user on the gateway's machine.
2
+ //
3
+ // The gateway writes its token to `~/.chatpanel/gateway-token` (mode 0600). A Node
4
+ // application running as that user may read it — that is the same trust the CLI and the
5
+ // desktop use. This module is the only place that knows the path. It loads `node:fs` lazily
6
+ // so the package still imports in a browser, where there is no file and a client pairs
7
+ // instead (see `ChatPanel.pair`).
8
+ export const TOKEN_ENV = 'CHATPANEL_GATEWAY_TOKEN';
9
+ export const TOKEN_PATH_ENV = 'CHATPANEL_GATEWAY_TOKEN_PATH';
10
+ export const URL_ENV = 'CHATPANEL_GATEWAY_URL';
11
+ function env() {
12
+ const p = globalThis.process;
13
+ return p?.env || {};
14
+ }
15
+ /** The base URL from `CHATPANEL_GATEWAY_URL`, else the default. */
16
+ export function discoverBaseUrl() {
17
+ return env()[URL_ENV] || 'http://127.0.0.1:4320';
18
+ }
19
+ /**
20
+ * The token from `CHATPANEL_GATEWAY_TOKEN`, else the token file (`CHATPANEL_GATEWAY_TOKEN_PATH`
21
+ * or `~/.chatpanel/gateway-token`). Empty string when neither exists or this is not Node.
22
+ */
23
+ export async function discoverToken() {
24
+ const e = env();
25
+ if (e[TOKEN_ENV])
26
+ return e[TOKEN_ENV].trim();
27
+ try {
28
+ const [{ readFileSync }, os, path] = await Promise.all([import('node:fs'), import('node:os'), import('node:path')]);
29
+ const file = e[TOKEN_PATH_ENV] || path.join(os.homedir(), '.chatpanel', 'gateway-token');
30
+ return readFileSync(file, 'utf8').trim();
31
+ }
32
+ catch {
33
+ return '';
34
+ }
35
+ }
@@ -0,0 +1,34 @@
1
+ /** Base class. `status` is the HTTP status (0 when no response arrived); `type` is the gateway's stable machine word when it gave one. */
2
+ export declare class ChatPanelError extends Error {
3
+ readonly status: number;
4
+ readonly type: string;
5
+ readonly operation: string;
6
+ constructor(message: string, { status, type, operation }?: {
7
+ status?: number;
8
+ type?: string;
9
+ operation?: string;
10
+ });
11
+ }
12
+ /** The gateway did not answer at all — not running, wrong port, or the request timed out. */
13
+ export declare class GatewayUnreachableError extends ChatPanelError {
14
+ constructor(message: string, operation?: string);
15
+ }
16
+ /** The running gateway predates this route. `have` is its version, `need` the one the route requires. */
17
+ export declare class GatewayTooOldError extends ChatPanelError {
18
+ readonly have: string;
19
+ readonly need: string;
20
+ constructor(operation: string, have: string, need: string);
21
+ }
22
+ /** The route (or the agent lane, for a chat turn — 401) needs the gateway token and this client has none, or the wrong one. */
23
+ export declare class ForbiddenError extends ChatPanelError {
24
+ constructor(message: string, operation?: string, status?: 401 | 403);
25
+ }
26
+ export declare class NotFoundError extends ChatPanelError {
27
+ constructor(message: string, operation?: string);
28
+ }
29
+ /** The SDK refused to send: a bad base URL, a missing path parameter, a body that is not JSON. */
30
+ export declare class InvalidRequestError extends ChatPanelError {
31
+ constructor(message: string, operation?: string);
32
+ }
33
+ /** Build the right subclass from an HTTP response the gateway answered with. */
34
+ export declare function errorFromResponse(status: number, body: string, operation: string): ChatPanelError;
package/dist/errors.js ADDED
@@ -0,0 +1,62 @@
1
+ // Every failure the SDK raises is one of these, so an application can branch on the class
2
+ // (or on `status` / `type`) instead of parsing prose. The message is the gateway's own
3
+ // sentence when it gave one — it is written for a person and far more useful than "request
4
+ // failed". No error ever carries a token or a request header.
5
+ /** Base class. `status` is the HTTP status (0 when no response arrived); `type` is the gateway's stable machine word when it gave one. */
6
+ export class ChatPanelError extends Error {
7
+ status;
8
+ type;
9
+ operation;
10
+ constructor(message, { status = 0, type = 'error', operation = '' } = {}) {
11
+ super(message);
12
+ this.name = new.target.name;
13
+ this.status = status;
14
+ this.type = type;
15
+ this.operation = operation;
16
+ }
17
+ }
18
+ /** The gateway did not answer at all — not running, wrong port, or the request timed out. */
19
+ export class GatewayUnreachableError extends ChatPanelError {
20
+ constructor(message, operation = '') { super(message, { status: 0, type: 'unreachable', operation }); }
21
+ }
22
+ /** The running gateway predates this route. `have` is its version, `need` the one the route requires. */
23
+ export class GatewayTooOldError extends ChatPanelError {
24
+ have;
25
+ need;
26
+ constructor(operation, have, need) {
27
+ super(`your gateway is ${have}; ${operation} needs ${need} — update it (npm i -g @chatpanel/gateway, or the desktop app)`, { status: 0, type: 'gateway_too_old', operation });
28
+ this.have = have;
29
+ this.need = need;
30
+ }
31
+ }
32
+ /** The route (or the agent lane, for a chat turn — 401) needs the gateway token and this client has none, or the wrong one. */
33
+ export class ForbiddenError extends ChatPanelError {
34
+ constructor(message, operation = '', status = 403) { super(message, { status, type: 'forbidden', operation }); }
35
+ }
36
+ export class NotFoundError extends ChatPanelError {
37
+ constructor(message, operation = '') { super(message, { status: 404, type: 'not_found', operation }); }
38
+ }
39
+ /** The SDK refused to send: a bad base URL, a missing path parameter, a body that is not JSON. */
40
+ export class InvalidRequestError extends ChatPanelError {
41
+ constructor(message, operation = '') { super(message, { status: 0, type: 'invalid_request', operation }); }
42
+ }
43
+ /** Build the right subclass from an HTTP response the gateway answered with. */
44
+ export function errorFromResponse(status, body, operation) {
45
+ let message = body.slice(0, 400) || `HTTP ${status}`;
46
+ let type = '';
47
+ try {
48
+ const j = JSON.parse(body);
49
+ if (typeof j?.error === 'string')
50
+ message = j.error;
51
+ else if (j?.error && typeof j.error === 'object') {
52
+ message = String(j.error.message || message);
53
+ type = String(j.error.type || '');
54
+ }
55
+ }
56
+ catch { /* not JSON — keep the text */ }
57
+ if (status === 403 || status === 401)
58
+ return new ForbiddenError(message, operation, status);
59
+ if (status === 404)
60
+ return new NotFoundError(message, operation);
61
+ return new ChatPanelError(message, { status, type: type || `http_${status}`, operation });
62
+ }
@@ -0,0 +1,53 @@
1
+ import { buildApi, type OperationId } from './api.generated.js';
2
+ import { Runtime, type RuntimeOptions, type CallArgs, type SseFrame } from './runtime.js';
3
+ import type * as T from './types.generated.js';
4
+ export * from './errors.js';
5
+ export * from './api.generated.js';
6
+ export * as types from './types.generated.js';
7
+ export { Runtime, compareVersions, normaliseBaseUrl } from './runtime.js';
8
+ export type { RuntimeOptions, RequestOptions, Operation, SseFrame, TokenSource } from './runtime.js';
9
+ export { parseFrame, readSse } from './sse.js';
10
+ export { discoverBaseUrl, discoverToken, TOKEN_ENV, TOKEN_PATH_ENV, URL_ENV } from './discover.js';
11
+ export type ChatPanelOptions = RuntimeOptions;
12
+ type Api = ReturnType<typeof buildApi>;
13
+ /** The text of one streamed chunk, or '' when the frame carried none (a usage frame, a tool call). */
14
+ export declare function deltaText(frame: SseFrame<T.ChatCompletionChunk>): string;
15
+ export declare class ChatPanel {
16
+ readonly runtime: Runtime;
17
+ readonly gateway: Api['gateway'];
18
+ readonly models: Api['models'];
19
+ readonly chat: Api['chat'] & {
20
+ /** Stream just the text of a reply. Tool calls and usage frames are skipped; use `completionsStream` for those. */
21
+ text(body: T.ChatCompletionRequest, opts?: Parameters<Api['chat']['completionsStream']>[1]): AsyncGenerator<string>;
22
+ };
23
+ readonly redaction: Api['redaction'];
24
+ readonly history: Api['history'];
25
+ readonly memory: Api['memory'];
26
+ readonly prefs: Api['prefs'];
27
+ readonly teams: Api['teams'];
28
+ readonly projects: Api['projects'];
29
+ readonly agents: Api['agents'];
30
+ readonly engines: Api['engines'];
31
+ readonly skills: Api['skills'];
32
+ constructor(options?: ChatPanelOptions);
33
+ /**
34
+ * A client for the gateway on this machine, authenticated as the current user: the URL
35
+ * from `CHATPANEL_GATEWAY_URL` and the token from `CHATPANEL_GATEWAY_TOKEN` or the token
36
+ * file. Node only — in a browser, construct one and `pair()`.
37
+ */
38
+ static fromEnvironment(options?: Omit<ChatPanelOptions, 'token' | 'baseUrl'> & {
39
+ baseUrl?: string;
40
+ }): Promise<ChatPanel>;
41
+ /** GET /health — the version and capabilities. */
42
+ health(): Promise<T.Health>;
43
+ /** POST /whoami — the trust class this client's credential earns. */
44
+ whoami(): Promise<T.WhoAmI>;
45
+ /**
46
+ * Exchange a one-time code (from `chatpanel-gateway pair`, or the desktop app) for the
47
+ * token, and start using it. The token is RETURNED so the application can persist it —
48
+ * in the platform keychain or a 0600 file, never in a log or a URL.
49
+ */
50
+ pair(code: string): Promise<T.Paired>;
51
+ /** Any operation by id, for a route added to the contract before this package learnt a method for it. */
52
+ request<R = unknown>(id: OperationId, args?: CallArgs): Promise<R>;
53
+ }