@miosa/sdk 0.3.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.
Files changed (81) hide show
  1. package/README.md +181 -0
  2. package/dist/index.d.ts +4689 -0
  3. package/dist/index.js +6045 -0
  4. package/dist/index.js.map +1 -0
  5. package/package.json +63 -0
  6. package/src/client.ts +249 -0
  7. package/src/errors.ts +136 -0
  8. package/src/http.test.ts +374 -0
  9. package/src/http.ts +390 -0
  10. package/src/index.ts +452 -0
  11. package/src/resources/admin.ts +348 -0
  12. package/src/resources/analytics.ts +60 -0
  13. package/src/resources/api-keys.ts +119 -0
  14. package/src/resources/audit-log.ts +64 -0
  15. package/src/resources/benchmarks.ts +104 -0
  16. package/src/resources/builder-sessions.ts +75 -0
  17. package/src/resources/channels.ts +143 -0
  18. package/src/resources/checkpoints.ts +225 -0
  19. package/src/resources/command-center.ts +73 -0
  20. package/src/resources/community.ts +103 -0
  21. package/src/resources/completions.ts +104 -0
  22. package/src/resources/computer-auto-stop.ts +43 -0
  23. package/src/resources/computer-env.ts +76 -0
  24. package/src/resources/computer-logs.ts +50 -0
  25. package/src/resources/computer-osa.ts +76 -0
  26. package/src/resources/computer-ports.ts +91 -0
  27. package/src/resources/computer-terminal.ts +61 -0
  28. package/src/resources/computer-volumes.ts +64 -0
  29. package/src/resources/computer.ts +530 -0
  30. package/src/resources/computers.ts +75 -0
  31. package/src/resources/credits.ts +43 -0
  32. package/src/resources/cron-jobs.ts +191 -0
  33. package/src/resources/custom_domains.ts +123 -0
  34. package/src/resources/dashboard.ts +49 -0
  35. package/src/resources/databases.ts +218 -0
  36. package/src/resources/deployments.ts +777 -0
  37. package/src/resources/desktop.ts +134 -0
  38. package/src/resources/email.ts +212 -0
  39. package/src/resources/embeddings.ts +36 -0
  40. package/src/resources/events.ts +296 -0
  41. package/src/resources/exec.ts +319 -0
  42. package/src/resources/external-keys.ts +79 -0
  43. package/src/resources/files.test.ts +339 -0
  44. package/src/resources/files.ts +220 -0
  45. package/src/resources/flat-custom-domains.ts +127 -0
  46. package/src/resources/functions.ts +178 -0
  47. package/src/resources/health-checks.ts +165 -0
  48. package/src/resources/integrations.ts +183 -0
  49. package/src/resources/mcp.ts +70 -0
  50. package/src/resources/models.ts +45 -0
  51. package/src/resources/network_policy.ts +73 -0
  52. package/src/resources/open-computers/agents.ts +91 -0
  53. package/src/resources/open-computers/apps.ts +102 -0
  54. package/src/resources/open-computers/clusters.ts +88 -0
  55. package/src/resources/open-computers/desktop.ts +34 -0
  56. package/src/resources/open-computers/files.ts +97 -0
  57. package/src/resources/open-computers/hosts.ts +85 -0
  58. package/src/resources/open-computers/index.ts +98 -0
  59. package/src/resources/open-computers/jobs.ts +75 -0
  60. package/src/resources/open-computers/open_computers.test.ts +288 -0
  61. package/src/resources/open-computers/secrets.ts +115 -0
  62. package/src/resources/open-computers/terminal.ts +33 -0
  63. package/src/resources/open-computers/tunnels.ts +87 -0
  64. package/src/resources/open-computers/types.ts +343 -0
  65. package/src/resources/open-computers/workspaces.ts +135 -0
  66. package/src/resources/project-auth.ts +142 -0
  67. package/src/resources/project-integrations.ts +133 -0
  68. package/src/resources/provider-defaults.ts +89 -0
  69. package/src/resources/regions.ts +94 -0
  70. package/src/resources/sandbox-templates.ts +195 -0
  71. package/src/resources/sandboxes.live.test.ts +92 -0
  72. package/src/resources/sandboxes.test.ts +624 -0
  73. package/src/resources/sandboxes.ts +1173 -0
  74. package/src/resources/settings.ts +143 -0
  75. package/src/resources/snapshots-standalone.ts +51 -0
  76. package/src/resources/storage.ts +221 -0
  77. package/src/resources/tenant.ts +39 -0
  78. package/src/resources/usage.ts +85 -0
  79. package/src/resources/volumes.ts +117 -0
  80. package/src/resources/webhooks.ts +171 -0
  81. package/src/types.ts +460 -0
@@ -0,0 +1,343 @@
1
+ // ─── OpenComputers shared types ──────────────────────────────────────────────
2
+
3
+ export type HostId = string & { readonly __brand: "HostId" };
4
+ export type JobId = string & { readonly __brand: "JobId" };
5
+ export type TunnelId = string & { readonly __brand: "TunnelId" };
6
+ export type ClusterId = string & { readonly __brand: "ClusterId" };
7
+ export type WorkspaceId = string & { readonly __brand: "WorkspaceId" };
8
+ export type SecretId = string & { readonly __brand: "SecretId" };
9
+
10
+ // ─── Hosts ───────────────────────────────────────────────────────────────────
11
+
12
+ export type HostStatus = "pending" | "online" | "offline" | "error" | "revoked";
13
+
14
+ export interface HostData {
15
+ id: HostId;
16
+ name: string;
17
+ region: string | null;
18
+ status: HostStatus;
19
+ tenant_id: string;
20
+ labels: Record<string, string>;
21
+ /** Present only on create response — treat as write-once. */
22
+ host_key?: string;
23
+ created_at: string;
24
+ updated_at: string;
25
+ }
26
+
27
+ export interface HostCreateParams {
28
+ name: string;
29
+ region?: string;
30
+ labels?: Record<string, string>;
31
+ }
32
+
33
+ export interface HostUpdateParams {
34
+ name?: string;
35
+ labels?: Record<string, string>;
36
+ }
37
+
38
+ export interface HostListResponse {
39
+ data: HostData[];
40
+ meta: { total: number; page: number; per_page: number };
41
+ }
42
+
43
+ export interface HostEvent {
44
+ type: "host_connected" | "host_disconnected" | "host_error" | string;
45
+ host_id: HostId;
46
+ data: unknown;
47
+ timestamp: string;
48
+ }
49
+
50
+ // ─── Jobs (exec on host) ─────────────────────────────────────────────────────
51
+
52
+ export type JobStatus =
53
+ | "queued"
54
+ | "running"
55
+ | "completed"
56
+ | "failed"
57
+ | "cancelled";
58
+
59
+ export interface JobData {
60
+ id: JobId;
61
+ host_id: HostId;
62
+ status: JobStatus;
63
+ command: string;
64
+ args: string[];
65
+ env: string[];
66
+ cwd: string | null;
67
+ exit_code: number | null;
68
+ stdout: string | null;
69
+ stderr: string | null;
70
+ created_at: string;
71
+ updated_at: string;
72
+ completed_at: string | null;
73
+ }
74
+
75
+ export interface JobRunParams {
76
+ command: string;
77
+ args?: string[];
78
+ env?: string[];
79
+ cwd?: string;
80
+ timeout?: number;
81
+ }
82
+
83
+ export interface JobListResponse {
84
+ data: JobData[];
85
+ meta: { total: number; page: number; per_page: number };
86
+ }
87
+
88
+ export type JobEventType =
89
+ | "stdout"
90
+ | "stderr"
91
+ | "exit"
92
+ | "error"
93
+ | "started"
94
+ | "done";
95
+
96
+ export interface JobEvent {
97
+ type: JobEventType;
98
+ job_id: JobId;
99
+ data: string | number | null;
100
+ timestamp: string;
101
+ }
102
+
103
+ // ─── File system ─────────────────────────────────────────────────────────────
104
+
105
+ export interface FsEntry {
106
+ name: string;
107
+ path: string;
108
+ size: number;
109
+ is_dir: boolean;
110
+ modified_at: string;
111
+ }
112
+
113
+ export interface FsStat {
114
+ path: string;
115
+ size: number;
116
+ mode: number;
117
+ is_dir: boolean;
118
+ is_symlink: boolean;
119
+ symlink_target?: string;
120
+ modified_at: string;
121
+ }
122
+
123
+ export interface FsListResponse {
124
+ entries: FsEntry[];
125
+ path: string;
126
+ }
127
+
128
+ // ─── Terminal / Desktop tickets ───────────────────────────────────────────────
129
+
130
+ export interface WsTicket {
131
+ /** Short-lived JWT for WS authentication. */
132
+ ticket: string;
133
+ /** Fully-qualified WS URL to connect to. */
134
+ ws_url: string;
135
+ expires_at: string;
136
+ }
137
+
138
+ // ─── Tunnels ─────────────────────────────────────────────────────────────────
139
+
140
+ export type TunnelAuthMode = "public" | "tenant_only" | "password";
141
+
142
+ export interface TunnelData {
143
+ id: TunnelId;
144
+ host_id: HostId;
145
+ slug: string;
146
+ target_port: number;
147
+ auth_mode: TunnelAuthMode;
148
+ public_url: string;
149
+ enabled: boolean;
150
+ created_at: string;
151
+ updated_at: string;
152
+ }
153
+
154
+ export interface TunnelCreateParams {
155
+ target_port: number;
156
+ auth_mode?: TunnelAuthMode;
157
+ slug?: string;
158
+ }
159
+
160
+ export interface TunnelUpdateParams {
161
+ target_port?: number;
162
+ auth_mode?: TunnelAuthMode;
163
+ enabled?: boolean;
164
+ }
165
+
166
+ export interface TunnelListResponse {
167
+ data: TunnelData[];
168
+ }
169
+
170
+ // ─── Agents ──────────────────────────────────────────────────────────────────
171
+
172
+ export type AgentSessionStatus =
173
+ | "pending"
174
+ | "running"
175
+ | "completed"
176
+ | "failed"
177
+ | "cancelled";
178
+
179
+ export interface OcAgentSessionData {
180
+ id: string;
181
+ host_id: HostId;
182
+ task: string;
183
+ model_id: string | null;
184
+ status: AgentSessionStatus;
185
+ max_turns: number;
186
+ turns_used: number;
187
+ created_at: string;
188
+ updated_at: string;
189
+ completed_at: string | null;
190
+ error: string | null;
191
+ }
192
+
193
+ export interface AgentDispatchParams {
194
+ task: string;
195
+ model_id?: string;
196
+ max_turns?: number;
197
+ context?: Record<string, unknown>;
198
+ }
199
+
200
+ export interface AgentSessionListResponse {
201
+ data: OcAgentSessionData[];
202
+ }
203
+
204
+ export interface AgentEvent {
205
+ type: string;
206
+ session_id: string;
207
+ data: unknown;
208
+ timestamp: string;
209
+ }
210
+
211
+ // ─── Inference Clusters ───────────────────────────────────────────────────────
212
+
213
+ export type ClusterStatus =
214
+ | "provisioning"
215
+ | "active"
216
+ | "stopped"
217
+ | "error"
218
+ | "destroyed";
219
+
220
+ export interface ClusterData {
221
+ id: ClusterId;
222
+ name: string;
223
+ model: string;
224
+ slug: string;
225
+ status: ClusterStatus;
226
+ host_ids: HostId[];
227
+ /** OpenAI-compatible endpoint: POST /inference/{slug}/v1/chat/completions */
228
+ inference_url: string;
229
+ created_at: string;
230
+ updated_at: string;
231
+ }
232
+
233
+ export interface ClusterCreateParams {
234
+ name: string;
235
+ model: string;
236
+ host_ids: string[];
237
+ }
238
+
239
+ export interface ClusterListResponse {
240
+ data: ClusterData[];
241
+ }
242
+
243
+ export interface ClusterEvent {
244
+ type: string;
245
+ cluster_id: ClusterId;
246
+ data: unknown;
247
+ timestamp: string;
248
+ }
249
+
250
+ // ─── Apps ────────────────────────────────────────────────────────────────────
251
+
252
+ export interface AppCatalogEntry {
253
+ id: string;
254
+ name: string;
255
+ description: string;
256
+ category: string;
257
+ version: string;
258
+ icon_url: string | null;
259
+ }
260
+
261
+ export interface AppInstallData {
262
+ id: string;
263
+ host_id: HostId;
264
+ app_id: string;
265
+ status: "pending" | "installing" | "installed" | "failed" | "uninstalled";
266
+ error: string | null;
267
+ created_at: string;
268
+ updated_at: string;
269
+ }
270
+
271
+ export interface AppInstallEvent {
272
+ type: string;
273
+ install_id: string;
274
+ data: unknown;
275
+ timestamp: string;
276
+ }
277
+
278
+ // ─── Workspaces ───────────────────────────────────────────────────────────────
279
+
280
+ export type OcWorkspaceStatus =
281
+ | "creating"
282
+ | "ready"
283
+ | "running"
284
+ | "stopped"
285
+ | "error";
286
+
287
+ export interface OcWorkspaceData {
288
+ id: WorkspaceId;
289
+ host_id: HostId;
290
+ name: string;
291
+ repo_url: string | null;
292
+ branch: string | null;
293
+ status: OcWorkspaceStatus;
294
+ directory: string;
295
+ created_at: string;
296
+ updated_at: string;
297
+ }
298
+
299
+ export interface OcWorkspaceCreateParams {
300
+ name: string;
301
+ repo_url?: string;
302
+ branch?: string;
303
+ directory?: string;
304
+ }
305
+
306
+ export interface OcWorkspaceUpdateParams {
307
+ name?: string;
308
+ branch?: string;
309
+ }
310
+
311
+ export interface OcWorkspaceListResponse {
312
+ data: OcWorkspaceData[];
313
+ }
314
+
315
+ export interface OcWorkspaceEvent {
316
+ type: string;
317
+ workspace_id: WorkspaceId;
318
+ data: unknown;
319
+ timestamp: string;
320
+ }
321
+
322
+ // ─── Secrets ─────────────────────────────────────────────────────────────────
323
+
324
+ export interface SecretData {
325
+ id: SecretId;
326
+ name: string;
327
+ description: string | null;
328
+ host_id: HostId | null;
329
+ tenant_id: string;
330
+ created_at: string;
331
+ updated_at: string;
332
+ }
333
+
334
+ export interface SecretCreateParams {
335
+ name: string;
336
+ value: string;
337
+ description?: string;
338
+ }
339
+
340
+ export interface SecretUpdateParams {
341
+ value?: string;
342
+ description?: string;
343
+ }
@@ -0,0 +1,135 @@
1
+ import { HttpClient } from "../../http.js";
2
+ import type {
3
+ HostId,
4
+ OcWorkspaceCreateParams,
5
+ OcWorkspaceData,
6
+ OcWorkspaceEvent,
7
+ OcWorkspaceListResponse,
8
+ OcWorkspaceUpdateParams,
9
+ WorkspaceId,
10
+ WsTicket,
11
+ } from "./types.js";
12
+
13
+ /**
14
+ * Workspaces resource — git-backed development environments on a remote host.
15
+ *
16
+ * A workspace clones a repository, installs dependencies, and gives you a
17
+ * ready-to-use terminal scoped to the project root.
18
+ *
19
+ * ```ts
20
+ * const ws = await client.openComputers.workspaces.create(hostId, {
21
+ * name: "my-project",
22
+ * repo_url: "https://github.com/acme/backend",
23
+ * branch: "main",
24
+ * });
25
+ * const { ws_url } = await client.openComputers.workspaces.openTerminal(hostId, ws.id);
26
+ * ```
27
+ */
28
+ export class OcWorkspaces {
29
+ private readonly http: HttpClient;
30
+
31
+ constructor(http: HttpClient) {
32
+ this.http = http;
33
+ }
34
+
35
+ private base(hostId: string): string {
36
+ return `/opencomputers/hosts/${hostId}/workspaces`;
37
+ }
38
+
39
+ /**
40
+ * List all workspaces across all hosts for the tenant.
41
+ */
42
+ async listAll(): Promise<OcWorkspaceListResponse> {
43
+ return this.http.get<OcWorkspaceListResponse>("/opencomputers/workspaces");
44
+ }
45
+
46
+ /**
47
+ * List workspaces on a specific host.
48
+ */
49
+ async list(hostId: HostId | string): Promise<OcWorkspaceListResponse> {
50
+ return this.http.get<OcWorkspaceListResponse>(this.base(hostId));
51
+ }
52
+
53
+ /**
54
+ * Create a new workspace on a host.
55
+ */
56
+ async create(
57
+ hostId: HostId | string,
58
+ params: OcWorkspaceCreateParams,
59
+ ): Promise<OcWorkspaceData> {
60
+ return this.http.post<OcWorkspaceData>(this.base(hostId), params);
61
+ }
62
+
63
+ /**
64
+ * Fetch a single workspace.
65
+ */
66
+ async get(
67
+ hostId: HostId | string,
68
+ workspaceId: WorkspaceId | string,
69
+ ): Promise<OcWorkspaceData> {
70
+ return this.http.get<OcWorkspaceData>(
71
+ `${this.base(hostId)}/${workspaceId}`,
72
+ );
73
+ }
74
+
75
+ /**
76
+ * Update workspace metadata (name, branch).
77
+ */
78
+ async update(
79
+ hostId: HostId | string,
80
+ workspaceId: WorkspaceId | string,
81
+ params: OcWorkspaceUpdateParams,
82
+ ): Promise<OcWorkspaceData> {
83
+ return this.http.patch<OcWorkspaceData>(
84
+ `${this.base(hostId)}/${workspaceId}`,
85
+ params,
86
+ );
87
+ }
88
+
89
+ /**
90
+ * Delete a workspace.
91
+ */
92
+ async delete(
93
+ hostId: HostId | string,
94
+ workspaceId: WorkspaceId | string,
95
+ ): Promise<void> {
96
+ return this.http.delete<void>(`${this.base(hostId)}/${workspaceId}`);
97
+ }
98
+
99
+ /**
100
+ * Pull the latest changes from the remote repository.
101
+ */
102
+ async pull(
103
+ hostId: HostId | string,
104
+ workspaceId: WorkspaceId | string,
105
+ ): Promise<OcWorkspaceData> {
106
+ return this.http.post<OcWorkspaceData>(
107
+ `${this.base(hostId)}/${workspaceId}/pull`,
108
+ );
109
+ }
110
+
111
+ /**
112
+ * Open a terminal session scoped to the workspace root directory.
113
+ * Returns a short-lived WebSocket ticket.
114
+ */
115
+ async openTerminal(
116
+ hostId: HostId | string,
117
+ workspaceId: WorkspaceId | string,
118
+ ): Promise<WsTicket> {
119
+ return this.http.post<WsTicket>(
120
+ `${this.base(hostId)}/${workspaceId}/open-terminal`,
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Stream workspace setup / clone / install events.
126
+ */
127
+ events(
128
+ hostId: HostId | string,
129
+ workspaceId: WorkspaceId | string,
130
+ ): AsyncIterableIterator<OcWorkspaceEvent> {
131
+ return this.http.stream<OcWorkspaceEvent>(
132
+ `${this.base(hostId)}/${workspaceId}/events`,
133
+ );
134
+ }
135
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Project auth — built-in auth for sandboxes and deployments.
3
+ */
4
+
5
+ import type { HttpClient } from "../http.js";
6
+
7
+ // ── Resource shapes ──────────────────────────────────────────────────────────
8
+
9
+ export interface ProjectAuthStatus {
10
+ enabled?: boolean;
11
+ state?: string;
12
+ database_id?: string | null;
13
+ config?: Record<string, unknown>;
14
+ [key: string]: unknown;
15
+ }
16
+
17
+ // ── Request payloads ─────────────────────────────────────────────────────────
18
+
19
+ export type ProjectAuthResourceType = "sandbox" | "deployment";
20
+
21
+ export interface ProjectAuthResourceParams {
22
+ resourceType?: ProjectAuthResourceType;
23
+ resource_type?: ProjectAuthResourceType;
24
+ resourceId?: string;
25
+ resource_id?: string;
26
+ }
27
+
28
+ export interface ProjectAuthEnableParams extends ProjectAuthResourceParams {
29
+ signupEnabled?: boolean;
30
+ signup_enabled?: boolean;
31
+ emailConfirmRequired?: boolean;
32
+ email_confirm_required?: boolean;
33
+ tokenExpirySec?: number;
34
+ token_expiry_sec?: number;
35
+ config?: Record<string, unknown>;
36
+ [key: string]: unknown;
37
+ }
38
+
39
+ export interface ProjectAuthUpdateParams extends ProjectAuthEnableParams {}
40
+
41
+ export interface ProjectAuthDisableParams extends ProjectAuthResourceParams {
42
+ [key: string]: unknown;
43
+ }
44
+
45
+ export interface ProjectAuthStatusParams extends ProjectAuthResourceParams {
46
+ [key: string]: unknown;
47
+ }
48
+
49
+ function resourcePayload(params: ProjectAuthResourceParams): {
50
+ resource_type: ProjectAuthResourceType;
51
+ resource_id: string;
52
+ } {
53
+ const resource_type = params.resource_type ?? params.resourceType;
54
+ const resource_id = params.resource_id ?? params.resourceId;
55
+
56
+ if (!resource_type || !resource_id) {
57
+ throw new Error("project auth requires resourceType/resourceId");
58
+ }
59
+
60
+ return { resource_type, resource_id };
61
+ }
62
+
63
+ function authConfig(params: ProjectAuthEnableParams): Record<string, unknown> {
64
+ return stripUndefined({
65
+ ...(params.config ?? {}),
66
+ signup_enabled: params.signup_enabled ?? params.signupEnabled,
67
+ email_confirm_required:
68
+ params.email_confirm_required ?? params.emailConfirmRequired,
69
+ token_expiry_sec: params.token_expiry_sec ?? params.tokenExpirySec,
70
+ });
71
+ }
72
+
73
+ function requestBody(params: ProjectAuthEnableParams): Record<string, unknown> {
74
+ return stripUndefined({
75
+ ...resourcePayload(params),
76
+ config: authConfig(params),
77
+ });
78
+ }
79
+
80
+ export interface ProjectAuthLegacyParams {
81
+ provider?: string;
82
+ config?: Record<string, unknown>;
83
+ [key: string]: unknown;
84
+ }
85
+
86
+ // ── Helpers ───────────────────────────────────────────────────────────────────
87
+
88
+ function unwrap<T>(payload: unknown): T {
89
+ if (payload && typeof payload === "object") {
90
+ const p = payload as Record<string, unknown>;
91
+ for (const k of ["data", "project_auth", "config", "items"]) {
92
+ if (k in p) return p[k] as T;
93
+ }
94
+ }
95
+ return payload as T;
96
+ }
97
+
98
+ function stripUndefined(
99
+ input: Record<string, unknown>,
100
+ ): Record<string, unknown> {
101
+ return Object.fromEntries(
102
+ Object.entries(input).filter(([, v]) => v !== undefined),
103
+ );
104
+ }
105
+
106
+ // ── Main resource ─────────────────────────────────────────────────────────────
107
+
108
+ export class ProjectAuth {
109
+ constructor(private readonly http: HttpClient) {}
110
+
111
+ /** Get the current project-auth status and config. */
112
+ async status(params: ProjectAuthStatusParams): Promise<ProjectAuthStatus> {
113
+ const data = await this.http.get<unknown>(
114
+ "/project-auth/status",
115
+ resourcePayload(params),
116
+ );
117
+ return unwrap<ProjectAuthStatus>(data);
118
+ }
119
+
120
+ /** Enable project auth. */
121
+ async enable(params: ProjectAuthEnableParams): Promise<ProjectAuthStatus> {
122
+ const body = requestBody(params);
123
+ const data = await this.http.post<unknown>("/project-auth/enable", body);
124
+ return unwrap<ProjectAuthStatus>(data);
125
+ }
126
+
127
+ /** Disable project auth. */
128
+ async disable(params: ProjectAuthDisableParams): Promise<ProjectAuthStatus> {
129
+ const data = await this.http.post<unknown>(
130
+ "/project-auth/disable",
131
+ resourcePayload(params),
132
+ );
133
+ return unwrap<ProjectAuthStatus>(data);
134
+ }
135
+
136
+ /** Update project-auth configuration. */
137
+ async update(params: ProjectAuthUpdateParams): Promise<ProjectAuthStatus> {
138
+ const body = requestBody(params);
139
+ const data = await this.http.patch<unknown>("/project-auth/config", body);
140
+ return unwrap<ProjectAuthStatus>(data);
141
+ }
142
+ }