Skip to content

Conversation

@Kitenite
Copy link
Contributor

@Kitenite Kitenite commented Oct 2, 2025

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes


Important

Refactor chat agent architecture to reduce overhead by unifying agents and simplifying tool handling.

  • Behavior:
    • Unified chat experience with a single smart agent for all chat modes.
    • Improved handling of long-running tool calls in stream.ts and route.ts.
  • Refactor:
    • Removed legacy agent types and deprecated tools in root.ts and toolset.ts.
    • Simplified tool handling by removing BaseAgent and UserAgent classes.
  • Dependencies:
    • Updated @ai-sdk/provider-utils and @ai-sdk/react versions in package.json.
    • Removed unused dependencies related to legacy agents.

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


Summary by CodeRabbit

  • New Features
    • More reliable tool calls with automatic input repair during chat streaming.
  • Improvements
    • Streamlined chat to a single path for faster, smoother responses.
    • Clearer tool error messages and consistent tool result reporting.
    • Updated token window to latest model limits.
    • Conversation create/update now returns the latest data immediately.
  • Bug Fixes
    • Consistent usage tracking for edit chats.
  • Chores
    • Upgraded AI SDKs and dependencies; consolidated to OpenRouter provider.
    • Removed Anthropic/Claude model options from settings.

@supabase
Copy link

supabase bot commented Oct 2, 2025

This pull request has been ignored for the connected project wowaemfasoptxrdjhilu because there are no changes detected in apps/backend/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@vercel
Copy link

vercel bot commented Oct 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
web Ready Ready Preview Comment Oct 3, 2025 0:06am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 3, 2025 0:06am

@coderabbitai
Copy link

coderabbitai bot commented Oct 2, 2025

Caution

Review failed

The pull request is closed.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Consolidates chat streaming to a single root-agent flow using createRootAgentStream, removes legacy agent/sub-agent architecture and related tools, updates tool handling APIs, drops Anthropic provider/models, adjusts enums and provider logic, refactors server conversation mutations, and bumps AI-related dependencies across packages.

Changes

Cohort / File(s) Summary
API route and helper
apps/web/client/src/app/api/chat/route.ts, apps/web/client/src/app/api/chat/helpers/stream.ts
Route now always uses createRootAgentStream; removes AgentType branching and schema validation; adjusts metadata and usage tracking; helper removes repairToolCall leaving only errorHandler.
Client chat/use and tools
apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx, apps/web/client/src/components/tools/tools.ts, apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/chat-context.tsx
Eliminates AgentType usage; updates handleToolCall signature and tool discovery to getToolClassesFromType; refines addToolResult shape; updates token model reference for context window.
Server conversation router
apps/web/client/src/server/api/routers/chat/conversation.ts
upsert now returns mapped conversation via returning(); update payload construction adjusted; returns mapped results consistently.
AI agents removal and exports
packages/ai/src/agents/classes/*, packages/ai/src/agents/models/*, packages/ai/src/agents/onlook-chat.ts, packages/ai/src/agents/streamer.ts, packages/ai/src/agents/tool-lookup.ts, packages/ai/src/agents/tools/*, packages/ai/src/agents/index.ts
Removes BaseAgent, RootAgent, UserAgent, AgentStreamer, sub-agent tools and lookup; drops related barrels; agents index now exports only from ./root.
AI tools typings and toolset
packages/ai/src/tools/models/client.ts, packages/ai/src/tools/toolset.ts, packages/ai/src/tools/index.ts, packages/ai/src/tools/toolset-utils.ts
ClientTool de-genericized; handle(input, editorEngine) returns Promise; removes OnToolCallHandler and createToolSet util; introduces readOnly/all tool classes, toolsets, TOOLS_MAP, and getters by ChatType; removes getAvailableTools and user tools re-export.
New root agent stream and providers
packages/ai/src/agents/root.ts, packages/ai/src/chat/providers.ts
Adds createRootAgentStream with system prompt/model selection by ChatType, telemetry, transforms, and repairToolCall; provider simplifies to OPENROUTER with conditional Anthropic cache flags; removes Anthropic creation path.
Model enums and limits
packages/models/src/llm/index.ts
Removes ANTHROPIC provider/models and related max token entries; removes CLAUDE_4_SONNET from OPENROUTER_MODELS and token limits.
Dependency updates
apps/web/client/package.json, packages/ai/package.json, packages/db/package.json, packages/models/package.json, packages/ui/package.json
Bumps ai and SDK/provider packages; removes several @AI-SDK providers; adds openai and other deps in packages/ai; updates versions across packages.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Web Client (useChat)
  participant API as /api/chat (route.ts)
  participant Root as createRootAgentStream
  participant Model as LLM (OpenRouter)
  participant Tools as Toolset
  Note over UI,API: UI sends messages, chatType, ids (no AgentType)
  User->>UI: Send message
  UI->>API: POST messages, chatType, conversationId, projectId
  API->>Root: createRootAgentStream(payload, metadata)
  Root->>Model: streamText(system, messages, tools, options)
  Model-->>Root: Stream parts (text/toolCall/finish)
  alt toolCall
    Root->>Tools: Find tool by name
    alt invalid tool input
      Root->>Root: repairToolCall(tool, toolCall)
      Root->>Model: Retry with repaired tool input
    end
    Tools-->>Root: Tool output
  end
  Root-->>API: UIMessage stream with metadata
  API-->>UI: Stream response
  UI-->>User: Render streaming output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

In streams I hop, with packets bright,
No agents split—one path feels right.
Tools align, their handles true,
If inputs break, I fix them too.
Models hum, the tokens sing—
A rootward waltz on rabbit spring. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “feat: reduce agent overhead” succinctly describes the primary change of refactoring and simplification of agent-related code to lower system overhead, clearly matching the main focus of the pull request. The title is concise and accurately reflects the core improvements; no changes needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. You can run `@coderabbitai generate docstrings` to improve docstring coverage.
Description Check ⚠️ Warning The pull request description only includes the template headings and placeholder comments without any substantive entries for Description, Related Issues, Type of Change, Testing, or Additional Notes, and none of the checklist boxes are checked. Please populate each section of the template with actual content: provide a concise Description of the changes, link any Related Issues, check the appropriate Type of Change box, describe your Testing steps, and add any Additional Notes or Screenshots as needed.

📜 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 530df00 and 5b5ff0a.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (19)
  • apps/web/client/package.json (1 hunks)
  • apps/web/client/src/app/api/chat/helpers/stream.ts (0 hunks)
  • apps/web/client/src/app/api/chat/route.ts (4 hunks)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/chat-context.tsx (1 hunks)
  • apps/web/client/src/components/tools/tools.ts (1 hunks)
  • apps/web/client/src/server/api/routers/chat/conversation.ts (2 hunks)
  • packages/ai/package.json (1 hunks)
  • packages/ai/src/agents/classes/index.ts (0 hunks)
  • packages/ai/src/agents/classes/root.ts (0 hunks)
  • packages/ai/src/agents/index.ts (1 hunks)
  • packages/ai/src/agents/models/base.ts (0 hunks)
  • packages/ai/src/agents/models/index.ts (0 hunks)
  • packages/ai/src/agents/root.ts (1 hunks)
  • packages/ai/src/agents/streamer.ts (0 hunks)
  • packages/ai/src/chat/providers.ts (2 hunks)
  • packages/db/package.json (1 hunks)
  • packages/models/package.json (1 hunks)
  • packages/models/src/llm/index.ts (0 hunks)
  • packages/ui/package.json (1 hunks)

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.

@Kitenite Kitenite marked this pull request as draft October 2, 2025 01:30
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/client/src/server/api/routers/chat/conversation.ts (1)

39-44: Restore real upsert semantics

This mutation now issues a raw insert with no conflict handling, so calling it for an existing conversation will trigger a duplicate-key error instead of updating the row as before. Please reinstate the conflict update (including refreshing updatedAt) to keep the API contract intact.

-            const [conversation] = await ctx.db.insert(conversations).values(input).returning();
+            const [conversation] = await ctx.db.insert(conversations)
+                .values(input)
+                .onConflictDoUpdate({
+                    target: conversations.id,
+                    set: {
+                        ...input,
+                        updatedAt: new Date(),
+                    },
+                })
+                .returning();
🧹 Nitpick comments (6)
packages/ai/src/agents/streamer.ts (3)

5-5: Remove unused import.

UIMessageStreamOnFinishCallback is imported but not used anywhere in this file.

Apply this diff to remove the unused import:

-import type { streamText, UIMessageStreamOnFinishCallback, UIMessageStreamOptions } from "ai";
+import type { streamText, UIMessageStreamOptions } from "ai";

28-29: Consider documenting empty context and checkpoints.

The context and checkpoints fields are hardcoded to empty arrays. If these are placeholders for future implementation or intentionally empty in this refactor, consider adding a brief comment to clarify intent.

Example:

                 return {
                     createdAt: new Date(),
                     conversationId,
+                    // TODO: Populate context and checkpoints when available
                     context: [],
                     checkpoints: [],
                     finishReason: part.type === 'finish-step' ? part.finishReason : undefined,
                     usage: part.type === 'finish-step' ? part.usage : undefined,
                 } satisfies ChatMetadata;

16-16: Remove unnecessary async/await from streamText. Since BaseAgent.streamText is synchronous, drop async on line 16 and remove await before this.agent.streamText on line 19.

packages/db/src/mappers/chat/conversation.ts (2)

4-10: Review spread operator usage in mapper.

The spread operator copies all properties from the DB conversation, which may include fields that shouldn't be in the model (or vice versa). While this works if DB and model schemas are aligned, it creates coupling and could cause issues if extra fields exist.

Consider being more explicit about which fields to map:

 export const fromDbConversation = (conversation: DbConversation): ChatConversation => {
     return {
-        ...conversation,
+        id: conversation.id,
+        projectId: conversation.projectId,
+        createdAt: conversation.createdAt,
+        updatedAt: conversation.updatedAt,
         title: conversation.displayName || null,
         suggestions: conversation.suggestions || [],
     }
 }

12-19: Review spread operator usage and redundant assignments.

Similar to fromDbConversation, the spread operator combined with explicit field assignments (lines 15-17) is redundant. The explicit assignments will override the spread values for those same keys.

Consider removing the spread or removing the redundant explicit assignments:

 export const toDbConversation = (conversation: ChatConversation): DbConversation => {
     return {
-        ...conversation,
+        id: conversation.id,
         projectId: conversation.projectId,
+        createdAt: conversation.createdAt,
+        updatedAt: conversation.updatedAt,
         displayName: conversation.title || null,
         suggestions: conversation.suggestions || [],
     }
 }
apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx (1)

56-60: Reset the tool-call flag even on failures

Line 58: if handleToolCall throws, the .then(...) never runs and isExecutingToolCall stays true, leaving the UI in a perpetual "running" state. Swap to .finally(...) so the flag always resets.

-                void handleToolCall(toolCall.toolCall, editorEngine, addToolResult).then(() => {
-                    setIsExecutingToolCall(false);
-                });
+                void handleToolCall(toolCall.toolCall, editorEngine, addToolResult).finally(() => {
+                    setIsExecutingToolCall(false);
+                });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53ec325 and 530df00.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (29)
  • apps/web/client/src/app/api/chat/helpers/stream.ts (2 hunks)
  • apps/web/client/src/app/api/chat/route.ts (4 hunks)
  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx (3 hunks)
  • apps/web/client/src/components/store/editor/chat/conversation.ts (0 hunks)
  • apps/web/client/src/components/tools/tools.ts (1 hunks)
  • apps/web/client/src/server/api/routers/chat/conversation.ts (3 hunks)
  • apps/web/client/src/server/api/routers/chat/suggestion.ts (1 hunks)
  • apps/web/client/src/server/api/routers/project/project.ts (1 hunks)
  • packages/ai/src/agents/classes/index.ts (1 hunks)
  • packages/ai/src/agents/classes/root.ts (2 hunks)
  • packages/ai/src/agents/classes/user.ts (0 hunks)
  • packages/ai/src/agents/index.ts (0 hunks)
  • packages/ai/src/agents/models/base.ts (2 hunks)
  • packages/ai/src/agents/onlook-chat.ts (0 hunks)
  • packages/ai/src/agents/streamer.ts (2 hunks)
  • packages/ai/src/agents/tool-lookup.ts (0 hunks)
  • packages/ai/src/agents/tools/base.ts (0 hunks)
  • packages/ai/src/agents/tools/index.ts (0 hunks)
  • packages/ai/src/agents/tools/user.ts (0 hunks)
  • packages/ai/src/chat/providers.ts (2 hunks)
  • packages/ai/src/tools/index.ts (1 hunks)
  • packages/ai/src/tools/models/client.ts (1 hunks)
  • packages/ai/src/tools/toolset-utils.ts (0 hunks)
  • packages/ai/src/tools/toolset.ts (1 hunks)
  • packages/db/src/defaults/conversation.ts (0 hunks)
  • packages/db/src/mappers/chat/conversation.ts (1 hunks)
  • packages/db/src/schema/chat/conversation.ts (2 hunks)
  • packages/models/src/chat/conversation/index.ts (0 hunks)
  • packages/models/src/chat/message/message.ts (0 hunks)
💤 Files with no reviewable changes (12)
  • packages/models/src/chat/message/message.ts
  • packages/ai/src/agents/index.ts
  • packages/models/src/chat/conversation/index.ts
  • packages/ai/src/agents/tools/user.ts
  • apps/web/client/src/components/store/editor/chat/conversation.ts
  • packages/ai/src/agents/tools/base.ts
  • packages/ai/src/tools/toolset-utils.ts
  • packages/ai/src/agents/classes/user.ts
  • packages/ai/src/agents/tools/index.ts
  • packages/ai/src/agents/onlook-chat.ts
  • packages/ai/src/agents/tool-lookup.ts
  • packages/db/src/defaults/conversation.ts
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Do not use the any type unless necessary

Files:

  • packages/ai/src/agents/classes/index.ts
  • packages/db/src/mappers/chat/conversation.ts
  • apps/web/client/src/server/api/routers/project/project.ts
  • packages/ai/src/agents/classes/root.ts
  • apps/web/client/src/server/api/routers/chat/conversation.ts
  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
  • apps/web/client/src/app/api/chat/helpers/stream.ts
  • packages/ai/src/chat/providers.ts
  • packages/ai/src/agents/streamer.ts
  • packages/ai/src/agents/models/base.ts
  • packages/db/src/schema/chat/conversation.ts
  • packages/ai/src/tools/index.ts
  • apps/web/client/src/components/tools/tools.ts
  • apps/web/client/src/server/api/routers/chat/suggestion.ts
  • apps/web/client/src/app/api/chat/route.ts
  • packages/ai/src/tools/toolset.ts
  • packages/ai/src/tools/models/client.ts
{apps,packages}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Avoid using the any type unless absolutely necessary

Files:

  • packages/ai/src/agents/classes/index.ts
  • packages/db/src/mappers/chat/conversation.ts
  • apps/web/client/src/server/api/routers/project/project.ts
  • packages/ai/src/agents/classes/root.ts
  • apps/web/client/src/server/api/routers/chat/conversation.ts
  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
  • apps/web/client/src/app/api/chat/helpers/stream.ts
  • packages/ai/src/chat/providers.ts
  • packages/ai/src/agents/streamer.ts
  • packages/ai/src/agents/models/base.ts
  • packages/db/src/schema/chat/conversation.ts
  • packages/ai/src/tools/index.ts
  • apps/web/client/src/components/tools/tools.ts
  • apps/web/client/src/server/api/routers/chat/suggestion.ts
  • apps/web/client/src/app/api/chat/route.ts
  • packages/ai/src/tools/toolset.ts
  • packages/ai/src/tools/models/client.ts
apps/web/client/src/server/api/routers/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/server/api/routers/**/*.ts: Place tRPC routers under apps/web/client/src/server/api/routers/**
Use publicProcedure/protectedProcedure from apps/web/client/src/server/api/trpc.ts and validate inputs with Zod
Return plain objects/arrays; rely on SuperJSON for serialization in tRPC procedures

apps/web/client/src/server/api/routers/**/*.ts: Place tRPC routers under src/server/api/routers/**
Use publicProcedure/protectedProcedure from src/server/api/trpc.ts and validate inputs with Zod
Return plain objects/arrays; rely on SuperJSON for serialization

Files:

  • apps/web/client/src/server/api/routers/project/project.ts
  • apps/web/client/src/server/api/routers/chat/conversation.ts
  • apps/web/client/src/server/api/routers/chat/suggestion.ts
apps/web/client/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/**/*.{ts,tsx}: Use path aliases @/* and ~/* for imports that map to apps/web/client/src/*
Avoid hardcoded user-facing text; use next-intl messages/hooks instead

Use path aliases @/* and ~/* for imports mapping to src/*

Files:

  • apps/web/client/src/server/api/routers/project/project.ts
  • apps/web/client/src/server/api/routers/chat/conversation.ts
  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
  • apps/web/client/src/app/api/chat/helpers/stream.ts
  • apps/web/client/src/components/tools/tools.ts
  • apps/web/client/src/server/api/routers/chat/suggestion.ts
  • apps/web/client/src/app/api/chat/route.ts
apps/web/client/src/app/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/app/**/*.tsx: Default to Server Components; add 'use client' when using events, state/effects, browser APIs, or client‑only libraries
Do not use process.env in client code; import env from @/env instead

Avoid hardcoded user-facing text; use next-intl messages/hooks

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
apps/web/client/src/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/**/*.tsx: Create MobX store instances with useState(() => new Store()) for stable references across renders
Keep the active MobX store in a useRef and perform async cleanup with setTimeout(() => storeRef.current?.clear(), 0) to avoid route-change races
Avoid useMemo for creating MobX store instances
Avoid putting the MobX store instance in effect dependency arrays if it causes loops; split concerns by domain

apps/web/client/src/**/*.tsx: Create MobX store instances with useState(() => new Store()) for stable identities across renders
Keep the active MobX store in a useRef and clean up asynchronously with setTimeout(() => storeRef.current?.clear(), 0)
Do not use useMemo to create MobX stores
Avoid placing MobX store instances in effect dependency arrays if it causes loops; split concerns instead
observer components must be client components; place a single client boundary at the feature entry; child observers need not repeat 'use client'

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
apps/web/client/src/app/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Default to Server Components; add 'use client' only when using events, state/effects, browser APIs, or client-only libs

Files:

  • apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx
  • apps/web/client/src/app/api/chat/helpers/stream.ts
  • apps/web/client/src/app/api/chat/route.ts
🧬 Code graph analysis (13)
apps/web/client/src/server/api/routers/project/project.ts (1)
packages/ai/src/chat/providers.ts (1)
  • initModel (14-51)
packages/ai/src/agents/classes/root.ts (3)
packages/models/src/llm/index.ts (1)
  • ModelConfig (35-40)
packages/ai/src/tools/toolset.ts (1)
  • getToolSetFromType (66-68)
packages/ai/src/chat/providers.ts (1)
  • initModel (14-51)
apps/web/client/src/server/api/routers/chat/conversation.ts (2)
packages/db/src/schema/chat/conversation.ts (1)
  • conversations (11-20)
packages/ai/src/chat/providers.ts (1)
  • initModel (14-51)
apps/web/client/src/app/project/[id]/_hooks/use-chat/index.tsx (1)
apps/web/client/src/components/tools/tools.ts (1)
  • handleToolCall (6-37)
apps/web/client/src/app/api/chat/helpers/stream.ts (4)
packages/ai/src/agents/classes/root.ts (2)
  • getModelFromType (38-54)
  • getSystemPromptFromType (21-31)
packages/models/src/llm/index.ts (1)
  • ModelConfig (35-40)
packages/ai/src/chat/providers.ts (1)
  • initModel (14-51)
packages/ai/src/prompt/provider.ts (3)
  • getCreatePageSystemPrompt (28-32)
  • getAskModeSystemPrompt (40-44)
  • getSystemPrompt (21-26)
packages/ai/src/chat/providers.ts (1)
packages/models/src/llm/index.ts (3)
  • InitialModelPayload (28-33)
  • ModelConfig (35-40)
  • MODEL_MAX_TOKENS (42-51)
packages/ai/src/agents/streamer.ts (3)
packages/models/src/chat/message/message.ts (1)
  • ChatMessage (18-18)
packages/ai/src/agents/models/base.ts (1)
  • streamText (30-51)
packages/ai/src/stream/index.ts (1)
  • convertToStreamMessages (5-23)
packages/ai/src/agents/models/base.ts (1)
packages/models/src/llm/index.ts (1)
  • ModelConfig (35-40)
apps/web/client/src/components/tools/tools.ts (2)
apps/web/client/src/components/store/editor/engine.ts (1)
  • EditorEngine (34-140)
packages/ai/src/tools/toolset.ts (1)
  • getToolClassesFromType (62-64)
apps/web/client/src/server/api/routers/chat/suggestion.ts (1)
packages/ai/src/chat/providers.ts (1)
  • initModel (14-51)
apps/web/client/src/app/api/chat/route.ts (3)
packages/models/src/chat/message/message.ts (1)
  • ChatMessage (18-18)
apps/web/client/src/app/api/chat/helpers/usage.ts (1)
  • incrementUsage (43-65)
packages/ai/src/agents/classes/root.ts (1)
  • RootAgent (5-55)
packages/ai/src/tools/toolset.ts (2)
packages/ai/src/tools/classes/list-files.ts (1)
  • ListFilesTool (8-144)
packages/ai/src/tools/classes/index.ts (19)
  • ListFilesTool (8-8)
  • ReadFileTool (10-10)
  • BashReadTool (2-2)
  • OnlookInstructionsTool (9-9)
  • ReadStyleGuideTool (11-11)
  • ListBranchesTool (7-7)
  • ScrapeUrlTool (13-13)
  • WebSearchTool (18-18)
  • GlobTool (5-5)
  • GrepTool (6-6)
  • TypecheckTool (17-17)
  • CheckErrorsTool (3-3)
  • SearchReplaceEditTool (14-14)
  • SearchReplaceMultiEditFileTool (15-15)
  • FuzzyEditFileTool (4-4)
  • WriteFileTool (19-19)
  • BashEditTool (1-1)
  • SandboxTool (12-12)
  • TerminalCommandTool (16-16)
packages/ai/src/tools/models/client.ts (1)
apps/web/client/src/components/store/editor/engine.ts (1)
  • EditorEngine (34-140)
🔇 Additional comments (8)
packages/db/src/schema/chat/conversation.ts (3)

1-1: LGTM: Type-only import is appropriate.

The change to a type-only import for ChatSuggestion is correct since it's only used as a type parameter in $type<ChatSuggestion[]>() on line 19.


22-25: Simplified insert schema and explicit UUID validation.

The insert schema now correctly relies solely on the table definition without custom field handling. The update schema's explicit id: z.string().uuid() ensures UUID validation at the API boundary, which is a good practice for update operations.


11-20: Verify migration for dropping agentType column

Automated search didn’t locate any SQL or TS migration that drops agent_type; please manually confirm a migration has been created and applied to remove this column in existing databases.

packages/ai/src/agents/classes/root.ts (5)

1-2: LGTM!

The import changes correctly support the refactored architecture: ModelConfig and initModel enable async model initialization, and getToolSetFromType replaces the removed tool lookups.


6-6: LGTM!

The id field provides a stable identifier for the root agent, which is useful for logging and debugging.


10-15: LGTM!

The constructor refactor correctly supports the factory pattern by accepting a pre-initialized modelConfig, avoiding async constructor issues and enabling cleaner initialization via RootAgent.create.


33-36: LGTM!

The static factory method correctly encapsulates async model initialization, following best practices for asynchronous construction patterns.


38-54: Validate availability of OPENROUTER_MODELS.OPEN_AI_GPT_5
Ensure "openai/gpt-5" is listed by OpenRouter’s Models API or live model browser, and implement a fallback if it’s unavailable.

Comment on lines 17 to 23
case ChatType.EDIT:
default:
model = await initModel({
provider: LLMProvider.OPENROUTER,
model: OPENROUTER_MODELS.CLAUDE_4_SONNET,
});
break;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Align ASK/EDIT model selection with RootAgent

Line [19] currently returns OPENROUTER_MODELS.CLAUDE_4_SONNET, but RootAgent.getModelFromType already moved ASK/EDIT over to CLAUDE_4_5_SONNET (see packages/ai/src/agents/classes/root.ts, Lines 37-53). Leaving this helper on the older model makes the API choose a different LLM than the agents, undermining the overhead refactor and producing inconsistent chat behaviour. Please switch this branch to OPENROUTER_MODELS.CLAUDE_4_5_SONNET so both paths stay in sync.

🤖 Prompt for AI Agents
In apps/web/client/src/app/api/chat/helpers/stream.ts around lines 17 to 23, the
ASK/EDIT branch currently selects OPENROUTER_MODELS.CLAUDE_4_SONNET which is out
of sync with RootAgent.getModelFromType; update this branch to use
OPENROUTER_MODELS.CLAUDE_4_5_SONNET so the helper and RootAgent choose the same
LLM, ensuring consistent chat behavior across paths.

Comment on lines +48 to +51
const [conversation] = await ctx.db.update({
...conversations,
updatedAt: new Date(),
}).set(input)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix Drizzle update call

Spreading the table into a plain object strips the symbols Drizzle needs, so this will throw at runtime (table name becomes undefined) and updatedAt is no longer refreshed. Stick with the table instance and set updatedAt inside .set(...).

-            const [conversation] = await ctx.db.update({
-                ...conversations,
-                updatedAt: new Date(),
-            }).set(input)
+            const [conversation] = await ctx.db.update(conversations)
+                .set({
+                    ...input,
+                    updatedAt: new Date(),
+                })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [conversation] = await ctx.db.update({
...conversations,
updatedAt: new Date(),
}).set(input)
const [conversation] = await ctx.db.update(conversations)
.set({
...input,
updatedAt: new Date(),
})
🤖 Prompt for AI Agents
In apps/web/client/src/server/api/routers/chat/conversation.ts around lines
48-51, the code spreads the `conversations` table into a plain object which
removes the Drizzle table symbols and prevents `updatedAt` from being updated;
change the update call to use the table instance (e.g.,
ctx.db.update(conversations)) and pass the update payload to .set(...) including
updatedAt (for example .set({ ...input, updatedAt: new Date() })) so the table
metadata is preserved and updatedAt is refreshed.

@vercel vercel bot temporarily deployed to Preview – docs October 2, 2025 02:02 Inactive
@vercel vercel bot temporarily deployed to Preview – docs October 2, 2025 23:22 Inactive
@vercel vercel bot temporarily deployed to Preview – docs October 3, 2025 00:03 Inactive
@Kitenite Kitenite marked this pull request as ready for review October 3, 2025 00:06
@Kitenite Kitenite merged commit b1eb66f into main Oct 3, 2025
7 of 8 checks passed
@Kitenite Kitenite deleted the refactor/reduce-agent-overhead branch October 3, 2025 00:07
@coderabbitai coderabbitai bot mentioned this pull request Oct 21, 2025
5 tasks
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