@finalai/sandbox-router-agent-provider 0.1.4 → 0.2.0
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/README.md +41 -7
- package/dist/modules/environment.d.mts +22 -0
- package/dist/modules/environment.mjs +31 -2
- package/dist/modules/environment.mjs.map +3 -3
- package/dist/modules/index.d.mts +3 -2
- package/dist/modules/index.mjs +8 -2
- package/dist/modules/index.mjs.map +2 -2
- package/dist/modules/placement.d.mts +23 -0
- package/dist/modules/placement.mjs +40 -0
- package/dist/modules/placement.mjs.map +7 -0
- package/dist/modules/provider.d.mts +1 -0
- package/dist/modules/provider.mjs +93 -17
- package/dist/modules/provider.mjs.map +2 -2
- package/dist/modules/router-computer-use.d.mts +19 -0
- package/dist/modules/router-computer-use.mjs +211 -0
- package/dist/modules/router-computer-use.mjs.map +7 -0
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -23,7 +23,8 @@ const provider = createRoutedSandboxProvider({
|
|
|
23
23
|
- `router(ctx)`: the router a call uses, with credentials for `ctx.projectId`.
|
|
24
24
|
Sandboxes, builders and snapshots belong to that project; each sandbox carries the label
|
|
25
25
|
`agent-sandbox` (the platform sandbox's id), and `delete` removes every sandbox carrying it.
|
|
26
|
-
- `routing`, `providerOptions`: passed to every create
|
|
26
|
+
- `routing`, `providerOptions`: passed to every create; an environment's `routing` layers over
|
|
27
|
+
`routing` (see below).
|
|
27
28
|
- `name`: the name the provider is registered under (default `routed`).
|
|
28
29
|
- `defaultImage`, `images`: the image of an environment that names none, and image names
|
|
29
30
|
mapped to router images (a spec or a registered `simg_…` id).
|
|
@@ -35,14 +36,21 @@ const provider = createRoutedSandboxProvider({
|
|
|
35
36
|
default deletes sandboxes, which would lose their files.
|
|
36
37
|
- `portTokenTtlS`: how long a port endpoint's token lasts (default an hour) on providers whose
|
|
37
38
|
port tokens expire (`portTokens`); it is renewed before it ends.
|
|
38
|
-
- `computerUse`: the computer-use MCP server (`{ command, user? }`) a desktop image runs
|
|
39
|
-
|
|
39
|
+
- `computerUse`: the computer-use MCP server (`{ command, user? }`) a desktop image runs: the
|
|
40
|
+
fallback for a placed sandbox whose provider lacks the router's computer-use API. With it,
|
|
41
|
+
every environment offers computer use, as before.
|
|
40
42
|
|
|
41
43
|
## Environment
|
|
42
44
|
|
|
43
|
-
`routed({ image, build, machine, region, idleTimeoutSeconds })
|
|
45
|
+
`routed({ image, build, machine, region, idleTimeoutSeconds, routing, computerUse })`
|
|
46
|
+
(`routedEnvironmentSchema`). `/environment` exports the environment schemas and types alone,
|
|
47
|
+
with the enums `routing` takes (`ByokPreference`, `RoutingSort`, `RouterCapability`) and no
|
|
48
|
+
provider code, for a host that serves this provider under another name (Final serves it
|
|
49
|
+
as `computer`, and `computer(...)` from `@finalai/final-agent-provider/sandboxes` takes the same
|
|
50
|
+
options). The options:
|
|
44
51
|
|
|
45
|
-
- `image`: an OCI reference, a registered `simg_…` id, or a name from `images`.
|
|
52
|
+
- `image`: an OCI reference, a registered `simg_…` id, or a name from `images`. `desktop`
|
|
53
|
+
(`DESKTOP_IMAGE`) is the router's desktop preset unless `images.desktop` maps it.
|
|
46
54
|
- `build`: `steps` and `verify` run once on a builder sandbox, which is snapshotted;
|
|
47
55
|
sandboxes start from the snapshot once it is ready. The snapshot is named for its build, so a
|
|
48
56
|
prepare that finds no cached artifact reuses it rather than building again; one that is gone
|
|
@@ -50,6 +58,16 @@ const provider = createRoutedSandboxProvider({
|
|
|
50
58
|
- `machine`: `vcpu`, `memoryMb`, `diskGb`.
|
|
51
59
|
- `idleTimeoutSeconds`: idle time before the sandbox pauses. Without it, the platform's
|
|
52
60
|
idle parking plus five minutes.
|
|
61
|
+
- `routing` (`routedRoutingSchema`): the project's routing preferences: `only`, `order` and
|
|
62
|
+
`ignore` (provider names), `sort` (`price`, `latency`, `balanced`), `byok` (`first`,
|
|
63
|
+
`fallback`, `only`, `off`), `maxPricePerHour` (a decimal USD amount) and `require` (router
|
|
64
|
+
capabilities). Each field it sets replaces the provider config's; `require` is the union of
|
|
65
|
+
both and of what `computerUse` needs; `only` drops the config's `provider` pin. A build's
|
|
66
|
+
snapshot is keyed by these preferences too, since it belongs to the provider it was built on.
|
|
67
|
+
- `computerUse`: a desktop the agent drives. The router places the sandbox only on a provider
|
|
68
|
+
with a verified `desktop` and, unless the host configured the `computerUse` fallback,
|
|
69
|
+
`computerUse`; an environment that names no image gets `desktop`. The same agent then works on
|
|
70
|
+
an E2B, Daytona or Final desktop.
|
|
53
71
|
|
|
54
72
|
The first `attach` creates the sandbox with the setup's network policy (an allowlist's
|
|
55
73
|
address ranges as CIDRs, everything else as domains; deny lists are refused), pausing when
|
|
@@ -59,6 +77,22 @@ Reads and commands through a sandbox's handle never wake it. Large files are wri
|
|
|
59
77
|
parts. `readSnapshot` reads a parked sandbox's workspace without waking it, on providers that
|
|
60
78
|
read a paused disk (`coldFiles`).
|
|
61
79
|
|
|
80
|
+
`fork` copies a sandbox through the router's fork into the new sandbox, which keeps the
|
|
81
|
+
source's network policy and ports and carries its own `agent-sandbox` label, so deleting either
|
|
82
|
+
leaves the other. A retry finds the copy the first call made (by that label, and with the
|
|
83
|
+
router's `Idempotency-Key`). A source that never started has nothing to copy, so its copy starts
|
|
84
|
+
as a new sandbox would.
|
|
85
|
+
|
|
62
86
|
Sandboxes offer files, processes, durable processes (the provider must support
|
|
63
|
-
reattaching), ports, network policy, and, with a
|
|
64
|
-
|
|
87
|
+
reattaching), ports, network policy, and, with a desktop, screen sessions (view-only unless
|
|
88
|
+
input control is asked for) and computer use. What a placed sandbox offers depends on the
|
|
89
|
+
provider it landed on, never on the registration alone:
|
|
90
|
+
|
|
91
|
+
- Computer use goes through the router's provider-neutral API wherever the provider has
|
|
92
|
+
`desktop` and `computerUse`: an MCP server in the host's process whose tools
|
|
93
|
+
(`RouterComputerUseTool`: `screenshot`, `click`, `move`, `drag`, `type`, `key`, `scroll`, in
|
|
94
|
+
screenshot pixels) call the router. A stopped desktop is started on first use for an
|
|
95
|
+
environment that asked for computer use.
|
|
96
|
+
- Elsewhere, with a running desktop and the `computerUse` command configured, the image's own
|
|
97
|
+
computer-use server runs through the router's exec.
|
|
98
|
+
- Otherwise the sandbox offers no computer use, and its handle does not list it.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { ByokPreference, Capability, RoutingSort } from '@finalai/sandbox-router/routing';
|
|
1
2
|
import * as z from 'zod';
|
|
2
3
|
export declare const ROUTED_SANDBOX_PROVIDER = "routed";
|
|
4
|
+
export { ByokPreference, Capability as RouterCapability, RoutingSort, } from '@finalai/sandbox-router/routing';
|
|
3
5
|
export declare const routedBuildSchema: z.ZodObject<{
|
|
4
6
|
steps: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
5
7
|
run: z.ZodString;
|
|
@@ -15,6 +17,15 @@ export declare const routedMachineSchema: z.ZodObject<{
|
|
|
15
17
|
memoryMb: z.ZodOptional<z.ZodNumber>;
|
|
16
18
|
diskGb: z.ZodOptional<z.ZodNumber>;
|
|
17
19
|
}, z.core.$strict>;
|
|
20
|
+
export declare const routedRoutingSchema: z.ZodObject<{
|
|
21
|
+
only: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
22
|
+
order: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
23
|
+
ignore: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
|
+
sort: z.ZodOptional<z.ZodEnum<typeof RoutingSort>>;
|
|
25
|
+
byok: z.ZodOptional<z.ZodEnum<typeof ByokPreference>>;
|
|
26
|
+
maxPricePerHour: z.ZodOptional<z.ZodString>;
|
|
27
|
+
require: z.ZodOptional<z.ZodArray<z.ZodEnum<typeof Capability>>>;
|
|
28
|
+
}, z.core.$strict>;
|
|
18
29
|
export declare const routedEnvironmentSchema: z.ZodObject<{
|
|
19
30
|
image: z.ZodOptional<z.ZodString>;
|
|
20
31
|
build: z.ZodOptional<z.ZodObject<{
|
|
@@ -34,9 +45,20 @@ export declare const routedEnvironmentSchema: z.ZodObject<{
|
|
|
34
45
|
}, z.core.$strict>>;
|
|
35
46
|
region: z.ZodOptional<z.ZodString>;
|
|
36
47
|
idleTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
routing: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
only: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
50
|
+
order: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
51
|
+
ignore: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
52
|
+
sort: z.ZodOptional<z.ZodEnum<typeof RoutingSort>>;
|
|
53
|
+
byok: z.ZodOptional<z.ZodEnum<typeof ByokPreference>>;
|
|
54
|
+
maxPricePerHour: z.ZodOptional<z.ZodString>;
|
|
55
|
+
require: z.ZodOptional<z.ZodArray<z.ZodEnum<typeof Capability>>>;
|
|
56
|
+
}, z.core.$strict>>;
|
|
57
|
+
computerUse: z.ZodOptional<z.ZodBoolean>;
|
|
37
58
|
}, z.core.$strict>;
|
|
38
59
|
export type RoutedBuildIface = z.output<typeof routedBuildSchema>;
|
|
39
60
|
export type RoutedMachineIface = z.output<typeof routedMachineSchema>;
|
|
40
61
|
export type RoutedEnvironmentIface = z.output<typeof routedEnvironmentSchema>;
|
|
41
62
|
export type RoutedEnvironmentInputIface = z.input<typeof routedEnvironmentSchema>;
|
|
63
|
+
export type RoutedRoutingIface = z.output<typeof routedRoutingSchema>;
|
|
42
64
|
export declare const routedNeedsBuild: (build: RoutedBuildIface | undefined) => boolean;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { ByokPreference, Capability, RoutingSort } from "@finalai/sandbox-router/routing";
|
|
1
2
|
import * as z from "zod";
|
|
2
3
|
const ROUTED_SANDBOX_PROVIDER = "routed";
|
|
4
|
+
import {
|
|
5
|
+
ByokPreference as ByokPreference2,
|
|
6
|
+
Capability as Capability2,
|
|
7
|
+
RoutingSort as RoutingSort2
|
|
8
|
+
} from "@finalai/sandbox-router/routing";
|
|
3
9
|
const buildStepSchema = z.strictObject({
|
|
4
10
|
run: z.string().min(1).max(10 * 1024),
|
|
5
11
|
timeoutMinutes: z.number().int().min(1).max(120).default(20)
|
|
@@ -14,6 +20,20 @@ const routedMachineSchema = z.strictObject({
|
|
|
14
20
|
memoryMb: z.number().int().min(512).max(262144).optional(),
|
|
15
21
|
diskGb: z.number().int().min(1).max(2048).optional()
|
|
16
22
|
});
|
|
23
|
+
const routedRoutingSchema = z.strictObject({
|
|
24
|
+
// Only these providers, by name.
|
|
25
|
+
only: z.array(z.string().min(1).max(64)).min(1).max(32).optional(),
|
|
26
|
+
// These providers first, in this order.
|
|
27
|
+
order: z.array(z.string().min(1).max(64)).min(1).max(32).optional(),
|
|
28
|
+
ignore: z.array(z.string().min(1).max(64)).max(32).optional(),
|
|
29
|
+
sort: z.nativeEnum(RoutingSort).optional(),
|
|
30
|
+
// Whose provider account pays: the project's own keys, Final's, or both in an order.
|
|
31
|
+
byok: z.nativeEnum(ByokPreference).optional(),
|
|
32
|
+
// A decimal amount of US dollars.
|
|
33
|
+
maxPricePerHour: z.string().regex(/^\d+(\.\d+)?$/u).optional(),
|
|
34
|
+
// Capabilities the provider must have verified.
|
|
35
|
+
require: z.array(z.nativeEnum(Capability)).max(32).optional()
|
|
36
|
+
});
|
|
17
37
|
const routedEnvironmentSchema = z.strictObject({
|
|
18
38
|
// An OCI image reference, a registered router image id (`simg_…`), or a name the host maps
|
|
19
39
|
// to a router image.
|
|
@@ -22,14 +42,23 @@ const routedEnvironmentSchema = z.strictObject({
|
|
|
22
42
|
machine: routedMachineSchema.optional(),
|
|
23
43
|
region: z.string().min(1).max(64).optional(),
|
|
24
44
|
// Idle time before the sandbox pauses (its disk and processes kept).
|
|
25
|
-
idleTimeoutSeconds: z.number().int().min(60).max(7 * 24 * 60 * 60).optional()
|
|
45
|
+
idleTimeoutSeconds: z.number().int().min(60).max(7 * 24 * 60 * 60).optional(),
|
|
46
|
+
routing: routedRoutingSchema.optional(),
|
|
47
|
+
// A desktop the agent drives (screenshots, mouse and keyboard): the router places the sandbox
|
|
48
|
+
// only on a provider with a verified desktop and computer use, and an environment that names
|
|
49
|
+
// no image gets the router's `desktop` image.
|
|
50
|
+
computerUse: z.boolean().optional()
|
|
26
51
|
});
|
|
27
52
|
const routedNeedsBuild = (build) => build != null && (build.steps.length > 0 || build.verify.length > 0);
|
|
28
53
|
export {
|
|
54
|
+
ByokPreference2 as ByokPreference,
|
|
29
55
|
ROUTED_SANDBOX_PROVIDER,
|
|
56
|
+
Capability2 as RouterCapability,
|
|
57
|
+
RoutingSort2 as RoutingSort,
|
|
30
58
|
routedBuildSchema,
|
|
31
59
|
routedEnvironmentSchema,
|
|
32
60
|
routedMachineSchema,
|
|
33
|
-
routedNeedsBuild
|
|
61
|
+
routedNeedsBuild,
|
|
62
|
+
routedRoutingSchema
|
|
34
63
|
};
|
|
35
64
|
//# sourceMappingURL=environment.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/environment.ts"],
|
|
4
|
-
"sourcesContent": ["import * as z from 'zod';\n\n// Environment options of the routed provider: what a sandbox is created from (an image, steps\n// baked into a snapshot once), its size, region and idle time. What should be on the machine is\n// the provider-neutral sandbox setup, which the platform applies. Pure (no I/O).\n\nexport const ROUTED_SANDBOX_PROVIDER = 'routed';\n\nconst buildStepSchema = z.strictObject({\n run: z\n .string()\n .min(1)\n .max(10 * 1024),\n timeoutMinutes: z.number().int().min(1).max(120).default(20),\n});\n\n// Steps run once on a builder sandbox, which is then snapshotted; sandboxes start from the\n// snapshot. They never run per sandbox.\nexport const routedBuildSchema = z.strictObject({\n steps: z.array(buildStepSchema).max(30).default([]),\n // Checks that the built snapshot works; a failing one fails the build.\n verify: z.array(buildStepSchema).max(30).default([]),\n});\n\nexport const routedMachineSchema = z.strictObject({\n vcpu: z.number().int().min(1).max(32).optional(),\n memoryMb: z.number().int().min(512).max(262_144).optional(),\n diskGb: z.number().int().min(1).max(2048).optional(),\n});\n\nexport const routedEnvironmentSchema = z.strictObject({\n // An OCI image reference, a registered router image id (`simg_\u2026`), or a name the host maps\n // to a router image.\n image: z.string().min(1).max(512).optional(),\n build: routedBuildSchema.optional(),\n machine: routedMachineSchema.optional(),\n region: z.string().min(1).max(64).optional(),\n // Idle time before the sandbox pauses (its disk and processes kept).\n idleTimeoutSeconds: z\n .number()\n .int()\n .min(60)\n .max(7 * 24 * 60 * 60)\n .optional(),\n});\n\nexport type RoutedBuildIface = z.output<typeof routedBuildSchema>;\nexport type RoutedMachineIface = z.output<typeof routedMachineSchema>;\nexport type RoutedEnvironmentIface = z.output<typeof routedEnvironmentSchema>;\nexport type RoutedEnvironmentInputIface = z.input<typeof routedEnvironmentSchema>;\n\nexport const routedNeedsBuild = (build: RoutedBuildIface | undefined): boolean =>\n build != null && (build.steps.length > 0 || build.verify.length > 0);\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,OAAO;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { ByokPreference, Capability, RoutingSort } from '@finalai/sandbox-router/routing';\nimport * as z from 'zod';\n\n// Environment options of the routed provider: what a sandbox is created from (an image, steps\n// baked into a snapshot once), its size, region and idle time. What should be on the machine is\n// the provider-neutral sandbox setup, which the platform applies. Pure (no I/O, no Node modules),\n// so browser bundles can reach it.\n\nexport const ROUTED_SANDBOX_PROVIDER = 'routed';\n\n// The enums `routing` takes, so an environment can be written from this module alone.\nexport {\n ByokPreference,\n Capability as RouterCapability,\n RoutingSort,\n} from '@finalai/sandbox-router/routing';\n\nconst buildStepSchema = z.strictObject({\n run: z\n .string()\n .min(1)\n .max(10 * 1024),\n timeoutMinutes: z.number().int().min(1).max(120).default(20),\n});\n\n// Steps run once on a builder sandbox, which is then snapshotted; sandboxes start from the\n// snapshot. They never run per sandbox.\nexport const routedBuildSchema = z.strictObject({\n steps: z.array(buildStepSchema).max(30).default([]),\n // Checks that the built snapshot works; a failing one fails the build.\n verify: z.array(buildStepSchema).max(30).default([]),\n});\n\nexport const routedMachineSchema = z.strictObject({\n vcpu: z.number().int().min(1).max(32).optional(),\n memoryMb: z.number().int().min(512).max(262_144).optional(),\n diskGb: z.number().int().min(1).max(2048).optional(),\n});\n\n// Routing preferences of the environment, over the provider's own (see the README for how\n// they layer).\nexport const routedRoutingSchema = z.strictObject({\n // Only these providers, by name.\n only: z.array(z.string().min(1).max(64)).min(1).max(32).optional(),\n // These providers first, in this order.\n order: z.array(z.string().min(1).max(64)).min(1).max(32).optional(),\n ignore: z.array(z.string().min(1).max(64)).max(32).optional(),\n sort: z.nativeEnum(RoutingSort).optional(),\n // Whose provider account pays: the project's own keys, Final's, or both in an order.\n byok: z.nativeEnum(ByokPreference).optional(),\n // A decimal amount of US dollars.\n maxPricePerHour: z\n .string()\n .regex(/^\\d+(\\.\\d+)?$/u)\n .optional(),\n // Capabilities the provider must have verified.\n require: z.array(z.nativeEnum(Capability)).max(32).optional(),\n});\n\nexport const routedEnvironmentSchema = z.strictObject({\n // An OCI image reference, a registered router image id (`simg_\u2026`), or a name the host maps\n // to a router image.\n image: z.string().min(1).max(512).optional(),\n build: routedBuildSchema.optional(),\n machine: routedMachineSchema.optional(),\n region: z.string().min(1).max(64).optional(),\n // Idle time before the sandbox pauses (its disk and processes kept).\n idleTimeoutSeconds: z\n .number()\n .int()\n .min(60)\n .max(7 * 24 * 60 * 60)\n .optional(),\n routing: routedRoutingSchema.optional(),\n // A desktop the agent drives (screenshots, mouse and keyboard): the router places the sandbox\n // only on a provider with a verified desktop and computer use, and an environment that names\n // no image gets the router's `desktop` image.\n computerUse: z.boolean().optional(),\n});\n\nexport type RoutedBuildIface = z.output<typeof routedBuildSchema>;\nexport type RoutedMachineIface = z.output<typeof routedMachineSchema>;\nexport type RoutedEnvironmentIface = z.output<typeof routedEnvironmentSchema>;\nexport type RoutedEnvironmentInputIface = z.input<typeof routedEnvironmentSchema>;\nexport type RoutedRoutingIface = z.output<typeof routedRoutingSchema>;\n\nexport const routedNeedsBuild = (build: RoutedBuildIface | undefined): boolean =>\n build != null && (build.steps.length > 0 || build.verify.length > 0);\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB,YAAY,mBAAmB;AACxD,YAAY,OAAO;AAOZ,MAAM,0BAA0B;AAGvC;AAAA,EACE,kBAAAA;AAAA,EACc,cAAdC;AAAA,EACA,eAAAC;AAAA,OACK;AAEP,MAAM,kBAAkB,EAAE,aAAa;AAAA,EACrC,KAAK,EACF,OAAO,EACP,IAAI,CAAC,EACL,IAAI,KAAK,IAAI;AAAA,EAChB,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,QAAQ,EAAE;AAC7D,CAAC;AAIM,MAAM,oBAAoB,EAAE,aAAa;AAAA,EAC9C,OAAO,EAAE,MAAM,eAAe,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,EAElD,QAAQ,EAAE,MAAM,eAAe,EAAE,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;AACrD,CAAC;AAEM,MAAM,sBAAsB,EAAE,aAAa;AAAA,EAChD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA,EAC/C,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,IAAI,MAAO,EAAE,SAAS;AAAA,EAC1D,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI,EAAE,SAAS;AACrD,CAAC;AAIM,MAAM,sBAAsB,EAAE,aAAa;AAAA;AAAA,EAEhD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA;AAAA,EAEjE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA,EAClE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA,EAC5D,MAAM,EAAE,WAAW,WAAW,EAAE,SAAS;AAAA;AAAA,EAEzC,MAAM,EAAE,WAAW,cAAc,EAAE,SAAS;AAAA;AAAA,EAE5C,iBAAiB,EACd,OAAO,EACP,MAAM,gBAAgB,EACtB,SAAS;AAAA;AAAA,EAEZ,SAAS,EAAE,MAAM,EAAE,WAAW,UAAU,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAC9D,CAAC;AAEM,MAAM,0BAA0B,EAAE,aAAa;AAAA;AAAA;AAAA,EAGpD,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,SAAS;AAAA,EAC3C,OAAO,kBAAkB,SAAS;AAAA,EAClC,SAAS,oBAAoB,SAAS;AAAA,EACtC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS;AAAA;AAAA,EAE3C,oBAAoB,EACjB,OAAO,EACP,IAAI,EACJ,IAAI,EAAE,EACN,IAAI,IAAI,KAAK,KAAK,EAAE,EACpB,SAAS;AAAA,EACZ,SAAS,oBAAoB,SAAS;AAAA;AAAA;AAAA;AAAA,EAItC,aAAa,EAAE,QAAQ,EAAE,SAAS;AACpC,CAAC;AAQM,MAAM,mBAAmB,CAAC,UAC/B,SAAS,SAAS,MAAM,MAAM,SAAS,KAAK,MAAM,OAAO,SAAS;",
|
|
6
|
+
"names": ["ByokPreference", "Capability", "RoutingSort"]
|
|
7
7
|
}
|
package/dist/modules/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { JsonObject, SandboxEnvironmentValueIface } from '@finalai/agent-provider';
|
|
2
2
|
import { type RoutedEnvironmentInputIface } from "./environment.mjs";
|
|
3
|
-
export { ROUTED_SANDBOX_PROVIDER, routedBuildSchema, routedEnvironmentSchema, routedMachineSchema, type RoutedBuildIface, type RoutedEnvironmentIface, type RoutedEnvironmentInputIface, type RoutedMachineIface, } from "./environment.mjs";
|
|
3
|
+
export { ROUTED_SANDBOX_PROVIDER, routedBuildSchema, routedEnvironmentSchema, routedMachineSchema, routedRoutingSchema, type RoutedBuildIface, type RoutedEnvironmentIface, type RoutedEnvironmentInputIface, type RoutedMachineIface, type RoutedRoutingIface, } from "./environment.mjs";
|
|
4
4
|
export type { ComputerUseCommandIface } from "./computer-use.mjs";
|
|
5
|
-
export {
|
|
5
|
+
export { RouterComputerUseTool } from "./router-computer-use.mjs";
|
|
6
|
+
export { createRoutedSandboxProvider, DESKTOP_IMAGE, RoutedSandboxErrorCode, routedNetworkPolicyOf, SANDBOX_LABEL, WORKSPACE_ROOT, type RoutedSandboxArtifact, type RoutedSandboxErrorIface, type RoutedSandboxLogIface, type RoutedSandboxProviderConfigIface, type RoutedSandboxProviderIface, type RoutedSandboxSessionIface, type RoutedSandboxState, } from "./provider.mjs";
|
|
6
7
|
export declare const routed: (options?: RoutedEnvironmentInputIface) => SandboxEnvironmentValueIface<JsonObject>;
|
package/dist/modules/index.mjs
CHANGED
|
@@ -7,10 +7,13 @@ import {
|
|
|
7
7
|
ROUTED_SANDBOX_PROVIDER as ROUTED_SANDBOX_PROVIDER2,
|
|
8
8
|
routedBuildSchema,
|
|
9
9
|
routedEnvironmentSchema as routedEnvironmentSchema2,
|
|
10
|
-
routedMachineSchema
|
|
10
|
+
routedMachineSchema,
|
|
11
|
+
routedRoutingSchema
|
|
11
12
|
} from "./environment.mjs";
|
|
13
|
+
import { RouterComputerUseTool } from "./router-computer-use.mjs";
|
|
12
14
|
import {
|
|
13
15
|
createRoutedSandboxProvider,
|
|
16
|
+
DESKTOP_IMAGE,
|
|
14
17
|
RoutedSandboxErrorCode,
|
|
15
18
|
routedNetworkPolicyOf,
|
|
16
19
|
SANDBOX_LABEL,
|
|
@@ -26,8 +29,10 @@ const routed = (options = {}) => {
|
|
|
26
29
|
};
|
|
27
30
|
};
|
|
28
31
|
export {
|
|
32
|
+
DESKTOP_IMAGE,
|
|
29
33
|
ROUTED_SANDBOX_PROVIDER2 as ROUTED_SANDBOX_PROVIDER,
|
|
30
34
|
RoutedSandboxErrorCode,
|
|
35
|
+
RouterComputerUseTool,
|
|
31
36
|
SANDBOX_LABEL,
|
|
32
37
|
WORKSPACE_ROOT,
|
|
33
38
|
createRoutedSandboxProvider,
|
|
@@ -35,6 +40,7 @@ export {
|
|
|
35
40
|
routedBuildSchema,
|
|
36
41
|
routedEnvironmentSchema2 as routedEnvironmentSchema,
|
|
37
42
|
routedMachineSchema,
|
|
38
|
-
routedNetworkPolicyOf
|
|
43
|
+
routedNetworkPolicyOf,
|
|
44
|
+
routedRoutingSchema
|
|
39
45
|
};
|
|
40
46
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import type { JsonObject, SandboxEnvironmentValueIface } from '@finalai/agent-provider';\nimport { jsonObjectSchema } from '@finalai/agent-provider';\nimport {\n ROUTED_SANDBOX_PROVIDER,\n routedEnvironmentSchema,\n type RoutedEnvironmentInputIface,\n} from \"./environment.mjs\";\n\nexport {\n ROUTED_SANDBOX_PROVIDER,\n routedBuildSchema,\n routedEnvironmentSchema,\n routedMachineSchema,\n type RoutedBuildIface,\n type RoutedEnvironmentIface,\n type RoutedEnvironmentInputIface,\n type RoutedMachineIface,\n} from \"./environment.mjs\";\nexport type { ComputerUseCommandIface } from \"./computer-use.mjs\";\nexport {\n createRoutedSandboxProvider,\n RoutedSandboxErrorCode,\n routedNetworkPolicyOf,\n SANDBOX_LABEL,\n WORKSPACE_ROOT,\n type RoutedSandboxArtifact,\n type RoutedSandboxErrorIface,\n type RoutedSandboxLogIface,\n type RoutedSandboxProviderConfigIface,\n type RoutedSandboxProviderIface,\n type RoutedSandboxSessionIface,\n type RoutedSandboxState,\n} from \"./provider.mjs\";\n\n// A routed sandbox environment as plain data: `project.sandboxes.create(routed({ image }))`.\nexport const routed = (\n options: RoutedEnvironmentInputIface = {},\n): SandboxEnvironmentValueIface<JsonObject> => {\n const parsed = routedEnvironmentSchema.safeParse(options);\n if (!parsed.success)\n throw new Error(`invalid ${ROUTED_SANDBOX_PROVIDER} environment: ${parsed.error.message}`);\n // The input as written (defaults are the provider's), with undefined members dropped.\n return {\n provider: ROUTED_SANDBOX_PROVIDER,\n environment: jsonObjectSchema.parse(JSON.parse(JSON.stringify(options))),\n };\n};\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP;AAAA,EACE,2BAAAA;AAAA,EACA;AAAA,EACA,2BAAAC;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["import type { JsonObject, SandboxEnvironmentValueIface } from '@finalai/agent-provider';\nimport { jsonObjectSchema } from '@finalai/agent-provider';\nimport {\n ROUTED_SANDBOX_PROVIDER,\n routedEnvironmentSchema,\n type RoutedEnvironmentInputIface,\n} from \"./environment.mjs\";\n\nexport {\n ROUTED_SANDBOX_PROVIDER,\n routedBuildSchema,\n routedEnvironmentSchema,\n routedMachineSchema,\n routedRoutingSchema,\n type RoutedBuildIface,\n type RoutedEnvironmentIface,\n type RoutedEnvironmentInputIface,\n type RoutedMachineIface,\n type RoutedRoutingIface,\n} from \"./environment.mjs\";\nexport type { ComputerUseCommandIface } from \"./computer-use.mjs\";\nexport { RouterComputerUseTool } from \"./router-computer-use.mjs\";\nexport {\n createRoutedSandboxProvider,\n DESKTOP_IMAGE,\n RoutedSandboxErrorCode,\n routedNetworkPolicyOf,\n SANDBOX_LABEL,\n WORKSPACE_ROOT,\n type RoutedSandboxArtifact,\n type RoutedSandboxErrorIface,\n type RoutedSandboxLogIface,\n type RoutedSandboxProviderConfigIface,\n type RoutedSandboxProviderIface,\n type RoutedSandboxSessionIface,\n type RoutedSandboxState,\n} from \"./provider.mjs\";\n\n// A routed sandbox environment as plain data: `project.sandboxes.create(routed({ image }))`.\nexport const routed = (\n options: RoutedEnvironmentInputIface = {},\n): SandboxEnvironmentValueIface<JsonObject> => {\n const parsed = routedEnvironmentSchema.safeParse(options);\n if (!parsed.success)\n throw new Error(`invalid ${ROUTED_SANDBOX_PROVIDER} environment: ${parsed.error.message}`);\n // The input as written (defaults are the provider's), with undefined members dropped.\n return {\n provider: ROUTED_SANDBOX_PROVIDER,\n environment: jsonObjectSchema.parse(JSON.parse(JSON.stringify(options))),\n };\n};\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP;AAAA,EACE,2BAAAA;AAAA,EACA;AAAA,EACA,2BAAAC;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AAEP,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAQK;AAGA,MAAM,SAAS,CACpB,UAAuC,CAAC,MACK;AAC7C,QAAM,SAAS,wBAAwB,UAAU,OAAO;AACxD,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,WAAW,uBAAuB,iBAAiB,OAAO,MAAM,OAAO,EAAE;AAE3F,SAAO;AAAA,IACL,UAAU;AAAA,IACV,aAAa,iBAAiB,MAAM,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC,CAAC;AAAA,EACzE;AACF;",
|
|
6
6
|
"names": ["ROUTED_SANDBOX_PROVIDER", "routedEnvironmentSchema"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Capability as RouterCapability, DesktopState, type RoutingOptionsIface } from '@finalai/sandbox-router';
|
|
2
|
+
import type { RoutedRoutingIface } from "./environment.mjs";
|
|
3
|
+
export declare const routedRoutingOf: (args: {
|
|
4
|
+
config: RoutingOptionsIface | undefined;
|
|
5
|
+
environment: RoutedRoutingIface | undefined;
|
|
6
|
+
require: readonly RouterCapability[];
|
|
7
|
+
}) => RoutingOptionsIface | undefined;
|
|
8
|
+
export declare const computerUseRequirements: (hasCommand: boolean) => RouterCapability[];
|
|
9
|
+
export declare enum RoutedComputerUseKind {
|
|
10
|
+
Router = "router",
|
|
11
|
+
Command = "command"
|
|
12
|
+
}
|
|
13
|
+
export declare const routedComputerUseOf: (args: {
|
|
14
|
+
capabilities: readonly RouterCapability[];
|
|
15
|
+
desktop: DesktopState | null;
|
|
16
|
+
requested: boolean;
|
|
17
|
+
hasCommand: boolean;
|
|
18
|
+
}) => RoutedComputerUseKind | null;
|
|
19
|
+
export declare const routedDesktopAvailable: (args: {
|
|
20
|
+
capabilities: readonly RouterCapability[];
|
|
21
|
+
desktop: DesktopState | null;
|
|
22
|
+
requested: boolean;
|
|
23
|
+
}) => boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Capability as RouterCapability,
|
|
3
|
+
DesktopState
|
|
4
|
+
} from "@finalai/sandbox-router";
|
|
5
|
+
const routedRoutingOf = (args) => {
|
|
6
|
+
const { provider, require: configRequire, ...configRest } = args.config ?? {};
|
|
7
|
+
const { require: environmentRequire, ...environmentRest } = args.environment ?? {};
|
|
8
|
+
const require2 = [
|
|
9
|
+
.../* @__PURE__ */ new Set([...configRequire ?? [], ...environmentRequire ?? [], ...args.require])
|
|
10
|
+
];
|
|
11
|
+
const routing = {
|
|
12
|
+
...provider == null || environmentRest.only != null ? {} : { provider },
|
|
13
|
+
...configRest,
|
|
14
|
+
...environmentRest,
|
|
15
|
+
...require2.length === 0 ? {} : { require: require2 }
|
|
16
|
+
};
|
|
17
|
+
return Object.keys(routing).length === 0 ? void 0 : routing;
|
|
18
|
+
};
|
|
19
|
+
const computerUseRequirements = (hasCommand) => hasCommand ? [RouterCapability.Desktop] : [RouterCapability.Desktop, RouterCapability.ComputerUse];
|
|
20
|
+
var RoutedComputerUseKind = /* @__PURE__ */ ((RoutedComputerUseKind2) => {
|
|
21
|
+
RoutedComputerUseKind2["Router"] = "router";
|
|
22
|
+
RoutedComputerUseKind2["Command"] = "command";
|
|
23
|
+
return RoutedComputerUseKind2;
|
|
24
|
+
})(RoutedComputerUseKind || {});
|
|
25
|
+
const desktopUp = (desktop) => desktop === DesktopState.Running || desktop === DesktopState.Starting;
|
|
26
|
+
const routedComputerUseOf = (args) => {
|
|
27
|
+
const routerApi = args.capabilities.includes(RouterCapability.Desktop) && args.capabilities.includes(RouterCapability.ComputerUse);
|
|
28
|
+
if (routerApi && (desktopUp(args.desktop) || args.requested)) return "router" /* Router */;
|
|
29
|
+
if (desktopUp(args.desktop) && args.hasCommand) return "command" /* Command */;
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
const routedDesktopAvailable = (args) => desktopUp(args.desktop) || args.requested && args.capabilities.includes(RouterCapability.Desktop);
|
|
33
|
+
export {
|
|
34
|
+
RoutedComputerUseKind,
|
|
35
|
+
computerUseRequirements,
|
|
36
|
+
routedComputerUseOf,
|
|
37
|
+
routedDesktopAvailable,
|
|
38
|
+
routedRoutingOf
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=placement.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/placement.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n Capability as RouterCapability,\n DesktopState,\n type RoutingOptionsIface,\n} from '@finalai/sandbox-router';\nimport type { RoutedRoutingIface } from \"./environment.mjs\";\n\n// Where a routed sandbox may be placed, and what a placed one offers. Pure (no I/O).\n\n// The routing a create uses: the environment's preferences over the provider's. Each field the\n// environment sets replaces the provider's; `require` is the union of both and of what the\n// environment's use needs; a provider pin (`provider`) gives way to an environment's `only`.\nexport const routedRoutingOf = (args: {\n config: RoutingOptionsIface | undefined;\n environment: RoutedRoutingIface | undefined;\n require: readonly RouterCapability[];\n}): RoutingOptionsIface | undefined => {\n const { provider, require: configRequire, ...configRest } = args.config ?? {};\n const { require: environmentRequire, ...environmentRest } = args.environment ?? {};\n const require = [\n ...new Set([...(configRequire ?? []), ...(environmentRequire ?? []), ...args.require]),\n ];\n const routing: RoutingOptionsIface = {\n ...(provider == null || environmentRest.only != null ? {} : { provider }),\n ...configRest,\n ...environmentRest,\n ...(require.length === 0 ? {} : { require }),\n };\n return Object.keys(routing).length === 0 ? undefined : routing;\n};\n\n// What a computer-use environment needs of its provider: a desktop, and the router's computer-use\n// API unless the host has an in-image computer-use server to fall back on.\nexport const computerUseRequirements = (hasCommand: boolean): RouterCapability[] =>\n hasCommand\n ? [RouterCapability.Desktop]\n : [RouterCapability.Desktop, RouterCapability.ComputerUse];\n\nexport enum RoutedComputerUseKind {\n // The router's provider-neutral screenshots and input.\n Router = 'router',\n // The computer-use MCP server the image ships, run through the router's exec.\n Command = 'command',\n}\n\nconst desktopUp = (desktop: DesktopState | null): boolean =>\n desktop === DesktopState.Running || desktop === DesktopState.Starting;\n\n// How a placed sandbox offers computer use, or null when it cannot. The router's API wins\n// wherever the provider has it; the image's server is the fallback. A desktop that is not up is\n// started on first use only for an environment that asked for computer use.\nexport const routedComputerUseOf = (args: {\n capabilities: readonly RouterCapability[];\n desktop: DesktopState | null;\n requested: boolean;\n hasCommand: boolean;\n}): RoutedComputerUseKind | null => {\n const routerApi =\n args.capabilities.includes(RouterCapability.Desktop) &&\n args.capabilities.includes(RouterCapability.ComputerUse);\n if (routerApi && (desktopUp(args.desktop) || args.requested)) return RoutedComputerUseKind.Router;\n if (desktopUp(args.desktop) && args.hasCommand) return RoutedComputerUseKind.Command;\n return null;\n};\n\n// Whether a placed sandbox has a desktop to show: one that is up, or one the provider has for an\n// environment that asked for it (started on first use).\nexport const routedDesktopAvailable = (args: {\n capabilities: readonly RouterCapability[];\n desktop: DesktopState | null;\n requested: boolean;\n}): boolean =>\n desktopUp(args.desktop) ||\n (args.requested && args.capabilities.includes(RouterCapability.Desktop));\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EACE,cAAc;AAAA,EACd;AAAA,OAEK;AAQA,MAAM,kBAAkB,CAAC,SAIO;AACrC,QAAM,EAAE,UAAU,SAAS,eAAe,GAAG,WAAW,IAAI,KAAK,UAAU,CAAC;AAC5E,QAAM,EAAE,SAAS,oBAAoB,GAAG,gBAAgB,IAAI,KAAK,eAAe,CAAC;AACjF,QAAMA,WAAU;AAAA,IACd,GAAG,oBAAI,IAAI,CAAC,GAAI,iBAAiB,CAAC,GAAI,GAAI,sBAAsB,CAAC,GAAI,GAAG,KAAK,OAAO,CAAC;AAAA,EACvF;AACA,QAAM,UAA+B;AAAA,IACnC,GAAI,YAAY,QAAQ,gBAAgB,QAAQ,OAAO,CAAC,IAAI,EAAE,SAAS;AAAA,IACvE,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAIA,SAAQ,WAAW,IAAI,CAAC,IAAI,EAAE,SAAAA,SAAQ;AAAA,EAC5C;AACA,SAAO,OAAO,KAAK,OAAO,EAAE,WAAW,IAAI,SAAY;AACzD;AAIO,MAAM,0BAA0B,CAAC,eACtC,aACI,CAAC,iBAAiB,OAAO,IACzB,CAAC,iBAAiB,SAAS,iBAAiB,WAAW;AAEtD,IAAK,wBAAL,kBAAKC,2BAAL;AAEL,EAAAA,uBAAA,YAAS;AAET,EAAAA,uBAAA,aAAU;AAJA,SAAAA;AAAA,GAAA;AAOZ,MAAM,YAAY,CAAC,YACjB,YAAY,aAAa,WAAW,YAAY,aAAa;AAKxD,MAAM,sBAAsB,CAAC,SAKA;AAClC,QAAM,YACJ,KAAK,aAAa,SAAS,iBAAiB,OAAO,KACnD,KAAK,aAAa,SAAS,iBAAiB,WAAW;AACzD,MAAI,cAAc,UAAU,KAAK,OAAO,KAAK,KAAK,WAAY,QAAO;AACrE,MAAI,UAAU,KAAK,OAAO,KAAK,KAAK,WAAY,QAAO;AACvD,SAAO;AACT;AAIO,MAAM,yBAAyB,CAAC,SAKrC,UAAU,KAAK,OAAO,KACrB,KAAK,aAAa,KAAK,aAAa,SAAS,iBAAiB,OAAO;",
|
|
6
|
+
"names": ["require", "RoutedComputerUseKind"]
|
|
7
|
+
}
|
|
@@ -6,6 +6,7 @@ import { type ComputerUseCommandIface } from "./computer-use.mjs";
|
|
|
6
6
|
import { type RoutedMachineIface } from "./environment.mjs";
|
|
7
7
|
export declare const WORKSPACE_ROOT = "/workspaces";
|
|
8
8
|
export declare const SANDBOX_LABEL = "agent-sandbox";
|
|
9
|
+
export declare const DESKTOP_IMAGE = "desktop";
|
|
9
10
|
export interface RoutedSandboxLogIface {
|
|
10
11
|
(message: string, fields?: Record<string, string | number | boolean | null>): void;
|
|
11
12
|
}
|
|
@@ -37,6 +37,14 @@ import {
|
|
|
37
37
|
routedNeedsBuild
|
|
38
38
|
} from "./environment.mjs";
|
|
39
39
|
import { routerNetworkOf } from "./network.mjs";
|
|
40
|
+
import {
|
|
41
|
+
computerUseRequirements,
|
|
42
|
+
RoutedComputerUseKind,
|
|
43
|
+
routedComputerUseOf,
|
|
44
|
+
routedDesktopAvailable,
|
|
45
|
+
routedRoutingOf
|
|
46
|
+
} from "./placement.mjs";
|
|
47
|
+
import { createRouterComputerUseEndpoint, ensureDesktopRunning } from "./router-computer-use.mjs";
|
|
40
48
|
import {
|
|
41
49
|
createRouterSession,
|
|
42
50
|
isRouterNotFound,
|
|
@@ -48,6 +56,7 @@ import {
|
|
|
48
56
|
} from "./session.mjs";
|
|
49
57
|
const WORKSPACE_ROOT = "/workspaces";
|
|
50
58
|
const SANDBOX_LABEL = "agent-sandbox";
|
|
59
|
+
const DESKTOP_IMAGE = "desktop";
|
|
51
60
|
const DEFAULT_IDLE_TIMEOUT_SECONDS = 15 * 60;
|
|
52
61
|
const IDLE_TIMEOUT_MARGIN_SECONDS = 5 * 60;
|
|
53
62
|
const BUILDER_IDLE_TIMEOUT_SECONDS = 2 * 60 * 60;
|
|
@@ -137,7 +146,9 @@ const artifactKeyOf = async (inputs) => {
|
|
|
137
146
|
v: ARTIFACT_KEY_VERSION,
|
|
138
147
|
image: inputs.image,
|
|
139
148
|
build: { steps: inputs.build?.steps ?? [], verify: inputs.build?.verify ?? [] },
|
|
140
|
-
machine: inputs.machine ?? null
|
|
149
|
+
machine: inputs.machine ?? null,
|
|
150
|
+
// Absent for environments without routing preferences, keeping their earlier keys.
|
|
151
|
+
routing: inputs.routing
|
|
141
152
|
})
|
|
142
153
|
);
|
|
143
154
|
return `snap-${hex.slice(0, 16)}`;
|
|
@@ -161,6 +172,7 @@ const createRoutedSandboxProvider = (config) => {
|
|
|
161
172
|
const alias = config.images?.[name];
|
|
162
173
|
if (alias != null)
|
|
163
174
|
return typeof alias === "string" || !("toJSON" in alias) ? alias : alias.toJSON();
|
|
175
|
+
if (name === DESKTOP_IMAGE) return routerImage.desktop().toJSON();
|
|
164
176
|
if (name.startsWith("simg_")) return name;
|
|
165
177
|
return routerImage.from(name).toJSON();
|
|
166
178
|
};
|
|
@@ -184,9 +196,9 @@ const createRoutedSandboxProvider = (config) => {
|
|
|
184
196
|
diskGib: machine?.diskGb
|
|
185
197
|
};
|
|
186
198
|
};
|
|
187
|
-
const routed = (options) => ({
|
|
199
|
+
const routed = (routing, options) => ({
|
|
188
200
|
...options,
|
|
189
|
-
routing
|
|
201
|
+
routing,
|
|
190
202
|
providerOptions: config.providerOptions
|
|
191
203
|
});
|
|
192
204
|
const findSandbox = async (router, id) => {
|
|
@@ -278,10 +290,10 @@ const createRoutedSandboxProvider = (config) => {
|
|
|
278
290
|
log("routed_sandbox.snapshot_delete_failed", { snapshotId, error: errorText(error) });
|
|
279
291
|
}
|
|
280
292
|
};
|
|
281
|
-
const builtSnapshot = async (router, key) => {
|
|
293
|
+
const builtSnapshot = async (router, routing, key) => {
|
|
282
294
|
let listed;
|
|
283
295
|
try {
|
|
284
|
-
listed = await router.snapshots.list({ provider:
|
|
296
|
+
listed = await router.snapshots.list({ provider: routing?.provider });
|
|
285
297
|
} catch (cause) {
|
|
286
298
|
if (isRouterUnsupported(cause)) return null;
|
|
287
299
|
throw cause;
|
|
@@ -354,8 +366,19 @@ const createRoutedSandboxProvider = (config) => {
|
|
|
354
366
|
}
|
|
355
367
|
});
|
|
356
368
|
const desktop = await desktopState(sandbox);
|
|
357
|
-
const
|
|
358
|
-
|
|
369
|
+
const placed = {
|
|
370
|
+
capabilities: sandbox.info.capabilities,
|
|
371
|
+
desktop,
|
|
372
|
+
requested: args.computerUse
|
|
373
|
+
};
|
|
374
|
+
const desktopUp = routedDesktopAvailable(placed);
|
|
375
|
+
const computerUseKind = args.passive ? null : routedComputerUseOf({ ...placed, hasCommand: config.computerUse != null });
|
|
376
|
+
const computerUse = computerUseKind === RoutedComputerUseKind.Router ? createRouterComputerUseEndpoint({ sandbox }) : computerUseKind === RoutedComputerUseKind.Command && config.computerUse != null ? createComputerUseEndpoint({ sandbox, server: config.computerUse, cwd: WORKSPACE_ROOT }) : null;
|
|
377
|
+
log("routed_sandbox.computer_use", {
|
|
378
|
+
sandboxId: sandbox.id,
|
|
379
|
+
provider: sandbox.info.provider,
|
|
380
|
+
computerUse: computerUseKind
|
|
381
|
+
});
|
|
359
382
|
const closeComputerUse = async () => {
|
|
360
383
|
try {
|
|
361
384
|
await computerUse?.close();
|
|
@@ -391,6 +414,7 @@ const createRoutedSandboxProvider = (config) => {
|
|
|
391
414
|
if (computerUse != null) full.computerUse = async () => computerUse.endpoint;
|
|
392
415
|
if (desktopUp)
|
|
393
416
|
full.screen = async (options) => {
|
|
417
|
+
if (args.computerUse) await ensureDesktopRunning(sandbox);
|
|
394
418
|
const screen = await sandbox.desktop.screen({ viewOnly: options?.viewOnly !== false });
|
|
395
419
|
if (screen.token == null || screen.expiresAt == null)
|
|
396
420
|
throw new Error("the screen session has no token or expiry");
|
|
@@ -415,7 +439,7 @@ const createRoutedSandboxProvider = (config) => {
|
|
|
415
439
|
const build = async (args) => {
|
|
416
440
|
const { ctx, router, key } = args;
|
|
417
441
|
const builder = await router.sandboxes.create(
|
|
418
|
-
routed({
|
|
442
|
+
routed(args.routing, {
|
|
419
443
|
image: args.image ?? void 0,
|
|
420
444
|
...sizeOf(args.machine),
|
|
421
445
|
lifecycle: {
|
|
@@ -480,14 +504,26 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
480
504
|
`invalid routed environment: ${parsed.error.message}`
|
|
481
505
|
);
|
|
482
506
|
const options = parsed.data;
|
|
483
|
-
const
|
|
507
|
+
const computerUseRequested = options.computerUse === true;
|
|
508
|
+
const imageName = options.image ?? (computerUseRequested ? DESKTOP_IMAGE : config.defaultImage) ?? null;
|
|
484
509
|
const image = routerImageOf(imageName);
|
|
510
|
+
const routing = routedRoutingOf({
|
|
511
|
+
config: config.routing,
|
|
512
|
+
environment: options.routing,
|
|
513
|
+
require: computerUseRequested ? computerUseRequirements(config.computerUse != null) : []
|
|
514
|
+
});
|
|
515
|
+
const buildRouting = options.routing;
|
|
485
516
|
const machine = options.machine ?? config.machine;
|
|
486
517
|
const region = options.region ?? config.region ?? null;
|
|
487
518
|
const idleTimeoutFor = (ctx) => options.idleTimeoutSeconds ?? (ctx.lifecycle.parkAfterIdleMs == null ? DEFAULT_IDLE_TIMEOUT_SECONDS : Math.ceil(ctx.lifecycle.parkAfterIdleMs / 1e3) + IDLE_TIMEOUT_MARGIN_SECONDS);
|
|
488
519
|
const seedsFor = (ctx) => sandboxSeedFiles({ files: ctx.files, resources: ctx.resources });
|
|
489
520
|
const keyFor = async (files) => {
|
|
490
|
-
const baseKey = await artifactKeyOf({
|
|
521
|
+
const baseKey = await artifactKeyOf({
|
|
522
|
+
image: imageName,
|
|
523
|
+
build: options.build,
|
|
524
|
+
machine,
|
|
525
|
+
routing: buildRouting
|
|
526
|
+
});
|
|
491
527
|
return Object.keys(files).length === 0 ? baseKey : `${baseKey}-s${await sha256Hex(sandboxSeedIdentity(files))}`;
|
|
492
528
|
};
|
|
493
529
|
const stateOf = (raw) => {
|
|
@@ -595,7 +631,7 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
595
631
|
capabilities: async () => ({
|
|
596
632
|
[Capability.Files]: FilesAccess.Write,
|
|
597
633
|
[Capability.Shell]: ShellAccess.Execute,
|
|
598
|
-
...config.computerUse == null ? {} : { [Capability.ComputerUse]: ScreenAccess.Control }
|
|
634
|
+
...config.computerUse == null && !computerUseRequested ? {} : { [Capability.ComputerUse]: ScreenAccess.Control }
|
|
599
635
|
}),
|
|
600
636
|
processes: async (ctx, rawState, request) => {
|
|
601
637
|
const sandbox = await runningSandbox(ctx, stateOf(rawState));
|
|
@@ -656,14 +692,15 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
656
692
|
const cached = artifactSchema.safeParse(await ctx.artifacts?.get(baseKey));
|
|
657
693
|
if (cached.success && cached.data.base.kind === "snapshot" && await readySnapshot(router, cached.data.base.snapshotId) != null)
|
|
658
694
|
return { ...cached.data, key, ...seedArtifact };
|
|
659
|
-
const snapshotId = await builtSnapshot(router, baseKey) ?? (await build({
|
|
695
|
+
const snapshotId = await builtSnapshot(router, routing, baseKey) ?? (await build({
|
|
660
696
|
ctx,
|
|
661
697
|
router,
|
|
662
698
|
image,
|
|
663
699
|
build: options.build,
|
|
664
700
|
machine,
|
|
665
701
|
region,
|
|
666
|
-
key: baseKey
|
|
702
|
+
key: baseKey,
|
|
703
|
+
routing
|
|
667
704
|
})).snapshotId;
|
|
668
705
|
const built = {
|
|
669
706
|
version: 1,
|
|
@@ -680,7 +717,7 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
680
717
|
else if (image != null) {
|
|
681
718
|
const record = await router.images.prepare({
|
|
682
719
|
image,
|
|
683
|
-
providers:
|
|
720
|
+
providers: routing?.provider == null ? routing?.only == null ? void 0 : [...routing.only] : [routing.provider],
|
|
684
721
|
providerOptions: config.providerOptions
|
|
685
722
|
});
|
|
686
723
|
const failed = record.builds.filter((entry) => entry.state === ImageBuildState.Failed);
|
|
@@ -707,6 +744,42 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
707
744
|
];
|
|
708
745
|
return { state: { version: 1, sandboxId: null, network, ports }, region };
|
|
709
746
|
},
|
|
747
|
+
// A copy of a sandbox of this environment, through the router's fork. A source that never
|
|
748
|
+
// started has nothing to copy, so its copy starts as a new sandbox would. A retry finds the
|
|
749
|
+
// copy the first call made by its label, and the router's idempotency key covers a retry
|
|
750
|
+
// racing the first call.
|
|
751
|
+
fork: async (ctx, { source }) => {
|
|
752
|
+
const sourceState = stateOf(source.state);
|
|
753
|
+
const copied = {
|
|
754
|
+
version: 1,
|
|
755
|
+
sandboxId: null,
|
|
756
|
+
network: sourceState.network,
|
|
757
|
+
ports: sourceState.ports
|
|
758
|
+
};
|
|
759
|
+
if (sourceState.sandboxId == null) return { state: copied, region };
|
|
760
|
+
const router = config.router(ctx);
|
|
761
|
+
const earlier = (await router.sandboxes.list({ labels: { [SANDBOX_LABEL]: ctx.sandboxId } })).find((sandbox) => sandbox.info.state !== SandboxState.Deleted);
|
|
762
|
+
if (earlier != null)
|
|
763
|
+
return { state: { ...copied, sandboxId: earlier.id }, region: earlier.info.region };
|
|
764
|
+
const parent = await findSandbox(router, sourceState.sandboxId);
|
|
765
|
+
if (parent == null)
|
|
766
|
+
throw routedSandboxError(
|
|
767
|
+
"sandbox_gone" /* SandboxGone */,
|
|
768
|
+
`sandbox ${sourceState.sandboxId} to fork is gone`
|
|
769
|
+
);
|
|
770
|
+
const idempotencyKey = `agent-sandbox-fork-${(await sha256Hex(`${ctx.sandboxId}:${parent.id}`)).slice(0, 32)}`;
|
|
771
|
+
const [child] = await parent.fork(1, {
|
|
772
|
+
labels: { ...config.labels, [SANDBOX_LABEL]: ctx.sandboxId },
|
|
773
|
+
idempotencyKey
|
|
774
|
+
});
|
|
775
|
+
if (child == null)
|
|
776
|
+
throw routedSandboxError(
|
|
777
|
+
"sandbox_gone" /* SandboxGone */,
|
|
778
|
+
`the router made no fork of sandbox ${parent.id}`
|
|
779
|
+
);
|
|
780
|
+
log("routed_sandbox.forked", { sandboxId: child.id, source: parent.id });
|
|
781
|
+
return { state: { ...copied, sandboxId: child.id }, region: child.info.region };
|
|
782
|
+
},
|
|
710
783
|
awaitRunning: async (ctx, rawState, awaitOptions) => {
|
|
711
784
|
const state = stateOf(rawState);
|
|
712
785
|
if (state.sandboxId == null)
|
|
@@ -762,7 +835,7 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
762
835
|
const idempotencyKey = `agent-sandbox-${(await sha256Hex(`${ctx.sandboxId}:${state.sandboxId ?? "first"}:${source}`)).slice(0, 32)}`;
|
|
763
836
|
try {
|
|
764
837
|
sandbox = await router.sandboxes.create(
|
|
765
|
-
routed({
|
|
838
|
+
routed(routing, {
|
|
766
839
|
...base.kind === "snapshot" ? { snapshot: base.snapshotId } : { image: imageFromArtifact(artifact.data.image) },
|
|
767
840
|
...sizeOf(machine),
|
|
768
841
|
network,
|
|
@@ -816,7 +889,8 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
816
889
|
sandbox,
|
|
817
890
|
env,
|
|
818
891
|
ports: state.ports,
|
|
819
|
-
passive: false
|
|
892
|
+
passive: false,
|
|
893
|
+
computerUse: computerUseRequested
|
|
820
894
|
});
|
|
821
895
|
return {
|
|
822
896
|
handle,
|
|
@@ -852,7 +926,8 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
852
926
|
sandbox,
|
|
853
927
|
env: platformProcessEnvironment(ctx, {}),
|
|
854
928
|
ports: state.ports,
|
|
855
|
-
passive: true
|
|
929
|
+
passive: true,
|
|
930
|
+
computerUse: computerUseRequested
|
|
856
931
|
});
|
|
857
932
|
},
|
|
858
933
|
// The sandbox pauses on its own idle lifecycle; nothing to do.
|
|
@@ -919,6 +994,7 @@ ${step.run}`, step.timeoutMinutes * 6e4);
|
|
|
919
994
|
});
|
|
920
995
|
};
|
|
921
996
|
export {
|
|
997
|
+
DESKTOP_IMAGE,
|
|
922
998
|
RoutedSandboxErrorCode,
|
|
923
999
|
SANDBOX_LABEL,
|
|
924
1000
|
WORKSPACE_ROOT,
|