@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,103 +0,0 @@
1
- /**
2
- * Community — public template + agent catalog with install + rate.
3
- *
4
- * Routes: /community/*
5
- * Requires JWT.
6
- */
7
-
8
- import type { HttpClient } from "../http.js";
9
-
10
- function unwrap(data: unknown): Record<string, unknown> {
11
- if (data && typeof data === "object") {
12
- const d = data as Record<string, unknown>;
13
- for (const k of ["data", "templates", "agents", "items"]) {
14
- if (k in d) return d[k] as Record<string, unknown>;
15
- }
16
- }
17
- return data as Record<string, unknown>;
18
- }
19
-
20
- function unwrapList(data: unknown): Record<string, unknown>[] {
21
- if (Array.isArray(data)) return data as Record<string, unknown>[];
22
- if (data && typeof data === "object") {
23
- const d = data as Record<string, unknown>;
24
- for (const k of ["data", "templates", "agents", "items"]) {
25
- if (Array.isArray(d[k])) return d[k] as Record<string, unknown>[];
26
- }
27
- }
28
- return [];
29
- }
30
-
31
- export class Community {
32
- constructor(private readonly http: HttpClient) {}
33
-
34
- // ── Agents ────────────────────────────────────────────────────────────
35
-
36
- async listAgents(
37
- filters: Record<string, string | number | boolean | undefined> = {},
38
- ): Promise<Record<string, unknown>[]> {
39
- const query = Object.fromEntries(
40
- Object.entries(filters).filter(([, v]) => v !== undefined),
41
- ) as Record<string, string | number | boolean | undefined>;
42
- return unwrapList(await this.http.get<unknown>("/community/agents", query));
43
- }
44
-
45
- async getAgent(agentId: string): Promise<Record<string, unknown>> {
46
- return unwrap(await this.http.get<unknown>(`/community/agents/${agentId}`));
47
- }
48
-
49
- // ── Templates ─────────────────────────────────────────────────────────
50
-
51
- async listTemplates(
52
- filters: Record<string, string | number | boolean | undefined> = {},
53
- ): Promise<Record<string, unknown>[]> {
54
- const query = Object.fromEntries(
55
- Object.entries(filters).filter(([, v]) => v !== undefined),
56
- ) as Record<string, string | number | boolean | undefined>;
57
- return unwrapList(
58
- await this.http.get<unknown>("/community/templates", query),
59
- );
60
- }
61
-
62
- async getTemplate(templateId: string): Promise<Record<string, unknown>> {
63
- return unwrap(
64
- await this.http.get<unknown>(`/community/templates/${templateId}`),
65
- );
66
- }
67
-
68
- /** Install a community template into the caller's tenant. */
69
- async installTemplate(
70
- templateId: string,
71
- opts: Record<string, unknown> = {},
72
- ): Promise<Record<string, unknown>> {
73
- const body = Object.fromEntries(
74
- Object.entries(opts).filter(([, v]) => v !== undefined),
75
- );
76
- return unwrap(
77
- await this.http.post<unknown>(
78
- `/community/templates/${templateId}/install`,
79
- body,
80
- ),
81
- );
82
- }
83
-
84
- /** Rate a community template (1–5). */
85
- async rateTemplate(
86
- templateId: string,
87
- rating: number,
88
- opts: Record<string, unknown> = {},
89
- ): Promise<Record<string, unknown>> {
90
- const body = {
91
- rating,
92
- ...Object.fromEntries(
93
- Object.entries(opts).filter(([, v]) => v !== undefined),
94
- ),
95
- };
96
- return unwrap(
97
- await this.http.post<unknown>(
98
- `/community/templates/${templateId}/rate`,
99
- body,
100
- ),
101
- );
102
- }
103
- }
@@ -1,104 +0,0 @@
1
- /**
2
- * Completions — OpenAI-compatible chat / text completion endpoints.
3
- *
4
- * Routes: POST /intelligence/completions, POST /intelligence/chat/completions
5
- * Requires an mki_* intelligence key. Supports stream=true via SSE.
6
- */
7
-
8
- import type { HttpClient } from "../http.js";
9
-
10
- interface CompletionBase {
11
- model: string;
12
- prompt?: string | string[];
13
- [key: string]: unknown;
14
- }
15
-
16
- export interface CompletionCreateParams extends CompletionBase {
17
- stream?: false;
18
- }
19
-
20
- export interface CompletionCreateStreamParams extends CompletionBase {
21
- stream: true;
22
- }
23
-
24
- interface ChatBase {
25
- model: string;
26
- messages: Record<string, unknown>[];
27
- [key: string]: unknown;
28
- }
29
-
30
- export interface ChatCompletionCreateParams extends ChatBase {
31
- stream?: false;
32
- }
33
-
34
- export interface ChatCompletionCreateStreamParams extends ChatBase {
35
- stream: true;
36
- }
37
-
38
- function unwrap(data: unknown): Record<string, unknown> {
39
- if (data && typeof data === "object") {
40
- const d = data as Record<string, unknown>;
41
- // Preserve OpenAI envelope (choices array present)
42
- if (Array.isArray(d.choices)) return d;
43
- if ("data" in d) return d.data as Record<string, unknown>;
44
- }
45
- return data as Record<string, unknown>;
46
- }
47
-
48
- function buildBody(params: Record<string, unknown>): Record<string, unknown> {
49
- return Object.fromEntries(
50
- Object.entries(params).filter(([, v]) => v !== undefined),
51
- );
52
- }
53
-
54
- export class Completions {
55
- constructor(private readonly http: HttpClient) {}
56
-
57
- /** Create a text completion (POST /intelligence/completions). */
58
- async create(
59
- params: CompletionCreateParams,
60
- ): Promise<Record<string, unknown>>;
61
- create(
62
- params: CompletionCreateStreamParams,
63
- ): AsyncIterableIterator<Record<string, unknown>>;
64
- create(
65
- params: CompletionCreateParams | CompletionCreateStreamParams,
66
- ):
67
- | Promise<Record<string, unknown>>
68
- | AsyncIterableIterator<Record<string, unknown>> {
69
- const body = buildBody(params);
70
- if (params.stream === true) {
71
- return this.http.stream<Record<string, unknown>>(
72
- "/intelligence/completions",
73
- { method: "POST", body },
74
- );
75
- }
76
- return this.http
77
- .post<unknown>("/intelligence/completions", body)
78
- .then(unwrap);
79
- }
80
-
81
- /** Create a chat completion (POST /intelligence/chat/completions). */
82
- async chat(
83
- params: ChatCompletionCreateParams,
84
- ): Promise<Record<string, unknown>>;
85
- chat(
86
- params: ChatCompletionCreateStreamParams,
87
- ): AsyncIterableIterator<Record<string, unknown>>;
88
- chat(
89
- params: ChatCompletionCreateParams | ChatCompletionCreateStreamParams,
90
- ):
91
- | Promise<Record<string, unknown>>
92
- | AsyncIterableIterator<Record<string, unknown>> {
93
- const body = buildBody(params);
94
- if (params.stream === true) {
95
- return this.http.stream<Record<string, unknown>>(
96
- "/intelligence/chat/completions",
97
- { method: "POST", body },
98
- );
99
- }
100
- return this.http
101
- .post<unknown>("/intelligence/chat/completions", body)
102
- .then(unwrap);
103
- }
104
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * ComputerAutoStop — read/update idle-timeout config.
3
- *
4
- * Routes:
5
- * GET /computers/:id/auto-stop
6
- * PATCH /computers/:id/auto-stop
7
- */
8
-
9
- import type { HttpClient } from "../http.js";
10
-
11
- function unwrap(data: unknown): Record<string, unknown> {
12
- if (data && typeof data === "object") {
13
- const d = data as Record<string, unknown>;
14
- if ("data" in d && Object.keys(d).length <= 2) {
15
- return d.data as Record<string, unknown>;
16
- }
17
- }
18
- return (data ?? {}) as Record<string, unknown>;
19
- }
20
-
21
- export class ComputerAutoStop {
22
- constructor(
23
- private readonly http: HttpClient,
24
- private readonly computerId: string,
25
- ) {}
26
-
27
- /** Return the current auto-stop configuration. */
28
- async get(): Promise<Record<string, unknown>> {
29
- return unwrap(
30
- await this.http.get<unknown>(`/computers/${this.computerId}/auto-stop`),
31
- );
32
- }
33
-
34
- /** Set the idle timeout in seconds (0 disables auto-stop). */
35
- async update(seconds: number): Promise<Record<string, unknown>> {
36
- return unwrap(
37
- await this.http.patch<unknown>(
38
- `/computers/${this.computerId}/auto-stop`,
39
- { seconds },
40
- ),
41
- );
42
- }
43
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * ComputerEnv — encrypted env var CRUD scoped to one Computer.
3
- *
4
- * Routes:
5
- * GET /computers/:id/env → list
6
- * POST /computers/:id/env → create (single)
7
- * PATCH /computers/:id/env/:name → update value
8
- * DELETE /computers/:id/env/:name → remove
9
- *
10
- * bulkSet falls back to N individual POSTs (no bulk endpoint yet).
11
- */
12
-
13
- import type { HttpClient } from "../http.js";
14
-
15
- function unwrap(data: unknown): Record<string, unknown> {
16
- if (data && typeof data === "object") {
17
- const d = data as Record<string, unknown>;
18
- if ("data" in d && Object.keys(d).length <= 2) {
19
- return d.data as Record<string, unknown>;
20
- }
21
- }
22
- return (data ?? {}) as Record<string, unknown>;
23
- }
24
-
25
- function unwrapList(data: unknown): Record<string, unknown>[] {
26
- if (Array.isArray(data)) return data as Record<string, unknown>[];
27
- if (data && typeof data === "object") {
28
- const d = data as Record<string, unknown>;
29
- for (const k of ["data", "env", "items"]) {
30
- if (Array.isArray(d[k])) return d[k] as Record<string, unknown>[];
31
- }
32
- }
33
- return [];
34
- }
35
-
36
- export class ComputerEnv {
37
- constructor(
38
- private readonly http: HttpClient,
39
- private readonly computerId: string,
40
- ) {}
41
-
42
- private base(): string {
43
- return `/computers/${this.computerId}/env`;
44
- }
45
-
46
- /** List all env vars (values may be masked depending on server policy). */
47
- async list(): Promise<Record<string, unknown>[]> {
48
- return unwrapList(await this.http.get<unknown>(this.base()));
49
- }
50
-
51
- /** Create a new env var. Use update() to change an existing one. */
52
- async set(name: string, value: string): Promise<Record<string, unknown>> {
53
- return unwrap(await this.http.post<unknown>(this.base(), { name, value }));
54
- }
55
-
56
- /** Patch the value of an existing env var by name. */
57
- async update(name: string, value: string): Promise<Record<string, unknown>> {
58
- return unwrap(
59
- await this.http.patch<unknown>(`${this.base()}/${name}`, { value }),
60
- );
61
- }
62
-
63
- /** Remove an env var by name. */
64
- async delete(name: string): Promise<void> {
65
- await this.http.delete(`${this.base()}/${name}`);
66
- }
67
-
68
- /** Convenience: create one env var per entry. */
69
- async bulkSet(
70
- env: Record<string, string>,
71
- ): Promise<Record<string, unknown>[]> {
72
- return Promise.all(
73
- Object.entries(env).map(([name, value]) => this.set(name, value)),
74
- );
75
- }
76
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * ComputerLogs — read + stream VM logs.
3
- *
4
- * Routes:
5
- * GET /computers/:id/logs — JSON snapshot (last N lines)
6
- * GET /computers/:id/logs/stream — text/event-stream of new lines (SSE)
7
- */
8
-
9
- import type { HttpClient } from "../http.js";
10
-
11
- export interface ComputerLogsGetParams {
12
- lines?: number;
13
- since?: string;
14
- }
15
-
16
- function unwrap(data: unknown): Record<string, unknown> {
17
- if (data && typeof data === "object") {
18
- const d = data as Record<string, unknown>;
19
- if ("data" in d && Object.keys(d).length <= 2) {
20
- return d.data as Record<string, unknown>;
21
- }
22
- }
23
- return (data ?? {}) as Record<string, unknown>;
24
- }
25
-
26
- export class ComputerLogs {
27
- constructor(
28
- private readonly http: HttpClient,
29
- private readonly computerId: string,
30
- ) {}
31
-
32
- /** Fetch the most recent log snapshot. */
33
- async get(
34
- params: ComputerLogsGetParams = {},
35
- ): Promise<Record<string, unknown>> {
36
- const query = Object.fromEntries(
37
- Object.entries(params).filter(([, v]) => v !== undefined),
38
- ) as Record<string, string | number | boolean | undefined>;
39
- return unwrap(
40
- await this.http.get<unknown>(`/computers/${this.computerId}/logs`, query),
41
- );
42
- }
43
-
44
- /** Stream live log events as SSE dicts `{type, data, id}`. */
45
- stream(): AsyncIterableIterator<Record<string, unknown>> {
46
- return this.http.stream<Record<string, unknown>>(
47
- `/computers/${this.computerId}/logs/stream`,
48
- );
49
- }
50
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * ComputerOsa — task dispatch to the in-VM OSA agent.
3
- *
4
- * Routes:
5
- * POST /computers/:id/osa/task
6
- * DELETE /computers/:id/osa/task
7
- * GET /computers/:id/osa/status
8
- * POST /computers/:id/osa/configure
9
- */
10
-
11
- import type { HttpClient } from "../http.js";
12
-
13
- function unwrap(data: unknown): Record<string, unknown> {
14
- if (data && typeof data === "object") {
15
- const d = data as Record<string, unknown>;
16
- if ("data" in d && Object.keys(d).length <= 2) {
17
- return d.data as Record<string, unknown>;
18
- }
19
- }
20
- return (data ?? {}) as Record<string, unknown>;
21
- }
22
-
23
- export class ComputerOsa {
24
- constructor(
25
- private readonly http: HttpClient,
26
- private readonly computerId: string,
27
- ) {}
28
-
29
- /** Submit a free-form task to the in-VM OSA agent. */
30
- async submitTask(
31
- task: string,
32
- params: Record<string, unknown> = {},
33
- ): Promise<Record<string, unknown>> {
34
- const body = {
35
- task,
36
- ...Object.fromEntries(
37
- Object.entries(params).filter(([, v]) => v !== undefined),
38
- ),
39
- };
40
- return unwrap(
41
- await this.http.post<unknown>(
42
- `/computers/${this.computerId}/osa/task`,
43
- body,
44
- ),
45
- );
46
- }
47
-
48
- /** Cancel the currently-running OSA task, if any. */
49
- async cancelTask(): Promise<Record<string, unknown>> {
50
- return unwrap(
51
- await this.http.delete<unknown>(`/computers/${this.computerId}/osa/task`),
52
- );
53
- }
54
-
55
- /** Return OSA's current task / configuration / health snapshot. */
56
- async status(): Promise<Record<string, unknown>> {
57
- return unwrap(
58
- await this.http.get<unknown>(`/computers/${this.computerId}/osa/status`),
59
- );
60
- }
61
-
62
- /** Update OSA runtime configuration (model, tools, secrets, etc.). */
63
- async configure(
64
- config: Record<string, unknown>,
65
- ): Promise<Record<string, unknown>> {
66
- const body = Object.fromEntries(
67
- Object.entries(config).filter(([, v]) => v !== undefined),
68
- );
69
- return unwrap(
70
- await this.http.post<unknown>(
71
- `/computers/${this.computerId}/osa/configure`,
72
- body,
73
- ),
74
- );
75
- }
76
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * ComputerPorts — per-port visibility control.
3
- *
4
- * Routes:
5
- * GET /computers/:id/ports — list
6
- * POST /computers/:id/ports — create
7
- * PATCH /computers/:id/ports/:port — update
8
- * DELETE /computers/:id/ports/:port — delete
9
- *
10
- * The backend does not expose a single-port GET; get() filters the list
11
- * response client-side for ergonomics.
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
- if ("data" in d && Object.keys(d).length <= 2) {
20
- return d.data as Record<string, unknown>;
21
- }
22
- }
23
- return (data ?? {}) as Record<string, unknown>;
24
- }
25
-
26
- function unwrapList(data: unknown): Record<string, unknown>[] {
27
- if (Array.isArray(data)) return data as Record<string, unknown>[];
28
- if (data && typeof data === "object") {
29
- const d = data as Record<string, unknown>;
30
- for (const k of ["data", "ports", "items"]) {
31
- if (Array.isArray(d[k])) return d[k] as Record<string, unknown>[];
32
- }
33
- }
34
- return [];
35
- }
36
-
37
- export class ComputerPorts {
38
- constructor(
39
- private readonly http: HttpClient,
40
- private readonly computerId: string,
41
- ) {}
42
-
43
- private base(): string {
44
- return `/computers/${this.computerId}/ports`;
45
- }
46
-
47
- async list(): Promise<Record<string, unknown>[]> {
48
- return unwrapList(await this.http.get<unknown>(this.base()));
49
- }
50
-
51
- /** Return the port record for port, or null if not exposed. */
52
- async get(port: number): Promise<Record<string, unknown> | null> {
53
- const all = await this.list();
54
- return (
55
- all.find((r) => Number((r as Record<string, unknown>).port) === port) ??
56
- null
57
- );
58
- }
59
-
60
- /** Expose port with the given visibility options. */
61
- async create(
62
- port: number,
63
- opts: Record<string, unknown> = {},
64
- ): Promise<Record<string, unknown>> {
65
- const body = {
66
- port,
67
- ...Object.fromEntries(
68
- Object.entries(opts).filter(([, v]) => v !== undefined),
69
- ),
70
- };
71
- return unwrap(await this.http.post<unknown>(this.base(), body));
72
- }
73
-
74
- /** Patch visibility / auth options for port. */
75
- async update(
76
- port: number,
77
- opts: Record<string, unknown>,
78
- ): Promise<Record<string, unknown>> {
79
- const body = Object.fromEntries(
80
- Object.entries(opts).filter(([, v]) => v !== undefined),
81
- );
82
- return unwrap(
83
- await this.http.patch<unknown>(`${this.base()}/${port}`, body),
84
- );
85
- }
86
-
87
- /** Stop exposing port. */
88
- async delete(port: number): Promise<void> {
89
- await this.http.delete(`${this.base()}/${port}`);
90
- }
91
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * ComputerTerminal — PTY session management for a Computer.
3
- *
4
- * Routes:
5
- * POST /computers/:id/terminal
6
- * POST /computers/:id/pty/:sessionId/resize
7
- */
8
-
9
- import type { HttpClient } from "../http.js";
10
-
11
- export interface TerminalCreateParams {
12
- cols?: number;
13
- rows?: number;
14
- shell?: string;
15
- cwd?: string;
16
- env?: Record<string, string>;
17
- }
18
-
19
- export class ComputerTerminal {
20
- constructor(
21
- private readonly http: HttpClient,
22
- private readonly computerId: string,
23
- ) {}
24
-
25
- /** Open a new PTY session. Returns the server payload (session id, etc.). */
26
- async create(
27
- params: TerminalCreateParams = {},
28
- ): Promise<Record<string, unknown>> {
29
- const body = Object.fromEntries(
30
- Object.entries(params).filter(([, v]) => v !== undefined),
31
- );
32
- const raw = await this.http.post<unknown>(
33
- `/computers/${this.computerId}/terminal`,
34
- body,
35
- );
36
- return unwrap(raw);
37
- }
38
-
39
- /** Resize an existing PTY session. */
40
- async resize(
41
- sessionId: string,
42
- cols: number,
43
- rows: number,
44
- ): Promise<Record<string, unknown>> {
45
- const raw = await this.http.post<unknown>(
46
- `/computers/${this.computerId}/pty/${sessionId}/resize`,
47
- { cols, rows },
48
- );
49
- return unwrap(raw);
50
- }
51
- }
52
-
53
- function unwrap(data: unknown): Record<string, unknown> {
54
- if (data && typeof data === "object") {
55
- const d = data as Record<string, unknown>;
56
- if ("data" in d && Object.keys(d).length <= 2) {
57
- return d.data as Record<string, unknown>;
58
- }
59
- }
60
- return (data ?? {}) as Record<string, unknown>;
61
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * ComputerVolumes — per-computer volume attachment.
3
- *
4
- * Routes:
5
- * GET /computers/:id/volumes — list attachments
6
- * POST /computers/:id/volumes — attach a volume
7
- * DELETE /computers/:id/volumes/:aid — detach an attachment
8
- */
9
-
10
- import type { HttpClient } from "../http.js";
11
-
12
- function unwrap(data: unknown): Record<string, unknown> {
13
- if (data && typeof data === "object") {
14
- const d = data as Record<string, unknown>;
15
- if ("data" in d && Object.keys(d).length <= 2) {
16
- return d.data as Record<string, unknown>;
17
- }
18
- }
19
- return (data ?? {}) as Record<string, unknown>;
20
- }
21
-
22
- function unwrapList(data: unknown): Record<string, unknown>[] {
23
- if (Array.isArray(data)) return data as Record<string, unknown>[];
24
- if (data && typeof data === "object") {
25
- const d = data as Record<string, unknown>;
26
- for (const k of ["data", "attachments", "volumes", "items"]) {
27
- if (Array.isArray(d[k])) return d[k] as Record<string, unknown>[];
28
- }
29
- }
30
- return [];
31
- }
32
-
33
- export class ComputerVolumes {
34
- constructor(
35
- private readonly http: HttpClient,
36
- private readonly computerId: string,
37
- ) {}
38
-
39
- private base(): string {
40
- return `/computers/${this.computerId}/volumes`;
41
- }
42
-
43
- async list(): Promise<Record<string, unknown>[]> {
44
- return unwrapList(await this.http.get<unknown>(this.base()));
45
- }
46
-
47
- /** Attach volumeId at mountPath inside the VM. */
48
- async attach(
49
- volumeId: string,
50
- mountPath: string,
51
- ): Promise<Record<string, unknown>> {
52
- return unwrap(
53
- await this.http.post<unknown>(this.base(), {
54
- volume_id: volumeId,
55
- mount_path: mountPath,
56
- }),
57
- );
58
- }
59
-
60
- /** Detach an existing attachment by attachment id. */
61
- async detach(attachmentId: string): Promise<void> {
62
- await this.http.delete(`${this.base()}/${attachmentId}`);
63
- }
64
- }