@@ -15,7 +15,7 @@ import { getCopilotModel } from '@/lib/copilot/config'
1515import type { CopilotProviderConfig } from '@/lib/copilot/types'
1616import { env } from '@/lib/env'
1717import { createLogger } from '@/lib/logs/console/logger'
18- import { SIM_AGENT_API_URL_DEFAULT } from '@/lib/sim-agent'
18+ import { SIM_AGENT_API_URL_DEFAULT , SIM_AGENT_VERSION } from '@/lib/sim-agent'
1919import { generateChatTitle } from '@/lib/sim-agent/utils'
2020import { createFileContent , isSupportedFileType } from '@/lib/uploads/file-utils'
2121import { S3_COPILOT_CONFIG } from '@/lib/uploads/setup'
@@ -38,8 +38,21 @@ const ChatMessageSchema = z.object({
3838 userMessageId : z . string ( ) . optional ( ) , // ID from frontend for the user message
3939 chatId : z . string ( ) . optional ( ) ,
4040 workflowId : z . string ( ) . min ( 1 , 'Workflow ID is required' ) ,
41+ model : z
42+ . enum ( [
43+ 'gpt-5-fast' ,
44+ 'gpt-5' ,
45+ 'gpt-5-medium' ,
46+ 'gpt-5-high' ,
47+ 'gpt-4o' ,
48+ 'gpt-4.1' ,
49+ 'o3' ,
50+ 'claude-4-sonnet' ,
51+ 'claude-4.1-opus' ,
52+ ] )
53+ . optional ( )
54+ . default ( 'gpt-5' ) ,
4155 mode : z . enum ( [ 'ask' , 'agent' ] ) . optional ( ) . default ( 'agent' ) ,
42- depth : z . number ( ) . int ( ) . min ( 0 ) . max ( 3 ) . optional ( ) . default ( 0 ) ,
4356 prefetch : z . boolean ( ) . optional ( ) ,
4457 createNewChat : z . boolean ( ) . optional ( ) . default ( false ) ,
4558 stream : z . boolean ( ) . optional ( ) . default ( true ) ,
@@ -97,8 +110,8 @@ export async function POST(req: NextRequest) {
97110 userMessageId,
98111 chatId,
99112 workflowId,
113+ model,
100114 mode,
101- depth,
102115 prefetch,
103116 createNewChat,
104117 stream,
@@ -147,19 +160,6 @@ export async function POST(req: NextRequest) {
147160 }
148161 }
149162
150- // Consolidation mapping: map negative depths to base depth with prefetch=true
151- let effectiveDepth : number | undefined = typeof depth === 'number' ? depth : undefined
152- let effectivePrefetch : boolean | undefined = prefetch
153- if ( typeof effectiveDepth === 'number' ) {
154- if ( effectiveDepth === - 2 ) {
155- effectiveDepth = 1
156- effectivePrefetch = true
157- } else if ( effectiveDepth === - 1 ) {
158- effectiveDepth = 0
159- effectivePrefetch = true
160- }
161- }
162-
163163 // Handle chat context
164164 let currentChat : any = null
165165 let conversationHistory : any [ ] = [ ]
@@ -366,16 +366,18 @@ export async function POST(req: NextRequest) {
366366
367367 const requestPayload = {
368368 messages : messagesForAgent ,
369+ chatMessages : messages , // Full unfiltered messages array
369370 workflowId,
370371 userId : authenticatedUserId ,
371372 stream : stream ,
372373 streamToolCalls : true ,
374+ model : model ,
373375 mode : mode ,
374376 messageId : userMessageIdToUse ,
377+ version : SIM_AGENT_VERSION ,
375378 ...( providerConfig ? { provider : providerConfig } : { } ) ,
376379 ...( effectiveConversationId ? { conversationId : effectiveConversationId } : { } ) ,
377- ...( typeof effectiveDepth === 'number' ? { depth : effectiveDepth } : { } ) ,
378- ...( typeof effectivePrefetch === 'boolean' ? { prefetch : effectivePrefetch } : { } ) ,
380+ ...( typeof prefetch === 'boolean' ? { prefetch : prefetch } : { } ) ,
379381 ...( session ?. user ?. name && { userName : session . user . name } ) ,
380382 ...( agentContexts . length > 0 && { context : agentContexts } ) ,
381383 ...( actualChatId ? { chatId : actualChatId } : { } ) ,
@@ -384,6 +386,9 @@ export async function POST(req: NextRequest) {
384386 try {
385387 logger . info ( `[${ tracker . requestId } ] About to call Sim Agent with context` , {
386388 context : ( requestPayload as any ) . context ,
389+ messagesCount : messagesForAgent . length ,
390+ chatMessagesCount : messages . length ,
391+ hasConversationId : ! ! effectiveConversationId ,
387392 } )
388393 } catch { }
389394
0 commit comments