-
Notifications
You must be signed in to change notification settings - Fork 9
fix(chat-workflow): persist the assistant message after a successful run #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sweetmantech
merged 9 commits into
test
from
feat/persist-assistant-message-after-workflow
May 25, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5f327a2
fix(chat-workflow): persist the assistant message after a successful run
sweetmantech e8b711f
fix(chat-workflow): loosen AssistantMessage type to accept UIMessage
sweetmantech 3040000
fix(chat-workflow): mark persistAssistantMessage as a "use step"
sweetmantech 299919a
debug(chat-workflow): TEMP diagnostic logs in persistAssistantMessage
sweetmantech 636fff5
fix(chat-workflow): pass generateMessageId to toUIMessageStream
sweetmantech 8974a37
refactor(chat-workflow): move assistantMessageId generation to workfl…
sweetmantech fe6c30a
chore(chat-workflow): revert temp diagnostic logs in persistAssistant…
sweetmantech df312db
fix(chat-workflow): bump last_assistant_message_at on persist (unread…
sweetmantech 8fd29dd
chore: format-fix workflow files (prettier --write)
sweetmantech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/lib/workflows/__tests__/generateAssistantMessageId.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import { generateAssistantMessageId } from "@/app/lib/workflows/generateAssistantMessageId"; | ||
|
|
||
| vi.mock("ai", async () => { | ||
| const actual = await vi.importActual<typeof import("ai")>("ai"); | ||
| return { ...actual, generateId: vi.fn(() => "generated-by-mock") }; | ||
| }); | ||
|
|
||
| describe("generateAssistantMessageId", () => { | ||
| it("returns the value from ai's generateId()", async () => { | ||
| const id = await generateAssistantMessageId(); | ||
| expect(id).toBe("generated-by-mock"); | ||
| }); | ||
|
|
||
| it("returns a string", async () => { | ||
| const id = await generateAssistantMessageId(); | ||
| expect(typeof id).toBe("string"); | ||
| expect(id.length).toBeGreaterThan(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { generateId } from "ai"; | ||
|
|
||
| /** | ||
| * Vercel Workflow `"use step"` that returns a fresh message id. | ||
| * | ||
| * Wrapped as a step rather than inlined into the workflow body | ||
| * because `generateId()` is non-deterministic — calling it directly | ||
| * from workflow code would break the durable-replay contract (a | ||
| * replay would generate a *different* id and diverge from the | ||
| * captured event log). As a step, the result is captured in the | ||
| * event log once and reused on every replay. | ||
| * | ||
| * Mirrors open-agents' `generateId` step in | ||
| * `apps/web/app/workflows/chat.ts`. | ||
| */ | ||
| export async function generateAssistantMessageId(): Promise<string> { | ||
| "use step"; | ||
| return generateId(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Custom agent: Enforce Clear Code Style and Maintainability Practices
This test file exceeds the rule’s 100-line limit and should be split into smaller modules.
Prompt for AI agents