Skip to content

fix: integrate handleChatCompletion to save chat memories#128

Merged
sweetmantech merged 2 commits intotestfrom
sweetmantech/myc-3950-api-apichat-fix-missing-memories
Jan 16, 2026
Merged

fix: integrate handleChatCompletion to save chat memories#128
sweetmantech merged 2 commits intotestfrom
sweetmantech/myc-3950-api-apichat-fix-missing-memories

Conversation

@sweetmantech
Copy link
Contributor

Summary

  • Integrates handleChatCompletion into chat handlers using the same pattern as Recoup-Chat
  • Fixes the bug where conversations appear empty when users return to them

Implementation (matching Recoup-Chat pattern)

Streaming (handleChatStream.ts):

onFinish: ({ messages }) => {
  void handleChatCompletion(body, messages).catch((e) => {
    console.error("Failed to handle chat completion:", e);
  });
},

Generate (handleChatGenerate.ts):

const responseUIMessage = {
  id: generateUUID(),
  role: "assistant",
  parts: [{ type: "text", text: result?.text || "" }],
} as UIMessage;

void handleChatCompletion(body, [responseUIMessage]).catch((e) => {
  console.error("Failed to handle chat completion:", e);
});

Test plan

  • All existing tests pass (16 tests)
  • Mocks added for handleChatCompletion in test files

🤖 Generated with Claude Code

Uses the same pattern as Recoup-Chat:
- Streaming: Uses onFinish callback which receives completed messages
- Generate: Constructs UIMessage from result.text with generateUUID

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@vercel
Copy link
Contributor

vercel bot commented Jan 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
recoup-api Ready Ready Preview Jan 16, 2026 9:37pm

@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Add comprehensive unit tests to verify handleChatCompletion is called correctly:

handleChatStream.test.ts:
- Verify onFinish callback is passed to createUIMessageStream
- Verify handleChatCompletion receives body and response messages
- Verify errors in handleChatCompletion don't break streaming response

handleChatGenerate.test.ts:
- Verify handleChatCompletion is called with body and constructed UIMessage
- Verify UIMessage has correct structure (id, role, parts with text)
- Verify errors in handleChatCompletion don't break JSON response
- Verify empty text from generateText is handled correctly

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@sweetmantech sweetmantech merged commit 8bf8f44 into test Jan 16, 2026
3 checks passed
sweetmantech added a commit that referenced this pull request Jan 16, 2026
…)"

This reverts the handleChatCompletion integration as memories are still not being saved correctly.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments