@craftstead/protocol 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +606 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +198 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agent Bridge contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
export declare const PROTOCOL_VERSION: 1;
|
|
2
|
+
export declare const RELAY_PROTOCOL_VERSION: 2;
|
|
3
|
+
/** Max plaintext bytes carried by one Noise transport message. */
|
|
4
|
+
export declare const MAX_FRAME_BYTES: number;
|
|
5
|
+
/** Max reassembled business message size. */
|
|
6
|
+
export declare const MAX_MESSAGE_BYTES: number;
|
|
7
|
+
/** Max concurrently reassembled messages per channel. */
|
|
8
|
+
export declare const MAX_PENDING_MESSAGES = 8;
|
|
9
|
+
/** Reassembly timeout for a chunked message. */
|
|
10
|
+
export declare const CHUNK_TTL_MS = 60000;
|
|
11
|
+
export declare const RELAY_WS_PATH = "/v1/ws";
|
|
12
|
+
export declare const RELAY_PING = "{\"v\":1,\"type\":\"ping\"}";
|
|
13
|
+
export declare const RELAY_PONG = "{\"v\":1,\"type\":\"pong\"}";
|
|
14
|
+
export type RelayRole = "bridge" | "browser";
|
|
15
|
+
export type RelayCredential = {
|
|
16
|
+
kind: "bridge";
|
|
17
|
+
token: string;
|
|
18
|
+
}
|
|
19
|
+
/** Only the SHA-256 of the invite token is sent, so the relay never learns the PSK input. */
|
|
20
|
+
| {
|
|
21
|
+
kind: "invite";
|
|
22
|
+
tokenHash: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "device";
|
|
25
|
+
deviceId: string;
|
|
26
|
+
token: string;
|
|
27
|
+
};
|
|
28
|
+
export interface RelayHello {
|
|
29
|
+
v: typeof RELAY_PROTOCOL_VERSION;
|
|
30
|
+
type: "hello";
|
|
31
|
+
role: RelayRole;
|
|
32
|
+
room: string;
|
|
33
|
+
/** 32 hex chars. Required for browser connections. */
|
|
34
|
+
channel?: string;
|
|
35
|
+
credential: RelayCredential;
|
|
36
|
+
}
|
|
37
|
+
export type RelayErrorCode = "bad_request" | "invalid_credential" | "invite_expired" | "invite_used" | "device_expired" | "device_revoked" | "bridge_offline" | "channel_in_use" | "unauthorized" | "not_found" | "conflict" | "rate_limited" | "internal";
|
|
38
|
+
export type RelayServerMessage = {
|
|
39
|
+
v: typeof RELAY_PROTOCOL_VERSION;
|
|
40
|
+
type: "ready";
|
|
41
|
+
role: RelayRole;
|
|
42
|
+
channel?: string;
|
|
43
|
+
bridgeOnline: boolean;
|
|
44
|
+
} | {
|
|
45
|
+
v: typeof RELAY_PROTOCOL_VERSION;
|
|
46
|
+
type: "error";
|
|
47
|
+
code: RelayErrorCode;
|
|
48
|
+
message: string;
|
|
49
|
+
} | {
|
|
50
|
+
v: typeof RELAY_PROTOCOL_VERSION;
|
|
51
|
+
type: "channel.open";
|
|
52
|
+
channel: string;
|
|
53
|
+
mode: "pair" | "device";
|
|
54
|
+
deviceId?: string;
|
|
55
|
+
inviteId?: string;
|
|
56
|
+
name?: string;
|
|
57
|
+
} | {
|
|
58
|
+
v: typeof RELAY_PROTOCOL_VERSION;
|
|
59
|
+
type: "channel.close";
|
|
60
|
+
channel: string;
|
|
61
|
+
reason?: string;
|
|
62
|
+
} | {
|
|
63
|
+
v: typeof RELAY_PROTOCOL_VERSION;
|
|
64
|
+
type: "peer.state";
|
|
65
|
+
bridgeOnline: boolean;
|
|
66
|
+
};
|
|
67
|
+
/** Bridge → relay control frames carried as text. */
|
|
68
|
+
export interface RelayBridgeControl {
|
|
69
|
+
v: typeof RELAY_PROTOCOL_VERSION;
|
|
70
|
+
type: "channel.close";
|
|
71
|
+
channel: string;
|
|
72
|
+
reason?: string;
|
|
73
|
+
}
|
|
74
|
+
/** 16-byte channel id prefix on relay binary frames plus Noise ciphertext. */
|
|
75
|
+
export declare const RELAY_CHANNEL_BYTES = 16;
|
|
76
|
+
export declare const METHODS: readonly ["pair.request", "host.info", "host.capabilities", "app.list", "project.list", "session.list", "session.get", "session.rail", "session.models", "task.messages", "message.list", "session.subscribe", "session.unsubscribe", "sync.resume", "message.send", "turn.cancel", "approval.respond", "transfer.prepare", "transfer.commit", "file.upload.begin", "file.upload.chunk", "file.upload.finish", "operation.get", "device.list", "device.revoke", "fs.roots", "fs.list", "fs.read", "shell.exec", "shell.cancel"];
|
|
77
|
+
export type Method = (typeof METHODS)[number];
|
|
78
|
+
export declare const EVENT_NAMES: readonly ["session.updated", "message.delta", "message.completed", "approval.required", "capabilities.changed", "host.status", "shell.output"];
|
|
79
|
+
export type EventName = (typeof EVENT_NAMES)[number];
|
|
80
|
+
export declare const ERROR_CODES: readonly ["invalid_params", "not_found", "unsupported", "unauthorized", "conflict", "operation_conflict", "stale_cursor", "adapter_unavailable", "rate_limited", "internal"];
|
|
81
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
82
|
+
export interface RequestMessage {
|
|
83
|
+
v: typeof PROTOCOL_VERSION;
|
|
84
|
+
kind: "request";
|
|
85
|
+
id: string;
|
|
86
|
+
method: Method;
|
|
87
|
+
params?: unknown;
|
|
88
|
+
/** Idempotency key for mutating methods. */
|
|
89
|
+
operationId?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface ResponseMessage {
|
|
92
|
+
v: typeof PROTOCOL_VERSION;
|
|
93
|
+
kind: "response";
|
|
94
|
+
id: string;
|
|
95
|
+
ok: boolean;
|
|
96
|
+
result?: unknown;
|
|
97
|
+
error?: {
|
|
98
|
+
code: ErrorCode;
|
|
99
|
+
message: string;
|
|
100
|
+
data?: unknown;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export interface EventMessage {
|
|
104
|
+
v: typeof PROTOCOL_VERSION;
|
|
105
|
+
kind: "event";
|
|
106
|
+
event: EventName;
|
|
107
|
+
data?: unknown;
|
|
108
|
+
}
|
|
109
|
+
export interface ChunkMessage {
|
|
110
|
+
v: typeof PROTOCOL_VERSION;
|
|
111
|
+
kind: "chunk";
|
|
112
|
+
messageId: string;
|
|
113
|
+
seq: number;
|
|
114
|
+
total: number;
|
|
115
|
+
/** base64 of this slice of the serialized message. */
|
|
116
|
+
data: string;
|
|
117
|
+
}
|
|
118
|
+
export type WireMessage = RequestMessage | ResponseMessage | EventMessage | ChunkMessage;
|
|
119
|
+
export interface PairRequestParams {
|
|
120
|
+
deviceName: string;
|
|
121
|
+
platform?: string;
|
|
122
|
+
/** 6-digit code the user must confirm on both screens. */
|
|
123
|
+
confirmCode: string;
|
|
124
|
+
}
|
|
125
|
+
export interface PairResult {
|
|
126
|
+
deviceId: string;
|
|
127
|
+
reconnectToken: string;
|
|
128
|
+
expiresAt: number | null;
|
|
129
|
+
confirmCode: string;
|
|
130
|
+
bridge: {
|
|
131
|
+
name: string;
|
|
132
|
+
version: string;
|
|
133
|
+
platform: string;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export interface DeviceSummary {
|
|
137
|
+
deviceId: string;
|
|
138
|
+
name: string;
|
|
139
|
+
createdAt: number;
|
|
140
|
+
expiresAt: number | null;
|
|
141
|
+
revokedAt: number | null;
|
|
142
|
+
lastSeenAt: number | null;
|
|
143
|
+
}
|
|
144
|
+
export interface HostInfoResult {
|
|
145
|
+
name: string;
|
|
146
|
+
version: string;
|
|
147
|
+
platform: string;
|
|
148
|
+
adapters: Array<{
|
|
149
|
+
id: string;
|
|
150
|
+
status: "ready" | "unavailable" | "needs_permission";
|
|
151
|
+
label?: string;
|
|
152
|
+
detail?: string;
|
|
153
|
+
}>;
|
|
154
|
+
/** Present only while the local user has opened the remote devtools switch. */
|
|
155
|
+
devtools?: DevtoolsStatus;
|
|
156
|
+
}
|
|
157
|
+
export declare const DEVTOOLS_CAPABILITIES: readonly ["files", "terminal"];
|
|
158
|
+
export type DevtoolsCapabilityName = (typeof DEVTOOLS_CAPABILITIES)[number];
|
|
159
|
+
/** One independently switched capability; `expiresAt` null means until it is turned off. */
|
|
160
|
+
export interface DevtoolsCapability {
|
|
161
|
+
enabled: boolean;
|
|
162
|
+
expiresAt: number | null;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Reading project files and running commands are separate switches: the browser is
|
|
166
|
+
* read-only and stays inside one project, while a command can write anywhere.
|
|
167
|
+
*/
|
|
168
|
+
export interface DevtoolsStatus {
|
|
169
|
+
files: DevtoolsCapability;
|
|
170
|
+
terminal: DevtoolsCapability;
|
|
171
|
+
}
|
|
172
|
+
export interface FsRoot {
|
|
173
|
+
name: string;
|
|
174
|
+
path: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* `root` is the project directory the chat belongs to; the bridge refuses anything else.
|
|
178
|
+
* `sessionId` is what ties the request to that chat: the bridge checks the session's
|
|
179
|
+
* project resolves to `root`, so a device cannot aim the browser at another project.
|
|
180
|
+
*/
|
|
181
|
+
export interface FsRootsParams {
|
|
182
|
+
sessionId: string;
|
|
183
|
+
root: string;
|
|
184
|
+
}
|
|
185
|
+
export interface FsRootsResult {
|
|
186
|
+
enabled: boolean;
|
|
187
|
+
roots: FsRoot[];
|
|
188
|
+
}
|
|
189
|
+
export interface FsEntry {
|
|
190
|
+
name: string;
|
|
191
|
+
path: string;
|
|
192
|
+
type: "file" | "dir";
|
|
193
|
+
size?: number;
|
|
194
|
+
mtime?: number;
|
|
195
|
+
}
|
|
196
|
+
export interface FsListParams {
|
|
197
|
+
/** The chat whose project directory is being browsed. */
|
|
198
|
+
sessionId: string;
|
|
199
|
+
/** Project directory of the chat; every read is confined to it. */
|
|
200
|
+
root: string;
|
|
201
|
+
path?: string;
|
|
202
|
+
}
|
|
203
|
+
export interface FsListResult {
|
|
204
|
+
path: string;
|
|
205
|
+
/** Parent directory, null at a root. */
|
|
206
|
+
parent: string | null;
|
|
207
|
+
entries: FsEntry[];
|
|
208
|
+
}
|
|
209
|
+
export interface FsReadParams {
|
|
210
|
+
sessionId: string;
|
|
211
|
+
root: string;
|
|
212
|
+
path: string;
|
|
213
|
+
}
|
|
214
|
+
export interface FsReadResult {
|
|
215
|
+
path: string;
|
|
216
|
+
name: string;
|
|
217
|
+
mime: string;
|
|
218
|
+
size: number;
|
|
219
|
+
mtime: number;
|
|
220
|
+
truncated: boolean;
|
|
221
|
+
/** Set for text-like files. */
|
|
222
|
+
text?: string;
|
|
223
|
+
/** Set for images, base64 encoded. */
|
|
224
|
+
dataBase64?: string;
|
|
225
|
+
}
|
|
226
|
+
export interface ShellExecParams {
|
|
227
|
+
/** The chat whose project directory the command runs in. */
|
|
228
|
+
sessionId: string;
|
|
229
|
+
/** Project directory of the chat; the command starts there unless `cwd` names a path inside it. */
|
|
230
|
+
root: string;
|
|
231
|
+
command: string;
|
|
232
|
+
cwd?: string;
|
|
233
|
+
timeoutMs?: number;
|
|
234
|
+
}
|
|
235
|
+
export interface ShellExecResult {
|
|
236
|
+
execId: string;
|
|
237
|
+
cwd: string;
|
|
238
|
+
}
|
|
239
|
+
export interface ShellCancelParams {
|
|
240
|
+
execId: string;
|
|
241
|
+
}
|
|
242
|
+
export interface ShellCancelResult {
|
|
243
|
+
ok: boolean;
|
|
244
|
+
killed: boolean;
|
|
245
|
+
}
|
|
246
|
+
export type ShellEventData = {
|
|
247
|
+
execId: string;
|
|
248
|
+
type: "stdout" | "stderr";
|
|
249
|
+
data: string;
|
|
250
|
+
} | {
|
|
251
|
+
execId: string;
|
|
252
|
+
type: "exit";
|
|
253
|
+
code: number | null;
|
|
254
|
+
signal: string | null;
|
|
255
|
+
killed: boolean;
|
|
256
|
+
durationMs: number;
|
|
257
|
+
truncated: boolean;
|
|
258
|
+
};
|
|
259
|
+
export type AdapterMode = "official" | "cli" | "local-store" | "ui-automation";
|
|
260
|
+
/** How complete an adapter's view is; never claim complete without evidence. */
|
|
261
|
+
export type Completeness = "complete" | "partial" | "unknown" | "unavailable";
|
|
262
|
+
export interface AdapterCapabilities {
|
|
263
|
+
enumerate: Completeness;
|
|
264
|
+
read: Completeness;
|
|
265
|
+
send: boolean;
|
|
266
|
+
/** Why sending is limited, even when it is available in some cases. */
|
|
267
|
+
sendDetail?: string;
|
|
268
|
+
/** Whether the adapter can start a new conversation in a project. */
|
|
269
|
+
create: boolean;
|
|
270
|
+
/** Why creating a conversation is unavailable. */
|
|
271
|
+
createDetail?: string;
|
|
272
|
+
/** Why an operation is unavailable. */
|
|
273
|
+
reason?: string;
|
|
274
|
+
}
|
|
275
|
+
export interface AppInfo {
|
|
276
|
+
appId: string;
|
|
277
|
+
provider: "anthropic" | "openai" | "google" | "deepseek";
|
|
278
|
+
kind: "claude-code" | "codex" | "antigravity" | "antigravity-desktop" | "dsh";
|
|
279
|
+
name: string;
|
|
280
|
+
version?: string;
|
|
281
|
+
mode: AdapterMode;
|
|
282
|
+
status: "ready" | "unavailable" | "needs_permission";
|
|
283
|
+
capabilities: AdapterCapabilities;
|
|
284
|
+
}
|
|
285
|
+
export interface ProjectInfo {
|
|
286
|
+
projectId: string;
|
|
287
|
+
appId: string;
|
|
288
|
+
name: string;
|
|
289
|
+
cwd?: string;
|
|
290
|
+
sessionCount: number;
|
|
291
|
+
}
|
|
292
|
+
export interface SessionSummary {
|
|
293
|
+
sessionId: string;
|
|
294
|
+
appId: string;
|
|
295
|
+
projectId: string;
|
|
296
|
+
kind: string;
|
|
297
|
+
title: string;
|
|
298
|
+
createdAt: number;
|
|
299
|
+
updatedAt: number;
|
|
300
|
+
archived: boolean;
|
|
301
|
+
/** Desktop currently holds a live process / open view for this session. */
|
|
302
|
+
live: boolean;
|
|
303
|
+
/** The session process is actively running a turn right now. */
|
|
304
|
+
busy?: boolean;
|
|
305
|
+
canSend: boolean;
|
|
306
|
+
/** Set when canSend is false. */
|
|
307
|
+
sendBlockedReason?: string;
|
|
308
|
+
/**
|
|
309
|
+
* The directory the session actually works in. A worktree session keeps the
|
|
310
|
+
* original repository as its project but runs in `.claude/worktrees/<name>`;
|
|
311
|
+
* remote tools (file browsing, commands) must start here, not at the project.
|
|
312
|
+
*/
|
|
313
|
+
cwd?: string;
|
|
314
|
+
}
|
|
315
|
+
export type MessageRole = "user" | "assistant" | "system";
|
|
316
|
+
/** One button the desktop client offered after a turn. */
|
|
317
|
+
export interface NextStepAction {
|
|
318
|
+
/** Desktop host action id (`commit`, `merge`, …); absent for reply buttons. */
|
|
319
|
+
action?: string;
|
|
320
|
+
/** Button text; a client sends it as the user's message when it has no host API. */
|
|
321
|
+
label: string;
|
|
322
|
+
}
|
|
323
|
+
/** 桌面端弹给用户选的选项;网页只展示,回答仍然在桌面里做。 */
|
|
324
|
+
export interface MessageQuestionOption {
|
|
325
|
+
label: string;
|
|
326
|
+
description?: string;
|
|
327
|
+
}
|
|
328
|
+
/** 桌面端的一次结构化提问(AskUserQuestion)。 */
|
|
329
|
+
export interface MessageQuestion {
|
|
330
|
+
/** 分组标题,桌面端显示在问题上方。 */
|
|
331
|
+
header?: string;
|
|
332
|
+
question: string;
|
|
333
|
+
multiSelect?: boolean;
|
|
334
|
+
options: MessageQuestionOption[];
|
|
335
|
+
}
|
|
336
|
+
export interface MessageBlock {
|
|
337
|
+
type: "text" | "tool" | "next-step" | "ask";
|
|
338
|
+
text: string;
|
|
339
|
+
truncated?: boolean;
|
|
340
|
+
/** `next-step` only: the question the client drew above the buttons. */
|
|
341
|
+
ask?: string;
|
|
342
|
+
/** `next-step` only: the buttons the desktop client offered. */
|
|
343
|
+
actions?: NextStepAction[];
|
|
344
|
+
/** `ask` only: the structured questions, for clients that can draw them. */
|
|
345
|
+
questions?: MessageQuestion[];
|
|
346
|
+
}
|
|
347
|
+
export interface MessageRecord {
|
|
348
|
+
messageId: string;
|
|
349
|
+
sessionId: string;
|
|
350
|
+
role: MessageRole;
|
|
351
|
+
createdAt: number;
|
|
352
|
+
blocks: MessageBlock[];
|
|
353
|
+
/** `peer` marks a message injected by another local agent session. */
|
|
354
|
+
origin?: "local" | "peer";
|
|
355
|
+
}
|
|
356
|
+
export interface AppListResult {
|
|
357
|
+
apps: AppInfo[];
|
|
358
|
+
}
|
|
359
|
+
export interface ProjectListResult {
|
|
360
|
+
projects: ProjectInfo[];
|
|
361
|
+
}
|
|
362
|
+
export interface SessionListResult {
|
|
363
|
+
sessions: SessionSummary[];
|
|
364
|
+
completeness: Completeness;
|
|
365
|
+
/** Set when completeness is not complete. */
|
|
366
|
+
note?: string;
|
|
367
|
+
}
|
|
368
|
+
export interface SessionGetResult {
|
|
369
|
+
session: SessionSummary;
|
|
370
|
+
}
|
|
371
|
+
export interface ContextDetail {
|
|
372
|
+
label: string;
|
|
373
|
+
value: string;
|
|
374
|
+
}
|
|
375
|
+
/** How much of the model context window the session currently occupies. */
|
|
376
|
+
export interface ContextUsage {
|
|
377
|
+
usedTokens: number;
|
|
378
|
+
windowTokens: number;
|
|
379
|
+
model?: string;
|
|
380
|
+
/** True when the window size is an assumption rather than reported by the client. */
|
|
381
|
+
windowEstimated?: boolean;
|
|
382
|
+
/** Client specific rows for the details popover. */
|
|
383
|
+
details?: ContextDetail[];
|
|
384
|
+
}
|
|
385
|
+
export interface MessageListResult {
|
|
386
|
+
messages: MessageRecord[];
|
|
387
|
+
/** Pass as `before` to load the previous page. Absent when at the start. */
|
|
388
|
+
nextBefore?: string;
|
|
389
|
+
completeness: Completeness;
|
|
390
|
+
note?: string;
|
|
391
|
+
/** Context window usage of the session, when the client exposes it. */
|
|
392
|
+
context?: ContextUsage;
|
|
393
|
+
/** The client is still working on the latest turn. */
|
|
394
|
+
busy?: boolean;
|
|
395
|
+
/** The latest turn was stopped by the user before it finished. */
|
|
396
|
+
interrupted?: boolean;
|
|
397
|
+
}
|
|
398
|
+
export interface MessageSendResult {
|
|
399
|
+
accepted: boolean;
|
|
400
|
+
/** True only when the target confirmed delivery. */
|
|
401
|
+
delivered: boolean;
|
|
402
|
+
detail?: string;
|
|
403
|
+
}
|
|
404
|
+
/** One environment row of the session rail. */
|
|
405
|
+
export interface RailRow {
|
|
406
|
+
label: string;
|
|
407
|
+
value: string;
|
|
408
|
+
}
|
|
409
|
+
/** A background task (subagent) spawned inside a session. */
|
|
410
|
+
export interface RailTask {
|
|
411
|
+
taskId: string;
|
|
412
|
+
name: string;
|
|
413
|
+
detail?: string;
|
|
414
|
+
kind: "subagent" | "background";
|
|
415
|
+
agentType?: string;
|
|
416
|
+
model?: string;
|
|
417
|
+
status: "running" | "done";
|
|
418
|
+
startedAt?: number;
|
|
419
|
+
updatedAt?: number;
|
|
420
|
+
/** 1 for tasks the session spawned directly. */
|
|
421
|
+
depth?: number;
|
|
422
|
+
}
|
|
423
|
+
/** What the session rail shows beside the conversation. */
|
|
424
|
+
export interface SessionRailResult {
|
|
425
|
+
environment: RailRow[];
|
|
426
|
+
context?: ContextUsage;
|
|
427
|
+
servers: Array<{
|
|
428
|
+
name: string;
|
|
429
|
+
detail?: string;
|
|
430
|
+
}>;
|
|
431
|
+
tasks: RailTask[];
|
|
432
|
+
note?: string;
|
|
433
|
+
}
|
|
434
|
+
export interface SessionRailParams {
|
|
435
|
+
sessionId: string;
|
|
436
|
+
}
|
|
437
|
+
export interface SessionModelsParams {
|
|
438
|
+
sessionId: string;
|
|
439
|
+
}
|
|
440
|
+
/** 会话所属客户端提供的一个模型。 */
|
|
441
|
+
export interface ModelOption {
|
|
442
|
+
id: string;
|
|
443
|
+
name: string;
|
|
444
|
+
/** 桌面端把次要模型收在「更多」里;保留原始分组,菜单据此排序。 */
|
|
445
|
+
section?: "main" | "overflow";
|
|
446
|
+
}
|
|
447
|
+
/** 当前会话的模型信息;各 agent 能给出的内容不一样,缺字段就是不知道。 */
|
|
448
|
+
export interface SessionModelsResult {
|
|
449
|
+
/** 客户端报告的模型标识。 */
|
|
450
|
+
current?: string;
|
|
451
|
+
/** 模型的可读名称。 */
|
|
452
|
+
currentName?: string;
|
|
453
|
+
models: ModelOption[];
|
|
454
|
+
/** 能否从网页切换模型;false 时看 note。 */
|
|
455
|
+
canSwitch: boolean;
|
|
456
|
+
note?: string;
|
|
457
|
+
}
|
|
458
|
+
export interface TaskMessagesParams {
|
|
459
|
+
sessionId: string;
|
|
460
|
+
taskId: string;
|
|
461
|
+
limit?: number;
|
|
462
|
+
before?: string;
|
|
463
|
+
}
|
|
464
|
+
export interface SessionListParams {
|
|
465
|
+
appId?: string;
|
|
466
|
+
projectId?: string;
|
|
467
|
+
includeArchived?: boolean;
|
|
468
|
+
limit?: number;
|
|
469
|
+
}
|
|
470
|
+
export interface MessageListParams {
|
|
471
|
+
sessionId: string;
|
|
472
|
+
limit?: number;
|
|
473
|
+
before?: string;
|
|
474
|
+
}
|
|
475
|
+
export interface MessageAttachment {
|
|
476
|
+
name: string;
|
|
477
|
+
mime: string;
|
|
478
|
+
size: number;
|
|
479
|
+
/** Absolute path on the bridge host. */
|
|
480
|
+
path: string;
|
|
481
|
+
kind: "image" | "file";
|
|
482
|
+
}
|
|
483
|
+
export interface MessageSendParams {
|
|
484
|
+
sessionId: string;
|
|
485
|
+
text: string;
|
|
486
|
+
attachments?: MessageAttachment[];
|
|
487
|
+
}
|
|
488
|
+
export interface FileUploadBeginParams {
|
|
489
|
+
sessionId: string;
|
|
490
|
+
name: string;
|
|
491
|
+
mime: string;
|
|
492
|
+
size: number;
|
|
493
|
+
}
|
|
494
|
+
export interface FileUploadBeginResult {
|
|
495
|
+
uploadId: string;
|
|
496
|
+
/** Raw bytes per upload.chunk call (base64 expands by ~4/3). */
|
|
497
|
+
chunkSize: number;
|
|
498
|
+
}
|
|
499
|
+
export interface FileUploadChunkParams {
|
|
500
|
+
uploadId: string;
|
|
501
|
+
index: number;
|
|
502
|
+
/** base64 of the raw chunk bytes. */
|
|
503
|
+
data: string;
|
|
504
|
+
}
|
|
505
|
+
export interface FileUploadChunkResult {
|
|
506
|
+
uploadId: string;
|
|
507
|
+
received: number;
|
|
508
|
+
}
|
|
509
|
+
export interface FileUploadFinishParams {
|
|
510
|
+
uploadId: string;
|
|
511
|
+
}
|
|
512
|
+
export interface FileUploadFinishResult {
|
|
513
|
+
uploadId: string;
|
|
514
|
+
name: string;
|
|
515
|
+
mime: string;
|
|
516
|
+
size: number;
|
|
517
|
+
path: string;
|
|
518
|
+
kind: "image" | "file";
|
|
519
|
+
}
|
|
520
|
+
export interface TransferPrepareParams {
|
|
521
|
+
sourceSessionId: string;
|
|
522
|
+
messageId: string;
|
|
523
|
+
targetSessionId: string;
|
|
524
|
+
}
|
|
525
|
+
export interface TransferSourceInfo {
|
|
526
|
+
sessionId: string;
|
|
527
|
+
title: string;
|
|
528
|
+
messageId: string;
|
|
529
|
+
role: MessageRecord["role"];
|
|
530
|
+
createdAt: number;
|
|
531
|
+
}
|
|
532
|
+
export interface TransferTargetInfo {
|
|
533
|
+
sessionId: string;
|
|
534
|
+
title: string;
|
|
535
|
+
appId: string;
|
|
536
|
+
canSend: boolean;
|
|
537
|
+
sendBlockedReason?: string;
|
|
538
|
+
}
|
|
539
|
+
/** 转发正文(含预览里编辑后的内容)的长度上限,客户端据此提前拦住过长的内容。 */
|
|
540
|
+
export declare const MAX_TRANSFER_CHARS = 200000;
|
|
541
|
+
export interface TransferPrepareResult {
|
|
542
|
+
transferId: string;
|
|
543
|
+
/** Epoch ms after which the prepared transfer is discarded. */
|
|
544
|
+
expiresAt: number;
|
|
545
|
+
/** Full, untruncated text the target will receive. */
|
|
546
|
+
text: string;
|
|
547
|
+
textLength: number;
|
|
548
|
+
source: TransferSourceInfo;
|
|
549
|
+
target: TransferTargetInfo;
|
|
550
|
+
note?: string;
|
|
551
|
+
}
|
|
552
|
+
export interface TransferCommitParams {
|
|
553
|
+
transferId: string;
|
|
554
|
+
/** 预览里改过的正文;省略时发送 prepare 生成的内容。 */
|
|
555
|
+
text?: string;
|
|
556
|
+
}
|
|
557
|
+
export interface TransferCommitResult extends MessageSendResult {
|
|
558
|
+
transferId: string;
|
|
559
|
+
targetSessionId: string;
|
|
560
|
+
textLength: number;
|
|
561
|
+
}
|
|
562
|
+
export interface CreateRoomRequest {
|
|
563
|
+
roomId?: string;
|
|
564
|
+
label?: string;
|
|
565
|
+
}
|
|
566
|
+
export interface CreateRoomResponse {
|
|
567
|
+
roomId: string;
|
|
568
|
+
bridgeToken: string;
|
|
569
|
+
}
|
|
570
|
+
export interface CreateInviteRequest {
|
|
571
|
+
inviteId: string;
|
|
572
|
+
/** SHA-256 of the invite token, hex. The raw token never leaves the bridge. */
|
|
573
|
+
tokenHash: string;
|
|
574
|
+
ttlSeconds?: number;
|
|
575
|
+
}
|
|
576
|
+
export interface InviteResponse {
|
|
577
|
+
inviteId: string;
|
|
578
|
+
expiresAt: number;
|
|
579
|
+
}
|
|
580
|
+
export interface RegisterDeviceRequest {
|
|
581
|
+
deviceId: string;
|
|
582
|
+
name: string;
|
|
583
|
+
publicKey: string;
|
|
584
|
+
ttlSeconds?: number | null;
|
|
585
|
+
}
|
|
586
|
+
export interface RegisterDeviceResponse {
|
|
587
|
+
deviceId: string;
|
|
588
|
+
reconnectToken: string;
|
|
589
|
+
expiresAt: number | null;
|
|
590
|
+
}
|
|
591
|
+
export interface DeviceListResponse {
|
|
592
|
+
devices: DeviceSummary[];
|
|
593
|
+
}
|
|
594
|
+
export interface RoomStatusResponse {
|
|
595
|
+
roomId: string;
|
|
596
|
+
bridgeOnline: boolean;
|
|
597
|
+
deviceCount: number;
|
|
598
|
+
}
|
|
599
|
+
export declare function parseRelayHello(value: unknown): RelayHello | null;
|
|
600
|
+
export declare function parseWireMessage(value: unknown): WireMessage | null;
|
|
601
|
+
export declare function isRequest(message: WireMessage): message is RequestMessage;
|
|
602
|
+
export declare function isResponse(message: WireMessage): message is ResponseMessage;
|
|
603
|
+
export declare function isEvent(message: WireMessage): message is EventMessage;
|
|
604
|
+
export declare function isChunk(message: WireMessage): message is ChunkMessage;
|
|
605
|
+
export declare function parseBridgeControl(value: unknown): RelayBridgeControl | null;
|
|
606
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,EAAG,CAAU,CAAC;AAC3C,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAC;AAEjD,kEAAkE;AAClE,eAAO,MAAM,eAAe,QAAY,CAAC;AACzC,6CAA6C;AAC7C,eAAO,MAAM,iBAAiB,QAAkB,CAAC;AACjD,yDAAyD;AACzD,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,gDAAgD;AAChD,eAAO,MAAM,YAAY,QAAS,CAAC;AAEnC,eAAO,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O,IAAI,YAAY,CAErE;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,IAAI,YAAY,CAErE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAU5E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
export const PROTOCOL_VERSION = 1;
|
|
2
|
+
export const RELAY_PROTOCOL_VERSION = 2;
|
|
3
|
+
/** Max plaintext bytes carried by one Noise transport message. */
|
|
4
|
+
export const MAX_FRAME_BYTES = 32 * 1024;
|
|
5
|
+
/** Max reassembled business message size. */
|
|
6
|
+
export const MAX_MESSAGE_BYTES = 4 * 1024 * 1024;
|
|
7
|
+
/** Max concurrently reassembled messages per channel. */
|
|
8
|
+
export const MAX_PENDING_MESSAGES = 8;
|
|
9
|
+
/** Reassembly timeout for a chunked message. */
|
|
10
|
+
export const CHUNK_TTL_MS = 60_000;
|
|
11
|
+
export const RELAY_WS_PATH = "/v1/ws";
|
|
12
|
+
export const RELAY_PING = '{"v":1,"type":"ping"}';
|
|
13
|
+
export const RELAY_PONG = '{"v":1,"type":"pong"}';
|
|
14
|
+
/** 16-byte channel id prefix on relay binary frames plus Noise ciphertext. */
|
|
15
|
+
export const RELAY_CHANNEL_BYTES = 16;
|
|
16
|
+
export const METHODS = [
|
|
17
|
+
"pair.request",
|
|
18
|
+
"host.info",
|
|
19
|
+
"host.capabilities",
|
|
20
|
+
"app.list",
|
|
21
|
+
"project.list",
|
|
22
|
+
"session.list",
|
|
23
|
+
"session.get",
|
|
24
|
+
"session.rail",
|
|
25
|
+
"session.models",
|
|
26
|
+
"task.messages",
|
|
27
|
+
"message.list",
|
|
28
|
+
"session.subscribe",
|
|
29
|
+
"session.unsubscribe",
|
|
30
|
+
"sync.resume",
|
|
31
|
+
"message.send",
|
|
32
|
+
"turn.cancel",
|
|
33
|
+
"approval.respond",
|
|
34
|
+
"transfer.prepare",
|
|
35
|
+
"transfer.commit",
|
|
36
|
+
"file.upload.begin",
|
|
37
|
+
"file.upload.chunk",
|
|
38
|
+
"file.upload.finish",
|
|
39
|
+
"operation.get",
|
|
40
|
+
"device.list",
|
|
41
|
+
"device.revoke",
|
|
42
|
+
"fs.roots",
|
|
43
|
+
"fs.list",
|
|
44
|
+
"fs.read",
|
|
45
|
+
"shell.exec",
|
|
46
|
+
"shell.cancel",
|
|
47
|
+
];
|
|
48
|
+
export const EVENT_NAMES = [
|
|
49
|
+
"session.updated",
|
|
50
|
+
"message.delta",
|
|
51
|
+
"message.completed",
|
|
52
|
+
"approval.required",
|
|
53
|
+
"capabilities.changed",
|
|
54
|
+
"host.status",
|
|
55
|
+
"shell.output",
|
|
56
|
+
];
|
|
57
|
+
export const ERROR_CODES = [
|
|
58
|
+
"invalid_params",
|
|
59
|
+
"not_found",
|
|
60
|
+
"unsupported",
|
|
61
|
+
"unauthorized",
|
|
62
|
+
"conflict",
|
|
63
|
+
"operation_conflict",
|
|
64
|
+
"stale_cursor",
|
|
65
|
+
"adapter_unavailable",
|
|
66
|
+
"rate_limited",
|
|
67
|
+
"internal",
|
|
68
|
+
];
|
|
69
|
+
// ---- Remote devtools (files + single command execution) ----
|
|
70
|
+
export const DEVTOOLS_CAPABILITIES = ["files", "terminal"];
|
|
71
|
+
/** 转发正文(含预览里编辑后的内容)的长度上限,客户端据此提前拦住过长的内容。 */
|
|
72
|
+
export const MAX_TRANSFER_CHARS = 200_000;
|
|
73
|
+
function isObject(value) {
|
|
74
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
|
+
}
|
|
76
|
+
function isString(value) {
|
|
77
|
+
return typeof value === "string";
|
|
78
|
+
}
|
|
79
|
+
export function parseRelayHello(value) {
|
|
80
|
+
if (!isObject(value))
|
|
81
|
+
return null;
|
|
82
|
+
if (value["v"] !== RELAY_PROTOCOL_VERSION)
|
|
83
|
+
return null;
|
|
84
|
+
if (value["type"] !== "hello")
|
|
85
|
+
return null;
|
|
86
|
+
const role = value["role"];
|
|
87
|
+
if (role !== "bridge" && role !== "browser")
|
|
88
|
+
return null;
|
|
89
|
+
const room = value["room"];
|
|
90
|
+
if (!isString(room) || !/^[a-z0-9-]{8,64}$/.test(room))
|
|
91
|
+
return null;
|
|
92
|
+
const credential = value["credential"];
|
|
93
|
+
if (!isObject(credential))
|
|
94
|
+
return null;
|
|
95
|
+
const kind = credential["kind"];
|
|
96
|
+
let parsed;
|
|
97
|
+
if (kind === "invite") {
|
|
98
|
+
const tokenHash = credential["tokenHash"];
|
|
99
|
+
if (!isString(tokenHash) || !/^[0-9a-f]{64}$/.test(tokenHash))
|
|
100
|
+
return null;
|
|
101
|
+
parsed = { kind, tokenHash };
|
|
102
|
+
}
|
|
103
|
+
else if (kind === "bridge" || kind === "device") {
|
|
104
|
+
const token = credential["token"];
|
|
105
|
+
if (!isString(token) || token.length < 16 || token.length > 256)
|
|
106
|
+
return null;
|
|
107
|
+
if (kind === "bridge") {
|
|
108
|
+
parsed = { kind, token };
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const deviceId = credential["deviceId"];
|
|
112
|
+
if (!isString(deviceId) || !/^[a-z0-9-]{8,64}$/.test(deviceId))
|
|
113
|
+
return null;
|
|
114
|
+
parsed = { kind, deviceId, token };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const channel = value["channel"];
|
|
121
|
+
if (role === "browser") {
|
|
122
|
+
if (!isString(channel) || !/^[0-9a-f]{32}$/.test(channel))
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
else if (channel !== undefined) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return channel === undefined
|
|
129
|
+
? { v: RELAY_PROTOCOL_VERSION, type: "hello", role, room, credential: parsed }
|
|
130
|
+
: { v: RELAY_PROTOCOL_VERSION, type: "hello", role, room, channel, credential: parsed };
|
|
131
|
+
}
|
|
132
|
+
export function parseWireMessage(value) {
|
|
133
|
+
if (!isObject(value) || value["v"] !== PROTOCOL_VERSION)
|
|
134
|
+
return null;
|
|
135
|
+
const kind = value["kind"];
|
|
136
|
+
if (kind === "request") {
|
|
137
|
+
const id = value["id"];
|
|
138
|
+
const method = value["method"];
|
|
139
|
+
if (!isString(id) || id.length === 0 || id.length > 64)
|
|
140
|
+
return null;
|
|
141
|
+
if (!isString(method) || !METHODS.includes(method))
|
|
142
|
+
return null;
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
if (kind === "response") {
|
|
146
|
+
const id = value["id"];
|
|
147
|
+
if (!isString(id) || typeof value["ok"] !== "boolean")
|
|
148
|
+
return null;
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
if (kind === "event") {
|
|
152
|
+
const event = value["event"];
|
|
153
|
+
if (!isString(event) || !EVENT_NAMES.includes(event))
|
|
154
|
+
return null;
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
if (kind === "chunk") {
|
|
158
|
+
const { messageId, seq, total, data } = value;
|
|
159
|
+
if (!isString(messageId) || !isString(data))
|
|
160
|
+
return null;
|
|
161
|
+
if (typeof seq !== "number" || typeof total !== "number")
|
|
162
|
+
return null;
|
|
163
|
+
if (!Number.isInteger(seq) || !Number.isInteger(total))
|
|
164
|
+
return null;
|
|
165
|
+
if (seq < 0 || total < 1 || total > 4096 || seq >= total)
|
|
166
|
+
return null;
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
export function isRequest(message) {
|
|
172
|
+
return message.kind === "request";
|
|
173
|
+
}
|
|
174
|
+
export function isResponse(message) {
|
|
175
|
+
return message.kind === "response";
|
|
176
|
+
}
|
|
177
|
+
export function isEvent(message) {
|
|
178
|
+
return message.kind === "event";
|
|
179
|
+
}
|
|
180
|
+
export function isChunk(message) {
|
|
181
|
+
return message.kind === "chunk";
|
|
182
|
+
}
|
|
183
|
+
export function parseBridgeControl(value) {
|
|
184
|
+
if (!isObject(value))
|
|
185
|
+
return null;
|
|
186
|
+
if (value["v"] !== RELAY_PROTOCOL_VERSION || value["type"] !== "channel.close")
|
|
187
|
+
return null;
|
|
188
|
+
const channel = value["channel"];
|
|
189
|
+
if (!isString(channel) || !/^[0-9a-f]{32}$/.test(channel))
|
|
190
|
+
return null;
|
|
191
|
+
const reason = value["reason"];
|
|
192
|
+
if (reason !== undefined && !isString(reason))
|
|
193
|
+
return null;
|
|
194
|
+
return reason === undefined
|
|
195
|
+
? { v: RELAY_PROTOCOL_VERSION, type: "channel.close", channel }
|
|
196
|
+
: { v: RELAY_PROTOCOL_VERSION, type: "channel.close", channel, reason };
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAU,CAAC;AAC3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAU,CAAC;AAEjD,kEAAkE;AAClE,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC;AACzC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACjD,yDAAyD;AACzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,gDAAgD;AAChD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AAEnC,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC;AACtC,MAAM,CAAC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AA8ElD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,c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AAO,IAAI,CAAC;IAC3D,OAAO,MAAM,KAAK,SAAS;QACzB,CAAC,CAAC,EAAE,CAAC,EAAE,sBAAsB,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE;QAC/D,CAAC,CAAC,EAAE,CAAC,EAAE,sBAAsB,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC5E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@craftstead/protocol",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Agent Bridge 的共享协议类型",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"!dist/*.tsbuildinfo"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/gowinder/agent-bridge.git",
|
|
22
|
+
"directory": "packages/protocol"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -b"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/README.md
DELETED