improvement(copilot): structured metadata context + start block deprecation (#1362)

* progress

* progress

* deploy command update

* add trigger mode modal

* fix trigger icons'

* fix corners for add trigger card

* update serialization error visual in console

* works

* improvement(copilot-context): structured context for copilot

* forgot long description

* Update metadata params

* progress

* add better workflow ux

* progress

* highlighting works

* trigger card

* default agent workflow change

* fix build error

* remove any casts

* address greptile comments

* Diff input format

* address greptile comments

* improvement: ui/ux

* improvement: changed to vertical scrolling

* fix(workflow): ensure new blocks from sidebar click/drag use getUniqueBlockName (with semantic trigger base when applicable)

* Validation + build/edit mark complete

* fix trigger dropdown

* Copilot stuff (lots of it)

* Temp update prod dns

* fix trigger check

* fix

* fix trigger mode check

* Fix yaml imports

* Fix autolayout error

* fix deployed chat

* Fix copilot input text overflow

* fix trigger mode persistence in addBlock with enableTriggerMode flag passed in

* Lint

* Fix failing tests

* Reset ishosted

* Lint

* input format for legacy starter

* Fix executor

---------

Co-authored-by: Siddharth Ganesan <siddharthganesan@gmail.com>
Co-authored-by: Emir Karabeg <emirkarabeg@berkeley.edu>
This commit is contained in:
Vikhyath Mondreti
2025-09-22 23:24:50 -07:00
committed by GitHub
parent 68df95906f
commit b7876ca466
128 changed files with 4263 additions and 1275 deletions

View File

@@ -220,13 +220,20 @@ describe('Copilot Chat API Route', () => {
content: 'Hello',
},
],
chatMessages: [
{
role: 'user',
content: 'Hello',
},
],
workflowId: 'workflow-123',
userId: 'user-123',
stream: true,
streamToolCalls: true,
model: 'gpt-5',
mode: 'agent',
messageId: 'mock-uuid-1234-5678',
depth: 0,
version: '1.0.0',
chatId: 'chat-123',
}),
})
@@ -284,13 +291,19 @@ describe('Copilot Chat API Route', () => {
{ role: 'assistant', content: 'Previous response' },
{ role: 'user', content: 'New message' },
],
chatMessages: [
{ role: 'user', content: 'Previous message' },
{ role: 'assistant', content: 'Previous response' },
{ role: 'user', content: 'New message' },
],
workflowId: 'workflow-123',
userId: 'user-123',
stream: true,
streamToolCalls: true,
model: 'gpt-5',
mode: 'agent',
messageId: 'mock-uuid-1234-5678',
depth: 0,
version: '1.0.0',
chatId: 'chat-123',
}),
})
@@ -337,13 +350,18 @@ describe('Copilot Chat API Route', () => {
{ role: 'system', content: 'User seems confused about the workflow' },
{ role: 'user', content: 'Hello' },
],
chatMessages: [
{ role: 'system', content: 'User seems confused about the workflow' },
{ role: 'user', content: 'Hello' },
],
workflowId: 'workflow-123',
userId: 'user-123',
stream: true,
streamToolCalls: true,
model: 'gpt-5',
mode: 'agent',
messageId: 'mock-uuid-1234-5678',
depth: 0,
version: '1.0.0',
chatId: 'chat-123',
}),
})
@@ -427,13 +445,15 @@ describe('Copilot Chat API Route', () => {
expect.objectContaining({
body: JSON.stringify({
messages: [{ role: 'user', content: 'What is this workflow?' }],
chatMessages: [{ role: 'user', content: 'What is this workflow?' }],
workflowId: 'workflow-123',
userId: 'user-123',
stream: true,
streamToolCalls: true,
model: 'gpt-5',
mode: 'ask',
messageId: 'mock-uuid-1234-5678',
depth: 0,
version: '1.0.0',
chatId: 'chat-123',
}),
})

View File

@@ -15,7 +15,7 @@ import { getCopilotModel } from '@/lib/copilot/config'
import type { CopilotProviderConfig } from '@/lib/copilot/types'
import { env } from '@/lib/env'
import { createLogger } from '@/lib/logs/console/logger'
import { SIM_AGENT_API_URL_DEFAULT } from '@/lib/sim-agent'
import { SIM_AGENT_API_URL_DEFAULT, SIM_AGENT_VERSION } from '@/lib/sim-agent'
import { generateChatTitle } from '@/lib/sim-agent/utils'
import { createFileContent, isSupportedFileType } from '@/lib/uploads/file-utils'
import { S3_COPILOT_CONFIG } from '@/lib/uploads/setup'
@@ -38,8 +38,21 @@ const ChatMessageSchema = z.object({
userMessageId: z.string().optional(), // ID from frontend for the user message
chatId: z.string().optional(),
workflowId: z.string().min(1, 'Workflow ID is required'),
model: z
.enum([
'gpt-5-fast',
'gpt-5',
'gpt-5-medium',
'gpt-5-high',
'gpt-4o',
'gpt-4.1',
'o3',
'claude-4-sonnet',
'claude-4.1-opus',
])
.optional()
.default('gpt-5'),
mode: z.enum(['ask', 'agent']).optional().default('agent'),
depth: z.number().int().min(0).max(3).optional().default(0),
prefetch: z.boolean().optional(),
createNewChat: z.boolean().optional().default(false),
stream: z.boolean().optional().default(true),
@@ -97,8 +110,8 @@ export async function POST(req: NextRequest) {
userMessageId,
chatId,
workflowId,
model,
mode,
depth,
prefetch,
createNewChat,
stream,
@@ -147,19 +160,6 @@ export async function POST(req: NextRequest) {
}
}
// Consolidation mapping: map negative depths to base depth with prefetch=true
let effectiveDepth: number | undefined = typeof depth === 'number' ? depth : undefined
let effectivePrefetch: boolean | undefined = prefetch
if (typeof effectiveDepth === 'number') {
if (effectiveDepth === -2) {
effectiveDepth = 1
effectivePrefetch = true
} else if (effectiveDepth === -1) {
effectiveDepth = 0
effectivePrefetch = true
}
}
// Handle chat context
let currentChat: any = null
let conversationHistory: any[] = []
@@ -366,16 +366,18 @@ export async function POST(req: NextRequest) {
const requestPayload = {
messages: messagesForAgent,
chatMessages: messages, // Full unfiltered messages array
workflowId,
userId: authenticatedUserId,
stream: stream,
streamToolCalls: true,
model: model,
mode: mode,
messageId: userMessageIdToUse,
version: SIM_AGENT_VERSION,
...(providerConfig ? { provider: providerConfig } : {}),
...(effectiveConversationId ? { conversationId: effectiveConversationId } : {}),
...(typeof effectiveDepth === 'number' ? { depth: effectiveDepth } : {}),
...(typeof effectivePrefetch === 'boolean' ? { prefetch: effectivePrefetch } : {}),
...(typeof prefetch === 'boolean' ? { prefetch: prefetch } : {}),
...(session?.user?.name && { userName: session.user.name }),
...(agentContexts.length > 0 && { context: agentContexts }),
...(actualChatId ? { chatId: actualChatId } : {}),
@@ -384,6 +386,9 @@ export async function POST(req: NextRequest) {
try {
logger.info(`[${tracker.requestId}] About to call Sim Agent with context`, {
context: (requestPayload as any).context,
messagesCount: messagesForAgent.length,
chatMessagesCount: messages.length,
hasConversationId: !!effectiveConversationId,
})
} catch {}

View File

@@ -48,6 +48,7 @@ export async function POST(req: NextRequest) {
return createBadRequestResponse('Invalid request body for execute-copilot-server-tool')
}
logger.error(`[${tracker.requestId}] Failed to execute server tool:`, error)
return createInternalServerErrorResponse('Failed to execute server tool')
const errorMessage = error instanceof Error ? error.message : 'Failed to execute server tool'
return createInternalServerErrorResponse(errorMessage)
}
}