@nestm/storage 0.1.0-alpha.0 → 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +264 -0
- package/README.md +724 -25
- package/SECURITY.md +101 -0
- package/dist/ai-sdk/ai-sdk-workspace-tools.d.ts +91 -0
- package/dist/ai-sdk/ai-sdk-workspace-tools.d.ts.map +1 -0
- package/dist/ai-sdk/ai-sdk-workspace-tools.js +491 -0
- package/dist/ai-sdk/ai-sdk-workspace-tools.js.map +1 -0
- package/dist/ai-sdk/index.d.ts +2 -0
- package/dist/ai-sdk/index.d.ts.map +1 -0
- package/dist/ai-sdk/index.js +2 -0
- package/dist/ai-sdk/index.js.map +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/files-sdk/files-sdk.driver.d.ts +85 -3
- package/dist/files-sdk/files-sdk.driver.d.ts.map +1 -1
- package/dist/files-sdk/files-sdk.driver.js +1437 -37
- package/dist/files-sdk/files-sdk.driver.js.map +1 -1
- package/dist/files-sdk/fs/index.d.ts +42 -0
- package/dist/files-sdk/fs/index.d.ts.map +1 -0
- package/dist/files-sdk/fs/index.js +1117 -0
- package/dist/files-sdk/fs/index.js.map +1 -0
- package/dist/files-sdk/index.d.ts +1 -1
- package/dist/files-sdk/index.d.ts.map +1 -1
- package/dist/files-sdk/index.js.map +1 -1
- package/dist/files-sdk/provider/index.d.ts +58 -0
- package/dist/files-sdk/provider/index.d.ts.map +1 -0
- package/dist/files-sdk/provider/index.js +147 -0
- package/dist/files-sdk/provider/index.js.map +1 -0
- package/dist/files-sdk/s3/construction-metadata.d.ts +9 -0
- package/dist/files-sdk/s3/construction-metadata.d.ts.map +1 -0
- package/dist/files-sdk/s3/construction-metadata.js +24 -0
- package/dist/files-sdk/s3/construction-metadata.js.map +1 -0
- package/dist/files-sdk/s3/index.d.ts +54 -0
- package/dist/files-sdk/s3/index.d.ts.map +1 -0
- package/dist/files-sdk/s3/index.js +1505 -0
- package/dist/files-sdk/s3/index.js.map +1 -0
- package/dist/gateway/index.d.ts +1 -1
- package/dist/gateway/index.d.ts.map +1 -1
- package/dist/gateway/index.js.map +1 -1
- package/dist/gateway/storage-gateway-fastify-parser.d.ts.map +1 -1
- package/dist/gateway/storage-gateway-fastify-parser.js.map +1 -1
- package/dist/gateway/storage-gateway.controller.d.ts +12 -11
- package/dist/gateway/storage-gateway.controller.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.controller.js +240 -70
- package/dist/gateway/storage-gateway.controller.js.map +1 -1
- package/dist/gateway/storage-gateway.guard.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.guard.js.map +1 -1
- package/dist/gateway/storage-gateway.module.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.module.js +60 -1
- package/dist/gateway/storage-gateway.module.js.map +1 -1
- package/dist/gateway/storage-gateway.tokens.d.ts +1 -0
- package/dist/gateway/storage-gateway.tokens.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.tokens.js +1 -0
- package/dist/gateway/storage-gateway.tokens.js.map +1 -1
- package/dist/gateway/storage-gateway.types.d.ts +53 -10
- package/dist/gateway/storage-gateway.types.d.ts.map +1 -1
- package/dist/gateway/storage-gateway.types.js.map +1 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/inject-storage.decorator.js.map +1 -1
- package/dist/storage-etag.d.ts +13 -0
- package/dist/storage-etag.d.ts.map +1 -0
- package/dist/storage-etag.js +31 -0
- package/dist/storage-etag.js.map +1 -0
- package/dist/storage-upload-control.d.ts.map +1 -1
- package/dist/storage.client.d.ts +15 -3
- package/dist/storage.client.d.ts.map +1 -1
- package/dist/storage.client.js +204 -2
- package/dist/storage.client.js.map +1 -1
- package/dist/storage.driver.d.ts +28 -1
- package/dist/storage.driver.d.ts.map +1 -1
- package/dist/storage.driver.js.map +1 -1
- package/dist/storage.error.d.ts +17 -10
- package/dist/storage.error.d.ts.map +1 -1
- package/dist/storage.error.js +47 -1
- package/dist/storage.error.js.map +1 -1
- package/dist/storage.module.d.ts.map +1 -1
- package/dist/storage.module.js.map +1 -1
- package/dist/storage.service.d.ts.map +1 -1
- package/dist/storage.service.js +28 -3
- package/dist/storage.service.js.map +1 -1
- package/dist/storage.tokens.js.map +1 -1
- package/dist/storage.types.d.ts +150 -1
- package/dist/storage.types.d.ts.map +1 -1
- package/dist/storage.types.js.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/provider-conformance.d.ts +65 -0
- package/dist/testing/provider-conformance.d.ts.map +1 -0
- package/dist/testing/provider-conformance.js +869 -0
- package/dist/testing/provider-conformance.js.map +1 -0
- package/dist/workspace/index.d.ts +5 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +5 -0
- package/dist/workspace/index.js.map +1 -0
- package/dist/workspace/storage-workspace.cursor.d.ts +71 -0
- package/dist/workspace/storage-workspace.cursor.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.cursor.js +408 -0
- package/dist/workspace/storage-workspace.cursor.js.map +1 -0
- package/dist/workspace/storage-workspace.d.ts +6 -0
- package/dist/workspace/storage-workspace.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.error.d.ts +32 -0
- package/dist/workspace/storage-workspace.error.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.error.js +75 -0
- package/dist/workspace/storage-workspace.error.js.map +1 -0
- package/dist/workspace/storage-workspace.js +849 -0
- package/dist/workspace/storage-workspace.js.map +1 -0
- package/dist/workspace/storage-workspace.path.d.ts +9 -0
- package/dist/workspace/storage-workspace.path.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.path.js +68 -0
- package/dist/workspace/storage-workspace.path.js.map +1 -0
- package/dist/workspace/storage-workspace.types.d.ts +123 -0
- package/dist/workspace/storage-workspace.types.d.ts.map +1 -0
- package/dist/workspace/storage-workspace.types.js +22 -0
- package/dist/workspace/storage-workspace.types.js.map +1 -0
- package/package.json +103 -35
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { tool } from 'ai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { STORAGE_WORKSPACE_MAX_CURSOR_BYTES, isStorageWorkspaceError, } from '../workspace/index.js';
|
|
4
|
+
import { StorageErrorCode, isStorageError, } from '../storage.error.js';
|
|
5
|
+
import { isCanonicalStorageEtag } from '../storage-etag.js';
|
|
6
|
+
export const AI_SDK_WORKSPACE_TOOL_NAMES = [
|
|
7
|
+
'workspace_list',
|
|
8
|
+
'workspace_stat',
|
|
9
|
+
'workspace_read_file',
|
|
10
|
+
'workspace_search',
|
|
11
|
+
'workspace_write_file',
|
|
12
|
+
'workspace_copy_file',
|
|
13
|
+
'workspace_move_file',
|
|
14
|
+
'workspace_delete_file',
|
|
15
|
+
];
|
|
16
|
+
const SAFE_ERROR_MESSAGES = {
|
|
17
|
+
[StorageErrorCode.NOT_FOUND]: 'The requested workspace path was not found.',
|
|
18
|
+
[StorageErrorCode.UNAUTHORIZED]: 'This operation is not permitted in the workspace.',
|
|
19
|
+
[StorageErrorCode.CONFLICT]: 'The operation conflicts with current workspace state. Inspect the affected paths before retrying.',
|
|
20
|
+
[StorageErrorCode.READ_ONLY]: 'This operation is not permitted in the workspace.',
|
|
21
|
+
[StorageErrorCode.INVALID_ARGUMENT]: 'The workspace tool input was rejected.',
|
|
22
|
+
[StorageErrorCode.NOT_SUPPORTED]: 'This workspace operation is not supported by the configured storage.',
|
|
23
|
+
[StorageErrorCode.ABORTED]: 'The workspace operation was aborted.',
|
|
24
|
+
[StorageErrorCode.TIMEOUT]: 'The workspace operation timed out.',
|
|
25
|
+
[StorageErrorCode.LIMIT_EXCEEDED]: 'The workspace operation exceeded a configured limit.',
|
|
26
|
+
[StorageErrorCode.PROVIDER]: 'The workspace operation failed.',
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Safe error exposed at the AI tool boundary. It deliberately carries no
|
|
30
|
+
* provider error, storage key, mount prefix, store name, or cause. Applied
|
|
31
|
+
* reconciliation metadata is retained so callers do not blindly retry a
|
|
32
|
+
* mutation that may already have committed.
|
|
33
|
+
*/
|
|
34
|
+
export class AiSdkWorkspaceToolError extends Error {
|
|
35
|
+
code;
|
|
36
|
+
constructor(code, options = {}) {
|
|
37
|
+
super(SAFE_ERROR_MESSAGES[code]);
|
|
38
|
+
this.name = 'AiSdkWorkspaceToolError';
|
|
39
|
+
this.code = code;
|
|
40
|
+
if (options.applied === true) {
|
|
41
|
+
this.applied = true;
|
|
42
|
+
if (options.appliedEtag !== undefined &&
|
|
43
|
+
isCanonicalStorageEtag(options.appliedEtag)) {
|
|
44
|
+
this.appliedEtag = options.appliedEtag;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const mutationToolNames = new Set([
|
|
50
|
+
'workspace_write_file',
|
|
51
|
+
'workspace_copy_file',
|
|
52
|
+
'workspace_move_file',
|
|
53
|
+
'workspace_delete_file',
|
|
54
|
+
]);
|
|
55
|
+
const utf8Encoder = new TextEncoder();
|
|
56
|
+
const forbiddenUnicodeCharacter = /\p{C}/u;
|
|
57
|
+
const workspaceCursor = /^[A-Za-z0-9._-]+$/u;
|
|
58
|
+
const windowsDeviceName = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/iu;
|
|
59
|
+
function isLogicalPath(value) {
|
|
60
|
+
if (value.length === 0 ||
|
|
61
|
+
value.startsWith('/') ||
|
|
62
|
+
value.endsWith('/') ||
|
|
63
|
+
value !== value.normalize('NFC') ||
|
|
64
|
+
value.includes('\\') ||
|
|
65
|
+
forbiddenUnicodeCharacter.test(value)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return value
|
|
69
|
+
.split('/')
|
|
70
|
+
.every((segment) => segment.length > 0 &&
|
|
71
|
+
segment !== '.' &&
|
|
72
|
+
segment !== '..' &&
|
|
73
|
+
!segment.includes(':') &&
|
|
74
|
+
!segment.endsWith('.') &&
|
|
75
|
+
!segment.endsWith(' ') &&
|
|
76
|
+
!windowsDeviceName.test(segment));
|
|
77
|
+
}
|
|
78
|
+
function logicalPath(label, maxBytes) {
|
|
79
|
+
return z
|
|
80
|
+
.string()
|
|
81
|
+
.min(1)
|
|
82
|
+
.refine(isLogicalPath, {
|
|
83
|
+
message: `${label} must be a portable, NFC-normalized, relative POSIX workspace path.`,
|
|
84
|
+
})
|
|
85
|
+
.refine((value) => utf8Encoder.encode(value).byteLength <= maxBytes, {
|
|
86
|
+
message: `${label} exceeds the ${maxBytes}-byte workspace path limit.`,
|
|
87
|
+
})
|
|
88
|
+
.describe(`${label}. Use an NFC-normalized relative POSIX path inside the mounted workspace. Empty, dot, parent, colon, trailing dot or space, and Windows reserved device segments are forbidden.`);
|
|
89
|
+
}
|
|
90
|
+
function searchQuery(maxBytes) {
|
|
91
|
+
return z
|
|
92
|
+
.string()
|
|
93
|
+
.min(1)
|
|
94
|
+
.refine((value) => !value.includes('\\') && !forbiddenUnicodeCharacter.test(value), { message: 'Search query contains forbidden characters.' })
|
|
95
|
+
.refine((value) => utf8Encoder.encode(value).byteLength <= maxBytes, {
|
|
96
|
+
message: `Search query exceeds the ${maxBytes}-byte workspace limit.`,
|
|
97
|
+
})
|
|
98
|
+
.describe('Path pattern or text to find inside the mounted workspace.');
|
|
99
|
+
}
|
|
100
|
+
function boundedEtag() {
|
|
101
|
+
return z
|
|
102
|
+
.string()
|
|
103
|
+
.refine(isCanonicalStorageEtag, {
|
|
104
|
+
message: 'ETag must be a canonical bare value of at most 1,024 bytes.',
|
|
105
|
+
})
|
|
106
|
+
.describe('Exact canonical bare ETag returned by the latest workspace stat or read.');
|
|
107
|
+
}
|
|
108
|
+
function continuationCursor(description, maxBytes) {
|
|
109
|
+
return z
|
|
110
|
+
.string()
|
|
111
|
+
.min(1)
|
|
112
|
+
.max(Math.min(STORAGE_WORKSPACE_MAX_CURSOR_BYTES, maxBytes))
|
|
113
|
+
.regex(workspaceCursor, 'Cursor must be the bounded opaque token returned by the workspace.')
|
|
114
|
+
.optional()
|
|
115
|
+
.describe(description);
|
|
116
|
+
}
|
|
117
|
+
function positiveIntegerAtMost(maximum, description) {
|
|
118
|
+
return z
|
|
119
|
+
.number()
|
|
120
|
+
.int()
|
|
121
|
+
.positive()
|
|
122
|
+
.max(maximum)
|
|
123
|
+
.optional()
|
|
124
|
+
.describe(description);
|
|
125
|
+
}
|
|
126
|
+
function operationOptions(signal) {
|
|
127
|
+
return signal === undefined ? {} : { signal };
|
|
128
|
+
}
|
|
129
|
+
function resolveApproval(toolName, config) {
|
|
130
|
+
return typeof config === 'boolean' ? config : (config[toolName] ?? true);
|
|
131
|
+
}
|
|
132
|
+
function resolveReadLimit(workspace, requested) {
|
|
133
|
+
const workspaceLimit = workspace.limits.maxReadBytes;
|
|
134
|
+
if (!Number.isSafeInteger(workspaceLimit) || workspaceLimit <= 0) {
|
|
135
|
+
throw new RangeError('workspace.limits.maxReadBytes must be a positive safe integer.');
|
|
136
|
+
}
|
|
137
|
+
if (requested !== undefined &&
|
|
138
|
+
(!Number.isSafeInteger(requested) || requested <= 0)) {
|
|
139
|
+
throw new RangeError('maxReadBytes must be a positive safe integer.');
|
|
140
|
+
}
|
|
141
|
+
return Math.min(requested ?? workspaceLimit, workspaceLimit);
|
|
142
|
+
}
|
|
143
|
+
function sanitizeToolError(error, signal) {
|
|
144
|
+
if (error instanceof AiSdkWorkspaceToolError) {
|
|
145
|
+
return error;
|
|
146
|
+
}
|
|
147
|
+
const reconciliation = isStorageWorkspaceError(error) || isStorageError(error)
|
|
148
|
+
? {
|
|
149
|
+
applied: error.applied,
|
|
150
|
+
...(error.appliedEtag !== undefined && {
|
|
151
|
+
appliedEtag: error.appliedEtag,
|
|
152
|
+
}),
|
|
153
|
+
}
|
|
154
|
+
: {};
|
|
155
|
+
if (signal?.aborted === true) {
|
|
156
|
+
return new AiSdkWorkspaceToolError(StorageErrorCode.ABORTED, reconciliation);
|
|
157
|
+
}
|
|
158
|
+
if (isStorageWorkspaceError(error)) {
|
|
159
|
+
return new AiSdkWorkspaceToolError(error.code, reconciliation);
|
|
160
|
+
}
|
|
161
|
+
if (isStorageError(error)) {
|
|
162
|
+
return new AiSdkWorkspaceToolError(error.code, reconciliation);
|
|
163
|
+
}
|
|
164
|
+
return new AiSdkWorkspaceToolError(StorageErrorCode.PROVIDER);
|
|
165
|
+
}
|
|
166
|
+
async function executeSafely(signal, operation) {
|
|
167
|
+
try {
|
|
168
|
+
return await operation();
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
throw sanitizeToolError(error, signal);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async function executeCreateAware(signal, input, operation, mapCreateConflict) {
|
|
175
|
+
try {
|
|
176
|
+
return await operation();
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
const safeError = sanitizeToolError(error, signal);
|
|
180
|
+
if (input.mode === 'create' &&
|
|
181
|
+
safeError.code === StorageErrorCode.CONFLICT &&
|
|
182
|
+
safeError.applied !== true &&
|
|
183
|
+
mapCreateConflict !== undefined) {
|
|
184
|
+
try {
|
|
185
|
+
return await mapCreateConflict({ path: input.path });
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
throw new AiSdkWorkspaceToolError(StorageErrorCode.PROVIDER);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
throw safeError;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function serializeFile(file) {
|
|
195
|
+
if (file.etag !== undefined && !isCanonicalStorageEtag(file.etag)) {
|
|
196
|
+
throw new Error('Workspace returned a malformed ETag.');
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
kind: 'file',
|
|
200
|
+
path: file.path,
|
|
201
|
+
name: file.name,
|
|
202
|
+
size: file.size,
|
|
203
|
+
contentType: file.contentType,
|
|
204
|
+
...(file.etag === undefined ? {} : { etag: file.etag }),
|
|
205
|
+
...(file.lastModified === undefined
|
|
206
|
+
? {}
|
|
207
|
+
: { lastModified: file.lastModified.toISOString() }),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function serializeEntry(entry) {
|
|
211
|
+
return entry.kind === 'file'
|
|
212
|
+
? serializeFile(entry)
|
|
213
|
+
: { kind: 'directory', path: entry.path, name: entry.name };
|
|
214
|
+
}
|
|
215
|
+
function serializeTextFile(file) {
|
|
216
|
+
return { ...serializeFile(file), text: file.text };
|
|
217
|
+
}
|
|
218
|
+
function serializePage(page) {
|
|
219
|
+
return {
|
|
220
|
+
entries: page.entries.map(serializeEntry),
|
|
221
|
+
...(page.cursor === undefined ? {} : { cursor: page.cursor }),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Creates Vercel AI SDK tools backed only by a mounted StorageWorkspace.
|
|
226
|
+
*
|
|
227
|
+
* A tool is omitted unless the workspace grants its required permission.
|
|
228
|
+
* The workspace remains the enforcing boundary if a retained tool reference
|
|
229
|
+
* is invoked after further narrowing.
|
|
230
|
+
*/
|
|
231
|
+
export function createAiSdkWorkspaceTools({ workspace, maxReadBytes: requestedMaxReadBytes, mutationMode = 'conditional', requireApproval = true, mapCreateConflict, }) {
|
|
232
|
+
if (mutationMode !== 'conditional' && mutationMode !== 'last-write-wins') {
|
|
233
|
+
throw new RangeError('mutationMode must be "conditional" or "last-write-wins".');
|
|
234
|
+
}
|
|
235
|
+
if (mutationMode === 'last-write-wins' && mapCreateConflict !== undefined) {
|
|
236
|
+
throw new RangeError('mapCreateConflict is available only in conditional mutation mode.');
|
|
237
|
+
}
|
|
238
|
+
const maxReadBytes = resolveReadLimit(workspace, requestedMaxReadBytes);
|
|
239
|
+
const tools = {};
|
|
240
|
+
const pathSchema = logicalPath('File path', workspace.limits.maxPathBytes);
|
|
241
|
+
const directorySchema = logicalPath('Directory path', workspace.limits.maxPathBytes);
|
|
242
|
+
const etagSchema = boundedEtag();
|
|
243
|
+
if (workspace.allows('list')) {
|
|
244
|
+
tools.workspace_list = tool({
|
|
245
|
+
description: 'List files and directories inside the mounted workspace. Omit directory to list the workspace root.',
|
|
246
|
+
// Optional pagination and directory inputs are not compatible with
|
|
247
|
+
// OpenAI strict function schemas, which require every property.
|
|
248
|
+
strict: false,
|
|
249
|
+
inputSchema: z
|
|
250
|
+
.object({
|
|
251
|
+
directory: directorySchema.optional(),
|
|
252
|
+
recursive: z
|
|
253
|
+
.boolean()
|
|
254
|
+
.optional()
|
|
255
|
+
.describe('Whether to include descendants recursively.'),
|
|
256
|
+
limit: positiveIntegerAtMost(workspace.limits.maxPageSize, `Maximum entries to return, up to ${workspace.limits.maxPageSize}.`),
|
|
257
|
+
cursor: continuationCursor('Opaque cursor returned by a preceding list call. It may be replayed before expiry while its provider continuation remains valid; repeat the same directory, recursive, and limit options when continuing.', workspace.limits.maxCursorBytes),
|
|
258
|
+
})
|
|
259
|
+
.strict(),
|
|
260
|
+
execute: (input, { abortSignal }) => executeSafely(abortSignal, async () => serializePage(await workspace.list({
|
|
261
|
+
...(input.directory === undefined
|
|
262
|
+
? {}
|
|
263
|
+
: { directory: input.directory }),
|
|
264
|
+
...(input.recursive === undefined
|
|
265
|
+
? {}
|
|
266
|
+
: { recursive: input.recursive }),
|
|
267
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
268
|
+
...(input.cursor === undefined ? {} : { cursor: input.cursor }),
|
|
269
|
+
...operationOptions(abortSignal),
|
|
270
|
+
}))),
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
if (workspace.allows('read')) {
|
|
274
|
+
tools.workspace_stat = tool({
|
|
275
|
+
description: mutationMode === 'conditional'
|
|
276
|
+
? 'Inspect a file inside the mounted workspace without reading its contents. Returns the ETag required for safe replace, move, and delete operations.'
|
|
277
|
+
: 'Inspect a file inside the mounted workspace without reading its contents. Any returned ETag is informational in last-write-wins mode.',
|
|
278
|
+
strict: true,
|
|
279
|
+
inputSchema: z.object({ path: pathSchema }).strict(),
|
|
280
|
+
execute: ({ path }, { abortSignal }) => executeSafely(abortSignal, async () => serializeFile(await workspace.stat(path, operationOptions(abortSignal)))),
|
|
281
|
+
});
|
|
282
|
+
tools.workspace_read_file = tool({
|
|
283
|
+
description: `Read a UTF-8 text file inside the mounted workspace. The result is bounded to ${maxReadBytes} bytes.`,
|
|
284
|
+
strict: true,
|
|
285
|
+
inputSchema: z.object({ path: pathSchema }).strict(),
|
|
286
|
+
execute: ({ path }, { abortSignal }) => executeSafely(abortSignal, async () => serializeTextFile(await workspace.readText(path, {
|
|
287
|
+
maxBytes: maxReadBytes,
|
|
288
|
+
...operationOptions(abortSignal),
|
|
289
|
+
}))),
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
if (workspace.allows('search')) {
|
|
293
|
+
tools.workspace_search = tool({
|
|
294
|
+
description: 'Search logical paths inside the mounted workspace using a bounded glob, substring, or exact match. Omit directory to search from the workspace root.',
|
|
295
|
+
// Search intentionally has optional filters and cursor inputs.
|
|
296
|
+
strict: false,
|
|
297
|
+
inputSchema: z
|
|
298
|
+
.object({
|
|
299
|
+
query: searchQuery(workspace.limits.maxPathBytes),
|
|
300
|
+
directory: directorySchema.optional(),
|
|
301
|
+
match: z
|
|
302
|
+
.enum(['glob', 'substring', 'exact'])
|
|
303
|
+
.optional()
|
|
304
|
+
.describe('Matching strategy; defaults to glob.'),
|
|
305
|
+
caseInsensitive: z.boolean().optional(),
|
|
306
|
+
limit: positiveIntegerAtMost(workspace.limits.maxSearchResults, `Maximum matches to return, up to ${workspace.limits.maxSearchResults}.`),
|
|
307
|
+
cursor: continuationCursor('Opaque cursor returned by a preceding search call. It may be replayed before expiry while its provider continuation remains valid; repeat the same query, directory, match, caseInsensitive, and limit options when continuing.', workspace.limits.maxCursorBytes),
|
|
308
|
+
})
|
|
309
|
+
.strict(),
|
|
310
|
+
execute: ({ query, directory, match, caseInsensitive, limit, cursor }, { abortSignal }) => executeSafely(abortSignal, async () => serializePage(await workspace.search(query, {
|
|
311
|
+
...(directory === undefined ? {} : { directory }),
|
|
312
|
+
...(match === undefined ? {} : { match }),
|
|
313
|
+
...(caseInsensitive === undefined ? {} : { caseInsensitive }),
|
|
314
|
+
...(limit === undefined ? {} : { limit }),
|
|
315
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
316
|
+
...operationOptions(abortSignal),
|
|
317
|
+
}))),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
const commonWriteShape = {
|
|
321
|
+
path: pathSchema,
|
|
322
|
+
content: z
|
|
323
|
+
.string()
|
|
324
|
+
.refine((value) => utf8Encoder.encode(value).byteLength <=
|
|
325
|
+
workspace.limits.maxWriteBytes, {
|
|
326
|
+
message: `Content exceeds the ${workspace.limits.maxWriteBytes}-byte workspace write limit.`,
|
|
327
|
+
})
|
|
328
|
+
.describe(`UTF-8 text to write. The workspace enforces its ${workspace.limits.maxWriteBytes}-byte write limit.`),
|
|
329
|
+
};
|
|
330
|
+
if (mutationMode === 'last-write-wins' && workspace.allows('write')) {
|
|
331
|
+
const inputSchema = z.object(commonWriteShape).strict();
|
|
332
|
+
tools.workspace_write_file = tool({
|
|
333
|
+
description: 'Write a UTF-8 text file inside the mounted workspace. An existing destination is overwritten; the last successful writer wins.',
|
|
334
|
+
strict: true,
|
|
335
|
+
inputSchema,
|
|
336
|
+
needsApproval: resolveApproval('workspace_write_file', requireApproval),
|
|
337
|
+
execute: ({ path, content }, { abortSignal }) => executeSafely(abortSignal, async () => serializeFile(await workspace.writeFile(path, content, {
|
|
338
|
+
mode: 'overwrite',
|
|
339
|
+
...operationOptions(abortSignal),
|
|
340
|
+
}))),
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
else if (mutationMode === 'conditional') {
|
|
344
|
+
const canCreate = workspace.allows('create');
|
|
345
|
+
const canReplace = workspace.allows('replace');
|
|
346
|
+
if (canCreate || canReplace) {
|
|
347
|
+
const createSchema = z
|
|
348
|
+
.object({ ...commonWriteShape, mode: z.literal('create') })
|
|
349
|
+
.strict();
|
|
350
|
+
const replaceSchema = z
|
|
351
|
+
.object({
|
|
352
|
+
...commonWriteShape,
|
|
353
|
+
mode: z.literal('replace'),
|
|
354
|
+
etag: etagSchema,
|
|
355
|
+
})
|
|
356
|
+
.strict();
|
|
357
|
+
const inputSchema = canCreate && canReplace
|
|
358
|
+
? z.discriminatedUnion('mode', [createSchema, replaceSchema])
|
|
359
|
+
: canCreate
|
|
360
|
+
? createSchema
|
|
361
|
+
: replaceSchema;
|
|
362
|
+
tools.workspace_write_file = tool({
|
|
363
|
+
description: canCreate && canReplace
|
|
364
|
+
? 'Create a new UTF-8 text file or replace an existing file inside the mounted workspace. Create fails if the destination exists; replace requires its current ETag.'
|
|
365
|
+
: canCreate
|
|
366
|
+
? 'Create a new UTF-8 text file inside the mounted workspace. The operation fails if the destination already exists.'
|
|
367
|
+
: 'Replace an existing UTF-8 text file inside the mounted workspace using its current ETag.',
|
|
368
|
+
// The combined create/replace schema is a discriminated union. OpenAI
|
|
369
|
+
// strict function tools reject its root-level oneOf, while the runtime
|
|
370
|
+
// Zod schema continues to validate every tool call in non-strict mode.
|
|
371
|
+
strict: !(canCreate && canReplace),
|
|
372
|
+
inputSchema,
|
|
373
|
+
needsApproval: resolveApproval('workspace_write_file', requireApproval),
|
|
374
|
+
execute: (input, { abortSignal }) => executeCreateAware(abortSignal, input, async () => serializeFile(input.mode === 'create'
|
|
375
|
+
? await workspace.writeFile(input.path, input.content, {
|
|
376
|
+
mode: 'create',
|
|
377
|
+
...operationOptions(abortSignal),
|
|
378
|
+
})
|
|
379
|
+
: await workspace.writeFile(input.path, input.content, {
|
|
380
|
+
mode: 'replace',
|
|
381
|
+
etag: input.etag,
|
|
382
|
+
...operationOptions(abortSignal),
|
|
383
|
+
})), mapCreateConflict),
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
const canCopy = workspace.allows('copy') && workspace.allows('read');
|
|
388
|
+
if (mutationMode === 'last-write-wins' &&
|
|
389
|
+
canCopy &&
|
|
390
|
+
workspace.allows('write')) {
|
|
391
|
+
tools.workspace_copy_file = tool({
|
|
392
|
+
description: 'Copy the latest readable contents of a file inside the mounted workspace. The source remains intact, and an existing destination is overwritten.',
|
|
393
|
+
strict: true,
|
|
394
|
+
inputSchema: z
|
|
395
|
+
.object({
|
|
396
|
+
source: logicalPath('Source file path', workspace.limits.maxPathBytes),
|
|
397
|
+
destination: logicalPath('Destination file path', workspace.limits.maxPathBytes),
|
|
398
|
+
})
|
|
399
|
+
.strict(),
|
|
400
|
+
needsApproval: resolveApproval('workspace_copy_file', requireApproval),
|
|
401
|
+
execute: ({ source, destination }, { abortSignal }) => executeSafely(abortSignal, async () => serializeFile(await workspace.copyFile(source, destination, {
|
|
402
|
+
mode: 'overwrite',
|
|
403
|
+
...operationOptions(abortSignal),
|
|
404
|
+
}))),
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
else if (mutationMode === 'conditional' &&
|
|
408
|
+
canCopy &&
|
|
409
|
+
workspace.allows('create')) {
|
|
410
|
+
tools.workspace_copy_file = tool({
|
|
411
|
+
description: 'Copy an exact observed version of a file inside the mounted workspace. The source remains intact, and the operation fails if the source changed or the destination already exists.',
|
|
412
|
+
strict: true,
|
|
413
|
+
inputSchema: z
|
|
414
|
+
.object({
|
|
415
|
+
source: logicalPath('Source file path', workspace.limits.maxPathBytes),
|
|
416
|
+
destination: logicalPath('Destination file path', workspace.limits.maxPathBytes),
|
|
417
|
+
etag: etagSchema.describe('Exact ETag of the source returned by the latest workspace stat or read.'),
|
|
418
|
+
})
|
|
419
|
+
.strict(),
|
|
420
|
+
needsApproval: resolveApproval('workspace_copy_file', requireApproval),
|
|
421
|
+
execute: ({ source, destination, etag }, { abortSignal }) => executeSafely(abortSignal, async () => serializeFile(await workspace.copyFile(source, destination, {
|
|
422
|
+
etag,
|
|
423
|
+
...operationOptions(abortSignal),
|
|
424
|
+
}))),
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
if (mutationMode === 'conditional' &&
|
|
428
|
+
workspace.allows('move') &&
|
|
429
|
+
workspace.allows('read') &&
|
|
430
|
+
workspace.allows('delete') &&
|
|
431
|
+
workspace.allows('create')) {
|
|
432
|
+
tools.workspace_move_file = tool({
|
|
433
|
+
description: "Move a file inside the mounted workspace using the source's current ETag. The operation fails if the destination already exists. If source deletion cannot be confirmed, the destination is retained and the tool reports a conflict; inspect both paths before retrying.",
|
|
434
|
+
strict: true,
|
|
435
|
+
inputSchema: z
|
|
436
|
+
.object({
|
|
437
|
+
source: logicalPath('Source file path', workspace.limits.maxPathBytes),
|
|
438
|
+
destination: logicalPath('Destination file path', workspace.limits.maxPathBytes),
|
|
439
|
+
etag: etagSchema.describe('Exact ETag of the source returned by the latest workspace stat or read.'),
|
|
440
|
+
})
|
|
441
|
+
.strict(),
|
|
442
|
+
needsApproval: resolveApproval('workspace_move_file', requireApproval),
|
|
443
|
+
execute: ({ source, destination, etag }, { abortSignal }) => executeSafely(abortSignal, async () => serializeFile(await workspace.moveFile(source, destination, {
|
|
444
|
+
etag,
|
|
445
|
+
...operationOptions(abortSignal),
|
|
446
|
+
}))),
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (mutationMode === 'last-write-wins' &&
|
|
450
|
+
workspace.allows('delete') &&
|
|
451
|
+
workspace.allows('write')) {
|
|
452
|
+
tools.workspace_delete_file = tool({
|
|
453
|
+
description: 'Unconditionally delete the current file at a path inside the mounted workspace.',
|
|
454
|
+
strict: true,
|
|
455
|
+
inputSchema: z.object({ path: pathSchema }).strict(),
|
|
456
|
+
needsApproval: resolveApproval('workspace_delete_file', requireApproval),
|
|
457
|
+
execute: ({ path }, { abortSignal }) => executeSafely(abortSignal, async () => {
|
|
458
|
+
await workspace.deleteFile(path, {
|
|
459
|
+
mode: 'unconditional',
|
|
460
|
+
...operationOptions(abortSignal),
|
|
461
|
+
});
|
|
462
|
+
return { deleted: true, path };
|
|
463
|
+
}),
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
else if (mutationMode === 'conditional' && workspace.allows('delete')) {
|
|
467
|
+
tools.workspace_delete_file = tool({
|
|
468
|
+
description: 'Delete a file inside the mounted workspace using its current ETag.',
|
|
469
|
+
strict: true,
|
|
470
|
+
inputSchema: z
|
|
471
|
+
.object({
|
|
472
|
+
path: pathSchema,
|
|
473
|
+
etag: etagSchema,
|
|
474
|
+
})
|
|
475
|
+
.strict(),
|
|
476
|
+
needsApproval: resolveApproval('workspace_delete_file', requireApproval),
|
|
477
|
+
execute: ({ path, etag }, { abortSignal }) => executeSafely(abortSignal, async () => {
|
|
478
|
+
await workspace.deleteFile(path, {
|
|
479
|
+
etag,
|
|
480
|
+
...operationOptions(abortSignal),
|
|
481
|
+
});
|
|
482
|
+
return { deleted: true, path };
|
|
483
|
+
}),
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
return tools;
|
|
487
|
+
}
|
|
488
|
+
export function isAiSdkWorkspaceMutationToolName(value) {
|
|
489
|
+
return mutationToolNames.has(value);
|
|
490
|
+
}
|
|
491
|
+
//# sourceMappingURL=ai-sdk-workspace-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-sdk-workspace-tools.js","sourceRoot":"","sources":["../../src/ai-sdk/ai-sdk-workspace-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgC,MAAM,IAAI,CAAC;AACxD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,kCAAkC,EAClC,uBAAuB,GAKxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,cAAc,GAEf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBA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,CAAC,IAAI,EAAE;oBAC/B,IAAI;oBACJ,GAAG,gBAAgB,CAAC,WAAW,CAAC;iBACjC,CAAC,CAAC;gBACH,OAAO,EAAE,OAAO,EAAE,IAAa,EAAE,IAAI,EAAE,CAAC;YAC1C,CAAC,CAAC;SACL,CAAC,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,KAAa;IAEb,OAAO,iBAAiB,CAAC,GAAG,CAAC,KAAuC,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import { tool, type JSONValue, type ToolSet } from 'ai';\nimport { z } from 'zod';\n\nimport {\n STORAGE_WORKSPACE_MAX_CURSOR_BYTES,\n isStorageWorkspaceError,\n type StorageWorkspace,\n type StorageWorkspaceEntry,\n type StorageWorkspaceFile,\n type StorageWorkspaceTextFile,\n} from '../workspace/index.js';\nimport {\n StorageErrorCode,\n isStorageError,\n type StorageErrorCode as StorageErrorCodeValue,\n} from '../storage.error.js';\nimport { isCanonicalStorageEtag } from '../storage-etag.js';\n\nexport const AI_SDK_WORKSPACE_TOOL_NAMES = [\n 'workspace_list',\n 'workspace_stat',\n 'workspace_read_file',\n 'workspace_search',\n 'workspace_write_file',\n 'workspace_copy_file',\n 'workspace_move_file',\n 'workspace_delete_file',\n] as const;\n\nexport type AiSdkWorkspaceToolName =\n (typeof AI_SDK_WORKSPACE_TOOL_NAMES)[number];\n\nexport type AiSdkWorkspaceMutationToolName = Extract<\n AiSdkWorkspaceToolName,\n | 'workspace_write_file'\n | 'workspace_copy_file'\n | 'workspace_move_file'\n | 'workspace_delete_file'\n>;\n\n/**\n * Approval policy for mutation tools. An omitted entry defaults to requiring\n * approval, matching an omitted policy.\n */\nexport type AiSdkWorkspaceApprovalConfig =\n boolean | Partial<Record<AiSdkWorkspaceMutationToolName, boolean>>;\n\nexport type AiSdkWorkspaceMutationMode = 'conditional' | 'last-write-wins';\n\nexport interface AiSdkWorkspaceCreateConflict {\n /** The logical destination inside the mounted workspace. */\n readonly path: string;\n}\n\nexport type AiSdkWorkspaceCreateConflictMapper<Result extends JSONValue> = (\n conflict: AiSdkWorkspaceCreateConflict,\n) => PromiseLike<Result> | Result;\n\nexport interface CreateAiSdkWorkspaceToolsOptions<\n CreateConflictResult extends JSONValue = never,\n> {\n /** The already-mounted, policy-enforcing workspace exposed to the tools. */\n workspace: StorageWorkspace;\n /**\n * Optional tighter read ceiling. Values above the workspace ceiling are\n * clamped; the model cannot choose or raise this value.\n */\n maxReadBytes?: number;\n /** Mutation tools require approval by default. */\n requireApproval?: AiSdkWorkspaceApprovalConfig;\n /**\n * Selects the mutation contract exposed to the model. Conditional mode is\n * the default; last-write-wins uses the workspace's ordinary Files path.\n */\n mutationMode?: AiSdkWorkspaceMutationMode;\n /**\n * Maps an atomic create collision to an application result. When omitted,\n * the collision remains an AiSdkWorkspaceToolError like every other storage\n * failure. Replace conflicts are never mapped by this hook. This option is\n * valid only when mutationMode is conditional.\n */\n mapCreateConflict?: AiSdkWorkspaceCreateConflictMapper<CreateConflictResult>;\n}\n\nexport type AiSdkWorkspaceToolErrorCode = StorageErrorCodeValue;\n\nexport interface AiSdkWorkspaceToolErrorOptions {\n /** True when the failed operation may already have committed. */\n readonly applied?: boolean;\n /** Canonical ETag of the committed object, when the provider returned one. */\n readonly appliedEtag?: string;\n}\n\nconst SAFE_ERROR_MESSAGES: Readonly<\n Record<AiSdkWorkspaceToolErrorCode, string>\n> = {\n [StorageErrorCode.NOT_FOUND]: 'The requested workspace path was not found.',\n [StorageErrorCode.UNAUTHORIZED]:\n 'This operation is not permitted in the workspace.',\n [StorageErrorCode.CONFLICT]:\n 'The operation conflicts with current workspace state. Inspect the affected paths before retrying.',\n [StorageErrorCode.READ_ONLY]:\n 'This operation is not permitted in the workspace.',\n [StorageErrorCode.INVALID_ARGUMENT]: 'The workspace tool input was rejected.',\n [StorageErrorCode.NOT_SUPPORTED]:\n 'This workspace operation is not supported by the configured storage.',\n [StorageErrorCode.ABORTED]: 'The workspace operation was aborted.',\n [StorageErrorCode.TIMEOUT]: 'The workspace operation timed out.',\n [StorageErrorCode.LIMIT_EXCEEDED]:\n 'The workspace operation exceeded a configured limit.',\n [StorageErrorCode.PROVIDER]: 'The workspace operation failed.',\n};\n\n/**\n * Safe error exposed at the AI tool boundary. It deliberately carries no\n * provider error, storage key, mount prefix, store name, or cause. Applied\n * reconciliation metadata is retained so callers do not blindly retry a\n * mutation that may already have committed.\n */\nexport class AiSdkWorkspaceToolError extends Error {\n readonly code: AiSdkWorkspaceToolErrorCode;\n declare readonly applied?: true;\n declare readonly appliedEtag?: string;\n\n constructor(\n code: AiSdkWorkspaceToolErrorCode,\n options: AiSdkWorkspaceToolErrorOptions = {},\n ) {\n super(SAFE_ERROR_MESSAGES[code]);\n this.name = 'AiSdkWorkspaceToolError';\n this.code = code;\n if (options.applied === true) {\n this.applied = true;\n if (\n options.appliedEtag !== undefined &&\n isCanonicalStorageEtag(options.appliedEtag)\n ) {\n this.appliedEtag = options.appliedEtag;\n }\n }\n }\n}\n\nexport interface AiSdkWorkspaceFileResult {\n kind: 'file';\n path: string;\n name: string;\n size: number;\n contentType: string;\n etag?: string;\n lastModified?: string;\n}\n\nexport interface AiSdkWorkspaceDirectoryResult {\n kind: 'directory';\n path: string;\n name: string;\n}\n\nexport type AiSdkWorkspaceEntryResult =\n AiSdkWorkspaceFileResult | AiSdkWorkspaceDirectoryResult;\n\nexport interface AiSdkWorkspaceTextFileResult extends AiSdkWorkspaceFileResult {\n text: string;\n}\n\nexport interface AiSdkWorkspacePageResult {\n entries: AiSdkWorkspaceEntryResult[];\n cursor?: string;\n}\n\nconst mutationToolNames = new Set<AiSdkWorkspaceMutationToolName>([\n 'workspace_write_file',\n 'workspace_copy_file',\n 'workspace_move_file',\n 'workspace_delete_file',\n]);\nconst utf8Encoder = new TextEncoder();\nconst forbiddenUnicodeCharacter = /\\p{C}/u;\nconst workspaceCursor = /^[A-Za-z0-9._-]+$/u;\nconst windowsDeviceName = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\\..*)?$/iu;\n\nfunction isLogicalPath(value: string): boolean {\n if (\n value.length === 0 ||\n value.startsWith('/') ||\n value.endsWith('/') ||\n value !== value.normalize('NFC') ||\n value.includes('\\\\') ||\n forbiddenUnicodeCharacter.test(value)\n ) {\n return false;\n }\n\n return value\n .split('/')\n .every(\n (segment) =>\n segment.length > 0 &&\n segment !== '.' &&\n segment !== '..' &&\n !segment.includes(':') &&\n !segment.endsWith('.') &&\n !segment.endsWith(' ') &&\n !windowsDeviceName.test(segment),\n );\n}\n\nfunction logicalPath(label: string, maxBytes: number) {\n return z\n .string()\n .min(1)\n .refine(isLogicalPath, {\n message: `${label} must be a portable, NFC-normalized, relative POSIX workspace path.`,\n })\n .refine((value) => utf8Encoder.encode(value).byteLength <= maxBytes, {\n message: `${label} exceeds the ${maxBytes}-byte workspace path limit.`,\n })\n .describe(\n `${label}. Use an NFC-normalized relative POSIX path inside the mounted workspace. Empty, dot, parent, colon, trailing dot or space, and Windows reserved device segments are forbidden.`,\n );\n}\n\nfunction searchQuery(maxBytes: number) {\n return z\n .string()\n .min(1)\n .refine(\n (value) =>\n !value.includes('\\\\') && !forbiddenUnicodeCharacter.test(value),\n { message: 'Search query contains forbidden characters.' },\n )\n .refine((value) => utf8Encoder.encode(value).byteLength <= maxBytes, {\n message: `Search query exceeds the ${maxBytes}-byte workspace limit.`,\n })\n .describe('Path pattern or text to find inside the mounted workspace.');\n}\n\nfunction boundedEtag() {\n return z\n .string()\n .refine(isCanonicalStorageEtag, {\n message: 'ETag must be a canonical bare value of at most 1,024 bytes.',\n })\n .describe(\n 'Exact canonical bare ETag returned by the latest workspace stat or read.',\n );\n}\n\nfunction continuationCursor(description: string, maxBytes: number) {\n return z\n .string()\n .min(1)\n .max(Math.min(STORAGE_WORKSPACE_MAX_CURSOR_BYTES, maxBytes))\n .regex(\n workspaceCursor,\n 'Cursor must be the bounded opaque token returned by the workspace.',\n )\n .optional()\n .describe(description);\n}\n\nfunction positiveIntegerAtMost(maximum: number, description: string) {\n return z\n .number()\n .int()\n .positive()\n .max(maximum)\n .optional()\n .describe(description);\n}\n\nfunction operationOptions(signal: AbortSignal | undefined): {\n signal?: AbortSignal;\n} {\n return signal === undefined ? {} : { signal };\n}\n\nfunction resolveApproval(\n toolName: AiSdkWorkspaceMutationToolName,\n config: AiSdkWorkspaceApprovalConfig,\n): boolean {\n return typeof config === 'boolean' ? config : (config[toolName] ?? true);\n}\n\nfunction resolveReadLimit(\n workspace: StorageWorkspace,\n requested: number | undefined,\n): number {\n const workspaceLimit = workspace.limits.maxReadBytes;\n if (!Number.isSafeInteger(workspaceLimit) || workspaceLimit <= 0) {\n throw new RangeError(\n 'workspace.limits.maxReadBytes must be a positive safe integer.',\n );\n }\n if (\n requested !== undefined &&\n (!Number.isSafeInteger(requested) || requested <= 0)\n ) {\n throw new RangeError('maxReadBytes must be a positive safe integer.');\n }\n return Math.min(requested ?? workspaceLimit, workspaceLimit);\n}\n\nfunction sanitizeToolError(\n error: unknown,\n signal: AbortSignal | undefined,\n): AiSdkWorkspaceToolError {\n if (error instanceof AiSdkWorkspaceToolError) {\n return error;\n }\n const reconciliation =\n isStorageWorkspaceError(error) || isStorageError(error)\n ? {\n applied: error.applied,\n ...(error.appliedEtag !== undefined && {\n appliedEtag: error.appliedEtag,\n }),\n }\n : {};\n if (signal?.aborted === true) {\n return new AiSdkWorkspaceToolError(\n StorageErrorCode.ABORTED,\n reconciliation,\n );\n }\n if (isStorageWorkspaceError(error)) {\n return new AiSdkWorkspaceToolError(error.code, reconciliation);\n }\n if (isStorageError(error)) {\n return new AiSdkWorkspaceToolError(error.code, reconciliation);\n }\n return new AiSdkWorkspaceToolError(StorageErrorCode.PROVIDER);\n}\n\nasync function executeSafely<Result>(\n signal: AbortSignal | undefined,\n operation: () => Promise<Result>,\n): Promise<Result> {\n try {\n return await operation();\n } catch (error) {\n throw sanitizeToolError(error, signal);\n }\n}\n\nasync function executeCreateAware<\n Result,\n CreateConflictResult extends JSONValue,\n>(\n signal: AbortSignal | undefined,\n input: { mode: 'create' | 'replace'; path: string },\n operation: () => Promise<Result>,\n mapCreateConflict:\n AiSdkWorkspaceCreateConflictMapper<CreateConflictResult> | undefined,\n): Promise<CreateConflictResult | Result> {\n try {\n return await operation();\n } catch (error) {\n const safeError = sanitizeToolError(error, signal);\n if (\n input.mode === 'create' &&\n safeError.code === StorageErrorCode.CONFLICT &&\n safeError.applied !== true &&\n mapCreateConflict !== undefined\n ) {\n try {\n return await mapCreateConflict({ path: input.path });\n } catch {\n throw new AiSdkWorkspaceToolError(StorageErrorCode.PROVIDER);\n }\n }\n throw safeError;\n }\n}\n\nfunction serializeFile(file: StorageWorkspaceFile): AiSdkWorkspaceFileResult {\n if (file.etag !== undefined && !isCanonicalStorageEtag(file.etag)) {\n throw new Error('Workspace returned a malformed ETag.');\n }\n return {\n kind: 'file',\n path: file.path,\n name: file.name,\n size: file.size,\n contentType: file.contentType,\n ...(file.etag === undefined ? {} : { etag: file.etag }),\n ...(file.lastModified === undefined\n ? {}\n : { lastModified: file.lastModified.toISOString() }),\n };\n}\n\nfunction serializeEntry(\n entry: StorageWorkspaceEntry,\n): AiSdkWorkspaceEntryResult {\n return entry.kind === 'file'\n ? serializeFile(entry)\n : { kind: 'directory', path: entry.path, name: entry.name };\n}\n\nfunction serializeTextFile(\n file: StorageWorkspaceTextFile,\n): AiSdkWorkspaceTextFileResult {\n return { ...serializeFile(file), text: file.text };\n}\n\nfunction serializePage(page: {\n entries: StorageWorkspaceEntry[];\n cursor?: string;\n}): AiSdkWorkspacePageResult {\n return {\n entries: page.entries.map(serializeEntry),\n ...(page.cursor === undefined ? {} : { cursor: page.cursor }),\n };\n}\n\n/**\n * Creates Vercel AI SDK tools backed only by a mounted StorageWorkspace.\n *\n * A tool is omitted unless the workspace grants its required permission.\n * The workspace remains the enforcing boundary if a retained tool reference\n * is invoked after further narrowing.\n */\nexport function createAiSdkWorkspaceTools<\n CreateConflictResult extends JSONValue = never,\n>({\n workspace,\n maxReadBytes: requestedMaxReadBytes,\n mutationMode = 'conditional',\n requireApproval = true,\n mapCreateConflict,\n}: CreateAiSdkWorkspaceToolsOptions<CreateConflictResult>): ToolSet {\n if (mutationMode !== 'conditional' && mutationMode !== 'last-write-wins') {\n throw new RangeError(\n 'mutationMode must be \"conditional\" or \"last-write-wins\".',\n );\n }\n if (mutationMode === 'last-write-wins' && mapCreateConflict !== undefined) {\n throw new RangeError(\n 'mapCreateConflict is available only in conditional mutation mode.',\n );\n }\n const maxReadBytes = resolveReadLimit(workspace, requestedMaxReadBytes);\n const tools: ToolSet = {};\n const pathSchema = logicalPath('File path', workspace.limits.maxPathBytes);\n const directorySchema = logicalPath(\n 'Directory path',\n workspace.limits.maxPathBytes,\n );\n const etagSchema = boundedEtag();\n\n if (workspace.allows('list')) {\n tools.workspace_list = tool({\n description:\n 'List files and directories inside the mounted workspace. Omit directory to list the workspace root.',\n // Optional pagination and directory inputs are not compatible with\n // OpenAI strict function schemas, which require every property.\n strict: false,\n inputSchema: z\n .object({\n directory: directorySchema.optional(),\n recursive: z\n .boolean()\n .optional()\n .describe('Whether to include descendants recursively.'),\n limit: positiveIntegerAtMost(\n workspace.limits.maxPageSize,\n `Maximum entries to return, up to ${workspace.limits.maxPageSize}.`,\n ),\n cursor: continuationCursor(\n 'Opaque cursor returned by a preceding list call. It may be replayed before expiry while its provider continuation remains valid; repeat the same directory, recursive, and limit options when continuing.',\n workspace.limits.maxCursorBytes,\n ),\n })\n .strict(),\n execute: (input, { abortSignal }) =>\n executeSafely(abortSignal, async () =>\n serializePage(\n await workspace.list({\n ...(input.directory === undefined\n ? {}\n : { directory: input.directory }),\n ...(input.recursive === undefined\n ? {}\n : { recursive: input.recursive }),\n ...(input.limit === undefined ? {} : { limit: input.limit }),\n ...(input.cursor === undefined ? {} : { cursor: input.cursor }),\n ...operationOptions(abortSignal),\n }),\n ),\n ),\n });\n }\n\n if (workspace.allows('read')) {\n tools.workspace_stat = tool({\n description:\n mutationMode === 'conditional'\n ? 'Inspect a file inside the mounted workspace without reading its contents. Returns the ETag required for safe replace, move, and delete operations.'\n : 'Inspect a file inside the mounted workspace without reading its contents. Any returned ETag is informational in last-write-wins mode.',\n strict: true,\n inputSchema: z.object({ path: pathSchema }).strict(),\n execute: ({ path }, { abortSignal }) =>\n executeSafely(abortSignal, async () =>\n serializeFile(\n await workspace.stat(path, operationOptions(abortSignal)),\n ),\n ),\n });\n\n tools.workspace_read_file = tool({\n description: `Read a UTF-8 text file inside the mounted workspace. The result is bounded to ${maxReadBytes} bytes.`,\n strict: true,\n inputSchema: z.object({ path: pathSchema }).strict(),\n execute: ({ path }, { abortSignal }) =>\n executeSafely(abortSignal, async () =>\n serializeTextFile(\n await workspace.readText(path, {\n maxBytes: maxReadBytes,\n ...operationOptions(abortSignal),\n }),\n ),\n ),\n });\n }\n\n if (workspace.allows('search')) {\n tools.workspace_search = tool({\n description:\n 'Search logical paths inside the mounted workspace using a bounded glob, substring, or exact match. Omit directory to search from the workspace root.',\n // Search intentionally has optional filters and cursor inputs.\n strict: false,\n inputSchema: z\n .object({\n query: searchQuery(workspace.limits.maxPathBytes),\n directory: directorySchema.optional(),\n match: z\n .enum(['glob', 'substring', 'exact'])\n .optional()\n .describe('Matching strategy; defaults to glob.'),\n caseInsensitive: z.boolean().optional(),\n limit: positiveIntegerAtMost(\n workspace.limits.maxSearchResults,\n `Maximum matches to return, up to ${workspace.limits.maxSearchResults}.`,\n ),\n cursor: continuationCursor(\n 'Opaque cursor returned by a preceding search call. It may be replayed before expiry while its provider continuation remains valid; repeat the same query, directory, match, caseInsensitive, and limit options when continuing.',\n workspace.limits.maxCursorBytes,\n ),\n })\n .strict(),\n execute: (\n { query, directory, match, caseInsensitive, limit, cursor },\n { abortSignal },\n ) =>\n executeSafely(abortSignal, async () =>\n serializePage(\n await workspace.search(query, {\n ...(directory === undefined ? {} : { directory }),\n ...(match === undefined ? {} : { match }),\n ...(caseInsensitive === undefined ? {} : { caseInsensitive }),\n ...(limit === undefined ? {} : { limit }),\n ...(cursor === undefined ? {} : { cursor }),\n ...operationOptions(abortSignal),\n }),\n ),\n ),\n });\n }\n\n const commonWriteShape = {\n path: pathSchema,\n content: z\n .string()\n .refine(\n (value) =>\n utf8Encoder.encode(value).byteLength <=\n workspace.limits.maxWriteBytes,\n {\n message: `Content exceeds the ${workspace.limits.maxWriteBytes}-byte workspace write limit.`,\n },\n )\n .describe(\n `UTF-8 text to write. The workspace enforces its ${workspace.limits.maxWriteBytes}-byte write limit.`,\n ),\n };\n if (mutationMode === 'last-write-wins' && workspace.allows('write')) {\n const inputSchema = z.object(commonWriteShape).strict();\n tools.workspace_write_file = tool({\n description:\n 'Write a UTF-8 text file inside the mounted workspace. An existing destination is overwritten; the last successful writer wins.',\n strict: true,\n inputSchema,\n needsApproval: resolveApproval('workspace_write_file', requireApproval),\n execute: ({ path, content }, { abortSignal }) =>\n executeSafely(abortSignal, async () =>\n serializeFile(\n await workspace.writeFile(path, content, {\n mode: 'overwrite',\n ...operationOptions(abortSignal),\n }),\n ),\n ),\n });\n } else if (mutationMode === 'conditional') {\n const canCreate = workspace.allows('create');\n const canReplace = workspace.allows('replace');\n if (canCreate || canReplace) {\n const createSchema = z\n .object({ ...commonWriteShape, mode: z.literal('create') })\n .strict();\n const replaceSchema = z\n .object({\n ...commonWriteShape,\n mode: z.literal('replace'),\n etag: etagSchema,\n })\n .strict();\n const inputSchema =\n canCreate && canReplace\n ? z.discriminatedUnion('mode', [createSchema, replaceSchema])\n : canCreate\n ? createSchema\n : replaceSchema;\n\n tools.workspace_write_file = tool<\n z.infer<typeof inputSchema>,\n unknown,\n Record<string, unknown>\n >({\n description:\n canCreate && canReplace\n ? 'Create a new UTF-8 text file or replace an existing file inside the mounted workspace. Create fails if the destination exists; replace requires its current ETag.'\n : canCreate\n ? 'Create a new UTF-8 text file inside the mounted workspace. The operation fails if the destination already exists.'\n : 'Replace an existing UTF-8 text file inside the mounted workspace using its current ETag.',\n // The combined create/replace schema is a discriminated union. OpenAI\n // strict function tools reject its root-level oneOf, while the runtime\n // Zod schema continues to validate every tool call in non-strict mode.\n strict: !(canCreate && canReplace),\n inputSchema,\n needsApproval: resolveApproval('workspace_write_file', requireApproval),\n execute: (input, { abortSignal }) =>\n executeCreateAware(\n abortSignal,\n input,\n async () =>\n serializeFile(\n input.mode === 'create'\n ? await workspace.writeFile(input.path, input.content, {\n mode: 'create',\n ...operationOptions(abortSignal),\n })\n : await workspace.writeFile(input.path, input.content, {\n mode: 'replace',\n etag: input.etag,\n ...operationOptions(abortSignal),\n }),\n ),\n mapCreateConflict,\n ),\n });\n }\n }\n\n const canCopy = workspace.allows('copy') && workspace.allows('read');\n if (\n mutationMode === 'last-write-wins' &&\n canCopy &&\n workspace.allows('write')\n ) {\n tools.workspace_copy_file = tool({\n description:\n 'Copy the latest readable contents of a file inside the mounted workspace. The source remains intact, and an existing destination is overwritten.',\n strict: true,\n inputSchema: z\n .object({\n source: logicalPath(\n 'Source file path',\n workspace.limits.maxPathBytes,\n ),\n destination: logicalPath(\n 'Destination file path',\n workspace.limits.maxPathBytes,\n ),\n })\n .strict(),\n needsApproval: resolveApproval('workspace_copy_file', requireApproval),\n execute: ({ source, destination }, { abortSignal }) =>\n executeSafely(abortSignal, async () =>\n serializeFile(\n await workspace.copyFile(source, destination, {\n mode: 'overwrite',\n ...operationOptions(abortSignal),\n }),\n ),\n ),\n });\n } else if (\n mutationMode === 'conditional' &&\n canCopy &&\n workspace.allows('create')\n ) {\n tools.workspace_copy_file = tool({\n description:\n 'Copy an exact observed version of a file inside the mounted workspace. The source remains intact, and the operation fails if the source changed or the destination already exists.',\n strict: true,\n inputSchema: z\n .object({\n source: logicalPath(\n 'Source file path',\n workspace.limits.maxPathBytes,\n ),\n destination: logicalPath(\n 'Destination file path',\n workspace.limits.maxPathBytes,\n ),\n etag: etagSchema.describe(\n 'Exact ETag of the source returned by the latest workspace stat or read.',\n ),\n })\n .strict(),\n needsApproval: resolveApproval('workspace_copy_file', requireApproval),\n execute: ({ source, destination, etag }, { abortSignal }) =>\n executeSafely(abortSignal, async () =>\n serializeFile(\n await workspace.copyFile(source, destination, {\n etag,\n ...operationOptions(abortSignal),\n }),\n ),\n ),\n });\n }\n\n if (\n mutationMode === 'conditional' &&\n workspace.allows('move') &&\n workspace.allows('read') &&\n workspace.allows('delete') &&\n workspace.allows('create')\n ) {\n tools.workspace_move_file = tool({\n description:\n \"Move a file inside the mounted workspace using the source's current ETag. The operation fails if the destination already exists. If source deletion cannot be confirmed, the destination is retained and the tool reports a conflict; inspect both paths before retrying.\",\n strict: true,\n inputSchema: z\n .object({\n source: logicalPath(\n 'Source file path',\n workspace.limits.maxPathBytes,\n ),\n destination: logicalPath(\n 'Destination file path',\n workspace.limits.maxPathBytes,\n ),\n etag: etagSchema.describe(\n 'Exact ETag of the source returned by the latest workspace stat or read.',\n ),\n })\n .strict(),\n needsApproval: resolveApproval('workspace_move_file', requireApproval),\n execute: ({ source, destination, etag }, { abortSignal }) =>\n executeSafely(abortSignal, async () =>\n serializeFile(\n await workspace.moveFile(source, destination, {\n etag,\n ...operationOptions(abortSignal),\n }),\n ),\n ),\n });\n }\n\n if (\n mutationMode === 'last-write-wins' &&\n workspace.allows('delete') &&\n workspace.allows('write')\n ) {\n tools.workspace_delete_file = tool({\n description:\n 'Unconditionally delete the current file at a path inside the mounted workspace.',\n strict: true,\n inputSchema: z.object({ path: pathSchema }).strict(),\n needsApproval: resolveApproval('workspace_delete_file', requireApproval),\n execute: ({ path }, { abortSignal }) =>\n executeSafely(abortSignal, async () => {\n await workspace.deleteFile(path, {\n mode: 'unconditional',\n ...operationOptions(abortSignal),\n });\n return { deleted: true as const, path };\n }),\n });\n } else if (mutationMode === 'conditional' && workspace.allows('delete')) {\n tools.workspace_delete_file = tool({\n description:\n 'Delete a file inside the mounted workspace using its current ETag.',\n strict: true,\n inputSchema: z\n .object({\n path: pathSchema,\n etag: etagSchema,\n })\n .strict(),\n needsApproval: resolveApproval('workspace_delete_file', requireApproval),\n execute: ({ path, etag }, { abortSignal }) =>\n executeSafely(abortSignal, async () => {\n await workspace.deleteFile(path, {\n etag,\n ...operationOptions(abortSignal),\n });\n return { deleted: true as const, path };\n }),\n });\n }\n\n return tools;\n}\n\nexport function isAiSdkWorkspaceMutationToolName(\n value: string,\n): value is AiSdkWorkspaceMutationToolName {\n return mutationToolNames.has(value as AiSdkWorkspaceMutationToolName);\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { AI_SDK_WORKSPACE_TOOL_NAMES, AiSdkWorkspaceToolError, createAiSdkWorkspaceTools, isAiSdkWorkspaceMutationToolName, type AiSdkWorkspaceApprovalConfig, type AiSdkWorkspaceCreateConflict, type AiSdkWorkspaceCreateConflictMapper, type AiSdkWorkspaceDirectoryResult, type AiSdkWorkspaceEntryResult, type AiSdkWorkspaceFileResult, type AiSdkWorkspaceMutationMode, type AiSdkWorkspaceMutationToolName, type AiSdkWorkspacePageResult, type AiSdkWorkspaceTextFileResult, type AiSdkWorkspaceToolErrorCode, type AiSdkWorkspaceToolErrorOptions, type AiSdkWorkspaceToolName, type CreateAiSdkWorkspaceToolsOptions, } from './ai-sdk-workspace-tools.js';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai-sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,gCAAgC,EAChC,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,EACjC,KAAK,kCAAkC,EACvC,KAAK,6BAA6B,EAClC,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,8BAA8B,EACnC,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,sBAAsB,EAC3B,KAAK,gCAAgC,GACtC,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai-sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,gCAAgC,GAejC,MAAM,6BAA6B,CAAC","sourcesContent":["export {\n AI_SDK_WORKSPACE_TOOL_NAMES,\n AiSdkWorkspaceToolError,\n createAiSdkWorkspaceTools,\n isAiSdkWorkspaceMutationToolName,\n type AiSdkWorkspaceApprovalConfig,\n type AiSdkWorkspaceCreateConflict,\n type AiSdkWorkspaceCreateConflictMapper,\n type AiSdkWorkspaceDirectoryResult,\n type AiSdkWorkspaceEntryResult,\n type AiSdkWorkspaceFileResult,\n type AiSdkWorkspaceMutationMode,\n type AiSdkWorkspaceMutationToolName,\n type AiSdkWorkspacePageResult,\n type AiSdkWorkspaceTextFileResult,\n type AiSdkWorkspaceToolErrorCode,\n type AiSdkWorkspaceToolErrorOptions,\n type AiSdkWorkspaceToolName,\n type CreateAiSdkWorkspaceToolsOptions,\n} from './ai-sdk-workspace-tools.js';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DEFAULT_BUFFER_LIMIT, StorageClient, type StorageFileHandle, } from '../storage.client.js';
|
|
2
|
+
export type { StorageDriver } from '../storage.driver.js';
|
|
3
|
+
export { StorageError, StorageErrorCode, isStorageError, normalizeStorageError, type StorageErrorOptions, } from '../storage.error.js';
|
|
4
|
+
export { StorageUploadControl, type StorageResumableToken, type StorageUploadStatus, } from '../storage-upload-control.js';
|
|
5
|
+
export type * from '../storage.types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,KAAK,iBAAiB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,KAAK,mBAAmB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,8BAA8B,CAAC;AACtC,mBAAmB,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DEFAULT_BUFFER_LIMIT, StorageClient, } from '../storage.client.js';
|
|
2
|
+
export { StorageError, StorageErrorCode, isStorageError, normalizeStorageError, } from '../storage.error.js';
|
|
3
|
+
export { StorageUploadControl, } from '../storage-upload-control.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,aAAa,GAEd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,qBAAqB,GAEtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,oBAAoB,GAGrB,MAAM,8BAA8B,CAAC","sourcesContent":["export {\n DEFAULT_BUFFER_LIMIT,\n StorageClient,\n type StorageFileHandle,\n} from '../storage.client.js';\nexport type { StorageDriver } from '../storage.driver.js';\nexport {\n StorageError,\n StorageErrorCode,\n isStorageError,\n normalizeStorageError,\n type StorageErrorOptions,\n} from '../storage.error.js';\nexport {\n StorageUploadControl,\n type StorageResumableToken,\n type StorageUploadStatus,\n} from '../storage-upload-control.js';\nexport type * from '../storage.types.js';\n"]}
|