🐛 fix: normalize AI-generated dates to valid ISO offset datetimes

- add normalizeAiDateString() to coerce bare ISO datetimes, date-only
  strings, and fractional-second variants into offset-aware format
- apply via z.preprocess in AiEventResponseItemSchema so Zod validation
  no longer rejects AI responses missing a timezone offset
- fix system prompt to use toISOString() (unambiguous UTC) and clarify
  expected datetime format for the AI model
- install bun-types and add to tsconfig so bun:test resolves cleanly
- add 8 behaviour-driven tests covering all normalizer edge cases
This commit is contained in:
2026-04-07 23:01:42 -04:00
parent f3ccbf5db5
commit cbd2559169
7 changed files with 109 additions and 5 deletions

View File

@@ -17,7 +17,7 @@ TypeScript type:
description?: string,
location?: string,
url?: string,
start: string, // ISO datetime
start: string, // ISO 8601 datetime with timezone, e.g. "2025-04-10T10:00:00-04:00"
end?: string,
allDay?: boolean,
recurrenceRule?: string // valid iCal RRULE string like FREQ=WEEKLY;BYDAY=MO;INTERVAL=1
@@ -26,7 +26,7 @@ TypeScript type:
Rules:
- If the user describes multiple events in one prompt, return multiple objects (one per event).
- Always return a valid JSON array of objects, even if there's only one event.
- Today is ${new Date().toLocaleString()}.
- Today is ${new Date().toISOString()}.
- If no time is given, assume allDay event.
- If no end time is given (and event is not allDay), default to 1 hour after start.
- If multiple events are described, return multiple.