Skip to content

refactor(core): migrate MessageV2 message DTOs (User/Assistant/Part/Info/WithParts) to Effect Schema#23757

Merged
kitlangton merged 1 commit intodevfrom
kit/session-schema-messages
Apr 22, 2026
Merged

refactor(core): migrate MessageV2 message DTOs (User/Assistant/Part/Info/WithParts) to Effect Schema#23757
kitlangton merged 1 commit intodevfrom
kit/session-schema-messages

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Summary

Fourth piecemeal slice of the session-domain Effect Schema migration, stacked on #23756.

  • Migrates User, Assistant, Part discriminated union, Info, and WithParts to Effect Schema.
  • Replaces the cast-based Zod Part definition with a proper Schema.Union that annotates `discriminator: "type"` + `identifier: "Part"`.
  • Assistant.error keeps a Zod-side discriminated union via ZodOverride because NamedError.create(...) errors are still Zod (error migration is intentionally out of scope for this PR).
  • Event payloads (`SyncEvent.define`, `BusEvent.define`) still take Zod inputs and now reference the derived `.zod` on each schema.
  • Updates callers that were reaching into the Zod API directly:
    • `session.ts` (`MessageV2.Assistant.shape.error` → `.zod.shape.error`)
    • `server/routes/instance/session.ts` (`MessageV2.{Info,Assistant,Part,WithParts}` → `.zod`)
    • `session/prompt.ts` (`.safeParse` → `.zod.safeParse`)
    • `cli/cmd/import.ts` (`.parse` → `.zod.parse`)
    • `test/session/structured-output.test.ts` (`.safeParse` → `.zod.safeParse`)

Acceptance check

  • `bun typecheck` (package + repo root) clean.
  • `bun run test` → 2010 pass / 0 fail.
  • `bun dev generate` byte-identical to committed `packages/sdk/openapi.json`.
  • `packages/sdk/js/src/v2/gen/types.gen.ts` unchanged after `bun script/build.ts`.

Follow-up

Remaining Zod in `message-v2.ts`:

  • `NamedError.create(...)` error classes (`OutputLengthError`, `AbortedError`, `StructuredOutputError`, `AuthError`, `APIError`, `ContextOverflowError`). These ripple across `retry.ts`, `processor.ts`, `prompt.ts` `isInstance`/`toObject` callers, plus other files. Best approached as its own PR using a bridge on top of `Schema.TaggedErrorClass`.
  • Internal `Cursor`. Not worth a dedicated PR; can ride along with a future cleanup.
  • `SyncEvent.define` / `BusEvent.define` payloads remain `z.object` until those APIs move to `Schema`.

@kitlangton kitlangton force-pushed the kit/session-schema-parts branch from 27da9ba to ec4f641 Compare April 22, 2026 03:07
@kitlangton kitlangton force-pushed the kit/session-schema-messages branch from bc8ca4b to eebe1f7 Compare April 22, 2026 03:10
@kitlangton kitlangton force-pushed the kit/session-schema-parts branch from ec4f641 to f93bc46 Compare April 22, 2026 03:12
@kitlangton kitlangton force-pushed the kit/session-schema-messages branch from eebe1f7 to c7ba857 Compare April 22, 2026 03:12
Base automatically changed from kit/session-schema-parts to dev April 22, 2026 03:17
…nfo/WithParts) to Effect Schema

Continues the session-domain Schema migration. The assistant error union still references NamedError-based Zod errors via ZodOverride; errors migrate in a separate slice.
@kitlangton kitlangton force-pushed the kit/session-schema-messages branch from c7ba857 to 6241e36 Compare April 22, 2026 03:18
@kitlangton kitlangton merged commit e895438 into dev Apr 22, 2026
9 checks passed
@kitlangton kitlangton deleted the kit/session-schema-messages branch April 22, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant