Files
dify/web/types/sandbox-file.ts
yyh 166b4a5a2b feat(sandbox): add sandbox file API service layer
- Add types for sandbox file API (SandboxFileNode, SandboxFileDownloadTicket)
- Add oRPC contracts for listFiles and downloadFile endpoints
- Add TanStack Query hooks (useGetSandboxFiles, useDownloadSandboxFile)
- Add useSandboxFilesTree hook with flat-to-tree conversion
2026-01-26 15:40:27 +08:00

72 lines
1.8 KiB
TypeScript

/**
* Sandbox File Types
*
* Types for sandbox file API - file listing and download operations.
* These files are generated by agent during test runs and may be cleared later.
*/
/**
* Sandbox file node from API (flat format)
* Returned by GET /sandboxes/{sandbox_id}/files
*/
export type SandboxFileNode = {
/** Relative path (POSIX format), e.g. "folder/file.txt" */
path: string
/** Whether this is a directory */
is_dir: boolean
/** File size in bytes (null for directories) */
size: number | null
/** Modification timestamp in seconds (null for some directories) */
mtime: number | null
}
/**
* Download ticket returned by POST /sandboxes/{sandbox_id}/files/download
*/
export type SandboxFileDownloadTicket = {
/** Signed download URL */
download_url: string
/** Expiration time in seconds */
expires_in: number
/** Export ID (16-char hex) */
export_id: string
}
/**
* Tree node for frontend rendering (converted from flat list)
*/
export type SandboxFileTreeNode = {
/** Unique ID (uses path as ID) */
id: string
/** File/folder name extracted from path */
name: string
/** Full relative path */
path: string
/** Node type for compatibility with existing tree components */
node_type: 'file' | 'folder'
/** File size in bytes (null for directories) */
size: number | null
/** Modification timestamp */
mtime: number | null
/** Child nodes (for folders) */
children: SandboxFileTreeNode[]
}
/**
* Request payload for listing files
*/
export type SandboxFileListQuery = {
/** Workspace-relative path, defaults to "." */
path?: string
/** Whether to list recursively */
recursive?: boolean
}
/**
* Request payload for downloading a file
*/
export type SandboxFileDownloadRequest = {
/** Workspace-relative file path */
path: string
}