Skip to content

feat(core): support render stream objects in front-end components #12842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: feat/ai-stream-objects
Choose a base branch
from

Conversation

akumatus
Copy link
Member

@akumatus akumatus commented Jun 17, 2025

Close AI-194

截屏2025-06-17 17 16 08

Summary by CodeRabbit

  • New Features

    • Added support for streaming and displaying structured AI chat responses as "stream objects" (including text deltas, reasoning, tool calls, and tool results) across backend, API, and frontend.
    • Chat messages now include a new field for stream objects, visible in chat panels and GraphQL APIs.
    • Enhanced chat UI to render and style different types of stream objects for richer, incremental feedback.
  • Bug Fixes

    • Improved handling of streamed chat responses, ensuring proper fallback to plain text if structured data is invalid.
  • Refactor

    • Centralized and modularized backend logic for chat session preparation and streaming.
    • Refactored chat UI code for clearer handling of message content and stream objects.
  • Tests

    • Added tests for streaming object responses and validation of structured AI outputs.
  • Chores

    • Updated GraphQL schema and queries to support the new stream objects in chat message histories.

@akumatus akumatus requested a review from a team as a code owner June 17, 2025 09:16
Copy link

coderabbitai bot commented Jun 17, 2025

Important

Review skipped

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

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

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

"""

Walkthrough

This change introduces comprehensive support for streaming structured objects ("stream objects") in AI chat sessions. It spans backend schema, provider, and controller updates, GraphQL schema and queries, frontend message handling, rendering, and utilities. The implementation includes new streaming endpoints, parsing/merging logic, and test coverage for stream objects throughout the stack.

Changes

Files/Groups Change Summary
packages/backend/server/migrations/.../migration.sql, schema.prisma Add streamObjects JSON column/field to ai_sessions_messages table/model.
src/plugins/copilot/providers/types.ts, ai-chat-messages/type.ts Define StreamObjectSchema, StreamObject type, and extend schemas for stream objects (backend and frontend).
src/plugins/copilot/providers/provider.ts Add abstract streamObject method to provider interface.
src/plugins/copilot/providers/openai.ts, anthropic/anthropic.ts, gemini/gemini.ts, mocks/copilot.mock.ts Implement streamObject method for OpenAI, Anthropic, Gemini, and mock providers.
src/plugins/copilot/providers/anthropic/official.ts, anthropic/vertex.ts, gemini/generative.ts, gemini/vertex.ts, openai.ts Update provider model capability declarations to include ModelOutputType.Object.
src/plugins/copilot/providers/utils.ts Add StreamObjectParser and error handling utility for streaming.
src/plugins/copilot/controller.ts Refactor session preparation, add chatStreamObject SSE endpoint, handle stream object persistence.
src/plugins/copilot/session.ts Persist and retrieve streamObjects in session message storage and queries.
src/plugins/copilot/resolver.ts, schema.gql, common/graphql/src/schema.ts, copilot-history-list.gql, index.ts Extend GraphQL schema/types/queries to support streamObjects in messages.
src/__tests__/copilot-provider.spec.ts, copilot.e2e.ts, mocks/copilot.mock.ts, utils/copilot.ts Add/extend tests for streaming object functionality and validation.
frontend/core/src/blocksuite/ai/chat-panel/chat-panel-messages.ts, ai-chat-input/ai-chat-input.ts, peek-view/chat-block-peek-view.ts Update streaming message handling to parse, validate, and merge stream objects.
chat-panel/message/assistant.ts Refactor message rendering to support and style stream objects.
ai/provider/request.ts Adjust streaming argument to use 'stream-object' when not in workflow mode.
ai/utils/stream-objects.ts Add mergeStreamObjects utility for merging consecutive stream object chunks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant Provider

    User->>Frontend: Sends chat message
    Frontend->>Backend: POST /chatStreamObject (SSE)
    Backend->>Provider: provider.streamObject(...)
    loop Streaming
        Provider-->>Backend: yield StreamObject
        Backend-->>Frontend: SSE event with StreamObject[]
        Frontend->>Frontend: Parse/Merge StreamObject(s)
    end
    Frontend->>User: Render message with streamObjects
Loading

Assessment against linked issues

Objective (Issue) Addressed Explanation
Frontend supports rendering stream objects (AI-194)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested reviewers

  • akumatus

Poem

In the meadow of code, a new stream flows,
With objects that chatter as each message grows.
From backend to frontend, the rabbits all cheer,
For structured replies now magically appear!
Hop, merge, and render—what a clever delight,
Stream objects are hopping into view tonight! 🐇✨
"""


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added app:server test Related to test cases app:core labels Jun 17, 2025
@akumatus akumatus changed the title Feat/ai render objects feat(core): support render stream objects in front-end components Jun 17, 2025
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

Attention: Patch coverage is 63.25088% with 208 lines in your changes missing coverage. Please review.

Project coverage is 55.62%. Comparing base (899ffd1) to head (9a633b9).
Report is 1 commits behind head on feat/ai-stream-objects.

Files with missing lines Patch % Lines
...end/server/src/plugins/copilot/providers/openai.ts 41.48% 55 Missing ⚠️
...c/plugins/copilot/providers/anthropic/anthropic.ts 17.74% 51 Missing ⚠️
...ver/src/plugins/copilot/providers/gemini/gemini.ts 17.74% 51 Missing ⚠️
...kend/server/src/plugins/copilot/providers/utils.ts 60.00% 28 Missing ⚠️
...s/backend/server/src/plugins/copilot/controller.ts 91.85% 11 Missing ⚠️
...d/server/src/plugins/copilot/providers/provider.ts 25.00% 9 Missing ⚠️
...backend/server/src/__tests__/mocks/copilot.mock.ts 91.66% 3 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##           feat/ai-stream-objects   #12842      +/-   ##
==========================================================
- Coverage                   55.93%   55.62%   -0.32%     
==========================================================
  Files                        2658     2658              
  Lines                      125982   126408     +426     
  Branches                    20031    19986      -45     
==========================================================
- Hits                        70474    70320     -154     
- Misses                      53172    53748     +576     
- Partials                     2336     2340       +4     
Flag Coverage Δ
server-test 78.76% <63.25%> (-0.92%) ⬇️
unittest 31.67% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@akumatus akumatus force-pushed the feat/ai-render-objects branch from 46adb53 to 8ca5f1b Compare June 17, 2025 09:24
@akumatus akumatus changed the base branch from canary to feat/ai-stream-objects June 17, 2025 09:27
@akumatus akumatus force-pushed the feat/ai-stream-objects branch 2 times, most recently from 37f9b85 to 3e1de13 Compare June 17, 2025 12:48
@akumatus akumatus force-pushed the feat/ai-render-objects branch from 8ca5f1b to 776ca0a Compare June 17, 2025 12:51
@akumatus akumatus force-pushed the feat/ai-stream-objects branch from 3e1de13 to 28bfa95 Compare June 18, 2025 08:39
@akumatus akumatus force-pushed the feat/ai-render-objects branch from 776ca0a to bda09c6 Compare June 18, 2025 08:41
@akumatus akumatus force-pushed the feat/ai-stream-objects branch from 28bfa95 to 1bc9e60 Compare June 18, 2025 09:16
@akumatus akumatus force-pushed the feat/ai-render-objects branch from bda09c6 to 9a633b9 Compare June 18, 2025 09:16
@akumatus akumatus force-pushed the feat/ai-stream-objects branch from 1bc9e60 to ccb026b Compare June 18, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app:core app:server test Related to test cases
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant