Skip to content

Commit 5e3ed27

Browse files
feat(file): include public share status in File read output
The read operation now attaches each workspace file's public share status as a "share" field (the share record, or null when not shared), batch-fetched via getSharesForResources to avoid N+1. Picker/upload input files have no canonical id and carry share: null.
1 parent 4554df9 commit 5e3ed27

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

apps/sim/app/api/tools/file/manage/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1717
import { isSupportedFileType, parseBuffer } from '@/lib/file-parsers'
1818
import {
1919
getShareForResource,
20+
getSharesForResources,
2021
ShareValidationError,
2122
upsertFileShare,
2223
} from '@/lib/public-shares/share-manager'
@@ -417,12 +418,16 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
417418
)
418419
}
419420

421+
// Attach each workspace file's public share status (batched to avoid N+1).
422+
// Picker/upload input files have no canonical id, so they carry no share.
423+
const shares = await getSharesForResources('file', selectedFileIds)
420424
const userFiles = files
421425
.map((file) => workspaceFileToUserFile(file))
422426
.filter((file): file is NonNullable<ReturnType<typeof workspaceFileToUserFile>> =>
423427
Boolean(file)
424428
)
425-
.concat(selectedInputFiles)
429+
.map((file) => ({ ...file, share: shares.get(file.id) ?? null }))
430+
.concat(selectedInputFiles.map((file) => ({ ...file, share: null })))
426431

427432
logger.info('Files retrieved', {
428433
count: userFiles.length,

apps/sim/blocks/blocks/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ export const FileV5Block: BlockConfig<FileParserV3Output> = {
13611361
files: {
13621362
type: 'file[]',
13631363
description:
1364-
'Workspace file objects (read), fetched file objects (fetch), the compressed archive (compress), or extracted files (decompress)',
1364+
'Workspace file objects (read; each includes a "share" field with its public share status, null when not shared), fetched file objects (fetch), the compressed archive (compress), or extracted files (decompress)',
13651365
},
13661366
contents: {
13671367
type: 'array',

apps/sim/tools/file/get.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ const createFileReadTool = (config: {
6060
},
6161

6262
outputs: {
63-
files: { type: 'file[]', description: 'Workspace file objects' },
63+
files: {
64+
type: 'file[]',
65+
description:
66+
'Workspace file objects, each with its public share status in a "share" field (null when the file is not shared)',
67+
},
6468
},
6569
})
6670

0 commit comments

Comments
 (0)