Skip to content

Commit a510c26

Browse files
committed
Fix planner response schema for Responses API
1 parent e78dbd3 commit a510c26

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

packages/core/src/index.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,17 @@ export const scheduleConstraintSchema = z.object({
454454

455455
});
456456

457+
export const scheduleConstraintResponseFormatSchema = z.object({
458+
dayReference: z.enum(["today", "tomorrow", "weekday"]).nullable(),
459+
weekday: weekdaySchema.nullable(),
460+
weekOffset: z.number().int().min(0).max(8).nullable(),
461+
relativeMinutes: z.number().int().positive().max(7 * 24 * 60).nullable().optional(),
462+
explicitHour: z.number().int().min(0).max(23).nullable(),
463+
minute: z.number().int().min(0).max(59).nullable(),
464+
preferredWindow: z.enum(["morning", "afternoon", "evening"]).nullable(),
465+
sourceText: z.string().min(1)
466+
});
467+
457468
export const taskReferenceSchema = z.discriminatedUnion("kind", [
458469
z.object({
459470
kind: z.literal("created_task"),
@@ -484,13 +495,27 @@ export const createScheduleBlockPlanningActionSchema = z.object({
484495
reason: z.string().min(1)
485496
});
486497

498+
export const createScheduleBlockPlanningActionResponseFormatSchema = z.object({
499+
type: z.literal("create_schedule_block"),
500+
taskRef: taskReferenceSchema,
501+
scheduleConstraint: scheduleConstraintResponseFormatSchema.nullable(),
502+
reason: z.string().min(1)
503+
});
504+
487505
export const moveScheduleBlockPlanningActionSchema = z.object({
488506
type: z.literal("move_schedule_block"),
489507
blockRef: scheduleBlockReferenceSchema,
490508
scheduleConstraint: scheduleConstraintSchema.nullable(),
491509
reason: z.string().min(1)
492510
});
493511

512+
export const moveScheduleBlockPlanningActionResponseFormatSchema = z.object({
513+
type: z.literal("move_schedule_block"),
514+
blockRef: scheduleBlockReferenceSchema,
515+
scheduleConstraint: scheduleConstraintResponseFormatSchema.nullable(),
516+
reason: z.string().min(1)
517+
});
518+
494519
export const completeTaskPlanningActionSchema = z.object({
495520
type: z.literal("complete_task"),
496521
taskRef: taskReferenceSchema,
@@ -510,12 +535,26 @@ export const planningActionSchema = z.discriminatedUnion("type", [
510535
clarifyPlanningActionSchema
511536
]);
512537

538+
export const planningActionResponseFormatSchema = z.discriminatedUnion("type", [
539+
createTaskPlanningActionSchema,
540+
createScheduleBlockPlanningActionResponseFormatSchema,
541+
moveScheduleBlockPlanningActionResponseFormatSchema,
542+
completeTaskPlanningActionSchema,
543+
clarifyPlanningActionSchema
544+
]);
545+
513546
export const inboxPlanningOutputSchema = z.object({
514547
confidence: z.number().min(0).max(1),
515548
summary: z.string().min(1),
516549
actions: z.array(planningActionSchema).min(1)
517550
});
518551

552+
export const inboxPlanningResponseFormatSchema = z.object({
553+
confidence: z.number().min(0).max(1),
554+
summary: z.string().min(1),
555+
actions: z.array(planningActionResponseFormatSchema).min(1)
556+
});
557+
519558
export const inboxPlanningTaskContextSchema = z.object({
520559
alias: z.string().min(1),
521560
task: taskSchema

packages/integrations/src/openai.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { z } from "zod";
55
import {
66
getConfig,
77
inboxPlanningContextSchema,
8+
inboxPlanningResponseFormatSchema,
89
inboxPlanningOutputSchema,
910
turnRoutingInputSchema,
1011
turnRoutingOutputSchema,
@@ -95,11 +96,11 @@ export async function planInboxItemWithResponses(
9596
}
9697
],
9798
text: {
98-
format: zodTextFormat(inboxPlanningOutputSchema, "atlas_inbox_planning_output")
99+
format: zodTextFormat(inboxPlanningResponseFormatSchema, "atlas_inbox_planning_output")
99100
}
100101
});
101102

102-
return inboxPlanningOutputSchema.parse(response.output_parsed);
103+
return inboxPlanningOutputSchema.parse(inboxPlanningResponseFormatSchema.parse(response.output_parsed));
103104
}
104105

105106
export async function routeTurnWithResponses(

0 commit comments

Comments
 (0)