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