@finalai/sandbox-router-final 0.0.0-stage → 0.2.1
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +38 -2
- package/dist/modules/frames.d.mts +18 -0
- package/dist/modules/frames.mjs +98 -0
- package/dist/modules/frames.mjs.map +7 -0
- package/dist/modules/images.d.mts +15 -0
- package/dist/modules/images.mjs +116 -0
- package/dist/modules/images.mjs.map +7 -0
- package/dist/modules/index.d.mts +4 -0
- package/dist/modules/index.mjs +16 -0
- package/dist/modules/index.mjs.map +7 -0
- package/dist/modules/limits.d.mts +6 -0
- package/dist/modules/limits.mjs +37 -0
- package/dist/modules/limits.mjs.map +7 -0
- package/dist/modules/options.d.mts +24 -0
- package/dist/modules/options.mjs +19 -0
- package/dist/modules/options.mjs.map +7 -0
- package/dist/modules/provider.d.mts +5 -0
- package/dist/modules/provider.mjs +654 -0
- package/dist/modules/provider.mjs.map +7 -0
- package/dist/modules/vm/api.d.mts +28 -0
- package/dist/modules/vm/api.mjs +94 -0
- package/dist/modules/vm/api.mjs.map +7 -0
- package/dist/modules/vm/client.d.mts +104 -0
- package/dist/modules/vm/client.mjs +186 -0
- package/dist/modules/vm/client.mjs.map +7 -0
- package/dist/modules/vm/clock.d.mts +5 -0
- package/dist/modules/vm/clock.mjs +11 -0
- package/dist/modules/vm/clock.mjs.map +7 -0
- package/dist/modules/vm/errors.d.mts +23 -0
- package/dist/modules/vm/errors.mjs +30 -0
- package/dist/modules/vm/errors.mjs.map +7 -0
- package/dist/modules/vm/exec.d.mts +47 -0
- package/dist/modules/vm/exec.mjs +292 -0
- package/dist/modules/vm/exec.mjs.map +7 -0
- package/dist/modules/vm/files.d.mts +18 -0
- package/dist/modules/vm/files.mjs +160 -0
- package/dist/modules/vm/files.mjs.map +7 -0
- package/dist/modules/vm/grants.d.mts +35 -0
- package/dist/modules/vm/grants.mjs +106 -0
- package/dist/modules/vm/grants.mjs.map +7 -0
- package/dist/modules/vm/ids.d.mts +3 -0
- package/dist/modules/vm/ids.mjs +35 -0
- package/dist/modules/vm/ids.mjs.map +7 -0
- package/dist/modules/vm/ingress.d.mts +99 -0
- package/dist/modules/vm/ingress.mjs +263 -0
- package/dist/modules/vm/ingress.mjs.map +7 -0
- package/dist/modules/vm/machines.d.mts +82 -0
- package/dist/modules/vm/machines.mjs +62 -0
- package/dist/modules/vm/machines.mjs.map +7 -0
- package/dist/modules/vm/network.d.mts +17 -0
- package/dist/modules/vm/network.mjs +44 -0
- package/dist/modules/vm/network.mjs.map +7 -0
- package/dist/modules/vm/sandbox.d.mts +75 -0
- package/dist/modules/vm/sandbox.mjs +175 -0
- package/dist/modules/vm/sandbox.mjs.map +7 -0
- package/dist/modules/vm/schemas.d.mts +1209 -0
- package/dist/modules/vm/schemas.mjs +289 -0
- package/dist/modules/vm/schemas.mjs.map +7 -0
- package/dist/modules/vm/wire.d.mts +3 -0
- package/dist/modules/vm/wire.mjs +9 -0
- package/dist/modules/vm/wire.mjs.map +7 -0
- package/dist/modules/vm/workload.d.mts +14 -0
- package/dist/modules/vm/workload.mjs +11 -0
- package/dist/modules/vm/workload.mjs.map +7 -0
- package/package.json +38 -4
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { type ApiTransport } from "./api.mjs";
|
|
3
|
+
export declare enum MachineSort {
|
|
4
|
+
Price = "price",
|
|
5
|
+
Order = "order"
|
|
6
|
+
}
|
|
7
|
+
export interface MachineOptionsIface {
|
|
8
|
+
types?: string[];
|
|
9
|
+
cpuFamilies?: string[];
|
|
10
|
+
sort?: MachineSort;
|
|
11
|
+
maxPricePerHour?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const machineBody: (options: MachineOptionsIface | undefined) => {
|
|
14
|
+
types: string[] | undefined;
|
|
15
|
+
cpu_families: string[] | undefined;
|
|
16
|
+
sort: MachineSort | undefined;
|
|
17
|
+
max_price_per_hour: string | undefined;
|
|
18
|
+
} | undefined;
|
|
19
|
+
declare const machineTypeSchema: z.ZodPipe<z.ZodObject<{
|
|
20
|
+
machine_type: z.ZodString;
|
|
21
|
+
region_zone: z.ZodString;
|
|
22
|
+
hardware: z.ZodObject<{
|
|
23
|
+
provider: z.ZodString;
|
|
24
|
+
cpu_model: z.ZodString;
|
|
25
|
+
cpu_family: z.ZodString;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
price: z.ZodObject<{
|
|
28
|
+
currency: z.ZodString;
|
|
29
|
+
hourly: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
30
|
+
baseline: z.ZodString;
|
|
31
|
+
ceiling: z.ZodString;
|
|
32
|
+
}, z.core.$strip>>>;
|
|
33
|
+
rates: z.ZodObject<{
|
|
34
|
+
disk_gib_month: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
38
|
+
machineType: string;
|
|
39
|
+
regionZone: string;
|
|
40
|
+
hardware: {
|
|
41
|
+
provider: string;
|
|
42
|
+
cpuModel: string;
|
|
43
|
+
cpuFamily: string;
|
|
44
|
+
};
|
|
45
|
+
price: {
|
|
46
|
+
currency: string;
|
|
47
|
+
hourly: {
|
|
48
|
+
baseline: string;
|
|
49
|
+
ceiling: string;
|
|
50
|
+
} | null;
|
|
51
|
+
diskGibMonth: string | null;
|
|
52
|
+
};
|
|
53
|
+
}, {
|
|
54
|
+
machine_type: string;
|
|
55
|
+
region_zone: string;
|
|
56
|
+
hardware: {
|
|
57
|
+
provider: string;
|
|
58
|
+
cpu_model: string;
|
|
59
|
+
cpu_family: string;
|
|
60
|
+
};
|
|
61
|
+
price: {
|
|
62
|
+
currency: string;
|
|
63
|
+
rates: {
|
|
64
|
+
disk_gib_month?: string | null | undefined;
|
|
65
|
+
};
|
|
66
|
+
hourly?: {
|
|
67
|
+
baseline: string;
|
|
68
|
+
ceiling: string;
|
|
69
|
+
} | null | undefined;
|
|
70
|
+
};
|
|
71
|
+
}>>;
|
|
72
|
+
export type MachineTypeIface = z.output<typeof machineTypeSchema>;
|
|
73
|
+
export interface MachineSizeIface {
|
|
74
|
+
cpu?: [request: number, limit: number];
|
|
75
|
+
memory?: [request: number, limit: number];
|
|
76
|
+
diskGb?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface MachineTypesIface {
|
|
79
|
+
list: (size?: MachineSizeIface) => Promise<MachineTypeIface[]>;
|
|
80
|
+
}
|
|
81
|
+
export declare const createMachineTypesApi: (api: ApiTransport) => MachineTypesIface;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { HttpMethod } from "./api.mjs";
|
|
3
|
+
var MachineSort = /* @__PURE__ */ ((MachineSort2) => {
|
|
4
|
+
MachineSort2["Price"] = "price";
|
|
5
|
+
MachineSort2["Order"] = "order";
|
|
6
|
+
return MachineSort2;
|
|
7
|
+
})(MachineSort || {});
|
|
8
|
+
const machineBody = (options) => options == null ? void 0 : {
|
|
9
|
+
types: options.types,
|
|
10
|
+
cpu_families: options.cpuFamilies,
|
|
11
|
+
sort: options.sort,
|
|
12
|
+
max_price_per_hour: options.maxPricePerHour
|
|
13
|
+
};
|
|
14
|
+
const machineTypeSchema = z.object({
|
|
15
|
+
machine_type: z.string(),
|
|
16
|
+
region_zone: z.string(),
|
|
17
|
+
hardware: z.object({
|
|
18
|
+
provider: z.string(),
|
|
19
|
+
cpu_model: z.string(),
|
|
20
|
+
cpu_family: z.string()
|
|
21
|
+
}),
|
|
22
|
+
price: z.object({
|
|
23
|
+
currency: z.string(),
|
|
24
|
+
hourly: z.object({ baseline: z.string(), ceiling: z.string() }).nullable().optional(),
|
|
25
|
+
rates: z.object({ disk_gib_month: z.string().nullish() })
|
|
26
|
+
})
|
|
27
|
+
}).transform((value) => ({
|
|
28
|
+
machineType: value.machine_type,
|
|
29
|
+
regionZone: value.region_zone,
|
|
30
|
+
hardware: {
|
|
31
|
+
provider: value.hardware.provider,
|
|
32
|
+
cpuModel: value.hardware.cpu_model,
|
|
33
|
+
cpuFamily: value.hardware.cpu_family
|
|
34
|
+
},
|
|
35
|
+
price: {
|
|
36
|
+
currency: value.price.currency,
|
|
37
|
+
// One running hour of the size: idle at its CPU and memory requests (`baseline`), and
|
|
38
|
+
// with every CPU busy and all memory used up to the limits (`ceiling`).
|
|
39
|
+
hourly: value.price.hourly ?? null,
|
|
40
|
+
diskGibMonth: value.price.rates.disk_gib_month ?? null
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
const createMachineTypesApi = (api) => ({
|
|
44
|
+
list: async (size = {}) => (await api({
|
|
45
|
+
method: HttpMethod.Get,
|
|
46
|
+
path: "/machine-types",
|
|
47
|
+
query: {
|
|
48
|
+
cpu_request: size.cpu?.[0],
|
|
49
|
+
cpu_limit: size.cpu?.[1],
|
|
50
|
+
memory_request: size.memory?.[0],
|
|
51
|
+
memory_limit: size.memory?.[1],
|
|
52
|
+
disk_gb: size.diskGb
|
|
53
|
+
},
|
|
54
|
+
schema: z.object({ machine_types: z.array(machineTypeSchema) })
|
|
55
|
+
})).machine_types
|
|
56
|
+
});
|
|
57
|
+
export {
|
|
58
|
+
MachineSort,
|
|
59
|
+
createMachineTypesApi,
|
|
60
|
+
machineBody
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=machines.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/vm/machines.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport { HttpMethod, type ApiTransport } from \"./api.mjs\";\n\n// Machine types a sandbox can run on. Money is decimal strings in the price's currency.\n\nexport enum MachineSort {\n // Lowest price for the sandbox's size first.\n Price = 'price',\n // The order of `types`.\n Order = 'order',\n}\n\nexport interface MachineOptionsIface {\n // Only these machine types; one pins it to that type.\n types?: string[];\n // Only these CPU microarchitectures.\n cpuFamilies?: string[];\n // Default `price`; `order` needs `types`.\n sort?: MachineSort;\n // The most one running hour may cost (USD), with every CPU busy up to the size's limit.\n maxPricePerHour?: string;\n}\n\nexport const machineBody = (options: MachineOptionsIface | undefined) =>\n options == null\n ? undefined\n : {\n types: options.types,\n cpu_families: options.cpuFamilies,\n sort: options.sort,\n max_price_per_hour: options.maxPricePerHour,\n };\n\nconst machineTypeSchema = z\n .object({\n machine_type: z.string(),\n region_zone: z.string(),\n hardware: z.object({\n provider: z.string(),\n cpu_model: z.string(),\n cpu_family: z.string(),\n }),\n price: z.object({\n currency: z.string(),\n hourly: z.object({ baseline: z.string(), ceiling: z.string() }).nullable().optional(),\n rates: z.object({ disk_gib_month: z.string().nullish() }),\n }),\n })\n .transform((value) => ({\n machineType: value.machine_type,\n regionZone: value.region_zone,\n hardware: {\n provider: value.hardware.provider,\n cpuModel: value.hardware.cpu_model,\n cpuFamily: value.hardware.cpu_family,\n },\n price: {\n currency: value.price.currency,\n // One running hour of the size: idle at its CPU and memory requests (`baseline`), and\n // with every CPU busy and all memory used up to the limits (`ceiling`).\n hourly: value.price.hourly ?? null,\n diskGibMonth: value.price.rates.disk_gib_month ?? null,\n },\n }));\n\nexport type MachineTypeIface = z.output<typeof machineTypeSchema>;\n\nexport interface MachineSizeIface {\n cpu?: [request: number, limit: number];\n // MiB.\n memory?: [request: number, limit: number];\n diskGb?: number;\n}\n\nexport interface MachineTypesIface {\n // Where new sandboxes can run now; with a size, each carries that size's price, cheapest\n // first.\n list: (size?: MachineSizeIface) => Promise<MachineTypeIface[]>;\n}\n\nexport const createMachineTypesApi = (api: ApiTransport): MachineTypesIface => ({\n list: async (size = {}) =>\n (\n await api({\n method: HttpMethod.Get,\n path: '/machine-types',\n query: {\n cpu_request: size.cpu?.[0],\n cpu_limit: size.cpu?.[1],\n memory_request: size.memory?.[0],\n memory_limit: size.memory?.[1],\n disk_gb: size.diskGb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AAkB;AAAA,EACpD;AACF,EAAE;AAiBG,MAAM,wBAAwB,CAAC,SAA0C;AAAA,EAC9E,MAAM,OAAO,OAAO,CAAC,OAEjB,MAAM,IAAI;AAAA,IACR,QAAQ,WAAW;AAAA,IACnB,MAAM;AAAA,IACN,OAAO;AAAA,MACL,aAAa,KAAK,MAAM,CAAC;AAAA,MACzB,WAAW,KAAK,MAAM,CAAC;AAAA,MACvB,gBAAgB,KAAK,SAAS,CAAC;AAAA,MAC/B,cAAc,KAAK,SAAS,CAAC;AAAA,MAC7B,SAAS,KAAK;AAAA,IAChB;AAAA,IACA,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,EAAE,CAAC;AAAA,EAChE,CAAC,GACD;AACN;",
|
|
6
|
+
"names": ["MachineSort"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ApiTransport } from "./api.mjs";
|
|
2
|
+
export interface NetworkPolicyIface {
|
|
3
|
+
allowInternet: boolean;
|
|
4
|
+
allowCidrs?: string[];
|
|
5
|
+
denyCidrs?: string[];
|
|
6
|
+
allowDomains?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface NetworkStatusIface {
|
|
9
|
+
policy: NetworkPolicyIface;
|
|
10
|
+
revision: number | null;
|
|
11
|
+
applied: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface NetworkIface {
|
|
14
|
+
get: () => Promise<NetworkStatusIface>;
|
|
15
|
+
set: (policy: NetworkPolicyIface) => Promise<NetworkStatusIface>;
|
|
16
|
+
}
|
|
17
|
+
export declare const createNetworkHandle: (api: ApiTransport, id: string) => NetworkIface;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { HttpMethod } from "./api.mjs";
|
|
3
|
+
const statusSchema = z.object({
|
|
4
|
+
policy: z.object({
|
|
5
|
+
allow_internet: z.boolean(),
|
|
6
|
+
allow_cidrs: z.array(z.string()),
|
|
7
|
+
deny_cidrs: z.array(z.string()),
|
|
8
|
+
allow_domains: z.array(z.string())
|
|
9
|
+
}),
|
|
10
|
+
revision: z.number().int().positive().nullable(),
|
|
11
|
+
applied: z.boolean()
|
|
12
|
+
}).transform(
|
|
13
|
+
({ policy, ...status }) => ({
|
|
14
|
+
...status,
|
|
15
|
+
policy: {
|
|
16
|
+
allowInternet: policy.allow_internet,
|
|
17
|
+
allowCidrs: policy.allow_cidrs,
|
|
18
|
+
denyCidrs: policy.deny_cidrs,
|
|
19
|
+
allowDomains: policy.allow_domains
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
const createNetworkHandle = (api, id) => ({
|
|
24
|
+
get: () => api({
|
|
25
|
+
method: HttpMethod.Get,
|
|
26
|
+
path: `/sandboxes/${encodeURIComponent(id)}/network`,
|
|
27
|
+
schema: statusSchema
|
|
28
|
+
}),
|
|
29
|
+
set: (policy) => api({
|
|
30
|
+
method: HttpMethod.Put,
|
|
31
|
+
path: `/sandboxes/${encodeURIComponent(id)}/network`,
|
|
32
|
+
schema: statusSchema,
|
|
33
|
+
body: {
|
|
34
|
+
allow_internet: policy.allowInternet,
|
|
35
|
+
allow_cidrs: policy.allowCidrs ?? [],
|
|
36
|
+
deny_cidrs: policy.denyCidrs ?? [],
|
|
37
|
+
allow_domains: policy.allowDomains ?? []
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
export {
|
|
42
|
+
createNetworkHandle
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=network.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/vm/network.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport { HttpMethod, type ApiTransport } from \"./api.mjs\";\n\nexport interface NetworkPolicyIface {\n allowInternet: boolean;\n allowCidrs?: string[];\n denyCidrs?: string[];\n allowDomains?: string[];\n}\n\nexport interface NetworkStatusIface {\n policy: NetworkPolicyIface;\n revision: number | null;\n applied: boolean;\n}\n\nexport interface NetworkIface {\n get: () => Promise<NetworkStatusIface>;\n set: (policy: NetworkPolicyIface) => Promise<NetworkStatusIface>;\n}\n\nconst statusSchema = z\n .object({\n policy: z.object({\n allow_internet: z.boolean(),\n allow_cidrs: z.array(z.string()),\n deny_cidrs: z.array(z.string()),\n allow_domains: z.array(z.string()),\n }),\n revision: z.number().int().positive().nullable(),\n applied: z.boolean(),\n })\n .transform(\n ({ policy, ...status }): NetworkStatusIface => ({\n ...status,\n policy: {\n allowInternet: policy.allow_internet,\n allowCidrs: policy.allow_cidrs,\n denyCidrs: policy.deny_cidrs,\n allowDomains: policy.allow_domains,\n },\n }),\n );\n\nexport const createNetworkHandle = (api: ApiTransport, id: string): NetworkIface => ({\n get: () =>\n api({\n method: HttpMethod.Get,\n path: `/sandboxes/${encodeURIComponent(id)}/network`,\n schema: statusSchema,\n }),\n set: (policy) =>\n api({\n method: HttpMethod.Put,\n path: `/sandboxes/${encodeURIComponent(id)}/network`,\n schema: statusSchema,\n body: {\n allow_internet: policy.allowInternet,\n allow_cidrs: policy.allowCidrs ?? [],\n deny_cidrs: policy.denyCidrs ?? [],\n allow_domains: policy.allowDomains ?? [],\n },\n }),\n});\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,OAAO;AACnB,SAAS,kBAAqC;AAoB9C,MAAM,eAAe,EAClB,OAAO;AAAA,EACN,QAAQ,EAAE,OAAO;AAAA,IACf,gBAAgB,EAAE,QAAQ;AAAA,IAC1B,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,IAC/B,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,IAC9B,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,EACnC,CAAC;AAAA,EACD,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS;AAAA,EAC/C,SAAS,EAAE,QAAQ;AACrB,CAAC,EACA;AAAA,EACC,CAAC,EAAE,QAAQ,GAAG,OAAO,OAA2B;AAAA,IAC9C,GAAG;AAAA,IACH,QAAQ;AAAA,MACN,eAAe,OAAO;AAAA,MACtB,YAAY,OAAO;AAAA,MACnB,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IACvB;AAAA,EACF;AACF;AAEK,MAAM,sBAAsB,CAAC,KAAmB,QAA8B;AAAA,EACnF,KAAK,MACH,IAAI;AAAA,IACF,QAAQ,WAAW;AAAA,IACnB,MAAM,cAAc,mBAAmB,EAAE,CAAC;AAAA,IAC1C,QAAQ;AAAA,EACV,CAAC;AAAA,EACH,KAAK,CAAC,WACJ,IAAI;AAAA,IACF,QAAQ,WAAW;AAAA,IACnB,MAAM,cAAc,mBAAmB,EAAE,CAAC;AAAA,IAC1C,QAAQ;AAAA,IACR,MAAM;AAAA,MACJ,gBAAgB,OAAO;AAAA,MACvB,aAAa,OAAO,cAAc,CAAC;AAAA,MACnC,YAAY,OAAO,aAAa,CAAC;AAAA,MACjC,eAAe,OAAO,gBAAgB,CAAC;AAAA,IACzC;AAAA,EACF,CAAC;AACL;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { type NetworkIface } from "./network.mjs";
|
|
2
|
+
import { type ApiTransport } from "./api.mjs";
|
|
3
|
+
import type { ClockIface } from "./clock.mjs";
|
|
4
|
+
import { type AttachOptionsIface, type ExecOptionsIface, type ExecProcessIface } from "./exec.mjs";
|
|
5
|
+
import { type FileStatIface, type ReadOptionsIface, type RunOptionsIface, type RunResultIface, type WriteOptionsIface } from "./ingress.mjs";
|
|
6
|
+
import { type ConnectGrantIface, type SandboxInfoIface, type SandboxOpResultIface } from "./schemas.mjs";
|
|
7
|
+
export interface SandboxContextIface {
|
|
8
|
+
api: ApiTransport;
|
|
9
|
+
fetch: typeof fetch;
|
|
10
|
+
clock: ClockIface;
|
|
11
|
+
previewDomain: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SandboxIface {
|
|
14
|
+
network: NetworkIface;
|
|
15
|
+
id: string;
|
|
16
|
+
info: () => SandboxInfoIface;
|
|
17
|
+
refresh: () => Promise<SandboxInfoIface>;
|
|
18
|
+
pause: () => Promise<SandboxOpResultIface>;
|
|
19
|
+
resume: () => Promise<SandboxOpResultIface>;
|
|
20
|
+
stop: () => Promise<SandboxOpResultIface>;
|
|
21
|
+
start: () => Promise<SandboxOpResultIface>;
|
|
22
|
+
delete: () => Promise<SandboxOpResultIface>;
|
|
23
|
+
checkpoint: (options?: {
|
|
24
|
+
name?: string;
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
snapshotId: string;
|
|
28
|
+
}>;
|
|
29
|
+
fork: (count: number) => Promise<{
|
|
30
|
+
snapshotId: string;
|
|
31
|
+
children: SandboxIface[];
|
|
32
|
+
}>;
|
|
33
|
+
setTimeout: (wallClockLimitS: number) => Promise<SandboxOpResultIface>;
|
|
34
|
+
updateLabels: (labels: Record<string, string>) => Promise<Record<string, string>>;
|
|
35
|
+
connect: () => Promise<ConnectGrantIface>;
|
|
36
|
+
run: (cmd: string, options?: RunOptionsIface) => Promise<RunResultIface>;
|
|
37
|
+
exec: (options: ExecOptionsIface) => Promise<ExecProcessIface>;
|
|
38
|
+
attach: (options: AttachOptionsIface) => Promise<ExecProcessIface>;
|
|
39
|
+
files: {
|
|
40
|
+
read: (path: string, options?: ReadOptionsIface) => Promise<Uint8Array>;
|
|
41
|
+
write: (path: string, data: Uint8Array | string, options?: WriteOptionsIface) => Promise<{
|
|
42
|
+
bytesWritten: number;
|
|
43
|
+
}>;
|
|
44
|
+
stat: (path: string, options?: {
|
|
45
|
+
signal?: AbortSignal;
|
|
46
|
+
}) => Promise<FileStatIface | null>;
|
|
47
|
+
list: (path: string, options?: {
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}) => Promise<{
|
|
50
|
+
entries: FileStatIface[];
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
mkdir: (path: string, options?: {
|
|
54
|
+
parents?: boolean;
|
|
55
|
+
}) => Promise<void>;
|
|
56
|
+
remove: (path: string, options?: {
|
|
57
|
+
recursive?: boolean;
|
|
58
|
+
}) => Promise<void>;
|
|
59
|
+
};
|
|
60
|
+
previewUrl: (port: number) => Promise<string>;
|
|
61
|
+
listPorts: () => Promise<{
|
|
62
|
+
port: number;
|
|
63
|
+
public: boolean;
|
|
64
|
+
}[]>;
|
|
65
|
+
createPreviewToken: (port: number, options?: {
|
|
66
|
+
ttlS?: number;
|
|
67
|
+
}) => Promise<{
|
|
68
|
+
token: string;
|
|
69
|
+
expiresAt: Date;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
export declare const createSandboxHandle: (ctx: SandboxContextIface, initial: SandboxInfoIface, initialGrant?: {
|
|
73
|
+
grant: ConnectGrantIface | null;
|
|
74
|
+
requestedAt: number;
|
|
75
|
+
}) => SandboxIface;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { createFileReader } from "./files.mjs";
|
|
3
|
+
import { createNetworkHandle } from "./network.mjs";
|
|
4
|
+
import { HttpMethod } from "./api.mjs";
|
|
5
|
+
import { vmError, VmErrorSource } from "./errors.mjs";
|
|
6
|
+
import {
|
|
7
|
+
attachExec,
|
|
8
|
+
startExec
|
|
9
|
+
} from "./exec.mjs";
|
|
10
|
+
import { createGrantSource } from "./grants.mjs";
|
|
11
|
+
import {
|
|
12
|
+
createIngress,
|
|
13
|
+
makeDirectory,
|
|
14
|
+
removeFile,
|
|
15
|
+
runCommand,
|
|
16
|
+
writeFile
|
|
17
|
+
} from "./ingress.mjs";
|
|
18
|
+
import {
|
|
19
|
+
checkpointSchema,
|
|
20
|
+
snapshotSchema,
|
|
21
|
+
connectGrantSchema,
|
|
22
|
+
forkSchema,
|
|
23
|
+
labelsAnswerSchema,
|
|
24
|
+
portSchema,
|
|
25
|
+
previewTokenSchema,
|
|
26
|
+
sandboxInfoSchema,
|
|
27
|
+
sandboxOpSchema
|
|
28
|
+
} from "./schemas.mjs";
|
|
29
|
+
const CHECKPOINT_DURABLE_TIMEOUT_MS = 10 * 6e4;
|
|
30
|
+
const CHECKPOINT_POLL_MS = 500;
|
|
31
|
+
const path = (id, action) => `/sandboxes/${encodeURIComponent(id)}${action == null ? "" : `/${action}`}`;
|
|
32
|
+
const createSandboxHandle = (ctx, initial, initialGrant) => {
|
|
33
|
+
let info = initial;
|
|
34
|
+
const id = initial.id;
|
|
35
|
+
const mintGrant = (signal, refusedByHost) => ctx.api({
|
|
36
|
+
method: HttpMethod.Post,
|
|
37
|
+
path: path(id, "connect"),
|
|
38
|
+
body: { refused_by_host: refusedByHost },
|
|
39
|
+
idempotent: true,
|
|
40
|
+
schema: connectGrantSchema,
|
|
41
|
+
signal
|
|
42
|
+
});
|
|
43
|
+
const grants = createGrantSource({
|
|
44
|
+
mint: (signal, refusedByHost) => mintGrant(signal, refusedByHost),
|
|
45
|
+
clock: ctx.clock
|
|
46
|
+
});
|
|
47
|
+
const ingress = createIngress({
|
|
48
|
+
grants,
|
|
49
|
+
fetch: ctx.fetch,
|
|
50
|
+
clock: ctx.clock
|
|
51
|
+
});
|
|
52
|
+
const fileReader = createFileReader({ api: ctx.api, sandboxId: id });
|
|
53
|
+
const execTransport = { grants, clock: ctx.clock };
|
|
54
|
+
const seed = (grant, requestedAt) => {
|
|
55
|
+
if (grant != null) grants.seed(grant, requestedAt);
|
|
56
|
+
};
|
|
57
|
+
if (initialGrant != null) seed(initialGrant.grant, initialGrant.requestedAt);
|
|
58
|
+
const lifecycle = async (action, method = HttpMethod.Post, body) => {
|
|
59
|
+
const requestedAt = ctx.clock.now();
|
|
60
|
+
const result = await ctx.api({
|
|
61
|
+
method,
|
|
62
|
+
path: path(id, action ?? void 0),
|
|
63
|
+
body,
|
|
64
|
+
schema: sandboxOpSchema,
|
|
65
|
+
// State commands: a repeat finds the state already reached.
|
|
66
|
+
idempotent: true
|
|
67
|
+
});
|
|
68
|
+
grants.clear();
|
|
69
|
+
seed(result.connect, requestedAt);
|
|
70
|
+
info = result.sandbox;
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
network: createNetworkHandle(ctx.api, id),
|
|
75
|
+
id,
|
|
76
|
+
info: () => info,
|
|
77
|
+
refresh: async () => {
|
|
78
|
+
info = await ctx.api({ method: HttpMethod.Get, path: path(id), schema: sandboxInfoSchema });
|
|
79
|
+
return info;
|
|
80
|
+
},
|
|
81
|
+
pause: () => lifecycle("pause"),
|
|
82
|
+
// Explicit lifecycle actions recheck the caller's current authority with the API.
|
|
83
|
+
resume: () => lifecycle("resume"),
|
|
84
|
+
stop: () => lifecycle("stop"),
|
|
85
|
+
start: () => lifecycle("start"),
|
|
86
|
+
delete: () => lifecycle(null, HttpMethod.Delete),
|
|
87
|
+
setTimeout: (wallClockLimitS) => lifecycle("timeout", HttpMethod.Post, { wall_clock_limit_s: wallClockLimitS }),
|
|
88
|
+
updateLabels: async (labels) => {
|
|
89
|
+
const result = await ctx.api({
|
|
90
|
+
method: HttpMethod.Patch,
|
|
91
|
+
path: path(id, "labels"),
|
|
92
|
+
body: { labels },
|
|
93
|
+
schema: labelsAnswerSchema
|
|
94
|
+
});
|
|
95
|
+
info = { ...info, labels: result.labels };
|
|
96
|
+
return result.labels;
|
|
97
|
+
},
|
|
98
|
+
checkpoint: async (options = {}) => {
|
|
99
|
+
const taken = await ctx.api({
|
|
100
|
+
method: HttpMethod.Post,
|
|
101
|
+
path: path(id, "checkpoint"),
|
|
102
|
+
body: { name: options.name },
|
|
103
|
+
schema: checkpointSchema
|
|
104
|
+
});
|
|
105
|
+
const deadline = ctx.clock.now() + (options.timeoutMs ?? CHECKPOINT_DURABLE_TIMEOUT_MS);
|
|
106
|
+
for (; ; ) {
|
|
107
|
+
const snapshot = await ctx.api({
|
|
108
|
+
method: HttpMethod.Get,
|
|
109
|
+
path: `/snapshots/${encodeURIComponent(taken.snapshotId)}`,
|
|
110
|
+
schema: snapshotSchema
|
|
111
|
+
});
|
|
112
|
+
if (snapshot.durableAt != null) return taken;
|
|
113
|
+
if (ctx.clock.now() >= deadline) {
|
|
114
|
+
throw vmError({
|
|
115
|
+
source: VmErrorSource.Api,
|
|
116
|
+
status: null,
|
|
117
|
+
code: "timeout",
|
|
118
|
+
message: `snapshot ${taken.snapshotId} is not durable yet`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
await ctx.clock.sleep(CHECKPOINT_POLL_MS);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
fork: async (count) => {
|
|
125
|
+
const requestedAt = ctx.clock.now();
|
|
126
|
+
const result = await ctx.api({
|
|
127
|
+
method: HttpMethod.Post,
|
|
128
|
+
path: path(id, "fork"),
|
|
129
|
+
body: { count },
|
|
130
|
+
schema: forkSchema
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
snapshotId: result.snapshotId,
|
|
134
|
+
children: result.children.map(
|
|
135
|
+
({ connect, ...child }) => createSandboxHandle(ctx, child, { grant: connect, requestedAt })
|
|
136
|
+
)
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
connect: () => mintGrant(),
|
|
140
|
+
run: (cmd, options) => runCommand(ingress, cmd, options),
|
|
141
|
+
exec: (options) => startExec(execTransport, options),
|
|
142
|
+
attach: (options) => attachExec(execTransport, options),
|
|
143
|
+
files: {
|
|
144
|
+
read: fileReader.read,
|
|
145
|
+
write: (filePath, data, options) => writeFile(ingress, filePath, data, options),
|
|
146
|
+
stat: fileReader.stat,
|
|
147
|
+
list: fileReader.list,
|
|
148
|
+
mkdir: (filePath, options) => makeDirectory(ingress, filePath, options),
|
|
149
|
+
remove: (filePath, options) => removeFile(ingress, filePath, options)
|
|
150
|
+
},
|
|
151
|
+
previewUrl: async (port) => {
|
|
152
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
153
|
+
throw new RangeError("port must be an integer between 1 and 65535");
|
|
154
|
+
}
|
|
155
|
+
const grant = await grants.get();
|
|
156
|
+
return `https://${port}-${grant.sandboxUuid.replaceAll("-", "")}.${ctx.previewDomain}`;
|
|
157
|
+
},
|
|
158
|
+
listPorts: async () => (await ctx.api({
|
|
159
|
+
method: HttpMethod.Get,
|
|
160
|
+
path: path(id, "ports"),
|
|
161
|
+
schema: z.object({ ports: z.array(portSchema) })
|
|
162
|
+
})).ports,
|
|
163
|
+
createPreviewToken: (port, options = {}) => ctx.api({
|
|
164
|
+
method: HttpMethod.Post,
|
|
165
|
+
path: path(id, "preview-tokens"),
|
|
166
|
+
body: { port, ttl_s: options.ttlS },
|
|
167
|
+
idempotent: true,
|
|
168
|
+
schema: previewTokenSchema
|
|
169
|
+
})
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
export {
|
|
173
|
+
createSandboxHandle
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=sandbox.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/vm/sandbox.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod';\nimport { createFileReader } from \"./files.mjs\";\nimport { createNetworkHandle, type NetworkIface } from \"./network.mjs\";\nimport { HttpMethod, type ApiTransport } from \"./api.mjs\";\nimport type { ClockIface } from \"./clock.mjs\";\nimport { vmError, VmErrorSource } from \"./errors.mjs\";\nimport {\n attachExec,\n startExec,\n type AttachOptionsIface,\n type ExecOptionsIface,\n type ExecProcessIface,\n} from \"./exec.mjs\";\nimport { createGrantSource, type GrantSourceIface } from \"./grants.mjs\";\nimport {\n createIngress,\n makeDirectory,\n removeFile,\n runCommand,\n writeFile,\n type FileStatIface,\n type IngressIface,\n type ReadOptionsIface,\n type RunOptionsIface,\n type RunResultIface,\n type WriteOptionsIface,\n} from \"./ingress.mjs\";\nimport {\n checkpointSchema,\n snapshotSchema,\n connectGrantSchema,\n forkSchema,\n labelsAnswerSchema,\n portSchema,\n previewTokenSchema,\n sandboxInfoSchema,\n sandboxOpSchema,\n type ConnectGrantIface,\n type SandboxInfoIface,\n type SandboxOpResultIface,\n} from \"./schemas.mjs\";\n\n// Lifecycle and file reads use the API. Commands and file writes use the data plane with a\n// connect grant the handle keeps fresh.\n\n// How long `checkpoint` waits for the snapshot's layers to be durable, and how often it looks.\nconst CHECKPOINT_DURABLE_TIMEOUT_MS = 10 * 60_000;\nconst CHECKPOINT_POLL_MS = 500;\n\nexport interface SandboxContextIface {\n api: ApiTransport;\n fetch: typeof fetch;\n clock: ClockIface;\n previewDomain: string;\n}\n\nexport interface SandboxIface {\n network: NetworkIface;\n // The wire id (`sbx_\u2026`).\n id: string;\n // As of the last answer about this sandbox.\n info: () => SandboxInfoIface;\n refresh: () => Promise<SandboxInfoIface>;\n pause: () => Promise<SandboxOpResultIface>;\n resume: () => Promise<SandboxOpResultIface>;\n stop: () => Promise<SandboxOpResultIface>;\n start: () => Promise<SandboxOpResultIface>;\n delete: () => Promise<SandboxOpResultIface>;\n // Returns once the snapshot is durable.\n checkpoint: (options?: { name?: string; timeoutMs?: number }) => Promise<{ snapshotId: string }>;\n // `count` running copies; this sandbox keeps running.\n fork: (count: number) => Promise<{ snapshotId: string; children: SandboxIface[] }>;\n setTimeout: (wallClockLimitS: number) => Promise<SandboxOpResultIface>;\n // Merges these labels into the sandbox's (at most 64 in all) and answers the result.\n updateLabels: (labels: Record<string, string>) => Promise<Record<string, string>>;\n // A new grant for the data plane, for callers that connect on their own.\n connect: () => Promise<ConnectGrantIface>;\n run: (cmd: string, options?: RunOptionsIface) => Promise<RunResultIface>;\n exec: (options: ExecOptionsIface) => Promise<ExecProcessIface>;\n attach: (options: AttachOptionsIface) => Promise<ExecProcessIface>;\n files: {\n read: (path: string, options?: ReadOptionsIface) => Promise<Uint8Array>;\n write: (\n path: string,\n data: Uint8Array | string,\n options?: WriteOptionsIface,\n ) => Promise<{ bytesWritten: number }>;\n stat: (path: string, options?: { signal?: AbortSignal }) => Promise<FileStatIface | null>;\n list: (\n path: string,\n options?: { signal?: AbortSignal },\n ) => Promise<{ entries: FileStatIface[]; truncated: boolean }>;\n mkdir: (path: string, options?: { parents?: boolean }) => Promise<void>;\n remove: (path: string, options?: { recursive?: boolean }) => Promise<void>;\n };\n // `https://<port>-<uuid hex>.<preview domain>`. Private unless the port is public; pass a\n // preview token (`createPreviewToken`) with the request.\n previewUrl: (port: number) => Promise<string>;\n // Ports with an explicit visibility (published at create or with `setPortPublic`).\n listPorts: () => Promise<{ port: number; public: boolean }[]>;\n createPreviewToken: (\n port: number,\n options?: { ttlS?: number },\n ) => Promise<{ token: string; expiresAt: Date }>;\n}\n\nconst path = (id: string, action?: string) =>\n `/sandboxes/${encodeURIComponent(id)}${action == null ? '' : `/${action}`}`;\n\nexport const createSandboxHandle = (\n ctx: SandboxContextIface,\n initial: SandboxInfoIface,\n // A grant that came with the answer that made or found this sandbox, and when it was asked.\n initialGrant?: { grant: ConnectGrantIface | null; requestedAt: number },\n): SandboxIface => {\n let info = initial;\n const id = initial.id;\n const mintGrant = (signal?: AbortSignal, refusedByHost?: string) =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'connect'),\n body: { refused_by_host: refusedByHost },\n idempotent: true,\n schema: connectGrantSchema,\n signal,\n });\n const grants: GrantSourceIface = createGrantSource({\n mint: (signal, refusedByHost) => mintGrant(signal, refusedByHost),\n clock: ctx.clock,\n });\n const ingress: IngressIface = createIngress({\n grants,\n fetch: ctx.fetch,\n clock: ctx.clock,\n });\n const fileReader = createFileReader({ api: ctx.api, sandboxId: id });\n const execTransport = { grants, clock: ctx.clock };\n // The API's answers carry grants for the default scopes, which this client asks for too.\n const seed = (grant: ConnectGrantIface | null, requestedAt: number) => {\n if (grant != null) grants.seed(grant, requestedAt);\n };\n if (initialGrant != null) seed(initialGrant.grant, initialGrant.requestedAt);\n\n // A transition the API ran bumped the generation, so the grant in hand would be `moved`.\n const lifecycle = async (\n action: string | null,\n method = HttpMethod.Post,\n body?: { wall_clock_limit_s: number },\n ) => {\n const requestedAt = ctx.clock.now();\n const result = await ctx.api({\n method,\n path: path(id, action ?? undefined),\n body,\n schema: sandboxOpSchema,\n // State commands: a repeat finds the state already reached.\n idempotent: true,\n });\n grants.clear();\n seed(result.connect, requestedAt);\n info = result.sandbox;\n return result;\n };\n\n return {\n network: createNetworkHandle(ctx.api, id),\n id,\n info: () => info,\n refresh: async () => {\n info = await ctx.api({ method: HttpMethod.Get, path: path(id), schema: sandboxInfoSchema });\n return info;\n },\n pause: () => lifecycle('pause'),\n // Explicit lifecycle actions recheck the caller's current authority with the API.\n resume: () => lifecycle('resume'),\n stop: () => lifecycle('stop'),\n start: () => lifecycle('start'),\n delete: () => lifecycle(null, HttpMethod.Delete),\n setTimeout: (wallClockLimitS) =>\n lifecycle('timeout', HttpMethod.Post, { wall_clock_limit_s: wallClockLimitS }),\n updateLabels: async (labels) => {\n const result = await ctx.api({\n method: HttpMethod.Patch,\n path: path(id, 'labels'),\n body: { labels },\n schema: labelsAnswerSchema,\n });\n info = { ...info, labels: result.labels };\n return result.labels;\n },\n checkpoint: async (options = {}) => {\n const taken = await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'checkpoint'),\n body: { name: options.name },\n schema: checkpointSchema,\n });\n // The API answers once the snapshot is taken; its layers upload after. Restoring it (a\n // create from it) needs it durable, which is what this promises.\n const deadline = ctx.clock.now() + (options.timeoutMs ?? CHECKPOINT_DURABLE_TIMEOUT_MS);\n for (;;) {\n const snapshot = await ctx.api({\n method: HttpMethod.Get,\n path: `/snapshots/${encodeURIComponent(taken.snapshotId)}`,\n schema: snapshotSchema,\n });\n if (snapshot.durableAt != null) return taken;\n if (ctx.clock.now() >= deadline) {\n throw vmError({\n source: VmErrorSource.Api,\n status: null,\n code: 'timeout',\n message: `snapshot ${taken.snapshotId} is not durable yet`,\n });\n }\n await ctx.clock.sleep(CHECKPOINT_POLL_MS);\n }\n },\n fork: async (count) => {\n const requestedAt = ctx.clock.now();\n const result = await ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'fork'),\n body: { count },\n schema: forkSchema,\n });\n return {\n snapshotId: result.snapshotId,\n children: result.children.map(({ connect, ...child }) =>\n createSandboxHandle(ctx, child, { grant: connect, requestedAt }),\n ),\n };\n },\n connect: () => mintGrant(),\n run: (cmd, options) => runCommand(ingress, cmd, options),\n exec: (options) => startExec(execTransport, options),\n attach: (options) => attachExec(execTransport, options),\n files: {\n read: fileReader.read,\n write: (filePath, data, options) => writeFile(ingress, filePath, data, options),\n stat: fileReader.stat,\n list: fileReader.list,\n mkdir: (filePath, options) => makeDirectory(ingress, filePath, options),\n remove: (filePath, options) => removeFile(ingress, filePath, options),\n },\n previewUrl: async (port) => {\n if (!Number.isInteger(port) || port < 1 || port > 65_535) {\n throw new RangeError('port must be an integer between 1 and 65535');\n }\n const grant = await grants.get();\n return `https://${port}-${grant.sandboxUuid.replaceAll('-', '')}.${ctx.previewDomain}`;\n },\n listPorts: async () =>\n (\n await ctx.api({\n method: HttpMethod.Get,\n path: path(id, 'ports'),\n schema: z.object({ ports: z.array(portSchema) }),\n })\n ).ports,\n createPreviewToken: (port, options = {}) =>\n ctx.api({\n method: HttpMethod.Post,\n path: path(id, 'preview-tokens'),\n body: { port, ttl_s: options.ttlS },\n idempotent: true,\n schema: previewTokenSchema,\n }),\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,OAAO;AACnB,SAAS,wBAAwB;AACjC,SAAS,2BAA8C;AACvD,SAAS,kBAAqC;AAE9C,SAAS,SAAS,qBAAqB;AACvC;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AACP,SAAS,yBAAgD;AACzD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK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