From 5f89f625d7b6f1a54bca8c485fb1b0551fbcf79b Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Thu, 5 Feb 2026 19:26:47 -0800 Subject: [PATCH] Fix - cursor makes me sad --- apps/sim/app/api/copilot/chat/route.ts | 4 -- apps/sim/app/api/mcp/copilot/route.ts | 2 - apps/sim/app/api/v1/copilot/chat/route.ts | 4 +- apps/sim/lib/copilot/chat-payload.ts | 39 ++-------------- .../tool-executor/workflow-tools/mutations.ts | 3 +- .../tools/server/blocks/get-block-options.ts | 1 + .../server/blocks/get-blocks-and-tools.ts | 2 +- .../server/blocks/get-blocks-metadata-tool.ts | 2 +- .../server/user/set-environment-variables.ts | 46 +++++-------------- .../workflows/executor/execute-workflow.ts | 4 +- 10 files changed, 26 insertions(+), 81 deletions(-) diff --git a/apps/sim/app/api/copilot/chat/route.ts b/apps/sim/app/api/copilot/chat/route.ts index a048e31d2..cd9ad7436 100644 --- a/apps/sim/app/api/copilot/chat/route.ts +++ b/apps/sim/app/api/copilot/chat/route.ts @@ -205,15 +205,11 @@ export async function POST(req: NextRequest) { userMessageId: userMessageIdToUse, mode, model: selectedModel, - stream, - conversationId: effectiveConversationId, conversationHistory, contexts: agentContexts, fileAttachments, commands, chatId: actualChatId, - prefetch, - userName: session?.user?.name || undefined, implicitFeedback, }, { diff --git a/apps/sim/app/api/mcp/copilot/route.ts b/apps/sim/app/api/mcp/copilot/route.ts index 9f8a0cf13..7e330ff01 100644 --- a/apps/sim/app/api/mcp/copilot/route.ts +++ b/apps/sim/app/api/mcp/copilot/route.ts @@ -384,8 +384,6 @@ async function handleBuildToolCall( message: requestText, workflowId: resolved.workflowId, userId, - stream: true, - streamToolCalls: true, model, mode: 'agent', commands: ['fast'], diff --git a/apps/sim/app/api/v1/copilot/chat/route.ts b/apps/sim/app/api/v1/copilot/chat/route.ts index 57def1fb5..d08234cff 100644 --- a/apps/sim/app/api/v1/copilot/chat/route.ts +++ b/apps/sim/app/api/v1/copilot/chat/route.ts @@ -73,13 +73,11 @@ export async function POST(req: NextRequest) { message: parsed.message, workflowId: resolved.workflowId, userId: auth.userId, - stream: true, - streamToolCalls: true, model: selectedModel, mode: transportMode, messageId: crypto.randomUUID(), version: SIM_AGENT_VERSION, - headless: true, // Enable cross-workflow operations via workflowId params + headless: true, chatId, } diff --git a/apps/sim/lib/copilot/chat-payload.ts b/apps/sim/lib/copilot/chat-payload.ts index 7883f4234..ab6fcad0b 100644 --- a/apps/sim/lib/copilot/chat-payload.ts +++ b/apps/sim/lib/copilot/chat-payload.ts @@ -17,15 +17,11 @@ export interface BuildPayloadParams { userMessageId: string mode: string model: string - stream: boolean - conversationId?: string conversationHistory?: unknown[] contexts?: Array<{ type: string; content: string }> fileAttachments?: Array<{ id: string; key: string; size: number; [key: string]: unknown }> commands?: string[] chatId?: string - prefetch?: boolean - userName?: string implicitFeedback?: string } @@ -99,9 +95,9 @@ export async function buildCopilotRequestPayload( } ): Promise> { const { - message, workflowId, userId, userMessageId, mode, stream, - conversationId, conversationHistory = [], contexts, fileAttachments, - commands, chatId, prefetch, userName, implicitFeedback, + message, workflowId, userId, userMessageId, mode, + conversationHistory = [], contexts, fileAttachments, + commands, chatId, implicitFeedback, } = params const selectedModel = options.selectedModel @@ -146,29 +142,10 @@ export async function buildCopilotRequestPayload( } let integrationTools: ToolSchema[] = [] - let baseTools: ToolSchema[] = [] let credentials: CredentialsPayload | null = null if (effectiveMode === 'build') { - baseTools = [ - { - name: 'function_execute', - description: - 'Execute JavaScript code to perform calculations, data transformations, API calls, or any programmatic task. Code runs in a secure sandbox with fetch() available. Write plain statements (not wrapped in functions). Example: const res = await fetch(url); const data = await res.json(); return data;', - input_schema: { - type: 'object', - properties: { - code: { - type: 'string', - description: - 'Raw JavaScript statements to execute. Code is auto-wrapped in async context. Use fetch() for HTTP requests. Write like: const res = await fetch(url); return await res.json();', - }, - }, - required: ['code'], - }, - executeLocally: true, - }, - ] + // function_execute sandbox tool is now defined in Go — no need to send it try { const rawCredentials = await getCredentialsServerTool.execute({ workflowId }, { userId }) @@ -231,21 +208,15 @@ export async function buildCopilotRequestPayload( message, workflowId, userId, - stream, - streamToolCalls: true, model: selectedModel, mode: transportMode, messageId: userMessageId, version: SIM_AGENT_VERSION, ...(providerConfig ? { provider: providerConfig } : {}), - ...(conversationId ? { conversationId } : {}), - ...(typeof prefetch === 'boolean' ? { prefetch } : {}), - ...(userName ? { userName } : {}), ...(contexts && contexts.length > 0 ? { context: contexts } : {}), ...(chatId ? { chatId } : {}), ...(processedFileContents.length > 0 ? { fileAttachments: processedFileContents } : {}), - ...(integrationTools.length > 0 ? { tools: integrationTools } : {}), - ...(baseTools.length > 0 ? { baseTools } : {}), + ...(integrationTools.length > 0 ? { integrationTools } : {}), ...(credentials ? { credentials } : {}), ...(commands && commands.length > 0 ? { commands } : {}), } diff --git a/apps/sim/lib/copilot/orchestrator/tool-executor/workflow-tools/mutations.ts b/apps/sim/lib/copilot/orchestrator/tool-executor/workflow-tools/mutations.ts index 148928694..0b5afbf12 100644 --- a/apps/sim/lib/copilot/orchestrator/tool-executor/workflow-tools/mutations.ts +++ b/apps/sim/lib/copilot/orchestrator/tool-executor/workflow-tools/mutations.ts @@ -156,7 +156,8 @@ export async function executeRunWorkflow( }, generateRequestId(), params.workflow_input || params.input || undefined, - context.userId + context.userId, + { enabled: true, useDraftState: true } ) return { diff --git a/apps/sim/lib/copilot/tools/server/blocks/get-block-options.ts b/apps/sim/lib/copilot/tools/server/blocks/get-block-options.ts index c93db8b8a..49c0648b2 100644 --- a/apps/sim/lib/copilot/tools/server/blocks/get-block-options.ts +++ b/apps/sim/lib/copilot/tools/server/blocks/get-block-options.ts @@ -1,6 +1,7 @@ import { createLogger } from '@sim/logger' import type { BaseServerTool } from '@/lib/copilot/tools/server/base-tool' import { + GetBlockOptionsInput, type GetBlockOptionsInputType, GetBlockOptionsResult, type GetBlockOptionsResultType, diff --git a/apps/sim/lib/copilot/tools/server/blocks/get-blocks-and-tools.ts b/apps/sim/lib/copilot/tools/server/blocks/get-blocks-and-tools.ts index cf32eea70..64a4db00e 100644 --- a/apps/sim/lib/copilot/tools/server/blocks/get-blocks-and-tools.ts +++ b/apps/sim/lib/copilot/tools/server/blocks/get-blocks-and-tools.ts @@ -1,7 +1,7 @@ import { createLogger } from '@sim/logger' import type { BaseServerTool } from '@/lib/copilot/tools/server/base-tool' import { - type GetBlocksAndToolsInput, + GetBlocksAndToolsInput, GetBlocksAndToolsResult, } from '@/lib/copilot/tools/shared/schemas' import { registry as blockRegistry } from '@/blocks/registry' diff --git a/apps/sim/lib/copilot/tools/server/blocks/get-blocks-metadata-tool.ts b/apps/sim/lib/copilot/tools/server/blocks/get-blocks-metadata-tool.ts index 374b47c0d..0db7cebdc 100644 --- a/apps/sim/lib/copilot/tools/server/blocks/get-blocks-metadata-tool.ts +++ b/apps/sim/lib/copilot/tools/server/blocks/get-blocks-metadata-tool.ts @@ -3,7 +3,7 @@ import { join } from 'path' import { createLogger } from '@sim/logger' import type { BaseServerTool } from '@/lib/copilot/tools/server/base-tool' import { - type GetBlocksMetadataInput, + GetBlocksMetadataInput, GetBlocksMetadataResult, } from '@/lib/copilot/tools/shared/schemas' import { registry as blockRegistry } from '@/blocks/registry' diff --git a/apps/sim/lib/copilot/tools/server/user/set-environment-variables.ts b/apps/sim/lib/copilot/tools/server/user/set-environment-variables.ts index a4f7959b5..000cb65ab 100644 --- a/apps/sim/lib/copilot/tools/server/user/set-environment-variables.ts +++ b/apps/sim/lib/copilot/tools/server/user/set-environment-variables.ts @@ -1,9 +1,8 @@ import { db } from '@sim/db' -import { workspaceEnvironment } from '@sim/db/schema' +import { environment } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { eq } from 'drizzle-orm' import { z } from 'zod' -import { createPermissionError, verifyWorkflowAccess } from '@/lib/copilot/auth/permissions' import type { BaseServerTool } from '@/lib/copilot/tools/server/base-tool' import { decryptSecret, encryptSecret } from '@/lib/core/security/encryption' @@ -50,35 +49,16 @@ export const setEnvironmentVariablesServerTool: BaseServerTool) || {} @@ -114,36 +94,34 @@ export const setEnvironmentVariablesServerTool: BaseServerTool