Repository navigation
Expand file tree
/
Copy pathwrite.ts
More file actions
71 lines (65 loc) · 2.13 KB
/
Copy pathwrite.ts
File metadata and controls
71 lines (65 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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,
}),
secretProvenance: {
request: () => [{ key: 'content', inputPaths: [['content']] }],
},
},
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 },
},
}