Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Nov 24, 2025

Summary

This PR adds streaming support for native tool calls (OpenAI-style function calling) in both the Roo Code Cloud (roo.ts) and OpenRouter providers. This allows the UI to show tool parameters as they stream in, providing the same experience as XML tools during LLM streaming.

Changes

API Layer

  • Added tool_call_start, tool_call_delta, and tool_call_end events to ApiStreamChunk type in src/api/transform/stream.ts
  • Implemented streaming tool call tracking in src/api/providers/roo.ts
  • Implemented streaming tool call tracking in src/api/providers/openrouter.ts

Tool Call Parsing

  • Added NativeToolCallParser.startStreamingToolCall() to initialize streaming state
  • Added NativeToolCallParser.processStreamingChunk() for incremental JSON parsing using partial-json-parser
  • Added NativeToolCallParser.finalizeStreamingToolCall() to complete tool call processing
  • Added createPartialToolUse() helper to build partial ToolUse objects from incomplete JSON

Task Processing

  • Updated Task.ts to handle the new streaming tool call events
  • Calls tool.handlePartial() on each delta to update the UI

Tool Infrastructure

  • Updated BaseTool.ts to properly handle partial native tool calls
  • Added partial-json package dependency for parsing incomplete JSON

How It Works

  1. When the API streams a tool call, it yields:

    • tool_call_start: Tool name and ID (when available)
    • tool_call_delta: Incremental JSON argument chunks
    • tool_call_end: Signals completion
  2. Task.ts receives these events and:

    • Starts tracking the tool call on tool_call_start
    • Uses partial-json-parser to extract partial values from incomplete JSON on each delta
    • Creates partial ToolUse objects and calls tool.handlePartial() for UI updates
    • Finalizes the tool call on tool_call_end
  3. Individual tools can override handlePartial() to show streaming UI (e.g., showing file content as it streams)

Testing

  • Updated roo.spec.ts with tests for the new streaming events
  • All existing tests pass

Important

Adds streaming support for native tool calls, enhancing real-time UI updates in roo.ts and openrouter.ts.

  • Behavior:
    • Adds streaming support for native tool calls in roo.ts and openrouter.ts.
    • Introduces tool_call_start, tool_call_delta, and tool_call_end events in stream.ts.
    • Updates Task.ts to handle new streaming events and update UI.
  • Tool Call Parsing:
    • Implements NativeToolCallParser with methods for streaming tool call processing.
    • Uses partial-json-parser for incremental JSON parsing.
  • Testing:
    • Updates roo.spec.ts with tests for streaming events.
    • Ensures all existing tests pass.

This description was created by Ellipsis for 5a5ff93. You can customize this summary. It will automatically update as commits are pushed.

This adds streaming support for native tool calls (OpenAI-style function calling)
in both the Roo Code Cloud (roo.ts) and OpenRouter providers.

Changes:
- Add tool_call_start, tool_call_delta, and tool_call_end events to ApiStreamChunk
- Implement streaming tool call tracking in roo.ts and openrouter.ts providers
- Add NativeToolCallParser.processStreamingChunk() for incremental JSON parsing
- Add NativeToolCallParser.startStreamingToolCall() and finalizeStreamingToolCall()
- Use partial-json-parser to extract partial values from incomplete JSON
- Handle streaming tool calls in Task.ts by calling tool.handlePartial()
- Update BaseTool to handle partial native tool calls

The streaming implementation allows the UI to show tool parameters as they
stream in, providing the same experience as XML tools during LLM streaming.
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. Enhancement New feature or request labels Nov 24, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 24, 2025

Rooviewer Clock   See task on Roo Cloud

Re-reviewed commit 5a5ff93. This commit completes the refactoring to emit raw tool call chunks from providers, moving all state management into NativeToolCallParser. All previous review issues remain resolved. The implementation is sound with proper cleanup and no memory leaks.

✅ All issues from previous reviews are resolved
✅ No new issues found in this iteration

Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 24, 2025
- Add clearAllStreamingToolCalls() to prevent memory leak when streams are interrupted
- Add hasActiveStreamingToolCalls() for debugging/testing
- Add comment clarifying the intentional difference between partial and complete
  validation logic for insert_content (partial uses OR to show progress incrementally)
- Call clearAllStreamingToolCalls() in Task.ts when resetting streaming state
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Nov 24, 2025
@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 24, 2025
The providers now yield tool_call_partial chunks during streaming, and
the NativeToolCallParser is responsible for reassembling them into
complete tool_call chunks. Updated tests to match this new behavior.
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Nov 25, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 26, 2025
* feat: add Google Tag Manager to marketing website (RooCodeInc#9148)

* feat: add Google Tag Manager to marketing website using Next.js Script component

* refactor: remove Google Ads implementation in favor of Tag Manager

* fix: wrap GTM script in consent-checking client component for GDPR compliance

---------

Co-authored-by: Roo Code <[email protected]>

* IPC command for sending messages to the current task (RooCodeInc#9149)

* fix: prevent command_output ask from blocking in cloud/headless environments (RooCodeInc#9152)

* chore: add changeset for v3.31.1 (RooCodeInc#9153)

* Release: v1.85.0 (RooCodeInc#9155)

* Gate XML out when native tool protocol is ON (RooCodeInc#9107)

* Add native tool definitions (RooCodeInc#9156)

* feat: sync reviewer landing page copy - variant B to variant A (RooCodeInc#9158)

- Updated variant A content to match variant B messaging
- Both variants now show the same improved copy focused on catching meaningful bugs
- Emphasizes depth over token-saving and repository-aware analysis

Co-authored-by: Roo Code <[email protected]>

* feat: sync reviewer landing page copy - variant B to variant A (RooCodeInc#9158)

- Updated variant A content to match variant B messaging
- Both variants now show the same improved copy focused on catching meaningful bugs
- Emphasizes depth over token-saving and repository-aware analysis

Co-authored-by: Roo Code <[email protected]>

* Move auto-approval from `ChatView` to `Task` (RooCodeInc#9157)

* feat(i18n): add internationalization for unexpected API response error message

* fix(task): use consistent error message for API response failures and ensure message queue is never undefined

* test: update vscode mock and improve test coverage

* fix: Model switch re-applies selected profile (sync task.apiConfiguration) (RooCodeInc#9179) (RooCodeInc#9181)

* Add custom Button component with variant system (RooCodeInc#9150)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>

* Changeset version bump (RooCodeInc#9154)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat(core): detect API configuration changes for model switching

* fix: include mcpServers in getState() for auto-approval (