Repository navigation
fix: restore message callbacks - #2864
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
WalkthroughExports 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
UseCopilotChatOptionshave 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
📒 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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.tsCopilotKit/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.tsCopilotKit/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
OnReloadMessagesArgumentsprovides 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-corecorrectly use thetypekeyword and align with the newly exported public types.
568-574: LGTM!The callbacks are correctly wired from
CopilotChatPropsthrough touseCopilotChatInternal, enabling external observers to track chat lifecycle events.
351d19c to
226e45b
Compare
There was a problem hiding this comment.
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.tsor the internal hook).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 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.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.mdxCopilotKit/packages/react-ui/src/components/chat/Chat.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.mdxCopilotKit/packages/react-ui/src/components/chat/Chat.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.tsxCopilotKit/packages/react-core/src/hooks/index.tsCopilotKit/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.tsxCopilotKit/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:
OnReloadMessagesArgumentsproperly extendsOnStopGenerationArgumentswith the additionalmessageIdfield, 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
onSubmitMessagesignature supporting bothPromise<void>andvoidis 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 includesonSubmitMessage.
466-476: Previous review concerns addressed.The implementation now correctly:
- Provides a default empty array (
agent?.messages ?? []) ensuringMessage[]type- Includes
onReloadMessagesin 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. Usingagentas 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
OnReloadMessagesandOnStopGenerationare 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-coreinstead 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 touseCopilotChatInternal.
There was a problem hiding this comment.
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
📒 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?.isRunningand invokes the callback with a boolean value. Dependency array is complete.
470-480: LGTM! Proper callback invocation with complete dependencies.The
onReloadMessagescallback correctly provides required context and usesagent?.messages ?? []to ensure type safety. The dependency array is complete.
482-488: LGTM! Proper callback invocation before abort.The
onStopGenerationcallback is correctly invoked before aborting, with type-safe message array and complete dependencies.
| 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); | ||
| } |
There was a problem hiding this comment.
Inconsistent callback timing based on followUp option.
The onSubmitMessage callback fires at different times depending on the followUp option:
- When
followUp=false: immediately afteraddMessage(line 429) - When
followUp=true: afterrunAgentcompletes (line 432)
This inconsistency could confuse consumers who expect deterministic timing. Consider one of these approaches:
- Always call before
runAgentfor predictable "on submit" semantics - Rename to
onMessageProcessedto reflect the current "after processing" behavior - 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.
PreviewsCommit SHA: 0462e7c
|
Test ResultsStatus: ❌ Failed (View Run) Commit: 0462e7c Duration: 1746.3s Total Tests: 37 Pass Rate: 5.4% Failed Tests: 35 ❌ Failed Tests
🔍 Detailed Resultscoagents-research-canvasCoAgents Research Canvas (UI) - Local Depenencies
coagents-qa-nativeCoAgents QA Native (UI) - Local
coagents-qa-textCoAgents QA Text (UI) - Local
coagents-routingCoAgents Routing (UI) - Local
next-openaiNext OpenAI - Self Hosted
|
🦋 Changeset detectedLatest commit: 11a5573 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Click here if you're a maintainer who wants to add another changeset to this PR |
…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.
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.