Fix - cursor makes me sad

This commit is contained in:
Siddharth Ganesan
2026-02-05 19:26:47 -08:00
parent adf6b83d00
commit 5f89f625d7
10 changed files with 26 additions and 81 deletions

View File

@@ -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,
},
{

View File

@@ -384,8 +384,6 @@ async function handleBuildToolCall(
message: requestText,
workflowId: resolved.workflowId,
userId,
stream: true,
streamToolCalls: true,
model,
mode: 'agent',
commands: ['fast'],

View File

@@ -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,
}

View File

@@ -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<Record<string, unknown>> {
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 } : {}),
}

View File

@@ -156,7 +156,8 @@ export async function executeRunWorkflow(
},
generateRequestId(),
params.workflow_input || params.input || undefined,
context.userId
context.userId,
{ enabled: true, useDraftState: true }
)
return {

View File

@@ -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,

View File

@@ -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'

View File

@@ -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'

View File

@@ -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<SetEnvironmentVar
}
const authenticatedUserId = context.userId
const { variables, workflowId } = params || ({} as SetEnvironmentVariablesParams)
if (!workflowId) {
throw new Error('workflowId is required to set workspace environment variables')
}
const { hasAccess, workspaceId } = await verifyWorkflowAccess(authenticatedUserId, workflowId)
if (!hasAccess) {
const errorMessage = createPermissionError('modify environment variables in')
logger.error('Unauthorized attempt to set environment variables', {
workflowId,
authenticatedUserId,
})
throw new Error(errorMessage)
}
if (!workspaceId) {
throw new Error('Could not determine workspace for this workflow')
}
const { variables } = params || ({} as SetEnvironmentVariablesParams)
const normalized = normalizeVariables(variables || {})
const { variables: validatedVariables } = EnvVarSchema.parse({ variables: normalized })
// Fetch existing workspace environment variables
// Fetch existing personal environment variables
const existingData = await db
.select()
.from(workspaceEnvironment)
.where(eq(workspaceEnvironment.workspaceId, workspaceId))
.from(environment)
.where(eq(environment.userId, authenticatedUserId))
.limit(1)
const existingEncrypted = (existingData[0]?.variables as Record<string, string>) || {}
@@ -114,36 +94,34 @@ export const setEnvironmentVariablesServerTool: BaseServerTool<SetEnvironmentVar
const finalEncrypted = { ...existingEncrypted, ...newlyEncrypted }
// Save to workspace environment variables
// Save to personal environment variables (keyed by userId)
await db
.insert(workspaceEnvironment)
.insert(environment)
.values({
id: crypto.randomUUID(),
workspaceId,
userId: authenticatedUserId,
variables: finalEncrypted,
updatedAt: new Date(),
})
.onConflictDoUpdate({
target: [workspaceEnvironment.workspaceId],
target: [environment.userId],
set: { variables: finalEncrypted, updatedAt: new Date() },
})
logger.info('Saved workspace environment variables', {
workspaceId,
workflowId,
logger.info('Saved personal environment variables', {
userId: authenticatedUserId,
addedCount: added.length,
updatedCount: updated.length,
totalCount: Object.keys(finalEncrypted).length,
})
return {
message: `Successfully processed ${Object.keys(validatedVariables).length} workspace environment variable(s): ${added.length} added, ${updated.length} updated`,
message: `Successfully processed ${Object.keys(validatedVariables).length} personal environment variable(s): ${added.length} added, ${updated.length} updated`,
variableCount: Object.keys(validatedVariables).length,
variableNames: Object.keys(validatedVariables),
totalVariableCount: Object.keys(finalEncrypted).length,
addedVariables: added,
updatedVariables: updated,
workspaceId,
}
},
}

View File

@@ -20,6 +20,8 @@ export interface ExecuteWorkflowOptions {
includeFileBase64?: boolean
base64MaxBytes?: number
abortSignal?: AbortSignal
/** Use the live/draft workflow state instead of the deployed state. Used by copilot. */
useDraftState?: boolean
}
export interface WorkflowInfo {
@@ -57,7 +59,7 @@ export async function executeWorkflow(
userId: actorUserId,
workflowUserId: workflow.userId,
triggerType,
useDraftState: false,
useDraftState: streamConfig?.useDraftState ?? false,
startTime: new Date().toISOString(),
isClientSession: false,
}