@ai-sdk/provider-utils 5.0.71 → 5.0.72
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 +15 -0
- package/dist/index.d.ts +77 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/resolve.ts +25 -0
- package/src/types/index.ts +5 -0
- package/src/types/sandbox.ts +87 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/provider-utils",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.72",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ai-sdk/provider": "4.0.
|
|
45
|
+
"@ai-sdk/provider": "4.0.35",
|
|
46
46
|
"@standard-schema/spec": "^1.1.0",
|
|
47
47
|
"@workflow/serde": "4.1.0",
|
|
48
48
|
"eventsource-parser": "^3.0.8",
|
package/src/resolve.ts
CHANGED
|
@@ -30,3 +30,28 @@ export async function resolve<T>(value: Resolvable<T>): Promise<T> {
|
|
|
30
30
|
// Otherwise just resolve whatever we got (value or promise)
|
|
31
31
|
return value as T;
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resolves and transforms a value, preserving synchronous results. This allows
|
|
36
|
+
* synchronous credentials to remain usable by workflow serialization while
|
|
37
|
+
* asynchronous credentials are awaited by request handlers.
|
|
38
|
+
*/
|
|
39
|
+
export function resolveWith<T, U>(
|
|
40
|
+
value: Resolvable<T>,
|
|
41
|
+
transform: (value: T) => U,
|
|
42
|
+
): U | Promise<Awaited<U>> {
|
|
43
|
+
const resolved =
|
|
44
|
+
typeof value === 'function'
|
|
45
|
+
? (value as () => MaybePromiseLike<T>)()
|
|
46
|
+
: value;
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
resolved != null &&
|
|
50
|
+
(typeof resolved === 'object' || typeof resolved === 'function') &&
|
|
51
|
+
typeof (resolved as PromiseLike<T>).then === 'function'
|
|
52
|
+
) {
|
|
53
|
+
return Promise.resolve(resolved).then(transform) as Promise<Awaited<U>>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return transform(resolved as T);
|
|
57
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -45,6 +45,11 @@ export type {
|
|
|
45
45
|
SandboxWriteBinaryFileOptions as Experimental_SandboxWriteBinaryFileOptions,
|
|
46
46
|
SandboxWriteTextFileOptions as Experimental_SandboxWriteTextFileOptions,
|
|
47
47
|
WritableSandboxProcess as Experimental_WritableSandboxProcess,
|
|
48
|
+
SandboxStatOptions as Experimental_SandboxStatOptions,
|
|
49
|
+
SandboxListDirectoryOptions as Experimental_SandboxListDirectoryOptions,
|
|
50
|
+
SandboxDeleteFileOptions as Experimental_SandboxDeleteFileOptions,
|
|
51
|
+
SandboxFileStat as Experimental_SandboxFileStat,
|
|
52
|
+
SandboxDirectoryEntry as Experimental_SandboxDirectoryEntry,
|
|
48
53
|
} from './sandbox';
|
|
49
54
|
export type { SystemModelMessage } from './system-model-message';
|
|
50
55
|
export {
|
package/src/types/sandbox.ts
CHANGED
|
@@ -42,23 +42,25 @@ export type SandboxSpawnOptionsWithoutStdin = SandboxProcessOptions & {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Options for reading
|
|
45
|
+
* Options for reading, inspecting, or deleting one path in the sandbox.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
type PathOptions = {
|
|
48
48
|
/**
|
|
49
|
-
* Path
|
|
49
|
+
* Path to operate on.
|
|
50
50
|
*/
|
|
51
51
|
path: string;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Signal that can be used to abort the
|
|
54
|
+
* Signal that can be used to abort the operation.
|
|
55
55
|
*/
|
|
56
56
|
abortSignal?: AbortSignal;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
export type
|
|
59
|
+
export type SandboxReadFileOptions = PathOptions;
|
|
60
60
|
|
|
61
|
-
export type
|
|
61
|
+
export type SandboxReadBinaryFileOptions = PathOptions;
|
|
62
|
+
|
|
63
|
+
export type SandboxReadTextFileOptions = PathOptions & {
|
|
62
64
|
/**
|
|
63
65
|
* Text encoding used to decode the file bytes. Defaults to `"utf-8"`.
|
|
64
66
|
*/
|
|
@@ -76,6 +78,44 @@ export type SandboxReadTextFileOptions = SandboxReadFileOptions & {
|
|
|
76
78
|
endLine?: number;
|
|
77
79
|
};
|
|
78
80
|
|
|
81
|
+
export type SandboxStatOptions = PathOptions;
|
|
82
|
+
|
|
83
|
+
export type SandboxListDirectoryOptions = PathOptions;
|
|
84
|
+
|
|
85
|
+
export type SandboxDeleteFileOptions = PathOptions;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Information about a file or directory in the sandbox, returned by
|
|
89
|
+
* `SandboxSession.stat`. Symbolic links are followed.
|
|
90
|
+
*/
|
|
91
|
+
export type SandboxFileStat = {
|
|
92
|
+
/**
|
|
93
|
+
* Type of the path. `other` covers devices, sockets, and named pipes.
|
|
94
|
+
*/
|
|
95
|
+
type: 'file' | 'directory' | 'other';
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Size in bytes. The size of a directory is implementation-defined.
|
|
99
|
+
*/
|
|
100
|
+
size: number;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Entry in a directory listing, returned by `SandboxSession.listDirectory`.
|
|
105
|
+
*/
|
|
106
|
+
export type SandboxDirectoryEntry = {
|
|
107
|
+
/**
|
|
108
|
+
* Name of the entry, without the directory path.
|
|
109
|
+
*/
|
|
110
|
+
name: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Type of the entry. Symbolic links are reported as `symlink` and not
|
|
114
|
+
* followed. `other` covers devices, sockets, and named pipes.
|
|
115
|
+
*/
|
|
116
|
+
type: 'file' | 'directory' | 'symlink' | 'other';
|
|
117
|
+
};
|
|
118
|
+
|
|
79
119
|
/**
|
|
80
120
|
* Options for writing a file to the sandbox. `CONTENT` is the payload written
|
|
81
121
|
* to the file: a byte stream, raw bytes, or a string.
|
|
@@ -112,6 +152,13 @@ export type SandboxWriteTextFileOptions = WriteFileOptions<string> & {
|
|
|
112
152
|
|
|
113
153
|
/**
|
|
114
154
|
* Sandbox session that can execute commands and read/write files.
|
|
155
|
+
*
|
|
156
|
+
* Relative paths in every method, including the `workingDirectory` option of
|
|
157
|
+
* `run` and `spawn`, resolve against the same base directory: the directory
|
|
158
|
+
* that `run` and `spawn` start in when no `workingDirectory` is given. The
|
|
159
|
+
* base directory does not change for the lifetime of the session; changing
|
|
160
|
+
* the directory inside a command, e.g. with `cd`, only affects that command.
|
|
161
|
+
* Absolute paths are used as is.
|
|
115
162
|
*/
|
|
116
163
|
export type SandboxSession = {
|
|
117
164
|
/**
|
|
@@ -125,9 +172,8 @@ export type SandboxSession = {
|
|
|
125
172
|
* Read one file from the sandbox as a stream of bytes. Resolves to `null`
|
|
126
173
|
* when the file does not exist.
|
|
127
174
|
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* to stream bytes.
|
|
175
|
+
* This is the lowest-level read primitive; prefer `readBinaryFile` or
|
|
176
|
+
* `readTextFile` unless you need to stream bytes.
|
|
131
177
|
*/
|
|
132
178
|
readonly readFile: (
|
|
133
179
|
options: SandboxReadFileOptions,
|
|
@@ -154,7 +200,8 @@ export type SandboxSession = {
|
|
|
154
200
|
|
|
155
201
|
/**
|
|
156
202
|
* Write one file to the sandbox from a stream of bytes. Creates parent
|
|
157
|
-
* directories recursively and overwrites any existing file.
|
|
203
|
+
* directories recursively and overwrites any existing file. Rejects when the
|
|
204
|
+
* path is a directory.
|
|
158
205
|
*
|
|
159
206
|
* This is the lowest-level write primitive; prefer `writeBinaryFile` or
|
|
160
207
|
* `writeTextFile` when the full content is already materialized in memory.
|
|
@@ -163,7 +210,8 @@ export type SandboxSession = {
|
|
|
163
210
|
|
|
164
211
|
/**
|
|
165
212
|
* Write one file to the sandbox from raw bytes. Creates parent directories
|
|
166
|
-
* recursively and overwrites any existing file.
|
|
213
|
+
* recursively and overwrites any existing file. Rejects when the path is a
|
|
214
|
+
* directory.
|
|
167
215
|
*/
|
|
168
216
|
readonly writeBinaryFile: (
|
|
169
217
|
options: SandboxWriteBinaryFileOptions,
|
|
@@ -172,12 +220,39 @@ export type SandboxSession = {
|
|
|
172
220
|
/**
|
|
173
221
|
* Write one file to the sandbox from a string, encoded using the requested
|
|
174
222
|
* encoding. Creates parent directories recursively and overwrites any
|
|
175
|
-
* existing file.
|
|
223
|
+
* existing file. Rejects when the path is a directory.
|
|
176
224
|
*/
|
|
177
225
|
readonly writeTextFile: (
|
|
178
226
|
options: SandboxWriteTextFileOptions,
|
|
179
227
|
) => PromiseLike<void>;
|
|
180
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Get information about a file or directory. Symbolic links are followed.
|
|
231
|
+
* Resolves to `null` when the path does not exist.
|
|
232
|
+
*/
|
|
233
|
+
readonly stat: (
|
|
234
|
+
options: SandboxStatOptions,
|
|
235
|
+
) => PromiseLike<SandboxFileStat | null>;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* List the entries of one directory, without descending into
|
|
239
|
+
* subdirectories. The order of entries is unspecified. Resolves to `null`
|
|
240
|
+
* when the directory does not exist and rejects when the path is not a
|
|
241
|
+
* directory.
|
|
242
|
+
*/
|
|
243
|
+
readonly listDirectory: (
|
|
244
|
+
options: SandboxListDirectoryOptions,
|
|
245
|
+
) => PromiseLike<Array<SandboxDirectoryEntry> | null>;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Delete one file. A symbolic link is deleted itself, not its target.
|
|
249
|
+
* Resolves to `true` when the file was deleted and `false` when it does not
|
|
250
|
+
* exist. Rejects when the path is a directory.
|
|
251
|
+
*/
|
|
252
|
+
readonly deleteFile: (
|
|
253
|
+
options: SandboxDeleteFileOptions,
|
|
254
|
+
) => PromiseLike<boolean>;
|
|
255
|
+
|
|
181
256
|
/**
|
|
182
257
|
* Spawn a long-running process in the sandbox. Returns immediately with a
|
|
183
258
|
* handle that streams stdout/stderr, can be waited on, and can be killed.
|