History

Introduce v2 provider runtime event schema and validation tests

- Restructure runtime events around a shared base plus typed payloads - Add runtime-branded IDs and new event types (plan, item, request, user-input) - Remove legacy canonical event names from docs and add schema decode/rejection tests

Julius Marminge committed 8 months ago

Commit 7c0ccb51 parent cfae88f5 files · +502 −179Browse files

Unified · Split

5 files
  1. EVENTS.md +0 −18
  2. apps/server/src/main.ts +1 −0
  3. packages/contracts/src/baseSchemas.ts +8 −0
  4. packages/contracts/src/providerRuntime.test.ts +120 −0
  5. packages/contracts/src/providerRuntime.ts +373 −161
EVENTS.md+0−18
@@ -83,12 +83,6 @@ type CanonicalRuntimeEventType = · 82 unmodified lines
8383 | "thread.started"
8484 | "thread.state.changed"
8585 | "thread.metadata.updated"
86− | "thread.token-usage.updated"
87− | "thread.realtime.started"
88− | "thread.realtime.item-added"
89− | "thread.realtime.audio.delta"
90− | "thread.realtime.error"
91− | "thread.realtime.closed"
9286 | "turn.started"
9387 | "turn.completed"
9488 | "turn.aborted"
@@ -111,20 +105,8 @@ type CanonicalRuntimeEventType = · 16 unmodified lines
111105 | "task.started"
112106 | "task.progress"
113107 | "task.completed"
114− | "hook.started"
115− | "hook.progress"
116− | "hook.completed"
117108 | "tool.progress"
118109 | "tool.summary"
119− | "auth.status"
120− | "account.updated"
121− | "account.rate-limits.updated"
122− | "mcp.status.updated"
123− | "mcp.oauth.completed"
124− | "model.rerouted"
125− | "config.warning"
126− | "deprecation.notice"
127− | "files.persisted"
128110 | "runtime.warning"
129111 | "runtime.error";
130112 ```
apps/server/src/main.ts+1−0
@@ -10,6 +10,7 @@ import { Config, Data, Effect, FileSystem, Layer, Option, Path, Schema, ServiceM · 9 unmodified lines
1010 import { Command, Flag } from "effect/unstable/cli";
1111 import { NetService } from "@t3tools/shared/Net";
1212
13+// Dummy comment.
1314 import {
1415 DEFAULT_PORT,
1516 resolveStaticDir,
packages/contracts/src/baseSchemas.ts+8−0
@@ -36,6 +36,14 @@ export const ProviderTurnId = makeEntityId("ProviderTurnId"); · 35 unmodified lines
3636 export type ProviderTurnId = typeof ProviderTurnId.Type;
3737 export const ProviderItemId = makeEntityId("ProviderItemId");
3838 export type ProviderItemId = typeof ProviderItemId.Type;
39+export const RuntimeSessionId = makeEntityId("RuntimeSessionId");
40+export type RuntimeSessionId = typeof RuntimeSessionId.Type;
41+export const RuntimeItemId = makeEntityId("RuntimeItemId");
42+export type RuntimeItemId = typeof RuntimeItemId.Type;
43+export const RuntimeRequestId = makeEntityId("RuntimeRequestId");
44+export type RuntimeRequestId = typeof RuntimeRequestId.Type;
45+export const RuntimeTaskId = makeEntityId("RuntimeTaskId");
46+export type RuntimeTaskId = typeof RuntimeTaskId.Type;
3947 export const ApprovalRequestId = makeEntityId("ApprovalRequestId");
4048 export type ApprovalRequestId = typeof ApprovalRequestId.Type;
4149 export const CheckpointRef = makeEntityId("CheckpointRef");
packages/contracts/src/providerRuntime.test.ts+120−0
@@ -0,0 +1,120 @@
1+import { describe, expect, it } from "vitest";
2+import { Schema } from "effect";
3+
4+import { ProviderRuntimeEvent } from "./providerRuntime";
5+
6+const decodeRuntimeEvent = Schema.decodeUnknownSync(ProviderRuntimeEvent);
7+
8+describe("ProviderRuntimeEvent", () => {
9+ it("decodes turn.plan.updated for plan rendering", () => {
10+ const parsed = decodeRuntimeEvent({
11+ type: "turn.plan.updated",
12+ eventId: "event-1",
13+ provider: "claudeCode",
14+ sessionId: "runtime-session-1",
15+ createdAt: "2026-02-28T00:00:00.000Z",
16+ threadId: "thread-1",
17+ turnId: "turn-1",
18+ payload: {
19+ explanation: "Implement schema updates",
20+ plan: [
21+ { step: "Define event union", status: "completed" },
22+ { step: "Wire adapter mapping", status: "inProgress" },
23+ ],
24+ },
25+ });
26+
27+ expect(parsed.type).toBe("turn.plan.updated");
28+ if (parsed.type !== "turn.plan.updated") {
29+ throw new Error("expected turn.plan.updated");
30+ }
31+ expect(parsed.payload.plan).toHaveLength(2);
32+ expect(parsed.payload.plan[1]?.status).toBe("inProgress");
33+ });
34+
35+ it("decodes user-input.requested with structured questions", () => {
36+ const parsed = decodeRuntimeEvent({
37+ type: "user-input.requested",
38+ eventId: "event-2",
39+ provider: "claudeCode",
40+ sessionId: "runtime-session-2",
41+ createdAt: "2026-02-28T00:00:01.000Z",
42+ requestId: "request-1",
43+ payload: {
44+ questions: [
45+ {
46+ id: "sandbox_mode",
47+ header: "Sandbox",
48+ question: "Which mode should be used?",
49+ options: [
50+ {
51+ label: "workspace-write",
52+ description: "Allow edits in workspace only",
53+ },
54+ {
55+ label: "danger-full-access",
56+ description: "Allow unrestricted access",
57+ },
58+ ],
59+ },
60+ ],
61+ },
62+ });
63+
64+ expect(parsed.type).toBe("user-input.requested");
65+ if (parsed.type !== "user-input.requested") {
66+ throw new Error("expected user-input.requested");
67+ }
68+ expect(parsed.payload.questions[0]?.id).toBe("sandbox_mode");
69+ expect(parsed.payload.questions[0]?.options).toHaveLength(2);
70+ });
71+
72+ it("decodes user-input.resolved with answer map", () => {
73+ const parsed = decodeRuntimeEvent({
74+ type: "user-input.resolved",
75+ eventId: "event-3",
76+ provider: "claudeCode",
77+ sessionId: "runtime-session-2",
78+ createdAt: "2026-02-28T00:00:02.000Z",
79+ requestId: "request-1",
80+ payload: {
81+ answers: {
82+ sandbox_mode: "workspace-write",
83+ },
84+ },
85+ });
86+
87+ expect(parsed.type).toBe("user-input.resolved");
88+ if (parsed.type !== "user-input.resolved") {
89+ throw new Error("expected user-input.resolved");
90+ }
91+ expect(parsed.payload.answers.sandbox_mode).toBe("workspace-write");
92+ });
93+
94+ it("rejects legacy message.delta type", () => {
95+ expect(() =>
96+ decodeRuntimeEvent({
97+ type: "message.delta",
98+ eventId: "event-4",
99+ provider: "codex",
100+ sessionId: "runtime-session-3",
101+ createdAt: "2026-02-28T00:00:03.000Z",
102+ payload: { delta: "legacy" },
103+ }),
104+ ).toThrow();
105+ });
106+
107+ it("rejects empty branded canonical ids", () => {
108+ expect(() =>
109+ decodeRuntimeEvent({
110+ type: "runtime.error",
111+ eventId: "event-5",
112+ provider: "codex",
113+ sessionId: "runtime-session-3",
114+ createdAt: "2026-02-28T00:00:03.000Z",
115+ threadId: " ",
116+ payload: { message: "boom" },
117+ }),
118+ ).toThrow();
119+ });
120+});
packages/contracts/src/providerRuntime.ts+373−161
@@ -1,226 +1,438 @@
11 import { Schema } from "effect";
2−import { TrimmedNonEmptyString } from "./baseSchemas";
3−
42 import {
5− ApprovalRequestId,
63 EventId,
7− NonNegativeInt,
4+ IsoDateTime,
85 ProviderItemId,
96 ProviderSessionId,
107 ProviderThreadId,
118 ProviderTurnId,
12− IsoDateTime,
9+ RuntimeItemId,
10+ RuntimeRequestId,
11+ RuntimeSessionId,
12+ ThreadId,
13+ TrimmedNonEmptyString,
14+ TurnId,
1315 } from "./baseSchemas";
14−import { ProviderApprovalDecision, ProviderKind, ProviderRequestKind } from "./orchestration";
16+import { ProviderKind } from "./orchestration";
1517
1618 const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
19+const UnknownRecordSchema = Schema.Record(Schema.String, Schema.Unknown);
1720
18−export const ProviderRuntimeToolKind = Schema.Union([ProviderRequestKind, Schema.Literal("other")]);
19−export type ProviderRuntimeToolKind = typeof ProviderRuntimeToolKind.Type;
21+export const RuntimeEventRawSource = Schema.Literals([
22+ "codex.app-server.notification",
23+ "codex.app-server.request",
24+ "codex.eventmsg",
25+ "claude.sdk.message",
26+ "claude.sdk.permission",
27+ "codex.sdk.thread-event",
28+]);
29+export type RuntimeEventRawSource = typeof RuntimeEventRawSource.Type;
30+
31+export const RuntimeEventRaw = Schema.Struct({
32+ source: RuntimeEventRawSource,
33+ method: Schema.optional(TrimmedNonEmptyStringSchema),
34+ messageType: Schema.optional(TrimmedNonEmptyStringSchema),
35+ payload: Schema.Unknown,
36+});
37+export type RuntimeEventRaw = typeof RuntimeEventRaw.Type;
38+
39+export const ProviderRequestId = TrimmedNonEmptyStringSchema;
40+export type ProviderRequestId = typeof ProviderRequestId.Type;
2041
21−export const ProviderRuntimeTurnStatus = Schema.Literals([
42+export const ProviderRefs = Schema.Struct({
43+ providerSessionId: Schema.optional(ProviderSessionId),
44+ providerThreadId: Schema.optional(ProviderThreadId),
45+ providerTurnId: Schema.optional(ProviderTurnId),
46+ providerItemId: Schema.optional(ProviderItemId),
47+ providerRequestId: Schema.optional(ProviderRequestId),
48+});
49+export type ProviderRefs = typeof ProviderRefs.Type;
50+
51+export const RuntimeTurnState = Schema.Literals([
2252 "completed",
2353 "failed",
24− "cancelled",
2554 "interrupted",
55+ "cancelled",
2656 ]);
27−export type ProviderRuntimeTurnStatus = typeof ProviderRuntimeTurnStatus.Type;
57+export type RuntimeTurnState = typeof RuntimeTurnState.Type;
2858
29−export const ProviderRuntimeSessionStartedEvent = Schema.Struct({
30− type: Schema.Literal("session.started"),
59+export const RuntimePlanStepStatus = Schema.Literals(["pending", "inProgress", "completed"]);
60+export type RuntimePlanStepStatus = typeof RuntimePlanStepStatus.Type;
61+
62+export const RuntimeItemStatus = Schema.Literals(["inProgress", "completed", "failed", "declined"]);
63+export type RuntimeItemStatus = typeof RuntimeItemStatus.Type;
64+
65+export const RuntimeContentStreamKind = Schema.Literals([
66+ "assistant_text",
67+ "reasoning_text",
68+ "reasoning_summary_text",
69+ "plan_text",
70+ "command_output",
71+ "file_change_output",
72+ "unknown",
73+]);
74+export type RuntimeContentStreamKind = typeof RuntimeContentStreamKind.Type;
75+
76+export const RuntimeSessionExitKind = Schema.Literals(["graceful", "error"]);
77+export type RuntimeSessionExitKind = typeof RuntimeSessionExitKind.Type;
78+
79+export const RuntimeErrorClass = Schema.Literals([
80+ "provider_error",
81+ "transport_error",
82+ "permission_error",
83+ "validation_error",
84+ "unknown",
85+]);
86+export type RuntimeErrorClass = typeof RuntimeErrorClass.Type;
87+
88+export const CanonicalItemType = Schema.Literals([
89+ "user_message",
90+ "assistant_message",
91+ "reasoning",
92+ "plan",
93+ "command_execution",
94+ "file_change",
95+ "mcp_tool_call",
96+ "dynamic_tool_call",
97+ "error",
98+ "unknown",
99+]);
100+export type CanonicalItemType = typeof CanonicalItemType.Type;
101+
102+export const CanonicalRequestType = Schema.Literals([
103+ "command_execution_approval",
104+ "file_change_approval",
105+ "apply_patch_approval",
106+ "exec_command_approval",
107+ "tool_user_input",
108+ "dynamic_tool_call",
109+ "unknown",
110+]);
111+export type CanonicalRequestType = typeof CanonicalRequestType.Type;
112+
113+export const ProviderRuntimeEventType = Schema.Literals([
114+ "session.started",
115+ "session.exited",
116+ "thread.started",
117+ "turn.started",
118+ "turn.completed",
119+ "turn.plan.updated",
120+ "item.started",
121+ "item.updated",
122+ "item.completed",
123+ "content.delta",
124+ "request.opened",
125+ "request.resolved",
126+ "user-input.requested",
127+ "user-input.resolved",
128+ "runtime.warning",
129+ "runtime.error",
130+]);
131+export type ProviderRuntimeEventType = typeof ProviderRuntimeEventType.Type;
132+
133+export const SessionStartedType = Schema.Literal("session.started");
134+export const SessionExitedType = Schema.Literal("session.exited");
135+export const ThreadStartedType = Schema.Literal("thread.started");
136+export const TurnStartedType = Schema.Literal("turn.started");
137+export const TurnCompletedType = Schema.Literal("turn.completed");
138+export const TurnPlanUpdatedType = Schema.Literal("turn.plan.updated");
139+export const ItemStartedType = Schema.Literal("item.started");
140+export const ItemUpdatedType = Schema.Literal("item.updated");
141+export const ItemCompletedType = Schema.Literal("item.completed");
142+export const ContentDeltaType = Schema.Literal("content.delta");
143+export const RequestOpenedType = Schema.Literal("request.opened");
144+export const RequestResolvedType = Schema.Literal("request.resolved");
145+export const UserInputRequestedType = Schema.Literal("user-input.requested");
146+export const UserInputResolvedType = Schema.Literal("user-input.resolved");
147+export const RuntimeWarningType = Schema.Literal("runtime.warning");
148+export const RuntimeErrorType = Schema.Literal("runtime.error");
149+
150+export const ProviderRuntimeEventBase = Schema.Struct({
31151 eventId: EventId,
32152 provider: ProviderKind,
33− sessionId: ProviderSessionId,
34− sessionSequence: Schema.optional(NonNegativeInt),
153+ sessionId: RuntimeSessionId,
35154 createdAt: IsoDateTime,
36− threadId: Schema.optional(ProviderThreadId),
155+ threadId: Schema.optional(ThreadId),
156+ turnId: Schema.optional(TurnId),
157+ itemId: Schema.optional(RuntimeItemId),
158+ requestId: Schema.optional(RuntimeRequestId),
159+ providerRefs: Schema.optional(ProviderRefs),
160+ raw: Schema.optional(RuntimeEventRaw),
161+});
162+export type ProviderRuntimeEventBase = typeof ProviderRuntimeEventBase.Type;
163+
164+export const SessionStartedPayload = Schema.Struct({
37165 message: Schema.optional(TrimmedNonEmptyStringSchema),
166+ resume: Schema.optional(Schema.Unknown),
167+});
168+export type SessionStartedPayload = typeof SessionStartedPayload.Type;
169+
170+export const SessionExitedPayload = Schema.Struct({
171+ reason: Schema.optional(TrimmedNonEmptyStringSchema),
172+ recoverable: Schema.optional(Schema.Boolean),
173+ exitKind: Schema.optional(RuntimeSessionExitKind),
174+});
175+export type SessionExitedPayload = typeof SessionExitedPayload.Type;
176+
177+export const ThreadStartedPayload = Schema.Struct({
178+ providerThreadId: Schema.optional(ProviderThreadId),
179+});
180+export type ThreadStartedPayload = typeof ThreadStartedPayload.Type;
181+
182+export const TurnStartedPayload = Schema.Struct({
183+ model: Schema.optional(TrimmedNonEmptyStringSchema),
184+ effort: Schema.optional(TrimmedNonEmptyStringSchema),
185+});
186+export type TurnStartedPayload = typeof TurnStartedPayload.Type;
187+
188+export const TurnCompletedPayload = Schema.Struct({
189+ state: RuntimeTurnState,
190+ stopReason: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
191+ usage: Schema.optional(Schema.Unknown),
192+ modelUsage: Schema.optional(UnknownRecordSchema),
193+ totalCostUsd: Schema.optional(Schema.Number),
194+ errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
195+});
196+export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
197+
198+export const RuntimePlanStep = Schema.Struct({
199+ step: TrimmedNonEmptyStringSchema,
200+ status: RuntimePlanStepStatus,
201+});
202+export type RuntimePlanStep = typeof RuntimePlanStep.Type;
203+
204+export const TurnPlanUpdatedPayload = Schema.Struct({
205+ explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
206+ plan: Schema.Array(RuntimePlanStep),
207+});
208+export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type;
209+
210+export const ItemLifecyclePayload = Schema.Struct({
211+ itemType: CanonicalItemType,
212+ status: Schema.optional(RuntimeItemStatus),
213+ title: Schema.optional(TrimmedNonEmptyStringSchema),
214+ detail: Schema.optional(TrimmedNonEmptyStringSchema),
215+ data: Schema.optional(Schema.Unknown),
216+});
217+export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
218+
219+export const ContentDeltaPayload = Schema.Struct({
220+ streamKind: RuntimeContentStreamKind,
221+ delta: Schema.String,
222+ contentIndex: Schema.optional(Schema.Int),
223+ summaryIndex: Schema.optional(Schema.Int),
224+});
225+export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
226+
227+export const RequestOpenedPayload = Schema.Struct({
228+ requestType: CanonicalRequestType,
229+ detail: Schema.optional(TrimmedNonEmptyStringSchema),
230+ args: Schema.optional(Schema.Unknown),
231+});
232+export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
233+
234+export const RequestResolvedPayload = Schema.Struct({
235+ requestType: CanonicalRequestType,
236+ decision: Schema.optional(TrimmedNonEmptyStringSchema),
237+ resolution: Schema.optional(Schema.Unknown),
238+});
239+export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
240+
241+export const UserInputQuestionOption = Schema.Struct({
242+ label: TrimmedNonEmptyStringSchema,
243+ description: TrimmedNonEmptyStringSchema,
244+});
245+export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
246+
247+export const UserInputQuestion = Schema.Struct({
248+ id: TrimmedNonEmptyStringSchema,
249+ header: TrimmedNonEmptyStringSchema,
250+ question: TrimmedNonEmptyStringSchema,
251+ options: Schema.Array(UserInputQuestionOption),
252+});
253+export type UserInputQuestion = typeof UserInputQuestion.Type;
254+
255+export const UserInputRequestedPayload = Schema.Struct({
256+ questions: Schema.Array(UserInputQuestion),
257+});
258+export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
259+
260+export const UserInputResolvedPayload = Schema.Struct({
261+ answers: UnknownRecordSchema,
262+});
263+export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
264+
265+export const RuntimeWarningPayload = Schema.Struct({
266+ message: TrimmedNonEmptyStringSchema,
267+ detail: Schema.optional(Schema.Unknown),
268+});
269+export type RuntimeWarningPayload = typeof RuntimeWarningPayload.Type;
270+
271+export const RuntimeErrorPayload = Schema.Struct({
272+ message: TrimmedNonEmptyStringSchema,
273+ class: Schema.optional(RuntimeErrorClass),
274+ detail: Schema.optional(Schema.Unknown),
275+});
276+export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
277+
278+export const ProviderRuntimeSessionStartedEvent = Schema.Struct({
279+ ...ProviderRuntimeEventBase.fields,
280+ type: SessionStartedType,
281+ payload: SessionStartedPayload,
38282 });
39283 export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
40284
41285 export const ProviderRuntimeSessionExitedEvent = Schema.Struct({
42− type: Schema.Literal("session.exited"),
43− eventId: EventId,
44− provider: ProviderKind,
45− sessionId: ProviderSessionId,
46− sessionSequence: Schema.optional(NonNegativeInt),
47− createdAt: IsoDateTime,
48− threadId: Schema.optional(ProviderThreadId),
49− message: Schema.optional(TrimmedNonEmptyStringSchema),
286+ ...ProviderRuntimeEventBase.fields,
287+ type: SessionExitedType,
288+ payload: SessionExitedPayload,
50289 });
51290 export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
52291
53292 export const ProviderRuntimeThreadStartedEvent = Schema.Struct({
54− type: Schema.Literal("thread.started"),
55− eventId: EventId,
56− provider: ProviderKind,
57− sessionId: ProviderSessionId,
58− sessionSequence: Schema.optional(NonNegativeInt),
59− createdAt: IsoDateTime,
60− threadId: ProviderThreadId,
293+ ...ProviderRuntimeEventBase.fields,
294+ type: ThreadStartedType,
295+ payload: ThreadStartedPayload,
61296 });
62297 export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
63298
64299 export const ProviderRuntimeTurnStartedEvent = Schema.Struct({
65− type: Schema.Literal("turn.started"),
66− eventId: EventId,
67− provider: ProviderKind,
68− sessionId: ProviderSessionId,
69− sessionSequence: Schema.optional(NonNegativeInt),
70− createdAt: IsoDateTime,
71− threadId: Schema.optional(ProviderThreadId),
72− turnId: ProviderTurnId,
300+ ...ProviderRuntimeEventBase.fields,
301+ type: TurnStartedType,
302+ payload: TurnStartedPayload,
73303 });
74304 export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
75305
76306 export const ProviderRuntimeTurnCompletedEvent = Schema.Struct({
77− type: Schema.Literal("turn.completed"),
78− eventId: EventId,
79− provider: ProviderKind,
80− sessionId: ProviderSessionId,
81− sessionSequence: Schema.optional(NonNegativeInt),
82− createdAt: IsoDateTime,
83− threadId: Schema.optional(ProviderThreadId),
84− turnId: Schema.optional(ProviderTurnId),
85− status: Schema.optional(ProviderRuntimeTurnStatus),
86− errorMessage: Schema.optional(TrimmedNonEmptyStringSchema),
307+ ...ProviderRuntimeEventBase.fields,
308+ type: TurnCompletedType,
309+ payload: TurnCompletedPayload,
87310 });
88311 export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
89312
90−export const ProviderRuntimeMessageDeltaEvent = Schema.Struct({
91− type: Schema.Literal("message.delta"),
92− eventId: EventId,
93− provider: ProviderKind,
94− sessionId: ProviderSessionId,
95− sessionSequence: Schema.optional(NonNegativeInt),
96− createdAt: IsoDateTime,
97− threadId: Schema.optional(ProviderThreadId),
98− turnId: Schema.optional(ProviderTurnId),
99− itemId: Schema.optional(ProviderItemId),
100− delta: Schema.String,
313+export const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
314+ ...ProviderRuntimeEventBase.fields,
315+ type: TurnPlanUpdatedType,
316+ payload: TurnPlanUpdatedPayload,
101317 });
102−export type ProviderRuntimeMessageDeltaEvent = typeof ProviderRuntimeMessageDeltaEvent.Type;
318+export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
103319
104−export const ProviderRuntimeMessageCompletedEvent = Schema.Struct({
105− type: Schema.Literal("message.completed"),
106− eventId: EventId,
107− provider: ProviderKind,
108− sessionId: ProviderSessionId,
109− sessionSequence: Schema.optional(NonNegativeInt),
110− createdAt: IsoDateTime,
111− itemId: ProviderItemId,
112− threadId: Schema.optional(ProviderThreadId),
113− turnId: Schema.optional(ProviderTurnId),
320+export const ProviderRuntimeItemStartedEvent = Schema.Struct({
321+ ...ProviderRuntimeEventBase.fields,
322+ type: ItemStartedType,
323+ payload: ItemLifecyclePayload,
114324 });
115−export type ProviderRuntimeMessageCompletedEvent = typeof ProviderRuntimeMessageCompletedEvent.Type;
325+export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
116326
117−export const ProviderRuntimeToolStartedEvent = Schema.Struct({
118− type: Schema.Literal("tool.started"),
119− eventId: EventId,
120− provider: ProviderKind,
121− sessionId: ProviderSessionId,
122− sessionSequence: Schema.optional(NonNegativeInt),
123− createdAt: IsoDateTime,
124− threadId: Schema.optional(ProviderThreadId),
125− turnId: Schema.optional(ProviderTurnId),
126− itemId: Schema.optional(ProviderItemId),
127− toolKind: ProviderRuntimeToolKind,
128− title: TrimmedNonEmptyStringSchema,
129− detail: Schema.optional(TrimmedNonEmptyStringSchema),
327+export const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
328+ ...ProviderRuntimeEventBase.fields,
329+ type: ItemUpdatedType,
330+ payload: ItemLifecyclePayload,
130331 });
131−export type ProviderRuntimeToolStartedEvent = typeof ProviderRuntimeToolStartedEvent.Type;
332+export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
132333
133−export const ProviderRuntimeToolCompletedEvent = Schema.Struct({
134− type: Schema.Literal("tool.completed"),
135− eventId: EventId,
136− provider: ProviderKind,
137− sessionId: ProviderSessionId,
138− sessionSequence: Schema.optional(NonNegativeInt),
139− createdAt: IsoDateTime,
140− threadId: Schema.optional(ProviderThreadId),
141− turnId: Schema.optional(ProviderTurnId),
142− itemId: Schema.optional(ProviderItemId),
143− toolKind: ProviderRuntimeToolKind,
144− title: TrimmedNonEmptyStringSchema,
145− detail: Schema.optional(TrimmedNonEmptyStringSchema),
334+export const ProviderRuntimeItemCompletedEvent = Schema.Struct({
335+ ...ProviderRuntimeEventBase.fields,
336+ type: ItemCompletedType,
337+ payload: ItemLifecyclePayload,
146338 });
147−export type ProviderRuntimeToolCompletedEvent = typeof ProviderRuntimeToolCompletedEvent.Type;
339+export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
148340
149−export const ProviderRuntimeApprovalRequestedEvent = Schema.Struct({
150− type: Schema.Literal("approval.requested"),
151− eventId: EventId,
152− provider: ProviderKind,
153− sessionId: ProviderSessionId,
154− sessionSequence: Schema.optional(NonNegativeInt),
155− createdAt: IsoDateTime,
156− threadId: Schema.optional(ProviderThreadId),
157− turnId: Schema.optional(ProviderTurnId),
158− itemId: Schema.optional(ProviderItemId),
159− requestId: ApprovalRequestId,
160− requestKind: ProviderRequestKind,
161− detail: Schema.optional(TrimmedNonEmptyStringSchema),
341+export const ProviderRuntimeContentDeltaEvent = Schema.Struct({
342+ ...ProviderRuntimeEventBase.fields,
343+ type: ContentDeltaType,
344+ payload: ContentDeltaPayload,
162345 });
163−export type ProviderRuntimeApprovalRequestedEvent =
164− typeof ProviderRuntimeApprovalRequestedEvent.Type;
346+export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
165347
166−export const ProviderRuntimeApprovalResolvedEvent = Schema.Struct({
167− type: Schema.Literal("approval.resolved"),
168− eventId: EventId,
169− provider: ProviderKind,
170− sessionId: ProviderSessionId,
171− sessionSequence: Schema.optional(NonNegativeInt),
172− createdAt: IsoDateTime,
173− threadId: Schema.optional(ProviderThreadId),
174− turnId: Schema.optional(ProviderTurnId),
175− itemId: Schema.optional(ProviderItemId),
176− requestId: ApprovalRequestId,
177− requestKind: Schema.optional(ProviderRequestKind),
178− decision: Schema.optional(ProviderApprovalDecision),
348+export const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
349+ ...ProviderRuntimeEventBase.fields,
350+ type: RequestOpenedType,
351+ payload: RequestOpenedPayload,
179352 });
180−export type ProviderRuntimeApprovalResolvedEvent = typeof ProviderRuntimeApprovalResolvedEvent.Type;
353+export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
181354
182−export const ProviderRuntimeCheckpointCapturedEvent = Schema.Struct({
183− type: Schema.Literal("checkpoint.captured"),
184− eventId: EventId,
185− provider: ProviderKind,
186− sessionId: ProviderSessionId,
187− sessionSequence: Schema.optional(NonNegativeInt),
188− createdAt: IsoDateTime,
189− threadId: ProviderThreadId,
190− turnId: Schema.optional(ProviderTurnId),
191− turnCount: NonNegativeInt,
192− status: Schema.optional(ProviderRuntimeTurnStatus),
355+export const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
356+ ...ProviderRuntimeEventBase.fields,
357+ type: RequestResolvedType,
358+ payload: RequestResolvedPayload,
193359 });
194−export type ProviderRuntimeCheckpointCapturedEvent =
195− typeof ProviderRuntimeCheckpointCapturedEvent.Type;
360+export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
361+
362+export const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
363+ ...ProviderRuntimeEventBase.fields,
364+ type: UserInputRequestedType,
365+ payload: UserInputRequestedPayload,
366+});
367+export type ProviderRuntimeUserInputRequestedEvent =
368+ typeof ProviderRuntimeUserInputRequestedEvent.Type;
369+
370+export const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
371+ ...ProviderRuntimeEventBase.fields,
372+ type: UserInputResolvedType,
373+ payload: UserInputResolvedPayload,
374+});
375+export type ProviderRuntimeUserInputResolvedEvent =
376+ typeof ProviderRuntimeUserInputResolvedEvent.Type;
377+
378+export const ProviderRuntimeWarningEvent = Schema.Struct({
379+ ...ProviderRuntimeEventBase.fields,
380+ type: RuntimeWarningType,
381+ payload: RuntimeWarningPayload,
382+});
383+export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
196384
197385 export const ProviderRuntimeErrorEvent = Schema.Struct({
198− type: Schema.Literal("runtime.error"),
199− eventId: EventId,
200− provider: ProviderKind,
201− sessionId: ProviderSessionId,
202− sessionSequence: Schema.optional(NonNegativeInt),
203− createdAt: IsoDateTime,
204− threadId: Schema.optional(ProviderThreadId),
205− turnId: Schema.optional(ProviderTurnId),
206− itemId: Schema.optional(ProviderItemId),
207− message: TrimmedNonEmptyStringSchema,
386+ ...ProviderRuntimeEventBase.fields,
387+ type: RuntimeErrorType,
388+ payload: RuntimeErrorPayload,
208389 });
209390 export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
210391
211−export const ProviderRuntimeEvent = Schema.Union([
392+export const ProviderRuntimeEventV2 = Schema.Union([
212393 ProviderRuntimeSessionStartedEvent,
213394 ProviderRuntimeSessionExitedEvent,
214395 ProviderRuntimeThreadStartedEvent,
215396 ProviderRuntimeTurnStartedEvent,
216397 ProviderRuntimeTurnCompletedEvent,
217− ProviderRuntimeMessageDeltaEvent,
218− ProviderRuntimeMessageCompletedEvent,
219− ProviderRuntimeToolStartedEvent,
220− ProviderRuntimeToolCompletedEvent,
221− ProviderRuntimeApprovalRequestedEvent,
222− ProviderRuntimeApprovalResolvedEvent,
223− ProviderRuntimeCheckpointCapturedEvent,
398+ ProviderRuntimeTurnPlanUpdatedEvent,
399+ ProviderRuntimeItemStartedEvent,
400+ ProviderRuntimeItemUpdatedEvent,
401+ ProviderRuntimeItemCompletedEvent,
402+ ProviderRuntimeContentDeltaEvent,
403+ ProviderRuntimeRequestOpenedEvent,
404+ ProviderRuntimeRequestResolvedEvent,
405+ ProviderRuntimeUserInputRequestedEvent,
406+ ProviderRuntimeUserInputResolvedEvent,
407+ ProviderRuntimeWarningEvent,
224408 ProviderRuntimeErrorEvent,
225409 ]);
226−export type ProviderRuntimeEvent = typeof ProviderRuntimeEvent.Type;
410+export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
411+
412+export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
413+export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
414+
415+export const ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
416+export type ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
417+export const ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
418+export type ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
419+export const ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
420+export type ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
421+export const ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
422+export type ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
423+export const ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
424+export type ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
425+export const ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
426+export type ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
427+
428+export const ProviderRuntimeToolKind = Schema.Literals([
429+ "command_execution",
430+ "file_change",
431+ "mcp_tool_call",
432+ "dynamic_tool_call",
433+ "other",
434+]);
435+export type ProviderRuntimeToolKind = typeof ProviderRuntimeToolKind.Type;
436+
437+export const ProviderRuntimeTurnStatus = RuntimeTurnState;
438+export type ProviderRuntimeTurnStatus = RuntimeTurnState;