@miosa/sdk 1.2.4 → 1.2.6

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.
Files changed (100) hide show
  1. package/README.md +75 -3
  2. package/dist/index.d.ts +323 -175
  3. package/dist/index.js +441 -386
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -2
  6. package/src/client.ts +0 -293
  7. package/src/errors.ts +0 -136
  8. package/src/http.test.ts +0 -374
  9. package/src/http.ts +0 -390
  10. package/src/index.ts +0 -564
  11. package/src/resources/admin.ts +0 -359
  12. package/src/resources/analytics.ts +0 -60
  13. package/src/resources/api-keys.ts +0 -135
  14. package/src/resources/audit-log.ts +0 -64
  15. package/src/resources/benchmarks.ts +0 -104
  16. package/src/resources/builder-sessions.ts +0 -75
  17. package/src/resources/channels.ts +0 -143
  18. package/src/resources/checkpoints.ts +0 -225
  19. package/src/resources/command-center.ts +0 -73
  20. package/src/resources/community.ts +0 -103
  21. package/src/resources/completions.ts +0 -104
  22. package/src/resources/computer-auto-stop.ts +0 -43
  23. package/src/resources/computer-env.ts +0 -76
  24. package/src/resources/computer-logs.ts +0 -50
  25. package/src/resources/computer-osa.ts +0 -76
  26. package/src/resources/computer-ports.ts +0 -91
  27. package/src/resources/computer-terminal.ts +0 -61
  28. package/src/resources/computer-volumes.ts +0 -64
  29. package/src/resources/computer.ts +0 -551
  30. package/src/resources/computers.ts +0 -75
  31. package/src/resources/credits.ts +0 -43
  32. package/src/resources/cron-jobs.ts +0 -191
  33. package/src/resources/custom_domains.ts +0 -123
  34. package/src/resources/dashboard.ts +0 -49
  35. package/src/resources/databases.ts +0 -218
  36. package/src/resources/deployments.test.ts +0 -194
  37. package/src/resources/deployments.ts +0 -1060
  38. package/src/resources/desktop.ts +0 -134
  39. package/src/resources/docker-deploy.test.ts +0 -102
  40. package/src/resources/docker-deploy.ts +0 -183
  41. package/src/resources/egress.test.ts +0 -318
  42. package/src/resources/egressAudit.ts +0 -245
  43. package/src/resources/egressNetwork.ts +0 -450
  44. package/src/resources/egressSecrets.ts +0 -577
  45. package/src/resources/email.ts +0 -212
  46. package/src/resources/embeddings.ts +0 -36
  47. package/src/resources/events.ts +0 -296
  48. package/src/resources/exec.ts +0 -319
  49. package/src/resources/external-keys.ts +0 -79
  50. package/src/resources/files.test.ts +0 -339
  51. package/src/resources/files.ts +0 -220
  52. package/src/resources/flat-custom-domains.ts +0 -127
  53. package/src/resources/functions.ts +0 -178
  54. package/src/resources/governance.test.ts +0 -355
  55. package/src/resources/governance.ts +0 -528
  56. package/src/resources/health-checks.ts +0 -165
  57. package/src/resources/integrations.ts +0 -183
  58. package/src/resources/mcp.ts +0 -70
  59. package/src/resources/models.ts +0 -45
  60. package/src/resources/network_policy.ts +0 -73
  61. package/src/resources/open-computers/agents.ts +0 -91
  62. package/src/resources/open-computers/apps.ts +0 -102
  63. package/src/resources/open-computers/clusters.ts +0 -88
  64. package/src/resources/open-computers/desktop.ts +0 -34
  65. package/src/resources/open-computers/files.ts +0 -97
  66. package/src/resources/open-computers/hosts.ts +0 -85
  67. package/src/resources/open-computers/index.ts +0 -98
  68. package/src/resources/open-computers/jobs.ts +0 -75
  69. package/src/resources/open-computers/open_computers.test.ts +0 -288
  70. package/src/resources/open-computers/secrets.ts +0 -115
  71. package/src/resources/open-computers/terminal.ts +0 -33
  72. package/src/resources/open-computers/tunnels.ts +0 -87
  73. package/src/resources/open-computers/types.ts +0 -343
  74. package/src/resources/open-computers/workspaces.ts +0 -135
  75. package/src/resources/org-invites.ts +0 -189
  76. package/src/resources/phase1.test.ts +0 -187
  77. package/src/resources/project-auth.ts +0 -142
  78. package/src/resources/project-integrations.ts +0 -133
  79. package/src/resources/provider-defaults.ts +0 -89
  80. package/src/resources/quotas.ts +0 -77
  81. package/src/resources/regions.ts +0 -94
  82. package/src/resources/sandbox-processes.ts +0 -112
  83. package/src/resources/sandbox-shares.ts +0 -83
  84. package/src/resources/sandbox-templates.ts +0 -195
  85. package/src/resources/sandboxes.live.test.ts +0 -92
  86. package/src/resources/sandboxes.test.ts +0 -653
  87. package/src/resources/sandboxes.ts +0 -1433
  88. package/src/resources/settings.ts +0 -143
  89. package/src/resources/snapshots-standalone.ts +0 -51
  90. package/src/resources/storage.ts +0 -221
  91. package/src/resources/tenant-events.ts +0 -32
  92. package/src/resources/tenant.ts +0 -148
  93. package/src/resources/usage.ts +0 -85
  94. package/src/resources/volumes.ts +0 -117
  95. package/src/resources/webhooks.ts +0 -224
  96. package/src/resources/workspace-invites.ts +0 -188
  97. package/src/resources/workspace-members.test.ts +0 -121
  98. package/src/resources/workspace-members.ts +0 -143
  99. package/src/resources/workspaces.ts +0 -285
  100. package/src/types.ts +0 -463
@@ -1,89 +0,0 @@
1
- /**
2
- * ProviderDefaults — admin LLM provider routing config.
3
- *
4
- * Routes:
5
- * GET /admin/provider-defaults
6
- * PUT /admin/provider-defaults
7
- * GET /admin/tenants/:id/provider-config
8
- * PUT /admin/tenants/:id/provider-config
9
- * DELETE /admin/tenants/:id/provider-config
10
- *
11
- * Requires admin credential (msk_a_* / msk_p_* or admin JWT).
12
- */
13
-
14
- import type { HttpClient } from "../http.js";
15
-
16
- function unwrap(data: unknown): Record<string, unknown> {
17
- if (data && typeof data === "object") {
18
- const d = data as Record<string, unknown>;
19
- for (const k of ["data", "defaults", "provider_defaults", "config"]) {
20
- if (k in d) return d[k] as Record<string, unknown>;
21
- }
22
- }
23
- return data as Record<string, unknown>;
24
- }
25
-
26
- export class ProviderDefaults {
27
- constructor(private readonly http: HttpClient) {}
28
-
29
- /** Get the current fleet-wide provider defaults. */
30
- async list(): Promise<Record<string, unknown>> {
31
- return unwrap(await this.http.get<unknown>("/admin/provider-defaults"));
32
- }
33
-
34
- /** Return the defaults entry for a single provider, or {} if missing. */
35
- async get(provider: string): Promise<Record<string, unknown>> {
36
- const data = await this.list();
37
- const providers =
38
- (data.providers as Record<string, unknown> | undefined) ?? data;
39
- if (
40
- typeof providers === "object" &&
41
- providers !== null &&
42
- provider in providers
43
- ) {
44
- return providers[provider] as Record<string, unknown>;
45
- }
46
- return {};
47
- }
48
-
49
- /** Replace the fleet-wide defaults (PUT /admin/provider-defaults). */
50
- async update(
51
- opts: Record<string, unknown>,
52
- ): Promise<Record<string, unknown>> {
53
- const body = Object.fromEntries(
54
- Object.entries(opts).filter(([, v]) => v !== undefined),
55
- );
56
- return unwrap(
57
- await this.http.put<unknown>("/admin/provider-defaults", body),
58
- );
59
- }
60
-
61
- // ── Per-tenant overrides ────────────────────────────────────────────────
62
-
63
- async getTenant(tenantId: string): Promise<Record<string, unknown>> {
64
- return unwrap(
65
- await this.http.get<unknown>(
66
- `/admin/tenants/${tenantId}/provider-config`,
67
- ),
68
- );
69
- }
70
-
71
- async setTenant(
72
- tenantId: string,
73
- opts: Record<string, unknown>,
74
- ): Promise<Record<string, unknown>> {
75
- const body = Object.fromEntries(
76
- Object.entries(opts).filter(([, v]) => v !== undefined),
77
- );
78
- return unwrap(
79
- await this.http.put<unknown>(
80
- `/admin/tenants/${tenantId}/provider-config`,
81
- body,
82
- ),
83
- );
84
- }
85
-
86
- async resetTenant(tenantId: string): Promise<void> {
87
- await this.http.delete(`/admin/tenants/${tenantId}/provider-config`);
88
- }
89
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * Quotas — per-external_user_id resource limits.
3
- * Corresponds to: GET/PUT/DELETE /api/v1/quotas/external/{external_user_id}
4
- */
5
-
6
- import type { HttpClient } from "../http.js";
7
-
8
- // ── Resource shapes ──────────────────────────────────────────────────────────
9
-
10
- export interface QuotaData {
11
- external_user_id: string;
12
- max_sandboxes?: number | null;
13
- max_concurrent?: number | null;
14
- max_storage_gb?: number | null;
15
- max_credit_cents?: number | null;
16
- usage?: {
17
- sandbox_count?: number;
18
- concurrent_count?: number;
19
- storage_gb?: number;
20
- credit_cents?: number;
21
- [key: string]: unknown;
22
- };
23
- [key: string]: unknown;
24
- }
25
-
26
- export interface QuotaSetParams {
27
- max_sandboxes?: number;
28
- max_concurrent?: number;
29
- max_storage_gb?: number;
30
- max_credit_cents?: number;
31
- }
32
-
33
- // ── Helpers ───────────────────────────────────────────────────────────────────
34
-
35
- function unwrap<T>(payload: unknown): T {
36
- if (payload && typeof payload === "object" && "data" in (payload as object)) {
37
- return (payload as { data: T }).data;
38
- }
39
- return payload as T;
40
- }
41
-
42
- function stripUndefined(
43
- input: Record<string, unknown>,
44
- ): Record<string, unknown> {
45
- return Object.fromEntries(
46
- Object.entries(input).filter(([, v]) => v !== undefined),
47
- );
48
- }
49
-
50
- // ── Main resource ─────────────────────────────────────────────────────────────
51
-
52
- export class Quotas {
53
- constructor(private readonly http: HttpClient) {}
54
-
55
- /** GET /api/v1/quotas/external/{external_user_id} — current limits + usage. */
56
- async get(externalUserId: string): Promise<QuotaData> {
57
- return unwrap(
58
- await this.http.get<unknown>(`/quotas/external/${externalUserId}`),
59
- );
60
- }
61
-
62
- /** PUT /api/v1/quotas/external/{external_user_id} — set per-user limits. */
63
- async set(
64
- externalUserId: string,
65
- params: QuotaSetParams,
66
- ): Promise<QuotaData> {
67
- const body = stripUndefined(params as Record<string, unknown>);
68
- return unwrap(
69
- await this.http.put<unknown>(`/quotas/external/${externalUserId}`, body),
70
- );
71
- }
72
-
73
- /** DELETE /api/v1/quotas/external/{external_user_id} — revert to tenant default. */
74
- async delete(externalUserId: string): Promise<void> {
75
- await this.http.delete<unknown>(`/quotas/external/${externalUserId}`);
76
- }
77
- }
@@ -1,94 +0,0 @@
1
- /**
2
- * Regions — datacenter availability, sizes, pricing, templates.
3
- */
4
-
5
- import type { HttpClient } from "../http.js";
6
-
7
- // ── Resource shapes ──────────────────────────────────────────────────────────
8
-
9
- export interface RegionData {
10
- id?: string;
11
- name?: string;
12
- slug?: string;
13
- available?: boolean;
14
- [key: string]: unknown;
15
- }
16
-
17
- export interface SizeData {
18
- id?: string;
19
- name?: string;
20
- slug?: string;
21
- cpu?: number;
22
- memory_mb?: number;
23
- [key: string]: unknown;
24
- }
25
-
26
- export interface TemplateData {
27
- id?: string;
28
- name?: string;
29
- slug?: string;
30
- [key: string]: unknown;
31
- }
32
-
33
- // ── Helpers ───────────────────────────────────────────────────────────────────
34
-
35
- function unwrap<T>(payload: unknown): T {
36
- if (payload && typeof payload === "object") {
37
- const p = payload as Record<string, unknown>;
38
- for (const k of [
39
- "data",
40
- "regions",
41
- "sizes",
42
- "pricing",
43
- "templates",
44
- "items",
45
- ]) {
46
- if (k in p) return p[k] as T;
47
- }
48
- }
49
- return payload as T;
50
- }
51
-
52
- function listItems<T>(payload: unknown): T[] {
53
- const result = unwrap<T[] | unknown>(payload);
54
- if (Array.isArray(result)) return result;
55
- return [];
56
- }
57
-
58
- // ── Main resource ─────────────────────────────────────────────────────────────
59
-
60
- export class Regions {
61
- constructor(private readonly http: HttpClient) {}
62
-
63
- /** List datacenter regions. */
64
- async listRegions(): Promise<RegionData[]> {
65
- const data = await this.http.get<unknown>("/compute/regions");
66
- return listItems<RegionData>(data);
67
- }
68
-
69
- /** List available compute sizes. */
70
- async listSizes(): Promise<SizeData[]> {
71
- const data = await this.http.get<unknown>("/compute/sizes");
72
- return listItems<SizeData>(data);
73
- }
74
-
75
- /** Get static compute pricing data. */
76
- async pricing(): Promise<unknown> {
77
- const data = await this.http.get<unknown>("/compute/pricing");
78
- return unwrap(data);
79
- }
80
-
81
- /** List community computer templates. */
82
- async listTemplates(): Promise<TemplateData[]> {
83
- const data = await this.http.get<unknown>("/compute/templates");
84
- return listItems<TemplateData>(data);
85
- }
86
-
87
- /** Get a single community template by id. */
88
- async getTemplate(templateId: string): Promise<TemplateData> {
89
- const data = await this.http.get<unknown>(
90
- `/compute/templates/${templateId}`,
91
- );
92
- return unwrap<TemplateData>(data);
93
- }
94
- }
@@ -1,112 +0,0 @@
1
- /**
2
- * SandboxProcesses — long-running process management inside a sandbox.
3
- * Corresponds to: POST/GET/DELETE /api/v1/sandboxes/{id}/processes
4
- */
5
-
6
- import type { HttpClient } from "../http.js";
7
-
8
- // ── Resource shapes ──────────────────────────────────────────────────────────
9
-
10
- export interface SandboxProcessData {
11
- pid: number;
12
- name?: string;
13
- command: string;
14
- status: "running" | "stopped" | "failed" | string;
15
- started_at?: string;
16
- exit_code?: number | null;
17
- [key: string]: unknown;
18
- }
19
-
20
- export interface SandboxProcessStartParams {
21
- command: string;
22
- env?: Record<string, string>;
23
- name?: string;
24
- }
25
-
26
- export interface SandboxProcessStreamEvent {
27
- stream: "stdout" | "stderr";
28
- line: string;
29
- }
30
-
31
- // ── Helpers ───────────────────────────────────────────────────────────────────
32
-
33
- function unwrap<T>(payload: unknown): T {
34
- if (payload && typeof payload === "object" && "data" in (payload as object)) {
35
- return (payload as { data: T }).data;
36
- }
37
- return payload as T;
38
- }
39
-
40
- function listItems<T>(payload: unknown): T[] {
41
- if (Array.isArray(payload)) return payload;
42
- if (!payload || typeof payload !== "object") return [];
43
- const p = payload as Record<string, unknown>;
44
- for (const k of ["data", "processes", "items"]) {
45
- if (Array.isArray(p[k])) return p[k] as T[];
46
- }
47
- return [];
48
- }
49
-
50
- function stripUndefined(
51
- input: Record<string, unknown>,
52
- ): Record<string, unknown> {
53
- return Object.fromEntries(
54
- Object.entries(input).filter(([, v]) => v !== undefined),
55
- );
56
- }
57
-
58
- // ── Main resource ─────────────────────────────────────────────────────────────
59
-
60
- export class SandboxProcesses {
61
- constructor(
62
- private readonly http: HttpClient,
63
- private readonly sandboxId: string,
64
- ) {}
65
-
66
- private base(): string {
67
- return `/sandboxes/${this.sandboxId}/processes`;
68
- }
69
-
70
- /** POST /api/v1/sandboxes/{id}/processes — start a long-running process. */
71
- async start(params: SandboxProcessStartParams): Promise<SandboxProcessData> {
72
- const body = stripUndefined({
73
- command: params.command,
74
- env: params.env,
75
- name: params.name,
76
- });
77
- return unwrap(await this.http.post<unknown>(this.base(), body));
78
- }
79
-
80
- /** GET /api/v1/sandboxes/{id}/processes — list all processes. */
81
- async list(): Promise<SandboxProcessData[]> {
82
- const data = await this.http.get<unknown>(this.base());
83
- return listItems<SandboxProcessData>(data);
84
- }
85
-
86
- /** GET /api/v1/sandboxes/{id}/processes/{pid} — get a single process. */
87
- async get(pid: number): Promise<SandboxProcessData> {
88
- return unwrap(await this.http.get<unknown>(`${this.base()}/${pid}`));
89
- }
90
-
91
- /** DELETE /api/v1/sandboxes/{id}/processes/{pid} — SIGTERM then SIGKILL after 5s. */
92
- async stop(pid: number): Promise<void> {
93
- await this.http.delete<unknown>(`${this.base()}/${pid}`);
94
- }
95
-
96
- /** GET /api/v1/sandboxes/{id}/processes/{pid}/logs?tail=N — tail log text. */
97
- async logs(pid: number, tail = 200): Promise<string> {
98
- const data = await this.http.get<unknown>(`${this.base()}/${pid}/logs`, {
99
- tail,
100
- });
101
- if (typeof data === "string") return data;
102
- const d = data as Record<string, unknown>;
103
- return String(d.logs ?? d.output ?? d.data ?? "");
104
- }
105
-
106
- /** GET /api/v1/sandboxes/{id}/processes/{pid}/stream (SSE) — live output. */
107
- stream(pid: number): AsyncIterableIterator<SandboxProcessStreamEvent> {
108
- return this.http.stream<SandboxProcessStreamEvent>(
109
- `${this.base()}/${pid}/stream`,
110
- );
111
- }
112
- }
@@ -1,83 +0,0 @@
1
- /**
2
- * SandboxShares — public read-only share URLs for a sandbox.
3
- * Corresponds to: POST/GET/DELETE /api/v1/sandboxes/{id}/shares
4
- */
5
-
6
- import type { HttpClient } from "../http.js";
7
-
8
- // ── Resource shapes ──────────────────────────────────────────────────────────
9
-
10
- export interface SandboxShareData {
11
- share_id: string;
12
- share_url: string;
13
- expires_at?: string | null;
14
- scope: string;
15
- [key: string]: unknown;
16
- }
17
-
18
- export interface SandboxShareCreateParams {
19
- expires_in?: number;
20
- scope?: "read";
21
- }
22
-
23
- // ── Helpers ───────────────────────────────────────────────────────────────────
24
-
25
- function unwrap<T>(payload: unknown): T {
26
- if (payload && typeof payload === "object" && "data" in (payload as object)) {
27
- return (payload as { data: T }).data;
28
- }
29
- return payload as T;
30
- }
31
-
32
- function listItems<T>(payload: unknown): T[] {
33
- if (Array.isArray(payload)) return payload;
34
- if (!payload || typeof payload !== "object") return [];
35
- const p = payload as Record<string, unknown>;
36
- for (const k of ["data", "shares", "items"]) {
37
- if (Array.isArray(p[k])) return p[k] as T[];
38
- }
39
- return [];
40
- }
41
-
42
- function stripUndefined(
43
- input: Record<string, unknown>,
44
- ): Record<string, unknown> {
45
- return Object.fromEntries(
46
- Object.entries(input).filter(([, v]) => v !== undefined),
47
- );
48
- }
49
-
50
- // ── Main resource ─────────────────────────────────────────────────────────────
51
-
52
- export class SandboxShares {
53
- constructor(
54
- private readonly http: HttpClient,
55
- private readonly sandboxId: string,
56
- ) {}
57
-
58
- private base(): string {
59
- return `/sandboxes/${this.sandboxId}/shares`;
60
- }
61
-
62
- /** POST /api/v1/sandboxes/{id}/shares — create a public share URL. */
63
- async create(
64
- params: SandboxShareCreateParams = {},
65
- ): Promise<SandboxShareData> {
66
- const body = stripUndefined({
67
- expires_in: params.expires_in,
68
- scope: params.scope ?? "read",
69
- });
70
- return unwrap(await this.http.post<unknown>(this.base(), body));
71
- }
72
-
73
- /** GET /api/v1/sandboxes/{id}/shares — list all active shares. */
74
- async list(): Promise<SandboxShareData[]> {
75
- const data = await this.http.get<unknown>(this.base());
76
- return listItems<SandboxShareData>(data);
77
- }
78
-
79
- /** DELETE /api/v1/sandboxes/{id}/shares/{share_id} — revoke a share. */
80
- async revoke(shareId: string): Promise<void> {
81
- await this.http.delete<unknown>(`${this.base()}/${shareId}`);
82
- }
83
- }
@@ -1,195 +0,0 @@
1
- /**
2
- * SandboxTemplates resource — tenant sandbox template management.
3
- */
4
-
5
- import { randomUUID } from "node:crypto";
6
-
7
- import type { HttpClient } from "../http.js";
8
-
9
- // ── Branded IDs ──────────────────────────────────────────────────────────────
10
-
11
- export type SandboxTemplateResourceId = string & {
12
- readonly __brand: "SandboxTemplateResourceId";
13
- };
14
- export type SandboxTemplateBuildResourceId = string & {
15
- readonly __brand: "SandboxTemplateBuildResourceId";
16
- };
17
-
18
- // ── Resource shapes ──────────────────────────────────────────────────────────
19
-
20
- export interface SandboxTemplateResourceData {
21
- id: SandboxTemplateResourceId;
22
- tenant_id: string;
23
- name: string;
24
- state?: string;
25
- build_spec?: Record<string, unknown>;
26
- aliases?: string[];
27
- created_at?: string;
28
- updated_at?: string;
29
- [key: string]: unknown;
30
- }
31
-
32
- export interface SandboxTemplateBuildResourceData {
33
- id: SandboxTemplateBuildResourceId;
34
- template_id: SandboxTemplateResourceId;
35
- state?: string;
36
- started_at?: string | null;
37
- finished_at?: string | null;
38
- error?: string | null;
39
- created_at?: string;
40
- [key: string]: unknown;
41
- }
42
-
43
- // ── Request payloads ─────────────────────────────────────────────────────────
44
-
45
- export interface SandboxTemplateListParams {
46
- include_aliases?: boolean;
47
- includeAliases?: boolean;
48
- }
49
-
50
- export interface TemplateCreateParams {
51
- name: string;
52
- build_spec: Record<string, unknown>;
53
- buildSpec?: Record<string, unknown>;
54
- idempotencyKey?: string;
55
- [key: string]: unknown;
56
- }
57
-
58
- export interface TemplateBuildCreateParams {
59
- idempotencyKey?: string;
60
- [key: string]: unknown;
61
- }
62
-
63
- // ── Helpers ───────────────────────────────────────────────────────────────────
64
-
65
- function unwrap<T>(payload: unknown): T {
66
- if (payload && typeof payload === "object" && "data" in (payload as object)) {
67
- return (payload as { data: T }).data;
68
- }
69
- return payload as T;
70
- }
71
-
72
- function listItems<T>(
73
- payload: unknown,
74
- candidateKeys: string[] = ["data", "templates", "builds", "items"],
75
- ): T[] {
76
- if (Array.isArray(payload)) return payload;
77
- if (!payload || typeof payload !== "object") return [];
78
- const p = payload as Record<string, unknown>;
79
- if (Array.isArray(p.data)) return p.data as T[];
80
- for (const key of candidateKeys) {
81
- if (Array.isArray(p[key])) return p[key] as T[];
82
- }
83
- return [];
84
- }
85
-
86
- function stripUndefined(
87
- input: Record<string, unknown>,
88
- ): Record<string, unknown> {
89
- return Object.fromEntries(
90
- Object.entries(input).filter(([, v]) => v !== undefined),
91
- );
92
- }
93
-
94
- function idempotencyKey(key?: string): string {
95
- return key ?? randomUUID();
96
- }
97
-
98
- // ── Main resource ─────────────────────────────────────────────────────────────
99
-
100
- export class SandboxTemplates {
101
- constructor(private readonly http: HttpClient) {}
102
-
103
- async list(
104
- params: SandboxTemplateListParams = {},
105
- ): Promise<SandboxTemplateResourceData[]> {
106
- const includeAliases =
107
- params.includeAliases ?? params.include_aliases ?? false;
108
- const query = includeAliases
109
- ? ({ include_aliases: true } as Record<
110
- string,
111
- string | number | boolean | undefined
112
- >)
113
- : undefined;
114
- const data = await this.http.get<unknown>("/sandbox-templates", query);
115
- return listItems<SandboxTemplateResourceData>(data, [
116
- "data",
117
- "templates",
118
- "items",
119
- ]);
120
- }
121
-
122
- async get(templateId: string): Promise<SandboxTemplateResourceData> {
123
- const data = await this.http.get<unknown>(
124
- `/sandbox-templates/${templateId}`,
125
- );
126
- return unwrap<SandboxTemplateResourceData>(data);
127
- }
128
-
129
- async create(
130
- params: TemplateCreateParams,
131
- ): Promise<SandboxTemplateResourceData> {
132
- const {
133
- idempotencyKey: ikey,
134
- buildSpec,
135
- build_spec,
136
- name,
137
- ...rest
138
- } = params;
139
- const body = stripUndefined({
140
- name,
141
- build_spec: buildSpec ?? build_spec,
142
- ...rest,
143
- });
144
- const data = await this.http.request<unknown>("/sandbox-templates", {
145
- method: "POST",
146
- body,
147
- headers: { "Idempotency-Key": idempotencyKey(ikey) },
148
- });
149
- return unwrap<SandboxTemplateResourceData>(data);
150
- }
151
-
152
- async buildSpecSchema(): Promise<Record<string, unknown>> {
153
- const data = await this.http.get<unknown>("/sandbox-templates/build-spec");
154
- return (data ?? {}) as Record<string, unknown>;
155
- }
156
-
157
- async validate(
158
- buildSpec: Record<string, unknown>,
159
- ): Promise<Record<string, unknown>> {
160
- const data = await this.http.post<unknown>("/sandbox-templates/validate", {
161
- build_spec: buildSpec,
162
- });
163
- return (data ?? {}) as Record<string, unknown>;
164
- }
165
-
166
- async listBuilds(
167
- templateId: string,
168
- ): Promise<SandboxTemplateBuildResourceData[]> {
169
- const data = await this.http.get<unknown>(
170
- `/sandbox-templates/${templateId}/builds`,
171
- );
172
- return listItems<SandboxTemplateBuildResourceData>(data, [
173
- "data",
174
- "builds",
175
- "items",
176
- ]);
177
- }
178
-
179
- async createBuild(
180
- templateId: string,
181
- params: TemplateBuildCreateParams = {},
182
- ): Promise<SandboxTemplateBuildResourceData> {
183
- const { idempotencyKey: ikey, ...rest } = params;
184
- const body = stripUndefined(rest as Record<string, unknown>);
185
- const data = await this.http.request<unknown>(
186
- `/sandbox-templates/${templateId}/builds`,
187
- {
188
- method: "POST",
189
- body,
190
- headers: { "Idempotency-Key": idempotencyKey(ikey) },
191
- },
192
- );
193
- return unwrap<SandboxTemplateBuildResourceData>(data);
194
- }
195
- }