freestyle-sandboxes 0.0.19 → 0.0.21

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/src/index.ts CHANGED
@@ -31,7 +31,7 @@ export class FreestyleSandboxes {
31
31
  */
32
32
  async executeScript(
33
33
  script: string,
34
- config?: sandbox_openapi.FreestyleExecuteScriptParamsConfiguration
34
+ config?: sandbox_openapi.FreestyleExecuteScriptParamsConfiguration,
35
35
  ): Promise<sandbox_openapi.FreestyleExecuteScriptResultSuccess> {
36
36
  const response = await sandbox_openapi.handleExecuteScript({
37
37
  client: this.client,
@@ -46,8 +46,8 @@ export class FreestyleSandboxes {
46
46
  } else {
47
47
  throw new Error(
48
48
  `Failed to execute script: \n\n${script}\n\nError:\n\n${JSON.stringify(
49
- response
50
- )}`
49
+ response,
50
+ )}`,
51
51
  );
52
52
  }
53
53
  }
@@ -63,7 +63,7 @@ export class FreestyleSandboxes {
63
63
  encoding?: string;
64
64
  }
65
65
  >,
66
- config?: sandbox_openapi.FreestyleDeployWebConfiguration
66
+ config?: sandbox_openapi.FreestyleDeployWebConfiguration,
67
67
  ): Promise<sandbox_openapi.FreestyleDeployWebSuccessResponse> {
68
68
  const response = await sandbox_openapi.handleDeployWeb({
69
69
  client: this.client,
@@ -76,7 +76,7 @@ export class FreestyleSandboxes {
76
76
  return response.data;
77
77
  } else {
78
78
  throw new Error(
79
- `Failed to deploy web project\n\nStatus: ${response.response.status}\n\nMessage: ${response.error?.message}`
79
+ `Failed to deploy web project\n\nStatus: ${response.response.status}\n\nMessage: ${response.error?.message}`,
80
80
  );
81
81
  }
82
82
  }
@@ -85,7 +85,7 @@ export class FreestyleSandboxes {
85
85
  * Deploy a Cloudstate project to a sandbox.
86
86
  */
87
87
  async deployCloudstate(
88
- body: sandbox_openapi.FreestyleCloudstateDeployRequest
88
+ body: sandbox_openapi.FreestyleCloudstateDeployRequest,
89
89
  ): Promise<sandbox_openapi.FreestyleCloudstateDeploySuccessResponse> {
90
90
  const response = await sandbox_openapi.handleDeployCloudstate({
91
91
  client: this.client,
@@ -105,7 +105,7 @@ export class FreestyleSandboxes {
105
105
  * @throws An error if the backup could not be retrieved.
106
106
  */
107
107
  async backupCloudstate(
108
- id: string
108
+ id: string,
109
109
  ): Promise<sandbox_openapi.HandleBackupCloudstateResponse> {
110
110
  const response = await sandbox_openapi.handleBackupCloudstate({
111
111
  client: this.client,
@@ -149,7 +149,7 @@ export class FreestyleSandboxes {
149
149
  * @returns The domain verification token.
150
150
  */
151
151
  async createDomainVerificationRequest(
152
- domain: string
152
+ domain: string,
153
153
  ): Promise<sandbox_openapi.HandleCreateDomainVerificationResponse> {
154
154
  const response = await sandbox_openapi.handleCreateDomainVerification({
155
155
  client: this.client,
@@ -161,7 +161,7 @@ export class FreestyleSandboxes {
161
161
  return response.data;
162
162
  } else {
163
163
  throw new Error(
164
- `Failed to create domain verification request for domain ${domain}: ${response.error.message}`
164
+ `Failed to create domain verification request for domain ${domain}: ${response.error.message}`,
165
165
  );
166
166
  }
167
167
  }
@@ -172,7 +172,7 @@ export class FreestyleSandboxes {
172
172
  * @returns The domain verification request.
173
173
  */
174
174
  async verifyDomain(
175
- domain: string
175
+ domain: string,
176
176
  ): Promise<
177
177
  | sandbox_openapi.HandleVerifyDomainResponse
178
178
  | sandbox_openapi.HandleVerifyDomainError
@@ -187,7 +187,7 @@ export class FreestyleSandboxes {
187
187
  return response.data;
188
188
  } else {
189
189
  throw new Error(
190
- `Failed to verify domain ${domain}: ${response.error.message}`
190
+ `Failed to verify domain ${domain}: ${response.error.message}`,
191
191
  );
192
192
  }
193
193
  }
@@ -207,20 +207,21 @@ export class FreestyleSandboxes {
207
207
  const response = await sandbox_openapi.handleListDomainVerificationRequests(
208
208
  {
209
209
  client: this.client,
210
- }
210
+ },
211
211
  );
212
212
  if (response.data) {
213
213
  return response.data;
214
214
  } else {
215
215
  throw new Error(
216
- "Failed to list domain verification requests\n" + response.error.message
216
+ "Failed to list domain verification requests\n" +
217
+ response.error.message,
217
218
  );
218
219
  }
219
220
  }
220
221
 
221
222
  async deleteDomainVerificationRequest(
222
223
  domain: string,
223
- verificationCode: string
224
+ verificationCode: string,
224
225
  ): Promise<sandbox_openapi.HandleDeleteDomainVerificationResponse> {
225
226
  const response = await sandbox_openapi.handleDeleteDomainVerification({
226
227
  client: this.client,
@@ -233,27 +234,41 @@ export class FreestyleSandboxes {
233
234
  return response.data;
234
235
  } else {
235
236
  throw new Error(
236
- `Failed to delete domain verification request for domain ${domain}: ${response.error.message}`
237
+ `Failed to delete domain verification request for domain ${domain}: ${response.error.message}`,
237
238
  );
238
239
  }
239
240
  }
240
241
 
241
- async listWebDeployments(): Promise<sandbox_openapi.HandleListWebDeploysResponse> {
242
+ async listWebDeployments(
243
+ limit?: number,
244
+ offset?: number,
245
+ ): Promise<sandbox_openapi.HandleListWebDeploysResponse> {
242
246
  const response = await sandbox_openapi.handleListWebDeploys({
243
247
  client: this.client,
248
+ query: {
249
+ limit: limit ?? 10,
250
+ offset: offset ?? 0,
251
+ },
244
252
  });
245
253
  if (response.data) {
246
254
  return response.data;
247
255
  } else {
248
256
  throw new Error(
249
- "Failed to list web deployments\n" + response.error.message
257
+ "Failed to list web deployments\n" + response.error.message,
250
258
  );
251
259
  }
252
260
  }
253
261
 
254
- async listExecuteRuns(): Promise<sandbox_openapi.HandleListExecuteRunsResponse> {
262
+ async listExecuteRuns(
263
+ limit?: number,
264
+ offset?: number,
265
+ ): Promise<sandbox_openapi.HandleListExecuteRunsResponse> {
255
266
  const response = await sandbox_openapi.handleListExecuteRuns({
256
267
  client: this.client,
268
+ query: {
269
+ limit: limit ?? 10,
270
+ offset: offset ?? 0,
271
+ },
257
272
  });
258
273
  if (response.data) {
259
274
  return response.data;
@@ -263,7 +278,7 @@ export class FreestyleSandboxes {
263
278
  }
264
279
 
265
280
  async getExecuteRun(
266
- id: string
281
+ id: string,
267
282
  ): Promise<sandbox_openapi.HandleGetExecuteRunResponse> {
268
283
  const response = await sandbox_openapi.handleGetExecuteRun({
269
284
  client: this.client,
@@ -272,11 +287,80 @@ export class FreestyleSandboxes {
272
287
  },
273
288
  });
274
289
 
290
+ if (response.data) {
291
+ return response.data;
292
+ }
293
+
294
+ throw new Error(
295
+ `Failed to get execute run with ID ${id}: ${response.error.message}`,
296
+ );
297
+ }
298
+
299
+ /**
300
+ * Create a new git repository.
301
+ *
302
+ * @param name The name of the repository.
303
+ */
304
+ async createGitRepository(
305
+ name: string,
306
+ ): Promise<sandbox_openapi.CreateRepoHandlerResponse> {
307
+ const response = await sandbox_openapi.createRepoHandler({
308
+ client: this.client,
309
+ body: {
310
+ name,
311
+ },
312
+ });
313
+ if (response.data) {
314
+ return response.data;
315
+ }
316
+ throw new Error(
317
+ `Failed to create git repository ${name}: ${response.error}`,
318
+ );
319
+ }
320
+
321
+ /**
322
+ * List git repositories.
323
+ *
324
+ * @param limit The maximum number of repositories to return. Defaults to 10.
325
+ * @param offset The offset to start at. Defaults to 0.
326
+ */
327
+ async listGitRepositories(
328
+ limit?: number,
329
+ offset?: number,
330
+ ): Promise<sandbox_openapi.ListRepositoriesHandlerResponse> {
331
+ const response = await sandbox_openapi.listRepositoriesHandler({
332
+ client: this.client,
333
+ query: {
334
+ limit: limit ?? 10,
335
+ offset: offset ?? 0,
336
+ },
337
+ });
338
+ if (response.data) {
339
+ return response.data;
340
+ }
341
+ throw new Error(`Failed to list git repositories: ${response.error}`);
342
+ }
343
+
344
+ /**
345
+ * Delete a git repository.
346
+ *
347
+ * @param repositoryId The ID of the repository to delete.
348
+ */
349
+ async deleteGitRepository(
350
+ repositoryId: string,
351
+ ): Promise<sandbox_openapi.DeleteRepoHandlerResponse> {
352
+ const response = await sandbox_openapi.deleteRepoHandler({
353
+ client: this.client,
354
+ path: {
355
+ repo: repositoryId,
356
+ },
357
+ });
358
+
275
359
  if (response.data) {
276
360
  return response.data;
277
361
  } else {
278
362
  throw new Error(
279
- `Failed to get execute run with ID ${id}: ${response.error.message}`
363
+ `Failed to delete git repository ${repositoryId}: ${response.error}`,
280
364
  );
281
365
  }
282
366
  }
@@ -294,7 +378,7 @@ export class FreestyleSandboxes {
294
378
  return response.data;
295
379
  } else {
296
380
  throw new Error(
297
- `Failed to provision wildcard for domain ${domain}: ${response.error.message}`
381
+ `Failed to provision wildcard for domain ${domain}: ${response.error.message}`,
298
382
  );
299
383
  }
300
384
  }
@@ -1,17 +1,17 @@
1
1
  import { createTool } from "@mastra/core";
2
2
  import { z } from "zod";
3
3
  import { executeCodeDescription, executeCodeSchema } from "../ai";
4
- import { FreestyleExecuteScriptParamsConfiguration } from "../../openapi";
4
+ import type { FreestyleExecuteScriptParamsConfiguration } from "../../openapi";
5
5
  import { FreestyleSandboxes } from "..";
6
6
 
7
7
  export const executeTool = (
8
8
  config: FreestyleExecuteScriptParamsConfiguration & {
9
9
  apiKey: string;
10
- }
10
+ },
11
11
  ) => {
12
12
  const description = executeCodeDescription(
13
13
  Object.keys(config.envVars ?? {}).join(", "),
14
- Object.keys(config.nodeModules ?? {}).join(", ")
14
+ Object.keys(config.nodeModules ?? {}).join(", "),
15
15
  );
16
16
 
17
17
  const client = new FreestyleSandboxes({
@@ -21,16 +21,16 @@ export const executeTool = (
21
21
  return createTool({
22
22
  id: "Execute a TypeScript or JavaScript Script",
23
23
  description,
24
- inputSchema: executeCodeSchema,
25
24
  execute: async ({ context: { script } }) => {
26
25
  return await client.executeScript(script, config);
27
26
  },
27
+ inputSchema: executeCodeSchema,
28
28
  outputSchema: z.object({
29
29
  logs: z.array(
30
30
  z.object({
31
31
  message: z.string(),
32
32
  type: z.string(),
33
- })
33
+ }),
34
34
  ),
35
35
  result: z.unknown(),
36
36
  }),