@roll-agent/protocol 0.3.0 → 0.4.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/README.md +93 -14
- package/dist/index.d.ts +9482 -663
- package/dist/index.js +1257 -138
- package/dist/schema/roll-runtime-protocol-v1.0.schema.json +2657 -0
- package/dist/schema/roll-runtime-protocol-v1.1.schema.json +2824 -0
- package/dist/schema/roll-runtime-protocol-v1.2.schema.json +4112 -0
- package/dist/schema/roll-runtime-protocol-v1.3.schema.json +5695 -0
- package/dist/schema/roll-runtime-protocol-v1.schema.json +4061 -1223
- package/fixtures/v1.2/invalid-duplicate-client-capability-method.json +9 -0
- package/fixtures/v1.2/invalid-legacy-approval-request.json +15 -0
- package/fixtures/v1.2/invalid-legacy-server-request-cancel-notification.json +9 -0
- package/fixtures/v1.2/invalid-sensitive-approval-request.json +19 -0
- package/fixtures/v1.2/invalid-sensitive-user-input-request.json +20 -0
- package/fixtures/v1.2/invalid-thread-snapshot-interaction-payload.json +37 -0
- package/fixtures/v1.2/invalid-user-input-request-response.json +13 -0
- package/fixtures/v1.2/valid-approval-request.json +22 -0
- package/fixtures/v1.2/valid-client-capabilities-set-request.json +9 -0
- package/fixtures/v1.2/valid-client-capabilities-set-response.json +8 -0
- package/fixtures/v1.2/valid-server-request-cancel-notification.json +8 -0
- package/fixtures/v1.2/valid-thread-snapshot-response.json +42 -0
- package/fixtures/v1.2/valid-user-input-request-response.json +11 -0
- package/fixtures/v1.2/valid-user-input-request.json +35 -0
- package/fixtures/v1.3/invalid-durable-delta-event-notification.json +19 -0
- package/fixtures/v1.3/invalid-ephemeral-completed-event-notification.json +15 -0
- package/fixtures/v1.3/invalid-runtime-events-resume-cursor-request.json +9 -0
- package/fixtures/v1.3/invalid-thread-recovery-snapshot-response.json +31 -0
- package/fixtures/v1.3/invalid-thread-recovery-snapshot-timestamp-response.json +21 -0
- package/fixtures/v1.3/valid-runtime-durable-event-notification.json +20 -0
- package/fixtures/v1.3/valid-runtime-ephemeral-event-notification.json +18 -0
- package/fixtures/v1.3/valid-runtime-events-resume-request.json +9 -0
- package/fixtures/v1.3/valid-runtime-events-resume-response.json +8 -0
- package/fixtures/v1.3/valid-thread-recovery-snapshot-request.json +10 -0
- package/fixtures/v1.3/valid-thread-recovery-snapshot-response.json +21 -0
- package/fixtures/v1.3/valid-thread-snapshot-response.json +20 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -19,10 +19,12 @@ import {
|
|
|
19
19
|
RUNTIME_METHODS,
|
|
20
20
|
RUNTIME_PROTOCOL_VERSION,
|
|
21
21
|
RUNTIME_SERVER_REQUEST_METHODS,
|
|
22
|
+
compareRuntimeEventCursors,
|
|
22
23
|
getApprovalExplanation,
|
|
23
24
|
parseRuntimeMethodParams,
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
parseRuntimeServerRequestParamsForVersion,
|
|
26
|
+
normalizeUserInputResultForForm,
|
|
27
|
+
type RuntimeEventEnvelopeV13,
|
|
26
28
|
} from "@roll-agent/protocol";
|
|
27
29
|
|
|
28
30
|
const params = parseRuntimeMethodParams(RUNTIME_METHODS.threadSnapshot, {
|
|
@@ -32,16 +34,22 @@ const params = parseRuntimeMethodParams(RUNTIME_METHODS.threadSnapshot, {
|
|
|
32
34
|
|
|
33
35
|
console.log(RUNTIME_PROTOCOL_VERSION, params);
|
|
34
36
|
|
|
35
|
-
const
|
|
37
|
+
declare const incoming: { readonly params: unknown };
|
|
38
|
+
const approval = parseRuntimeServerRequestParamsForVersion(
|
|
39
|
+
"1.2",
|
|
36
40
|
RUNTIME_SERVER_REQUEST_METHODS.approvalRequest,
|
|
37
|
-
|
|
41
|
+
incoming.params,
|
|
38
42
|
);
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
declare const checkpoint: RuntimeEventEnvelopeV13;
|
|
45
|
+
function handleEvent(event: RuntimeEventEnvelopeV13): void {
|
|
41
46
|
if (event.event.type === "approval.required") {
|
|
42
47
|
console.log(getApprovalExplanation(event.event.approval));
|
|
43
48
|
}
|
|
44
|
-
console.log(event.event.type, approval.
|
|
49
|
+
console.log(event.event.type, approval.interactionId);
|
|
50
|
+
if (event.durability === "durable" && checkpoint.durability === "durable") {
|
|
51
|
+
console.log(compareRuntimeEventCursors(checkpoint.cursor, event.cursor));
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
54
|
```
|
|
47
55
|
|
|
@@ -50,31 +58,102 @@ function handleEvent(event: RuntimeEventEnvelope): void {
|
|
|
50
58
|
- 协议常量:`SUPPORTED_RUNTIME_PROTOCOL_VERSIONS`、`RUNTIME_PROTOCOL_VERSION`、
|
|
51
59
|
`RUNTIME_METHODS`、`RUNTIME_SERVER_REQUEST_METHODS`、
|
|
52
60
|
`RUNTIME_PROTOCOL_CAPABILITIES`、`REQUIRED_RUNTIME_SERVER_REQUEST_METHODS_BY_VERSION`、
|
|
53
|
-
`RUNTIME_FEATURES`、`RUNTIME_ERROR_CODES
|
|
61
|
+
`RUNTIME_FEATURES`、`RUNTIME_ERROR_CODES`、`RUNTIME_V13_MAX_DURABLE_EVENT_RECORD_BYTES`、
|
|
62
|
+
`RUNTIME_V13_MIN_CLIENT_FRAME_BYTES`、`RUNTIME_V13_DEFAULT_REPLAY_BUFFER_BYTES`;
|
|
54
63
|
- 能力查询:`getRuntimeProtocolCapabilities()`、
|
|
55
|
-
`
|
|
64
|
+
`getRuntimeProtocolRegistry()`、`isRuntimeMethodAvailable()`、
|
|
65
|
+
`isRuntimeServerRequestMethodAvailable()`、`isRuntimeServerRequestMethodRequired()`、
|
|
66
|
+
`isLatestRuntimeServerRequestMethod()`、`getApprovalExplanation()`;
|
|
56
67
|
- 全部 Zod Schema 与派生类型;
|
|
57
68
|
- `runtimeMethodSchemas`、`parseRuntimeMethodParams()`、
|
|
58
69
|
`parseRuntimeMethodResult()`;
|
|
59
70
|
- `runtimeServerRequestSchemas`、`parseRuntimeServerRequestParams()`、
|
|
60
71
|
`parseRuntimeServerRequestResult()`;
|
|
72
|
+
- User Input 关联校验:`normalizeUserInputResult()`、
|
|
73
|
+
`normalizeUserInputResultForForm()` 与 `NormalizedUserInputResult`;后者供只持有原始表单的
|
|
74
|
+
Runtime/Host 边界校验 submitted values,并按 control 定义顺序规范化;
|
|
75
|
+
- 按协商版本解析与投影:`parseRuntimeMethodParamsForVersion()`、
|
|
76
|
+
`parseRuntimeServerRequestParamsForVersion()`、
|
|
77
|
+
`parseRuntimeServerRequestCancelParamsForVersion()`、
|
|
78
|
+
`projectRuntimeServerRequestParams()`、`projectRuntimeServerRequestCancelParams()`、
|
|
79
|
+
`compareRuntimeEventCursors()`、`runtimeEventCursorDistance()`;
|
|
80
|
+
- latest 与矩阵类型:`LatestRuntimeServerRequestInput/Params/Result<TMethod>`、
|
|
81
|
+
`RuntimeServerRequestInput/Params/ResultForVersion<TVersion,TMethod>`、
|
|
82
|
+
`RuntimeServerRequestInput/Params/ResultForSupportedVersions<TMethod>`;
|
|
61
83
|
- JSON-RPC 与 Runtime Event Envelope 类型。
|
|
62
84
|
|
|
63
85
|
## JSON Schema 与 fixtures
|
|
64
86
|
|
|
65
|
-
- `@roll-agent/protocol/schema
|
|
66
|
-
|
|
87
|
+
- `@roll-agent/protocol/schema` 与 `@roll-agent/protocol/schema/latest`:最新版本
|
|
88
|
+
JSON Schema Draft 2020-12 根 Schema;
|
|
89
|
+
- `@roll-agent/protocol/schema/1.3`、`/1.2`、`/1.1`、`/1.0`:严格按协商版本隔离的 Schema;
|
|
90
|
+
- `@roll-agent/protocol/fixtures/v1.3/*`:Protocol 1.3 durable event/replay fixtures;
|
|
91
|
+
- `@roll-agent/protocol/fixtures/v1/*`:冻结的 1.1/1.0 跨语言有效/无效消息 fixtures。
|
|
92
|
+
- `@roll-agent/protocol/fixtures/v1.2/*`:Protocol 1.2 capability/interaction fixtures。
|
|
67
93
|
|
|
68
94
|
协议版本与 npm 包版本相互独立。`RUNTIME_PROTOCOL_VERSION` 表示这个包提供的最新 wire
|
|
69
|
-
schema,并不代表调用方已实现对应 Client
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`
|
|
95
|
+
schema,并不代表调用方已实现对应 Client 能力。当前支持顺序为
|
|
96
|
+
`["1.3", "1.2", "1.1", "1.0"]`。`initialize` 请求保持旧 strict 形状;协商到 `"1.2"`
|
|
97
|
+
或 `"1.3"` 后,
|
|
98
|
+
Client 必须用 `client.capabilities.set` 提交单调 `revision` 与当前 Handler methods,Runtime
|
|
99
|
+
返回 registry 交集后才进入 interaction-ready。ACK 可以为空或为请求集的任意子集,顺序按
|
|
100
|
+
Runtime registry;Client 必须按集合语义处理。未知的未来 method 名可安全发送但不会被接受。
|
|
101
|
+
|
|
102
|
+
广告 `"1.3"` 同时声明 Client 能接收至少 `17 MiB` 的单个 Runtime→Client NDJSON 帧:
|
|
103
|
+
durable record 的绝对上限为 `16 MiB`,额外 1 MiB 留给 envelope 与 JSON-RPC 元数据。本地
|
|
104
|
+
入站预算低于 17 MiB 的 Client 必须省略 `"1.3"`。这不会扩大 Client→Runtime 出站额度;
|
|
105
|
+
初始化后的出站上限仍取本地预算与 Runtime 返回的 `limits.maxFrameBytes` 的较小值。
|
|
106
|
+
官方 Node 恢复管理器的默认 replay 暂存窗口为 10,000 条 / 32 MiB。
|
|
107
|
+
|
|
108
|
+
`"1.3"` 把 Runtime Event 分为 `durability: "durable" | "ephemeral"`。durable Event
|
|
109
|
+
携带独立的 `RuntimeEventId` 与不透明 `RuntimeEventCursor`,只有事务提交成功后才可发布;
|
|
110
|
+
ephemeral Event 继续只使用进程内 `sequence`。`thread.snapshot.eventCursor` 在没有 durable
|
|
111
|
+
Event 时为 `null`;`runtime.events.resume({ threadId, afterCursor })` 允许从 `null` 或已有
|
|
112
|
+
cursor 恢复,并以 `{ throughCursor, replayedCount }` response 作为 replay 到 live 的 barrier。
|
|
113
|
+
其中 `null` 固定表示原始日志起点;如果该起点已被 retention 裁剪,Runtime 返回
|
|
114
|
+
`EVENT_CURSOR_EXPIRED`,不会静默返回不完整的保留后缀。
|
|
115
|
+
Snapshot fallback 在 1.3 使用
|
|
116
|
+
`thread.snapshot({ threadId, limit: 1, recovery: true })`。返回值必须携带
|
|
117
|
+
`recoveryProjection: true`,保留 Thread/checkpoint/active Turn 元数据,但故意清空 messages、
|
|
118
|
+
operations、pending Approvals 与 pending Interactions;完整 timeline 需另发普通 Snapshot 分页读取,
|
|
119
|
+
未决 Interaction 则以当前连接上的 Server Request 为权威。该投影保证可装入一帧,1.2/1.1/1.0
|
|
120
|
+
会 strict 拒绝 `recovery` 参数并剥离 `recoveryProjection`。
|
|
121
|
+
调用方必须通过官方 cursor 比较/距离 helper 排序,不能解析 `rte1:` 内部格式。旧版本投影会
|
|
122
|
+
剥离 `eventCursor`、`durability`、`eventId` 与 `cursor`;cursor 过期或出现 gap 时回退 Snapshot。
|
|
123
|
+
|
|
124
|
+
`"1.2"` 的 `approval.request` 与 `userInput.request` 使用独立的 UUID brand
|
|
125
|
+
`interactionId`,并携带 `threadId`、`turnId`、绝对 `expiresAt` 与首版固定的
|
|
126
|
+
`sensitivity: "normal"`。
|
|
127
|
+
`runtime.serverRequest.cancel` 也只投影 `{ interactionId, reason }`。JSON-RPC `id`、
|
|
128
|
+
`InteractionId` 与 mutation `RequestId` 是不同生命周期的类型,不能混用。
|
|
129
|
+
|
|
130
|
+
`userInput.request` 提供 `text | multiline | number | boolean | choice` 五类 control,表单
|
|
131
|
+
最多 16 项且不支持 secret/password 类型。Client 返回 `submitted` 或正常的 `cancelled`
|
|
132
|
+
结果后,Runtime 会结合原始表单再次校验必填项、值类型、choice option、未知/重复 ID 与
|
|
133
|
+
数量边界,并按 control 定义顺序规范化提交值。
|
|
134
|
+
|
|
135
|
+
`"1.1"` 的首个 Server Request 仍是 `approval.request`。Runtime 可用
|
|
73
136
|
`runtime.serverRequest.cancel.params.serverRequestId` 引用该请求的 JSON-RPC `id`,
|
|
74
137
|
终止尚未完成的交互,并用只读
|
|
75
138
|
`approval.resolved` Event 向所有观察端同步最终状态;`"1.0"` 继续使用
|
|
76
139
|
`approval.required` + `approval.respond`。
|
|
77
140
|
|
|
141
|
+
为避免已有宿主被 minor 版本打断,无 version 的 `approvalRequestParamsSchema`、
|
|
142
|
+
`runtimeServerRequestCancelParamsSchema`、`runtimeServerRequestSchemas` 与对应 parse helper
|
|
143
|
+
固定为 `"1.1"` compatibility façade。无 version 的 Runtime method type/parser 同样冻结在
|
|
144
|
+
`"1.1"`;新实现应始终使用 negotiated-version helper/registry,或使用 supported-version
|
|
145
|
+
派生类型处理多个已协商版本。`runtimeMethodSchemas` 则表示 latest registry,不能单独用来
|
|
146
|
+
判断旧版本 method availability。
|
|
147
|
+
|
|
148
|
+
1.2 的 `thread.open` / `thread.snapshot` 必须返回 `pendingInteractions`(允许空数组)。
|
|
149
|
+
Approval 安全投影严格只有 `method`、`interactionId`、`threadId`、`turnId`、`expiresAt`、
|
|
150
|
+
`sensitivity: "normal"` 与 `approvalId`;User Input 投影只包含相同 metadata 和安全表单
|
|
151
|
+
字段。JSON-RPC `id`、原始 payload/result、提交值与 secret 不会进入 Snapshot。1.1/1.0
|
|
152
|
+
会剥离整个字段。
|
|
153
|
+
|
|
154
|
+
1.2 的 `activeTurn.status` 额外允许 `waiting-for-user`;1.1/1.0 仍冻结为
|
|
155
|
+
`running | cancelling`,version projector 会把 `waiting-for-user` 映射为 `running`。
|
|
156
|
+
|
|
78
157
|
Shell 审批的模型说明位于 `approval.preview.explanation`。它是一个可选的、最多 100
|
|
79
158
|
字符的显示辅助字段;`getApprovalExplanation()` 会完成类型和长度校验。说明不会替代
|
|
80
159
|
原始命令,也不会影响 Policy。该字段刻意保留在既有 `preview` JSON 内,因此 Runtime
|