An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
feat: Implement search modes (Quick, Planning, Auto)
Yoshiki Miura6fe94058eb3a
diff --git a/app/api/chat/route.ts b/app/api/chat/route.tsindex 471a184a..6e7a30b6 100644--- a/app/api/chat/route.ts+++ b/app/api/chat/route.ts@@ -27,7 +27,7 @@ export async function POST(req: Request) {try {const body = await req.json()- const { message, chatId, trigger, messageId, isNewChat } = body+ const { message, chatId, trigger, messageId, isNewChat, searchMode } = bodyperfLog(`API Route - Start: chatId=${chatId}, trigger=${trigger}, isNewChat=${isNewChat}`@@ -104,7 +104,8 @@ export async function POST(req: Request) {trigger,messageId,abortSignal,- isNewChat+ isNewChat,+ searchMode})const totalTime = performance.now() - startTimediff --git a/app/globals.css b/app/globals.cssindex 95ed57e5..191bfe50 100644--- a/app/globals.css+++ b/app/globals.css@@ -249,6 +249,73 @@}}+/* Animation utilities for dropdown menu */+@utility animate-in {+ animation-name: enter;+ animation-duration: 150ms;+ animation-fill-mode: both;+}++@utility animate-out {+ animation-name: exit;+ animation-duration: 150ms;+ animation-fill-mode: both;+}++@utility fade-in-0 {+ --enter-opacity: 0;+}++@utility fade-out-0 {+ --exit-opacity: 0;+}++@utility zoom-in-95 {+ --enter-scale: 0.95;+}++@utility zoom-out-95 {+ --exit-scale: 0.95;+}++@utility slide-in-from-top-2 {+ --enter-translate-y: -0.5rem;+}++@utility slide-in-from-bottom-2 {+ --enter-translate-y: 0.5rem;+}++@utility slide-in-from-left-2 {+ --enter-translate-x: -0.5rem;+}++@utility slide-in-from-right-2 {+ --enter-translate-x: 0.5rem;+}++@keyframes enter {+ from {+ opacity: var(--enter-opacity, 1);+ transform: translate(var(--enter-translate-x, 0), var(--enter-translate-y, 0)) scale(var(--enter-scale, 1));+ }+ to {+ opacity: 1;+ transform: translate(0, 0) scale(1);+ }+}++@keyframes exit {+ from {+ opacity: 1;+ transform: translate(0, 0) scale(1);+ }+ to {+ opacity: var(--exit-opacity, 1);+ transform: translate(var(--exit-translate-x, 0), var(--exit-translate-y, 0)) scale(var(--exit-scale, 1));+ }+}+@utility container {margin-inline: auto;padding-inline: 2rem;diff --git a/bun.lock b/bun.lockindex a21de9c7..771f44f9 100644--- a/bun.lock+++ b/bun.lock@@ -19,7 +19,7 @@"@radix-ui/react-checkbox": "^1.0.4","@radix-ui/react-collapsible": "^1.0.3","@radix-ui/react-dialog": "^1.1.11",- "@radix-ui/react-dropdown-menu": "^2.0.6",+ "@radix-ui/react-dropdown-menu": "^2.1.16","@radix-ui/react-label": "^2.1.6","@radix-ui/react-popover": "^1.1.5","@radix-ui/react-select": "^2.1.2",@@ -461,7 +461,7 @@"@radix-ui/react-dismissable-layer": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.2", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-use-callback-ref": "1.1.1", "@radix-ui/react-use-escape-keydown": "1.1.1" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-IM1zzRV4W3HtVgftdQiiOmA0AdJlCtMLe00FXaHwgt3rAnNsIyDqshvkIW3hj/iu5hu8ERP7KIYki6NkqDxAwQ=="],- "@radix-ui/react-dropdown-menu": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.2", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-menu": "2.1.15", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-use-controllable-state": "1.2.2" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-mIBnOjgwo9AH3FyKaSWoSu/dYj6VdhJ7frEPiGTeXCdUFHjl9h3mFh2wwhEtINOmYXWhdpf1rY2minFsmaNgVQ=="],+ "@radix-ui/react-dropdown-menu": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.3", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-menu": "2.1.16", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-use-controllable-state": "1.2.2" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-1PLGQEynI/3OX/ftV54COn+3Sud/Mn8vALg2rWnBLnRaGtJDduNW/22XjlGgPdpcIbiQxjKtb7BkcjP00nqfJw=="],"@radix-ui/react-focus-guards": ["@radix-ui/[email protected]", "", { "peerDependencies": { "@types/react": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-fyjAACV62oPV925xFCrH8DR5xWhg9KYtJT4s3u54jxp+L/hbpTY2kIeEFFbFe+a/HCE94zGQMZLIpVTPVZDhaA=="],@@ -471,7 +471,7 @@"@radix-ui/react-label": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/react-primitive": "2.1.3" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-YT1GqPSL8kJn20djelMX7/cTRp/Y9w5IZHvfxQTVHrOqa2yMl7i/UfMqKRU5V7mEyKTrUVgJXhNQPVCG8PBLoQ=="],- "@radix-ui/react-menu": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.2", "@radix-ui/react-collection": "1.1.7", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-direction": "1.1.1", "@radix-ui/react-dismissable-layer": "1.1.10", "@radix-ui/react-focus-guards": "1.1.2", "@radix-ui/react-focus-scope": "1.1.7", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-popper": "1.2.7", "@radix-ui/react-portal": "1.1.9", "@radix-ui/react-presence": "1.1.4", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-roving-focus": "1.1.10", "@radix-ui/react-slot": "1.2.3", "@radix-ui/react-use-callback-ref": "1.1.1", "aria-hidden": "^1.2.4", "react-remove-scroll": "^2.6.3" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-tVlmA3Vb9n8SZSd+YSbuFR66l87Wiy4du+YE+0hzKQEANA+7cWKH1WgqcEX4pXqxUFQKrWQGHdvEfw00TjFiew=="],+ "@radix-ui/react-menu": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.3", "@radix-ui/react-collection": "1.1.7", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-direction": "1.1.1", "@radix-ui/react-dismissable-layer": "1.1.11", "@radix-ui/react-focus-guards": "1.1.3", "@radix-ui/react-focus-scope": "1.1.7", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-popper": "1.2.8", "@radix-ui/react-portal": "1.1.9", "@radix-ui/react-presence": "1.1.5", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-roving-focus": "1.1.11", "@radix-ui/react-slot": "1.2.3", "@radix-ui/react-use-callback-ref": "1.1.1", "aria-hidden": "^1.2.4", "react-remove-scroll": "^2.6.3" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-72F2T+PLlphrqLcAotYPp0uJMr5SjP5SL01wfEspJbru5Zs5vQaSHb4VB3ZMJPimgHHCHG7gMOeOB9H3Hdmtxg=="],"@radix-ui/react-popover": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.2", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-dismissable-layer": "1.1.10", "@radix-ui/react-focus-guards": "1.1.2", "@radix-ui/react-focus-scope": "1.1.7", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-popper": "1.2.7", "@radix-ui/react-portal": "1.1.9", "@radix-ui/react-presence": "1.1.4", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-slot": "1.2.3", "@radix-ui/react-use-controllable-state": "1.2.2", "aria-hidden": "^1.2.4", "react-remove-scroll": "^2.6.3" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-ODz16+1iIbGUfFEfKx2HTPKizg2MN39uIOV8MXeHnmdd3i/N9Wt7vU46wbHsqA0xoaQyXVcs0KIlBdOA2Y95bw=="],@@ -483,7 +483,7 @@"@radix-ui/react-primitive": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/react-slot": "1.2.3" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-m9gTwRkhy2lvCPe6QJp4d3G1TYEUHn/FzJUtq9MjH46an1wJU+GdoGC5VLof8RX8Ft/DlpshApkhswDLZzHIcQ=="],- "@radix-ui/react-roving-focus": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.2", "@radix-ui/react-collection": "1.1.7", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-direction": "1.1.1", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-use-callback-ref": "1.1.1", "@radix-ui/react-use-controllable-state": "1.2.2" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-dT9aOXUen9JSsxnMPv/0VqySQf5eDQ6LCk5Sw28kamz8wSOW2bJdlX2Bg5VUIIcV+6XlHpWTIuTPCf/UNIyq8Q=="],+ "@radix-ui/react-roving-focus": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.3", "@radix-ui/react-collection": "1.1.7", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-direction": "1.1.1", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-use-callback-ref": "1.1.1", "@radix-ui/react-use-controllable-state": "1.2.2" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-7A6S9jSgm/S+7MdtNDSb+IU859vQqJ/QAtcYQcfFC6W8RS4IxIZDldLR0xqCFZ6DCyrQLjLPsxtTNch5jVA4lA=="],"@radix-ui/react-select": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/number": "1.1.1", "@radix-ui/primitive": "1.1.2", "@radix-ui/react-collection": "1.1.7", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-direction": "1.1.1", "@radix-ui/react-dismissable-layer": "1.1.10", "@radix-ui/react-focus-guards": "1.1.2", "@radix-ui/react-focus-scope": "1.1.7", "@radix-ui/react-id": "1.1.1", "@radix-ui/react-popper": "1.2.7", "@radix-ui/react-portal": "1.1.9", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-slot": "1.2.3", "@radix-ui/react-use-callback-ref": "1.1.1", "@radix-ui/react-use-controllable-state": "1.2.2", "@radix-ui/react-use-layout-effect": "1.1.1", "@radix-ui/react-use-previous": "1.1.1", "@radix-ui/react-visually-hidden": "1.2.3", "aria-hidden": "^1.2.4", "react-remove-scroll": "^2.6.3" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-HnMTdXEVuuyzx63ME0ut4+sEMYW6oouHWNGUZc7ddvUWIcfCva/AMoqEW/3wnEllriMWBa0RHspCYnfCWJQYmA=="],@@ -2055,6 +2055,20 @@"@napi-rs/wasm-runtime/@emnapi/runtime": ["@emnapi/[email protected]", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-++LApOtY0pEEz1zrd9vy1/zXVaVJJ/EbAF3u0fXIzPJEDtnITsBGbbK0EkM72amhl/R5b+5xx0Y/QhcVOpuulg=="],+ "@radix-ui/react-dropdown-menu/@radix-ui/primitive": ["@radix-ui/[email protected]", "", {}, "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg=="],++ "@radix-ui/react-menu/@radix-ui/primitive": ["@radix-ui/[email protected]", "", {}, "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg=="],++ "@radix-ui/react-menu/@radix-ui/react-dismissable-layer": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/primitive": "1.1.3", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-use-callback-ref": "1.1.1", "@radix-ui/react-use-escape-keydown": "1.1.1" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-Nqcp+t5cTB8BinFkZgXiMJniQH0PsUt2k51FUhbdfeKvc4ACcG2uQniY/8+h1Yv6Kza4Q7lD7PQV0z0oicE0Mg=="],++ "@radix-ui/react-menu/@radix-ui/react-focus-guards": ["@radix-ui/[email protected]", "", { "peerDependencies": { "@types/react": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-0rFg/Rj2Q62NCm62jZw0QX7a3sz6QCQU0LpZdNrJX8byRGaGVTqbrW9jAoIAHyMQqsNpeZ81YgSizOt5WXq0Pw=="],++ "@radix-ui/react-menu/@radix-ui/react-popper": ["@radix-ui/[email protected]", "", { "dependencies": { "@floating-ui/react-dom": "^2.0.0", "@radix-ui/react-arrow": "1.1.7", "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-context": "1.1.2", "@radix-ui/react-primitive": "2.1.3", "@radix-ui/react-use-callback-ref": "1.1.1", "@radix-ui/react-use-layout-effect": "1.1.1", "@radix-ui/react-use-rect": "1.1.1", "@radix-ui/react-use-size": "1.1.1", "@radix-ui/rect": "1.1.1" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-0NJQ4LFFUuWkE7Oxf0htBKS6zLkkjBH+hM1uk7Ng705ReR8m/uelduy1DBo0PyBXPKVnBA6YBlU94MBGXrSBCw=="],++ "@radix-ui/react-menu/@radix-ui/react-presence": ["@radix-ui/[email protected]", "", { "dependencies": { "@radix-ui/react-compose-refs": "1.1.2", "@radix-ui/react-use-layout-effect": "1.1.1" }, "peerDependencies": { "@types/react": "*", "@types/react-dom": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react", "@types/react-dom"] }, "sha512-/jfEwNDdQVBCNvjkGit4h6pMOzq8bHkopq458dPt2lMjx+eBQUohZNG9A7DtO/O5ukSbxuaNGXMjHicgwy6rQQ=="],++ "@radix-ui/react-roving-focus/@radix-ui/primitive": ["@radix-ui/[email protected]", "", {}, "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg=="],+"@supabase/auth-ui-react/react": ["[email protected]", "", { "dependencies": { "loose-envify": "^1.1.0" } }, "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ=="],"@supabase/auth-ui-react/react-dom": ["[email protected]", "", { "dependencies": { "loose-envify": "^1.1.0", "scheduler": "^0.23.2" }, "peerDependencies": { "react": "^18.3.1" } }, "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw=="],diff --git a/components/chat-panel.tsx b/components/chat-panel.tsxindex f576cbfa..188ce632 100644--- a/components/chat-panel.tsx+++ b/components/chat-panel.tsx@@ -19,6 +19,7 @@ import { IconLogo } from './ui/icons'import { ActionButtons } from './action-buttons'import { FileUploadButton } from './file-upload-button'import { ModelSelector } from './model-selector'+import { SearchModeSelector } from './search-mode-selector'import { UploadedFileList } from './uploaded-file-list'// Constants for timing delays@@ -202,6 +203,7 @@ export function ChatPanel({<div className="flex items-center justify-between p-3"><div className="flex items-center gap-2"><ModelSelector models={models || []} />+ <SearchModeSelector /></div><div className="flex items-center gap-2">{messages.length > 0 && (diff --git a/components/chat.tsx b/components/chat.tsxindex df1db594..edd413b4 100644--- a/components/chat.tsx+++ b/components/chat.tsx@@ -6,6 +6,7 @@ import { useChat } from '@ai-sdk/react'import { DefaultChatTransport } from 'ai'import { toast } from 'sonner'+import { SearchMode } from '@/lib/agents/researcher'import { generateId } from '@/lib/db/schema'import { UploadedFile } from '@/lib/types'import type { UIMessage } from '@/lib/types/ai'@@ -16,6 +17,7 @@ import {} from '@/lib/types/dynamic-tools'import { Model } from '@/lib/types/models'import { cn } from '@/lib/utils'+import { getCookie } from '@/lib/utils/cookies'import { useAuthCheck } from '@/hooks/use-auth-check'import { useFileDropzone } from '@/hooks/use-file-dropzone'@@ -61,6 +63,16 @@ export function Chat({})const { isAuthenticated } = useAuthCheck()+ // Get search mode from cookie+ const [searchMode, setSearchMode] = useState<SearchMode>('auto')++ useEffect(() => {+ const savedMode = getCookie('searchMode')+ if (savedMode && ['quick', 'planning', 'auto'].includes(savedMode)) {+ setSearchMode(savedMode as SearchMode)+ }+ }, [])+const {messages,status,@@ -94,7 +106,8 @@ export function Chat({: trigger === 'submit-message'? lastMessage: undefined,- isNewChat: trigger === 'submit-message' && messages.length === 1+ isNewChat: trigger === 'submit-message' && messages.length === 1,+ searchMode // Include search mode in the request}}}diff --git a/components/search-mode-selector.tsx b/components/search-mode-selector.tsxnew file mode 100644index 00000000..0e68ccba--- /dev/null+++ b/components/search-mode-selector.tsx@@ -0,0 +1,127 @@+'use client'++import { useEffect, useState } from 'react'++import { Check, ChevronDown, GitBranch, Sparkles, Zap } from 'lucide-react'++import { SearchMode } from '@/lib/agents/researcher'+import { cn } from '@/lib/utils'+import { getCookie, setCookie } from '@/lib/utils/cookies'++import { Button } from './ui/button'+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger+} from './ui/dropdown-menu'++interface SearchModeOption {+ value: SearchMode+ label: string+ description: string+ model: string+ icon: React.ComponentType<{ className?: string }>+ color: string+}++const searchModes: SearchModeOption[] = [+ {+ value: 'quick',+ label: 'Quick',+ description: 'Fast, concise responses',+ model: 'MoonshotAI/Kimi K2',+ icon: Zap,+ color: 'text-yellow-500'+ },+ {+ value: 'planning',+ label: 'Planning',+ description: 'Detailed, structured research',+ model: 'OpenAI GPT-5',+ icon: GitBranch,+ color: 'text-blue-500'+ },+ {+ value: 'auto',+ label: 'Auto',+ description: 'Balanced, adaptive approach',+ model: 'Auto',+ icon: Sparkles,+ color: 'text-purple-500'+ }+]++export function SearchModeSelector() {+ const [value, setValue] = useState<SearchMode>('auto')+ const [open, setOpen] = useState(false)++ useEffect(() => {+ const savedMode = getCookie('searchMode')+ if (savedMode && ['quick', 'planning', 'auto'].includes(savedMode)) {+ setValue(savedMode as SearchMode)+ }+ }, [])++ const handleModeSelect = (mode: SearchMode) => {+ setValue(mode)+ setCookie('searchMode', mode)+ setOpen(false)+ }++ const selectedMode = searchModes.find(mode => mode.value === value)+ const Icon = selectedMode?.icon || Sparkles++ return (+ <DropdownMenu open={open} onOpenChange={setOpen}>+ <DropdownMenuTrigger asChild>+ <Button+ variant="outline"+ className="text-sm rounded-full shadow-none gap-1 transition-all !ring-0 !outline-none !ring-offset-0 [&:focus]:!ring-0 [&:focus]:!outline-none [&:focus-visible]:!ring-0 [&:focus-visible]:!ring-offset-0"+ >+ <Icon+ className={cn('h-4 w-4 transition-colors', selectedMode?.color)}+ />+ <span className="text-xs font-medium">{selectedMode?.label}</span>+ <ChevronDown+ className={cn(+ 'h-3 w-3 ml-1 opacity-50 transition-transform duration-200',+ open && 'rotate-180'+ )}+ />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start" className="w-64" sideOffset={5}>+ {searchModes.map(mode => {+ const ModeIcon = mode.icon+ const isSelected = value === mode.value+ return (+ <DropdownMenuItem+ key={mode.value}+ onClick={() => handleModeSelect(mode.value)}+ className="relative flex flex-col items-start gap-1 py-2 pl-8 pr-2 cursor-pointer focus:outline-none"+ >+ {isSelected && (+ <Check className="absolute left-2 top-2.5 h-4 w-4" />+ )}+ <div className="flex items-center gap-2">+ <ModeIcon+ className={cn('h-4 w-4 transition-colors', mode.color)}+ />+ <span className="text-sm font-medium">{mode.label}</span>+ </div>+ <div className="flex flex-col gap-0.5 ml-6">+ <span className="text-xs text-muted-foreground">+ {mode.description}+ </span>+ <span className="text-xs text-muted-foreground/70">+ {mode.model}+ </span>+ </div>+ </DropdownMenuItem>+ )+ })}+ </DropdownMenuContent>+ </DropdownMenu>+ )+}diff --git a/components/ui/dropdown-menu.tsx b/components/ui/dropdown-menu.tsxindex 7defe912..a79bbf7d 100644--- a/components/ui/dropdown-menu.tsx+++ b/components/ui/dropdown-menu.tsx@@ -1,186 +1,245 @@-'use client'--import * as React from 'react'--import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'-import { Check, ChevronRight, Circle } from 'lucide-react'--import { cn } from '@/lib/utils'--const DropdownMenu = DropdownMenuPrimitive.Root--const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger--const DropdownMenuGroup = DropdownMenuPrimitive.Group--const DropdownMenuPortal = DropdownMenuPrimitive.Portal--const DropdownMenuSub = DropdownMenuPrimitive.Sub--const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup--const DropdownMenuSubTrigger = React.forwardRef<- React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {- inset?: boolean- }->(({ className, inset, children, ...props }, ref) => (- <DropdownMenuPrimitive.SubTrigger- ref={ref}- className={cn(- 'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-hidden focus:bg-accent data-[state=open]:bg-accent',- inset && 'pl-8',- className- )}- {...props}- >- {children}- <ChevronRight className="ml-auto h-4 w-4" />- </DropdownMenuPrimitive.SubTrigger>-))-DropdownMenuSubTrigger.displayName =- DropdownMenuPrimitive.SubTrigger.displayName--const DropdownMenuSubContent = React.forwardRef<- React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>->(({ className, ...props }, ref) => (- <DropdownMenuPrimitive.SubContent- ref={ref}- className={cn(- 'z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',- className- )}- {...props}- />-))-DropdownMenuSubContent.displayName =- DropdownMenuPrimitive.SubContent.displayName--const DropdownMenuContent = React.forwardRef<- React.ElementRef<typeof DropdownMenuPrimitive.Content>,- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>->(({ className, sideOffset = 4, ...props }, ref) => (- <DropdownMenuPrimitive.Portal>- <DropdownMenuPrimitive.Content- ref={ref}- sideOffset={sideOffset}+"use client"++import * as React from "react"++import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"+import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"++import { cn } from "@/lib/utils/index"++function DropdownMenu({+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {+ return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />+}++function DropdownMenuPortal({+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {+ return (+ <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />+ )+}++function DropdownMenuTrigger({+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {+ return (+ <DropdownMenuPrimitive.Trigger+ data-slot="dropdown-menu-trigger"+ {...props}+ />+ )+}++function DropdownMenuContent({+ className,+ sideOffset = 4,+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {+ return (+ <DropdownMenuPrimitive.Portal>+ <DropdownMenuPrimitive.Content+ data-slot="dropdown-menu-content"+ sideOffset={sideOffset}+ className={cn(+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",+ className+ )}+ {...props}+ />+ </DropdownMenuPrimitive.Portal>+ )+}++function DropdownMenuGroup({+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {+ return (+ <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />+ )+}++function DropdownMenuItem({+ className,+ inset,+ variant = "default",+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {+ inset?: boolean+ variant?: "default" | "destructive"+}) {+ return (+ <DropdownMenuPrimitive.Item+ data-slot="dropdown-menu-item"+ data-inset={inset}+ data-variant={variant}+ className={cn(+ "focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",+ className+ )}+ {...props}+ />+ )+}++function DropdownMenuCheckboxItem({+ className,+ children,+ checked,+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {+ return (+ <DropdownMenuPrimitive.CheckboxItem+ data-slot="dropdown-menu-checkbox-item"+ className={cn(+ "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",+ className+ )}+ checked={checked}+ {...props}+ >+ <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">+ <DropdownMenuPrimitive.ItemIndicator>+ <CheckIcon className="size-4" />+ </DropdownMenuPrimitive.ItemIndicator>+ </span>+ {children}+ </DropdownMenuPrimitive.CheckboxItem>+ )+}++function DropdownMenuRadioGroup({+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {+ return (+ <DropdownMenuPrimitive.RadioGroup+ data-slot="dropdown-menu-radio-group"+ {...props}+ />+ )+}++function DropdownMenuRadioItem({+ className,+ children,+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {+ return (+ <DropdownMenuPrimitive.RadioItem+ data-slot="dropdown-menu-radio-item"+ className={cn(+ "focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",+ className+ )}+ {...props}+ >+ <span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">+ <DropdownMenuPrimitive.ItemIndicator>+ <CircleIcon className="size-2 fill-current" />+ </DropdownMenuPrimitive.ItemIndicator>+ </span>+ {children}+ </DropdownMenuPrimitive.RadioItem>+ )+}++function DropdownMenuLabel({+ className,+ inset,+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {+ inset?: boolean+}) {+ return (+ <DropdownMenuPrimitive.Label+ data-slot="dropdown-menu-label"+ data-inset={inset}className={cn(- 'z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',+ "px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",className)}{...props}/>- </DropdownMenuPrimitive.Portal>-))-DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName--const DropdownMenuItem = React.forwardRef<- React.ElementRef<typeof DropdownMenuPrimitive.Item>,- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {- inset?: boolean- }->(({ className, inset, ...props }, ref) => (- <DropdownMenuPrimitive.Item- ref={ref}- className={cn(- 'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50',- inset && 'pl-8',- className- )}- {...props}- />-))-DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName--const DropdownMenuCheckboxItem = React.forwardRef<- React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>->(({ className, children, checked, ...props }, ref) => (- <DropdownMenuPrimitive.CheckboxItem- ref={ref}- className={cn(- 'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50',- className- )}- checked={checked}- {...props}- >- <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">- <DropdownMenuPrimitive.ItemIndicator>- <Check className="h-4 w-4" />- </DropdownMenuPrimitive.ItemIndicator>- </span>- {children}- </DropdownMenuPrimitive.CheckboxItem>-))-DropdownMenuCheckboxItem.displayName =- DropdownMenuPrimitive.CheckboxItem.displayName--const DropdownMenuRadioItem = React.forwardRef<- React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>->(({ className, children, ...props }, ref) => (- <DropdownMenuPrimitive.RadioItem- ref={ref}- className={cn(- 'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50',- className- )}- {...props}- >- <span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">- <DropdownMenuPrimitive.ItemIndicator>- <Circle className="h-2 w-2 fill-current" />- </DropdownMenuPrimitive.ItemIndicator>- </span>- {children}- </DropdownMenuPrimitive.RadioItem>-))-DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName--const DropdownMenuLabel = React.forwardRef<- React.ElementRef<typeof DropdownMenuPrimitive.Label>,- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {- inset?: boolean- }->(({ className, inset, ...props }, ref) => (- <DropdownMenuPrimitive.Label- ref={ref}- className={cn(- 'px-2 py-1.5 text-sm font-semibold',- inset && 'pl-8',- className- )}- {...props}- />-))-DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName--const DropdownMenuSeparator = React.forwardRef<- React.ElementRef<typeof DropdownMenuPrimitive.Separator>,- React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>->(({ className, ...props }, ref) => (- <DropdownMenuPrimitive.Separator- ref={ref}- className={cn('-mx-1 my-1 h-px bg-muted', className)}- {...props}- />-))-DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName--const DropdownMenuShortcut = ({+ )+}++function DropdownMenuSeparator({+ className,+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {+ return (+ <DropdownMenuPrimitive.Separator+ data-slot="dropdown-menu-separator"+ className={cn("bg-border -mx-1 my-1 h-px", className)}+ {...props}+ />+ )+}++function DropdownMenuShortcut({className,...props-}: React.HTMLAttributes<HTMLSpanElement>) => {+}: React.ComponentProps<"span">) {return (<span- className={cn('ml-auto text-xs tracking-widest opacity-60', className)}+ data-slot="dropdown-menu-shortcut"+ className={cn(+ "text-muted-foreground ml-auto text-xs tracking-widest",+ className+ )}{...props}/>)}-DropdownMenuShortcut.displayName = 'DropdownMenuShortcut'++function DropdownMenuSub({+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {+ return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />+}++function DropdownMenuSubTrigger({+ className,+ inset,+ children,+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {+ inset?: boolean+}) {+ return (+ <DropdownMenuPrimitive.SubTrigger+ data-slot="dropdown-menu-sub-trigger"+ data-inset={inset}+ className={cn(+ "focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8",+ className+ )}+ {...props}+ >+ {children}+ <ChevronRightIcon className="ml-auto size-4" />+ </DropdownMenuPrimitive.SubTrigger>+ )+}++function DropdownMenuSubContent({+ className,+ ...props+}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {+ return (+ <DropdownMenuPrimitive.Portal>+ <DropdownMenuPrimitive.SubContent+ data-slot="dropdown-menu-sub-content"+ className={cn(+ "bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",+ className+ )}+ {...props}+ />+ </DropdownMenuPrimitive.Portal>+ )+}export {DropdownMenu,@@ -197,5 +256,5 @@ export {DropdownMenuSub,DropdownMenuSubContent,DropdownMenuSubTrigger,- DropdownMenuTrigger+ DropdownMenuTrigger,}diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.tsindex 696f2617..2a29805b 100644--- a/lib/agents/researcher.ts+++ b/lib/agents/researcher.ts@@ -1,6 +1,7 @@import {Experimental_Agent as Agent,stepCountIs,+ tool,UIMessageStreamWriter} from 'ai'@@ -11,7 +12,74 @@ import { createTodoTools } from '../tools/todo'import { getModel } from '../utils/registry'import { isTracingEnabled } from '../utils/telemetry'-const SYSTEM_PROMPT = `+// Search mode type+export type SearchMode = 'quick' | 'planning' | 'auto'++// Quick Mode System Prompt - Minimal, direct responses+const QUICK_MODE_PROMPT = `+Instructions:++You are a fast, efficient AI assistant optimized for quick responses. You have access to web search and content retrieval.++Your approach:+1. Use the search tool with optimized results to get content snippets directly+2. Provide concise, direct answers based on search results+3. Focus on the most relevant information without extensive detail+4. Keep responses brief and to the point+5. **CRITICAL: You MUST cite sources inline using the [number](#toolCallId) format**++Search tool usage:+- The search tool is configured to always use type="optimized" for direct content snippets+- This provides faster responses without needing additional fetch operations+- Rely on the search results' content snippets for your answers++Citation Format (MANDATORY):+[number](#toolCallId) - Always use this EXACT format, e.g., [1](#toolu_abc123)+- Place citations at the END of sentences or statements+- Every piece of information from search results MUST have a citation++Keep responses concise - typically 1-2 paragraphs maximum.+`++// Planning Mode System Prompt - Structured, detailed responses+const PLANNING_MODE_PROMPT = `+Instructions:++You are a methodical AI assistant focused on thorough research and structured planning. You have access to web search, content retrieval, task management, and the ability to ask clarifying questions.++Your approach:+1. First, determine if you need clarification - use ask_question tool if needed+2. For complex queries, create a structured plan using todoWrite tool+3. Systematically work through each task, updating progress as you go+4. Search for comprehensive information using multiple searches if needed+5. Fetch detailed content from specific URLs when deeper analysis is required+6. Provide detailed, well-structured responses with clear sections+7. **CRITICAL: You MUST cite sources inline using the [number](#toolCallId) format**++Task Management:+- Use todoWrite to create and track tasks for complex research+- Update task status as you progress (pending → in_progress → completed)+- Ensure all tasks are completed before finishing++Search strategy:+- Use type="optimized" for detailed research and fact-checking+- Use type="general" for videos, images, or real-time information+- Follow up with fetch tool for in-depth content analysis++Citation Format (MANDATORY):+[number](#toolCallId) - Always use this EXACT format, e.g., [1](#toolu_abc123)+- Place citations at the END of sentences or statements+- Every piece of information from search results MUST have a citation++Structure your responses with:+- Clear headings and sections+- Comprehensive coverage of the topic+- Detailed analysis and insights+- Summary or conclusion when appropriate+`++// Auto Mode System Prompt - Balanced, adaptive approach (current default)+const AUTO_MODE_PROMPT = `Instructions:You are a helpful AI assistant with access to real-time web search, content retrieval, and the ability to ask clarifying questions.@@ -73,30 +141,92 @@ For complex queries requiring systematic investigation:import { Model } from '@/lib/types/models'+// Wrapper function to force optimized search for quick mode+function wrapSearchToolForQuickMode(originalTool: ReturnType<typeof createSearchTool>) {+ return tool({+ description: originalTool.description,+ inputSchema: originalTool.inputSchema,+ execute: async (params: any, context: any) => {+ // Force type to be optimized for quick mode+ const executeFunc = originalTool.execute+ if (!executeFunc) {+ throw new Error('Search tool execute function is not defined')+ }+ return executeFunc({+ ...params,+ type: 'optimized'+ }, context)+ }+ })+}+export function researcher({model,modelConfig,abortSignal,writer,- parentTraceId+ parentTraceId,+ searchMode = 'auto'}: {model: stringmodelConfig?: ModelabortSignal?: AbortSignalwriter?: UIMessageStreamWriterparentTraceId?: string+ searchMode?: SearchMode}) {try {const currentDate = new Date().toLocaleString()// Create model-specific tools- const searchTool = createSearchTool(model)+ const originalSearchTool = createSearchTool(model)const askQuestionTool = createQuestionTool(model)// Create todo tools if writer is providedconst todoTools = writer ? createTodoTools() : {}- // Build tools object+ // Direct mode-based parameter selection+ let systemPrompt: string+ let activeToolsList: string[]+ let maxSteps: number+ let searchTool: ReturnType<typeof createSearchTool>++ // Simple switch - no config objects+ switch (searchMode) {+ case 'quick':+ // Quick Mode: Minimal tools, fast responses, optimized search only+ systemPrompt = QUICK_MODE_PROMPT+ activeToolsList = ['search', 'fetch']+ maxSteps = 5+ // Force optimized search for quick mode+ searchTool = wrapSearchToolForQuickMode(originalSearchTool)+ break++ case 'planning':+ // Planning Mode: All tools, structured approach, many steps+ systemPrompt = PLANNING_MODE_PROMPT+ activeToolsList = ['search', 'fetch', 'askQuestion']+ if (writer && 'todoWrite' in todoTools) {+ activeToolsList.push('todoWrite', 'todoRead')+ }+ maxSteps = 30+ searchTool = originalSearchTool+ break++ case 'auto':+ default:+ // Auto Mode: Balanced approach, current behavior+ systemPrompt = AUTO_MODE_PROMPT+ activeToolsList = ['search', 'fetch']+ if (writer && 'todoWrite' in todoTools) {+ activeToolsList.push('todoWrite', 'todoRead')+ }+ maxSteps = 20+ searchTool = originalSearchTool+ break+ }++ // Build tools object with potentially wrapped search toolconst tools = {search: searchTool,fetch: fetchTool,@@ -104,21 +234,13 @@ export function researcher({...todoTools}- // Build activeTools array based on available tools- type ToolNames = keyof typeof tools- const activeToolsList: ToolNames[] = ['search', 'fetch']-- if (writer && 'todoWrite' in todoTools) {- activeToolsList.push('todoWrite' as ToolNames, 'todoRead' as ToolNames)- }-// Return an agent instancereturn new Agent({model: getModel(model),- system: `${SYSTEM_PROMPT}\nCurrent date and time: ${currentDate}`,+ system: `${systemPrompt}\nCurrent date and time: ${currentDate}`,tools,- activeTools: activeToolsList,- stopWhen: stepCountIs(20),+ activeTools: activeToolsList as (keyof typeof tools)[],+ stopWhen: stepCountIs(maxSteps),abortSignal,...(modelConfig?.providerOptions && {providerOptions: modelConfig.providerOptions@@ -129,6 +251,7 @@ export function researcher({metadata: {modelId: model,agentType: 'researcher',+ searchMode,...(parentTraceId && {langfuseTraceId: parentTraceId,langfuseUpdateParent: falsediff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.tsindex 49ae647a..c028cc05 100644--- a/lib/streaming/create-chat-stream-response.ts+++ b/lib/streaming/create-chat-stream-response.ts@@ -42,7 +42,8 @@ export async function createChatStreamResponse(trigger,messageId,abortSignal,- isNewChat+ isNewChat,+ searchMode} = configconst modelId = `${model.providerId}:${model.id}`@@ -114,13 +115,14 @@ export async function createChatStreamResponse(// Prepare messages for the modelconst messagesToModel = await prepareMessages(context, message)- // Get the researcher agent with parent trace ID+ // Get the researcher agent with parent trace ID and search modeconst researchAgent = researcher({model: context.modelId,modelConfig: model,abortSignal,writer,- parentTraceId+ parentTraceId,+ searchMode})// Write metadata including traceId at the start of streamingdiff --git a/lib/streaming/types.ts b/lib/streaming/types.tsindex 28820964..a6c763ff 100644--- a/lib/streaming/types.ts+++ b/lib/streaming/types.ts@@ -1,5 +1,6 @@import { UIMessage } from '@ai-sdk/react'+import { SearchMode } from '../agents/researcher'import { Model } from '../types/models'export interface BaseStreamConfig {@@ -11,4 +12,5 @@ export interface BaseStreamConfig {messageId?: stringabortSignal?: AbortSignalisNewChat?: boolean+ searchMode?: SearchMode}diff --git a/package.json b/package.jsonindex e1911013..3b6b3246 100644--- a/package.json+++ b/package.json@@ -32,7 +32,7 @@"@radix-ui/react-checkbox": "^1.0.4","@radix-ui/react-collapsible": "^1.0.3","@radix-ui/react-dialog": "^1.1.11",- "@radix-ui/react-dropdown-menu": "^2.0.6",+ "@radix-ui/react-dropdown-menu": "^2.1.16","@radix-ui/react-label": "^2.1.6","@radix-ui/react-popover": "^1.1.5","@radix-ui/react-select": "^2.1.2",