@dshremote/protocol 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/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@dshremote/protocol",
3
+ "description": "DshRemote 共享协议:事件契约 v1 + Connector↔Control Plane 通信协议的 TS 类型与 JSON Schema(单一事实来源)",
4
+ "version": "0.1.0",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "lib/index.js",
8
+ "types": "lib/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/types/index.d.ts",
12
+ "default": "./lib/index.js"
13
+ },
14
+ "./schemas/*": "./schemas/*",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "lib",
19
+ "schemas"
20
+ ],
21
+ "devDependencies": {
22
+ "@types/node": "^22.20.0",
23
+ "typescript": "^5.5.4"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json",
27
+ "typecheck": "tsc -p tsconfig.json --noEmit"
28
+ }
29
+ }
@@ -0,0 +1,401 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://dshremote.dev/schemas/dshremote-event-v1.schema.json",
4
+ "title": "DshRemote Event Contract v1",
5
+ "description": "事件契约 v1:Connector 上传到 Control Plane 的结构化 Session 事件信封。对应《DshRemote 技术方案 v0.1》§3。只允许脱敏后的结构化安全子集。",
6
+ "type": "object",
7
+ "oneOf": [
8
+ { "$ref": "#/$defs/sessionMetaEnvelope" },
9
+ { "$ref": "#/$defs/turnStartEnvelope" },
10
+ { "$ref": "#/$defs/turnEndEnvelope" },
11
+ { "$ref": "#/$defs/stepStartEnvelope" },
12
+ { "$ref": "#/$defs/stepEndEnvelope" },
13
+ { "$ref": "#/$defs/userMessageEnvelope" },
14
+ { "$ref": "#/$defs/assistantMessageEnvelope" },
15
+ { "$ref": "#/$defs/toolCallEnvelope" },
16
+ { "$ref": "#/$defs/toolResultEnvelope" },
17
+ { "$ref": "#/$defs/errorEnvelope" },
18
+ { "$ref": "#/$defs/approvalAskedEnvelope" },
19
+ { "$ref": "#/$defs/approvalDecidedEnvelope" },
20
+ { "$ref": "#/$defs/runStatusEnvelope" },
21
+ { "$ref": "#/$defs/artifactRefEnvelope" }
22
+ ],
23
+ "$defs": {
24
+ "id": { "type": "string", "minLength": 1, "maxLength": 128 },
25
+ "contentBlock": {
26
+ "oneOf": [
27
+ {
28
+ "type": "object",
29
+ "additionalProperties": false,
30
+ "required": ["type", "text"],
31
+ "properties": {
32
+ "type": { "const": "text" },
33
+ "text": { "type": "string" }
34
+ }
35
+ },
36
+ {
37
+ "type": "object",
38
+ "additionalProperties": false,
39
+ "required": ["type", "text"],
40
+ "properties": {
41
+ "type": { "const": "reasoning" },
42
+ "text": { "type": "string" }
43
+ }
44
+ }
45
+ ]
46
+ },
47
+ "errorSummary": {
48
+ "type": "object",
49
+ "additionalProperties": false,
50
+ "required": ["message"],
51
+ "properties": {
52
+ "message": { "type": "string" },
53
+ "code": { "type": "string" },
54
+ "errorId": { "type": "string" }
55
+ }
56
+ },
57
+ "envelopeBase": {
58
+ "type": "object",
59
+ "additionalProperties": false,
60
+ "required": ["schema", "version", "connectionId", "sessionId", "seq", "time", "msgId", "kind", "payload"],
61
+ "properties": {
62
+ "schema": { "const": "dshremote.event" },
63
+ "version": { "const": 1 },
64
+ "connectionId": { "$ref": "#/$defs/id" },
65
+ "sessionId": { "$ref": "#/$defs/id" },
66
+ "runId": { "$ref": "#/$defs/id" },
67
+ "seq": { "type": "integer", "minimum": 0 },
68
+ "time": { "type": "integer", "minimum": 0 },
69
+ "msgId": { "type": "string", "pattern": "^[A-Za-z0-9:_-]+$" }
70
+ }
71
+ },
72
+ "sessionMetaEnvelope": {
73
+ "allOf": [
74
+ { "$ref": "#/$defs/envelopeBase" },
75
+ {
76
+ "properties": {
77
+ "kind": { "const": "sessionMeta" },
78
+ "payload": {
79
+ "type": "object",
80
+ "additionalProperties": false,
81
+ "required": ["createdBy"],
82
+ "properties": {
83
+ "title": { "type": "string" },
84
+ "cwdSummary": { "type": "string", "description": "目录名摘要,禁止绝对路径" },
85
+ "projectId": { "$ref": "#/$defs/id" },
86
+ "createdBy": { "enum": ["local", "webhook", "cloud"] }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ ]
92
+ },
93
+ "turnStartEnvelope": {
94
+ "allOf": [
95
+ { "$ref": "#/$defs/envelopeBase" },
96
+ {
97
+ "properties": {
98
+ "kind": { "const": "turnStart" },
99
+ "payload": {
100
+ "type": "object",
101
+ "additionalProperties": false,
102
+ "required": ["turn"],
103
+ "properties": { "turn": { "type": "integer", "minimum": 0 } }
104
+ }
105
+ }
106
+ }
107
+ ]
108
+ },
109
+ "turnEndEnvelope": {
110
+ "allOf": [
111
+ { "$ref": "#/$defs/envelopeBase" },
112
+ {
113
+ "properties": {
114
+ "kind": { "const": "turnEnd" },
115
+ "payload": {
116
+ "type": "object",
117
+ "additionalProperties": false,
118
+ "required": ["turn", "reason"],
119
+ "properties": {
120
+ "turn": { "type": "integer", "minimum": 0 },
121
+ "reason": { "enum": ["completed", "aborted", "blocked", "error", "max-tokens", "interrupted"] },
122
+ "error": { "$ref": "#/$defs/errorSummary" }
123
+ }
124
+ }
125
+ }
126
+ }
127
+ ]
128
+ },
129
+ "stepStartEnvelope": {
130
+ "allOf": [
131
+ { "$ref": "#/$defs/envelopeBase" },
132
+ {
133
+ "properties": {
134
+ "kind": { "const": "stepStart" },
135
+ "payload": {
136
+ "type": "object",
137
+ "additionalProperties": false,
138
+ "required": ["turn", "step"],
139
+ "properties": {
140
+ "turn": { "type": "integer", "minimum": 0 },
141
+ "step": { "type": "integer", "minimum": 0 }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ ]
147
+ },
148
+ "stepEndEnvelope": {
149
+ "allOf": [
150
+ { "$ref": "#/$defs/envelopeBase" },
151
+ {
152
+ "properties": {
153
+ "kind": { "const": "stepEnd" },
154
+ "payload": {
155
+ "type": "object",
156
+ "additionalProperties": false,
157
+ "required": ["turn", "step"],
158
+ "properties": {
159
+ "turn": { "type": "integer", "minimum": 0 },
160
+ "step": { "type": "integer", "minimum": 0 }
161
+ }
162
+ }
163
+ }
164
+ }
165
+ ]
166
+ },
167
+ "userMessageEnvelope": {
168
+ "allOf": [
169
+ { "$ref": "#/$defs/envelopeBase" },
170
+ {
171
+ "properties": {
172
+ "kind": { "const": "userMessage" },
173
+ "payload": {
174
+ "type": "object",
175
+ "additionalProperties": false,
176
+ "required": ["content", "source"],
177
+ "properties": {
178
+ "content": {
179
+ "type": "array",
180
+ "items": { "$ref": "#/$defs/contentBlock" },
181
+ "minItems": 1
182
+ },
183
+ "source": { "enum": ["user", "inject", "webhook", "plugin"] },
184
+ "sourcePlugin": { "type": "string", "description": "source 为 plugin 时的插件名(远程投递记 dshremote;harness 上下文快照记 @deepseek-ai/dsh-system-prompt)" },
185
+ "sourceForm": { "type": "string", "description": "source 为 plugin 时的 form(如 snapshot),用于标注上下文快照" }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ ]
191
+ },
192
+ "assistantMessageEnvelope": {
193
+ "allOf": [
194
+ { "$ref": "#/$defs/envelopeBase" },
195
+ {
196
+ "properties": {
197
+ "kind": { "const": "assistantMessage" },
198
+ "payload": {
199
+ "type": "object",
200
+ "additionalProperties": false,
201
+ "required": ["content"],
202
+ "properties": {
203
+ "content": {
204
+ "type": "array",
205
+ "items": { "$ref": "#/$defs/contentBlock" }
206
+ },
207
+ "usage": {
208
+ "type": "object",
209
+ "additionalProperties": false,
210
+ "properties": {
211
+ "inputTokens": { "type": "integer", "minimum": 0 },
212
+ "outputTokens": { "type": "integer", "minimum": 0 },
213
+ "cacheReadTokens": { "type": "integer", "minimum": 0, "description": "缓存命中读取 token(provider 回报该桶时才有)" },
214
+ "cacheWriteTokens": { "type": "integer", "minimum": 0, "description": "缓存写入 token(provider 回报该桶时才有)" },
215
+ "reasoningTokens": { "type": "integer", "minimum": 0, "description": "推理输出 token 子集(provider 回报该桶时才有)" },
216
+ "totalTokens": { "type": "integer", "minimum": 0, "description": "输入 + 输出精确合计(provider 回报或可推导时才有)" },
217
+ "routes": {
218
+ "type": "array",
219
+ "items": {
220
+ "type": "object",
221
+ "additionalProperties": false,
222
+ "properties": {
223
+ "provider": { "type": "string" },
224
+ "model": { "type": "string" }
225
+ }
226
+ },
227
+ "description": "本轮贡献的 provider/model 路由(去重,供「提供方/模型」展示)"
228
+ }
229
+ }
230
+ },
231
+ "timing": {
232
+ "type": "object",
233
+ "additionalProperties": false,
234
+ "required": ["llmMs"],
235
+ "properties": {
236
+ "llmMs": { "type": "integer", "minimum": 0, "description": "step/start → assistant/message 的模型墙钟耗时(ms)" },
237
+ "ttftMs": { "type": "integer", "minimum": 0, "description": "step/start → 首个 token delta(ms)" },
238
+ "decodeMs": { "type": "integer", "minimum": 0, "description": "首个 token delta → assistant/message(ms)" }
239
+ },
240
+ "description": "单步 LLM 耗时快照(对齐官方 sessionStats 口径)"
241
+ },
242
+ "interrupted": { "type": "boolean" }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ ]
248
+ },
249
+ "toolCallEnvelope": {
250
+ "allOf": [
251
+ { "$ref": "#/$defs/envelopeBase" },
252
+ {
253
+ "properties": {
254
+ "kind": { "const": "toolCall" },
255
+ "payload": {
256
+ "type": "object",
257
+ "additionalProperties": false,
258
+ "required": ["callId", "name", "arguments"],
259
+ "properties": {
260
+ "callId": { "type": "string" },
261
+ "name": { "type": "string" },
262
+ "arguments": { "type": "string", "description": "脱敏 + 截断后的 JSON 字符串" }
263
+ }
264
+ }
265
+ }
266
+ }
267
+ ]
268
+ },
269
+ "toolResultEnvelope": {
270
+ "allOf": [
271
+ { "$ref": "#/$defs/envelopeBase" },
272
+ {
273
+ "properties": {
274
+ "kind": { "const": "toolResult" },
275
+ "payload": {
276
+ "type": "object",
277
+ "additionalProperties": false,
278
+ "required": ["callId"],
279
+ "properties": {
280
+ "callId": { "type": "string" },
281
+ "summary": { "type": "string" },
282
+ "error": {
283
+ "type": "object",
284
+ "additionalProperties": false,
285
+ "required": ["name", "code"],
286
+ "properties": {
287
+ "name": { "type": "string" },
288
+ "code": { "type": "string" }
289
+ }
290
+ },
291
+ "meta": { "type": "object", "description": "白名单字段,其余丢弃" }
292
+ }
293
+ }
294
+ }
295
+ }
296
+ ]
297
+ },
298
+ "errorEnvelope": {
299
+ "allOf": [
300
+ { "$ref": "#/$defs/envelopeBase" },
301
+ {
302
+ "properties": {
303
+ "kind": { "const": "error" },
304
+ "payload": {
305
+ "type": "object",
306
+ "additionalProperties": false,
307
+ "required": ["error"],
308
+ "properties": {
309
+ "error": { "$ref": "#/$defs/errorSummary" },
310
+ "turn": { "type": "integer", "minimum": 0 }
311
+ }
312
+ }
313
+ }
314
+ }
315
+ ]
316
+ },
317
+ "approvalAskedEnvelope": {
318
+ "allOf": [
319
+ { "$ref": "#/$defs/envelopeBase" },
320
+ {
321
+ "properties": {
322
+ "kind": { "const": "approvalAsked" },
323
+ "payload": {
324
+ "type": "object",
325
+ "additionalProperties": false,
326
+ "required": ["requestId", "toolName"],
327
+ "properties": {
328
+ "requestId": { "type": "string" },
329
+ "toolName": { "type": "string" },
330
+ "callId": { "type": "string" },
331
+ "reason": { "type": "string" }
332
+ }
333
+ }
334
+ }
335
+ }
336
+ ]
337
+ },
338
+ "approvalDecidedEnvelope": {
339
+ "allOf": [
340
+ { "$ref": "#/$defs/envelopeBase" },
341
+ {
342
+ "properties": {
343
+ "kind": { "const": "approvalDecided" },
344
+ "payload": {
345
+ "type": "object",
346
+ "additionalProperties": false,
347
+ "required": ["requestId", "outcome"],
348
+ "properties": {
349
+ "requestId": { "type": "string" },
350
+ "outcome": { "enum": ["allowed-once", "rejected", "cancelled", "unavailable"] }
351
+ }
352
+ }
353
+ }
354
+ }
355
+ ]
356
+ },
357
+ "runStatusEnvelope": {
358
+ "allOf": [
359
+ { "$ref": "#/$defs/envelopeBase" },
360
+ {
361
+ "properties": {
362
+ "kind": { "const": "runStatus" },
363
+ "payload": {
364
+ "type": "object",
365
+ "additionalProperties": false,
366
+ "required": ["runId", "status"],
367
+ "properties": {
368
+ "runId": { "$ref": "#/$defs/id" },
369
+ "status": { "enum": ["Queued", "Running", "WaitingForApproval", "Completed", "Failed", "Stopped", "ConnectionLost", "TimedOut", "LimitReached"] },
370
+ "reason": { "type": "string" }
371
+ }
372
+ }
373
+ }
374
+ }
375
+ ]
376
+ },
377
+ "artifactRefEnvelope": {
378
+ "allOf": [
379
+ { "$ref": "#/$defs/envelopeBase" },
380
+ {
381
+ "properties": {
382
+ "kind": { "const": "artifactRef" },
383
+ "payload": {
384
+ "type": "object",
385
+ "additionalProperties": false,
386
+ "required": ["artifactId", "name", "size", "type", "downloadAuthorized"],
387
+ "properties": {
388
+ "artifactId": { "type": "string" },
389
+ "name": { "type": "string" },
390
+ "size": { "type": "integer", "minimum": 0 },
391
+ "type": { "type": "string" },
392
+ "retentionMs": { "type": "integer", "minimum": 0 },
393
+ "downloadAuthorized": { "type": "boolean" }
394
+ }
395
+ }
396
+ }
397
+ }
398
+ ]
399
+ }
400
+ }
401
+ }