@roll-agent/protocol 0.1.0 → 0.2.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 +25 -4
- package/dist/index.d.ts +159 -5
- package/dist/index.js +131 -4
- package/dist/schema/roll-runtime-protocol-v1.schema.json +664 -502
- package/fixtures/v1/invalid-approval-request-response.json +7 -0
- package/fixtures/v1/invalid-v1-approval-resolved-event-notification.json +20 -0
- package/fixtures/v1/valid-approval-request-response.json +8 -0
- package/fixtures/v1/valid-approval-request.json +19 -0
- package/fixtures/v1/valid-approval-resolved-event-notification.json +21 -0
- package/fixtures/v1/valid-server-request-cancel-notification.json +9 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -18,7 +18,9 @@ pnpm add @roll-agent/protocol
|
|
|
18
18
|
import {
|
|
19
19
|
RUNTIME_METHODS,
|
|
20
20
|
RUNTIME_PROTOCOL_VERSION,
|
|
21
|
+
RUNTIME_SERVER_REQUEST_METHODS,
|
|
21
22
|
parseRuntimeMethodParams,
|
|
23
|
+
parseRuntimeServerRequestResult,
|
|
22
24
|
type RuntimeEventEnvelope,
|
|
23
25
|
} from "@roll-agent/protocol";
|
|
24
26
|
|
|
@@ -29,18 +31,29 @@ const params = parseRuntimeMethodParams(RUNTIME_METHODS.threadSnapshot, {
|
|
|
29
31
|
|
|
30
32
|
console.log(RUNTIME_PROTOCOL_VERSION, params);
|
|
31
33
|
|
|
34
|
+
const approval = parseRuntimeServerRequestResult(
|
|
35
|
+
RUNTIME_SERVER_REQUEST_METHODS.approvalRequest,
|
|
36
|
+
{ decision: "approve" },
|
|
37
|
+
);
|
|
38
|
+
|
|
32
39
|
function handleEvent(event: RuntimeEventEnvelope): void {
|
|
33
|
-
console.log(event.event.type);
|
|
40
|
+
console.log(event.event.type, approval.decision);
|
|
34
41
|
}
|
|
35
42
|
```
|
|
36
43
|
|
|
37
44
|
主要导出包括:
|
|
38
45
|
|
|
39
|
-
- 协议常量:`RUNTIME_PROTOCOL_VERSION
|
|
40
|
-
`
|
|
46
|
+
- 协议常量:`SUPPORTED_RUNTIME_PROTOCOL_VERSIONS`、`RUNTIME_PROTOCOL_VERSION`、
|
|
47
|
+
`RUNTIME_METHODS`、`RUNTIME_SERVER_REQUEST_METHODS`、
|
|
48
|
+
`RUNTIME_PROTOCOL_CAPABILITIES`、`REQUIRED_RUNTIME_SERVER_REQUEST_METHODS_BY_VERSION`、
|
|
49
|
+
`RUNTIME_FEATURES`、`RUNTIME_ERROR_CODES`;
|
|
50
|
+
- 能力查询:`getRuntimeProtocolCapabilities()`、
|
|
51
|
+
`isRuntimeServerRequestMethodRequired()`;
|
|
41
52
|
- 全部 Zod Schema 与派生类型;
|
|
42
53
|
- `runtimeMethodSchemas`、`parseRuntimeMethodParams()`、
|
|
43
54
|
`parseRuntimeMethodResult()`;
|
|
55
|
+
- `runtimeServerRequestSchemas`、`parseRuntimeServerRequestParams()`、
|
|
56
|
+
`parseRuntimeServerRequestResult()`;
|
|
44
57
|
- JSON-RPC 与 Runtime Event Envelope 类型。
|
|
45
58
|
|
|
46
59
|
## JSON Schema 与 fixtures
|
|
@@ -48,7 +61,15 @@ function handleEvent(event: RuntimeEventEnvelope): void {
|
|
|
48
61
|
- `@roll-agent/protocol/schema`:JSON Schema Draft 2020-12 根 Schema;
|
|
49
62
|
- `@roll-agent/protocol/fixtures/v1/*`:跨语言有效/无效消息 fixtures。
|
|
50
63
|
|
|
51
|
-
协议版本与 npm
|
|
64
|
+
协议版本与 npm 包版本相互独立。`RUNTIME_PROTOCOL_VERSION` 表示这个包提供的最新 wire
|
|
65
|
+
schema,并不代表调用方已实现对应 Client 能力。当前最新版本是 `"1.1"`;只有覆盖该版本
|
|
66
|
+
全部必需 Server Request handler 的 Client 才应广告它,否则应协商回退到 `"1.0"`。
|
|
67
|
+
|
|
68
|
+
`"1.1"` 首个 Server Request 是 `approval.request`。Runtime 可用
|
|
69
|
+
`runtime.serverRequest.cancel.params.serverRequestId` 引用该请求的 JSON-RPC `id`,
|
|
70
|
+
终止尚未完成的交互,并用只读
|
|
71
|
+
`approval.resolved` Event 向所有观察端同步最终状态;`"1.0"` 继续使用
|
|
72
|
+
`approval.required` + `approval.respond`。
|
|
52
73
|
|
|
53
74
|
## 文档
|
|
54
75
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS: readonly ["1.1", "1.0"];
|
|
3
|
+
export type RuntimeProtocolVersion = (typeof SUPPORTED_RUNTIME_PROTOCOL_VERSIONS)[number];
|
|
4
|
+
export declare const RUNTIME_PROTOCOL_VERSION: "1.1";
|
|
3
5
|
export declare const RUNTIME_EVENT_NOTIFICATION: "runtime.event";
|
|
6
|
+
export declare const RUNTIME_SERVER_REQUEST_CANCEL_NOTIFICATION: "runtime.serverRequest.cancel";
|
|
7
|
+
export declare const RUNTIME_SERVER_REQUEST_METHODS: {
|
|
8
|
+
readonly approvalRequest: "approval.request";
|
|
9
|
+
};
|
|
10
|
+
export type RuntimeServerRequestMethod = (typeof RUNTIME_SERVER_REQUEST_METHODS)[keyof typeof RUNTIME_SERVER_REQUEST_METHODS];
|
|
11
|
+
export interface RuntimeProtocolCapabilities {
|
|
12
|
+
readonly serverRequests: boolean;
|
|
13
|
+
readonly approvalResolvedEvents: boolean;
|
|
14
|
+
readonly clientApprovalResponses: boolean;
|
|
15
|
+
readonly requiredServerRequestMethods: readonly RuntimeServerRequestMethod[];
|
|
16
|
+
}
|
|
17
|
+
export declare const RUNTIME_PROTOCOL_CAPABILITIES: {
|
|
18
|
+
readonly "1.1": {
|
|
19
|
+
readonly serverRequests: true;
|
|
20
|
+
readonly approvalResolvedEvents: true;
|
|
21
|
+
readonly clientApprovalResponses: false;
|
|
22
|
+
readonly requiredServerRequestMethods: readonly ["approval.request"];
|
|
23
|
+
};
|
|
24
|
+
readonly "1.0": {
|
|
25
|
+
readonly serverRequests: false;
|
|
26
|
+
readonly approvalResolvedEvents: false;
|
|
27
|
+
readonly clientApprovalResponses: true;
|
|
28
|
+
readonly requiredServerRequestMethods: readonly [];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export declare const REQUIRED_RUNTIME_SERVER_REQUEST_METHODS_BY_VERSION: {
|
|
32
|
+
readonly "1.1": readonly ["approval.request"];
|
|
33
|
+
readonly "1.0": readonly [];
|
|
34
|
+
};
|
|
35
|
+
export declare function getRuntimeProtocolCapabilities(version: RuntimeProtocolVersion): RuntimeProtocolCapabilities;
|
|
36
|
+
export declare function isRuntimeServerRequestMethodRequired(version: RuntimeProtocolVersion, method: RuntimeServerRequestMethod): boolean;
|
|
4
37
|
export declare const RUNTIME_METHODS: {
|
|
5
38
|
readonly initialize: "initialize";
|
|
6
39
|
readonly threadList: "thread.list";
|
|
@@ -41,6 +74,11 @@ export declare const streamIdSchema: z.core.$ZodBranded<z.ZodString, "StreamId">
|
|
|
41
74
|
export declare const operationIdSchema: z.core.$ZodBranded<z.ZodString, "OperationId">;
|
|
42
75
|
export declare const timestampSchema: z.ZodString;
|
|
43
76
|
export declare const jsonValueSchema: z.ZodJSONSchema;
|
|
77
|
+
export declare const jsonRpcIdSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
78
|
+
export declare const runtimeProtocolVersionSchema: z.ZodEnum<{
|
|
79
|
+
1.1: "1.1";
|
|
80
|
+
"1.0": "1.0";
|
|
81
|
+
}>;
|
|
44
82
|
export type ThreadId = z.infer<typeof threadIdSchema>;
|
|
45
83
|
export type TurnId = z.infer<typeof turnIdSchema>;
|
|
46
84
|
export type ApprovalId = z.infer<typeof approvalIdSchema>;
|
|
@@ -49,6 +87,7 @@ export type RequestId = z.infer<typeof requestIdSchema>;
|
|
|
49
87
|
export type StreamId = z.infer<typeof streamIdSchema>;
|
|
50
88
|
export type OperationId = z.infer<typeof operationIdSchema>;
|
|
51
89
|
export type JsonValue = z.infer<typeof jsonValueSchema>;
|
|
90
|
+
export type JsonRpcId = z.infer<typeof jsonRpcIdSchema>;
|
|
52
91
|
export declare const runtimeClientInfoSchema: z.ZodReadonly<z.ZodObject<{
|
|
53
92
|
name: z.ZodString;
|
|
54
93
|
version: z.ZodString;
|
|
@@ -72,7 +111,10 @@ export declare const initializeParamsSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
72
111
|
}, z.core.$strict>>;
|
|
73
112
|
}, z.core.$strict>>;
|
|
74
113
|
export declare const initializeResultSchema: z.ZodReadonly<z.ZodObject<{
|
|
75
|
-
protocolVersion: z.
|
|
114
|
+
protocolVersion: z.ZodEnum<{
|
|
115
|
+
1.1: "1.1";
|
|
116
|
+
"1.0": "1.0";
|
|
117
|
+
}>;
|
|
76
118
|
runtimeInstanceId: z.core.$ZodBranded<z.ZodString, "RuntimeInstanceId">;
|
|
77
119
|
server: z.ZodReadonly<z.ZodObject<{
|
|
78
120
|
runtimeVersion: z.ZodString;
|
|
@@ -516,6 +558,29 @@ export declare const approvalRespondParamsSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
516
558
|
export declare const approvalRespondResultSchema: z.ZodReadonly<z.ZodObject<{
|
|
517
559
|
resolved: z.ZodLiteral<true>;
|
|
518
560
|
}, z.core.$strict>>;
|
|
561
|
+
export declare const approvalRequestParamsSchema: z.ZodReadonly<z.ZodObject<{
|
|
562
|
+
threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
|
|
563
|
+
approval: z.ZodReadonly<z.ZodObject<{
|
|
564
|
+
id: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
|
|
565
|
+
turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
|
|
566
|
+
agentName: z.ZodString;
|
|
567
|
+
toolName: z.ZodString;
|
|
568
|
+
preview: z.ZodJSONSchema;
|
|
569
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
570
|
+
}, z.core.$strict>>;
|
|
571
|
+
expiresAt: z.ZodOptional<z.ZodString>;
|
|
572
|
+
}, z.core.$strict>>;
|
|
573
|
+
export declare const approvalRequestResultSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
|
|
574
|
+
decision: z.ZodLiteral<"approve">;
|
|
575
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
576
|
+
decision: z.ZodLiteral<"reject">;
|
|
577
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
578
|
+
}, z.core.$strict>>]>;
|
|
579
|
+
export declare const runtimeServerRequestCancelParamsSchema: z.ZodReadonly<z.ZodObject<{
|
|
580
|
+
serverRequestId: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
581
|
+
approvalId: z.ZodOptional<z.core.$ZodBranded<z.ZodString, "ApprovalId">>;
|
|
582
|
+
reason: z.ZodString;
|
|
583
|
+
}, z.core.$strict>>;
|
|
519
584
|
export declare const operationGetParamsSchema: z.ZodReadonly<z.ZodObject<{
|
|
520
585
|
operationId: z.core.$ZodBranded<z.ZodString, "OperationId">;
|
|
521
586
|
threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
|
|
@@ -542,6 +607,20 @@ export declare const operationGetResultSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
542
607
|
display: z.ZodJSONSchema;
|
|
543
608
|
}, z.core.$strict>>>;
|
|
544
609
|
}, z.core.$strict>>;
|
|
610
|
+
export declare const approvalResolutionSchema: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
611
|
+
status: z.ZodLiteral<"resolved">;
|
|
612
|
+
decision: z.ZodLiteral<"approve">;
|
|
613
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
614
|
+
status: z.ZodLiteral<"resolved">;
|
|
615
|
+
decision: z.ZodLiteral<"reject">;
|
|
616
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
617
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
618
|
+
status: z.ZodLiteral<"cancelled">;
|
|
619
|
+
reason: z.ZodString;
|
|
620
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
621
|
+
status: z.ZodLiteral<"expired">;
|
|
622
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
623
|
+
}, z.core.$strict>>]>;
|
|
545
624
|
export declare const runtimeEventSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
|
|
546
625
|
type: z.ZodLiteral<"turn.started">;
|
|
547
626
|
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
@@ -603,6 +682,23 @@ export declare const runtimeEventSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<
|
|
|
603
682
|
preview: z.ZodJSONSchema;
|
|
604
683
|
reason: z.ZodOptional<z.ZodString>;
|
|
605
684
|
}, z.core.$strict>>;
|
|
685
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
686
|
+
type: z.ZodLiteral<"approval.resolved">;
|
|
687
|
+
approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
|
|
688
|
+
resolution: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
689
|
+
status: z.ZodLiteral<"resolved">;
|
|
690
|
+
decision: z.ZodLiteral<"approve">;
|
|
691
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
692
|
+
status: z.ZodLiteral<"resolved">;
|
|
693
|
+
decision: z.ZodLiteral<"reject">;
|
|
694
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
695
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
696
|
+
status: z.ZodLiteral<"cancelled">;
|
|
697
|
+
reason: z.ZodString;
|
|
698
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
699
|
+
status: z.ZodLiteral<"expired">;
|
|
700
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
701
|
+
}, z.core.$strict>>]>;
|
|
606
702
|
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
607
703
|
type: z.ZodLiteral<"turn.completed">;
|
|
608
704
|
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
@@ -621,7 +717,10 @@ export declare const runtimeEventSchema: z.ZodDiscriminatedUnion<[z.ZodReadonly<
|
|
|
621
717
|
type: z.ZodLiteral<"capabilities.changed">;
|
|
622
718
|
}, z.core.$strict>>]>;
|
|
623
719
|
export declare const runtimeEventEnvelopeSchema: z.ZodReadonly<z.ZodObject<{
|
|
624
|
-
protocolVersion: z.
|
|
720
|
+
protocolVersion: z.ZodEnum<{
|
|
721
|
+
1.1: "1.1";
|
|
722
|
+
"1.0": "1.0";
|
|
723
|
+
}>;
|
|
625
724
|
runtimeInstanceId: z.core.$ZodBranded<z.ZodString, "RuntimeInstanceId">;
|
|
626
725
|
sequence: z.ZodNumber;
|
|
627
726
|
timestamp: z.ZodString;
|
|
@@ -688,6 +787,23 @@ export declare const runtimeEventEnvelopeSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
688
787
|
preview: z.ZodJSONSchema;
|
|
689
788
|
reason: z.ZodOptional<z.ZodString>;
|
|
690
789
|
}, z.core.$strict>>;
|
|
790
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
791
|
+
type: z.ZodLiteral<"approval.resolved">;
|
|
792
|
+
approvalId: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
|
|
793
|
+
resolution: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
794
|
+
status: z.ZodLiteral<"resolved">;
|
|
795
|
+
decision: z.ZodLiteral<"approve">;
|
|
796
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
797
|
+
status: z.ZodLiteral<"resolved">;
|
|
798
|
+
decision: z.ZodLiteral<"reject">;
|
|
799
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
800
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
801
|
+
status: z.ZodLiteral<"cancelled">;
|
|
802
|
+
reason: z.ZodString;
|
|
803
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
804
|
+
status: z.ZodLiteral<"expired">;
|
|
805
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
806
|
+
}, z.core.$strict>>]>;
|
|
691
807
|
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
692
808
|
type: z.ZodLiteral<"turn.completed">;
|
|
693
809
|
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
@@ -734,7 +850,10 @@ export declare const runtimeMethodSchemas: {
|
|
|
734
850
|
}, z.core.$strict>>;
|
|
735
851
|
}, z.core.$strict>>;
|
|
736
852
|
readonly result: z.ZodReadonly<z.ZodObject<{
|
|
737
|
-
protocolVersion: z.
|
|
853
|
+
protocolVersion: z.ZodEnum<{
|
|
854
|
+
1.1: "1.1";
|
|
855
|
+
"1.0": "1.0";
|
|
856
|
+
}>;
|
|
738
857
|
runtimeInstanceId: z.core.$ZodBranded<z.ZodString, "RuntimeInstanceId">;
|
|
739
858
|
server: z.ZodReadonly<z.ZodObject<{
|
|
740
859
|
runtimeVersion: z.ZodString;
|
|
@@ -1053,10 +1172,39 @@ export declare const runtimeMethodSchemas: {
|
|
|
1053
1172
|
}, z.core.$strict>>;
|
|
1054
1173
|
};
|
|
1055
1174
|
};
|
|
1175
|
+
export declare const runtimeServerRequestSchemas: {
|
|
1176
|
+
readonly "approval.request": {
|
|
1177
|
+
readonly params: z.ZodReadonly<z.ZodObject<{
|
|
1178
|
+
threadId: z.core.$ZodBranded<z.ZodString, "ThreadId">;
|
|
1179
|
+
approval: z.ZodReadonly<z.ZodObject<{
|
|
1180
|
+
id: z.core.$ZodBranded<z.ZodString, "ApprovalId">;
|
|
1181
|
+
turnId: z.core.$ZodBranded<z.ZodString, "TurnId">;
|
|
1182
|
+
agentName: z.ZodString;
|
|
1183
|
+
toolName: z.ZodString;
|
|
1184
|
+
preview: z.ZodJSONSchema;
|
|
1185
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
1186
|
+
}, z.core.$strict>>;
|
|
1187
|
+
expiresAt: z.ZodOptional<z.ZodString>;
|
|
1188
|
+
}, z.core.$strict>>;
|
|
1189
|
+
readonly result: z.ZodDiscriminatedUnion<[z.ZodReadonly<z.ZodObject<{
|
|
1190
|
+
decision: z.ZodLiteral<"approve">;
|
|
1191
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
1192
|
+
decision: z.ZodLiteral<"reject">;
|
|
1193
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
1194
|
+
}, z.core.$strict>>]>;
|
|
1195
|
+
};
|
|
1196
|
+
};
|
|
1056
1197
|
export type RuntimeMethod = keyof typeof runtimeMethodSchemas;
|
|
1057
1198
|
export type RuntimeMethodInput<TMethod extends RuntimeMethod> = z.input<(typeof runtimeMethodSchemas)[TMethod]["params"]>;
|
|
1058
1199
|
export type RuntimeMethodParams<TMethod extends RuntimeMethod> = z.output<(typeof runtimeMethodSchemas)[TMethod]["params"]>;
|
|
1059
1200
|
export type RuntimeMethodResult<TMethod extends RuntimeMethod> = z.output<(typeof runtimeMethodSchemas)[TMethod]["result"]>;
|
|
1201
|
+
export type RuntimeServerRequestInput<TMethod extends RuntimeServerRequestMethod> = z.input<(typeof runtimeServerRequestSchemas)[TMethod]["params"]>;
|
|
1202
|
+
export type RuntimeServerRequestParams<TMethod extends RuntimeServerRequestMethod> = z.output<(typeof runtimeServerRequestSchemas)[TMethod]["params"]>;
|
|
1203
|
+
export type RuntimeServerRequestResult<TMethod extends RuntimeServerRequestMethod> = z.output<(typeof runtimeServerRequestSchemas)[TMethod]["result"]>;
|
|
1204
|
+
export type RuntimeServerRequestHandler<TMethod extends RuntimeServerRequestMethod> = (params: RuntimeServerRequestParams<TMethod>) => RuntimeServerRequestResult<TMethod> | Promise<RuntimeServerRequestResult<TMethod>>;
|
|
1205
|
+
export type RuntimeServerRequestHandlers = {
|
|
1206
|
+
readonly [TMethod in RuntimeServerRequestMethod]?: RuntimeServerRequestHandler<TMethod>;
|
|
1207
|
+
};
|
|
1060
1208
|
export type InitializeParams = z.output<typeof initializeParamsSchema>;
|
|
1061
1209
|
export type InitializeResult = z.output<typeof initializeResultSchema>;
|
|
1062
1210
|
export type RuntimeEvent = z.infer<typeof runtimeEventSchema>;
|
|
@@ -1068,7 +1216,10 @@ export type UiMessage = z.infer<typeof uiMessageSchema>;
|
|
|
1068
1216
|
export type OperationView = z.infer<typeof operationViewSchema>;
|
|
1069
1217
|
export type PendingApproval = z.infer<typeof pendingApprovalSchema>;
|
|
1070
1218
|
export type ActiveTurn = z.infer<typeof activeTurnSchema>;
|
|
1071
|
-
export type
|
|
1219
|
+
export type ApprovalRequestParams = z.infer<typeof approvalRequestParamsSchema>;
|
|
1220
|
+
export type ApprovalRequestResult = z.infer<typeof approvalRequestResultSchema>;
|
|
1221
|
+
export type ApprovalResolution = z.infer<typeof approvalResolutionSchema>;
|
|
1222
|
+
export type RuntimeServerRequestCancelParams = z.infer<typeof runtimeServerRequestCancelParamsSchema>;
|
|
1072
1223
|
export interface JsonRpcRequest {
|
|
1073
1224
|
readonly jsonrpc: "2.0";
|
|
1074
1225
|
readonly id: JsonRpcId;
|
|
@@ -1098,3 +1249,6 @@ export type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcSucce
|
|
|
1098
1249
|
export declare function isRuntimeMethod(value: string): value is RuntimeMethod;
|
|
1099
1250
|
export declare function parseRuntimeMethodParams<TMethod extends RuntimeMethod>(method: TMethod, value: unknown): RuntimeMethodParams<TMethod>;
|
|
1100
1251
|
export declare function parseRuntimeMethodResult<TMethod extends RuntimeMethod>(method: TMethod, value: unknown): RuntimeMethodResult<TMethod>;
|
|
1252
|
+
export declare function isRuntimeServerRequestMethod(value: string): value is RuntimeServerRequestMethod;
|
|
1253
|
+
export declare function parseRuntimeServerRequestParams<TMethod extends RuntimeServerRequestMethod>(method: TMethod, value: unknown): RuntimeServerRequestParams<TMethod>;
|
|
1254
|
+
export declare function parseRuntimeServerRequestResult<TMethod extends RuntimeServerRequestMethod>(method: TMethod, value: unknown): RuntimeServerRequestResult<TMethod>;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
|
-
export const
|
|
2
|
+
export const SUPPORTED_RUNTIME_PROTOCOL_VERSIONS = ["1.1", "1.0"];
|
|
3
|
+
export const RUNTIME_PROTOCOL_VERSION = SUPPORTED_RUNTIME_PROTOCOL_VERSIONS[0];
|
|
3
4
|
export const RUNTIME_EVENT_NOTIFICATION = "runtime.event";
|
|
5
|
+
export const RUNTIME_SERVER_REQUEST_CANCEL_NOTIFICATION = "runtime.serverRequest.cancel";
|
|
6
|
+
export const RUNTIME_SERVER_REQUEST_METHODS = {
|
|
7
|
+
approvalRequest: "approval.request",
|
|
8
|
+
};
|
|
9
|
+
export const RUNTIME_PROTOCOL_CAPABILITIES = {
|
|
10
|
+
"1.1": {
|
|
11
|
+
serverRequests: true,
|
|
12
|
+
approvalResolvedEvents: true,
|
|
13
|
+
clientApprovalResponses: false,
|
|
14
|
+
requiredServerRequestMethods: [RUNTIME_SERVER_REQUEST_METHODS.approvalRequest],
|
|
15
|
+
},
|
|
16
|
+
"1.0": {
|
|
17
|
+
serverRequests: false,
|
|
18
|
+
approvalResolvedEvents: false,
|
|
19
|
+
clientApprovalResponses: true,
|
|
20
|
+
requiredServerRequestMethods: [],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export const REQUIRED_RUNTIME_SERVER_REQUEST_METHODS_BY_VERSION = {
|
|
24
|
+
"1.1": RUNTIME_PROTOCOL_CAPABILITIES["1.1"].requiredServerRequestMethods,
|
|
25
|
+
"1.0": RUNTIME_PROTOCOL_CAPABILITIES["1.0"].requiredServerRequestMethods,
|
|
26
|
+
};
|
|
27
|
+
export function getRuntimeProtocolCapabilities(version) {
|
|
28
|
+
return RUNTIME_PROTOCOL_CAPABILITIES[version];
|
|
29
|
+
}
|
|
30
|
+
export function isRuntimeServerRequestMethodRequired(version, method) {
|
|
31
|
+
return getRuntimeProtocolCapabilities(version).requiredServerRequestMethods.some((requiredMethod) => requiredMethod === method);
|
|
32
|
+
}
|
|
4
33
|
export const RUNTIME_METHODS = {
|
|
5
34
|
initialize: "initialize",
|
|
6
35
|
threadList: "thread.list",
|
|
@@ -57,6 +86,8 @@ export const streamIdSchema = z.string().uuid().brand();
|
|
|
57
86
|
export const operationIdSchema = z.string().uuid().brand();
|
|
58
87
|
export const timestampSchema = z.string().datetime({ offset: true });
|
|
59
88
|
export const jsonValueSchema = z.json();
|
|
89
|
+
export const jsonRpcIdSchema = z.union([z.string(), z.number()]);
|
|
90
|
+
export const runtimeProtocolVersionSchema = z.enum(SUPPORTED_RUNTIME_PROTOCOL_VERSIONS);
|
|
60
91
|
const runtimeClientInfoFields = {
|
|
61
92
|
name: z.string().trim().min(1).max(100),
|
|
62
93
|
version: z.string().trim().min(1).max(100),
|
|
@@ -87,7 +118,7 @@ export const initializeParamsSchema = z
|
|
|
87
118
|
.readonly();
|
|
88
119
|
export const initializeResultSchema = z
|
|
89
120
|
.object({
|
|
90
|
-
protocolVersion:
|
|
121
|
+
protocolVersion: runtimeProtocolVersionSchema,
|
|
91
122
|
runtimeInstanceId: runtimeInstanceIdSchema,
|
|
92
123
|
server: runtimeServerInfoSchema,
|
|
93
124
|
features: z.array(z.enum(RUNTIME_FEATURES)),
|
|
@@ -292,6 +323,7 @@ export const turnCancelParamsSchema = z
|
|
|
292
323
|
.strict()
|
|
293
324
|
.readonly();
|
|
294
325
|
export const turnCancelResultSchema = z.object({ cancelling: z.boolean() }).strict().readonly();
|
|
326
|
+
const approvalRejectReasonSchema = z.string().min(1);
|
|
295
327
|
export const approvalRespondParamsSchema = z
|
|
296
328
|
.object({
|
|
297
329
|
...requestFields,
|
|
@@ -299,7 +331,7 @@ export const approvalRespondParamsSchema = z
|
|
|
299
331
|
turnId: turnIdSchema,
|
|
300
332
|
approvalId: approvalIdSchema,
|
|
301
333
|
decision: z.enum(["approve", "reject"]),
|
|
302
|
-
reason:
|
|
334
|
+
reason: approvalRejectReasonSchema.optional(),
|
|
303
335
|
})
|
|
304
336
|
.strict()
|
|
305
337
|
.readonly();
|
|
@@ -307,6 +339,37 @@ export const approvalRespondResultSchema = z
|
|
|
307
339
|
.object({ resolved: z.literal(true) })
|
|
308
340
|
.strict()
|
|
309
341
|
.readonly();
|
|
342
|
+
export const approvalRequestParamsSchema = z
|
|
343
|
+
.object({
|
|
344
|
+
threadId: threadIdSchema,
|
|
345
|
+
approval: pendingApprovalSchema,
|
|
346
|
+
expiresAt: timestampSchema.optional(),
|
|
347
|
+
})
|
|
348
|
+
.strict()
|
|
349
|
+
.readonly();
|
|
350
|
+
export const approvalRequestResultSchema = z.discriminatedUnion("decision", [
|
|
351
|
+
z
|
|
352
|
+
.object({
|
|
353
|
+
decision: z.literal("approve"),
|
|
354
|
+
})
|
|
355
|
+
.strict()
|
|
356
|
+
.readonly(),
|
|
357
|
+
z
|
|
358
|
+
.object({
|
|
359
|
+
decision: z.literal("reject"),
|
|
360
|
+
reason: approvalRejectReasonSchema.optional(),
|
|
361
|
+
})
|
|
362
|
+
.strict()
|
|
363
|
+
.readonly(),
|
|
364
|
+
]);
|
|
365
|
+
export const runtimeServerRequestCancelParamsSchema = z
|
|
366
|
+
.object({
|
|
367
|
+
serverRequestId: jsonRpcIdSchema,
|
|
368
|
+
approvalId: approvalIdSchema.optional(),
|
|
369
|
+
reason: z.string().min(1),
|
|
370
|
+
})
|
|
371
|
+
.strict()
|
|
372
|
+
.readonly();
|
|
310
373
|
export const operationGetParamsSchema = z
|
|
311
374
|
.object({
|
|
312
375
|
...threadRequestFields,
|
|
@@ -320,6 +383,37 @@ export const operationGetResultSchema = z
|
|
|
320
383
|
})
|
|
321
384
|
.strict()
|
|
322
385
|
.readonly();
|
|
386
|
+
export const approvalResolutionSchema = z.union([
|
|
387
|
+
z
|
|
388
|
+
.object({
|
|
389
|
+
status: z.literal("resolved"),
|
|
390
|
+
decision: z.literal("approve"),
|
|
391
|
+
})
|
|
392
|
+
.strict()
|
|
393
|
+
.readonly(),
|
|
394
|
+
z
|
|
395
|
+
.object({
|
|
396
|
+
status: z.literal("resolved"),
|
|
397
|
+
decision: z.literal("reject"),
|
|
398
|
+
reason: approvalRejectReasonSchema.optional(),
|
|
399
|
+
})
|
|
400
|
+
.strict()
|
|
401
|
+
.readonly(),
|
|
402
|
+
z
|
|
403
|
+
.object({
|
|
404
|
+
status: z.literal("cancelled"),
|
|
405
|
+
reason: z.string().min(1),
|
|
406
|
+
})
|
|
407
|
+
.strict()
|
|
408
|
+
.readonly(),
|
|
409
|
+
z
|
|
410
|
+
.object({
|
|
411
|
+
status: z.literal("expired"),
|
|
412
|
+
reason: z.string().min(1).optional(),
|
|
413
|
+
})
|
|
414
|
+
.strict()
|
|
415
|
+
.readonly(),
|
|
416
|
+
]);
|
|
323
417
|
export const runtimeEventSchema = z.discriminatedUnion("type", [
|
|
324
418
|
z
|
|
325
419
|
.object({ type: z.literal("turn.started") })
|
|
@@ -396,6 +490,14 @@ export const runtimeEventSchema = z.discriminatedUnion("type", [
|
|
|
396
490
|
})
|
|
397
491
|
.strict()
|
|
398
492
|
.readonly(),
|
|
493
|
+
z
|
|
494
|
+
.object({
|
|
495
|
+
type: z.literal("approval.resolved"),
|
|
496
|
+
approvalId: approvalIdSchema,
|
|
497
|
+
resolution: approvalResolutionSchema,
|
|
498
|
+
})
|
|
499
|
+
.strict()
|
|
500
|
+
.readonly(),
|
|
399
501
|
z
|
|
400
502
|
.object({ type: z.literal("turn.completed") })
|
|
401
503
|
.strict()
|
|
@@ -423,7 +525,7 @@ export const runtimeEventSchema = z.discriminatedUnion("type", [
|
|
|
423
525
|
]);
|
|
424
526
|
export const runtimeEventEnvelopeSchema = z
|
|
425
527
|
.object({
|
|
426
|
-
protocolVersion:
|
|
528
|
+
protocolVersion: runtimeProtocolVersionSchema,
|
|
427
529
|
runtimeInstanceId: runtimeInstanceIdSchema,
|
|
428
530
|
sequence: z.number().int().nonnegative(),
|
|
429
531
|
timestamp: timestampSchema,
|
|
@@ -432,6 +534,16 @@ export const runtimeEventEnvelopeSchema = z
|
|
|
432
534
|
event: runtimeEventSchema,
|
|
433
535
|
})
|
|
434
536
|
.strict()
|
|
537
|
+
.superRefine((value, context) => {
|
|
538
|
+
if (!getRuntimeProtocolCapabilities(value.protocolVersion).approvalResolvedEvents &&
|
|
539
|
+
value.event.type === "approval.resolved") {
|
|
540
|
+
context.addIssue({
|
|
541
|
+
code: "custom",
|
|
542
|
+
message: "approval.resolved requires the negotiated approval-resolved event capability",
|
|
543
|
+
path: ["event", "type"],
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
})
|
|
435
547
|
.readonly();
|
|
436
548
|
export const runtimeProtocolErrorDataSchema = z
|
|
437
549
|
.object({
|
|
@@ -495,6 +607,12 @@ export const runtimeMethodSchemas = {
|
|
|
495
607
|
result: operationGetResultSchema,
|
|
496
608
|
},
|
|
497
609
|
};
|
|
610
|
+
export const runtimeServerRequestSchemas = {
|
|
611
|
+
[RUNTIME_SERVER_REQUEST_METHODS.approvalRequest]: {
|
|
612
|
+
params: approvalRequestParamsSchema,
|
|
613
|
+
result: approvalRequestResultSchema,
|
|
614
|
+
},
|
|
615
|
+
};
|
|
498
616
|
export function isRuntimeMethod(value) {
|
|
499
617
|
return Object.hasOwn(runtimeMethodSchemas, value);
|
|
500
618
|
}
|
|
@@ -504,3 +622,12 @@ export function parseRuntimeMethodParams(method, value) {
|
|
|
504
622
|
export function parseRuntimeMethodResult(method, value) {
|
|
505
623
|
return runtimeMethodSchemas[method].result.parse(value);
|
|
506
624
|
}
|
|
625
|
+
export function isRuntimeServerRequestMethod(value) {
|
|
626
|
+
return Object.hasOwn(runtimeServerRequestSchemas, value);
|
|
627
|
+
}
|
|
628
|
+
export function parseRuntimeServerRequestParams(method, value) {
|
|
629
|
+
return runtimeServerRequestSchemas[method].params.parse(value);
|
|
630
|
+
}
|
|
631
|
+
export function parseRuntimeServerRequestResult(method, value) {
|
|
632
|
+
return runtimeServerRequestSchemas[method].result.parse(value);
|
|
633
|
+
}
|