@ai-sdk/sandbox-vercel 0.0.0 → 1.0.0-canary.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 +81 -0
- package/LICENSE +13 -0
- package/README.md +76 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +474 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -1
- package/src/index.ts +5 -0
- package/src/vercel-network-sandbox-session.ts +132 -0
- package/src/vercel-sandbox-session.ts +299 -0
- package/src/vercel-sandbox.ts +288 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @ai-sdk/sandbox-vercel
|
|
2
|
+
|
|
3
|
+
## 1.0.0-canary.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @ai-sdk/harness@1.0.0-canary.10
|
|
8
|
+
|
|
9
|
+
## 1.0.0-canary.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- @ai-sdk/harness@1.0.0-canary.9
|
|
14
|
+
|
|
15
|
+
## 1.0.0-canary.8
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [aae0138]
|
|
20
|
+
- @ai-sdk/harness@1.0.0-canary.8
|
|
21
|
+
|
|
22
|
+
## 1.0.0-canary.7
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- e551763: fix(harness): avoid using peer dependencies for underlying harness and sandbox SDKs
|
|
27
|
+
- Updated dependencies [3d87086]
|
|
28
|
+
- Updated dependencies [aeda373]
|
|
29
|
+
- Updated dependencies [1ea15a3]
|
|
30
|
+
- Updated dependencies [375fdd7]
|
|
31
|
+
- Updated dependencies [b4507d5]
|
|
32
|
+
- @ai-sdk/harness@1.0.0-canary.7
|
|
33
|
+
- @ai-sdk/provider-utils@5.0.0-canary.48
|
|
34
|
+
|
|
35
|
+
## 1.0.0-canary.6
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- @ai-sdk/harness@1.0.0-canary.6
|
|
40
|
+
|
|
41
|
+
## 1.0.0-canary.5
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- Updated dependencies [d77bed4]
|
|
46
|
+
- Updated dependencies [bae5e2b]
|
|
47
|
+
- @ai-sdk/harness@1.0.0-canary.5
|
|
48
|
+
- @ai-sdk/provider-utils@5.0.0-canary.47
|
|
49
|
+
|
|
50
|
+
## 1.0.0-canary.4
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- Updated dependencies [3d9a50c]
|
|
55
|
+
- @ai-sdk/harness@1.0.0-canary.4
|
|
56
|
+
|
|
57
|
+
## 1.0.0-canary.3
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [21d3d60]
|
|
62
|
+
- @ai-sdk/harness@1.0.0-canary.3
|
|
63
|
+
|
|
64
|
+
## 1.0.0-canary.2
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- 6c7a3e5: Start the `1.0.0` canary release line for the experimental harness and sandbox packages. They were unintentionally published as `0.0.0-canary.*` because they were scaffolded with a `0.0.0-canary.0` premajor version, which semver could not advance past on a major bump.
|
|
69
|
+
- Updated dependencies [6c7a3e5]
|
|
70
|
+
- @ai-sdk/harness@1.0.0-canary.2
|
|
71
|
+
|
|
72
|
+
## 0.0.0-canary.1
|
|
73
|
+
|
|
74
|
+
### Major Changes
|
|
75
|
+
|
|
76
|
+
- 9d6dbe0: feat(harness): add sandbox specific expansion for harness abstraction, add `sandbox-just-bash` and `sandbox-vercel`
|
|
77
|
+
|
|
78
|
+
### Patch Changes
|
|
79
|
+
|
|
80
|
+
- Updated dependencies [9d6dbe0]
|
|
81
|
+
- @ai-sdk/harness@0.0.0-canary.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Vercel, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# AI SDK - Vercel Sandbox
|
|
2
|
+
|
|
3
|
+
_This package is **experimental**._
|
|
4
|
+
|
|
5
|
+
`HarnessV1SandboxProvider` implementation for [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox).
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i @ai-sdk/sandbox-vercel
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
The factory is synchronous. The returned provider is stable; the actual `@vercel/sandbox` `Sandbox` is created on demand inside `provider.createSession()`.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createVercelSandbox } from '@ai-sdk/sandbox-vercel';
|
|
19
|
+
|
|
20
|
+
const vercelSandbox = createVercelSandbox({
|
|
21
|
+
runtime: 'node24',
|
|
22
|
+
ports: [3000],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const networkSandboxSession = await vercelSandbox.createSession();
|
|
26
|
+
const sandboxSession = networkSandboxSession.restricted();
|
|
27
|
+
|
|
28
|
+
await sandboxSession.writeTextFile({ path: 'hello.txt', content: 'hi' });
|
|
29
|
+
|
|
30
|
+
const { stdout } = await sandboxSession.run({
|
|
31
|
+
command: 'cat hello.txt',
|
|
32
|
+
});
|
|
33
|
+
console.log(stdout); // "hi"
|
|
34
|
+
await networkSandboxSession.stop();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`networkSandboxSession.restricted()` is typed as `Experimental_SandboxSession`, so it's safe to pass to AI SDK tools that accept `experimental_sandbox`. The network sandbox session itself carries the infra surface (`ports`, `getPortUrl`, `setNetworkPolicy`, `stop`) that only the harness should reach for.
|
|
38
|
+
|
|
39
|
+
The flat-field settings are aliased directly from `@vercel/sandbox`'s `Sandbox.create` parameters, so every option Vercel supports — including its native `NetworkPolicy` — is available without re-declaration:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const sandbox = createVercelSandbox({
|
|
43
|
+
runtime: 'node24',
|
|
44
|
+
ports: [3000],
|
|
45
|
+
timeout: 10 * 60 * 1000,
|
|
46
|
+
networkPolicy: {
|
|
47
|
+
allow: ['api.example.com'],
|
|
48
|
+
subnets: { deny: ['169.254.169.254/32'] },
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
To wrap an already-created `@vercel/sandbox` `Sandbox` instead — e.g. when you need credentials or options outside the factory's settings, or you want to share one sandbox across multiple harness sessions — pass it via `sandbox`. Install `@vercel/sandbox` directly if your application imports `Sandbox`. The network sandbox session's `stop()` is a no-op in this case; the caller owns the lifecycle.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { createVercelSandbox } from '@ai-sdk/sandbox-vercel';
|
|
57
|
+
import { Sandbox } from '@vercel/sandbox';
|
|
58
|
+
|
|
59
|
+
const sandbox = createVercelSandbox({
|
|
60
|
+
sandbox: await Sandbox.create({ runtime: 'node24', ports: [3000] }),
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Mid-session network policy
|
|
65
|
+
|
|
66
|
+
Once the network sandbox session is alive, the host can update outbound network policy on the running sandbox:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
await networkSandboxSession.setNetworkPolicy?.({
|
|
70
|
+
mode: 'custom',
|
|
71
|
+
allowedHosts: ['api.example.com'],
|
|
72
|
+
deniedCIDRs: ['169.254.169.254/32'],
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`HarnessV1NetworkPolicy` is the harness-level abstraction used here. The provider translates it to `@vercel/sandbox`'s native `NetworkPolicy` for enforcement.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { HarnessV1SandboxProvider, HarnessV1NetworkSandboxSession } from '@ai-sdk/harness';
|
|
2
|
+
import { Experimental_SandboxSession } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { Sandbox } from '@vercel/sandbox';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Flattens an intersection of object types into a single object type so the
|
|
7
|
+
* resolved shape displays as its named properties rather than a chain of
|
|
8
|
+
* `A & B & C`.
|
|
9
|
+
*/
|
|
10
|
+
type Prettify<T> = {
|
|
11
|
+
[K in keyof T]: T[K];
|
|
12
|
+
} & {};
|
|
13
|
+
/**
|
|
14
|
+
* Distributes `Omit` across each member of a union instead of collapsing the
|
|
15
|
+
* union to its common keys. `Sandbox.create`'s parameter is a union (a
|
|
16
|
+
* git/tarball/no-source create variant and a snapshot-source create variant),
|
|
17
|
+
* so a plain `Omit` would discard keys absent from any one member (e.g.
|
|
18
|
+
* `runtime`, which the snapshot variant lacks) and merge the `source` shapes.
|
|
19
|
+
* Applying `Omit` per-member preserves every variant intact; the `Prettify`
|
|
20
|
+
* wrapper collapses each member's intersections into a readable object shape.
|
|
21
|
+
*/
|
|
22
|
+
type DistributiveOmit<T, K extends keyof any> = T extends unknown ? Prettify<Omit<T, K>> : never;
|
|
23
|
+
/**
|
|
24
|
+
* Parameters forwarded to `@vercel/sandbox`'s `Sandbox.create` when creating
|
|
25
|
+
* a sandbox from scratch. Aliased directly from the underlying SDK so the
|
|
26
|
+
* full surface — every option Vercel supports, including its native
|
|
27
|
+
* `NetworkPolicy` — is available without us re-declaring it.
|
|
28
|
+
*/
|
|
29
|
+
type VercelSandboxCreateParams = DistributiveOmit<NonNullable<Parameters<typeof Sandbox.create>[0]>, 'onResume'>;
|
|
30
|
+
/**
|
|
31
|
+
* Settings for {@link createVercelSandbox}. Two mutually-exclusive shapes:
|
|
32
|
+
*
|
|
33
|
+
* - `{ sandbox }` — wrap an already-created `@vercel/sandbox` `Sandbox`. The
|
|
34
|
+
* caller owns its lifecycle; the provider's `stop()` and `destroy()` are
|
|
35
|
+
* no-ops. Optionally declare `bridgePorts` to give the harness a port pool to
|
|
36
|
+
* lease from for concurrent sessions on the same provided sandbox.
|
|
37
|
+
* - {@link VercelSandboxCreateParams} fields — provider creates the underlying
|
|
38
|
+
* sandbox. When the adapter declares a bootstrap recipe the provider uses
|
|
39
|
+
* `Sandbox.getOrCreate` to maintain a persistent named template snapshot
|
|
40
|
+
* keyed by the recipe identity, and forks an ephemeral sandbox per session
|
|
41
|
+
* from the snapshot. Use `name` to override the auto-derived template name.
|
|
42
|
+
*/
|
|
43
|
+
type VercelSandboxSettings = {
|
|
44
|
+
sandbox: Sandbox;
|
|
45
|
+
bridgePorts?: ReadonlyArray<number>;
|
|
46
|
+
} | (VercelSandboxCreateParams & {
|
|
47
|
+
sandbox?: never;
|
|
48
|
+
name?: string;
|
|
49
|
+
});
|
|
50
|
+
declare function createVercelSandbox(settings?: VercelSandboxSettings): HarnessV1SandboxProvider;
|
|
51
|
+
/**
|
|
52
|
+
* `HarnessV1SandboxProvider` implementation backed by `@vercel/sandbox`.
|
|
53
|
+
* Construct one via {@link createVercelSandbox} at module scope and pass it
|
|
54
|
+
* to a `HarnessAgent` (or call `createSession()` directly if you want raw
|
|
55
|
+
* access to a network sandbox session).
|
|
56
|
+
*/
|
|
57
|
+
declare class VercelSandboxProvider implements HarnessV1SandboxProvider {
|
|
58
|
+
private readonly settings;
|
|
59
|
+
readonly specificationVersion: "harness-sandbox-v1";
|
|
60
|
+
readonly providerId = "vercel-sandbox";
|
|
61
|
+
readonly bridgePorts?: ReadonlyArray<number>;
|
|
62
|
+
constructor(settings: VercelSandboxSettings);
|
|
63
|
+
createSession: (options?: {
|
|
64
|
+
sessionId?: string;
|
|
65
|
+
abortSignal?: AbortSignal;
|
|
66
|
+
identity?: string;
|
|
67
|
+
onFirstCreate?: (session: Experimental_SandboxSession, opts: {
|
|
68
|
+
abortSignal?: AbortSignal;
|
|
69
|
+
}) => Promise<void>;
|
|
70
|
+
}) => Promise<HarnessV1NetworkSandboxSession>;
|
|
71
|
+
resumeSession: (options: {
|
|
72
|
+
sessionId: string;
|
|
73
|
+
abortSignal?: AbortSignal;
|
|
74
|
+
}) => Promise<HarnessV1NetworkSandboxSession>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { VercelSandboxProvider, type VercelSandboxSettings, createVercelSandbox };
|