From 9da574a112acdb26abdecbc885fd41a946f5749f Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Thu, 9 Apr 2026 14:43:01 -0700 Subject: [PATCH] Fix dev --- .../workspace/[workspaceId]/home/hooks/use-chat.ts | 1 - apps/sim/lib/copilot/request/go/stream.ts | 14 ++++++++------ apps/sim/lib/copilot/request/handlers/types.ts | 2 +- apps/sim/lib/copilot/tools/handlers/vfs.ts | 8 ++++++-- .../lib/copilot/tools/server/files/create-file.ts | 8 +++----- .../lib/copilot/tools/server/files/delete-file.ts | 5 ++--- .../tools/server/files/file-intent-store.ts | 4 ++-- .../lib/copilot/tools/server/files/rename-file.ts | 7 +++---- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts index 45ce8fb70c..58b46cd066 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts +++ b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts @@ -1296,7 +1296,6 @@ export function useChat( const tc = blocks[parentIdx].toolCall! tc.status = 'executing' tc.result = undefined - tc.error = undefined flush() break } diff --git a/apps/sim/lib/copilot/request/go/stream.ts b/apps/sim/lib/copilot/request/go/stream.ts index 63b63f3425..707bf192d6 100644 --- a/apps/sim/lib/copilot/request/go/stream.ts +++ b/apps/sim/lib/copilot/request/go/stream.ts @@ -276,12 +276,14 @@ export async function runStreamLoop( newOperation: operation, } ) - const cleared = clearIntentsForWorkspace(execContext.workspaceId) - if (cleared > 0) { - logger.warn('Cleared orphaned execution intents from store', { - cleared, - workspaceId: execContext.workspaceId, - }) + if (execContext.workspaceId) { + const cleared = clearIntentsForWorkspace(execContext.workspaceId) + if (cleared > 0) { + logger.warn('Cleared orphaned execution intents from store', { + cleared, + workspaceId: execContext.workspaceId, + }) + } } } diff --git a/apps/sim/lib/copilot/request/handlers/types.ts b/apps/sim/lib/copilot/request/handlers/types.ts index 48c3e6fdc4..b98f2dcffe 100644 --- a/apps/sim/lib/copilot/request/handlers/types.ts +++ b/apps/sim/lib/copilot/request/handlers/types.ts @@ -24,7 +24,7 @@ export type StreamHandler = ( options: OrchestratorOptions ) => void | Promise -export type ToolScope = MothershipStreamV1StreamScope['lane'] +export type ToolScope = 'main' | MothershipStreamV1StreamScope['lane'] const logger = createLogger('CopilotHandlerHelpers') diff --git a/apps/sim/lib/copilot/tools/handlers/vfs.ts b/apps/sim/lib/copilot/tools/handlers/vfs.ts index e5007924fb..6c71e7adca 100644 --- a/apps/sim/lib/copilot/tools/handlers/vfs.ts +++ b/apps/sim/lib/copilot/tools/handlers/vfs.ts @@ -21,8 +21,12 @@ function isOversizedReadPlaceholder(content: string): boolean { ) } -function hasImageAttachment(result: { attachment?: { type?: string } }): boolean { - return result.attachment?.type === 'image' +function hasImageAttachment(result: unknown): boolean { + if (!result || typeof result !== 'object') { + return false + } + const attachment = (result as { attachment?: { type?: string } }).attachment + return attachment?.type === 'image' } export async function executeVfsGrep( diff --git a/apps/sim/lib/copilot/tools/server/files/create-file.ts b/apps/sim/lib/copilot/tools/server/files/create-file.ts index f64b2a738c..f182c94f12 100644 --- a/apps/sim/lib/copilot/tools/server/files/create-file.ts +++ b/apps/sim/lib/copilot/tools/server/files/create-file.ts @@ -40,11 +40,9 @@ export const createFileServerTool: BaseServerTool - const nested = raw.args as Record | undefined - const fileName = (params.fileName as string) ?? (nested?.fileName as string) ?? '' - const explicitType = - (params.contentType as string) ?? (nested?.contentType as string) ?? undefined + const nested = params.args + const fileName = params.fileName || (nested?.fileName as string) || '' + const explicitType = params.contentType || (nested?.contentType as string) || undefined const nameError = validateFlatWorkspaceFileName(fileName) if (nameError) return { success: false, message: nameError } diff --git a/apps/sim/lib/copilot/tools/server/files/delete-file.ts b/apps/sim/lib/copilot/tools/server/files/delete-file.ts index ed38e430ed..fba8d4e768 100644 --- a/apps/sim/lib/copilot/tools/server/files/delete-file.ts +++ b/apps/sim/lib/copilot/tools/server/files/delete-file.ts @@ -33,9 +33,8 @@ export const deleteFileServerTool: BaseServerTool - const nested = raw.args as Record | undefined - const fileId = (params.fileId as string) ?? (nested?.fileId as string) ?? '' + const nested = params.args + const fileId = params.fileId || (nested?.fileId as string) || '' if (!fileId) return { success: false, message: 'fileId is required' } diff --git a/apps/sim/lib/copilot/tools/server/files/file-intent-store.ts b/apps/sim/lib/copilot/tools/server/files/file-intent-store.ts index 5127666390..177281725d 100644 --- a/apps/sim/lib/copilot/tools/server/files/file-intent-store.ts +++ b/apps/sim/lib/copilot/tools/server/files/file-intent-store.ts @@ -1,11 +1,11 @@ -import type { UserFile } from '@/lib/uploads/contexts/workspace/workspace-file-manager' +import type { WorkspaceFileRecord } from '@/lib/uploads/contexts/workspace/workspace-file-manager' export type PendingFileIntent = { operation: 'append' | 'update' | 'patch' fileId: string workspaceId: string userId: string - fileRecord: UserFile + fileRecord: WorkspaceFileRecord existingContent?: string edit?: { strategy: string diff --git a/apps/sim/lib/copilot/tools/server/files/rename-file.ts b/apps/sim/lib/copilot/tools/server/files/rename-file.ts index d1ab117ad9..bfc7b02be1 100644 --- a/apps/sim/lib/copilot/tools/server/files/rename-file.ts +++ b/apps/sim/lib/copilot/tools/server/files/rename-file.ts @@ -39,10 +39,9 @@ export const renameFileServerTool: BaseServerTool - const nested = raw.args as Record | undefined - const fileId = (params.fileId as string) ?? (nested?.fileId as string) ?? '' - const newName = (params.newName as string) ?? (nested?.newName as string) ?? '' + const nested = params.args + const fileId = params.fileId || (nested?.fileId as string) || '' + const newName = params.newName || (nested?.newName as string) || '' if (!fileId) return { success: false, message: 'fileId is required' }