@roll-agent/protocol 0.2.0 → 0.3.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 CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  RUNTIME_METHODS,
20
20
  RUNTIME_PROTOCOL_VERSION,
21
21
  RUNTIME_SERVER_REQUEST_METHODS,
22
+ getApprovalExplanation,
22
23
  parseRuntimeMethodParams,
23
24
  parseRuntimeServerRequestResult,
24
25
  type RuntimeEventEnvelope,
@@ -37,6 +38,9 @@ const approval = parseRuntimeServerRequestResult(
37
38
  );
38
39
 
39
40
  function handleEvent(event: RuntimeEventEnvelope): void {
41
+ if (event.event.type === "approval.required") {
42
+ console.log(getApprovalExplanation(event.event.approval));
43
+ }
40
44
  console.log(event.event.type, approval.decision);
41
45
  }
42
46
  ```
@@ -48,7 +52,7 @@ function handleEvent(event: RuntimeEventEnvelope): void {
48
52
  `RUNTIME_PROTOCOL_CAPABILITIES`、`REQUIRED_RUNTIME_SERVER_REQUEST_METHODS_BY_VERSION`、
49
53
  `RUNTIME_FEATURES`、`RUNTIME_ERROR_CODES`;
50
54
  - 能力查询:`getRuntimeProtocolCapabilities()`、
51
- `isRuntimeServerRequestMethodRequired()`;
55
+ `isRuntimeServerRequestMethodRequired()`、`getApprovalExplanation()`;
52
56
  - 全部 Zod Schema 与派生类型;
53
57
  - `runtimeMethodSchemas`、`parseRuntimeMethodParams()`、
54
58
  `parseRuntimeMethodResult()`;
@@ -71,6 +75,14 @@ schema,并不代表调用方已实现对应 Client 能力。当前最新版本
71
75
  `approval.resolved` Event 向所有观察端同步最终状态;`"1.0"` 继续使用
72
76
  `approval.required` + `approval.respond`。
73
77
 
78
+ Shell 审批的模型说明位于 `approval.preview.explanation`。它是一个可选的、最多 100
79
+ 字符的显示辅助字段;`getApprovalExplanation()` 会完成类型和长度校验。说明不会替代
80
+ 原始命令,也不会影响 Policy。该字段刻意保留在既有 `preview` JSON 内,因此 Runtime
81
+ Protocol `"1.0"` / `"1.1"` 的 strict 顶层结构不变,旧 GUI 可以继续解析,新 GUI
82
+ 则可将它单独显示为“AI 说明”。内置 Shell 命令仅在分类器明确判定为 `dangerous`
83
+ 时才向用户展示风险 `reason`;仅因无法证明安全而复用 `destructiveHint` 的 `unknown`
84
+ 命令不会显示“破坏性操作”。GUI 在 `reason` 缺失时应使用中性提示或直接省略。
85
+
74
86
  ## 文档
75
87
 
76
88
  - [Runtime Protocol v1 参考](https://github.com/steveoon/roll-agent/blob/main/docs/runtime-protocol-v1-reference.md)
package/dist/index.d.ts CHANGED
@@ -4,6 +4,8 @@ export type RuntimeProtocolVersion = (typeof SUPPORTED_RUNTIME_PROTOCOL_VERSIONS
4
4
  export declare const RUNTIME_PROTOCOL_VERSION: "1.1";
5
5
  export declare const RUNTIME_EVENT_NOTIFICATION: "runtime.event";
6
6
  export declare const RUNTIME_SERVER_REQUEST_CANCEL_NOTIFICATION: "runtime.serverRequest.cancel";
7
+ export declare const APPROVAL_EXPLANATION_PREVIEW_KEY: "explanation";
8
+ export declare const APPROVAL_EXPLANATION_MAX_CHARS = 100;
7
9
  export declare const RUNTIME_SERVER_REQUEST_METHODS: {
8
10
  readonly approvalRequest: "approval.request";
9
11
  };
@@ -79,6 +81,7 @@ export declare const runtimeProtocolVersionSchema: z.ZodEnum<{
79
81
  1.1: "1.1";
80
82
  "1.0": "1.0";
81
83
  }>;
84
+ export declare const approvalExplanationSchema: z.ZodString;
82
85
  export type ThreadId = z.infer<typeof threadIdSchema>;
83
86
  export type TurnId = z.infer<typeof turnIdSchema>;
84
87
  export type ApprovalId = z.infer<typeof approvalIdSchema>;
@@ -1215,11 +1218,13 @@ export type ThreadSnapshot = z.infer<typeof threadSnapshotSchema>;
1215
1218
  export type UiMessage = z.infer<typeof uiMessageSchema>;
1216
1219
  export type OperationView = z.infer<typeof operationViewSchema>;
1217
1220
  export type PendingApproval = z.infer<typeof pendingApprovalSchema>;
1221
+ export type ApprovalExplanation = z.infer<typeof approvalExplanationSchema>;
1218
1222
  export type ActiveTurn = z.infer<typeof activeTurnSchema>;
1219
1223
  export type ApprovalRequestParams = z.infer<typeof approvalRequestParamsSchema>;
1220
1224
  export type ApprovalRequestResult = z.infer<typeof approvalRequestResultSchema>;
1221
1225
  export type ApprovalResolution = z.infer<typeof approvalResolutionSchema>;
1222
1226
  export type RuntimeServerRequestCancelParams = z.infer<typeof runtimeServerRequestCancelParamsSchema>;
1227
+ export declare function getApprovalExplanation(approval: Pick<PendingApproval, "preview">): ApprovalExplanation | undefined;
1223
1228
  export interface JsonRpcRequest {
1224
1229
  readonly jsonrpc: "2.0";
1225
1230
  readonly id: JsonRpcId;
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS = ["1.1", "1.0"];
3
3
  export const RUNTIME_PROTOCOL_VERSION = SUPPORTED_RUNTIME_PROTOCOL_VERSIONS[0];
4
4
  export const RUNTIME_EVENT_NOTIFICATION = "runtime.event";
5
5
  export const RUNTIME_SERVER_REQUEST_CANCEL_NOTIFICATION = "runtime.serverRequest.cancel";
6
+ export const APPROVAL_EXPLANATION_PREVIEW_KEY = "explanation";
7
+ export const APPROVAL_EXPLANATION_MAX_CHARS = 100;
6
8
  export const RUNTIME_SERVER_REQUEST_METHODS = {
7
9
  approvalRequest: "approval.request",
8
10
  };
@@ -88,6 +90,11 @@ export const timestampSchema = z.string().datetime({ offset: true });
88
90
  export const jsonValueSchema = z.json();
89
91
  export const jsonRpcIdSchema = z.union([z.string(), z.number()]);
90
92
  export const runtimeProtocolVersionSchema = z.enum(SUPPORTED_RUNTIME_PROTOCOL_VERSIONS);
93
+ export const approvalExplanationSchema = z
94
+ .string()
95
+ .trim()
96
+ .min(1)
97
+ .max(APPROVAL_EXPLANATION_MAX_CHARS);
91
98
  const runtimeClientInfoFields = {
92
99
  name: z.string().trim().min(1).max(100),
93
100
  version: z.string().trim().min(1).max(100),
@@ -613,6 +620,14 @@ export const runtimeServerRequestSchemas = {
613
620
  result: approvalRequestResultSchema,
614
621
  },
615
622
  };
623
+ export function getApprovalExplanation(approval) {
624
+ const preview = approval.preview;
625
+ if (typeof preview !== "object" || preview === null || Array.isArray(preview)) {
626
+ return undefined;
627
+ }
628
+ const parsed = approvalExplanationSchema.safeParse(preview[APPROVAL_EXPLANATION_PREVIEW_KEY]);
629
+ return parsed.success ? parsed.data : undefined;
630
+ }
616
631
  export function isRuntimeMethod(value) {
617
632
  return Object.hasOwn(runtimeMethodSchemas, value);
618
633
  }
@@ -10,7 +10,8 @@
10
10
  "agentName": "browser-use-agent",
11
11
  "toolName": "click",
12
12
  "preview": {
13
- "selector": "#submit"
13
+ "selector": "#submit",
14
+ "explanation": "提交当前表单,以完成用户要求的操作。"
14
15
  },
15
16
  "reason": "此操作会提交表单"
16
17
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roll-agent/protocol",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",