@miosa/sdk 1.2.5 → 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.
- package/README.md +107 -59
- package/dist/index.d.ts +331 -202
- package/dist/index.js +572 -603
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
- package/src/client.ts +0 -293
- package/src/errors.ts +0 -136
- package/src/http.test.ts +0 -374
- package/src/http.ts +0 -390
- package/src/index.ts +0 -569
- package/src/resources/admin.ts +0 -348
- package/src/resources/analytics.ts +0 -60
- package/src/resources/api-keys.ts +0 -119
- package/src/resources/audit-log.ts +0 -64
- package/src/resources/benchmarks.ts +0 -104
- package/src/resources/builder-sessions.ts +0 -75
- package/src/resources/channels.ts +0 -143
- package/src/resources/checkpoints.ts +0 -225
- package/src/resources/command-center.ts +0 -73
- package/src/resources/community.ts +0 -103
- package/src/resources/completions.ts +0 -104
- package/src/resources/computer-auto-stop.ts +0 -43
- package/src/resources/computer-env.ts +0 -76
- package/src/resources/computer-logs.ts +0 -50
- package/src/resources/computer-osa.ts +0 -76
- package/src/resources/computer-ports.ts +0 -91
- package/src/resources/computer-terminal.ts +0 -61
- package/src/resources/computer-volumes.ts +0 -64
- package/src/resources/computer.ts +0 -551
- package/src/resources/computers.ts +0 -75
- package/src/resources/credits.ts +0 -43
- package/src/resources/cron-jobs.ts +0 -191
- package/src/resources/custom_domains.ts +0 -123
- package/src/resources/dashboard.ts +0 -49
- package/src/resources/databases.ts +0 -218
- package/src/resources/deployments.test.ts +0 -197
- package/src/resources/deployments.ts +0 -1208
- package/src/resources/desktop.ts +0 -134
- package/src/resources/devices.test.ts +0 -92
- package/src/resources/devices.ts +0 -291
- package/src/resources/egress.test.ts +0 -318
- package/src/resources/egressAudit.ts +0 -245
- package/src/resources/egressNetwork.ts +0 -450
- package/src/resources/egressSecrets.ts +0 -577
- package/src/resources/email.ts +0 -212
- package/src/resources/embeddings.ts +0 -36
- package/src/resources/events.ts +0 -296
- package/src/resources/exec.ts +0 -319
- package/src/resources/external-keys.ts +0 -79
- package/src/resources/files.test.ts +0 -339
- package/src/resources/files.ts +0 -220
- package/src/resources/flat-custom-domains.ts +0 -127
- package/src/resources/functions.ts +0 -178
- package/src/resources/health-checks.ts +0 -165
- package/src/resources/integrations.ts +0 -183
- package/src/resources/mcp.ts +0 -70
- package/src/resources/models.ts +0 -45
- package/src/resources/network_policy.ts +0 -73
- package/src/resources/open-computers/agents.ts +0 -91
- package/src/resources/open-computers/apps.ts +0 -102
- package/src/resources/open-computers/clusters.ts +0 -88
- package/src/resources/open-computers/desktop.ts +0 -34
- package/src/resources/open-computers/files.ts +0 -97
- package/src/resources/open-computers/hosts.ts +0 -85
- package/src/resources/open-computers/index.ts +0 -98
- package/src/resources/open-computers/jobs.ts +0 -75
- package/src/resources/open-computers/open_computers.test.ts +0 -288
- package/src/resources/open-computers/secrets.ts +0 -115
- package/src/resources/open-computers/terminal.ts +0 -33
- package/src/resources/open-computers/tunnels.ts +0 -87
- package/src/resources/open-computers/types.ts +0 -343
- package/src/resources/open-computers/workspaces.ts +0 -135
- package/src/resources/org-invites.ts +0 -189
- package/src/resources/project-auth.ts +0 -142
- package/src/resources/project-integrations.ts +0 -133
- package/src/resources/provider-defaults.ts +0 -89
- package/src/resources/regions.ts +0 -94
- package/src/resources/sandbox-templates.ts +0 -195
- package/src/resources/sandboxes.live.test.ts +0 -92
- package/src/resources/sandboxes.test.ts +0 -655
- package/src/resources/sandboxes.ts +0 -1437
- package/src/resources/settings.ts +0 -143
- package/src/resources/snapshots-standalone.ts +0 -51
- package/src/resources/storage.ts +0 -221
- package/src/resources/tenant.ts +0 -66
- package/src/resources/usage.ts +0 -85
- package/src/resources/volumes.ts +0 -117
- package/src/resources/webhooks.ts +0 -239
- package/src/resources/workspace-invites.ts +0 -188
- package/src/resources/workspace-members.test.ts +0 -121
- package/src/resources/workspace-members.ts +0 -143
- package/src/types.ts +0 -463
|
@@ -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
|
-
}
|