Forward live usage stream events

The wire schema already allowed completed-turn usage, but rejected active usage updates before clients could see them. Accept usage_updated payloads and preserve turn ids on streamed turn events.
This commit is contained in:
Mohamed Boudra
2026-06-20 22:47:49 +07:00
parent 5180708e26
commit 4779757138
2 changed files with 52 additions and 0 deletions
+13
View File
@@ -594,11 +594,19 @@ export const AgentStreamEventPayloadSchema = z.discriminatedUnion("type", [
z.object({
type: z.literal("turn_started"),
provider: AgentProviderSchema,
turnId: z.string().optional(),
}),
z.object({
type: z.literal("turn_completed"),
provider: AgentProviderSchema,
usage: AgentUsageSchema.optional(),
turnId: z.string().optional(),
}),
z.object({
type: z.literal("usage_updated"),
provider: AgentProviderSchema,
usage: AgentUsageSchema,
turnId: z.string().optional(),
}),
z.object({
type: z.literal("turn_failed"),
@@ -606,27 +614,32 @@ export const AgentStreamEventPayloadSchema = z.discriminatedUnion("type", [
error: z.string(),
code: z.string().optional(),
diagnostic: z.string().optional(),
turnId: z.string().optional(),
}),
z.object({
type: z.literal("turn_canceled"),
provider: AgentProviderSchema,
reason: z.string(),
turnId: z.string().optional(),
}),
z.object({
type: z.literal("timeline"),
provider: AgentProviderSchema,
item: AgentTimelineItemPayloadSchema,
turnId: z.string().optional(),
}),
z.object({
type: z.literal("permission_requested"),
provider: AgentProviderSchema,
request: AgentPermissionRequestPayloadSchema,
turnId: z.string().optional(),
}),
z.object({
type: z.literal("permission_resolved"),
provider: AgentProviderSchema,
requestId: z.string(),
resolution: AgentPermissionResponseSchema,
turnId: z.string().optional(),
}),
z.object({
type: z.literal("attention_required"),