authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-02-28 18:34:52-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-05 23:00:41-08:00
logf2253269ddf80446425b06629ed5dd8809a2bc1e
tree1a517bc37ed235e5a0cfee6963715cfe2d769fa9
parentd08cecf1262991407ccb8db8168197ce8f493ff2

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

5 files changed, 502 insertions(+), 179 deletions(-)

EVENTS.md-18
......@@ -83,12 +83,6 @@ type CanonicalRuntimeEventType =
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 =
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
......@@ -10,6 +10,7 @@ import { Config, Data, Effect, FileSystem, Layer, Option, Path, Schema, ServiceM
1010import { Command, Flag } from "effect/unstable/cli";
1111import { NetService } from "@t3tools/shared/Net";
1212
13// Dummy comment.
1314import {
1415 DEFAULT_PORT,
1516 resolveStaticDir,
packages/contracts/src/baseSchemas.ts+8
......@@ -36,6 +36,14 @@ export const ProviderTurnId = makeEntityId("ProviderTurnId");
3636export type ProviderTurnId = typeof ProviderTurnId.Type;
3737export const ProviderItemId = makeEntityId("ProviderItemId");
3838export type ProviderItemId = typeof ProviderItemId.Type;
39export const RuntimeSessionId = makeEntityId("RuntimeSessionId");
40export type RuntimeSessionId = typeof RuntimeSessionId.Type;
41export const RuntimeItemId = makeEntityId("RuntimeItemId");
42export type RuntimeItemId = typeof RuntimeItemId.Type;
43export const RuntimeRequestId = makeEntityId("RuntimeRequestId");
44export type RuntimeRequestId = typeof RuntimeRequestId.Type;
45export const RuntimeTaskId = makeEntityId("RuntimeTaskId");
46export type RuntimeTaskId = typeof RuntimeTaskId.Type;
3947export const ApprovalRequestId = makeEntityId("ApprovalRequestId");
4048export type ApprovalRequestId = typeof ApprovalRequestId.Type;
4149export const CheckpointRef = makeEntityId("CheckpointRef");
packages/contracts/src/providerRuntime.test.ts created+120
......@@ -0,0 +1,120 @@
1import { describe, expect, it } from "vitest";
2import { Schema } from "effect";
3
4import { ProviderRuntimeEvent } from "./providerRuntime";
5
6const decodeRuntimeEvent = Schema.decodeUnknownSync(ProviderRuntimeEvent);
7
8describe("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 @@
11import { Schema } from "effect";
2import { TrimmedNonEmptyString } from "./baseSchemas";
3
42import {
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";
14import { ProviderApprovalDecision, ProviderKind, ProviderRequestKind } from "./orchestration";
16import { ProviderKind } from "./orchestration";
1517
1618const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
19const UnknownRecordSchema = Schema.Record(Schema.String, Schema.Unknown);
1720
18export const ProviderRuntimeToolKind = Schema.Union([ProviderRequestKind, Schema.Literal("other")]);
19export type ProviderRuntimeToolKind = typeof ProviderRuntimeToolKind.Type;
21export 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]);
29export type RuntimeEventRawSource = typeof RuntimeEventRawSource.Type;
30
31export const RuntimeEventRaw = Schema.Struct({
32 source: RuntimeEventRawSource,
33 method: Schema.optional(TrimmedNonEmptyStringSchema),
34 messageType: Schema.optional(TrimmedNonEmptyStringSchema),
35 payload: Schema.Unknown,
36});
37export type RuntimeEventRaw = typeof RuntimeEventRaw.Type;
38
39export const ProviderRequestId = TrimmedNonEmptyStringSchema;
40export type ProviderRequestId = typeof ProviderRequestId.Type;
2041
21export const ProviderRuntimeTurnStatus = Schema.Literals([
42export 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});
49export type ProviderRefs = typeof ProviderRefs.Type;
50
51export const RuntimeTurnState = Schema.Literals([
2252 "completed",
2353 "failed",
24 "cancelled",
2554 "interrupted",
55 "cancelled",
2656]);
27export type ProviderRuntimeTurnStatus = typeof ProviderRuntimeTurnStatus.Type;
57export type RuntimeTurnState = typeof RuntimeTurnState.Type;
2858
29export const ProviderRuntimeSessionStartedEvent = Schema.Struct({
30 type: Schema.Literal("session.started"),
59export const RuntimePlanStepStatus = Schema.Literals(["pending", "inProgress", "completed"]);
60export type RuntimePlanStepStatus = typeof RuntimePlanStepStatus.Type;
61
62export const RuntimeItemStatus = Schema.Literals(["inProgress", "completed", "failed", "declined"]);
63export type RuntimeItemStatus = typeof RuntimeItemStatus.Type;
64
65export 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]);
74export type RuntimeContentStreamKind = typeof RuntimeContentStreamKind.Type;
75
76export const RuntimeSessionExitKind = Schema.Literals(["graceful", "error"]);
77export type RuntimeSessionExitKind = typeof RuntimeSessionExitKind.Type;
78
79export const RuntimeErrorClass = Schema.Literals([
80 "provider_error",
81 "transport_error",
82 "permission_error",
83 "validation_error",
84 "unknown",
85]);
86export type RuntimeErrorClass = typeof RuntimeErrorClass.Type;
87
88export 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]);
100export type CanonicalItemType = typeof CanonicalItemType.Type;
101
102export 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]);
111export type CanonicalRequestType = typeof CanonicalRequestType.Type;
112
113export 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]);
131export type ProviderRuntimeEventType = typeof ProviderRuntimeEventType.Type;
132
133export const SessionStartedType = Schema.Literal("session.started");
134export const SessionExitedType = Schema.Literal("session.exited");
135export const ThreadStartedType = Schema.Literal("thread.started");
136export const TurnStartedType = Schema.Literal("turn.started");
137export const TurnCompletedType = Schema.Literal("turn.completed");
138export const TurnPlanUpdatedType = Schema.Literal("turn.plan.updated");
139export const ItemStartedType = Schema.Literal("item.started");
140export const ItemUpdatedType = Schema.Literal("item.updated");
141export const ItemCompletedType = Schema.Literal("item.completed");
142export const ContentDeltaType = Schema.Literal("content.delta");
143export const RequestOpenedType = Schema.Literal("request.opened");
144export const RequestResolvedType = Schema.Literal("request.resolved");
145export const UserInputRequestedType = Schema.Literal("user-input.requested");
146export const UserInputResolvedType = Schema.Literal("user-input.resolved");
147export const RuntimeWarningType = Schema.Literal("runtime.warning");
148export const RuntimeErrorType = Schema.Literal("runtime.error");
149
150export 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});
162export type ProviderRuntimeEventBase = typeof ProviderRuntimeEventBase.Type;
163
164export const SessionStartedPayload = Schema.Struct({
37165 message: Schema.optional(TrimmedNonEmptyStringSchema),
166 resume: Schema.optional(Schema.Unknown),
167});
168export type SessionStartedPayload = typeof SessionStartedPayload.Type;
169
170export const SessionExitedPayload = Schema.Struct({
171 reason: Schema.optional(TrimmedNonEmptyStringSchema),
172 recoverable: Schema.optional(Schema.Boolean),
173 exitKind: Schema.optional(RuntimeSessionExitKind),
174});
175export type SessionExitedPayload = typeof SessionExitedPayload.Type;
176
177export const ThreadStartedPayload = Schema.Struct({
178 providerThreadId: Schema.optional(ProviderThreadId),
179});
180export type ThreadStartedPayload = typeof ThreadStartedPayload.Type;
181
182export const TurnStartedPayload = Schema.Struct({
183 model: Schema.optional(TrimmedNonEmptyStringSchema),
184 effort: Schema.optional(TrimmedNonEmptyStringSchema),
185});
186export type TurnStartedPayload = typeof TurnStartedPayload.Type;
187
188export 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});
196export type TurnCompletedPayload = typeof TurnCompletedPayload.Type;
197
198export const RuntimePlanStep = Schema.Struct({
199 step: TrimmedNonEmptyStringSchema,
200 status: RuntimePlanStepStatus,
201});
202export type RuntimePlanStep = typeof RuntimePlanStep.Type;
203
204export const TurnPlanUpdatedPayload = Schema.Struct({
205 explanation: Schema.optional(Schema.NullOr(TrimmedNonEmptyStringSchema)),
206 plan: Schema.Array(RuntimePlanStep),
207});
208export type TurnPlanUpdatedPayload = typeof TurnPlanUpdatedPayload.Type;
209
210export 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});
217export type ItemLifecyclePayload = typeof ItemLifecyclePayload.Type;
218
219export const ContentDeltaPayload = Schema.Struct({
220 streamKind: RuntimeContentStreamKind,
221 delta: Schema.String,
222 contentIndex: Schema.optional(Schema.Int),
223 summaryIndex: Schema.optional(Schema.Int),
224});
225export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
226
227export const RequestOpenedPayload = Schema.Struct({
228 requestType: CanonicalRequestType,
229 detail: Schema.optional(TrimmedNonEmptyStringSchema),
230 args: Schema.optional(Schema.Unknown),
231});
232export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
233
234export const RequestResolvedPayload = Schema.Struct({
235 requestType: CanonicalRequestType,
236 decision: Schema.optional(TrimmedNonEmptyStringSchema),
237 resolution: Schema.optional(Schema.Unknown),
238});
239export type RequestResolvedPayload = typeof RequestResolvedPayload.Type;
240
241export const UserInputQuestionOption = Schema.Struct({
242 label: TrimmedNonEmptyStringSchema,
243 description: TrimmedNonEmptyStringSchema,
244});
245export type UserInputQuestionOption = typeof UserInputQuestionOption.Type;
246
247export const UserInputQuestion = Schema.Struct({
248 id: TrimmedNonEmptyStringSchema,
249 header: TrimmedNonEmptyStringSchema,
250 question: TrimmedNonEmptyStringSchema,
251 options: Schema.Array(UserInputQuestionOption),
252});
253export type UserInputQuestion = typeof UserInputQuestion.Type;
254
255export const UserInputRequestedPayload = Schema.Struct({
256 questions: Schema.Array(UserInputQuestion),
257});
258export type UserInputRequestedPayload = typeof UserInputRequestedPayload.Type;
259
260export const UserInputResolvedPayload = Schema.Struct({
261 answers: UnknownRecordSchema,
262});
263export type UserInputResolvedPayload = typeof UserInputResolvedPayload.Type;
264
265export const RuntimeWarningPayload = Schema.Struct({
266 message: TrimmedNonEmptyStringSchema,
267 detail: Schema.optional(Schema.Unknown),
268});
269export type RuntimeWarningPayload = typeof RuntimeWarningPayload.Type;
270
271export const RuntimeErrorPayload = Schema.Struct({
272 message: TrimmedNonEmptyStringSchema,
273 class: Schema.optional(RuntimeErrorClass),
274 detail: Schema.optional(Schema.Unknown),
275});
276export type RuntimeErrorPayload = typeof RuntimeErrorPayload.Type;
277
278export const ProviderRuntimeSessionStartedEvent = Schema.Struct({
279 ...ProviderRuntimeEventBase.fields,
280 type: SessionStartedType,
281 payload: SessionStartedPayload,
38282});
39283export type ProviderRuntimeSessionStartedEvent = typeof ProviderRuntimeSessionStartedEvent.Type;
40284
41285export 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});
51290export type ProviderRuntimeSessionExitedEvent = typeof ProviderRuntimeSessionExitedEvent.Type;
52291
53292export 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});
62297export type ProviderRuntimeThreadStartedEvent = typeof ProviderRuntimeThreadStartedEvent.Type;
63298
64299export 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});
74304export type ProviderRuntimeTurnStartedEvent = typeof ProviderRuntimeTurnStartedEvent.Type;
75305
76306export 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});
88311export type ProviderRuntimeTurnCompletedEvent = typeof ProviderRuntimeTurnCompletedEvent.Type;
89312
90export 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,
313export const ProviderRuntimeTurnPlanUpdatedEvent = Schema.Struct({
314 ...ProviderRuntimeEventBase.fields,
315 type: TurnPlanUpdatedType,
316 payload: TurnPlanUpdatedPayload,
101317});
102export type ProviderRuntimeMessageDeltaEvent = typeof ProviderRuntimeMessageDeltaEvent.Type;
318export type ProviderRuntimeTurnPlanUpdatedEvent = typeof ProviderRuntimeTurnPlanUpdatedEvent.Type;
103319
104export 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),
320export const ProviderRuntimeItemStartedEvent = Schema.Struct({
321 ...ProviderRuntimeEventBase.fields,
322 type: ItemStartedType,
323 payload: ItemLifecyclePayload,
114324});
115export type ProviderRuntimeMessageCompletedEvent = typeof ProviderRuntimeMessageCompletedEvent.Type;
325export type ProviderRuntimeItemStartedEvent = typeof ProviderRuntimeItemStartedEvent.Type;
116326
117export 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),
327export const ProviderRuntimeItemUpdatedEvent = Schema.Struct({
328 ...ProviderRuntimeEventBase.fields,
329 type: ItemUpdatedType,
330 payload: ItemLifecyclePayload,
130331});
131export type ProviderRuntimeToolStartedEvent = typeof ProviderRuntimeToolStartedEvent.Type;
332export type ProviderRuntimeItemUpdatedEvent = typeof ProviderRuntimeItemUpdatedEvent.Type;
132333
133export 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),
334export const ProviderRuntimeItemCompletedEvent = Schema.Struct({
335 ...ProviderRuntimeEventBase.fields,
336 type: ItemCompletedType,
337 payload: ItemLifecyclePayload,
146338});
147export type ProviderRuntimeToolCompletedEvent = typeof ProviderRuntimeToolCompletedEvent.Type;
339export type ProviderRuntimeItemCompletedEvent = typeof ProviderRuntimeItemCompletedEvent.Type;
148340
149export 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),
341export const ProviderRuntimeContentDeltaEvent = Schema.Struct({
342 ...ProviderRuntimeEventBase.fields,
343 type: ContentDeltaType,
344 payload: ContentDeltaPayload,
162345});
163export type ProviderRuntimeApprovalRequestedEvent =
164 typeof ProviderRuntimeApprovalRequestedEvent.Type;
346export type ProviderRuntimeContentDeltaEvent = typeof ProviderRuntimeContentDeltaEvent.Type;
165347
166export 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),
348export const ProviderRuntimeRequestOpenedEvent = Schema.Struct({
349 ...ProviderRuntimeEventBase.fields,
350 type: RequestOpenedType,
351 payload: RequestOpenedPayload,
179352});
180export type ProviderRuntimeApprovalResolvedEvent = typeof ProviderRuntimeApprovalResolvedEvent.Type;
353export type ProviderRuntimeRequestOpenedEvent = typeof ProviderRuntimeRequestOpenedEvent.Type;
181354
182export 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),
355export const ProviderRuntimeRequestResolvedEvent = Schema.Struct({
356 ...ProviderRuntimeEventBase.fields,
357 type: RequestResolvedType,
358 payload: RequestResolvedPayload,
193359});
194export type ProviderRuntimeCheckpointCapturedEvent =
195 typeof ProviderRuntimeCheckpointCapturedEvent.Type;
360export type ProviderRuntimeRequestResolvedEvent = typeof ProviderRuntimeRequestResolvedEvent.Type;
361
362export const ProviderRuntimeUserInputRequestedEvent = Schema.Struct({
363 ...ProviderRuntimeEventBase.fields,
364 type: UserInputRequestedType,
365 payload: UserInputRequestedPayload,
366});
367export type ProviderRuntimeUserInputRequestedEvent =
368 typeof ProviderRuntimeUserInputRequestedEvent.Type;
369
370export const ProviderRuntimeUserInputResolvedEvent = Schema.Struct({
371 ...ProviderRuntimeEventBase.fields,
372 type: UserInputResolvedType,
373 payload: UserInputResolvedPayload,
374});
375export type ProviderRuntimeUserInputResolvedEvent =
376 typeof ProviderRuntimeUserInputResolvedEvent.Type;
377
378export const ProviderRuntimeWarningEvent = Schema.Struct({
379 ...ProviderRuntimeEventBase.fields,
380 type: RuntimeWarningType,
381 payload: RuntimeWarningPayload,
382});
383export type ProviderRuntimeWarningEvent = typeof ProviderRuntimeWarningEvent.Type;
196384
197385export 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});
209390export type ProviderRuntimeErrorEvent = typeof ProviderRuntimeErrorEvent.Type;
210391
211export const ProviderRuntimeEvent = Schema.Union([
392export 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]);
226export type ProviderRuntimeEvent = typeof ProviderRuntimeEvent.Type;
410export type ProviderRuntimeEventV2 = typeof ProviderRuntimeEventV2.Type;
411
412export const ProviderRuntimeEvent = ProviderRuntimeEventV2;
413export type ProviderRuntimeEvent = ProviderRuntimeEventV2;
414
415export const ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
416export type ProviderRuntimeMessageDeltaEvent = ProviderRuntimeContentDeltaEvent;
417export const ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
418export type ProviderRuntimeMessageCompletedEvent = ProviderRuntimeItemCompletedEvent;
419export const ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
420export type ProviderRuntimeToolStartedEvent = ProviderRuntimeItemStartedEvent;
421export const ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
422export type ProviderRuntimeToolCompletedEvent = ProviderRuntimeItemCompletedEvent;
423export const ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
424export type ProviderRuntimeApprovalRequestedEvent = ProviderRuntimeRequestOpenedEvent;
425export const ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
426export type ProviderRuntimeApprovalResolvedEvent = ProviderRuntimeRequestResolvedEvent;
427
428export const ProviderRuntimeToolKind = Schema.Literals([
429 "command_execution",
430 "file_change",
431 "mcp_tool_call",
432 "dynamic_tool_call",
433 "other",
434]);
435export type ProviderRuntimeToolKind = typeof ProviderRuntimeToolKind.Type;
436
437export const ProviderRuntimeTurnStatus = RuntimeTurnState;
438export type ProviderRuntimeTurnStatus = RuntimeTurnState;