Skip to content

Commit cb9c2d5

Browse files
authored
improvement(files): validations (#4620)
* Fix * Fixes
1 parent a64b338 commit cb9c2d5

8 files changed

Lines changed: 116 additions & 117 deletions

File tree

apps/sim/executor/handlers/agent/agent-handler.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -745,21 +745,11 @@ export class AgentBlockHandler implements BlockHandler {
745745

746746
for (let messageIndex = 0; messageIndex < messages.length; messageIndex++) {
747747
const message = messages[messageIndex]
748-
const normalizedFiles = normalizeFileInput(message.files)
749-
if (!normalizedFiles || normalizedFiles.length === 0) {
748+
if (!message.files?.length) {
750749
continue
751750
}
752751

753-
const userFiles = processFilesToUserFiles(
754-
normalizedFiles as RawFileInput[],
755-
requestId,
756-
logger
757-
)
758-
if (userFiles.length === 0) {
759-
throw new Error('Files must include at least one valid file object')
760-
}
761-
762-
const hydratedFiles = await hydrateUserFilesWithBase64(userFiles, {
752+
const hydratedFiles = await hydrateUserFilesWithBase64(message.files, {
763753
requestId,
764754
workspaceId: ctx.workspaceId,
765755
workflowId: ctx.workflowId,
@@ -774,7 +764,7 @@ export class AgentBlockHandler implements BlockHandler {
774764
const missingFile = hydratedFiles.find((file) => !file.base64)
775765
if (missingFile) {
776766
throw new Error(
777-
`File "${missingFile.name}" could not be read for provider "${providerId}". Make sure the file is still accessible and under the provider attachment size limit.`
767+
`File "${missingFile.name}" could not be read for provider "${providerId}". The file may exceed the attachment size limit or may no longer be accessible.`
778768
)
779769
}
780770

apps/sim/executor/handlers/agent/memory.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe('Memory', () => {
179179
})
180180

181181
describe('sanitizeMessageForStorage', () => {
182-
it('should strip file payloads and provider-only fields before memory persistence', () => {
182+
it('should strip file payloads but preserve tool-call fields before memory persistence', () => {
183183
const message: Message = {
184184
role: 'user',
185185
content: 'Analyze this file',
@@ -202,6 +202,7 @@ describe('Memory', () => {
202202
role: 'user',
203203
content: 'Analyze this file',
204204
executionId: 'exec-1',
205+
tool_calls: [{ id: 'call-1' }],
205206
})
206207
})
207208
})

apps/sim/executor/handlers/agent/memory.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,8 @@ export class Memory {
123123
}
124124

125125
private sanitizeMessageForStorage(message: Message): Message {
126-
return {
127-
role: message.role,
128-
content: message.content,
129-
...(message.executionId && { executionId: message.executionId }),
130-
}
126+
const { files: _files, ...messageWithoutFiles } = message
127+
return messageWithoutFiles
131128
}
132129

133130
private applyTokenWindow(messages: Message[], maxTokens: number, model?: string): Message[] {

apps/sim/lib/api/contracts/workflows.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { defineRouteContract } from '@/lib/api/contracts/types'
33
import { getNextWorkflowColor } from '@/lib/workflows/colors'
44

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

715
const workflowPositionSchema = z.object({
816
x: z.number(),
@@ -336,7 +344,7 @@ export const executeWorkflowBodySchema = z.object({
336344
includeFileBase64: z.boolean().optional().default(true),
337345
base64MaxBytes: z.number().int().positive().optional(),
338346
workflowStateOverride: workflowStateSchema.optional(),
339-
executionId: z.string().optional(),
347+
executionId: executionIdSchema.optional(),
340348
triggerBlockId: z.string().optional(),
341349
startBlockId: z.string().optional(),
342350
stopAfterBlockId: z.string().optional(),

0 commit comments

Comments
 (0)