Files
simstudioai--sim/apps/sim/tools/daytona/download_file.ts
T
wehub-resource-sync d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

95 lines
2.8 KiB
TypeScript

import type { DaytonaDownloadFileParams, DaytonaDownloadFileResponse } from '@/tools/daytona/types'
import { daytonaToolboxUrl, extractDaytonaError } from '@/tools/daytona/utils'
import type { ToolConfig } from '@/tools/types'
const MAX_DOWNLOAD_SIZE_BYTES = 100 * 1024 * 1024
function downloadSizeError(bytes: number): Error {
const sizeMB = (bytes / (1024 * 1024)).toFixed(2)
return new Error(`File size (${sizeMB}MB) exceeds download limit of 100MB`)
}
export const daytonaDownloadFileTool: ToolConfig<
DaytonaDownloadFileParams,
DaytonaDownloadFileResponse
> = {
id: 'daytona_download_file',
name: 'Daytona Download File',
description: 'Download a file from a Daytona sandbox',
version: '1.0.0',
params: {
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'Daytona API key',
},
sandboxId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'ID of the sandbox to download the file from',
},
filePath: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Path of the file in the sandbox',
},
},
request: {
url: (params) =>
daytonaToolboxUrl(
params.sandboxId,
`/files/download?path=${encodeURIComponent(params.filePath.trim())}`
),
method: 'GET',
headers: (params) => ({
Authorization: `Bearer ${params.apiKey}`,
}),
},
transformResponse: async (response, params) => {
if (!response.ok) {
throw new Error(await extractDaytonaError(response, 'Failed to download file'))
}
const contentLength = Number(response.headers.get('content-length'))
if (Number.isFinite(contentLength) && contentLength > MAX_DOWNLOAD_SIZE_BYTES) {
throw downloadSizeError(contentLength)
}
const mimeType = response.headers.get('content-type') || 'application/octet-stream'
const fileName = params?.filePath.trim().split('/').filter(Boolean).pop() || 'download'
const arrayBuffer = await response.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
if (buffer.length > MAX_DOWNLOAD_SIZE_BYTES) {
throw downloadSizeError(buffer.length)
}
return {
success: true,
output: {
file: {
name: fileName,
mimeType,
data: buffer.toString('base64'),
size: buffer.length,
},
name: fileName,
mimeType,
size: buffer.length,
},
}
},
outputs: {
file: { type: 'file', description: 'Downloaded file stored in execution files' },
name: { type: 'string', description: 'Name of the downloaded file' },
mimeType: { type: 'string', description: 'MIME type of the downloaded file' },
size: { type: 'number', description: 'Size of the downloaded file in bytes' },
},
}