Skip to content

fix: restore message callbacks - #2864

Merged
ranst91 merged 4 commits into
mainfrom
fix/restore-message-callbacks
Dec 17, 2025
Merged

ranst91 merged 4 commits into
mainfrom
fix/restore-message-callbacks

Conversation

@ranst91

@ranst91 ranst91 commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added four chat callbacks: onInProgress (loading state), onSubmitMessage (message content), onStopGeneration, and onReloadMessages to observe submit, stop, reload, and progress events.
    • These callbacks enable integrations or analytics to react to message submissions, regeneration, stopping, and loading state changes.
  • Documentation

    • Reference docs updated to describe the new callback properties.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel

vercel Bot commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Review Updated (UTC)
docs Ready Ready Preview, Comment Dec 17, 2025 0:41am
examples-coagents-ai-travel-app Ready Ready Preview, Comment Dec 17, 2025 0:41am
examples-coagents-research-canvas-ui Ready Ready Preview, Comment Dec 17, 2025 0:41am
1 Skipped Deployment
Project Deployment Review Updated (UTC)
examples-coagents-ai-researcher-ui Ignored Ignored Dec 17, 2025 0:41am

@coderabbitai

coderabbitai Bot commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Exports two new public callback types and adds four optional callback options (onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) to the useCopilotChat API; threads these callbacks into the internal hook and replaces duplicate internal types in the Chat component. Documentation updated.

Changes

Cohort / File(s) Summary
Public Type Exports
CopilotKit/packages/react-core/src/hooks/index.ts
Exported type OnReloadMessages and type OnStopGeneration from ./use-copilot-chat_internal, expanding the public export surface.
Hook implementation & types
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
Added types OnStopGenerationArguments, OnReloadMessagesArguments, OnStopGeneration, OnReloadMessages; extended UseCopilotChatOptions with onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages; invoked these callbacks at message submit, reload, and stop flows.
Component wiring / refactor
CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
Removed local stop/reload argument types and imported the new public OnStopGeneration and OnReloadMessages types; passed onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages through to the internal hook.
Documentation
docs/content/docs/reference/hooks/useCopilotChat.mdx
Documented the four new optional callback properties and their signatures in the public API reference.
Release notes / changeset
CopilotKit/.changeset/eleven-ties-grin.md
Added changeset entry bumping patch versions for @copilotkit/react-core and @copilotkit/react-ui with note "restore message callbacks".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect callback invocation logic in CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts for correct extraction of message content and safe async handling of onSubmitMessage.
  • Verify that onStopGeneration and onReloadMessages receive the intended agent and messages context.
  • Confirm CopilotKit/packages/react-ui/src/components/chat/Chat.tsx type imports align with public exports and no accidental runtime changes were introduced.
  • Check documentation matches the implemented signatures.

Suggested reviewers

  • mme
  • ataibarkai
  • tylerslaton

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: restore message callbacks' accurately summarizes the main change: restoring four message callback options (onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) to the public API across the react-core and react-ui packages.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/restore-message-callbacks

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (1)

111-115: Consider adding JSDoc documentation for the new callback props.

Other props in UseCopilotChatOptions have documentation comments. For API consistency and better developer experience, consider documenting these new callbacks:

+  /**
+   * A callback that gets called when the loading state changes.
+   */
   onInProgress?: (isLoading: boolean) => void;
+  /**
+   * A callback that gets called when a message is submitted.
+   */
   onSubmitMessage?: (messageContent: string) => Promise<void> | void;
+  /**
+   * A callback that gets called when generation is stopped.
+   */
   onStopGeneration?: OnStopGeneration;
+  /**
+   * A callback that gets called when messages are reloaded/regenerated.
+   */
   onReloadMessages?: OnReloadMessages;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68f8f30 and 351d19c.

📒 Files selected for processing (3)
  • CopilotKit/packages/react-core/src/hooks/index.ts (1 hunks)
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (5 hunks)
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development-workflow.mdc)

Use ESLint configuration from CopilotKit/utilities/eslint-config-custom for consistent linting across the monorepo

Files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

**/*.{ts,tsx}: Use TypeScript for better type safety in React component development
Implement proper error handling in React components
Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components
Maintain consistent styling with Tailwind CSS in UI components
Implement responsive design in UI components
Use CopilotProvider at the root of the application to wrap all app components

**/*.{ts,tsx}: Use 'auto' mode (default) in CopilotChat suggestions prop to generate suggestions automatically at the start of chat and after every turn
Use 'manual' mode in CopilotChat suggestions prop only when you need full programmatic control via setSuggestions or generateSuggestions from useCopilotChat hook
Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system

Files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
**/*use-copilot-chat*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/suggestions-development.mdc)

Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts

Files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
**/*{suggestions,Suggestions,Chat}*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/suggestions-development.mdc)

Handle empty states in suggestions - some configurations may not generate suggestions

Files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
🧠 Learnings (16)
📓 Common learnings
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-11-26T15:00:55.767Z
Learning: Applies to **/*.{ts,tsx} : Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*use-copilot-chat*.{ts,tsx} : Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Use 'manual' mode in CopilotChat suggestions prop only when you need full programmatic control via setSuggestions or generateSuggestions from useCopilotChat hook
📚 Learning: 2025-11-26T15:00:55.767Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-11-26T15:00:55.767Z
Learning: Applies to **/*.{ts,tsx} : Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Use 'manual' mode in CopilotChat suggestions prop only when you need full programmatic control via setSuggestions or generateSuggestions from useCopilotChat hook

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*use-copilot-chat*.{ts,tsx} : Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Verify that useCopilotChatSuggestions hook is being called in components to register configuration for suggestions

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Use 'auto' mode (default) in CopilotChat suggestions prop to generate suggestions automatically at the start of chat and after every turn

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*{suggestions,Suggestions}*.{ts,tsx} : Don't modify suggestions state directly - always use provided hooks and functions for suggestions management

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*{suggestions,Suggestions}*.{ts,tsx} : When working with suggestions in CopilotKit, load the Suggestions development guide

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:08.247Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-11-26T15:01:08.247Z
Learning: Frontend applications should follow the pattern: Next.js app with CopilotProvider and CopilotChat component

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:08.247Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-11-26T15:01:08.247Z
Learning: For building a simple Copilot, start with the copilot-chat-with-your-data example, use react-core for basic integration, and add react-ui for pre-built components

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Implement clean cancellation of in-flight requests via abort controllers when new suggestion generation is initiated

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Implement streaming validation for suggestions to handle partial data gracefully during AI generation without console spam

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*{suggestions,Suggestions,Chat}*.{ts,tsx} : Handle empty states in suggestions - some configurations may not generate suggestions

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions*.{ts,tsx} : Ensure proper error handling for network/API errors without infinite retries in suggestions generation

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Automatically deduplicate suggestions based on message content to prevent duplicate suggestions from being shown

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
🧬 Code graph analysis (1)
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (1)
CopilotKit/packages/react-core/src/hooks/index.ts (2)
  • OnStopGeneration (13-13)
  • OnReloadMessages (12-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (26)
  • GitHub Check: dojo / agno
  • GitHub Check: dojo / langgraph-python
  • GitHub Check: dojo / server-starter
  • GitHub Check: dojo / middleware-starter
  • GitHub Check: dojo / llama-index
  • GitHub Check: dojo / langgraph-fastapi
  • GitHub Check: dojo / mastra
  • GitHub Check: dojo / mastra-agent-local
  • GitHub Check: dojo / pydantic-ai
  • GitHub Check: dojo / aws-strands
  • GitHub Check: dojo / langgraph-typescript
  • GitHub Check: dojo / server-starter-all
  • GitHub Check: dojo / adk-middleware
  • GitHub Check: dojo / a2a-middleware
  • GitHub Check: dojo / crew-ai
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: Test (20.x)
  • GitHub Check: Test (18.x)
🔇 Additional comments (4)
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (1)

43-64: LGTM!

The new callback argument types and function type aliases are well-documented and cleanly designed. Using intersection types for OnReloadMessagesArguments provides good type composition.

CopilotKit/packages/react-core/src/hooks/index.ts (1)

9-14: LGTM!

The new type exports (OnReloadMessages, OnStopGeneration) are correctly re-exported from the internal module, expanding the public API surface as intended.

CopilotKit/packages/react-ui/src/components/chat/Chat.tsx (2)

82-84: LGTM!

The type imports from @copilotkit/react-core correctly use the type keyword and align with the newly exported public types.


568-574: LGTM!

The callbacks are correctly wired from CopilotChatProps through to useCopilotChatInternal, enabling external observers to track chat lifecycle events.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/content/docs/reference/hooks/useCopilotChat.mdx (1)

127-141: Documentation entries missing descriptions.

The new callback properties are documented with their types but have empty descriptions. Consider adding brief descriptions to help users understand when each callback fires:

 <PropertyReference name="onInProgress" type="(isLoading: boolean) => void"  > 
-
+Called when the chat loading state changes.
 </PropertyReference>

 <PropertyReference name="onSubmitMessage" type="(messageContent: string) => Promise<void> | void"  > 
-
+Called after a message is submitted and processed.
 </PropertyReference>

 <PropertyReference name="onStopGeneration" type="OnStopGeneration"  > 
-
+Called when generation is stopped. Receives current agent name and messages.
 </PropertyReference>

 <PropertyReference name="onReloadMessages" type="OnReloadMessages"  > 
-
+Called when messages are reloaded/regenerated. Receives messageId, agent name, and messages.
 </PropertyReference>

Note: Since this file is auto-generated, the descriptions should be added to the source file (use-copilot-chat.ts or the internal hook).

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 351d19c and 226e45b.

📒 Files selected for processing (4)
  • CopilotKit/packages/react-core/src/hooks/index.ts (1 hunks)
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (5 hunks)
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx (2 hunks)
  • docs/content/docs/reference/hooks/useCopilotChat.mdx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development-workflow.mdc)

Use ESLint configuration from CopilotKit/utilities/eslint-config-custom for consistent linting across the monorepo

Files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

**/*.{ts,tsx}: Use TypeScript for better type safety in React component development
Implement proper error handling in React components
Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components
Maintain consistent styling with Tailwind CSS in UI components
Implement responsive design in UI components
Use CopilotProvider at the root of the application to wrap all app components

**/*.{ts,tsx}: Use 'auto' mode (default) in CopilotChat suggestions prop to generate suggestions automatically at the start of chat and after every turn
Use 'manual' mode in CopilotChat suggestions prop only when you need full programmatic control via setSuggestions or generateSuggestions from useCopilotChat hook
Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system

Files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
**/*{suggestions,Suggestions,Chat}*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/suggestions-development.mdc)

Handle empty states in suggestions - some configurations may not generate suggestions

Files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
**/*use-copilot-chat*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/suggestions-development.mdc)

Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts

Files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
🧠 Learnings (15)
📓 Common learnings
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-11-26T15:00:55.767Z
Learning: Applies to **/*.{ts,tsx} : Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*use-copilot-chat*.{ts,tsx} : Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Verify that useCopilotChatSuggestions hook is being called in components to register configuration for suggestions
📚 Learning: 2025-11-26T15:00:55.767Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-11-26T15:00:55.767Z
Learning: Applies to **/*.{ts,tsx} : Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components

Applied to files:

  • docs/content/docs/reference/hooks/useCopilotChat.mdx
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*use-copilot-chat*.{ts,tsx} : Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts

Applied to files:

  • docs/content/docs/reference/hooks/useCopilotChat.mdx
  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Use 'manual' mode in CopilotChat suggestions prop only when you need full programmatic control via setSuggestions or generateSuggestions from useCopilotChat hook

Applied to files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Use 'auto' mode (default) in CopilotChat suggestions prop to generate suggestions automatically at the start of chat and after every turn

Applied to files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system

Applied to files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:08.247Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-11-26T15:01:08.247Z
Learning: Frontend applications should follow the pattern: Next.js app with CopilotProvider and CopilotChat component

Applied to files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*{suggestions,Suggestions}*.{ts,tsx} : When working with suggestions in CopilotKit, load the Suggestions development guide

Applied to files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Verify that useCopilotChatSuggestions hook is being called in components to register configuration for suggestions

Applied to files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:08.247Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-11-26T15:01:08.247Z
Learning: For building a simple Copilot, start with the copilot-chat-with-your-data example, use react-core for basic integration, and add react-ui for pre-built components

Applied to files:

  • CopilotKit/packages/react-ui/src/components/chat/Chat.tsx
  • CopilotKit/packages/react-core/src/hooks/index.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Implement streaming validation for suggestions to handle partial data gracefully during AI generation without console spam

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Implement clean cancellation of in-flight requests via abort controllers when new suggestion generation is initiated

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*{suggestions,Suggestions,Chat}*.{ts,tsx} : Handle empty states in suggestions - some configurations may not generate suggestions

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions*.{ts,tsx} : Ensure proper error handling for network/API errors without infinite retries in suggestions generation

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Automatically deduplicate suggestions based on message content to prevent duplicate suggestions from being shown

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
🧬 Code graph analysis (1)
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (1)
CopilotKit/packages/react-core/src/hooks/index.ts (2)
  • OnStopGeneration (13-13)
  • OnReloadMessages (12-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (30)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Build Images (coagents-qa-native, agent, js, local-deps)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-qa-text, agent, js, local-deps)
  • GitHub Check: Build Images (coagents-routing, agent, js, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, agent, js, local-deps)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: dojo / server-starter
  • GitHub Check: dojo / server-starter-all
  • GitHub Check: dojo / aws-strands
  • GitHub Check: dojo / crew-ai
  • GitHub Check: Test (18.x)
  • GitHub Check: dojo / mastra-agent-local
  • GitHub Check: dojo / pydantic-ai
  • GitHub Check: dojo / llama-index
  • GitHub Check: dojo / mastra
  • GitHub Check: dojo / agno
  • GitHub Check: Test (20.x)
  • GitHub Check: dojo / langgraph-typescript
  • GitHub Check: dojo / langgraph-fastapi
  • GitHub Check: dojo / a2a-middleware
  • GitHub Check: dojo / middleware-starter
  • GitHub Check: dojo / langgraph-python
  • GitHub Check: dojo / adk-middleware
🔇 Additional comments (8)
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (5)

43-64: Well-structured type definitions for the new callback APIs.

The type hierarchy is clean: OnReloadMessagesArguments properly extends OnStopGenerationArguments with the additional messageId field, avoiding duplication. The callback type aliases provide a clear contract for consumers.


111-116: Callback options properly typed and optional.

The new callback options are correctly typed and optional. The onSubmitMessage signature supporting both Promise<void> and void is appropriate for flexible usage patterns (sync analytics vs async operations).


433-445: Type safety improvements applied correctly.

The null guards (message.content &&) properly handle the case where content might be undefined, addressing the previous review concern. The dependency array correctly includes onSubmitMessage.


466-476: Previous review concerns addressed.

The implementation now correctly:

  1. Provides a default empty array (agent?.messages ?? []) ensuring Message[] type
  2. Includes onReloadMessages in the dependency array

478-484: Previous review concerns addressed.

Type safety is ensured with agent?.messages ?? [], and the dependency array [onStopGeneration, agent] correctly captures all referenced values. Using agent as a dependency is appropriate since multiple agent properties are accessed.

CopilotKit/packages/react-core/src/hooks/index.ts (1)

9-14: Public API exports correctly extended.

The new type exports OnReloadMessages and OnStopGeneration are properly added alongside existing exports, enabling consumers to type their callback handlers correctly.

CopilotKit/packages/react-ui/src/components/chat/Chat.tsx (2)

82-84: Good consolidation of types to public API.

Using the public types from @copilotkit/react-core instead of local definitions ensures type consistency across the codebase and gives consumers access to the same types.


568-574: Callbacks correctly wired to internal hook.

All four callbacks (onInProgress, onSubmitMessage, onStopGeneration, onReloadMessages) are properly threaded from props to useCopilotChatInternal.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (1)

112-115: Consider adding JSDoc documentation for the new callback props.

While the types are clear, adding JSDoc comments would help developers understand when each callback fires and what data is provided, especially given the complex lifecycle of message submission.

Example:

   suggestions?: ChatSuggestions;
 
+  /**
+   * Called when the loading state changes during message generation.
+   */
   onInProgress?: (isLoading: boolean) => void;
+  /**
+   * Called after a message is submitted and agent execution completes (if followUp is true).
+   * @param messageContent - The text content extracted from the submitted message
+   */
   onSubmitMessage?: (messageContent: string) => Promise<void> | void;
+  /**
+   * Called when generation is stopped by the user.
+   */
   onStopGeneration?: OnStopGeneration;
+  /**
+   * Called when a message regeneration is requested.
+   */
   onReloadMessages?: OnReloadMessages;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 226e45b and 570cc4c.

📒 Files selected for processing (2)
  • CopilotKit/.changeset/eleven-ties-grin.md (1 hunks)
  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (6 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CopilotKit/.changeset/eleven-ties-grin.md
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development-workflow.mdc)

Use ESLint configuration from CopilotKit/utilities/eslint-config-custom for consistent linting across the monorepo

Files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

**/*.{ts,tsx}: Use TypeScript for better type safety in React component development
Implement proper error handling in React components
Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components
Maintain consistent styling with Tailwind CSS in UI components
Implement responsive design in UI components
Use CopilotProvider at the root of the application to wrap all app components

**/*.{ts,tsx}: Use 'auto' mode (default) in CopilotChat suggestions prop to generate suggestions automatically at the start of chat and after every turn
Use 'manual' mode in CopilotChat suggestions prop only when you need full programmatic control via setSuggestions or generateSuggestions from useCopilotChat hook
Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system

Files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
**/*use-copilot-chat*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/suggestions-development.mdc)

Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts

Files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
🧠 Learnings (14)
📓 Common learnings
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-11-26T15:00:55.767Z
Learning: Applies to **/*.{ts,tsx} : Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*use-copilot-chat*.{ts,tsx} : Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Verify that useCopilotChatSuggestions hook is being called in components to register configuration for suggestions
📚 Learning: 2025-11-26T15:00:55.767Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/frontend-development.mdc:0-0
Timestamp: 2025-11-26T15:00:55.767Z
Learning: Applies to **/*.{ts,tsx} : Use CopilotKit provided hooks (useCopilotChat, useCopilotAction, useCopilotReadable) and utilities in React components

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*use-copilot-chat*.{ts,tsx} : Use effect dependencies properly to handle timing between configuration registration and suggestion generation without requiring timeouts

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Configure suggestions via useCopilotChatSuggestions hook to register configuration for auto-generation system

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Use 'manual' mode in CopilotChat suggestions prop only when you need full programmatic control via setSuggestions or generateSuggestions from useCopilotChat hook

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*.{ts,tsx} : Use 'auto' mode (default) in CopilotChat suggestions prop to generate suggestions automatically at the start of chat and after every turn

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Implement streaming validation for suggestions to handle partial data gracefully during AI generation without console spam

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Implement clean cancellation of in-flight requests via abort controllers when new suggestion generation is initiated

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*{suggestions,Suggestions,Chat}*.{ts,tsx} : Handle empty states in suggestions - some configurations may not generate suggestions

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions*.{ts,tsx} : Ensure proper error handling for network/API errors without infinite retries in suggestions generation

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/utils/suggestions.ts : Automatically deduplicate suggestions based on message content to prevent duplicate suggestions from being shown

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:08.247Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/quick-reference.mdc:0-0
Timestamp: 2025-11-26T15:01:08.247Z
Learning: Frontend applications should follow the pattern: Next.js app with CopilotProvider and CopilotChat component

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Applies to **/*{suggestions,Suggestions}*.{ts,tsx} : When working with suggestions in CopilotKit, load the Suggestions development guide

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
📚 Learning: 2025-11-26T15:01:32.104Z
Learnt from: CR
Repo: CopilotKit/CopilotKit PR: 0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-11-26T15:01:32.104Z
Learning: Verify that useCopilotChatSuggestions hook is being called in components to register configuration for suggestions

Applied to files:

  • CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts
🧬 Code graph analysis (1)
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (1)
CopilotKit/packages/react-core/src/hooks/index.ts (2)
  • OnStopGeneration (13-13)
  • OnReloadMessages (12-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: dojo / mastra-agent-local
  • GitHub Check: dojo / crew-ai
  • GitHub Check: dojo / langgraph-typescript
  • GitHub Check: dojo / aws-strands
  • GitHub Check: dojo / langgraph-fastapi
  • GitHub Check: dojo / mastra
  • GitHub Check: dojo / a2a-middleware
  • GitHub Check: dojo / agno
  • GitHub Check: dojo / pydantic-ai
  • GitHub Check: dojo / adk-middleware
  • GitHub Check: dojo / server-starter
  • GitHub Check: dojo / langgraph-python
  • GitHub Check: dojo / server-starter-all
  • GitHub Check: dojo / llama-index
  • GitHub Check: dojo / middleware-starter
  • GitHub Check: Test (18.x)
  • GitHub Check: Test (20.x)
🔇 Additional comments (4)
CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts (4)

43-64: LGTM! Well-structured callback type definitions.

The new callback interfaces are properly typed and well-documented. Good use of type extension for OnReloadMessagesArguments.


338-340: LGTM! Proper effect implementation for progress tracking.

The effect correctly watches agent?.isRunning and invokes the callback with a boolean value. Dependency array is complete.


470-480: LGTM! Proper callback invocation with complete dependencies.

The onReloadMessages callback correctly provides required context and uses agent?.messages ?? [] to ensure type safety. The dependency array is complete.


482-488: LGTM! Proper callback invocation before abort.

The onStopGeneration callback is correctly invoked before aborting, with type-safe message array and complete dependencies.

Comment on lines +437 to +447
if (onSubmitMessage) {
const content =
typeof message.content === "string"
? message.content
: message.content && "text" in message.content
? message.content.text
: message.content && "filename" in message.content
? message.content.filename
: "";
onSubmitMessage(content);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Inconsistent callback timing based on followUp option.

The onSubmitMessage callback fires at different times depending on the followUp option:

  • When followUp=false: immediately after addMessage (line 429)
  • When followUp=true: after runAgent completes (line 432)

This inconsistency could confuse consumers who expect deterministic timing. Consider one of these approaches:

  1. Always call before runAgent for predictable "on submit" semantics
  2. Rename to onMessageProcessed to reflect the current "after processing" behavior
  3. Document this behavior explicitly in JSDoc comments

Missing error handling for async onSubmitMessage.

Since onSubmitMessage can return a Promise<void>, it should be wrapped in error handling to prevent unhandled rejections:

       if (onSubmitMessage) {
         const content =
           typeof message.content === "string"
             ? message.content
             : message.content && "text" in message.content
               ? message.content.text
               : message.content && "filename" in message.content
                 ? message.content.filename
                 : "";
-        onSubmitMessage(content);
+        try {
+          await onSubmitMessage(content);
+        } catch (error) {
+          console.error("CopilotChat: onSubmitMessage callback failed", error);
+        }
       }
🤖 Prompt for AI Agents
In CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts around
lines 437 to 447, the onSubmitMessage callback is invoked at different times
depending on followUp which is inconsistent and it’s not error-handled; always
invoke onSubmitMessage immediately after addMessage (i.e., the same timing for
both followUp=true/false) by extracting the content as currently done and then
call onSubmitMessage(content) right after addMessage, await its result via
Promise.resolve to support sync/async handlers, and wrap the await in a
try/catch to handle/log errors to avoid unhandled rejections.

@github-actions

Copy link
Copy Markdown
Contributor

Previews

Commit SHA: 0462e7c

Name Preview
coagents-research-canvas Preview • Preview with LGC Python • Preview with LGC JS
coagents-routing Preview • Preview with LGC Python • Preview with LGC JS
coagents-qa-text Preview • Preview with LGC Python • Preview with LGC JS
coagents-qa-native Preview • Preview with LGC Python • Preview with LGC JS
next-openai Preview

@github-actions

github-actions Bot commented Dec 17, 2025 •

Copy link
Copy Markdown
Contributor

Test Results

Status: ❌ Failed (View Run)

Commit: 0462e7c

Duration: 1746.3s

Total Tests: 37

Pass Rate: 5.4%

Failed Tests: 35

❌ Failed Tests

🔍 Detailed Results

coagents-research-canvas

CoAgents Research Canvas (UI) - Local Depenencies

Model Browser Status Video
OpenAI chromium ❌ FAILED Video
Anthropic chromium ✅ PASSED -
CrewAI chromium ✅ PASSED -

coagents-qa-native

CoAgents QA Native (UI) - Local

Model Browser Status Video
OpenAI chromium ❌ FAILED Video
Anthropic chromium ❌ FAILED Video

coagents-qa-text

CoAgents QA Text (UI) - Local

Model Browser Status Video
OpenAI chromium ❌ FAILED Video
Anthropic chromium ❌ FAILED Video
OpenAI (LGC Python) chromium ❌ FAILED Video
Anthropic (LGC Python) chromium ❌ FAILED Video
OpenAI (LGC JS) chromium ❌ FAILED Video
Anthropic (LGC JS) chromium ❌ FAILED Video

coagents-routing

CoAgents Routing (UI) - Local

Model Browser Status Video
OpenAI chromium ❌ FAILED Video
Anthropic chromium ❌ FAILED Video

next-openai

Next OpenAI - Self Hosted

Model Browser Status Video
OpenAI chromium ❌ FAILED Video, Video, Video, Video, Video, Video
Anthropic chromium ❌ FAILED Video, Video, Video, Video, Video, Video
LangChain (OpenAI) chromium ❌ FAILED Video, Video, Video, Video, Video, Video
Groq chromium ❌ FAILED Video, Video, Video, Video, Video, Video

@changesets-bot-copilotkit

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 11a5573

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@copilotkit/react-core Patch
@copilotkit/react-ui Patch
@copilotkit/react-textarea Patch
@copilotkit/a2ui-renderer Patch
@copilotkit/runtime-client-gql Patch
@copilotkit/runtime Patch
@copilotkit/sdk-js Patch
@copilotkit/shared Patch

Click here if you're a maintainer who wants to add another changeset to this PR

BenTaylorDev added a commit that referenced this pull request Jul 25, 2026
…e dispatch (#5360)

## Summary

In multi-turn conversations using the Anthropic adapter, a model turn
that contains both assistant text and a tool call can be replayed as two
consecutive `{role: "assistant"}` entries in the Anthropic payload.
Anthropic expects one message object per turn with alternating roles, so
that split payload can blur turn boundaries on the next request. This PR
coalesces same-role Anthropic messages before dispatch so one assistant
turn stays one assistant message.

## Root cause


[`convertMessageToAnthropicMessage`](https://github.com/CopilotKit/CopilotKit/blob/005aebbededbfdd7978b3c1ee221580b74dd088d/packages/runtime/src/service-adapters/anthropic/utils.ts#L142-L219)
maps each CopilotKit message independently. A mixed assistant turn, a
`TextMessage(role=assistant)` followed by an `ActionExecutionMessage`,
therefore becomes two separate assistant entries. The Anthropic Messages
API requires all content blocks for one assistant turn to be sent in a
single message object: https://docs.anthropic.com/en/api/messages


[`AnthropicAdapter.process()`](https://github.com/CopilotKit/CopilotKit/blob/005aebbededbfdd7978b3c1ee221580b74dd088d/packages/runtime/src/service-adapters/anthropic/anthropic-adapter.ts#L282-L366)
already deduplicates `tool_result` blocks on the user side, but it
previously forwarded the mapped assistant-side payload without a
coalescing pass. Rebasing onto current `main` also exposed test-fixture
drift in the two new regression tests, so the final branch updates those
fixtures to the current object-form `TextMessage` constructor and
removes one stale `ActionInput` field while keeping the production fix
unchanged.

## Changes

- `packages/runtime/src/service-adapters/anthropic/utils.ts`: add
`coalesceConsecutiveSameRoleMessages(messages)` to merge adjacent
equal-role
  Anthropic messages by concatenating their `content` arrays.
-
`packages/runtime/src/service-adapters/anthropic/anthropic-adapter.ts`:
call
`coalesceConsecutiveSameRoleMessages` before
`limitMessagesToTokenCount`.
-
`packages/runtime/tests/service-adapters/anthropic/anthropic-adapter.test.ts`:
add same-role regression coverage, align the new fixtures with the
current
object-form `TextMessage` constructor, and remove the stale `parameters`
field
  from the action fixture.
- `.changeset/coalesce-anthropic-same-role-messages.md`: patch changeset
for
  `@copilotkit/runtime`.

## Scope

The `tool_result` allowlist deduplication stays unchanged. Token
trimming and the orphan-removal post-processor still run after
coalescing, so `tool_use` and `tool_result` pairing remains intact. The
OpenAI, Google, LangChain, and Groq adapters are unaffected.

The reported regression and the explicit regression coverage are
assistant-side. The coalescing helper itself is role-agnostic for
adjacent equal-role array content, but this PR does not add a separate
user-side regression case.

## Related PRs and Issues

Prior attempted fix: #2864, which addressed unrelated message callbacks
rather than the adapter payload.

## Test plan

- [x] `pnpm -C packages/runtime exec vitest run
tests/service-adapters/anthropic/anthropic-adapter.test.ts`
  10/10 tests pass, including the two same-role coalescing cases.
- [x] `pnpm -C packages/runtime exec vitest run
tests/service-adapters/anthropic/utils-token-trimming.test.ts`
  9/9 tests pass.
- [ ] CI green (`static / quality`, `test / unit` on Node 20/22/24)

## Upstream

Closes #2910.
Reported by @alonronin.

This branch was successfully deployed

3 active deployments
Preview – examples-coagents-research-canvas-ui — 11a55734 Deployed Dec 17, 2025 by vercel[bot]
Preview – docs — 11a55734 Deployed Dec 17, 2025 by vercel[bot]
Preview – examples-coagents-ai-travel-app — 11a55734 Deployed Dec 17, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant