@sandbox-kit/daytona 0.1.0 → 0.1.2

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.
@@ -1,95 +1,101 @@
1
1
  // Provider field mappings between shared CreateOptions/Config and the native SDK.
2
2
  // Inventoried in specs/providers/daytona.yaml groups; kept in sync by hand (not emitted).
3
- import { ErrorKind, PolicyMode, ValueOrigin, sandboxError, CreateFieldLifetimeIdlePause, CreateFieldLifetimeIdleStop, CreateFieldLifetimeStoppedArchive, CreateFieldLifetimeStoppedDelete, CreateFieldResourcesCpuCores, CreateFieldResourcesDiskMib, CreateFieldResourcesMemoryMib, InfoFieldId, InfoFieldLabels, InfoFieldName, InfoFieldProviderState, InfoFieldRegion, } from "@sandbox-kit/sandbox";
3
+ import { ErrorKind, PolicyMode, ValueOrigin, CreateFieldLifetimeIdlePause, CreateFieldLifetimeIdleStop, CreateFieldLifetimeStoppedArchive, CreateFieldLifetimeStoppedDelete, CreateFieldResourcesCpuCores, CreateFieldResourcesDiskMib, CreateFieldResourcesMemoryMib, InfoFieldId, InfoFieldLabels, InfoFieldName, InfoFieldProviderState, InfoFieldRegion, } from "@sandbox-kit/sandbox";
4
+ import { providerError } from "#errors.js";
4
5
  export function mapLifetimePolicies(source, operation = "create") {
5
6
  const target = {};
6
7
  if (source === undefined)
7
8
  return target;
8
- if (source.idleStop !== undefined) {
9
- const policy = source.idleStop;
10
- const mode = policy.mode ?? PolicyMode.Default;
11
- if (mode === PolicyMode.Disabled) {
12
- target.autoStopInterval = 0;
13
- }
14
- else if (mode === PolicyMode.After) {
15
- if (policy.after === undefined)
16
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeIdleStop, "duration is required", operation);
17
- const afterMs = policy.after;
18
- if (afterMs === 0)
19
- mappingError(ErrorKind.Unsupported, CreateFieldLifetimeIdleStop, "immediate action is not representable", operation);
20
- if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
21
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeIdleStop, "delay cannot be represented in whole minutes", operation);
22
- const minutes = afterMs / 60_000;
23
- target.autoStopInterval = minutes;
24
- }
25
- else if (mode !== PolicyMode.Default) {
26
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeIdleStop, "unknown policy mode", operation);
27
- }
28
- }
29
- if (source.idlePause !== undefined) {
30
- const policy = source.idlePause;
31
- const mode = policy.mode ?? PolicyMode.Default;
32
- if (mode === PolicyMode.Disabled) {
33
- target.autoPauseInterval = 0;
34
- }
35
- else if (mode === PolicyMode.After) {
36
- if (policy.after === undefined)
37
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeIdlePause, "duration is required", operation);
38
- const afterMs = policy.after;
39
- if (afterMs === 0)
40
- mappingError(ErrorKind.Unsupported, CreateFieldLifetimeIdlePause, "immediate action is not representable", operation);
41
- if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
42
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeIdlePause, "delay cannot be represented in whole minutes", operation);
43
- const minutes = afterMs / 60_000;
44
- target.autoPauseInterval = minutes;
45
- }
46
- else if (mode !== PolicyMode.Default) {
47
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeIdlePause, "unknown policy mode", operation);
48
- }
49
- }
50
- if (source.stoppedArchive !== undefined) {
51
- const policy = source.stoppedArchive;
52
- const mode = policy.mode ?? PolicyMode.Default;
53
- if (mode === PolicyMode.Disabled) {
54
- mappingError(ErrorKind.Unsupported, CreateFieldLifetimeStoppedArchive, "explicit disabling is not representable", operation);
55
- }
56
- else if (mode === PolicyMode.After) {
57
- if (policy.after === undefined)
58
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeStoppedArchive, "duration is required", operation);
59
- const afterMs = policy.after;
60
- if (afterMs === 0)
61
- mappingError(ErrorKind.Unsupported, CreateFieldLifetimeStoppedArchive, "immediate action is not representable", operation);
62
- if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
63
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeStoppedArchive, "delay cannot be represented in whole minutes", operation);
64
- const minutes = afterMs / 60_000;
65
- if (minutes > 43200)
66
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeStoppedArchive, "delay exceeds documented maximum", operation);
67
- target.autoArchiveInterval = minutes;
68
- }
69
- else if (mode !== PolicyMode.Default) {
70
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeStoppedArchive, "unknown policy mode", operation);
71
- }
9
+ const idleStop = mapMinutePolicy(source.idleStop, {
10
+ field: CreateFieldLifetimeIdleStop,
11
+ operation,
12
+ allowDisable: true,
13
+ forbidImmediate: true,
14
+ });
15
+ if (idleStop !== undefined)
16
+ target.autoStopInterval = idleStop;
17
+ const idlePause = mapMinutePolicy(source.idlePause, {
18
+ field: CreateFieldLifetimeIdlePause,
19
+ operation,
20
+ allowDisable: true,
21
+ forbidImmediate: true,
22
+ });
23
+ if (idlePause !== undefined)
24
+ target.autoPauseInterval = idlePause;
25
+ const stoppedArchive = mapMinutePolicy(source.stoppedArchive, {
26
+ field: CreateFieldLifetimeStoppedArchive,
27
+ operation,
28
+ allowDisable: false,
29
+ forbidImmediate: true,
30
+ maxMinutes: 43200,
31
+ });
32
+ if (stoppedArchive !== undefined)
33
+ target.autoArchiveInterval = stoppedArchive;
34
+ const stoppedDelete = mapMinutePolicy(source.stoppedDelete, {
35
+ field: CreateFieldLifetimeStoppedDelete,
36
+ operation,
37
+ allowDisable: false,
38
+ forbidImmediate: false,
39
+ });
40
+ if (stoppedDelete !== undefined)
41
+ target.autoDeleteInterval = stoppedDelete;
42
+ return target;
43
+ }
44
+ function mapMinutePolicy(policy, spec) {
45
+ if (policy === undefined)
46
+ return undefined;
47
+ const mode = policy.mode ?? PolicyMode.Default;
48
+ if (mode === PolicyMode.Disabled) {
49
+ if (!spec.allowDisable)
50
+ mappingError({
51
+ kind: ErrorKind.Unsupported,
52
+ field: spec.field,
53
+ message: "explicit disabling is not representable",
54
+ operation: spec.operation,
55
+ });
56
+ return 0;
72
57
  }
73
- if (source.stoppedDelete !== undefined) {
74
- const policy = source.stoppedDelete;
75
- const mode = policy.mode ?? PolicyMode.Default;
76
- if (mode === PolicyMode.Disabled) {
77
- mappingError(ErrorKind.Unsupported, CreateFieldLifetimeStoppedDelete, "explicit disabling is not representable", operation);
78
- }
79
- else if (mode === PolicyMode.After) {
80
- if (policy.after === undefined)
81
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeStoppedDelete, "duration is required", operation);
82
- const afterMs = policy.after;
83
- if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
84
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeStoppedDelete, "delay cannot be represented in whole minutes", operation);
85
- const minutes = afterMs / 60_000;
86
- target.autoDeleteInterval = minutes;
87
- }
88
- else if (mode !== PolicyMode.Default) {
89
- mappingError(ErrorKind.InvalidArgument, CreateFieldLifetimeStoppedDelete, "unknown policy mode", operation);
90
- }
58
+ if (mode === PolicyMode.After) {
59
+ if (policy.after === undefined)
60
+ mappingError({
61
+ kind: ErrorKind.InvalidArgument,
62
+ field: spec.field,
63
+ message: "duration is required",
64
+ operation: spec.operation,
65
+ });
66
+ const afterMs = policy.after;
67
+ if (spec.forbidImmediate && afterMs === 0)
68
+ mappingError({
69
+ kind: ErrorKind.Unsupported,
70
+ field: spec.field,
71
+ message: "immediate action is not representable",
72
+ operation: spec.operation,
73
+ });
74
+ if (!Number.isFinite(afterMs) || afterMs < 0 || afterMs % 60_000 !== 0)
75
+ mappingError({
76
+ kind: ErrorKind.InvalidArgument,
77
+ field: spec.field,
78
+ message: "delay cannot be represented in whole minutes",
79
+ operation: spec.operation,
80
+ });
81
+ const minutes = afterMs / 60_000;
82
+ if (spec.maxMinutes !== undefined && minutes > spec.maxMinutes)
83
+ mappingError({
84
+ kind: ErrorKind.InvalidArgument,
85
+ field: spec.field,
86
+ message: "delay exceeds documented maximum",
87
+ operation: spec.operation,
88
+ });
89
+ return minutes;
91
90
  }
92
- return target;
91
+ if (mode !== PolicyMode.Default)
92
+ mappingError({
93
+ kind: ErrorKind.InvalidArgument,
94
+ field: spec.field,
95
+ message: "unknown policy mode",
96
+ operation: spec.operation,
97
+ });
98
+ return undefined;
93
99
  }
94
100
  export function mapCommonCreateFields(source, operation = "create") {
95
101
  const target = {};
@@ -123,7 +129,12 @@ export function mapResources(source, operation = "create") {
123
129
  if (source.cpuCores !== undefined) {
124
130
  const value = source.cpuCores;
125
131
  if (!Number.isInteger(value) || value > 2147483647)
126
- mappingError(ErrorKind.InvalidArgument, CreateFieldResourcesCpuCores, "cpu_cores cannot be represented", operation);
132
+ mappingError({
133
+ kind: ErrorKind.InvalidArgument,
134
+ field: CreateFieldResourcesCpuCores,
135
+ message: "cpu_cores cannot be represented",
136
+ operation,
137
+ });
127
138
  target.cpu = Number(value);
128
139
  }
129
140
  }
@@ -131,7 +142,12 @@ export function mapResources(source, operation = "create") {
131
142
  if (source.memoryMib !== undefined) {
132
143
  const value = source.memoryMib;
133
144
  if (value % 1024n !== 0n || value / 1024n > 2147483647n)
134
- mappingError(ErrorKind.InvalidArgument, CreateFieldResourcesMemoryMib, "memory_mib cannot be represented", operation);
145
+ mappingError({
146
+ kind: ErrorKind.InvalidArgument,
147
+ field: CreateFieldResourcesMemoryMib,
148
+ message: "memory_mib cannot be represented",
149
+ operation,
150
+ });
135
151
  target.memory = Number(value / 1024n);
136
152
  }
137
153
  }
@@ -139,7 +155,12 @@ export function mapResources(source, operation = "create") {
139
155
  if (source.diskMib !== undefined) {
140
156
  const value = source.diskMib;
141
157
  if (value % 1024n !== 0n || value / 1024n > 2147483647n)
142
- mappingError(ErrorKind.InvalidArgument, CreateFieldResourcesDiskMib, "disk_mib cannot be represented", operation);
158
+ mappingError({
159
+ kind: ErrorKind.InvalidArgument,
160
+ field: CreateFieldResourcesDiskMib,
161
+ message: "disk_mib cannot be represented",
162
+ operation,
163
+ });
143
164
  target.disk = Number(value / 1024n);
144
165
  }
145
166
  }
@@ -207,7 +228,12 @@ export function mapAllocatedResources(source, operation = "create") {
207
228
  if (source.memory !== undefined) {
208
229
  const value = source.memory;
209
230
  if (!Number.isSafeInteger(value) || value < 0)
210
- mappingError(ErrorKind.InvalidResponse, "memory", "memory cannot be represented", operation);
231
+ mappingError({
232
+ kind: ErrorKind.InvalidResponse,
233
+ field: "memory",
234
+ message: "memory cannot be represented",
235
+ operation,
236
+ });
211
237
  target.memoryMib = BigInt(value) * 1024n;
212
238
  }
213
239
  }
@@ -215,7 +241,12 @@ export function mapAllocatedResources(source, operation = "create") {
215
241
  if (source.disk !== undefined) {
216
242
  const value = source.disk;
217
243
  if (!Number.isSafeInteger(value) || value < 0)
218
- mappingError(ErrorKind.InvalidResponse, "disk", "disk cannot be represented", operation);
244
+ mappingError({
245
+ kind: ErrorKind.InvalidResponse,
246
+ field: "disk",
247
+ message: "disk cannot be represented",
248
+ operation,
249
+ });
219
250
  target.diskMib = BigInt(value) * 1024n;
220
251
  }
221
252
  }
@@ -271,12 +302,6 @@ export function mapScope(source, operation = "initialize") {
271
302
  }
272
303
  return target;
273
304
  }
274
- function mappingError(kind, field, message, operation) {
275
- throw sandboxError({
276
- kind,
277
- provider: "daytona",
278
- operation,
279
- field,
280
- message: "sandbox-kit daytona: " + message,
281
- });
305
+ function mappingError(input) {
306
+ providerError(input);
282
307
  }
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@sandbox-kit/daytona",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "daytona provider for sandbox kit",
5
+ "keywords": [
6
+ "sandbox-kit",
7
+ "sandbox",
8
+ "daytona",
9
+ "sdk",
10
+ "provider"
11
+ ],
5
12
  "license": "MIT",
6
13
  "type": "module",
7
14
  "packageManager": "npm@11.19.0",
@@ -45,17 +52,22 @@
45
52
  "#config/*.js": {
46
53
  "@sandbox-kit/source": "./src/config/*.ts",
47
54
  "default": "./dist/config/*.js"
55
+ },
56
+ "#errors.js": {
57
+ "@sandbox-kit/source": "./src/errors.ts",
58
+ "default": "./dist/errors.js"
48
59
  }
49
60
  },
50
61
  "scripts": {
62
+ "clean": "rm -rf dist",
51
63
  "build": "tsc -p tsconfig.build.json",
52
- "prepublishOnly": "npm run build",
64
+ "prepublishOnly": "npm run clean && npm run build",
53
65
  "test": "tsc -p tsconfig.test.json && vitest run"
54
66
  },
55
67
  "dependencies": {
56
68
  "@bufbuild/protobuf": "2.16.0",
57
69
  "@daytona/sdk": "0.225.0",
58
- "@sandbox-kit/sandbox": "0.1.0"
70
+ "@sandbox-kit/sandbox": "0.1.2"
59
71
  },
60
72
  "devDependencies": {
61
73
  "@types/node": "24.10.1",
@@ -1,8 +0,0 @@
1
- import { type Config, type CreateOptions, type SandboxInfo } from "@sandbox-kit/sandbox";
2
- import { type CreateSandboxFromImageParams, type CreateSandboxFromSnapshotParams, type DaytonaConfig, type Sandbox as DaytonaSandbox } from "@daytona/sdk";
3
- import { type Environment } from "./provider_config.js";
4
- export type DaytonaCreateParams = CreateSandboxFromImageParams | CreateSandboxFromSnapshotParams;
5
- export declare function mapClientConfig(config: Config, environment?: Environment): DaytonaConfig;
6
- export declare function mapCreateRequest(request: CreateOptions): DaytonaCreateParams;
7
- export declare function mapSandboxInfo(value: DaytonaSandbox, operation?: string): SandboxInfo;
8
- //# sourceMappingURL=mappings.d.ts.map
package/dist/mappings.js DELETED
@@ -1,332 +0,0 @@
1
- // Provider-specific orchestration around generated portable field mappings.
2
- import { EgressMode, ErrorKind, IsolationKind, SandboxState, SecretInjection, SnapshotKind, ValueOrigin, WaitCondition, sandboxError } from "@sandbox-kit/sandbox";
3
- import { metadataObjectFromMap, } from "@sandbox-kit/sandbox";
4
- import {} from "@daytona/sdk";
5
- import { mapAllocatedResources as generatedMapAllocatedResources, mapCommonCreateFields as generatedMapCommonCreateFields, mapLifetimePolicies as generatedMapLifetimePolicies, mapResources as generatedMapResources, mapSandboxInfo as generatedMapSandboxInfo, } from "./provider_mappings.js";
6
- import { validateProviderCreate } from "./provider_checks.js";
7
- import { mapGeneratedClientConfig } from "./provider_config.js";
8
- export function mapClientConfig(config, environment) {
9
- const result = mapGeneratedClientConfig(config, environment);
10
- if (config.auth?.bearerToken !== undefined &&
11
- config.scope?.organizationId === undefined)
12
- configInvalid("scope.organizationId", "organization ID is required with bearer authentication");
13
- return result;
14
- }
15
- export function mapCreateRequest(request) {
16
- validateProviderCreate(request);
17
- const base = generatedMapCommonCreateFields(request);
18
- mapRuntime(request, base);
19
- mapIsolation(request, base);
20
- mapSecurity(request, base);
21
- mapNetwork(request, base);
22
- mapLifetime(request, base);
23
- mapProvisioning(request, base);
24
- mapObservability(request, base);
25
- if (request.placement !== undefined)
26
- unsupported("placement", "per-request Daytona placement is unsupported; use Config.region");
27
- if (request.readiness !== undefined)
28
- unsupported("readiness", "Daytona readiness probes are not mapped");
29
- if (request.providerOptions !== undefined)
30
- unsupported("providerOptions", "Daytona provider options are not mapped");
31
- const source = request.source;
32
- if (source?.warmPool !== undefined)
33
- unsupported("source.warmPool", "explicit warm-pool creation mapping is unavailable");
34
- if (source?.image !== undefined)
35
- return {
36
- ...base,
37
- image: nonblank(source.image.reference, "source.image.reference"),
38
- ...(request.resources === undefined ? {} : { resources: mapResources(request.resources) }),
39
- };
40
- if (request.resources !== undefined)
41
- unsupported("resources", "Daytona resources require an image source");
42
- if (source?.snapshot !== undefined) {
43
- const snapshot = source.snapshot;
44
- if ((snapshot.kind ?? SnapshotKind.Default) !== SnapshotKind.Default)
45
- unsupported("source.snapshot.kind", "explicit snapshot-kind restore mapping is unavailable");
46
- if (snapshot.providerKind !== undefined)
47
- unsupported("source.snapshot.providerKind", "provider snapshot kind is unsupported");
48
- return { ...base, snapshot: nonblank(snapshot.reference, "source.snapshot.reference") };
49
- }
50
- return { ...base };
51
- }
52
- function mapRuntime(request, target) {
53
- const value = request.runtime;
54
- if (value === undefined)
55
- return;
56
- if (value.language !== undefined)
57
- target.language = value.language;
58
- if (value.user !== undefined)
59
- target.user = nonblank(value.user, "runtime.user");
60
- if (value.version !== undefined ||
61
- value.workingDirectory !== undefined ||
62
- value.entrypoint !== undefined ||
63
- value.pty !== undefined)
64
- unsupported("runtime", "runtime version, working directory, entrypoint, and PTY are not mapped by Daytona");
65
- }
66
- function mapIsolation(request, target) {
67
- const value = request.isolation;
68
- if (value === undefined)
69
- return;
70
- if ((value.kind ?? IsolationKind.Default) !== IsolationKind.Default || value.providerKind !== undefined)
71
- unsupported("isolation", "Daytona isolation class comes from the selected source");
72
- if (value.nestedVirtualization !== undefined)
73
- target.kvm = value.nestedVirtualization;
74
- }
75
- function mapSecurity(request, target) {
76
- const value = request.security;
77
- if (value === undefined)
78
- return;
79
- if (value.publicAccess !== undefined)
80
- target.public = value.publicAccess;
81
- if (value.workloadIdentity !== undefined)
82
- unsupported("security.workloadIdentity", "Daytona workload identity is not mapped");
83
- if (value.secrets !== undefined) {
84
- const secrets = {};
85
- for (const secret of value.secrets) {
86
- const variable = secret.environmentVariable === undefined
87
- ? ""
88
- : nonblank(secret.environmentVariable, "security.secrets.environmentVariable");
89
- if (variable === "")
90
- invalid("security.secrets.environmentVariable", "secret environment variable is required");
91
- const injection = secret.injection ?? SecretInjection.Default;
92
- if (injection !== SecretInjection.Default && injection !== SecretInjection.EgressPlaceholder)
93
- unsupported("security.secrets.injection", "Daytona secrets require egress-placeholder injection");
94
- if (Object.hasOwn(secrets, variable))
95
- invalid("security.secrets.environmentVariable", "duplicate secret environment variable");
96
- secrets[variable] = nonblank(secret.reference, "security.secrets.reference");
97
- }
98
- target.secrets = secrets;
99
- }
100
- }
101
- function mapNetwork(request, target) {
102
- const value = request.network;
103
- if (value === undefined)
104
- return;
105
- if (value.linkedSandbox !== undefined && request.lifetime?.ephemeral !== true)
106
- invalid("network.linkedSandbox", "linked sandboxes must be ephemeral");
107
- const egress = value.egress ?? EgressMode.Default;
108
- if (egress === EgressMode.BlockAll)
109
- target.networkBlockAll = true;
110
- else if (egress !== EgressMode.Default && egress !== EgressMode.AllowAll && egress !== EgressMode.Restricted)
111
- invalid("network.egress", "unknown egress mode");
112
- if (value.outboundCidrs !== undefined) {
113
- if (!value.outboundCidrs.length)
114
- unsupported("network.outboundCidrs", "empty CIDR allowlist mapping is not verified");
115
- target.networkAllowList = value.outboundCidrs.join(",");
116
- }
117
- if (value.outboundDomains !== undefined) {
118
- if (!value.outboundDomains.length)
119
- unsupported("network.outboundDomains", "empty domain allowlist mapping is not verified");
120
- target.domainAllowList = value.outboundDomains.join(",");
121
- }
122
- if (value.linkedSandbox !== undefined)
123
- target.linkedSandbox = nonblank(value.linkedSandbox, "network.linkedSandbox");
124
- if (value.outboundProxyUrl !== undefined)
125
- target.outboundProxyUrl = value.outboundProxyUrl;
126
- if (value.inboundCidrs !== undefined ||
127
- value.privateNetwork !== undefined ||
128
- value.proxyReference !== undefined ||
129
- value.customDomain !== undefined ||
130
- value.ports !== undefined)
131
- unsupported("network", "one or more Daytona network fields are not mapped");
132
- }
133
- function mapLifetime(request, target) {
134
- const value = request.lifetime;
135
- if (value === undefined)
136
- return;
137
- Object.assign(target, generatedMapLifetimePolicies(value));
138
- if (value.ephemeral !== undefined)
139
- target.ephemeral = value.ephemeral;
140
- if (value.maximumLifetime !== undefined)
141
- target.ttlMinutes = wholeMinutes(value.maximumLifetime, "lifetime.maximumLifetime", true);
142
- if (value.idleTerminate !== undefined)
143
- unsupported("lifetime.idleTerminate", "Daytona idle termination is not mapped");
144
- }
145
- function mapProvisioning(request, target) {
146
- const value = request.provisioning;
147
- if (value === undefined)
148
- return;
149
- if (value.queueTimeout !== undefined)
150
- target.queueTimeout = wholeMinutes(value.queueTimeout, "provisioning.queueTimeout", false);
151
- const waitFor = value.waitFor ?? WaitCondition.Default;
152
- if (waitFor !== WaitCondition.Default && waitFor !== WaitCondition.Started)
153
- unsupported("provisioning.waitFor", "the Daytona TypeScript SDK only returns after startup");
154
- }
155
- function mapObservability(request, target) {
156
- const value = request.observability;
157
- if (value === undefined)
158
- return;
159
- if (value.telemetryEndpoint !== undefined)
160
- target.otelEndpointOverride = nonblank(value.telemetryEndpoint, "observability.telemetryEndpoint");
161
- if (value.verbose !== undefined)
162
- unsupported("observability.verbose", "Daytona verbose creation is not mapped");
163
- }
164
- function mapResources(value) {
165
- if (value.cpuCores !== undefined && value.cpuCores <= 0)
166
- invalid("resources.cpuCores", "CPU must be positive");
167
- if (value.cpuLimitCores !== undefined || value.memoryLimitMib !== undefined)
168
- unsupported("resources", "Daytona resource limits are not mapped");
169
- return generatedMapResources(value);
170
- }
171
- function wholeMinutes(value, field, zeroAllowed) {
172
- if (!Number.isFinite(value) ||
173
- value < 0 ||
174
- value % 60_000 !== 0 ||
175
- value / 60_000 > 2_147_483_647 ||
176
- (!zeroAllowed && value === 0))
177
- invalid(field, "duration must be representable in whole minutes");
178
- return value / 60_000;
179
- }
180
- export function mapSandboxInfo(value, operation = "create") {
181
- const mapped = generatedMapSandboxInfo(value, operation);
182
- const origins = { ...(mapped.origins ?? {}) };
183
- const state = mapState(value.state === undefined ? undefined : String(value.state));
184
- const result = {
185
- ...mapped,
186
- id: mapped.id ?? value.id,
187
- provider: "daytona",
188
- state,
189
- labels: mapped.labels ?? {},
190
- origins,
191
- };
192
- const resources = generatedMapAllocatedResources(value, operation);
193
- if (Object.keys(resources).length > 0) {
194
- resultMutable(result).resources = resources;
195
- origins.resources = ValueOrigin.Provider;
196
- }
197
- if (value.sandboxClass !== undefined) {
198
- const native = String(value.sandboxClass);
199
- resultMutable(result).isolation =
200
- native === "container"
201
- ? { kind: IsolationKind.Container }
202
- : native === "linux-vm"
203
- ? { kind: IsolationKind.LinuxVm }
204
- : { kind: IsolationKind.ProviderSpecific, providerKind: native };
205
- origins.isolation = ValueOrigin.Provider;
206
- }
207
- if (state === SandboxState.Deleted) {
208
- resultMutable(result).terminal = true;
209
- origins.terminal = ValueOrigin.Provider;
210
- }
211
- const metadata = {};
212
- if (value.gpu > 0)
213
- metadata.gpu_count = value.gpu;
214
- if (value.gpuType !== undefined)
215
- metadata.gpu_type = String(value.gpuType);
216
- if (value.desiredState !== undefined)
217
- metadata.desired_state = String(value.desiredState);
218
- if (value.errorReason !== undefined)
219
- metadata.error_reason = value.errorReason;
220
- if (value.recoverable !== undefined)
221
- metadata.recoverable = value.recoverable;
222
- if (value.spot === true)
223
- metadata.spot = true;
224
- for (const [key, entry] of [
225
- ["spot_evicted_at", value.spotEvictedAt],
226
- ["backup_state", value.backupState],
227
- ["backup_created_at", value.backupCreatedAt],
228
- ["updated_at", value.updatedAt],
229
- ["last_activity_at", value.lastActivityAt],
230
- ["auto_destroy_at", value.autoDestroyAt],
231
- ["queue_timed_out_at", value.queueTimedOutAt],
232
- ["snapshot", value.snapshot],
233
- ["warm_pool_id", value.warmPoolId],
234
- ])
235
- if (entry !== undefined)
236
- metadata[key] = String(entry);
237
- for (const [key, entry] of [
238
- ["auto_stop_interval_minutes", value.autoStopInterval],
239
- ["auto_pause_interval_minutes", value.autoPauseInterval],
240
- ["auto_archive_interval_minutes", value.autoArchiveInterval],
241
- ["auto_delete_interval_minutes", value.autoDeleteInterval],
242
- ])
243
- if (entry !== undefined)
244
- metadata[key] = entry;
245
- if (Object.keys(metadata).length > 0) {
246
- const providerMetadata = metadataObjectFromMap(metadata);
247
- if (providerMetadata !== undefined) {
248
- resultMutable(result).providerMetadata = providerMetadata;
249
- origins.provider_metadata = ValueOrigin.Provider;
250
- }
251
- }
252
- if (value.createdAt !== undefined) {
253
- const date = new Date(value.createdAt);
254
- if (!Number.isNaN(date.valueOf())) {
255
- resultMutable(result).createdAt = date;
256
- origins.created_at = ValueOrigin.Provider;
257
- }
258
- }
259
- return result;
260
- }
261
- function resultMutable(value) {
262
- return value;
263
- }
264
- function mapState(value) {
265
- switch (value) {
266
- case "creating":
267
- case "restoring":
268
- case "pending_build":
269
- case "building_snapshot":
270
- case "pulling_snapshot":
271
- case "forking":
272
- return SandboxState.Queued;
273
- case "starting":
274
- case "resuming":
275
- return SandboxState.Starting;
276
- case "started":
277
- return SandboxState.Running;
278
- case "stopping":
279
- return SandboxState.Stopping;
280
- case "stopped":
281
- return SandboxState.Stopped;
282
- case "pausing":
283
- return SandboxState.Pausing;
284
- case "paused":
285
- return SandboxState.Paused;
286
- case "archiving":
287
- return SandboxState.Archiving;
288
- case "archived":
289
- return SandboxState.Archived;
290
- case "destroying":
291
- return SandboxState.Deleting;
292
- case "destroyed":
293
- return SandboxState.Deleted;
294
- case "error":
295
- case "build_failed":
296
- return SandboxState.Error;
297
- default:
298
- return SandboxState.Unknown;
299
- }
300
- }
301
- function nonblank(value, field) {
302
- if (value.trim() === "")
303
- invalid(field, "value must not be blank");
304
- return value;
305
- }
306
- function invalid(field, message) {
307
- throw sandboxError({
308
- kind: ErrorKind.InvalidArgument,
309
- provider: "daytona",
310
- operation: "create",
311
- field,
312
- message: "sandbox-kit daytona: " + message,
313
- });
314
- }
315
- function unsupported(field, message) {
316
- throw sandboxError({
317
- kind: ErrorKind.Unsupported,
318
- provider: "daytona",
319
- operation: "create",
320
- field,
321
- message: "sandbox-kit daytona: " + message,
322
- });
323
- }
324
- function configInvalid(field, message) {
325
- throw sandboxError({
326
- kind: ErrorKind.InvalidArgument,
327
- provider: "daytona",
328
- operation: "initialize",
329
- field,
330
- message: "sandbox-kit daytona: " + message,
331
- });
332
- }
@@ -1,3 +0,0 @@
1
- import { type CreateOptionsWire } from "@sandbox-kit/sandbox";
2
- export declare function validateProviderCreate(request: CreateOptionsWire): void;
3
- //# sourceMappingURL=provider.checks.gen.d.ts.map