@celestoai/sdk 0.1.0 → 0.1.2
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 +84 -22
- package/dist/chunk-4KVRJSVJ.js +177 -0
- package/dist/chunk-4KVRJSVJ.js.map +1 -0
- package/dist/chunk-7OJDEZ7J.js +212 -0
- package/dist/chunk-7OJDEZ7J.js.map +1 -0
- package/dist/chunk-N3HU6ONW.js +148 -0
- package/dist/chunk-N3HU6ONW.js.map +1 -0
- package/dist/computers/index.cjs +373 -0
- package/dist/computers/index.cjs.map +1 -0
- package/dist/computers/index.d.cts +131 -0
- package/dist/computers/index.d.ts +131 -0
- package/dist/computers/index.js +8 -0
- package/dist/computers/index.js.map +1 -0
- package/dist/config-BTTpuv_b.d.cts +25 -0
- package/dist/config-BTTpuv_b.d.ts +25 -0
- package/dist/gatekeeper/index.cjs +338 -0
- package/dist/gatekeeper/index.cjs.map +1 -0
- package/dist/gatekeeper/index.d.cts +104 -0
- package/dist/gatekeeper/index.d.ts +104 -0
- package/dist/gatekeeper/index.js +8 -0
- package/dist/gatekeeper/index.js.map +1 -0
- package/dist/index.cjs +559 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/package.json +16 -3
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @celestoai/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use this package to create Celesto computers from Node.js apps. Your code can
|
|
4
|
+
start a computer, run commands in it, and delete it when the work is done.
|
|
5
|
+
|
|
6
|
+
It includes:
|
|
7
|
+
|
|
8
|
+
- **Computers** (`/v1/computers`) — create, manage, and interact with sandboxed virtual machines
|
|
9
|
+
- **Gatekeeper** (`/v1/gatekeeper`) — delegated access to user resources
|
|
4
10
|
|
|
5
11
|
## Install
|
|
6
12
|
|
|
@@ -8,16 +14,84 @@ Node-only TypeScript SDK for Celesto's Gatekeeper API (`/v1/gatekeeper`).
|
|
|
8
14
|
npm install @celestoai/sdk
|
|
9
15
|
```
|
|
10
16
|
|
|
11
|
-
##
|
|
17
|
+
## Quickstart
|
|
12
18
|
|
|
13
19
|
```ts
|
|
14
|
-
import {
|
|
20
|
+
import { Celesto } from "@celestoai/sdk";
|
|
15
21
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
const celesto = new Celesto({
|
|
23
|
+
token: process.env.CELESTO_API_KEY,
|
|
24
|
+
// organizationId: "org_123", // optional, for JWTs with multiple orgs
|
|
19
25
|
});
|
|
20
26
|
|
|
27
|
+
// Computers
|
|
28
|
+
const computer = await celesto.computers.create({ templateId: "coding-agent" });
|
|
29
|
+
const result = await celesto.computers.exec(computer.id, "uname -a");
|
|
30
|
+
console.log(result.stdout);
|
|
31
|
+
await celesto.computers.delete(computer.id);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Computers
|
|
35
|
+
|
|
36
|
+
Templates are ready-made computer setups. Choose one when you want a computer
|
|
37
|
+
that already has the tools your agent needs.
|
|
38
|
+
|
|
39
|
+
### Lifecycle
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const computer = await celesto.computers.create({
|
|
43
|
+
templateId: "coding-agent",
|
|
44
|
+
cpus: 2,
|
|
45
|
+
memory: 2048,
|
|
46
|
+
diskSizeMb: 15360,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await celesto.computers.stop(computer.id);
|
|
50
|
+
await celesto.computers.start(computer.id);
|
|
51
|
+
await celesto.computers.delete(computer.id);
|
|
52
|
+
|
|
53
|
+
const { computers, count } = await celesto.computers.list();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Omit CPU, memory, or disk fields to use the selected template defaults.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const templates = await celesto.computers.listTemplates();
|
|
60
|
+
for (const template of templates) {
|
|
61
|
+
console.log(template.id, template.defaultRamMb);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Running commands
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const result = await celesto.computers.exec(computer.id, "ls -la", { timeout: 60 });
|
|
69
|
+
console.log(result.exitCode, result.stdout, result.stderr);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Terminal connection
|
|
73
|
+
|
|
74
|
+
`getTerminalConnection()` resolves a computer name or ID and returns everything you need
|
|
75
|
+
to open a WebSocket terminal with any library of your choice. No built-in WebSocket
|
|
76
|
+
dependency — bring your own.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const conn = await celesto.computers.getTerminalConnection("my-computer");
|
|
80
|
+
|
|
81
|
+
// Use any WebSocket library (ws, Node 22+ built-in, etc.)
|
|
82
|
+
import WebSocket from "ws";
|
|
83
|
+
const ws = new WebSocket(conn.url, { headers: conn.headers });
|
|
84
|
+
ws.on("open", () => ws.send(conn.firstMessage));
|
|
85
|
+
ws.on("message", (data) => process.stdout.write(data));
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Gatekeeper
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { GatekeeperClient } from "@celestoai/sdk/gatekeeper";
|
|
92
|
+
|
|
93
|
+
const client = new GatekeeperClient({ token: process.env.CELESTO_API_KEY });
|
|
94
|
+
|
|
21
95
|
const connect = await client.connect({
|
|
22
96
|
subject: "customer_123",
|
|
23
97
|
provider: "google_drive",
|
|
@@ -29,26 +103,14 @@ if (connect.status === "redirect") {
|
|
|
29
103
|
}
|
|
30
104
|
```
|
|
31
105
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- `connect`
|
|
35
|
-
- `listConnections`
|
|
36
|
-
- `getConnection`
|
|
37
|
-
- `revokeConnection`
|
|
38
|
-
- `listDriveFiles`
|
|
39
|
-
- `getAccessRules`
|
|
40
|
-
- `updateAccessRules`
|
|
41
|
-
- `clearAccessRules`
|
|
106
|
+
Full docs: https://docs.celesto.ai/celesto-sdk/gatekeeper
|
|
42
107
|
|
|
43
108
|
## Notes
|
|
44
109
|
|
|
45
110
|
- `token` accepts either a Celesto API key or a JWT.
|
|
46
111
|
- `organizationId` adds the `X-Current-Organization` header.
|
|
47
|
-
- Requires Node 18+ for built-in `fetch`.
|
|
112
|
+
- Requires Node 18+ for built-in `fetch`. Zero runtime dependencies.
|
|
48
113
|
|
|
49
114
|
## License
|
|
50
115
|
|
|
51
|
-
Apache-2.0. The SDK is open source; use of the Celesto platform is governed by the Celesto Terms of Service:
|
|
52
|
-
```
|
|
53
|
-
https://celesto.ai/legal/terms
|
|
54
|
-
```
|
|
116
|
+
Apache-2.0. The SDK is open source; use of the Celesto platform is governed by the Celesto Terms of Service: https://celesto.ai/legal/terms
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildRequestContext,
|
|
3
|
+
request
|
|
4
|
+
} from "./chunk-N3HU6ONW.js";
|
|
5
|
+
|
|
6
|
+
// src/gatekeeper/client.ts
|
|
7
|
+
var toConnectRequest = (payload) => ({
|
|
8
|
+
subject: payload.subject,
|
|
9
|
+
provider: payload.provider ?? "google_drive",
|
|
10
|
+
project_name: payload.projectName,
|
|
11
|
+
redirect_uri: payload.redirectUri
|
|
12
|
+
});
|
|
13
|
+
var toConnectResponse = (payload) => ({
|
|
14
|
+
status: payload.status,
|
|
15
|
+
oauthUrl: payload.oauth_url ?? void 0,
|
|
16
|
+
connectionId: payload.connection_id ?? void 0
|
|
17
|
+
});
|
|
18
|
+
var toConnection = (payload) => ({
|
|
19
|
+
id: payload.id,
|
|
20
|
+
subject: payload.subject,
|
|
21
|
+
provider: payload.provider,
|
|
22
|
+
projectId: payload.project_id,
|
|
23
|
+
accountEmail: payload.account_email ?? null,
|
|
24
|
+
scopes: payload.scopes ?? [],
|
|
25
|
+
status: payload.status,
|
|
26
|
+
createdAt: payload.created_at,
|
|
27
|
+
updatedAt: payload.updated_at,
|
|
28
|
+
lastUsedAt: payload.last_used_at ?? null,
|
|
29
|
+
accessRules: payload.access_rules ? {
|
|
30
|
+
version: payload.access_rules.version ?? "1",
|
|
31
|
+
allowedFolders: payload.access_rules.allowed_folders ?? [],
|
|
32
|
+
allowedFiles: payload.access_rules.allowed_files ?? [],
|
|
33
|
+
unrestricted: false
|
|
34
|
+
} : null
|
|
35
|
+
});
|
|
36
|
+
var toAccessRules = (payload) => ({
|
|
37
|
+
version: payload.version,
|
|
38
|
+
allowedFolders: payload.allowed_folders ?? [],
|
|
39
|
+
allowedFiles: payload.allowed_files ?? [],
|
|
40
|
+
unrestricted: payload.unrestricted
|
|
41
|
+
});
|
|
42
|
+
var toDriveFile = (payload) => ({
|
|
43
|
+
id: payload.id,
|
|
44
|
+
name: payload.name ?? null,
|
|
45
|
+
mimeType: payload.mime_type ?? null,
|
|
46
|
+
size: payload.size ?? null,
|
|
47
|
+
modifiedTime: payload.modified_time ?? null,
|
|
48
|
+
createdTime: payload.created_time ?? null,
|
|
49
|
+
webViewLink: payload.web_view_link ?? null,
|
|
50
|
+
iconLink: payload.icon_link ?? null,
|
|
51
|
+
thumbnailLink: payload.thumbnail_link ?? null,
|
|
52
|
+
parents: payload.parents ?? null,
|
|
53
|
+
driveId: payload.drive_id ?? null,
|
|
54
|
+
shared: payload.shared ?? null,
|
|
55
|
+
ownedByMe: payload.owned_by_me ?? null
|
|
56
|
+
});
|
|
57
|
+
var gatekeeperPath = (path) => `/v1/gatekeeper${path}`;
|
|
58
|
+
var pickOverrides = (options) => ({
|
|
59
|
+
headers: options?.headers,
|
|
60
|
+
signal: options?.signal
|
|
61
|
+
});
|
|
62
|
+
var GatekeeperClient = class {
|
|
63
|
+
constructor(config) {
|
|
64
|
+
this.config = config;
|
|
65
|
+
}
|
|
66
|
+
async connect(payload, options) {
|
|
67
|
+
const ctx = buildRequestContext(this.config);
|
|
68
|
+
const data = await request(ctx, {
|
|
69
|
+
method: "POST",
|
|
70
|
+
path: gatekeeperPath("/connect"),
|
|
71
|
+
body: toConnectRequest(payload),
|
|
72
|
+
...pickOverrides(options)
|
|
73
|
+
});
|
|
74
|
+
return toConnectResponse(data);
|
|
75
|
+
}
|
|
76
|
+
async listConnections(params, options) {
|
|
77
|
+
const ctx = buildRequestContext(this.config);
|
|
78
|
+
const data = await request(ctx, {
|
|
79
|
+
method: "GET",
|
|
80
|
+
path: gatekeeperPath("/connections"),
|
|
81
|
+
query: {
|
|
82
|
+
project_name: params.projectName,
|
|
83
|
+
status_filter: params.statusFilter
|
|
84
|
+
},
|
|
85
|
+
...pickOverrides(options)
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
total: data.total,
|
|
89
|
+
data: data.data.map(toConnection)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async getConnection(connectionId, options) {
|
|
93
|
+
const ctx = buildRequestContext(this.config);
|
|
94
|
+
const data = await request(ctx, {
|
|
95
|
+
method: "GET",
|
|
96
|
+
path: gatekeeperPath(`/connections/${connectionId}`),
|
|
97
|
+
...pickOverrides(options)
|
|
98
|
+
});
|
|
99
|
+
return toConnection(data);
|
|
100
|
+
}
|
|
101
|
+
async revokeConnection(params, options) {
|
|
102
|
+
const ctx = buildRequestContext(this.config);
|
|
103
|
+
return request(ctx, {
|
|
104
|
+
method: "DELETE",
|
|
105
|
+
path: gatekeeperPath("/connections"),
|
|
106
|
+
query: {
|
|
107
|
+
subject: params.subject,
|
|
108
|
+
project_name: params.projectName,
|
|
109
|
+
provider: params.provider
|
|
110
|
+
},
|
|
111
|
+
...pickOverrides(options)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async listDriveFiles(params, options) {
|
|
115
|
+
const ctx = buildRequestContext(this.config);
|
|
116
|
+
const data = await request(ctx, {
|
|
117
|
+
method: "GET",
|
|
118
|
+
path: gatekeeperPath("/connectors/drive/files"),
|
|
119
|
+
query: {
|
|
120
|
+
project_name: params.projectName,
|
|
121
|
+
subject: params.subject,
|
|
122
|
+
page_size: params.pageSize,
|
|
123
|
+
page_token: params.pageToken,
|
|
124
|
+
folder_id: params.folderId,
|
|
125
|
+
query: params.query,
|
|
126
|
+
include_folders: params.includeFolders,
|
|
127
|
+
order_by: params.orderBy
|
|
128
|
+
},
|
|
129
|
+
...pickOverrides(options)
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
files: data.files.map(toDriveFile),
|
|
133
|
+
nextPageToken: data.next_page_token ?? null
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async getAccessRules(connectionId, options) {
|
|
137
|
+
const ctx = buildRequestContext(this.config);
|
|
138
|
+
const data = await request(ctx, {
|
|
139
|
+
method: "GET",
|
|
140
|
+
path: gatekeeperPath(`/connections/${connectionId}/access-rules`),
|
|
141
|
+
...pickOverrides(options)
|
|
142
|
+
});
|
|
143
|
+
return toAccessRules(data);
|
|
144
|
+
}
|
|
145
|
+
async updateAccessRules(params, options) {
|
|
146
|
+
const ctx = buildRequestContext(this.config);
|
|
147
|
+
const data = await request(ctx, {
|
|
148
|
+
method: "PUT",
|
|
149
|
+
path: gatekeeperPath("/connections/access-rules"),
|
|
150
|
+
query: {
|
|
151
|
+
subject: params.subject,
|
|
152
|
+
project_name: params.projectName,
|
|
153
|
+
provider: params.provider
|
|
154
|
+
},
|
|
155
|
+
body: {
|
|
156
|
+
allowed_folders: params.accessRules.allowedFolders ?? [],
|
|
157
|
+
allowed_files: params.accessRules.allowedFiles ?? []
|
|
158
|
+
},
|
|
159
|
+
...pickOverrides(options)
|
|
160
|
+
});
|
|
161
|
+
return toAccessRules(data);
|
|
162
|
+
}
|
|
163
|
+
async clearAccessRules(connectionId, options) {
|
|
164
|
+
const ctx = buildRequestContext(this.config);
|
|
165
|
+
const data = await request(ctx, {
|
|
166
|
+
method: "DELETE",
|
|
167
|
+
path: gatekeeperPath(`/connections/${connectionId}/access-rules`),
|
|
168
|
+
...pickOverrides(options)
|
|
169
|
+
});
|
|
170
|
+
return toAccessRules(data);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
GatekeeperClient
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=chunk-4KVRJSVJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gatekeeper/client.ts"],"sourcesContent":["import { buildRequestContext, ClientConfig, RequestOverrides } from \"../core/config\";\nimport { request } from \"../core/http\";\nimport {\n GatekeeperAccessRules,\n GatekeeperAccessRulesParams,\n GatekeeperConnectRequest,\n GatekeeperConnectResponse,\n GatekeeperConnection,\n GatekeeperDriveFile,\n GatekeeperDriveListParams,\n GatekeeperDriveListResponse,\n GatekeeperListConnectionsParams,\n GatekeeperListConnectionsResponse,\n GatekeeperRevokeParams,\n GatekeeperRevokeResponse,\n} from \"./types\";\n\ninterface GatekeeperConnectRequestWire {\n subject: string;\n provider: string;\n project_name: string;\n redirect_uri?: string;\n}\n\ninterface GatekeeperConnectResponseWire {\n status: string;\n oauth_url?: string | null;\n connection_id?: string | null;\n}\n\ninterface GatekeeperConnectionWire {\n id: string;\n subject: string;\n provider: string;\n project_id: string;\n account_email?: string | null;\n scopes?: string[];\n status: string;\n created_at: string;\n updated_at: string;\n last_used_at?: string | null;\n access_rules?: {\n allowed_folders?: string[];\n allowed_files?: string[];\n version?: string;\n } | null;\n}\n\ninterface GatekeeperListConnectionsResponseWire {\n data: GatekeeperConnectionWire[];\n total: number;\n}\n\ninterface GatekeeperDriveFileWire {\n id: string;\n name?: string | null;\n mime_type?: string | null;\n size?: number | null;\n modified_time?: string | null;\n created_time?: string | null;\n web_view_link?: string | null;\n icon_link?: string | null;\n thumbnail_link?: string | null;\n parents?: string[] | null;\n drive_id?: string | null;\n shared?: boolean | null;\n owned_by_me?: boolean | null;\n}\n\ninterface GatekeeperDriveListResponseWire {\n files: GatekeeperDriveFileWire[];\n next_page_token?: string | null;\n}\n\ninterface GatekeeperAccessRulesResponseWire {\n version: string;\n allowed_folders: string[];\n allowed_files: string[];\n unrestricted: boolean;\n}\n\nconst toConnectRequest = (payload: GatekeeperConnectRequest): GatekeeperConnectRequestWire => ({\n subject: payload.subject,\n provider: payload.provider ?? \"google_drive\",\n project_name: payload.projectName,\n redirect_uri: payload.redirectUri,\n});\n\nconst toConnectResponse = (payload: GatekeeperConnectResponseWire): GatekeeperConnectResponse => ({\n status: payload.status,\n oauthUrl: payload.oauth_url ?? undefined,\n connectionId: payload.connection_id ?? undefined,\n});\n\nconst toConnection = (payload: GatekeeperConnectionWire): GatekeeperConnection => ({\n id: payload.id,\n subject: payload.subject,\n provider: payload.provider,\n projectId: payload.project_id,\n accountEmail: payload.account_email ?? null,\n scopes: payload.scopes ?? [],\n status: payload.status,\n createdAt: payload.created_at,\n updatedAt: payload.updated_at,\n lastUsedAt: payload.last_used_at ?? null,\n accessRules: payload.access_rules\n ? {\n version: payload.access_rules.version ?? \"1\",\n allowedFolders: payload.access_rules.allowed_folders ?? [],\n allowedFiles: payload.access_rules.allowed_files ?? [],\n unrestricted: false,\n }\n : null,\n});\n\nconst toAccessRules = (payload: GatekeeperAccessRulesResponseWire): GatekeeperAccessRules => ({\n version: payload.version,\n allowedFolders: payload.allowed_folders ?? [],\n allowedFiles: payload.allowed_files ?? [],\n unrestricted: payload.unrestricted,\n});\n\nconst toDriveFile = (payload: GatekeeperDriveFileWire): GatekeeperDriveFile => ({\n id: payload.id,\n name: payload.name ?? null,\n mimeType: payload.mime_type ?? null,\n size: payload.size ?? null,\n modifiedTime: payload.modified_time ?? null,\n createdTime: payload.created_time ?? null,\n webViewLink: payload.web_view_link ?? null,\n iconLink: payload.icon_link ?? null,\n thumbnailLink: payload.thumbnail_link ?? null,\n parents: payload.parents ?? null,\n driveId: payload.drive_id ?? null,\n shared: payload.shared ?? null,\n ownedByMe: payload.owned_by_me ?? null,\n});\n\nconst gatekeeperPath = (path: string): string => `/v1/gatekeeper${path}`;\n\nconst pickOverrides = (options?: RequestOverrides): RequestOverrides => ({\n headers: options?.headers,\n signal: options?.signal,\n});\n\nexport class GatekeeperClient {\n private readonly config: ClientConfig;\n\n constructor(config: ClientConfig) {\n this.config = config;\n }\n\n async connect(payload: GatekeeperConnectRequest, options?: RequestOverrides): Promise<GatekeeperConnectResponse> {\n const ctx = buildRequestContext(this.config);\n const data = await request<GatekeeperConnectResponseWire>(ctx, {\n method: \"POST\",\n path: gatekeeperPath(\"/connect\"),\n body: toConnectRequest(payload),\n ...pickOverrides(options),\n });\n return toConnectResponse(data);\n }\n\n async listConnections(params: GatekeeperListConnectionsParams, options?: RequestOverrides): Promise<GatekeeperListConnectionsResponse> {\n const ctx = buildRequestContext(this.config);\n const data = await request<GatekeeperListConnectionsResponseWire>(ctx, {\n method: \"GET\",\n path: gatekeeperPath(\"/connections\"),\n query: {\n project_name: params.projectName,\n status_filter: params.statusFilter,\n },\n ...pickOverrides(options),\n });\n\n return {\n total: data.total,\n data: data.data.map(toConnection),\n };\n }\n\n async getConnection(connectionId: string, options?: RequestOverrides): Promise<GatekeeperConnection> {\n const ctx = buildRequestContext(this.config);\n const data = await request<GatekeeperConnectionWire>(ctx, {\n method: \"GET\",\n path: gatekeeperPath(`/connections/${connectionId}`),\n ...pickOverrides(options),\n });\n return toConnection(data);\n }\n\n async revokeConnection(params: GatekeeperRevokeParams, options?: RequestOverrides): Promise<GatekeeperRevokeResponse> {\n const ctx = buildRequestContext(this.config);\n return request<GatekeeperRevokeResponse>(ctx, {\n method: \"DELETE\",\n path: gatekeeperPath(\"/connections\"),\n query: {\n subject: params.subject,\n project_name: params.projectName,\n provider: params.provider,\n },\n ...pickOverrides(options),\n });\n }\n\n async listDriveFiles(params: GatekeeperDriveListParams, options?: RequestOverrides): Promise<GatekeeperDriveListResponse> {\n const ctx = buildRequestContext(this.config);\n const data = await request<GatekeeperDriveListResponseWire>(ctx, {\n method: \"GET\",\n path: gatekeeperPath(\"/connectors/drive/files\"),\n query: {\n project_name: params.projectName,\n subject: params.subject,\n page_size: params.pageSize,\n page_token: params.pageToken,\n folder_id: params.folderId,\n query: params.query,\n include_folders: params.includeFolders,\n order_by: params.orderBy,\n },\n ...pickOverrides(options),\n });\n\n return {\n files: data.files.map(toDriveFile),\n nextPageToken: data.next_page_token ?? null,\n };\n }\n\n async getAccessRules(connectionId: string, options?: RequestOverrides): Promise<GatekeeperAccessRules> {\n const ctx = buildRequestContext(this.config);\n const data = await request<GatekeeperAccessRulesResponseWire>(ctx, {\n method: \"GET\",\n path: gatekeeperPath(`/connections/${connectionId}/access-rules`),\n ...pickOverrides(options),\n });\n return toAccessRules(data);\n }\n\n async updateAccessRules(params: GatekeeperAccessRulesParams, options?: RequestOverrides): Promise<GatekeeperAccessRules> {\n const ctx = buildRequestContext(this.config);\n const data = await request<GatekeeperAccessRulesResponseWire>(ctx, {\n method: \"PUT\",\n path: gatekeeperPath(\"/connections/access-rules\"),\n query: {\n subject: params.subject,\n project_name: params.projectName,\n provider: params.provider,\n },\n body: {\n allowed_folders: params.accessRules.allowedFolders ?? [],\n allowed_files: params.accessRules.allowedFiles ?? [],\n },\n ...pickOverrides(options),\n });\n return toAccessRules(data);\n }\n\n async clearAccessRules(connectionId: string, options?: RequestOverrides): Promise<GatekeeperAccessRules> {\n const ctx = buildRequestContext(this.config);\n const data = await request<GatekeeperAccessRulesResponseWire>(ctx, {\n method: \"DELETE\",\n path: gatekeeperPath(`/connections/${connectionId}/access-rules`),\n ...pickOverrides(options),\n });\n return toAccessRules(data);\n }\n}\n"],"mappings":";;;;;;AAiFA,IAAM,mBAAmB,CAAC,aAAqE;AAAA,EAC7F,SAAS,QAAQ;AAAA,EACjB,UAAU,QAAQ,YAAY;AAAA,EAC9B,cAAc,QAAQ;AAAA,EACtB,cAAc,QAAQ;AACxB;AAEA,IAAM,oBAAoB,CAAC,aAAuE;AAAA,EAChG,QAAQ,QAAQ;AAAA,EAChB,UAAU,QAAQ,aAAa;AAAA,EAC/B,cAAc,QAAQ,iBAAiB;AACzC;AAEA,IAAM,eAAe,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,MACA,MAAM;AAAA,QACJ,iBAAiB,OAAO,YAAY,kBAAkB,CAAC;AAAA,QACvD,eAAe,OAAO,YAAY,gBAAgB,CAAC;AAAA,MACrD;AAAA,MACA,GAAG,cAAc,OAAO;AAAA,IAC1B,CAAC;AACD,WAAO,cAAc,IAAI;AAAA,EAC3B;AAAA,EAEA,MAAM,iBAAiB,cAAsB,SAA4D;AACvG,UAAM,MAAM,oBAAoB,KAAK,MAAM;AAC3C,UAAM,OAAO,MAAM,QAA2C,KAAK;AAAA,MACjE,QAAQ;AAAA,MACR,MAAM,eAAe,gBAAgB,YAAY,eAAe;AAAA,MAChE,GAAG,cAAc,OAAO;AAAA,IAC1B,CAAC;AACD,WAAO,cAAc,IAAI;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildRequestContext,
|
|
3
|
+
request
|
|
4
|
+
} from "./chunk-N3HU6ONW.js";
|
|
5
|
+
|
|
6
|
+
// src/computers/client.ts
|
|
7
|
+
var toConnection = (payload) => {
|
|
8
|
+
if (!payload) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
const out = {};
|
|
12
|
+
if (payload.ssh != null) {
|
|
13
|
+
out.ssh = payload.ssh;
|
|
14
|
+
}
|
|
15
|
+
if (payload.access_url != null) {
|
|
16
|
+
out.accessUrl = payload.access_url;
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
};
|
|
20
|
+
var toComputerInfo = (payload) => ({
|
|
21
|
+
id: payload.id,
|
|
22
|
+
name: payload.name,
|
|
23
|
+
status: payload.status,
|
|
24
|
+
vcpus: payload.vcpus,
|
|
25
|
+
ramMb: payload.ram_mb,
|
|
26
|
+
diskSizeMb: payload.disk_size_mb,
|
|
27
|
+
image: payload.image,
|
|
28
|
+
templateId: payload.template_id,
|
|
29
|
+
templateVersion: payload.template_version ?? null,
|
|
30
|
+
connection: toConnection(payload.connection),
|
|
31
|
+
lastError: payload.last_error ?? null,
|
|
32
|
+
createdAt: payload.created_at,
|
|
33
|
+
stoppedAt: payload.stopped_at ?? null
|
|
34
|
+
});
|
|
35
|
+
var toExecResponse = (payload) => ({
|
|
36
|
+
exitCode: payload.exit_code,
|
|
37
|
+
stdout: payload.stdout,
|
|
38
|
+
stderr: payload.stderr
|
|
39
|
+
});
|
|
40
|
+
var toSandboxTemplateInfo = (payload) => ({
|
|
41
|
+
id: payload.id,
|
|
42
|
+
displayName: payload.display_name,
|
|
43
|
+
description: payload.description,
|
|
44
|
+
defaultVcpus: payload.default_vcpus,
|
|
45
|
+
defaultRamMb: payload.default_ram_mb,
|
|
46
|
+
defaultDiskSizeMb: payload.default_disk_size_mb,
|
|
47
|
+
version: payload.version ?? null,
|
|
48
|
+
experimental: payload.experimental
|
|
49
|
+
});
|
|
50
|
+
var buildCreateComputerBody = (params) => {
|
|
51
|
+
if (params.cpus !== void 0 && params.vcpus !== void 0 && params.cpus !== params.vcpus) {
|
|
52
|
+
throw new Error("cpus and vcpus must have the same value when both are provided.");
|
|
53
|
+
}
|
|
54
|
+
if (params.memory !== void 0 && params.ramMb !== void 0 && params.memory !== params.ramMb) {
|
|
55
|
+
throw new Error("memory and ramMb must have the same value when both are provided.");
|
|
56
|
+
}
|
|
57
|
+
const body = {};
|
|
58
|
+
const vcpus = params.vcpus ?? params.cpus;
|
|
59
|
+
const ramMb = params.ramMb ?? params.memory;
|
|
60
|
+
if (vcpus !== void 0) {
|
|
61
|
+
body.vcpus = vcpus;
|
|
62
|
+
}
|
|
63
|
+
if (ramMb !== void 0) {
|
|
64
|
+
body.ram_mb = ramMb;
|
|
65
|
+
}
|
|
66
|
+
if (params.diskSizeMb !== void 0) {
|
|
67
|
+
body.disk_size_mb = params.diskSizeMb;
|
|
68
|
+
}
|
|
69
|
+
if (params.image !== void 0) {
|
|
70
|
+
body.image = params.image;
|
|
71
|
+
}
|
|
72
|
+
if (params.templateId !== void 0) {
|
|
73
|
+
body.template_id = params.templateId;
|
|
74
|
+
}
|
|
75
|
+
if (params.templateVersion !== void 0) {
|
|
76
|
+
body.template_version = params.templateVersion;
|
|
77
|
+
}
|
|
78
|
+
return body;
|
|
79
|
+
};
|
|
80
|
+
var computersPath = (path) => `/v1/computers${path}`;
|
|
81
|
+
var pickOverrides = (options) => ({
|
|
82
|
+
headers: options?.headers,
|
|
83
|
+
signal: options?.signal
|
|
84
|
+
});
|
|
85
|
+
var ComputersClient = class {
|
|
86
|
+
constructor(config) {
|
|
87
|
+
this.config = config;
|
|
88
|
+
}
|
|
89
|
+
async create(params = {}, options) {
|
|
90
|
+
const ctx = buildRequestContext(this.config);
|
|
91
|
+
const data = await request(ctx, {
|
|
92
|
+
method: "POST",
|
|
93
|
+
path: computersPath(""),
|
|
94
|
+
body: buildCreateComputerBody(params),
|
|
95
|
+
...pickOverrides(options)
|
|
96
|
+
});
|
|
97
|
+
return toComputerInfo(data);
|
|
98
|
+
}
|
|
99
|
+
async listTemplates(options) {
|
|
100
|
+
const ctx = buildRequestContext(this.config);
|
|
101
|
+
const data = await request(ctx, {
|
|
102
|
+
method: "GET",
|
|
103
|
+
path: computersPath("/templates"),
|
|
104
|
+
...pickOverrides(options)
|
|
105
|
+
});
|
|
106
|
+
return data.map(toSandboxTemplateInfo);
|
|
107
|
+
}
|
|
108
|
+
async list(options) {
|
|
109
|
+
const ctx = buildRequestContext(this.config);
|
|
110
|
+
const data = await request(ctx, {
|
|
111
|
+
method: "GET",
|
|
112
|
+
path: computersPath(""),
|
|
113
|
+
...pickOverrides(options)
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
computers: data.computers.map(toComputerInfo),
|
|
117
|
+
count: data.count
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async get(computerId, options) {
|
|
121
|
+
const ctx = buildRequestContext(this.config);
|
|
122
|
+
const data = await request(ctx, {
|
|
123
|
+
method: "GET",
|
|
124
|
+
path: computersPath(`/${encodeURIComponent(computerId)}`),
|
|
125
|
+
...pickOverrides(options)
|
|
126
|
+
});
|
|
127
|
+
return toComputerInfo(data);
|
|
128
|
+
}
|
|
129
|
+
async exec(computerId, command, params = {}, options) {
|
|
130
|
+
const ctx = buildRequestContext(this.config);
|
|
131
|
+
const data = await request(ctx, {
|
|
132
|
+
method: "POST",
|
|
133
|
+
path: computersPath(`/${encodeURIComponent(computerId)}/exec`),
|
|
134
|
+
body: {
|
|
135
|
+
command,
|
|
136
|
+
timeout: params.timeout ?? 30
|
|
137
|
+
},
|
|
138
|
+
...pickOverrides(options)
|
|
139
|
+
});
|
|
140
|
+
return toExecResponse(data);
|
|
141
|
+
}
|
|
142
|
+
async stop(computerId, options) {
|
|
143
|
+
const ctx = buildRequestContext(this.config);
|
|
144
|
+
const data = await request(ctx, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
path: computersPath(`/${encodeURIComponent(computerId)}/stop`),
|
|
147
|
+
...pickOverrides(options)
|
|
148
|
+
});
|
|
149
|
+
return toComputerInfo(data);
|
|
150
|
+
}
|
|
151
|
+
async start(computerId, options) {
|
|
152
|
+
const ctx = buildRequestContext(this.config);
|
|
153
|
+
const data = await request(ctx, {
|
|
154
|
+
method: "POST",
|
|
155
|
+
path: computersPath(`/${encodeURIComponent(computerId)}/start`),
|
|
156
|
+
...pickOverrides(options)
|
|
157
|
+
});
|
|
158
|
+
return toComputerInfo(data);
|
|
159
|
+
}
|
|
160
|
+
async delete(computerId, options) {
|
|
161
|
+
const ctx = buildRequestContext(this.config);
|
|
162
|
+
const data = await request(ctx, {
|
|
163
|
+
method: "DELETE",
|
|
164
|
+
path: computersPath(`/${encodeURIComponent(computerId)}`),
|
|
165
|
+
...pickOverrides(options)
|
|
166
|
+
});
|
|
167
|
+
return toComputerInfo(data);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Get connection info for opening a WebSocket terminal session.
|
|
171
|
+
*
|
|
172
|
+
* Accepts either a computer ID (e.g. `cmp_xxx`) or a human-readable name.
|
|
173
|
+
* The name is resolved to the canonical ID via a GET call — the backend's
|
|
174
|
+
* WebSocket endpoint does not resolve names on its own.
|
|
175
|
+
*
|
|
176
|
+
* Returns the URL, headers, and first message needed to open the connection
|
|
177
|
+
* with any WebSocket library of your choice.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const conn = await celesto.computers.getTerminalConnection("my-computer");
|
|
182
|
+
* const ws = new WebSocket(conn.url, { headers: conn.headers });
|
|
183
|
+
* ws.on("open", () => ws.send(conn.firstMessage));
|
|
184
|
+
* ws.on("message", (data) => process.stdout.write(data));
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
async getTerminalConnection(computerIdOrName) {
|
|
188
|
+
const info = await this.get(computerIdOrName);
|
|
189
|
+
const ctx = buildRequestContext(this.config);
|
|
190
|
+
if (!ctx.token) {
|
|
191
|
+
throw new Error("A token is required for terminal connections");
|
|
192
|
+
}
|
|
193
|
+
const wsBase = ctx.baseUrl.replace(/^https:/i, "wss:").replace(/^http:/i, "ws:");
|
|
194
|
+
const url = `${wsBase}/v1/computers/${encodeURIComponent(info.id)}/terminal`;
|
|
195
|
+
const headers = {
|
|
196
|
+
Authorization: `Bearer ${ctx.token}`
|
|
197
|
+
};
|
|
198
|
+
if (ctx.organizationId) {
|
|
199
|
+
headers["X-Current-Organization"] = ctx.organizationId;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
url,
|
|
203
|
+
headers,
|
|
204
|
+
firstMessage: JSON.stringify({ token: ctx.token })
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export {
|
|
210
|
+
ComputersClient
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=chunk-7OJDEZ7J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/computers/client.ts"],"sourcesContent":["import { buildRequestContext, ClientConfig, RequestOverrides } from \"../core/config\";\nimport { request } from \"../core/http\";\nimport {\n ComputerConnectionInfo,\n ComputerExecResponse,\n ComputerInfo,\n ComputerListResponse,\n ComputerStatus,\n CreateComputerParams,\n ExecParams,\n SandboxTemplateInfo,\n TerminalConnectionInfo,\n} from \"./types\";\n\ninterface ComputerConnectionInfoWire {\n ssh?: string | null;\n access_url?: string | null;\n}\n\ninterface ComputerInfoWire {\n id: string;\n name: string;\n status: ComputerStatus;\n vcpus: number;\n ram_mb: number;\n disk_size_mb: number;\n image: string;\n template_id: string;\n template_version?: string | null;\n connection?: ComputerConnectionInfoWire | null;\n last_error?: string | null;\n created_at: string;\n stopped_at?: string | null;\n}\n\ninterface ComputerListResponseWire {\n computers: ComputerInfoWire[];\n count: number;\n}\n\ninterface ComputerExecResponseWire {\n exit_code: number;\n stdout: string;\n stderr: string;\n}\n\ninterface SandboxTemplateInfoWire {\n id: string;\n display_name: string;\n description: string;\n default_vcpus: number;\n default_ram_mb: number;\n default_disk_size_mb: number;\n version?: string | null;\n experimental: boolean;\n}\n\nconst toConnection = (\n payload: ComputerConnectionInfoWire | null | undefined,\n): ComputerConnectionInfo | undefined => {\n if (!payload) {\n return undefined;\n }\n const out: ComputerConnectionInfo = {};\n if (payload.ssh != null) {\n out.ssh = payload.ssh;\n }\n if (payload.access_url != null) {\n out.accessUrl = payload.access_url;\n }\n return out;\n};\n\nconst toComputerInfo = (payload: ComputerInfoWire): ComputerInfo => ({\n id: payload.id,\n name: payload.name,\n status: payload.status,\n vcpus: payload.vcpus,\n ramMb: payload.ram_mb,\n diskSizeMb: payload.disk_size_mb,\n image: payload.image,\n templateId: payload.template_id,\n templateVersion: payload.template_version ?? null,\n connection: toConnection(payload.connection),\n lastError: payload.last_error ?? null,\n createdAt: payload.created_at,\n stoppedAt: payload.stopped_at ?? null,\n});\n\nconst toExecResponse = (payload: ComputerExecResponseWire): ComputerExecResponse => ({\n exitCode: payload.exit_code,\n stdout: payload.stdout,\n stderr: payload.stderr,\n});\n\nconst toSandboxTemplateInfo = (payload: SandboxTemplateInfoWire): SandboxTemplateInfo => ({\n id: payload.id,\n displayName: payload.display_name,\n description: payload.description,\n defaultVcpus: payload.default_vcpus,\n defaultRamMb: payload.default_ram_mb,\n defaultDiskSizeMb: payload.default_disk_size_mb,\n version: payload.version ?? null,\n experimental: payload.experimental,\n});\n\nconst buildCreateComputerBody = (params: CreateComputerParams): Record<string, unknown> => {\n if (params.cpus !== undefined && params.vcpus !== undefined && params.cpus !== params.vcpus) {\n throw new Error(\"cpus and vcpus must have the same value when both are provided.\");\n }\n if (params.memory !== undefined && params.ramMb !== undefined && params.memory !== params.ramMb) {\n throw new Error(\"memory and ramMb must have the same value when both are provided.\");\n }\n\n const body: Record<string, unknown> = {};\n const vcpus = params.vcpus ?? params.cpus;\n const ramMb = params.ramMb ?? params.memory;\n if (vcpus !== undefined) {\n body.vcpus = vcpus;\n }\n if (ramMb !== undefined) {\n body.ram_mb = ramMb;\n }\n if (params.diskSizeMb !== undefined) {\n body.disk_size_mb = params.diskSizeMb;\n }\n if (params.image !== undefined) {\n body.image = params.image;\n }\n if (params.templateId !== undefined) {\n body.template_id = params.templateId;\n }\n if (params.templateVersion !== undefined) {\n body.template_version = params.templateVersion;\n }\n return body;\n};\n\nconst computersPath = (path: string): string => `/v1/computers${path}`;\n\nconst pickOverrides = (options?: RequestOverrides): RequestOverrides => ({\n headers: options?.headers,\n signal: options?.signal,\n});\n\n/**\n * Client for managing sandboxed computers (AI sandboxes).\n *\n * Provides create/list/get/exec/stop/start/delete over HTTP, plus\n * `getTerminalConnection()` which returns the URL and headers needed\n * to open a WebSocket terminal with any WS library of your choice.\n *\n * @example\n * ```ts\n * const celesto = new Celesto({ token: process.env.CELESTO_API_KEY });\n * const computer = await celesto.computers.create({ templateId: \"coding-agent\" });\n * const result = await celesto.computers.exec(computer.id, \"uname -a\");\n * console.log(result.stdout);\n * await celesto.computers.delete(computer.id);\n * ```\n */\nexport class ComputersClient {\n private readonly config: ClientConfig;\n\n constructor(config: ClientConfig) {\n this.config = config;\n }\n\n async create(params: CreateComputerParams = {}, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(\"\"),\n body: buildCreateComputerBody(params),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async listTemplates(options?: RequestOverrides): Promise<SandboxTemplateInfo[]> {\n const ctx = buildRequestContext(this.config);\n const data = await request<SandboxTemplateInfoWire[]>(ctx, {\n method: \"GET\",\n path: computersPath(\"/templates\"),\n ...pickOverrides(options),\n });\n return data.map(toSandboxTemplateInfo);\n }\n\n async list(options?: RequestOverrides): Promise<ComputerListResponse> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerListResponseWire>(ctx, {\n method: \"GET\",\n path: computersPath(\"\"),\n ...pickOverrides(options),\n });\n return {\n computers: data.computers.map(toComputerInfo),\n count: data.count,\n };\n }\n\n async get(computerId: string, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"GET\",\n path: computersPath(`/${encodeURIComponent(computerId)}`),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async exec(\n computerId: string,\n command: string,\n params: ExecParams = {},\n options?: RequestOverrides,\n ): Promise<ComputerExecResponse> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerExecResponseWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerId)}/exec`),\n body: {\n command,\n timeout: params.timeout ?? 30,\n },\n ...pickOverrides(options),\n });\n return toExecResponse(data);\n }\n\n async stop(computerId: string, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerId)}/stop`),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async start(computerId: string, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"POST\",\n path: computersPath(`/${encodeURIComponent(computerId)}/start`),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n async delete(computerId: string, options?: RequestOverrides): Promise<ComputerInfo> {\n const ctx = buildRequestContext(this.config);\n const data = await request<ComputerInfoWire>(ctx, {\n method: \"DELETE\",\n path: computersPath(`/${encodeURIComponent(computerId)}`),\n ...pickOverrides(options),\n });\n return toComputerInfo(data);\n }\n\n /**\n * Get connection info for opening a WebSocket terminal session.\n *\n * Accepts either a computer ID (e.g. `cmp_xxx`) or a human-readable name.\n * The name is resolved to the canonical ID via a GET call — the backend's\n * WebSocket endpoint does not resolve names on its own.\n *\n * Returns the URL, headers, and first message needed to open the connection\n * with any WebSocket library of your choice.\n *\n * @example\n * ```ts\n * const conn = await celesto.computers.getTerminalConnection(\"my-computer\");\n * const ws = new WebSocket(conn.url, { headers: conn.headers });\n * ws.on(\"open\", () => ws.send(conn.firstMessage));\n * ws.on(\"message\", (data) => process.stdout.write(data));\n * ```\n */\n async getTerminalConnection(computerIdOrName: string): Promise<TerminalConnectionInfo> {\n const info = await this.get(computerIdOrName);\n const ctx = buildRequestContext(this.config);\n\n if (!ctx.token) {\n throw new Error(\"A token is required for terminal connections\");\n }\n\n const wsBase = ctx.baseUrl.replace(/^https:/i, \"wss:\").replace(/^http:/i, \"ws:\");\n const url = `${wsBase}/v1/computers/${encodeURIComponent(info.id)}/terminal`;\n\n const headers: Record<string, string> = {\n Authorization: `Bearer ${ctx.token}`,\n };\n if (ctx.organizationId) {\n headers[\"X-Current-Organization\"] = ctx.organizationId;\n }\n\n return {\n url,\n headers,\n firstMessage: JSON.stringify({ token: ctx.token }),\n };\n }\n}\n"],"mappings":";;;;;;AAyDA,IAAM,eAAe,CACnB,YACuC;AACvC,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AACA,QAAM,MAA8B,CAAC;AACrC,MAAI,QAAQ,OA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