@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,348 @@
1
+ import type { HttpClient } from "../http.js";
2
+
3
+ type Json = Record<string, unknown>;
4
+ type Query = Record<string, string | number | boolean | undefined>;
5
+
6
+ function withDefined<T extends Record<string, unknown>>(obj: T): Partial<T> {
7
+ const out: Record<string, unknown> = {};
8
+ for (const [k, v] of Object.entries(obj)) {
9
+ if (v !== undefined && v !== null) out[k] = v;
10
+ }
11
+ return out as Partial<T>;
12
+ }
13
+
14
+ export interface ListAdminUsersParams {
15
+ limit?: number;
16
+ cursor?: string;
17
+ q?: string;
18
+ status?: "active" | "suspended" | "deleted";
19
+ }
20
+
21
+ export interface ListAdminTenantsParams {
22
+ limit?: number;
23
+ cursor?: string;
24
+ q?: string;
25
+ }
26
+
27
+ export interface ListAdminComputersParams {
28
+ limit?: number;
29
+ cursor?: string;
30
+ status?:
31
+ | "creating"
32
+ | "provisioning"
33
+ | "running"
34
+ | "stopped"
35
+ | "paused"
36
+ | "error";
37
+ tenantId?: string;
38
+ }
39
+
40
+ export interface ListAdminApiKeysParams {
41
+ limit?: number;
42
+ cursor?: string;
43
+ tenantId?: string;
44
+ status?: "active" | "revoked" | "expired";
45
+ }
46
+
47
+ export interface CreateAdminApiKeyParams {
48
+ name: string;
49
+ tenantId: string;
50
+ userId: string;
51
+ keyType?: "user" | "admin" | "platform";
52
+ purpose?: "api" | "optimal";
53
+ rateLimitRpm?: number;
54
+ expiresAt?: string;
55
+ allowedIps?: string[];
56
+ }
57
+
58
+ export interface BulkUserActionParams {
59
+ userIds: string[];
60
+ action: "suspend" | "unsuspend" | "delete" | "tag" | "notify";
61
+ params?: Json;
62
+ }
63
+
64
+ /**
65
+ * Admin surface — `/api/v1/admin/*` endpoints.
66
+ *
67
+ * Requires a `msk_a_*` or `msk_p_*` API key, or an admin JWT. Calls from
68
+ * a user-role credential return 403 Forbidden.
69
+ */
70
+ export class Admin {
71
+ private readonly http: HttpClient;
72
+
73
+ constructor(http: HttpClient) {
74
+ this.http = http;
75
+ }
76
+
77
+ /** Escape hatch — call any admin endpoint by method + path. */
78
+ async request<T = Json>(
79
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE",
80
+ path: string,
81
+ body?: unknown,
82
+ query?: Query,
83
+ ): Promise<T> {
84
+ const fullPath = query
85
+ ? (() => {
86
+ const qs = new URLSearchParams();
87
+ for (const [k, v] of Object.entries(query)) {
88
+ if (v !== undefined) qs.set(k, String(v));
89
+ }
90
+ const s = qs.toString();
91
+ return s ? `${path}?${s}` : path;
92
+ })()
93
+ : path;
94
+ // Route via the low-level method helpers so retries/backoff still apply.
95
+ switch (method) {
96
+ case "GET":
97
+ return this.http.get<T>(fullPath);
98
+ case "POST":
99
+ return this.http.post<T>(fullPath, body);
100
+ case "PUT":
101
+ return this.http.put<T>(fullPath, body);
102
+ case "PATCH":
103
+ return this.http.patch<T>(fullPath, body);
104
+ case "DELETE":
105
+ return this.http.delete<T>(fullPath, body);
106
+ }
107
+ }
108
+
109
+ // ── Overview ────────────────────────────────────────────────
110
+
111
+ dashboard(): Promise<Json> {
112
+ return this.http.get("/admin/dashboard");
113
+ }
114
+ stats(): Promise<Json> {
115
+ return this.http.get("/admin/stats");
116
+ }
117
+ auditLog(params?: { limit?: number; cursor?: string }): Promise<Json> {
118
+ return this.http.get("/admin/audit-log", {
119
+ limit: params?.limit,
120
+ cursor: params?.cursor,
121
+ });
122
+ }
123
+ detailedHealth(): Promise<Json> {
124
+ return this.http.get("/admin/health/detailed");
125
+ }
126
+
127
+ // ── Credits ─────────────────────────────────────────────────
128
+
129
+ grantCredits(params: {
130
+ tenantId: string;
131
+ amount: number;
132
+ description: string;
133
+ expiresAt?: string;
134
+ }): Promise<Json> {
135
+ return this.http.post(
136
+ "/admin/credits/grant",
137
+ withDefined({
138
+ tenant_id: params.tenantId,
139
+ amount: params.amount,
140
+ description: params.description,
141
+ expires_at: params.expiresAt,
142
+ }),
143
+ );
144
+ }
145
+ deductCredits(params: {
146
+ tenantId: string;
147
+ amount: number;
148
+ description: string;
149
+ }): Promise<Json> {
150
+ return this.http.post("/admin/credits/deduct", {
151
+ tenant_id: params.tenantId,
152
+ amount: params.amount,
153
+ description: params.description,
154
+ });
155
+ }
156
+ refundCredits(params: {
157
+ tenantId: string;
158
+ amount: number;
159
+ description: string;
160
+ transactionId?: string;
161
+ }): Promise<Json> {
162
+ return this.http.post(
163
+ "/admin/credits/refund",
164
+ withDefined({
165
+ tenant_id: params.tenantId,
166
+ amount: params.amount,
167
+ description: params.description,
168
+ transaction_id: params.transactionId,
169
+ }),
170
+ );
171
+ }
172
+ tenantBalance(tenantId: string): Promise<Json> {
173
+ return this.http.get(`/admin/credits/${tenantId}/balance`);
174
+ }
175
+ tenantCreditHistory(
176
+ tenantId: string,
177
+ params?: { limit?: number; cursor?: string },
178
+ ): Promise<Json> {
179
+ return this.http.get(`/admin/credits/${tenantId}/history`, {
180
+ limit: params?.limit,
181
+ cursor: params?.cursor,
182
+ });
183
+ }
184
+
185
+ // ── Users ───────────────────────────────────────────────────
186
+
187
+ listUsers(params?: ListAdminUsersParams): Promise<Json> {
188
+ return this.http.get("/admin/users", {
189
+ limit: params?.limit,
190
+ cursor: params?.cursor,
191
+ q: params?.q,
192
+ status: params?.status,
193
+ });
194
+ }
195
+ getUser(userId: string): Promise<Json> {
196
+ return this.http.get(`/admin/users/${userId}`);
197
+ }
198
+ updateUser(userId: string, attrs: Json): Promise<Json> {
199
+ return this.http.put(`/admin/users/${userId}`, attrs);
200
+ }
201
+ deleteUser(userId: string): Promise<Json> {
202
+ return this.http.delete(`/admin/users/${userId}`);
203
+ }
204
+ changeUserRole(
205
+ userId: string,
206
+ role: "user" | "admin" | "owner" | "super_admin",
207
+ ): Promise<Json> {
208
+ return this.http.post(`/admin/users/${userId}/role`, { role });
209
+ }
210
+ forceLogout(userId: string): Promise<Json> {
211
+ return this.http.post(`/admin/users/${userId}/force-logout`);
212
+ }
213
+ suspendUser(userId: string, reason?: string): Promise<Json> {
214
+ return this.http.post(
215
+ `/admin/users/${userId}/suspend`,
216
+ reason ? { reason } : undefined,
217
+ );
218
+ }
219
+ unsuspendUser(userId: string): Promise<Json> {
220
+ return this.http.post(`/admin/users/${userId}/unsuspend`);
221
+ }
222
+ banUser(userId: string, reason: string, expiresAt?: string): Promise<Json> {
223
+ return this.http.post(
224
+ `/admin/users/${userId}/ban`,
225
+ withDefined({ reason, expires_at: expiresAt }),
226
+ );
227
+ }
228
+ unbanUser(userId: string): Promise<Json> {
229
+ return this.http.post(`/admin/users/${userId}/unban`);
230
+ }
231
+ bulkUserAction(params: BulkUserActionParams): Promise<Json> {
232
+ return this.http.post(
233
+ "/admin/users/bulk",
234
+ withDefined({
235
+ user_ids: params.userIds,
236
+ action: params.action,
237
+ params: params.params,
238
+ }),
239
+ );
240
+ }
241
+
242
+ // ── Tenants ─────────────────────────────────────────────────
243
+
244
+ listTenants(params?: ListAdminTenantsParams): Promise<Json> {
245
+ return this.http.get("/admin/tenants", {
246
+ limit: params?.limit,
247
+ cursor: params?.cursor,
248
+ q: params?.q,
249
+ });
250
+ }
251
+ tenantDetail(tenantId: string): Promise<Json> {
252
+ return this.http.get(`/admin/tenants/${tenantId}/detail`);
253
+ }
254
+ suspendTenant(tenantId: string, reason?: string): Promise<Json> {
255
+ return this.http.post(
256
+ `/admin/tenants/${tenantId}/suspend`,
257
+ reason ? { reason } : undefined,
258
+ );
259
+ }
260
+ unsuspendTenant(tenantId: string): Promise<Json> {
261
+ return this.http.post(`/admin/tenants/${tenantId}/unsuspend`);
262
+ }
263
+ changeTenantPlan(
264
+ tenantId: string,
265
+ plan: "free" | "starter" | "pro" | "scale",
266
+ prorate = true,
267
+ ): Promise<Json> {
268
+ return this.http.post(`/admin/tenants/${tenantId}/plan`, { plan, prorate });
269
+ }
270
+ deleteTenant(tenantId: string): Promise<Json> {
271
+ return this.http.delete(`/admin/tenants/${tenantId}`);
272
+ }
273
+
274
+ // ── Computers ───────────────────────────────────────────────
275
+
276
+ listComputers(params?: ListAdminComputersParams): Promise<Json> {
277
+ return this.http.get("/admin/computers", {
278
+ limit: params?.limit,
279
+ cursor: params?.cursor,
280
+ status: params?.status,
281
+ tenant_id: params?.tenantId,
282
+ });
283
+ }
284
+ deleteComputer(computerId: string): Promise<Json> {
285
+ return this.http.delete(`/admin/computers/${computerId}`);
286
+ }
287
+ suspendComputer(computerId: string): Promise<Json> {
288
+ return this.http.post(`/admin/computers/${computerId}/suspend`);
289
+ }
290
+ resumeComputer(computerId: string): Promise<Json> {
291
+ return this.http.post(`/admin/computers/${computerId}/resume`);
292
+ }
293
+ restartComputer(computerId: string): Promise<Json> {
294
+ return this.http.post(`/admin/computers/${computerId}/restart`);
295
+ }
296
+ purgeStaleComputers(): Promise<Json> {
297
+ return this.http.post("/admin/computers/purge-stale");
298
+ }
299
+
300
+ // ── API Keys ────────────────────────────────────────────────
301
+
302
+ listApiKeys(params?: ListAdminApiKeysParams): Promise<Json> {
303
+ return this.http.get("/admin/api-keys", {
304
+ limit: params?.limit,
305
+ cursor: params?.cursor,
306
+ tenant_id: params?.tenantId,
307
+ status: params?.status,
308
+ });
309
+ }
310
+ createApiKey(params: CreateAdminApiKeyParams): Promise<Json> {
311
+ return this.http.post(
312
+ "/admin/api-keys",
313
+ withDefined({
314
+ name: params.name,
315
+ tenant_id: params.tenantId,
316
+ user_id: params.userId,
317
+ key_type: params.keyType ?? "user",
318
+ purpose: params.purpose ?? "api",
319
+ rate_limit_rpm: params.rateLimitRpm,
320
+ expires_at: params.expiresAt,
321
+ allowed_ips: params.allowedIps,
322
+ }),
323
+ );
324
+ }
325
+ apiKeyStats(): Promise<Json> {
326
+ return this.http.get("/admin/api-keys/stats");
327
+ }
328
+ bulkRevokeApiKeys(keyIds: string[]): Promise<Json> {
329
+ return this.http.post("/admin/api-keys/bulk-revoke", { key_ids: keyIds });
330
+ }
331
+ revokeApiKey(keyId: string): Promise<Json> {
332
+ return this.http.delete(`/admin/api-keys/${keyId}`);
333
+ }
334
+
335
+ // ── Optimal ─────────────────────────────────────────────────
336
+
337
+ optimalStatus(): Promise<Json> {
338
+ return this.http.get("/admin/optimal/status");
339
+ }
340
+ listOptimalModels(): Promise<Json> {
341
+ return this.http.get("/admin/optimal/models");
342
+ }
343
+ switchOptimalModel(modelId: string): Promise<Json> {
344
+ return this.http.post("/admin/optimal/models/switch", {
345
+ model_id: modelId,
346
+ });
347
+ }
348
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Analytics — overview + timeseries (admin scope).
3
+ */
4
+
5
+ import type { HttpClient } from "../http.js";
6
+
7
+ // ── Request payloads ─────────────────────────────────────────────────────────
8
+
9
+ export interface AnalyticsFilters {
10
+ [key: string]: string | number | boolean | undefined;
11
+ }
12
+
13
+ export interface TimeseriesParams extends AnalyticsFilters {
14
+ metric?: string;
15
+ period?: string;
16
+ }
17
+
18
+ // ── Helpers ───────────────────────────────────────────────────────────────────
19
+
20
+ function unwrap<T>(payload: unknown): T {
21
+ if (payload && typeof payload === "object") {
22
+ const p = payload as Record<string, unknown>;
23
+ for (const k of ["data", "analytics", "series", "items"]) {
24
+ if (k in p) return p[k] as T;
25
+ }
26
+ }
27
+ return payload as T;
28
+ }
29
+
30
+ function stripUndefined(
31
+ input: Record<string, unknown>,
32
+ ): Record<string, string | number | boolean | undefined> {
33
+ return Object.fromEntries(
34
+ Object.entries(input).filter(([, v]) => v !== undefined),
35
+ ) as Record<string, string | number | boolean | undefined>;
36
+ }
37
+
38
+ // ── Main resource ─────────────────────────────────────────────────────────────
39
+
40
+ export class Analytics {
41
+ constructor(private readonly http: HttpClient) {}
42
+
43
+ /** Get the platform analytics overview. */
44
+ async overview(
45
+ filters: AnalyticsFilters = {},
46
+ ): Promise<Record<string, unknown>> {
47
+ const query = stripUndefined(filters as Record<string, unknown>);
48
+ const data = await this.http.get<unknown>("/analytics/overview", query);
49
+ return unwrap<Record<string, unknown>>(data);
50
+ }
51
+
52
+ /** Get a timeseries for a metric over a period. */
53
+ async timeseries(
54
+ params: TimeseriesParams = {},
55
+ ): Promise<Record<string, unknown>> {
56
+ const query = stripUndefined(params as Record<string, unknown>);
57
+ const data = await this.http.get<unknown>("/analytics/timeseries", query);
58
+ return unwrap<Record<string, unknown>>(data);
59
+ }
60
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * ApiKeys resource — programmatic API key management.
3
+ *
4
+ * The plaintext key is returned ONLY at create time. Store it immediately;
5
+ * the server only keeps a hash.
6
+ */
7
+
8
+ import { randomUUID } from "node:crypto";
9
+
10
+ import type { HttpClient } from "../http.js";
11
+
12
+ // ── Branded IDs ──────────────────────────────────────────────────────────────
13
+
14
+ export type ApiKeyId = string & { readonly __brand: "ApiKeyId" };
15
+
16
+ // ── Resource shapes ──────────────────────────────────────────────────────────
17
+
18
+ export interface ApiKeyData {
19
+ id: ApiKeyId;
20
+ tenant_id: string;
21
+ name: string;
22
+ prefix?: string;
23
+ scopes?: string[];
24
+ expires_at?: string | null;
25
+ last_used_at?: string | null;
26
+ created_at?: string;
27
+ [key: string]: unknown;
28
+ }
29
+
30
+ export interface ApiKeyCreateResult extends ApiKeyData {
31
+ /** One-time plaintext key. Store immediately. */
32
+ token?: string;
33
+ key?: string;
34
+ }
35
+
36
+ // ── Request payloads ─────────────────────────────────────────────────────────
37
+
38
+ export interface ApiKeyListParams {
39
+ limit?: number;
40
+ cursor?: string;
41
+ [key: string]: string | number | boolean | undefined;
42
+ }
43
+
44
+ export interface ApiKeyCreateParams {
45
+ name: string;
46
+ scopes?: string[];
47
+ expires_at?: string;
48
+ expiresAt?: string;
49
+ idempotencyKey?: string;
50
+ [key: string]: unknown;
51
+ }
52
+
53
+ // ── Helpers ───────────────────────────────────────────────────────────────────
54
+
55
+ function unwrap<T>(payload: unknown): T {
56
+ if (payload && typeof payload === "object" && "data" in (payload as object)) {
57
+ return (payload as { data: T }).data;
58
+ }
59
+ return payload as T;
60
+ }
61
+
62
+ function listItems<T>(
63
+ payload: unknown,
64
+ candidateKeys: string[] = ["data", "keys", "api_keys", "items"],
65
+ ): T[] {
66
+ if (Array.isArray(payload)) return payload;
67
+ if (!payload || typeof payload !== "object") return [];
68
+ const p = payload as Record<string, unknown>;
69
+ if (Array.isArray(p.data)) return p.data as T[];
70
+ for (const key of candidateKeys) {
71
+ if (Array.isArray(p[key])) return p[key] as T[];
72
+ }
73
+ return [];
74
+ }
75
+
76
+ function stripUndefined(
77
+ input: Record<string, unknown>,
78
+ ): Record<string, unknown> {
79
+ return Object.fromEntries(
80
+ Object.entries(input).filter(([, v]) => v !== undefined),
81
+ );
82
+ }
83
+
84
+ function idempotencyKey(key?: string): string {
85
+ return key ?? randomUUID();
86
+ }
87
+
88
+ // ── Main resource ─────────────────────────────────────────────────────────────
89
+
90
+ export class ApiKeys {
91
+ constructor(private readonly http: HttpClient) {}
92
+
93
+ async list(params: ApiKeyListParams = {}): Promise<ApiKeyData[]> {
94
+ const query = stripUndefined({ ...params }) as Record<
95
+ string,
96
+ string | number | boolean | undefined
97
+ >;
98
+ const data = await this.http.get<unknown>("/api-keys", query);
99
+ return listItems<ApiKeyData>(data);
100
+ }
101
+
102
+ async create(params: ApiKeyCreateParams): Promise<ApiKeyCreateResult> {
103
+ const { idempotencyKey: ikey, expiresAt, ...rest } = params;
104
+ const body = stripUndefined({
105
+ ...rest,
106
+ expires_at: expiresAt ?? rest.expires_at,
107
+ });
108
+ const data = await this.http.request<unknown>("/api-keys", {
109
+ method: "POST",
110
+ body,
111
+ headers: { "Idempotency-Key": idempotencyKey(ikey) },
112
+ });
113
+ return unwrap<ApiKeyCreateResult>(data);
114
+ }
115
+
116
+ async delete(keyId: string): Promise<void> {
117
+ await this.http.delete<unknown>(`/api-keys/${keyId}`);
118
+ }
119
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Audit log — admin-scoped event history.
3
+ */
4
+
5
+ import type { HttpClient } from "../http.js";
6
+
7
+ // ── Resource shapes ──────────────────────────────────────────────────────────
8
+
9
+ export interface AuditLogEvent {
10
+ id?: string;
11
+ action?: string;
12
+ actor_id?: string;
13
+ resource_type?: string;
14
+ resource_id?: string;
15
+ metadata?: Record<string, unknown>;
16
+ inserted_at?: string;
17
+ [key: string]: unknown;
18
+ }
19
+
20
+ // ── Request payloads ─────────────────────────────────────────────────────────
21
+
22
+ export interface AuditLogListParams {
23
+ action?: string;
24
+ actor_id?: string;
25
+ resource_type?: string;
26
+ limit?: number;
27
+ cursor?: string;
28
+ [key: string]: string | number | boolean | undefined;
29
+ }
30
+
31
+ // ── Helpers ───────────────────────────────────────────────────────────────────
32
+
33
+ function unwrap<T>(payload: unknown): T {
34
+ if (payload && typeof payload === "object") {
35
+ const p = payload as Record<string, unknown>;
36
+ for (const k of ["data", "audit_log", "events", "items"]) {
37
+ if (k in p) return p[k] as T;
38
+ }
39
+ }
40
+ return payload as T;
41
+ }
42
+
43
+ function stripUndefined(
44
+ input: Record<string, unknown>,
45
+ ): Record<string, string | number | boolean | undefined> {
46
+ return Object.fromEntries(
47
+ Object.entries(input).filter(([, v]) => v !== undefined),
48
+ ) as Record<string, string | number | boolean | undefined>;
49
+ }
50
+
51
+ // ── Main resource ─────────────────────────────────────────────────────────────
52
+
53
+ export class AuditLog {
54
+ constructor(private readonly http: HttpClient) {}
55
+
56
+ /** List audit-log events with optional filters. */
57
+ async list(params: AuditLogListParams = {}): Promise<AuditLogEvent[]> {
58
+ const query = stripUndefined(params as Record<string, unknown>);
59
+ const data = await this.http.get<unknown>("/audit-log", query);
60
+ const result = unwrap<AuditLogEvent[] | unknown>(data);
61
+ if (Array.isArray(result)) return result;
62
+ return [];
63
+ }
64
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Benchmarks — admin-triggered platform benchmark runs.
3
+ *
4
+ * Routes: /admin/benchmarks/*
5
+ * Requires admin credential (msk_a_* / msk_p_* or admin JWT).
6
+ * Available kinds: cold_boot, fleet_routing, concurrent_create, full_e2e.
7
+ */
8
+
9
+ import type { HttpClient } from "../http.js";
10
+
11
+ export interface BenchmarkCreateParams {
12
+ kind: string;
13
+ [key: string]: unknown;
14
+ }
15
+
16
+ export interface BenchmarkCompareParams {
17
+ left_id: string;
18
+ right_id: string;
19
+ [key: string]: unknown;
20
+ }
21
+
22
+ function unwrap(data: unknown): Record<string, unknown> {
23
+ if (data && typeof data === "object") {
24
+ const d = data as Record<string, unknown>;
25
+ for (const k of ["data", "benchmarks", "samples", "items"]) {
26
+ if (k in d) return d[k] as Record<string, unknown>;
27
+ }
28
+ }
29
+ return data as Record<string, unknown>;
30
+ }
31
+
32
+ function unwrapList(data: unknown): Record<string, unknown>[] {
33
+ if (Array.isArray(data)) return data as Record<string, unknown>[];
34
+ if (data && typeof data === "object") {
35
+ const d = data as Record<string, unknown>;
36
+ for (const k of ["data", "benchmarks", "samples", "items"]) {
37
+ if (Array.isArray(d[k])) return d[k] as Record<string, unknown>[];
38
+ }
39
+ }
40
+ return [];
41
+ }
42
+
43
+ export class Benchmarks {
44
+ constructor(private readonly http: HttpClient) {}
45
+
46
+ async list(
47
+ filters: Record<string, string | number | boolean | undefined> = {},
48
+ ): Promise<Record<string, unknown>[]> {
49
+ const query = Object.fromEntries(
50
+ Object.entries(filters).filter(([, v]) => v !== undefined),
51
+ ) as Record<string, string | number | boolean | undefined>;
52
+ const data = await this.http.get<unknown>("/admin/benchmarks", query);
53
+ return unwrapList(data);
54
+ }
55
+
56
+ async get(benchmarkId: string): Promise<Record<string, unknown>> {
57
+ return unwrap(
58
+ await this.http.get<unknown>(`/admin/benchmarks/${benchmarkId}`),
59
+ );
60
+ }
61
+
62
+ /** Start a new benchmark run — pass kind and run-specific options. */
63
+ async create(
64
+ params: BenchmarkCreateParams,
65
+ ): Promise<Record<string, unknown>> {
66
+ const body = Object.fromEntries(
67
+ Object.entries(params).filter(([, v]) => v !== undefined),
68
+ );
69
+ return unwrap(await this.http.post<unknown>("/admin/benchmarks", body));
70
+ }
71
+
72
+ async cancel(benchmarkId: string): Promise<Record<string, unknown>> {
73
+ return unwrap(
74
+ await this.http.post<unknown>(`/admin/benchmarks/${benchmarkId}/cancel`),
75
+ );
76
+ }
77
+
78
+ /** Return per-iteration timing samples for a benchmark run. */
79
+ async samples(
80
+ benchmarkId: string,
81
+ filters: Record<string, string | number | boolean | undefined> = {},
82
+ ): Promise<Record<string, unknown>[]> {
83
+ const query = Object.fromEntries(
84
+ Object.entries(filters).filter(([, v]) => v !== undefined),
85
+ ) as Record<string, string | number | boolean | undefined>;
86
+ const data = await this.http.get<unknown>(
87
+ `/admin/benchmarks/${benchmarkId}/samples`,
88
+ query,
89
+ );
90
+ return unwrapList(data);
91
+ }
92
+
93
+ /** Compare two benchmark runs. */
94
+ async compare(
95
+ params: BenchmarkCompareParams,
96
+ ): Promise<Record<string, unknown>> {
97
+ const body = Object.fromEntries(
98
+ Object.entries(params).filter(([, v]) => v !== undefined),
99
+ );
100
+ return unwrap(
101
+ await this.http.post<unknown>("/admin/benchmarks/compare", body),
102
+ );
103
+ }
104
+ }