Skip to content

Conversation

gene9831
Copy link
Collaborator

@gene9831 gene9831 commented Sep 19, 2025

and message sending logic

  • Added onLoaded callback to handle conversation loading events in useConversation.
  • Improved sendMessage function to create a conversation if none exists before sending a message.
  • Updated Assistant demo to log loaded conversations for better debugging.

Summary by CodeRabbit

  • New Features

    • Added onLoaded event for conversations, triggered after conversations finish loading.
    • Sending a message now auto-creates a conversation if none is active.
  • Documentation

    • Updated conversation docs to include the onLoaded event and revised API signatures.
    • Clarified metadata typings and example usage in guides.
  • Refactor

    • Strengthened public metadata types from Record<string, any> to Record<string, unknown> for safer typing.
    • Unified event handling in the conversation API to consistently forward callbacks.

… sending logic

- Added onLoaded callback to handle conversation loading events in useConversation.
- Improved sendMessage function to create a conversation if none exists before sending a message.
- Updated Assistant demo to log loaded conversations for better debugging.
Copy link

coderabbitai bot commented Sep 19, 2025

Walkthrough

Introduced UseConversationEvents with optional onLoaded callback, updated UseConversationOptions signatures, and invoked onLoaded once after conversations load. Adjusted metadata types to Record<string, unknown>. In Assistant.vue, added onLoaded handler and wrapped sendMessage to auto-create a conversation when none exists.

Changes

Cohort / File(s) Summary
Vue hook API and behavior
packages/kit/src/vue/conversation/useConversation.ts
Added UseConversationEvents extending message events with onLoaded(conversations). Updated UseConversationOptions.events type. Ensured onLoaded is called once after conversations load/selection. Forwarded onReceiveData/onFinish from events.
Documentation updates
docs/src/tools/conversation.md
Documented UseConversationEvents and onLoaded. Changed events type to UseConversationEvents. Updated metadata types to Record<string, unknown> for createConversation, updateMetadata, and Conversation.metadata.
Demo component adjustments
docs/demos/examples/Assistant.vue
Added events.onLoaded logging. Aliased internal sendMessage to _sendMessage and introduced wrapper to create a conversation if none exists before sending. No change to onReceiveData behavior.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Assistant.vue as Assistant.vue
  participant useConversation as useConversation()
  participant Manager as MessageManager
  participant Store as Conversations Store

  Note over Assistant.vue,Store: Initialization & Load
  Assistant.vue->>useConversation: init with events { onLoaded, onReceiveData, onFinish }
  useConversation->>Store: load conversations
  Store-->>useConversation: conversations[]
  rect rgba(230,245,255,0.6)
    Note right of useConversation: New behavior
    useConversation-->>Assistant.vue: events.onLoaded(conversations) [once]
  end

  Note over User,Assistant.vue: Sending a message
  User->>Assistant.vue: sendMessage(text)
  alt No active conversation
    rect rgba(235,255,235,0.6)
      Note right of Assistant.vue: New wrapper
      Assistant.vue->>useConversation: createConversation()
      useConversation->>Store: create(title?, metadata?)
      Store-->>useConversation: id
      useConversation-->>Assistant.vue: id
    end
  end
  Assistant.vue->>Manager: _sendMessage(text, ...args)
  Manager-->>useConversation: onReceiveData(...)
  useConversation-->>Assistant.vue: events.onReceiveData(...)
  Manager-->>useConversation: onFinish(...)
  useConversation-->>Assistant.vue: events.onFinish(...)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A nibble of types, a hop through the store,
onLoaded now whispers when chats hit the floor.
If no thread exists, I stitch one anew,
then boop the manager—messages through!
With unknowns for metadata, tidy and bright,
I thump in approval—ship it tonight. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change—adding an onLoaded callback to enhance conversation loading in useConversation—and is concise, clear, and directly related to the changes described in the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2161536 and 94b0e2b.

📒 Files selected for processing (3)
  • docs/demos/examples/Assistant.vue (1 hunks)
  • docs/src/tools/conversation.md (3 hunks)
  • packages/kit/src/vue/conversation/useConversation.ts (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/kit/src/vue/conversation/useConversation.ts (1)
packages/kit/src/vue/message/useMessage.ts (2)
  • UseMessageOptions (33-51)
  • useMessage (85-305)
⏰ 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). (1)
  • GitHub Check: e2e-tests
🔇 Additional comments (9)
packages/kit/src/vue/conversation/useConversation.ts (4)

80-82: LGTM! Well-designed event extension.

The new UseConversationEvents type cleanly extends the existing UseMessageOptions['events'] with an optional onLoaded callback, maintaining backward compatibility while adding the new functionality.


164-165: Good practice using a guard flag.

Using hasTriggeredOnLoaded ensures the callback is invoked only once, preventing duplicate notifications even if loadConversations is called multiple times.


173-176: Clean event forwarding implementation.

The implementation correctly forwards the message-level events (onReceiveData and onFinish) while reserving onLoaded for conversation-level handling.


319-323: Well-placed callback invocation with proper guard.

The onLoaded callback is triggered at the right moment - after conversations are loaded and the first one is selected (if applicable). The guard ensures it runs only once.

docs/demos/examples/Assistant.vue (2)

451-453: LGTM! Useful debugging callback.

The onLoaded callback provides a clean way to log loaded conversations for debugging purposes.


457-464: Smart wrapper to ensure conversation exists before sending.

The wrapper function elegantly handles the edge case where a user tries to send a message without an active conversation. This improves the user experience by automatically creating a conversation when needed.

docs/src/tools/conversation.md (3)

30-32: Documentation correctly reflects the API change.

The documentation properly shows the updated events property type using UseConversationEvents.


35-42: Clear documentation of the new event type.

The new UseConversationEvents type is well-documented with a clear description of the onLoaded callback purpose.


53-53: Good type safety improvement with Record<string, unknown>.

The change from Record<string, any> to Record<string, unknown> improves type safety by requiring explicit type checking when accessing metadata properties.

Also applies to: 61-61, 100-100

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

@hexqi hexqi merged commit ea0fdc2 into opentiny:develop Sep 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants