@finalai/sandbox-router-agent-provider 0.0.0-stage → 0.1.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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/network.ts"],
4
+ "sourcesContent": ["import { NetworkPolicy, type NetworkPolicyIface } from '@finalai/agent-provider/sandbox';\nimport { EgressMode, type NetworkOptionsIface } from '@finalai/sandbox-router';\n\n// An IPv4 or IPv6 address, with or without a prefix length.\nconst ADDRESS_RANGE = /^(?:\\d{1,3}(?:\\.\\d{1,3}){3}|[0-9a-f]*:[0-9a-f:.]*)(?:\\/\\d{1,3})?$/i;\n\nexport const isAddressRange = (entry: string): boolean => ADDRESS_RANGE.test(entry);\n\n// A sandbox network policy as the router's egress: an allowlist's address ranges become CIDRs\n// and every other entry (a host or a `*.suffix` pattern) a domain.\nexport const routerNetworkOf = (policy: NetworkPolicyIface): NetworkOptionsIface => {\n if (policy.mode === NetworkPolicy.AllowAll) return { egress: EgressMode.AllowAll };\n if (policy.mode === NetworkPolicy.DenyAll) return { egress: EgressMode.DenyAll };\n const allow = [...new Set(policy.allow ?? [])];\n if (allow.length === 0) return { egress: EgressMode.DenyAll };\n return {\n egress: {\n allowDomains: allow.filter((entry) => !isAddressRange(entry)),\n allowCidrs: allow\n .filter(isAddressRange)\n .map((entry) =>\n entry.includes('/') ? entry : `${entry}${entry.includes(':') ? '/128' : '/32'}`,\n ),\n },\n };\n};\n"],
5
+ "mappings": "AAAA,SAAS,qBAA8C;AACvD,SAAS,kBAA4C;AAGrD,MAAM,gBAAgB;AAEf,MAAM,iBAAiB,CAAC,UAA2B,cAAc,KAAK,KAAK;AAI3E,MAAM,kBAAkB,CAAC,WAAoD;AAClF,MAAI,OAAO,SAAS,cAAc,SAAU,QAAO,EAAE,QAAQ,WAAW,SAAS;AACjF,MAAI,OAAO,SAAS,cAAc,QAAS,QAAO,EAAE,QAAQ,WAAW,QAAQ;AAC/E,QAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,OAAO,SAAS,CAAC,CAAC,CAAC;AAC7C,MAAI,MAAM,WAAW,EAAG,QAAO,EAAE,QAAQ,WAAW,QAAQ;AAC5D,SAAO;AAAA,IACL,QAAQ;AAAA,MACN,cAAc,MAAM,OAAO,CAAC,UAAU,CAAC,eAAe,KAAK,CAAC;AAAA,MAC5D,YAAY,MACT,OAAO,cAAc,EACrB;AAAA,QAAI,CAAC,UACJ,MAAM,SAAS,GAAG,IAAI,QAAQ,GAAG,KAAK,GAAG,MAAM,SAAS,GAAG,IAAI,SAAS,KAAK;AAAA,MAC/E;AAAA,IACJ;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,75 @@
1
+ import { type JsonObject, type JsonValue } from '@finalai/agent-provider';
2
+ import { NetworkPolicy, SandboxCapability, type NetworkPolicyIface, type NetworkSandboxSessionIface, type SandboxProviderContextIface, type SandboxProviderIface, type SandboxSetupIface } from '@finalai/agent-provider/sandbox';
3
+ import { type ImageBuilderIface, type ImageSpecIface, type LifecycleOptionsIface, type RoutingOptionsIface, type SandboxRouterIface } from '@finalai/sandbox-router';
4
+ import * as z from 'zod';
5
+ import { type ComputerUseCommandIface } from "./computer-use.mjs";
6
+ import { type RoutedMachineIface } from "./environment.mjs";
7
+ export declare const WORKSPACE_ROOT = "/workspaces";
8
+ export declare const SANDBOX_LABEL = "agent-sandbox";
9
+ export interface RoutedSandboxLogIface {
10
+ (message: string, fields?: Record<string, string | number | boolean | null>): void;
11
+ }
12
+ export interface RoutedSandboxProviderConfigIface {
13
+ name?: string;
14
+ router: (ctx: SandboxProviderContextIface) => SandboxRouterIface;
15
+ routing?: RoutingOptionsIface;
16
+ providerOptions?: Record<string, unknown>;
17
+ defaultImage?: string;
18
+ images?: Record<string, ImageBuilderIface | ImageSpecIface | string>;
19
+ machine?: RoutedMachineIface;
20
+ cpuRequest?: number;
21
+ maxLifetime?: LifecycleOptionsIface['max'];
22
+ portTokenTtlS?: number;
23
+ region?: string;
24
+ labels?: Record<string, string>;
25
+ computerUse?: ComputerUseCommandIface;
26
+ runningWaitMs?: number;
27
+ runningPollMs?: number;
28
+ log?: RoutedSandboxLogIface;
29
+ now?: () => number;
30
+ sleep?: (ms: number) => Promise<void>;
31
+ }
32
+ export declare enum RoutedSandboxErrorCode {
33
+ ArtifactUnavailable = "artifact_unavailable",
34
+ SandboxGone = "sandbox_gone",
35
+ SandboxNotRunning = "sandbox_not_running",
36
+ InvalidEnvironment = "invalid_environment",
37
+ BuildFailed = "build_failed"
38
+ }
39
+ export interface RoutedSandboxErrorIface extends Error {
40
+ code: RoutedSandboxErrorCode;
41
+ }
42
+ declare const artifactSchema: z.ZodObject<{
43
+ seedFiles: z.ZodDefault<z.ZodPreprocess<z.ZodPipe<z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>, z.ZodTransform<{
44
+ [k: string]: string;
45
+ }, [string, string][]>>, unknown>>;
46
+ seedSourceRevision: z.ZodOptional<z.ZodString>;
47
+ seedHash: z.ZodOptional<z.ZodString>;
48
+ version: z.ZodLiteral<1>;
49
+ key: z.ZodString;
50
+ image: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>]>>;
51
+ base: z.ZodDiscriminatedUnion<[z.ZodObject<{
52
+ kind: z.ZodLiteral<"image">;
53
+ }, z.core.$strip>, z.ZodObject<{
54
+ kind: z.ZodLiteral<"snapshot">;
55
+ snapshotId: z.ZodString;
56
+ }, z.core.$strip>], "kind">;
57
+ }, z.core.$strip>;
58
+ declare const stateSchema: z.ZodObject<{
59
+ version: z.ZodLiteral<1>;
60
+ sandboxId: z.ZodNullable<z.ZodString>;
61
+ network: z.ZodObject<{
62
+ mode: z.ZodEnum<typeof NetworkPolicy>;
63
+ allow: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
+ }, z.core.$strip>;
65
+ ports: z.ZodDefault<z.ZodArray<z.ZodNumber>>;
66
+ }, z.core.$strip>;
67
+ export type RoutedSandboxArtifact = z.infer<typeof artifactSchema>;
68
+ export type RoutedSandboxState = z.infer<typeof stateSchema>;
69
+ export interface RoutedSandboxSessionIface extends NetworkSandboxSessionIface {
70
+ readonly capabilities: readonly SandboxCapability[];
71
+ }
72
+ export type RoutedSandboxProviderIface = SandboxProviderIface<JsonValue, RoutedSandboxArtifact, RoutedSandboxState, RoutedSandboxSessionIface>;
73
+ export declare const routedNetworkPolicyOf: (setup: SandboxSetupIface | null) => NetworkPolicyIface;
74
+ export declare const createRoutedSandboxProvider: (config: RoutedSandboxProviderConfigIface) => RoutedSandboxProviderIface;
75
+ export {};