release: persist assistant message per step (#603)

Merged
SW
5mo ago
+251-283

Summary

Promotes `test` to `main`. Contains the squashed PR:

  • #603 — `feat(chat-workflow): persist assistant message per step`. Moves assistant message persistence from the workflow body into `runAgentStep` via `createUIMessageStream`'s `onStepFinish` + `onFinish` callbacks. Adds `update` option to `upsertChatMessage` for DO UPDATE on conflict. Verified end-to-end on preview — assistant row `QquxcYrQjN90QRWr` persists into `chat_messages` with full metadata.

Test plan

  • PR #603 CI green (format, lint, test, Vercel, CodeRabbit)
  • PR #603 end-to-end verified on preview via `GET /api/sessions/{sid}/chats/{cid}`
  • Watch Vercel production deploy after merge

Summary by cubic

Persist the assistant message on every step of the chat workflow so partial replies are saved and survive refreshes. Moves persistence into the step stream and makes writes idempotent via DO UPDATE.

  • New Features
    • Stream through createUIMessageStream and persist on onStepFinish and onFinish; uses a stable assistantMessageId for one row per turn.
    • persistAssistantMessage now overwrites the row as it grows and bumps updated_at and last_assistant_message_at on every persist (partials show as unread).
    • upsertChatMessage adds { update: true } to enable DO UPDATE (sets ignoreDuplicates: false).
    • runAgentStep accepts chatId and handles per-step persistence; runAgentWorkflow drops its own persist call and still uses the final message for credits.
    • Tests updated to cover the new streaming, persistence, and upsert behavior.