Skip to content

feat: support request abort#4

Merged
hexqi merged 2 commits intodevelopfrom
feat/request-abort
Apr 11, 2025
Merged

feat: support request abort#4
hexqi merged 2 commits intodevelopfrom
feat/request-abort

Conversation

@hexqi
Copy link
Copy Markdown
Contributor

@hexqi hexqi commented Apr 9, 2025

Summary by CodeRabbit

  • New Features

    • Enabled cancellation of ongoing streaming chat responses, giving users more control during long operations.
    • Introduced a new “Stop” button in the chat interface that appears during active responses for immediate cancellation.
  • Style

    • Enhanced the visual design of the cancellation button with a distinct red color for clear identification.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2025

Walkthrough

The pull request introduces support for aborting long-running streaming chat requests using an AbortController. Changes span across multiple modules, including the core chat stream flow in the OpenAI provider and SSE stream handling, as well as UI modifications in the TinyRobot demo component to allow manual cancellation. Documentation and type declarations have been updated accordingly to accommodate an optional abort signal for enhanced control flow and error handling.

Changes

File(s) Change Summary
packages/ai-adapter/README.md Updated documentation describing the new abort functionality in the chat stream process.
packages/ai-adapter/src/providers/openai.ts,
packages/ai-adapter/src/types.ts,
packages/ai-adapter/src/utils.ts
Integrated abort signal handling in the chat stream process by destructuring the signal from request options, updating type definitions, and modifying SSE stream logic to support cancellation.
packages/demo/src/views/tinyrobot/TinyRobotDemo.vue Added a UI abort button and updated response methods to accept an AbortSignal. Introduced state management and a new handleAbort function for cancelling ongoing requests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as TinyRobotDemo.vue
    participant Provider as OpenAIProvider
    participant Utils as handleSSEStream
    participant Server as Fetch Request

    User->>UI: Click "Send Message"
    UI->>UI: Create AbortController
    UI->>Provider: Call chatStream(signal)
    Provider->>Server: Initiate fetch with signal
    Server-->>Provider: Stream response or await abort
    Provider->>Utils: Call handleSSEStream(response, handler, signal)
    alt User clicks "Abort" button
        User->>UI: Trigger handleAbort()
        UI->>AbortController: Execute abort()
        AbortController->>Server: Propagate abort signal
        Server-->>Provider: Return abort error
    end
    Provider->>UI: Return processed result or error
Loading

Possibly related PRs

Poem

I'm a rabbit coding with delight,
Hopping through streams both day and night.
With bursts of code that can now abort,
I nibble bugs away, a happy cohort.
Leaping in fields of logic so bright,
Carrot-powered fixes make my heart take flight!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/ai-adapter/src/providers/openai.ts

Oops! Something went wrong! :(

ESLint: 9.24.0

Error: The 'jiti' library is required for loading TypeScript configuration files. Make sure to install it.
at /node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:144:9
at async loadTypeScriptConfigFileWithJiti (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:143:25)
at async loadConfigFile (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:261:11)
at async ConfigLoader.calculateConfigArray (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:584:23)
at async #calculateConfigArray (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:765:23)
at async /node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/eslint/eslint.js:746:6
at async Promise.all (index 0)
at async ESLint.lintFiles (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/eslint/eslint.js:743:19)
at async Object.execute (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/cli.js:638:14)
at async main (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/bin/eslint.js:160:19)

packages/demo/src/views/tinyrobot/TinyRobotDemo.vue

Oops! Something went wrong! :(

ESLint: 9.24.0

Error: The 'jiti' library is required for loading TypeScript configuration files. Make sure to install it.
at /node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:144:9
at async loadTypeScriptConfigFileWithJiti (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:143:25)
at async loadConfigFile (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:261:11)
at async ConfigLoader.calculateConfigArray (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:584:23)
at async #calculateConfigArray (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:765:23)
at async /node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/eslint/eslint.js:746:6
at async Promise.all (index 0)
at async ESLint.lintFiles (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/eslint/eslint.js:743:19)
at async Object.execute (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/cli.js:638:14)
at async main (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/bin/eslint.js:160:19)

packages/ai-adapter/src/utils.ts

Oops! Something went wrong! :(

ESLint: 9.24.0

Error: The 'jiti' library is required for loading TypeScript configuration files. Make sure to install it.
at /node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:144:9
at async loadTypeScriptConfigFileWithJiti (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:143:25)
at async loadConfigFile (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:261:11)
at async ConfigLoader.calculateConfigArray (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:584:23)
at async #calculateConfigArray (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/config/config-loader.js:765:23)
at async /node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/eslint/eslint.js:746:6
at async Promise.all (index 0)
at async ESLint.lintFiles (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/eslint/eslint.js:743:19)
at async Object.execute (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/lib/cli.js:638:14)
at async main (/node_modules/.pnpm/eslint@9.24.0/node_modules/eslint/bin/eslint.js:160:19)

  • 1 others

Warning

Review ran into problems

🔥 Problems

GitHub Actions and Pipeline Checks: Resource not accessible by integration - https://docs.github.com/rest/actions/workflow-runs#list-workflow-runs-for-a-repository.

Please grant the required permissions to the CodeRabbit GitHub App under the organization or repository settings.


📜 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 430ab85 and 390095e.

📒 Files selected for processing (5)
  • packages/ai-adapter/README.md (2 hunks)
  • packages/ai-adapter/src/providers/openai.ts (2 hunks)
  • packages/ai-adapter/src/types.ts (1 hunks)
  • packages/ai-adapter/src/utils.ts (2 hunks)
  • packages/demo/src/views/tinyrobot/TinyRobotDemo.vue (7 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@hexqi hexqi force-pushed the feat/request-abort branch from a5d0a18 to 390095e Compare April 10, 2025 01:08
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.

2 participants