chore: import upstream snapshot with attribution
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
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) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
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
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import type { ToolConfig, ToolResponse, WorkflowToolExecutionContext } from '@/tools/types'
|
||||
|
||||
interface FileAppendParams {
|
||||
fileName: string
|
||||
content: string
|
||||
workspaceId?: string
|
||||
_context?: WorkflowToolExecutionContext
|
||||
}
|
||||
|
||||
export const fileAppendTool: ToolConfig<FileAppendParams, ToolResponse> = {
|
||||
id: 'file_append',
|
||||
name: 'File Append',
|
||||
description:
|
||||
'Append content to an existing workspace file. The file must already exist. Content is added to the end of the file.',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
fileName: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Name of an existing workspace file to append to.',
|
||||
},
|
||||
content: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The text content to append to the file.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/file/manage',
|
||||
method: 'POST',
|
||||
headers: () => ({ 'Content-Type': 'application/json' }),
|
||||
body: (params) => ({
|
||||
operation: 'append',
|
||||
fileName: params.fileName,
|
||||
content: params.content,
|
||||
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 append to file' }
|
||||
}
|
||||
return { success: true, output: data.data }
|
||||
},
|
||||
|
||||
outputs: {
|
||||
id: { type: 'string', description: 'File ID' },
|
||||
name: { type: 'string', description: 'File name' },
|
||||
size: { type: 'number', description: 'File size in bytes' },
|
||||
url: { type: 'string', description: 'URL to access the file', optional: true },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { fileCompressTool, fileDecompressTool } from '@/tools/file/compress'
|
||||
|
||||
describe('fileCompressTool', () => {
|
||||
it('builds a compress request body from file IDs and archive name', () => {
|
||||
const body = fileCompressTool.request.body?.({
|
||||
fileId: ['wf_a', 'wf_b'],
|
||||
archiveName: 'documents.zip',
|
||||
_context: { workspaceId: 'ws_1' },
|
||||
} as Parameters<NonNullable<typeof fileCompressTool.request.body>>[0])
|
||||
|
||||
expect(body).toMatchObject({
|
||||
operation: 'compress',
|
||||
fileId: ['wf_a', 'wf_b'],
|
||||
archiveName: 'documents.zip',
|
||||
workspaceId: 'ws_1',
|
||||
})
|
||||
})
|
||||
|
||||
it('forwards a selected file object when no IDs are provided', () => {
|
||||
const fileInput = { id: 'wf_c', name: 'report.pdf' }
|
||||
const body = fileCompressTool.request.body?.({
|
||||
fileInput,
|
||||
workspaceId: 'ws_2',
|
||||
} as Parameters<NonNullable<typeof fileCompressTool.request.body>>[0])
|
||||
|
||||
expect(body).toMatchObject({
|
||||
operation: 'compress',
|
||||
fileInput,
|
||||
workspaceId: 'ws_2',
|
||||
})
|
||||
})
|
||||
|
||||
it('returns the compressed archive on success', async () => {
|
||||
const archive = {
|
||||
id: 'wf_zip',
|
||||
name: 'archive.zip',
|
||||
size: 1024,
|
||||
url: 'https://example.com/archive.zip',
|
||||
type: 'application/zip',
|
||||
key: 'workspace/ws_1/archive.zip',
|
||||
}
|
||||
|
||||
const result = await fileCompressTool.transformResponse?.(
|
||||
Response.json({
|
||||
success: true,
|
||||
data: {
|
||||
id: archive.id,
|
||||
name: archive.name,
|
||||
size: archive.size,
|
||||
url: archive.url,
|
||||
files: [archive],
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
expect(result).toMatchObject({
|
||||
success: true,
|
||||
output: { id: 'wf_zip', name: 'archive.zip', size: 1024, files: [archive] },
|
||||
})
|
||||
})
|
||||
|
||||
it('propagates route failures as tool failures', async () => {
|
||||
const result = await fileCompressTool.transformResponse?.(
|
||||
Response.json({ success: false, error: 'Combined input is too large to compress.' })
|
||||
)
|
||||
|
||||
expect(result).toMatchObject({
|
||||
success: false,
|
||||
error: 'Combined input is too large to compress.',
|
||||
output: {},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('fileDecompressTool', () => {
|
||||
it('builds a decompress request body from a file ID', () => {
|
||||
const body = fileDecompressTool.request.body?.({
|
||||
fileId: 'wf_zip',
|
||||
_context: { workspaceId: 'ws_1' },
|
||||
} as Parameters<NonNullable<typeof fileDecompressTool.request.body>>[0])
|
||||
|
||||
expect(body).toMatchObject({
|
||||
operation: 'decompress',
|
||||
fileId: 'wf_zip',
|
||||
workspaceId: 'ws_1',
|
||||
})
|
||||
})
|
||||
|
||||
it('returns the extracted files on success', async () => {
|
||||
const extracted = [
|
||||
{ id: 'wf_a', name: 'a.txt', url: 'https://example.com/a.txt', key: 'k/a.txt' },
|
||||
{ id: 'wf_b', name: 'b.txt', url: 'https://example.com/b.txt', key: 'k/b.txt' },
|
||||
]
|
||||
|
||||
const result = await fileDecompressTool.transformResponse?.(
|
||||
Response.json({ success: true, data: { files: extracted } })
|
||||
)
|
||||
|
||||
expect(result).toMatchObject({
|
||||
success: true,
|
||||
output: { files: extracted },
|
||||
})
|
||||
})
|
||||
|
||||
it('propagates route failures as tool failures', async () => {
|
||||
const result = await fileDecompressTool.transformResponse?.(
|
||||
Response.json({ success: false, error: '"data.txt" is not a valid .zip archive' })
|
||||
)
|
||||
|
||||
expect(result).toMatchObject({
|
||||
success: false,
|
||||
error: '"data.txt" is not a valid .zip archive',
|
||||
output: {},
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,125 @@
|
||||
import type { ToolConfig, ToolResponse, WorkflowToolExecutionContext } from '@/tools/types'
|
||||
|
||||
interface FileCompressParams {
|
||||
fileId?: string | string[]
|
||||
fileInput?: unknown
|
||||
archiveName?: string
|
||||
workspaceId?: string
|
||||
_context?: WorkflowToolExecutionContext
|
||||
}
|
||||
|
||||
export const fileCompressTool: ToolConfig<FileCompressParams, ToolResponse> = {
|
||||
id: 'file_compress',
|
||||
name: 'File Compress',
|
||||
description:
|
||||
'Compress one or more workspace files into a single .zip archive stored in the workspace, for bundling files to download, transfer, or store.',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
fileId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Canonical workspace file ID, or an array of canonical workspace file IDs.',
|
||||
},
|
||||
fileInput: {
|
||||
type: 'file',
|
||||
required: false,
|
||||
visibility: 'user-only',
|
||||
description: 'Selected workspace file object, or an array of file objects.',
|
||||
},
|
||||
archiveName: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Name for the .zip archive (e.g., "documents.zip"). Defaults to the source file name when compressing a single file, otherwise "archive.zip".',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/file/manage',
|
||||
method: 'POST',
|
||||
headers: () => ({ 'Content-Type': 'application/json' }),
|
||||
body: (params) => ({
|
||||
operation: 'compress',
|
||||
fileId: params.fileId,
|
||||
fileInput: params.fileInput,
|
||||
archiveName: params.archiveName,
|
||||
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 compress files' }
|
||||
}
|
||||
return { success: true, output: data.data }
|
||||
},
|
||||
|
||||
outputs: {
|
||||
id: { type: 'string', description: 'Compressed archive file ID' },
|
||||
name: { type: 'string', description: 'Compressed archive file name' },
|
||||
size: { type: 'number', description: 'Compressed archive size in bytes' },
|
||||
url: { type: 'string', description: 'URL to access the compressed archive', optional: true },
|
||||
files: {
|
||||
type: 'file[]',
|
||||
description: 'Compressed archive file object, as a single-item array',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
interface FileDecompressParams {
|
||||
fileId?: string
|
||||
fileInput?: unknown
|
||||
workspaceId?: string
|
||||
_context?: WorkflowToolExecutionContext
|
||||
}
|
||||
|
||||
export const fileDecompressTool: ToolConfig<FileDecompressParams, ToolResponse> = {
|
||||
id: 'file_decompress',
|
||||
name: 'File Decompress',
|
||||
description:
|
||||
'Extract the contents of a .zip archive into the workspace, preserving the archive folder structure.',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
fileId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Canonical workspace file ID of the .zip archive to extract.',
|
||||
},
|
||||
fileInput: {
|
||||
type: 'file',
|
||||
required: false,
|
||||
visibility: 'user-only',
|
||||
description: 'Selected .zip archive file object.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/file/manage',
|
||||
method: 'POST',
|
||||
headers: () => ({ 'Content-Type': 'application/json' }),
|
||||
body: (params) => ({
|
||||
operation: 'decompress',
|
||||
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 decompress archive' }
|
||||
}
|
||||
return { success: true, output: data.data }
|
||||
},
|
||||
|
||||
outputs: {
|
||||
files: { type: 'file[]', description: 'Extracted workspace file objects' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
import type { ToolConfig, ToolResponse, WorkflowToolExecutionContext } from '@/tools/types'
|
||||
|
||||
interface FileGetParams {
|
||||
fileId?: string
|
||||
fileInput?: unknown
|
||||
workspaceId?: string
|
||||
_context?: WorkflowToolExecutionContext
|
||||
}
|
||||
|
||||
interface FileReadParams {
|
||||
fileId?: string | string[]
|
||||
fileInput?: unknown
|
||||
workspaceId?: string
|
||||
_context?: WorkflowToolExecutionContext
|
||||
}
|
||||
|
||||
const createFileReadTool = (config: {
|
||||
id: 'file_read'
|
||||
name: string
|
||||
description: string
|
||||
}): ToolConfig<FileReadParams, ToolResponse> => ({
|
||||
id: config.id,
|
||||
name: config.name,
|
||||
description: config.description,
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
fileId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Canonical workspace file ID, or an array of canonical workspace file IDs.',
|
||||
},
|
||||
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: 'read',
|
||||
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: {
|
||||
files: { type: 'file[]', description: 'Workspace file objects' },
|
||||
},
|
||||
})
|
||||
|
||||
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' },
|
||||
},
|
||||
}
|
||||
|
||||
export const fileReadTool = createFileReadTool({
|
||||
id: 'file_read',
|
||||
name: 'File Read',
|
||||
description: 'Read workspace file objects from selected files or canonical workspace file IDs.',
|
||||
})
|
||||
|
||||
interface FileGetContentParams {
|
||||
fileId?: string | string[]
|
||||
fileInput?: unknown
|
||||
workspaceId?: string
|
||||
_context?: WorkflowToolExecutionContext
|
||||
}
|
||||
|
||||
export const fileGetContentTool: ToolConfig<FileGetContentParams, ToolResponse> = {
|
||||
id: 'file_get_content',
|
||||
name: 'File Get Content',
|
||||
description:
|
||||
'Extract the text content of one or more workspace files from selected file objects or canonical workspace file IDs.',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
fileId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Canonical workspace file ID, or an array of canonical workspace file IDs.',
|
||||
},
|
||||
fileInput: {
|
||||
type: 'file',
|
||||
required: false,
|
||||
visibility: 'user-only',
|
||||
description: 'Selected workspace file object, or an array of file objects.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/file/manage',
|
||||
method: 'POST',
|
||||
headers: () => ({ 'Content-Type': 'application/json' }),
|
||||
body: (params) => ({
|
||||
operation: 'content',
|
||||
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 read file content' }
|
||||
}
|
||||
return { success: true, output: data.data }
|
||||
},
|
||||
|
||||
outputs: {
|
||||
contents: {
|
||||
type: 'array',
|
||||
description: 'Array of file text contents, one entry per file in input order',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
fileFetchTool,
|
||||
fileParserTool,
|
||||
fileParserV2Tool,
|
||||
fileParserV3Tool,
|
||||
} from '@/tools/file/parser'
|
||||
|
||||
export { fileAppendTool } from '@/tools/file/append'
|
||||
export { fileCompressTool, fileDecompressTool } from '@/tools/file/compress'
|
||||
export { fileGetContentTool, fileGetTool, fileReadTool } from '@/tools/file/get'
|
||||
export { fileManageSharingTool } from '@/tools/file/manage-sharing'
|
||||
export { fileWriteTool } from '@/tools/file/write'
|
||||
|
||||
export const fileParseTool = fileParserTool
|
||||
export { fileFetchTool }
|
||||
export { fileParserV2Tool }
|
||||
export { fileParserV3Tool }
|
||||
@@ -0,0 +1,97 @@
|
||||
import type { ShareAuthType } from '@/lib/api/contracts/public-shares'
|
||||
import type { ToolConfig, ToolResponse, WorkflowToolExecutionContext } from '@/tools/types'
|
||||
|
||||
interface FileManageSharingParams {
|
||||
fileId?: string
|
||||
fileInput?: unknown
|
||||
isActive: boolean
|
||||
authType?: ShareAuthType
|
||||
password?: string
|
||||
allowedEmails?: string[]
|
||||
workspaceId?: string
|
||||
_context?: WorkflowToolExecutionContext
|
||||
}
|
||||
|
||||
export const fileManageSharingTool: ToolConfig<FileManageSharingParams, ToolResponse> = {
|
||||
id: 'file_manage_sharing',
|
||||
name: 'Manage Sharing',
|
||||
description:
|
||||
'Enable or disable the public share link for a workspace file, and set its access mode (public, password, email, or SSO). Idempotent: the public link stays stable across changes.',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
fileId: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Canonical ID of the workspace file to update sharing for.',
|
||||
},
|
||||
fileInput: {
|
||||
type: 'file',
|
||||
required: false,
|
||||
visibility: 'user-only',
|
||||
description: 'Selected workspace file object (from the file picker).',
|
||||
},
|
||||
isActive: {
|
||||
type: 'boolean',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'Whether the public link is enabled. Set to false to make the file private.',
|
||||
},
|
||||
authType: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Access mode for the link: "public", "password", "email", or "sso". Defaults to "public".',
|
||||
},
|
||||
password: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-only',
|
||||
description: 'Password to protect the link. Required when authType is "password".',
|
||||
},
|
||||
allowedEmails: {
|
||||
type: 'array',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'Allowed emails or "@domain" patterns. Required when authType is "email" or "sso".',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/file/manage',
|
||||
method: 'POST',
|
||||
headers: () => ({ 'Content-Type': 'application/json' }),
|
||||
body: (params) => ({
|
||||
operation: 'manage_sharing',
|
||||
fileId: params.fileId,
|
||||
fileInput: params.fileInput,
|
||||
isActive: params.isActive,
|
||||
authType: params.authType,
|
||||
password: params.password,
|
||||
allowedEmails: params.allowedEmails,
|
||||
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 update file sharing' }
|
||||
}
|
||||
return { success: true, output: data.data.share }
|
||||
},
|
||||
|
||||
outputs: {
|
||||
url: { type: 'string', description: 'Public share URL for the file' },
|
||||
isActive: { type: 'boolean', description: 'Whether the public link is enabled' },
|
||||
authType: { type: 'string', description: 'Access mode: public, password, email, or sso' },
|
||||
hasPassword: { type: 'boolean', description: 'Whether the share is password-protected' },
|
||||
allowedEmails: {
|
||||
type: 'array',
|
||||
description: 'Allowed emails/domains for email or SSO access',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* @vitest-environment node
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { fileFetchTool, fileParserTool, fileParserV3Tool } from '@/tools/file/parser'
|
||||
|
||||
describe('fileParserTool', () => {
|
||||
it('propagates parse route failures as tool failures', async () => {
|
||||
const result = await fileParserTool.transformResponse?.(
|
||||
Response.json({
|
||||
success: false,
|
||||
error: 'File is too large to parse safely.',
|
||||
filePath: 'https://example.com/big.pdf',
|
||||
})
|
||||
)
|
||||
|
||||
expect(result).toMatchObject({
|
||||
success: false,
|
||||
error: 'File is too large to parse safely.',
|
||||
output: {
|
||||
files: [],
|
||||
combinedContent: '',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('propagates parse route failures from V3 and file fetch tools', async () => {
|
||||
const body = {
|
||||
success: false,
|
||||
error: 'File is too large to parse safely.',
|
||||
filePath: 'https://example.com/big.pdf',
|
||||
}
|
||||
|
||||
await expect(fileParserV3Tool.transformResponse?.(Response.json(body))).resolves.toMatchObject({
|
||||
success: false,
|
||||
error: 'File is too large to parse safely.',
|
||||
output: {
|
||||
files: [],
|
||||
combinedContent: '',
|
||||
},
|
||||
})
|
||||
await expect(fileFetchTool.transformResponse?.(Response.json(body))).resolves.toMatchObject({
|
||||
success: false,
|
||||
error: 'File is too large to parse safely.',
|
||||
output: {
|
||||
files: [],
|
||||
combinedContent: '',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('omits failed entries from partial multi-file parse results', async () => {
|
||||
const result = await fileParserTool.transformResponse?.(
|
||||
Response.json({
|
||||
success: true,
|
||||
results: [
|
||||
{
|
||||
success: false,
|
||||
error: 'First file failed',
|
||||
filePath: 'bad.pdf',
|
||||
},
|
||||
{
|
||||
success: true,
|
||||
output: {
|
||||
content: 'ok',
|
||||
fileType: 'text/plain',
|
||||
size: 2,
|
||||
name: 'ok.txt',
|
||||
binary: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
|
||||
expect(result).toMatchObject({
|
||||
success: true,
|
||||
output: {
|
||||
files: [{ name: 'ok.txt', content: 'ok' }],
|
||||
combinedContent: 'ok',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('preserves partial multi-file parse successes from an oversized response', async () => {
|
||||
const result = await fileParserTool.transformResponse?.(
|
||||
Response.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Parsed file output is too large to return safely.',
|
||||
results: [
|
||||
{
|
||||
success: true,
|
||||
output: {
|
||||
content: 'ok',
|
||||
fileType: 'text/plain',
|
||||
size: 2,
|
||||
name: 'ok.txt',
|
||||
binary: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{ status: 413 }
|
||||
)
|
||||
)
|
||||
|
||||
expect(result).toMatchObject({
|
||||
success: true,
|
||||
error: 'Parsed file output is too large to return safely.',
|
||||
output: {
|
||||
files: [{ name: 'ok.txt', content: 'ok' }],
|
||||
combinedContent: 'ok',
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,400 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { inferContextFromKey } from '@/lib/uploads/utils/file-utils'
|
||||
import type { UserFile } from '@/executor/types'
|
||||
import type {
|
||||
FileParseResult,
|
||||
FileParserInput,
|
||||
FileParserOutput,
|
||||
FileParserOutputData,
|
||||
FileParserV3Output,
|
||||
FileParserV3OutputData,
|
||||
FileUploadInput,
|
||||
} from '@/tools/file/types'
|
||||
import { transformTable } from '@/tools/shared/table'
|
||||
import type { ToolConfig } from '@/tools/types'
|
||||
|
||||
const logger = createLogger('FileParserTool')
|
||||
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
||||
Boolean(value) && typeof value === 'object'
|
||||
|
||||
const isUserFile = (value: unknown): value is UserFile =>
|
||||
isRecord(value) &&
|
||||
typeof value.id === 'string' &&
|
||||
typeof value.name === 'string' &&
|
||||
typeof value.url === 'string' &&
|
||||
typeof value.size === 'number' &&
|
||||
typeof value.type === 'string' &&
|
||||
typeof value.key === 'string'
|
||||
|
||||
const isFileParseResult = (value: unknown): value is FileParseResult =>
|
||||
isRecord(value) &&
|
||||
typeof value.content === 'string' &&
|
||||
typeof value.fileType === 'string' &&
|
||||
typeof value.size === 'number' &&
|
||||
typeof value.name === 'string' &&
|
||||
typeof value.binary === 'boolean'
|
||||
|
||||
const normalizeHeaders = (headers: FileParserInput['headers']): Record<string, string> => {
|
||||
const transformed = transformTable(headers ?? null)
|
||||
return Object.entries(transformed).reduce(
|
||||
(acc, [key, value]) => {
|
||||
const headerName = key.trim()
|
||||
if (headerName && value !== undefined && value !== null) {
|
||||
acc[headerName] = String(value)
|
||||
}
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, string>
|
||||
)
|
||||
}
|
||||
|
||||
const normalizeFileParseResult = (value: unknown): FileParseResult => {
|
||||
if (isRecord(value) && isFileParseResult(value.output)) {
|
||||
return value.output
|
||||
}
|
||||
|
||||
if (isFileParseResult(value)) {
|
||||
return value
|
||||
}
|
||||
|
||||
const record = isRecord(value) ? value : {}
|
||||
const file = isUserFile(record.file) ? record.file : undefined
|
||||
const metadata = isRecord(record.metadata) ? record.metadata : undefined
|
||||
const fallback: FileParseResult = {
|
||||
content: typeof record.content === 'string' ? record.content : '',
|
||||
fileType: typeof record.fileType === 'string' ? record.fileType : '',
|
||||
size: typeof record.size === 'number' ? record.size : 0,
|
||||
name: typeof record.name === 'string' ? record.name : 'unknown',
|
||||
binary: typeof record.binary === 'boolean' ? record.binary : false,
|
||||
...(metadata && { metadata }),
|
||||
...(file && { file }),
|
||||
}
|
||||
|
||||
return Object.assign({}, record, fallback)
|
||||
}
|
||||
|
||||
interface ToolBodyParams extends Partial<FileParserInput> {
|
||||
files?: FileUploadInput[]
|
||||
_context?: {
|
||||
workspaceId?: string
|
||||
workflowId?: string
|
||||
executionId?: string
|
||||
}
|
||||
}
|
||||
|
||||
const parseFileParserResponse = async (response: Response): Promise<FileParserOutput> => {
|
||||
logger.info('Received response status:', response.status)
|
||||
|
||||
const result: unknown = await response.json()
|
||||
logger.info('Response parsed successfully')
|
||||
|
||||
// Handle multiple files response
|
||||
if (isRecord(result) && Array.isArray(result.results)) {
|
||||
logger.info('Processing multiple files response')
|
||||
|
||||
const failedResults = result.results.filter(
|
||||
(fileResult) => isRecord(fileResult) && fileResult.success === false
|
||||
)
|
||||
if (failedResults.length === result.results.length) {
|
||||
const firstError = failedResults.find(
|
||||
(fileResult) => isRecord(fileResult) && typeof fileResult.error === 'string'
|
||||
)
|
||||
return {
|
||||
success: false,
|
||||
output: {
|
||||
files: [],
|
||||
combinedContent: '',
|
||||
},
|
||||
error:
|
||||
isRecord(firstError) && typeof firstError.error === 'string'
|
||||
? firstError.error
|
||||
: 'Failed to parse files',
|
||||
}
|
||||
}
|
||||
|
||||
// Extract individual file results
|
||||
const fileResults: FileParseResult[] = result.results
|
||||
.filter((fileResult) => !(isRecord(fileResult) && fileResult.success === false))
|
||||
.map((fileResult) => normalizeFileParseResult(fileResult))
|
||||
|
||||
const processedFiles = fileResults.flatMap((file) => (file.file ? [file.file] : []))
|
||||
|
||||
// Combine all file contents with clear dividers
|
||||
const combinedContent = fileResults
|
||||
.map((file, index) => {
|
||||
const divider = `\n${'='.repeat(80)}\n`
|
||||
|
||||
return file.content + (index < fileResults.length - 1 ? divider : '')
|
||||
})
|
||||
.join('\n')
|
||||
|
||||
// Create the base output
|
||||
const output: FileParserOutputData = {
|
||||
files: fileResults,
|
||||
combinedContent,
|
||||
...(processedFiles.length > 0 && { processedFiles }),
|
||||
}
|
||||
const error = typeof result.error === 'string' ? result.error : undefined
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output,
|
||||
...(error ? { error } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
if (isRecord(result) && result.success === false) {
|
||||
return {
|
||||
success: false,
|
||||
output: {
|
||||
files: [],
|
||||
combinedContent: '',
|
||||
},
|
||||
error: typeof result.error === 'string' ? result.error : 'Failed to parse file',
|
||||
}
|
||||
}
|
||||
|
||||
// Handle single file response
|
||||
const fileOutput = normalizeFileParseResult(result)
|
||||
|
||||
logger.info('Successfully parsed file:', fileOutput.name || 'unknown')
|
||||
|
||||
// For a single file, create the output with just array format
|
||||
const output: FileParserOutputData = {
|
||||
files: [fileOutput],
|
||||
combinedContent:
|
||||
fileOutput.content ||
|
||||
(isRecord(result) && typeof result.content === 'string' ? result.content : ''),
|
||||
...(fileOutput.file && { processedFiles: [fileOutput.file] }),
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output,
|
||||
}
|
||||
}
|
||||
|
||||
export const fileParserTool: ToolConfig<FileParserInput, FileParserOutput> = {
|
||||
id: 'file_parser',
|
||||
name: 'File Parser',
|
||||
description: 'Parse one or more uploaded files or files from URLs (text, PDF, CSV, images, etc.)',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
filePath: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description: 'Path to the file(s). Can be a single path, URL, or an array of paths.',
|
||||
},
|
||||
file: {
|
||||
type: 'file',
|
||||
required: false,
|
||||
visibility: 'user-only',
|
||||
description: 'Uploaded file(s) to parse',
|
||||
},
|
||||
fileType: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'hidden',
|
||||
description: 'Type of file to parse (auto-detected if not specified)',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/files/parse',
|
||||
method: 'POST',
|
||||
headers: () => ({
|
||||
'Content-Type': 'application/json',
|
||||
}),
|
||||
body: (params: ToolBodyParams) => {
|
||||
logger.info('Request parameters received by tool body:', params)
|
||||
|
||||
if (!params) {
|
||||
logger.error('Tool body received no parameters')
|
||||
throw new Error('No parameters provided to tool body')
|
||||
}
|
||||
|
||||
let determinedFilePath: string | string[] | null = null
|
||||
const determinedFileType: string | undefined = params.fileType
|
||||
|
||||
const resolveFilePath = (fileInput: unknown): string | null => {
|
||||
if (!isRecord(fileInput)) return null
|
||||
|
||||
if (typeof fileInput.path === 'string') {
|
||||
return fileInput.path
|
||||
}
|
||||
|
||||
if (typeof fileInput.url === 'string') {
|
||||
return fileInput.url
|
||||
}
|
||||
|
||||
if (typeof fileInput.key === 'string') {
|
||||
const key = fileInput.key
|
||||
const context =
|
||||
typeof fileInput.context === 'string' ? fileInput.context : inferContextFromKey(key)
|
||||
return `/api/files/serve/${encodeURIComponent(key)}?context=${context}`
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
// Determine the file path(s) based on input parameters.
|
||||
// Precedence: direct filePath > file array > single file object > legacy files array
|
||||
// 1. Check for direct filePath (URL or single path from upload)
|
||||
if (params.filePath) {
|
||||
logger.info('Tool body found direct filePath:', params.filePath)
|
||||
determinedFilePath = params.filePath
|
||||
}
|
||||
// 2. Check for file upload (array)
|
||||
else if (params.file && Array.isArray(params.file) && params.file.length > 0) {
|
||||
logger.info('Tool body processing file array upload')
|
||||
const filePaths = params.file
|
||||
.map((file) => resolveFilePath(file))
|
||||
.filter(Boolean) as string[]
|
||||
if (filePaths.length !== params.file.length) {
|
||||
throw new Error('Invalid file input: One or more files are missing path or URL')
|
||||
}
|
||||
determinedFilePath = filePaths
|
||||
}
|
||||
// 3. Check for file upload (single object)
|
||||
else if (params.file && !Array.isArray(params.file)) {
|
||||
logger.info('Tool body processing single file object upload')
|
||||
const resolvedPath = resolveFilePath(params.file)
|
||||
if (!resolvedPath) {
|
||||
throw new Error('Invalid file input: Missing path or URL')
|
||||
}
|
||||
determinedFilePath = resolvedPath
|
||||
}
|
||||
// 4. Check for deprecated multiple files case (from older blocks?)
|
||||
else if (params.files && Array.isArray(params.files)) {
|
||||
logger.info('Tool body processing legacy files array:', params.files.length)
|
||||
if (params.files.length > 0) {
|
||||
const filePaths = params.files
|
||||
.map((file) => resolveFilePath(file))
|
||||
.filter(Boolean) as string[]
|
||||
if (filePaths.length !== params.files.length) {
|
||||
throw new Error('Invalid file input: One or more files are missing path or URL')
|
||||
}
|
||||
determinedFilePath = filePaths
|
||||
} else {
|
||||
logger.warn('Legacy files array provided but is empty')
|
||||
}
|
||||
}
|
||||
|
||||
// Final check if filePath was determined
|
||||
if (!determinedFilePath) {
|
||||
logger.error('Tool body could not determine filePath from parameters:', params)
|
||||
throw new Error('Missing required parameter: filePath')
|
||||
}
|
||||
|
||||
logger.info('Tool body determined filePath:', determinedFilePath)
|
||||
const headers = normalizeHeaders(params.headers)
|
||||
return {
|
||||
filePath: determinedFilePath,
|
||||
fileType: determinedFileType,
|
||||
...(Object.keys(headers).length > 0 && { headers }),
|
||||
workspaceId: params.workspaceId || params._context?.workspaceId,
|
||||
workflowId: params._context?.workflowId,
|
||||
executionId: params._context?.executionId,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
transformResponse: parseFileParserResponse,
|
||||
|
||||
outputs: {
|
||||
files: { type: 'array', description: 'Array of parsed files with content and metadata' },
|
||||
combinedContent: { type: 'string', description: 'Combined content of all parsed files' },
|
||||
processedFiles: { type: 'file[]', description: 'Array of UserFile objects for downstream use' },
|
||||
},
|
||||
}
|
||||
|
||||
export const fileParserV2Tool: ToolConfig<FileParserInput, FileParserOutput> = {
|
||||
id: 'file_parser_v2',
|
||||
name: 'File Parser',
|
||||
description: 'Parse one or more uploaded files or files from URLs (text, PDF, CSV, images, etc.)',
|
||||
version: '2.0.0',
|
||||
|
||||
params: fileParserTool.params,
|
||||
request: fileParserTool.request,
|
||||
transformResponse: parseFileParserResponse,
|
||||
|
||||
outputs: {
|
||||
files: {
|
||||
type: 'array',
|
||||
description: 'Array of parsed files with content, metadata, and file properties',
|
||||
},
|
||||
combinedContent: {
|
||||
type: 'string',
|
||||
description: 'All file contents merged into a single text string',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const parseFileParserV3Response = async (response: Response): Promise<FileParserV3Output> => {
|
||||
const parsed = await parseFileParserResponse(response)
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
success: false,
|
||||
output: {
|
||||
files: [],
|
||||
combinedContent: '',
|
||||
},
|
||||
error: parsed.error,
|
||||
}
|
||||
}
|
||||
|
||||
const output = parsed.output as FileParserOutputData
|
||||
const files =
|
||||
Array.isArray(output.processedFiles) && output.processedFiles.length > 0
|
||||
? output.processedFiles
|
||||
: []
|
||||
|
||||
const cleanedOutput: FileParserV3OutputData = {
|
||||
files,
|
||||
combinedContent: output.combinedContent,
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
output: cleanedOutput,
|
||||
}
|
||||
}
|
||||
|
||||
export const fileParserV3Tool: ToolConfig<FileParserInput, FileParserV3Output> = {
|
||||
id: 'file_parser_v3',
|
||||
name: 'File Parser',
|
||||
description: 'Parse one or more uploaded files or files from URLs (text, PDF, CSV, images, etc.)',
|
||||
version: '3.0.0',
|
||||
params: fileParserTool.params,
|
||||
request: fileParserTool.request,
|
||||
transformResponse: parseFileParserV3Response,
|
||||
outputs: {
|
||||
files: { type: 'file[]', description: 'Parsed files as UserFile objects' },
|
||||
combinedContent: { type: 'string', description: 'Combined content of all parsed files' },
|
||||
},
|
||||
}
|
||||
|
||||
export const fileFetchTool: ToolConfig<FileParserInput, FileParserV3Output> = {
|
||||
id: 'file_fetch',
|
||||
name: 'File Fetch',
|
||||
description: 'Fetch and parse a file from a URL with optional custom headers.',
|
||||
version: '1.0.0',
|
||||
params: {
|
||||
...fileParserTool.params,
|
||||
headers: {
|
||||
type: 'object',
|
||||
required: false,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'HTTP headers to include when fetching URL-based files.',
|
||||
},
|
||||
},
|
||||
request: fileParserTool.request,
|
||||
transformResponse: parseFileParserV3Response,
|
||||
outputs: {
|
||||
files: { type: 'file[]', description: 'Fetched files as UserFile objects' },
|
||||
combinedContent: { type: 'string', description: 'Combined content of all fetched files' },
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import type { UserFile } from '@/executor/types'
|
||||
import type { TableRow, ToolResponse } from '@/tools/types'
|
||||
|
||||
export interface FileParserInput {
|
||||
filePath?: string | string[]
|
||||
file?: UserFile | UserFile[] | FileUploadInput | FileUploadInput[]
|
||||
fileType?: string
|
||||
headers?: TableRow[] | Record<string, unknown> | string | null
|
||||
workspaceId?: string
|
||||
workflowId?: string
|
||||
executionId?: string
|
||||
}
|
||||
|
||||
export interface FileUploadInput {
|
||||
path: string
|
||||
name?: string
|
||||
size?: number
|
||||
type?: string
|
||||
}
|
||||
|
||||
export interface FileParseResult {
|
||||
content: string
|
||||
fileType: string
|
||||
size: number
|
||||
name: string
|
||||
binary: boolean
|
||||
metadata?: Record<string, unknown>
|
||||
/** UserFile object for the raw file (stored in execution storage) */
|
||||
file?: UserFile
|
||||
}
|
||||
|
||||
export interface FileParserOutputData {
|
||||
/** Array of parsed file results with content and optional UserFile */
|
||||
files: FileParseResult[]
|
||||
/** Combined text content from all files */
|
||||
combinedContent: string
|
||||
/** Array of UserFile objects for downstream use (attachments, uploads, etc.) */
|
||||
processedFiles?: UserFile[]
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export interface FileParserOutput extends ToolResponse {
|
||||
output: FileParserOutputData
|
||||
}
|
||||
|
||||
export interface FileParserV3OutputData {
|
||||
/** Array of parsed files as UserFile objects */
|
||||
files: UserFile[]
|
||||
/** Combined text content from all files */
|
||||
combinedContent: string
|
||||
}
|
||||
|
||||
export interface FileParserV3Output extends ToolResponse {
|
||||
output: FileParserV3OutputData
|
||||
}
|
||||
|
||||
/** API response structure for single file parse */
|
||||
interface FileParseApiResponse {
|
||||
success: boolean
|
||||
output?: FileParseResult
|
||||
content?: string
|
||||
filePath?: string
|
||||
viewerUrl?: string | null
|
||||
error?: string
|
||||
}
|
||||
|
||||
/** API response structure for multiple file parse */
|
||||
interface FileParseApiMultiResponse {
|
||||
success: boolean
|
||||
results: Array<{
|
||||
success: boolean
|
||||
output?: FileParseResult
|
||||
filePath?: string
|
||||
viewerUrl?: string | null
|
||||
error?: string
|
||||
}>
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { ToolConfig, ToolResponse, WorkflowToolExecutionContext } from '@/tools/types'
|
||||
|
||||
interface FileWriteParams {
|
||||
fileName: string
|
||||
content: string
|
||||
contentType?: string
|
||||
workspaceId?: string
|
||||
_context?: WorkflowToolExecutionContext
|
||||
}
|
||||
|
||||
export const fileWriteTool: ToolConfig<FileWriteParams, ToolResponse> = {
|
||||
id: 'file_write',
|
||||
name: 'File Write',
|
||||
description:
|
||||
'Create a new workspace file. If a file with the same name already exists, a numeric suffix is added (e.g., "data (1).csv").',
|
||||
version: '1.0.0',
|
||||
|
||||
params: {
|
||||
fileName: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description:
|
||||
'File name (e.g., "data.csv"). If a file with this name exists, a numeric suffix is added automatically.',
|
||||
},
|
||||
content: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
visibility: 'user-or-llm',
|
||||
description: 'The text content to write to the file.',
|
||||
},
|
||||
contentType: {
|
||||
type: 'string',
|
||||
required: false,
|
||||
visibility: 'user-only',
|
||||
description:
|
||||
'MIME type for new files (e.g., "text/plain"). Auto-detected from file extension if omitted.',
|
||||
},
|
||||
},
|
||||
|
||||
request: {
|
||||
url: '/api/tools/file/manage',
|
||||
method: 'POST',
|
||||
headers: () => ({ 'Content-Type': 'application/json' }),
|
||||
body: (params) => ({
|
||||
operation: 'write',
|
||||
fileName: params.fileName,
|
||||
content: params.content,
|
||||
contentType: params.contentType,
|
||||
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 write file' }
|
||||
}
|
||||
return { success: true, output: data.data }
|
||||
},
|
||||
|
||||
outputs: {
|
||||
id: { type: 'string', description: 'File ID' },
|
||||
name: { type: 'string', description: 'File name' },
|
||||
size: { type: 'number', description: 'File size in bytes' },
|
||||
url: { type: 'string', description: 'URL to access the file', optional: true },
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user