Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions apps/sim/executor/handlers/agent/agent-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,21 +745,11 @@ export class AgentBlockHandler implements BlockHandler {

for (let messageIndex = 0; messageIndex < messages.length; messageIndex++) {
const message = messages[messageIndex]
const normalizedFiles = normalizeFileInput(message.files)
if (!normalizedFiles || normalizedFiles.length === 0) {
if (!message.files?.length) {
continue
}

const userFiles = processFilesToUserFiles(
normalizedFiles as RawFileInput[],
requestId,
logger
)
if (userFiles.length === 0) {
throw new Error('Files must include at least one valid file object')
}

const hydratedFiles = await hydrateUserFilesWithBase64(userFiles, {
const hydratedFiles = await hydrateUserFilesWithBase64(message.files, {
requestId,
workspaceId: ctx.workspaceId,
workflowId: ctx.workflowId,
Expand All @@ -774,7 +764,7 @@ export class AgentBlockHandler implements BlockHandler {
const missingFile = hydratedFiles.find((file) => !file.base64)
if (missingFile) {
throw new Error(
`File "${missingFile.name}" could not be read for provider "${providerId}". Make sure the file is still accessible and under the provider attachment size limit.`
`File "${missingFile.name}" could not be read for provider "${providerId}". The file may exceed the attachment size limit or may no longer be accessible.`
)
}

Expand Down
3 changes: 2 additions & 1 deletion apps/sim/executor/handlers/agent/memory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('Memory', () => {
})

describe('sanitizeMessageForStorage', () => {
it('should strip file payloads and provider-only fields before memory persistence', () => {
it('should strip file payloads but preserve tool-call fields before memory persistence', () => {
const message: Message = {
role: 'user',
content: 'Analyze this file',
Expand All @@ -202,6 +202,7 @@ describe('Memory', () => {
role: 'user',
content: 'Analyze this file',
executionId: 'exec-1',
tool_calls: [{ id: 'call-1' }],
})
})
})
Expand Down
7 changes: 2 additions & 5 deletions apps/sim/executor/handlers/agent/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,8 @@ export class Memory {
}

private sanitizeMessageForStorage(message: Message): Message {
return {
role: message.role,
content: message.content,
...(message.executionId && { executionId: message.executionId }),
}
const { files: _files, ...messageWithoutFiles } = message
return messageWithoutFiles
}

private applyTokenWindow(messages: Message[], maxTokens: number, model?: string): Message[] {
Expand Down
10 changes: 9 additions & 1 deletion apps/sim/lib/api/contracts/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { defineRouteContract } from '@/lib/api/contracts/types'
import { getNextWorkflowColor } from '@/lib/workflows/colors'

const subBlockValuesSchema = z.record(z.string(), z.record(z.string(), z.unknown()))
const executionIdSchema = z
.string()
.min(1, 'Invalid execution ID')
.max(128, 'Execution ID too long')
.regex(
/^[A-Za-z0-9._:-]+$/,
'Execution ID can only contain letters, numbers, dots, underscores, colons, and hyphens'
)

const workflowPositionSchema = z.object({
x: z.number(),
Expand Down Expand Up @@ -336,7 +344,7 @@ export const executeWorkflowBodySchema = z.object({
includeFileBase64: z.boolean().optional().default(true),
base64MaxBytes: z.number().int().positive().optional(),
workflowStateOverride: workflowStateSchema.optional(),
executionId: z.string().optional(),
executionId: executionIdSchema.optional(),
triggerBlockId: z.string().optional(),
startBlockId: z.string().optional(),
stopAfterBlockId: z.string().optional(),
Expand Down
Loading
Loading