An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
feat: enable todo tools only for quality model type
Yoshiki Miura474b98ea822a
diff --git a/app/api/chat/route.ts b/app/api/chat/route.tsindex 331385bf..efe64e1e 100644--- a/app/api/chat/route.ts+++ b/app/api/chat/route.ts@@ -97,15 +97,19 @@ export async function POST(req: Request) {// Check rate limit for quality modeconst modelTypeCookie = cookieStore.get('modelType')?.value+ const modelType =+ modelTypeCookie === 'quality' || modelTypeCookie === 'speed'+ ? modelTypeCookie+ : undefinedconst rateLimitResponse = await checkAndEnforceQualityLimit(userId,- modelTypeCookie === 'quality'+ modelType === 'quality')if (rateLimitResponse) return rateLimitResponseconst streamStart = performance.now()perfLog(- `createChatStreamResponse - Start: model=${selectedModel.providerId}:${selectedModel.id}, searchMode=${searchMode}`+ `createChatStreamResponse - Start: model=${selectedModel.providerId}:${selectedModel.id}, searchMode=${searchMode}, modelType=${modelType}`)const response = await createChatStreamResponse({@@ -117,7 +121,8 @@ export async function POST(req: Request) {messageId,abortSignal,isNewChat,- searchMode+ searchMode,+ modelType})perfTime('createChatStreamResponse resolved', streamStart)diff --git a/lib/agents/researcher.ts b/lib/agents/researcher.tsindex 93fd7b1e..5026d258 100644--- a/lib/agents/researcher.ts+++ b/lib/agents/researcher.ts@@ -13,6 +13,7 @@ import type {ResearcherResponse,ResearcherTools} from '@/lib/types/agent'+import { type ModelType } from '@/lib/types/model-type'import { type Model } from '@/lib/types/models'import { fetchTool } from '../tools/fetch'@@ -81,7 +82,8 @@ export function createResearcher({abortSignal,writer,parentTraceId,- searchMode = 'adaptive'+ searchMode = 'adaptive',+ modelType}: {model: stringmodelConfig?: Model@@ -89,6 +91,7 @@ export function createResearcher({writer?: UIMessageStreamWriterparentTraceId?: stringsearchMode?: SearchMode+ modelType?: ModelType}): ResearcherAgent {try {const currentDate = new Date().toLocaleString()@@ -119,11 +122,12 @@ export function createResearcher({default:systemPrompt = ADAPTIVE_MODE_PROMPTactiveToolsList = ['search', 'fetch']- if (writer && 'todoWrite' in todoTools) {+ // Only enable todo tools for quality model type+ if (writer && 'todoWrite' in todoTools && modelType === 'quality') {activeToolsList.push('todoWrite', 'todoRead')}console.log(- `[Researcher] Adaptive mode: maxSteps=50, tools=[${activeToolsList.join(', ')}]`+ `[Researcher] Adaptive mode: maxSteps=50, modelType=${modelType}, tools=[${activeToolsList.join(', ')}]`)maxSteps = 50searchTool = originalSearchTooldiff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.tsindex 2234d7c6..b91b1b33 100644--- a/lib/streaming/create-chat-stream-response.ts+++ b/lib/streaming/create-chat-stream-response.ts@@ -44,7 +44,8 @@ export async function createChatStreamResponse(messageId,abortSignal,isNewChat,- searchMode+ searchMode,+ modelType} = config// Verify that chatId is provided@@ -123,14 +124,15 @@ export async function createChatStreamResponse(const messagesToModel = await prepareMessages(context, message)perfTime('prepareMessages completed (stream)', prepareStart)- // Get the researcher agent with parent trace ID and search mode+ // Get the researcher agent with parent trace ID, search mode, and model typeconst researchAgent = researcher({model: context.modelId,modelConfig: model,abortSignal,writer,parentTraceId,- searchMode+ searchMode,+ modelType})// Filter out reasoning parts from messages before converting to model messagesdiff --git a/lib/streaming/types.ts b/lib/streaming/types.tsindex e3361008..94da5b8a 100644--- a/lib/streaming/types.ts+++ b/lib/streaming/types.ts@@ -1,6 +1,7 @@import { UIMessage } from '@ai-sdk/react'import { Model } from '../types/models'+import { ModelType } from '../types/model-type'import { SearchMode } from '../types/search'export interface BaseStreamConfig {@@ -13,4 +14,5 @@ export interface BaseStreamConfig {abortSignal?: AbortSignalisNewChat?: booleansearchMode?: SearchMode+ modelType?: ModelType}