freestyle-sandboxes 0.0.3 → 0.0.5

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/dist/ai/index.cjs CHANGED
@@ -68,8 +68,12 @@ ${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModule
68
68
  `)
69
69
  }),
70
70
  execute: async ({ files }) => {
71
+ const new_files = Object.keys(files).reduce((acc, key) => {
72
+ acc[key] = { content: files[key] };
73
+ return acc;
74
+ }, {});
71
75
  try {
72
- const res = await api.deployWeb(files, config);
76
+ const res = await api.deployWeb(new_files, config);
73
77
  return res;
74
78
  } catch (e) {
75
79
  console.log("ERROR: ", e.message);
@@ -1,5 +1,5 @@
1
1
  import * as ai from 'ai';
2
- import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, c as FreestyleDeployWebSuccessResponse } from '../types.gen-BoJEFWW-.js';
2
+ import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, c as FreestyleDeployWebSuccessResponse } from '../types.gen-DyY7Deri.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import * as ai from 'ai';
2
- import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, c as FreestyleDeployWebSuccessResponse } from '../types.gen-BoJEFWW-.js';
2
+ import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, c as FreestyleDeployWebSuccessResponse } from '../types.gen-DyY7Deri.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  /**
package/dist/ai/index.mjs CHANGED
@@ -66,8 +66,12 @@ ${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModule
66
66
  `)
67
67
  }),
68
68
  execute: async ({ files }) => {
69
+ const new_files = Object.keys(files).reduce((acc, key) => {
70
+ acc[key] = { content: files[key] };
71
+ return acc;
72
+ }, {});
69
73
  try {
70
- const res = await api.deployWeb(files, config);
74
+ const res = await api.deployWeb(new_files, config);
71
75
  return res;
72
76
  } catch (e) {
73
77
  console.log("ERROR: ", e.message);
package/dist/index.cjs CHANGED
@@ -85,7 +85,9 @@ ${JSON.stringify(
85
85
  if (response.data) {
86
86
  return response.data;
87
87
  } else {
88
- throw new Error("Failed to deploy Web project");
88
+ throw new Error(
89
+ `Failed to deploy web project: ${response.error?.message}`
90
+ );
89
91
  }
90
92
  }
91
93
  /**
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, b as FreestyleDeployWebConfiguration, c as FreestyleDeployWebSuccessResponse, d as FreestyleCloudstateDeployRequest, e as FreestyleCloudstateDeploySuccessResponse, H as HandleBackupCloudstateResponse, f as HandleGetLogsResponse } from './types.gen-BoJEFWW-.js';
1
+ import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, b as FreestyleDeployWebConfiguration, c as FreestyleDeployWebSuccessResponse, d as FreestyleCloudstateDeployRequest, e as FreestyleCloudstateDeploySuccessResponse, H as HandleBackupCloudstateResponse, f as HandleGetLogsResponse } from './types.gen-DyY7Deri.js';
2
+ export { g as FreestyleCloudstateDeployConfiguration, h as FreestyleCloudstateDeployErrorResponse, i as FreestyleDeployWebErrorResponse, j as FreestyleDeployWebPayload, k as FreestyleExecureScriptResultError, l as FreestyleExecuteScriptParams, m as FreestyleFile, n as FreestyleLogResponseObject, r as HandleBackupCloudstateError, o as HandleDeployCloudstateData, q as HandleDeployCloudstateError, p as HandleDeployCloudstateResponse, v as HandleDeployWebData, x as HandleDeployWebError, w as HandleDeployWebResponse, s as HandleExecuteScriptData, u as HandleExecuteScriptError, t as HandleExecuteScriptResponse, y as HandleGetLogsError } from './types.gen-DyY7Deri.js';
2
3
 
3
4
  declare class FreestyleSandboxes {
4
5
  private client;
@@ -19,7 +20,10 @@ declare class FreestyleSandboxes {
19
20
  /**
20
21
  * Deploy a Web project to a sandbox.
21
22
  */
22
- deployWeb(files: Record<string, string>, config?: FreestyleDeployWebConfiguration): Promise<FreestyleDeployWebSuccessResponse>;
23
+ deployWeb(files: Record<string, {
24
+ content: string;
25
+ encoding?: string;
26
+ }>, config?: FreestyleDeployWebConfiguration): Promise<FreestyleDeployWebSuccessResponse>;
23
27
  /**
24
28
  * Deploy a Cloudstate project to a sandbox.
25
29
  */
@@ -40,4 +44,4 @@ declare class FreestyleSandboxes {
40
44
  getWebLogs(id: string): Promise<HandleGetLogsResponse>;
41
45
  }
42
46
 
43
- export { FreestyleSandboxes };
47
+ export { FreestyleCloudstateDeployRequest, FreestyleCloudstateDeploySuccessResponse, FreestyleDeployWebConfiguration, FreestyleDeployWebSuccessResponse, FreestyleExecureScriptResultSuccess, FreestyleExecuteScriptParamsConfiguration, FreestyleSandboxes, HandleBackupCloudstateResponse, HandleGetLogsResponse };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, b as FreestyleDeployWebConfiguration, c as FreestyleDeployWebSuccessResponse, d as FreestyleCloudstateDeployRequest, e as FreestyleCloudstateDeploySuccessResponse, H as HandleBackupCloudstateResponse, f as HandleGetLogsResponse } from './types.gen-BoJEFWW-.js';
1
+ import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess, b as FreestyleDeployWebConfiguration, c as FreestyleDeployWebSuccessResponse, d as FreestyleCloudstateDeployRequest, e as FreestyleCloudstateDeploySuccessResponse, H as HandleBackupCloudstateResponse, f as HandleGetLogsResponse } from './types.gen-DyY7Deri.js';
2
+ export { g as FreestyleCloudstateDeployConfiguration, h as FreestyleCloudstateDeployErrorResponse, i as FreestyleDeployWebErrorResponse, j as FreestyleDeployWebPayload, k as FreestyleExecureScriptResultError, l as FreestyleExecuteScriptParams, m as FreestyleFile, n as FreestyleLogResponseObject, r as HandleBackupCloudstateError, o as HandleDeployCloudstateData, q as HandleDeployCloudstateError, p as HandleDeployCloudstateResponse, v as HandleDeployWebData, x as HandleDeployWebError, w as HandleDeployWebResponse, s as HandleExecuteScriptData, u as HandleExecuteScriptError, t as HandleExecuteScriptResponse, y as HandleGetLogsError } from './types.gen-DyY7Deri.js';
2
3
 
3
4
  declare class FreestyleSandboxes {
4
5
  private client;
@@ -19,7 +20,10 @@ declare class FreestyleSandboxes {
19
20
  /**
20
21
  * Deploy a Web project to a sandbox.
21
22
  */
22
- deployWeb(files: Record<string, string>, config?: FreestyleDeployWebConfiguration): Promise<FreestyleDeployWebSuccessResponse>;
23
+ deployWeb(files: Record<string, {
24
+ content: string;
25
+ encoding?: string;
26
+ }>, config?: FreestyleDeployWebConfiguration): Promise<FreestyleDeployWebSuccessResponse>;
23
27
  /**
24
28
  * Deploy a Cloudstate project to a sandbox.
25
29
  */
@@ -40,4 +44,4 @@ declare class FreestyleSandboxes {
40
44
  getWebLogs(id: string): Promise<HandleGetLogsResponse>;
41
45
  }
42
46
 
43
- export { FreestyleSandboxes };
47
+ export { FreestyleCloudstateDeployRequest, FreestyleCloudstateDeploySuccessResponse, FreestyleDeployWebConfiguration, FreestyleDeployWebSuccessResponse, FreestyleExecureScriptResultSuccess, FreestyleExecuteScriptParamsConfiguration, FreestyleSandboxes, HandleBackupCloudstateResponse, HandleGetLogsResponse };
package/dist/index.mjs CHANGED
@@ -83,7 +83,9 @@ ${JSON.stringify(
83
83
  if (response.data) {
84
84
  return response.data;
85
85
  } else {
86
- throw new Error("Failed to deploy Web project");
86
+ throw new Error(
87
+ `Failed to deploy web project: ${response.error?.message}`
88
+ );
87
89
  }
88
90
  }
89
91
  /**
@@ -10,6 +10,9 @@ type FreestyleCloudstateDeployConfiguration = {
10
10
  [key: string]: (string);
11
11
  };
12
12
  };
13
+ type FreestyleCloudstateDeployErrorResponse = {
14
+ message: string;
15
+ };
13
16
  type FreestyleCloudstateDeployRequest = {
14
17
  classes: string;
15
18
  config?: FreestyleCloudstateDeployConfiguration;
@@ -47,12 +50,36 @@ type FreestyleDeployWebConfiguration = {
47
50
  [key: string]: (string);
48
51
  } | null;
49
52
  };
53
+ type FreestyleDeployWebErrorResponse = {
54
+ message: string;
55
+ };
56
+ type FreestyleDeployWebPayload = {
57
+ /**
58
+ * The files to deploy, a map of file paths to file contents, e.g. { \"index.js\": {\"content\": \"your main\", \"encoding\": \"utf-8\"}, \"file2.js\": {\"content\": \"your helper\" } }
59
+ *
60
+ * **Do not include node modules in this bundle, they will not work**. Instead, includes a package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock, the node modules for the project will be installed from that lock file, or use the node_modules field in the configuration to specify the node modules to install.
61
+ */
62
+ files: {
63
+ [key: string]: FreestyleFile;
64
+ };
65
+ config?: FreestyleDeployWebConfiguration;
66
+ };
50
67
  type FreestyleDeployWebSuccessResponse = {
51
68
  projectId: string;
52
69
  };
70
+ type FreestyleExecureScriptResultError = {
71
+ error: string;
72
+ };
53
73
  type FreestyleExecureScriptResultSuccess = {
54
74
  result: unknown;
55
75
  };
76
+ type FreestyleExecuteScriptParams = {
77
+ /**
78
+ * The JavaScript or TypeScript script to execute
79
+ */
80
+ script: string;
81
+ config?: FreestyleExecuteScriptParamsConfiguration;
82
+ };
56
83
  type FreestyleExecuteScriptParamsConfiguration = {
57
84
  /**
58
85
  * The environment variables to set for the script
@@ -75,10 +102,37 @@ type FreestyleExecuteScriptParamsConfiguration = {
75
102
  */
76
103
  timeout?: (string) | null;
77
104
  };
105
+ type FreestyleFile = {
106
+ /**
107
+ * The content of the file
108
+ */
109
+ content: string;
110
+ /**
111
+ * The encoding of the file. Either **utf-8** or **base64**
112
+ */
113
+ encoding?: string;
114
+ };
78
115
  type FreestyleLogResponseObject = {
79
116
  message: string;
80
117
  };
118
+ type HandleDeployCloudstateData = {
119
+ body: FreestyleCloudstateDeployRequest;
120
+ };
121
+ type HandleDeployCloudstateResponse = (FreestyleCloudstateDeploySuccessResponse);
122
+ type HandleDeployCloudstateError = (FreestyleCloudstateDeployErrorResponse);
81
123
  type HandleBackupCloudstateResponse = (Array<(number)>);
124
+ type HandleBackupCloudstateError = (unknown);
125
+ type HandleExecuteScriptData = {
126
+ body: FreestyleExecuteScriptParams;
127
+ };
128
+ type HandleExecuteScriptResponse = (FreestyleExecureScriptResultSuccess);
129
+ type HandleExecuteScriptError = (FreestyleExecureScriptResultError);
130
+ type HandleDeployWebData = {
131
+ body: FreestyleDeployWebPayload;
132
+ };
133
+ type HandleDeployWebResponse = (FreestyleDeployWebSuccessResponse);
134
+ type HandleDeployWebError = (FreestyleDeployWebErrorResponse);
82
135
  type HandleGetLogsResponse = (Array<FreestyleLogResponseObject>);
136
+ type HandleGetLogsError = unknown;
83
137
 
84
- export type { FreestyleExecuteScriptParamsConfiguration as F, HandleBackupCloudstateResponse as H, FreestyleExecureScriptResultSuccess as a, FreestyleDeployWebConfiguration as b, FreestyleDeployWebSuccessResponse as c, FreestyleCloudstateDeployRequest as d, FreestyleCloudstateDeploySuccessResponse as e, HandleGetLogsResponse as f };
138
+ export type { FreestyleExecuteScriptParamsConfiguration as F, HandleBackupCloudstateResponse as H, FreestyleExecureScriptResultSuccess as a, FreestyleDeployWebConfiguration as b, FreestyleDeployWebSuccessResponse as c, FreestyleCloudstateDeployRequest as d, FreestyleCloudstateDeploySuccessResponse as e, HandleGetLogsResponse as f, FreestyleCloudstateDeployConfiguration as g, FreestyleCloudstateDeployErrorResponse as h, FreestyleDeployWebErrorResponse as i, FreestyleDeployWebPayload as j, FreestyleExecureScriptResultError as k, FreestyleExecuteScriptParams as l, FreestyleFile as m, FreestyleLogResponseObject as n, HandleDeployCloudstateData as o, HandleDeployCloudstateResponse as p, HandleDeployCloudstateError as q, HandleBackupCloudstateError as r, HandleExecuteScriptData as s, HandleExecuteScriptResponse as t, HandleExecuteScriptError as u, HandleDeployWebData as v, HandleDeployWebResponse as w, HandleDeployWebError as x, HandleGetLogsError as y };
@@ -63,12 +63,12 @@ export type FreestyleDeployWebErrorResponse = {
63
63
 
64
64
  export type FreestyleDeployWebPayload = {
65
65
  /**
66
- * The files to deploy, a map of file paths to file contents, e.g. { \"index.js\": \"your main", \"file2.js\": \"your helper\" }
66
+ * The files to deploy, a map of file paths to file contents, e.g. { \"index.js\": {\"content\": \"your main\", \"encoding\": \"utf-8\"}, \"file2.js\": {\"content\": \"your helper\" } }
67
67
  *
68
68
  * **Do not include node modules in this bundle, they will not work**. Instead, includes a package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock, the node modules for the project will be installed from that lock file, or use the node_modules field in the configuration to specify the node modules to install.
69
69
  */
70
70
  files: {
71
- [key: string]: (string);
71
+ [key: string]: FreestyleFile;
72
72
  };
73
73
  config?: FreestyleDeployWebConfiguration;
74
74
  };
@@ -116,6 +116,17 @@ export type FreestyleExecuteScriptParamsConfiguration = {
116
116
  timeout?: (string) | null;
117
117
  };
118
118
 
119
+ export type FreestyleFile = {
120
+ /**
121
+ * The content of the file
122
+ */
123
+ content: string;
124
+ /**
125
+ * The encoding of the file. Either **utf-8** or **base64**
126
+ */
127
+ encoding?: string;
128
+ };
129
+
119
130
  export type FreestyleLogResponseObject = {
120
131
  message: string;
121
132
  };
package/openapi.json CHANGED
@@ -1 +1,432 @@
1
- {"openapi":"3.1.0","info":{"title":"Freestyle Sandoxes","description":"\nFreestyle Sandboxes lets you deploy your users or AIs code.\n \nThey are broken up into 3 categories: [Web](#tag/web), [Execute](#tag/execute) and [Cloudstate](#tag/cloudstate).\n\n[Web](#tag/web): Send us the code for the website, we'll provision the certificates and get it hosted\n\n[Execute](#tag/execute): Send us a function, we'll run it and send you the output\n\n[Cloudstate](#tag/cloudstate): Our Opensource JavaScript Runtime used for cloud functions with persistent state\n","contact":{"name":"Ben","email":"ben@freestyle.sh"},"license":{"name":""},"version":"0.1.0"},"servers":[{"url":"https://api.freestyle.sh","description":"Production"}],"paths":{"/cloudstate/v1/deploy":{"post":{"tags":["Cloudstate"],"summary":"Deploy Cloudstate Project","description":"Deploy a cloudstate project","operationId":"handle_deploy_cloudstate","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeployRequest"}}},"required":true},"responses":{"200":{"description":"successfully deployed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeploySuccessResponse"}}}},"500":{"description":"failed to deploy","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeployErrorResponse"}}}}}}},"/cloudstate/v1/projects/:id/backup":{"get":{"tags":["Cloudstate"],"summary":"Get Backup of Cloudstate Project","description":"Get a backup of a cloudstate project","operationId":"handle_backup_cloudstate","responses":{"200":{"description":"successfully backed up","content":{"application/octet-stream":{"schema":{"type":"array","items":{"type":"integer","format":"int32","minimum":0}}}}},"500":{"description":"failed to backup"}}}},"/execute/v1/script":{"post":{"tags":["Execute"],"summary":"Execute Code","description":"Send a TypeScript or JavaScript module, get the result","operationId":"handle_execute_script","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleExecuteScriptParams"}}},"required":true},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleExecureScriptResultSuccess"}}}},"400":{"description":"Error in your Script","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleExecureScriptResultError"}}}},"500":{"description":"Internal Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleExecureScriptResultError"}}}}}}},"/web/v1/deploy":{"post":{"tags":["Web"],"summary":"Deploy a Website","description":"Deploy a website. Files is a map of file paths to file contents. Configuration is optional and contains additional information about the deployment.","operationId":"handle_deploy_web","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebPayload"}}},"required":true},"responses":{"200":{"description":"successfully deployed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebSuccessResponse"}}}},"400":{"description":"failed to deploy","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebErrorResponse"}}}}}}},"/web/v1/projects/:id/logs":{"get":{"tags":["Web"],"summary":"Get Website Logs","description":"Get the logs for a project","operationId":"handle_get_logs","responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/FreestyleLogResponseObject"}}}}}}}}},"components":{"schemas":{"FreestyleCloudstateDeployConfiguration":{"type":"object","properties":{"projectId":{"type":["string","null"],"description":"ID of the project to deploy, if not provided will create a new project","default":null},"envVars":{"type":"object","description":"The environment variables that the cloudstate deploy can access","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}}}},"FreestyleCloudstateDeployErrorResponse":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}},"FreestyleCloudstateDeployRequest":{"type":"object","required":["classes"],"properties":{"classes":{"type":"string"},"config":{"$ref":"#/components/schemas/FreestyleCloudstateDeployConfiguration"}}},"FreestyleCloudstateDeploySuccessResponse":{"type":"object","required":["projectId"],"properties":{"projectId":{"type":"string","description":"The id of the project deployed to"}}},"FreestyleDeployWebConfiguration":{"type":"object","properties":{"entrypoint":{"type":["string","null"],"description":"The entrypoint file for the website","default":"index.js"},"domains":{"type":["array","null"],"items":{"type":"string"},"description":"The custom domains for the website, eg. [\\\"subdomain.yourwebsite.com\\\"]. You may not include *.style.dev domains here, those are reserved for projectIds","example":["subdomain.yourdomain.com"],"default":null},"projectId":{"type":["string","null"],"description":"The project id to deploy to, if not provided will create a new project, may be used to provision a new project with a specific id if that id is available","default":null},"nodeModules":{"type":["object","null"],"description":"Node Modules to install for the website, a map of package names to versions, e.g. { \\\"express\\\": \\\"4.17.1\\\" }. If this and a package-lock.json are provided, the package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock is also provided, the versions here will override the versions in those lock files.","default":null,"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"resend":"4.0.1"}},"envVars":{"type":["object","null"],"description":"The environment variables that the website can access\ne.g. { \\\"RESEND_API_KEY\\\": \\\"re_123456789\\\" }","default":null,"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"RESEND_API_KEY":"re_123456789"}}}},"FreestyleDeployWebErrorResponse":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}},"FreestyleDeployWebPayload":{"type":"object","required":["files"],"properties":{"files":{"type":"object","description":"The files to deploy, a map of file paths to file contents, e.g. { \\\"index.js\\\": \\\"your main\", \\\"file2.js\\\": \\\"your helper\\\" }\n\n**Do not include node modules in this bundle, they will not work**. Instead, includes a package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock, the node modules for the project will be installed from that lock file, or use the node_modules field in the configuration to specify the node modules to install.","additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"index.js":"import http from 'node:http';\\n// import { resolver } from './file2.js';\\n\\nconsole.log('starting server');\\n\\nconst server = http.createServer(async(req, res) => {\\n // wait 5 seconds before responding\\n // await new Promise((resolve) => setTimeout(resolve, 5000));\\n res.writeHead(200, { 'Content-Type': 'text/plain' });\\n res.end('Welcome to New York its been waiting for you');\\n});\\n\\nserver.listen(3000, () => {\\n console.log('Server is running at http://localhost:3000');\\n});"}},"config":{"$ref":"#/components/schemas/FreestyleDeployWebConfiguration"}}},"FreestyleDeployWebSuccessResponse":{"type":"object","required":["projectId"],"properties":{"projectId":{"type":"string"}}},"FreestyleExecureScriptResultError":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}},"FreestyleExecureScriptResultSuccess":{"type":"object","required":["result"],"properties":{"result":{}}},"FreestyleExecuteScriptParams":{"type":"object","required":["script"],"properties":{"script":{"type":"string","description":"The JavaScript or TypeScript script to execute","example":"export default () => {\n // get the value of the factorials of the numbers from 1 to 10 combined\n const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n function factorial(n) {\n if (n === 0) {\n return 1;\n }\n return n * factorial(n - 1);\n }\n\n const b = a.map(factorial);\n\n return b.reduce((a, b) => a + b);\n};\n"},"config":{"$ref":"#/components/schemas/FreestyleExecuteScriptParamsConfiguration"}}},"FreestyleExecuteScriptParamsConfiguration":{"type":"object","properties":{"envVars":{"type":"object","description":"The environment variables to set for the script","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"RESEND_API_KEY":"re_123456789"}},"nodeModules":{"type":"object","description":"The node modules to install for the script","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"resend":"4.0.1"}},"tags":{"type":"array","items":{"type":"string"},"description":"Tags for you to organize your scripts, useful for tracking what you're running","example":["email"],"default":[]},"timeout":{"type":["string","null"],"description":"The script timeout","default":null}}},"FreestyleLogResponseObject":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}},"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"tags":[{"name":"Web","description":"APIs for deploying websites. We handle node modules caching, scaling, certificates and the whole end to end process. Send the code using the [deploy](#tag/web/POST/web/v1/deploy) endpoint, and you'll get a full hosted website back. Works with any TypeScript or JavaScript codebase."},{"name":"Execute","description":"APIs for running code. Send the code using the [execute](#tag/execute/POST/execute/v1/execute) endpoint, and you'll get the output back. Works with any TypeScript or JavaScript code + handles any node modules and environment variables you want."},{"name":"Cloudstate","description":"APIs for running cloud functions with persistent state. [Cloudstate](https://github.com/freestyle-sh/cloudstate/) is an opensource, durable JavaScript runtime maintained by the Freestyle Team."}]}
1
+ {
2
+ "openapi": "3.1.0",
3
+ "info": {
4
+ "title": "Freestyle Sandboxes",
5
+ "description": "\nFreestyle Sandboxes lets you deploy your users or AIs code.\n \nThey are broken up into 3 categories: [Web](#tag/web), [Execute](#tag/execute) and [Cloudstate](#tag/cloudstate).\n\n[Web](#tag/web): Send us the code for the website, we'll provision the certificates and get it hosted\n\n[Execute](#tag/execute): Send us a function, we'll run it and send you the output\n\n[Cloudstate](#tag/cloudstate): Our Opensource JavaScript Runtime used for cloud functions with persistent state\n",
6
+ "contact": { "name": "Ben", "email": "ben@freestyle.sh" },
7
+ "license": { "name": "" },
8
+ "version": "0.1.0"
9
+ },
10
+ "servers": [
11
+ { "url": "https://api.freestyle.sh", "description": "Production" }
12
+ ],
13
+ "paths": {
14
+ "/cloudstate/v1/deploy": {
15
+ "post": {
16
+ "tags": ["Cloudstate"],
17
+ "summary": "Deploy Cloudstate Project",
18
+ "description": "Deploy a cloudstate project",
19
+ "operationId": "handle_deploy_cloudstate",
20
+ "requestBody": {
21
+ "content": {
22
+ "application/json": {
23
+ "schema": {
24
+ "$ref": "#/components/schemas/FreestyleCloudstateDeployRequest"
25
+ }
26
+ }
27
+ },
28
+ "required": true
29
+ },
30
+ "responses": {
31
+ "200": {
32
+ "description": "successfully deployed",
33
+ "content": {
34
+ "application/json": {
35
+ "schema": {
36
+ "$ref": "#/components/schemas/FreestyleCloudstateDeploySuccessResponse"
37
+ }
38
+ }
39
+ }
40
+ },
41
+ "500": {
42
+ "description": "failed to deploy",
43
+ "content": {
44
+ "application/json": {
45
+ "schema": {
46
+ "$ref": "#/components/schemas/FreestyleCloudstateDeployErrorResponse"
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ },
54
+ "/cloudstate/v1/projects/:id/backup": {
55
+ "get": {
56
+ "tags": ["Cloudstate"],
57
+ "summary": "Get Backup of Cloudstate Project",
58
+ "description": "Get a backup of a cloudstate project",
59
+ "operationId": "handle_backup_cloudstate",
60
+ "responses": {
61
+ "200": {
62
+ "description": "successfully backed up",
63
+ "content": {
64
+ "application/octet-stream": {
65
+ "schema": {
66
+ "type": "array",
67
+ "items": {
68
+ "type": "integer",
69
+ "format": "int32",
70
+ "minimum": 0
71
+ }
72
+ }
73
+ }
74
+ }
75
+ },
76
+ "500": { "description": "failed to backup" }
77
+ }
78
+ }
79
+ },
80
+ "/execute/v1/script": {
81
+ "post": {
82
+ "tags": ["Execute"],
83
+ "summary": "Execute Code",
84
+ "description": "Send a TypeScript or JavaScript module, get the result",
85
+ "operationId": "handle_execute_script",
86
+ "requestBody": {
87
+ "content": {
88
+ "application/json": {
89
+ "schema": {
90
+ "$ref": "#/components/schemas/FreestyleExecuteScriptParams"
91
+ }
92
+ }
93
+ },
94
+ "required": true
95
+ },
96
+ "responses": {
97
+ "200": {
98
+ "description": "Success",
99
+ "content": {
100
+ "application/json": {
101
+ "schema": {
102
+ "$ref": "#/components/schemas/FreestyleExecureScriptResultSuccess"
103
+ }
104
+ }
105
+ }
106
+ },
107
+ "400": {
108
+ "description": "Error in your Script",
109
+ "content": {
110
+ "application/json": {
111
+ "schema": {
112
+ "$ref": "#/components/schemas/FreestyleExecureScriptResultError"
113
+ }
114
+ }
115
+ }
116
+ },
117
+ "500": {
118
+ "description": "Internal Error",
119
+ "content": {
120
+ "application/json": {
121
+ "schema": {
122
+ "$ref": "#/components/schemas/FreestyleExecureScriptResultError"
123
+ }
124
+ }
125
+ }
126
+ }
127
+ },
128
+ "x-codeSamples": [
129
+ {
130
+ "label": "Human SDK",
131
+ "lang": "JavaScript",
132
+ "source": "import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.executeScript(\n `export default () => {\n let set1 = [1, 2, 3, 4, 5];\n let set2 = [4, 5, 6, 7, 8];\n\n // find the sum of every value of each set multiplied by every value of the other set\n\n let sum = 0;\n for (let i = 0; i < set1.length; i++) {\n for (let j = 0; j < set2.length; j++) {\n sum += set1[i] * set2[j];\n }\n }\n\n return sum;\n};`\n);"
133
+ },
134
+ {
135
+ "label": "AI SDK",
136
+ "lang": "JavaScript",
137
+ "source": "import { executeTool } from 'freestyle-sandboxes/ai';\nimport { generateText } from 'ai';\n\nconst codeExecutor = executeTool({\n apiKey: 'your-api-key',\n});\n\nconst { text, steps } = await generateText({\n model: yourModel,\n tools: {\n codeExecutor,\n },\n maxSteps: 2,\n prompt:\n 'What is the sum of every number between 1 and 12 multiplied by itself?',\n});"
138
+ }
139
+ ]
140
+ }
141
+ },
142
+ "/web/v1/deploy": {
143
+ "post": {
144
+ "tags": ["Web"],
145
+ "summary": "Deploy a Website",
146
+ "description": "Deploy a website. Files is a map of file paths to file contents. Configuration is optional and contains additional information about the deployment.",
147
+ "operationId": "handle_deploy_web",
148
+ "requestBody": {
149
+ "content": {
150
+ "application/json": {
151
+ "schema": {
152
+ "$ref": "#/components/schemas/FreestyleDeployWebPayload"
153
+ }
154
+ }
155
+ },
156
+ "required": true
157
+ },
158
+ "responses": {
159
+ "200": {
160
+ "description": "successfully deployed",
161
+ "content": {
162
+ "application/json": {
163
+ "schema": {
164
+ "$ref": "#/components/schemas/FreestyleDeployWebSuccessResponse"
165
+ }
166
+ }
167
+ }
168
+ },
169
+ "400": {
170
+ "description": "failed to deploy",
171
+ "content": {
172
+ "application/json": {
173
+ "schema": {
174
+ "$ref": "#/components/schemas/FreestyleDeployWebErrorResponse"
175
+ }
176
+ }
177
+ }
178
+ }
179
+ },
180
+ "x-codeSamples": [
181
+ {
182
+ "label": "Human SDK",
183
+ "lang": "JavaScript",
184
+ "source": "import { FreestyleSandboxes } from 'freestyle-sandboxes';\nimport 'dotenv/config';\n\nconst api = new FreestyleSandboxes({\n apiKey: process.env.FREESTYLE_API_KEY!,\n});\n\napi\n .deployWeb({\n 'index.js': `\n import http from 'node:http';\n console.log('starting server');\n\n const server = http.createServer(async(req, res) => {\n // wait 5 seconds before responding\n // await new Promise((resolve) => setTimeout(resolve, 5000));\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end('Welcome to New York its been waiting for you');\n });\n\n server.listen(3000, () => {\n console.log('Server is running at http://localhost:3000');\n });`,\n })\n .then((result) => {\n console.log('Deployed website @ ', result.projectId);\n });\n"
185
+ },
186
+ {
187
+ "label": "AI SDK",
188
+ "lang": "JavaScript",
189
+ "source": "import { deployWebTool } from 'freestyle-sandboxes/ai';\nimport { generateText } from 'ai';\n\nconst deployer = deployWebTool({\n apiKey: 'your-api-key',\n});\n\nconst { text, steps } = await generateText({\n model: yourModel,\n tools: {\n deployer,\n },\n maxSteps: 2,\n prompt:\n 'Deploy a website to subdomain.yourdomain.com that has all the lyrics to Sandstorm by Darude on the homepage',\n});"
190
+ }
191
+ ]
192
+ }
193
+ },
194
+ "/web/v1/projects/:id/logs": {
195
+ "get": {
196
+ "tags": ["Web"],
197
+ "summary": "Get Website Logs",
198
+ "description": "Get the logs for a project",
199
+ "operationId": "handle_get_logs",
200
+ "responses": {
201
+ "200": {
202
+ "description": "",
203
+ "content": {
204
+ "application/json": {
205
+ "schema": {
206
+ "type": "array",
207
+ "items": {
208
+ "$ref": "#/components/schemas/FreestyleLogResponseObject"
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
214
+ },
215
+ "x-codeSamples": [
216
+ {
217
+ "label": "Human SDK",
218
+ "lang": "JavaScript",
219
+ "source": "import { FreestyleSandboxes } from 'freestyle-sandboxes';\nimport 'dotenv/config';\n\nconst api = new FreestyleSandboxes({\n apiKey: process.env.FREESTYLE_API_KEY!,\n});\n\napi.getWebLogs('1234abcd-5678-efgh-ijkl-9012mnop3456').then((logs) => {\n console.log('Logs for project 1234abcd-5678-efgh-ijkl-9012mnop3456: ', logs);\n});"
220
+ }
221
+ ]
222
+ }
223
+ }
224
+ },
225
+ "components": {
226
+ "schemas": {
227
+ "FreestyleCloudstateDeployConfiguration": {
228
+ "type": "object",
229
+ "properties": {
230
+ "projectId": {
231
+ "type": ["string", "null"],
232
+ "description": "ID of the project to deploy, if not provided will create a new project",
233
+ "default": null
234
+ },
235
+ "envVars": {
236
+ "type": "object",
237
+ "description": "The environment variables that the cloudstate deploy can access",
238
+ "default": {},
239
+ "additionalProperties": { "type": "string" },
240
+ "propertyNames": { "type": "string" }
241
+ }
242
+ }
243
+ },
244
+ "FreestyleCloudstateDeployErrorResponse": {
245
+ "type": "object",
246
+ "required": ["message"],
247
+ "properties": { "message": { "type": "string" } }
248
+ },
249
+ "FreestyleCloudstateDeployRequest": {
250
+ "type": "object",
251
+ "required": ["classes"],
252
+ "properties": {
253
+ "classes": { "type": "string" },
254
+ "config": {
255
+ "$ref": "#/components/schemas/FreestyleCloudstateDeployConfiguration"
256
+ }
257
+ }
258
+ },
259
+ "FreestyleCloudstateDeploySuccessResponse": {
260
+ "type": "object",
261
+ "required": ["projectId"],
262
+ "properties": {
263
+ "projectId": {
264
+ "type": "string",
265
+ "description": "The id of the project deployed to"
266
+ }
267
+ }
268
+ },
269
+ "FreestyleDeployWebConfiguration": {
270
+ "type": "object",
271
+ "properties": {
272
+ "entrypoint": {
273
+ "type": ["string", "null"],
274
+ "description": "The entrypoint file for the website",
275
+ "default": "index.js"
276
+ },
277
+ "domains": {
278
+ "type": ["array", "null"],
279
+ "items": { "type": "string" },
280
+ "description": "The custom domains for the website, eg. [\\\"subdomain.yourwebsite.com\\\"]. You may not include *.style.dev domains here, those are reserved for projectIds",
281
+ "example": ["subdomain.yourdomain.com"],
282
+ "default": null
283
+ },
284
+ "projectId": {
285
+ "type": ["string", "null"],
286
+ "description": "The project id to deploy to, if not provided will create a new project, may be used to provision a new project with a specific id if that id is available",
287
+ "default": null
288
+ },
289
+ "nodeModules": {
290
+ "type": ["object", "null"],
291
+ "description": "Node Modules to install for the website, a map of package names to versions, e.g. { \\\"express\\\": \\\"4.17.1\\\" }. If this and a package-lock.json are provided, the package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock is also provided, the versions here will override the versions in those lock files.",
292
+ "default": null,
293
+ "additionalProperties": { "type": "string" },
294
+ "propertyNames": { "type": "string" },
295
+ "example": { "resend": "4.0.1" }
296
+ },
297
+ "envVars": {
298
+ "type": ["object", "null"],
299
+ "description": "The environment variables that the website can access\ne.g. { \\\"RESEND_API_KEY\\\": \\\"re_123456789\\\" }",
300
+ "default": null,
301
+ "additionalProperties": { "type": "string" },
302
+ "propertyNames": { "type": "string" },
303
+ "example": { "RESEND_API_KEY": "re_123456789" }
304
+ }
305
+ }
306
+ },
307
+ "FreestyleDeployWebErrorResponse": {
308
+ "type": "object",
309
+ "required": ["message"],
310
+ "properties": { "message": { "type": "string" } }
311
+ },
312
+ "FreestyleDeployWebPayload": {
313
+ "type": "object",
314
+ "required": ["files"],
315
+ "properties": {
316
+ "files": {
317
+ "type": "object",
318
+ "description": "The files to deploy, a map of file paths to file contents, e.g. { \\\"index.js\\\": {\\\"content\\\": \\\"your main\\\", \\\"encoding\\\": \\\"utf-8\\\"}, \\\"file2.js\\\": {\\\"content\\\": \\\"your helper\\\" } }\n\n**Do not include node modules in this bundle, they will not work**. Instead, includes a package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock, the node modules for the project will be installed from that lock file, or use the node_modules field in the configuration to specify the node modules to install.",
319
+ "additionalProperties": {
320
+ "$ref": "#/components/schemas/FreestyleFile"
321
+ },
322
+ "propertyNames": { "type": "string" },
323
+ "example": {
324
+ "index.js": {
325
+ "content": "import http from 'node:http';\\n// import { resolver } from './file2.js';\\n\\nconsole.log('starting server');\\n\\nconst server = http.createServer(async(req, res) => {\\n // wait 5 seconds before responding\\n // await new Promise((resolve) => setTimeout(resolve, 5000));\\n res.writeHead(200, { 'Content-Type': 'text/plain' });\\n res.end('Welcome to New York its been waiting for you');\\n});\\n\\nserver.listen(3000, () => {\\n console.log('Server is running at http://localhost:3000');\\n});"
326
+ }
327
+ }
328
+ },
329
+ "config": {
330
+ "$ref": "#/components/schemas/FreestyleDeployWebConfiguration"
331
+ }
332
+ }
333
+ },
334
+ "FreestyleDeployWebSuccessResponse": {
335
+ "type": "object",
336
+ "required": ["projectId"],
337
+ "properties": { "projectId": { "type": "string" } }
338
+ },
339
+ "FreestyleExecureScriptResultError": {
340
+ "type": "object",
341
+ "required": ["error"],
342
+ "properties": { "error": { "type": "string" } }
343
+ },
344
+ "FreestyleExecureScriptResultSuccess": {
345
+ "type": "object",
346
+ "required": ["result"],
347
+ "properties": { "result": {} }
348
+ },
349
+ "FreestyleExecuteScriptParams": {
350
+ "type": "object",
351
+ "required": ["script"],
352
+ "properties": {
353
+ "script": {
354
+ "type": "string",
355
+ "description": "The JavaScript or TypeScript script to execute",
356
+ "example": "export default () => {\n // get the value of the factorials of the numbers from 1 to 10 combined\n const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n function factorial(n) {\n if (n === 0) {\n return 1;\n }\n return n * factorial(n - 1);\n }\n\n const b = a.map(factorial);\n\n return b.reduce((a, b) => a + b);\n};\n"
357
+ },
358
+ "config": {
359
+ "$ref": "#/components/schemas/FreestyleExecuteScriptParamsConfiguration"
360
+ }
361
+ }
362
+ },
363
+ "FreestyleExecuteScriptParamsConfiguration": {
364
+ "type": "object",
365
+ "properties": {
366
+ "envVars": {
367
+ "type": "object",
368
+ "description": "The environment variables to set for the script",
369
+ "default": {},
370
+ "additionalProperties": { "type": "string" },
371
+ "propertyNames": { "type": "string" },
372
+ "example": { "RESEND_API_KEY": "re_123456789" }
373
+ },
374
+ "nodeModules": {
375
+ "type": "object",
376
+ "description": "The node modules to install for the script",
377
+ "default": {},
378
+ "additionalProperties": { "type": "string" },
379
+ "propertyNames": { "type": "string" },
380
+ "example": { "resend": "4.0.1" }
381
+ },
382
+ "tags": {
383
+ "type": "array",
384
+ "items": { "type": "string" },
385
+ "description": "Tags for you to organize your scripts, useful for tracking what you're running",
386
+ "example": ["email"],
387
+ "default": []
388
+ },
389
+ "timeout": {
390
+ "type": ["string", "null"],
391
+ "description": "The script timeout",
392
+ "default": null
393
+ }
394
+ }
395
+ },
396
+ "FreestyleFile": {
397
+ "type": "object",
398
+ "required": ["content"],
399
+ "properties": {
400
+ "content": {
401
+ "type": "string",
402
+ "description": "The content of the file"
403
+ },
404
+ "encoding": {
405
+ "type": "string",
406
+ "description": "The encoding of the file. Either **utf-8** or **base64**"
407
+ }
408
+ }
409
+ },
410
+ "FreestyleLogResponseObject": {
411
+ "type": "object",
412
+ "required": ["message"],
413
+ "properties": { "message": { "type": "string" } }
414
+ }
415
+ },
416
+ "securitySchemes": { "bearerAuth": { "type": "http", "scheme": "bearer" } }
417
+ },
418
+ "tags": [
419
+ {
420
+ "name": "Web",
421
+ "description": "APIs for deploying websites. We handle node modules caching, scaling, certificates and the whole end to end process. Send the code using the [deploy](#tag/web/POST/web/v1/deploy) endpoint, and you'll get a full hosted website back. Works with any TypeScript or JavaScript codebase."
422
+ },
423
+ {
424
+ "name": "Execute",
425
+ "description": "APIs for running code. Send the code using the [execute](#tag/execute/POST/execute/v1/execute) endpoint, and you'll get the output back. Works with any TypeScript or JavaScript code + handles any node modules and environment variables you want."
426
+ },
427
+ {
428
+ "name": "Cloudstate",
429
+ "description": "APIs for running cloud functions with persistent state. [Cloudstate](https://github.com/freestyle-sh/cloudstate/) is an opensource, durable JavaScript runtime maintained by the Freestyle Team."
430
+ }
431
+ ]
432
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle-sandboxes",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -42,6 +42,9 @@
42
42
  "dependencies": {
43
43
  "@hey-api/client-fetch": "^0.5.7",
44
44
  "ai": "^4.0.25",
45
+ "humanlayer": "^0.7.0",
46
+ "openai": "^4.77.3",
47
+ "openapi": "^1.0.1",
45
48
  "zod": "^3.24.1"
46
49
  }
47
50
  }
package/src/ai/index.ts CHANGED
@@ -99,8 +99,13 @@ export const deployWebTool = (
99
99
  `),
100
100
  }),
101
101
  execute: async ({ files }) => {
102
+ // map from record<string, string> to record<string, {content: string}>
103
+ const new_files = Object.keys(files).reduce((acc, key) => {
104
+ acc[key] = { content: files[key] };
105
+ return acc;
106
+ }, {} as Record<string, { content: string }>);
102
107
  try {
103
- const res = await api.deployWeb(files, config);
108
+ const res = await api.deployWeb(new_files, config);
104
109
  return res;
105
110
  } catch (e) {
106
111
  console.log("ERROR: ", e.message);
package/src/index.ts CHANGED
@@ -50,7 +50,13 @@ export class FreestyleSandboxes {
50
50
  * Deploy a Web project to a sandbox.
51
51
  */
52
52
  async deployWeb(
53
- files: Record<string, string>,
53
+ files: Record<
54
+ string,
55
+ {
56
+ content: string;
57
+ encoding?: string;
58
+ }
59
+ >,
54
60
  config?: sandbox_openapi.FreestyleDeployWebConfiguration
55
61
  ): Promise<sandbox_openapi.FreestyleDeployWebSuccessResponse> {
56
62
  const response = await sandbox_openapi.handleDeployWeb({
@@ -63,7 +69,9 @@ export class FreestyleSandboxes {
63
69
  if (response.data) {
64
70
  return response.data;
65
71
  } else {
66
- throw new Error("Failed to deploy Web project");
72
+ throw new Error(
73
+ `Failed to deploy web project: ${response.error?.message}`
74
+ );
67
75
  }
68
76
  }
69
77
 
@@ -126,3 +134,5 @@ export class FreestyleSandboxes {
126
134
  }
127
135
  }
128
136
  }
137
+
138
+ export * from "../openapi/types.gen.ts";