-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(file-block): fix get op #4590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,21 @@ export const fileManageAppendBodySchema = z.object({ | |
| content: z.string({ error: 'content is required for append operation' }), | ||
| }) | ||
|
|
||
| export const fileManageBodySchema = z.discriminatedUnion('operation', [ | ||
| export const fileManageGetBodySchema = z | ||
| .object({ | ||
| operation: z.literal('get'), | ||
| workspaceId: z.string().min(1).optional(), | ||
| fileId: z.string().min(1).optional(), | ||
| fileInput: z.any().optional(), | ||
| }) | ||
| .refine((data) => data.fileId !== undefined || data.fileInput !== undefined, { | ||
| message: 'Either fileId or fileInput is required for get operation', | ||
| }) | ||
|
|
||
| export const fileManageBodySchema = z.union([ | ||
| fileManageWriteBodySchema, | ||
| fileManageAppendBodySchema, | ||
| fileManageGetBodySchema, | ||
| ]) | ||
|
Comment on lines
+36
to
40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The schema was changed from |
||
|
|
||
| export const fileManageContract = defineRouteContract({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type { ToolConfig, ToolResponse, WorkflowToolExecutionContext } from '@/tools/types' | ||
|
|
||
| interface FileGetParams { | ||
| fileId?: string | ||
| fileInput?: unknown | ||
| workspaceId?: string | ||
| _context?: WorkflowToolExecutionContext | ||
| } | ||
|
|
||
| export const fileGetTool: ToolConfig<FileGetParams, ToolResponse> = { | ||
| id: 'file_get', | ||
| name: 'File Get', | ||
| description: 'Get a workspace file object from a selected file or canonical workspace file ID.', | ||
| version: '1.0.0', | ||
|
|
||
| params: { | ||
| fileId: { | ||
| type: 'string', | ||
| required: false, | ||
| visibility: 'user-or-llm', | ||
| description: 'Canonical workspace file ID.', | ||
| }, | ||
| fileInput: { | ||
| type: 'file', | ||
| required: false, | ||
| visibility: 'user-only', | ||
| description: 'Selected workspace file object.', | ||
| }, | ||
| }, | ||
|
|
||
| request: { | ||
| url: '/api/tools/file/manage', | ||
| method: 'POST', | ||
| headers: () => ({ 'Content-Type': 'application/json' }), | ||
| body: (params) => ({ | ||
| operation: 'get', | ||
| fileId: params.fileId, | ||
| fileInput: params.fileInput, | ||
| workspaceId: params.workspaceId || params._context?.workspaceId, | ||
| }), | ||
| }, | ||
|
|
||
| transformResponse: async (response) => { | ||
| const data = await response.json() | ||
| if (!response.ok || !data.success) { | ||
| return { success: false, output: {}, error: data.error || 'Failed to get file' } | ||
| } | ||
| return { success: true, output: data.data } | ||
| }, | ||
|
|
||
| outputs: { | ||
| file: { type: 'file', description: 'Workspace file object' }, | ||
| }, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.refine()predicate uses strict!== undefined, so{ operation: 'get', fileInput: null }passes Zod validation (sincenull !== undefined). The route handler catches this downstream with its own empty-ID check, but the schema's intent is to block such payloads early. Using!= null(loose inequality) or an explicit truthiness check would keep the two layers consistent.