freestyle-sandboxes 0.0.1

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.
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var index = require('../index.cjs');
4
+ var ai = require('ai');
5
+ var zod = require('zod');
6
+ require('@hey-api/client-fetch');
7
+
8
+ const executeTool = (config) => {
9
+ const api = new index.FreestyleSandboxes({
10
+ apiKey: config.apiKey
11
+ });
12
+ return ai.tool({
13
+ description: "Execute a JavaScript or TypeScript script",
14
+ parameters: zod.z.object({
15
+ script: zod.z.string().describe(`
16
+ The JavaScript or TypeScript script to execute, must be in the format of:
17
+
18
+ export default () => {
19
+ ... your code here ...
20
+ return output;
21
+ }
22
+
23
+ or for async functions:
24
+
25
+ export default async () => {
26
+ ... your code here ...
27
+ return output;
28
+ }
29
+ `)
30
+ }),
31
+ execute: async ({ script }) => {
32
+ return api.executeScript(script, config);
33
+ }
34
+ });
35
+ };
36
+
37
+ exports.executeTool = executeTool;
@@ -0,0 +1,29 @@
1
+ import * as ai from 'ai';
2
+ import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess } from '../types.gen-BoJEFWW-.js';
3
+ import { z } from 'zod';
4
+
5
+ /**
6
+ * Execute a JavaScript or TypeScript script
7
+ *
8
+ * **Note: Unless you tell it, the AI won't be aware of any node_modules or environment variables you give it, you need to tell it in your prompt what it can use.**
9
+
10
+ *
11
+ * @param config - Configuration for the tool
12
+ * @param config.apiKey - The API key to use
13
+ *
14
+ */
15
+ declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration & {
16
+ apiKey: string;
17
+ }) => ai.CoreTool<z.ZodObject<{
18
+ script: z.ZodString;
19
+ }, "strip", z.ZodTypeAny, {
20
+ script?: string;
21
+ }, {
22
+ script?: string;
23
+ }>, FreestyleExecureScriptResultSuccess> & {
24
+ execute: (args: {
25
+ script?: string;
26
+ }, options: ai.ToolExecutionOptions) => PromiseLike<FreestyleExecureScriptResultSuccess>;
27
+ };
28
+
29
+ export { executeTool };
@@ -0,0 +1,29 @@
1
+ import * as ai from 'ai';
2
+ import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecureScriptResultSuccess } from '../types.gen-BoJEFWW-.js';
3
+ import { z } from 'zod';
4
+
5
+ /**
6
+ * Execute a JavaScript or TypeScript script
7
+ *
8
+ * **Note: Unless you tell it, the AI won't be aware of any node_modules or environment variables you give it, you need to tell it in your prompt what it can use.**
9
+
10
+ *
11
+ * @param config - Configuration for the tool
12
+ * @param config.apiKey - The API key to use
13
+ *
14
+ */
15
+ declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration & {
16
+ apiKey: string;
17
+ }) => ai.CoreTool<z.ZodObject<{
18
+ script: z.ZodString;
19
+ }, "strip", z.ZodTypeAny, {
20
+ script?: string;
21
+ }, {
22
+ script?: string;
23
+ }>, FreestyleExecureScriptResultSuccess> & {
24
+ execute: (args: {
25
+ script?: string;
26
+ }, options: ai.ToolExecutionOptions) => PromiseLike<FreestyleExecureScriptResultSuccess>;
27
+ };
28
+
29
+ export { executeTool };
@@ -0,0 +1,35 @@
1
+ import { FreestyleSandboxes } from '../index.mjs';
2
+ import { tool } from 'ai';
3
+ import { z } from 'zod';
4
+ import '@hey-api/client-fetch';
5
+
6
+ const executeTool = (config) => {
7
+ const api = new FreestyleSandboxes({
8
+ apiKey: config.apiKey
9
+ });
10
+ return tool({
11
+ description: "Execute a JavaScript or TypeScript script",
12
+ parameters: z.object({
13
+ script: z.string().describe(`
14
+ The JavaScript or TypeScript script to execute, must be in the format of:
15
+
16
+ export default () => {
17
+ ... your code here ...
18
+ return output;
19
+ }
20
+
21
+ or for async functions:
22
+
23
+ export default async () => {
24
+ ... your code here ...
25
+ return output;
26
+ }
27
+ `)
28
+ }),
29
+ execute: async ({ script }) => {
30
+ return api.executeScript(script, config);
31
+ }
32
+ });
33
+ };
34
+
35
+ export { executeTool };
package/dist/index.cjs ADDED
@@ -0,0 +1,135 @@
1
+ 'use strict';
2
+
3
+ var clientFetch = require('@hey-api/client-fetch');
4
+
5
+ const client = clientFetch.createClient(clientFetch.createConfig());
6
+ const handleDeployCloudstate = (options) => {
7
+ return (options?.client ?? client).post({
8
+ ...options,
9
+ url: "/cloudstate/v1/deploy"
10
+ });
11
+ };
12
+ const handleBackupCloudstate = (options) => {
13
+ return (options?.client ?? client).get({
14
+ ...options,
15
+ url: "/cloudstate/v1/projects/:id/backup"
16
+ });
17
+ };
18
+ const handleExecuteScript = (options) => {
19
+ return (options?.client ?? client).post({
20
+ ...options,
21
+ url: "/execute/v1/script"
22
+ });
23
+ };
24
+ const handleDeployWeb = (options) => {
25
+ return (options?.client ?? client).post({
26
+ ...options,
27
+ url: "/web/v1/deploy"
28
+ });
29
+ };
30
+ const handleGetLogs = (options) => {
31
+ return (options?.client ?? client).get({
32
+ ...options,
33
+ url: "/web/v1/projects/:id/logs"
34
+ });
35
+ };
36
+
37
+ class FreestyleSandboxes {
38
+ client;
39
+ constructor(options) {
40
+ this.client = clientFetch.createClient({
41
+ baseUrl: options.baseUrl ?? "https://api.freestyle.sh",
42
+ headers: {
43
+ Authorization: `Bearer ${options.apiKey}`
44
+ }
45
+ });
46
+ }
47
+ /**
48
+ * Execute a script in a sandbox.
49
+ */
50
+ async executeScript(script, config) {
51
+ const response = await handleExecuteScript({
52
+ client: this.client,
53
+ body: {
54
+ script,
55
+ config
56
+ }
57
+ });
58
+ if (response.data) {
59
+ return response.data;
60
+ } else {
61
+ throw new Error("Failed to execute script");
62
+ }
63
+ }
64
+ /**
65
+ * Deploy a Web project to a sandbox.
66
+ */
67
+ async deployWeb(files, config) {
68
+ const response = await handleDeployWeb({
69
+ client: this.client,
70
+ body: {
71
+ files,
72
+ config
73
+ }
74
+ });
75
+ if (response.data) {
76
+ return response.data;
77
+ } else {
78
+ throw new Error("Failed to deploy Web project");
79
+ }
80
+ }
81
+ /**
82
+ * Deploy a Cloudstate project to a sandbox.
83
+ */
84
+ async deployCloudstate(body) {
85
+ const response = await handleDeployCloudstate({
86
+ client: this.client,
87
+ body
88
+ });
89
+ if (response.data) {
90
+ return response.data;
91
+ } else {
92
+ throw new Error("Failed to deploy Cloudstate project");
93
+ }
94
+ }
95
+ /**
96
+ * Get a backup of a Cloudstate project in a sandbox.
97
+ * @param id The ID of the Cloudstate project.
98
+ * @returns The backup of the Cloudstate project.
99
+ * @throws An error if the backup could not be retrieved.
100
+ */
101
+ async backupCloudstate(id) {
102
+ const response = await handleBackupCloudstate({
103
+ client: this.client,
104
+ path: {
105
+ id
106
+ }
107
+ });
108
+ if (response.data) {
109
+ return response.data;
110
+ } else {
111
+ throw new Error("Failed to get backup of Cloudstate project");
112
+ }
113
+ }
114
+ /**
115
+ * Get logs for a sandbox.
116
+ * @param id The ID of the sandbox.
117
+ * @returns The logs for the sandbox.
118
+ * @throws An error if the logs could not be retrieved.
119
+ */
120
+ async getLogs(id) {
121
+ const response = await handleGetLogs({
122
+ client: this.client,
123
+ path: {
124
+ id
125
+ }
126
+ });
127
+ if (response.data) {
128
+ return response.data;
129
+ } else {
130
+ throw new Error("Failed to get logs for sandbox");
131
+ }
132
+ }
133
+ }
134
+
135
+ exports.FreestyleSandboxes = FreestyleSandboxes;
@@ -0,0 +1,43 @@
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';
2
+
3
+ declare class FreestyleSandboxes {
4
+ private client;
5
+ constructor(options: {
6
+ /**
7
+ * The base URL for the API.
8
+ */
9
+ baseUrl?: string;
10
+ /**
11
+ * The API key to use for requests.
12
+ */
13
+ apiKey: string;
14
+ });
15
+ /**
16
+ * Execute a script in a sandbox.
17
+ */
18
+ executeScript(script: string, config: FreestyleExecuteScriptParamsConfiguration): Promise<FreestyleExecureScriptResultSuccess>;
19
+ /**
20
+ * Deploy a Web project to a sandbox.
21
+ */
22
+ deployWeb(files: Record<string, string>, config: FreestyleDeployWebConfiguration): Promise<FreestyleDeployWebSuccessResponse>;
23
+ /**
24
+ * Deploy a Cloudstate project to a sandbox.
25
+ */
26
+ deployCloudstate(body: FreestyleCloudstateDeployRequest): Promise<FreestyleCloudstateDeploySuccessResponse>;
27
+ /**
28
+ * Get a backup of a Cloudstate project in a sandbox.
29
+ * @param id The ID of the Cloudstate project.
30
+ * @returns The backup of the Cloudstate project.
31
+ * @throws An error if the backup could not be retrieved.
32
+ */
33
+ backupCloudstate(id: string): Promise<HandleBackupCloudstateResponse>;
34
+ /**
35
+ * Get logs for a sandbox.
36
+ * @param id The ID of the sandbox.
37
+ * @returns The logs for the sandbox.
38
+ * @throws An error if the logs could not be retrieved.
39
+ */
40
+ getLogs(id: string): Promise<HandleGetLogsResponse>;
41
+ }
42
+
43
+ export { FreestyleSandboxes };
@@ -0,0 +1,43 @@
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';
2
+
3
+ declare class FreestyleSandboxes {
4
+ private client;
5
+ constructor(options: {
6
+ /**
7
+ * The base URL for the API.
8
+ */
9
+ baseUrl?: string;
10
+ /**
11
+ * The API key to use for requests.
12
+ */
13
+ apiKey: string;
14
+ });
15
+ /**
16
+ * Execute a script in a sandbox.
17
+ */
18
+ executeScript(script: string, config: FreestyleExecuteScriptParamsConfiguration): Promise<FreestyleExecureScriptResultSuccess>;
19
+ /**
20
+ * Deploy a Web project to a sandbox.
21
+ */
22
+ deployWeb(files: Record<string, string>, config: FreestyleDeployWebConfiguration): Promise<FreestyleDeployWebSuccessResponse>;
23
+ /**
24
+ * Deploy a Cloudstate project to a sandbox.
25
+ */
26
+ deployCloudstate(body: FreestyleCloudstateDeployRequest): Promise<FreestyleCloudstateDeploySuccessResponse>;
27
+ /**
28
+ * Get a backup of a Cloudstate project in a sandbox.
29
+ * @param id The ID of the Cloudstate project.
30
+ * @returns The backup of the Cloudstate project.
31
+ * @throws An error if the backup could not be retrieved.
32
+ */
33
+ backupCloudstate(id: string): Promise<HandleBackupCloudstateResponse>;
34
+ /**
35
+ * Get logs for a sandbox.
36
+ * @param id The ID of the sandbox.
37
+ * @returns The logs for the sandbox.
38
+ * @throws An error if the logs could not be retrieved.
39
+ */
40
+ getLogs(id: string): Promise<HandleGetLogsResponse>;
41
+ }
42
+
43
+ export { FreestyleSandboxes };
package/dist/index.mjs ADDED
@@ -0,0 +1,133 @@
1
+ import { createClient, createConfig } from '@hey-api/client-fetch';
2
+
3
+ const client = createClient(createConfig());
4
+ const handleDeployCloudstate = (options) => {
5
+ return (options?.client ?? client).post({
6
+ ...options,
7
+ url: "/cloudstate/v1/deploy"
8
+ });
9
+ };
10
+ const handleBackupCloudstate = (options) => {
11
+ return (options?.client ?? client).get({
12
+ ...options,
13
+ url: "/cloudstate/v1/projects/:id/backup"
14
+ });
15
+ };
16
+ const handleExecuteScript = (options) => {
17
+ return (options?.client ?? client).post({
18
+ ...options,
19
+ url: "/execute/v1/script"
20
+ });
21
+ };
22
+ const handleDeployWeb = (options) => {
23
+ return (options?.client ?? client).post({
24
+ ...options,
25
+ url: "/web/v1/deploy"
26
+ });
27
+ };
28
+ const handleGetLogs = (options) => {
29
+ return (options?.client ?? client).get({
30
+ ...options,
31
+ url: "/web/v1/projects/:id/logs"
32
+ });
33
+ };
34
+
35
+ class FreestyleSandboxes {
36
+ client;
37
+ constructor(options) {
38
+ this.client = createClient({
39
+ baseUrl: options.baseUrl ?? "https://api.freestyle.sh",
40
+ headers: {
41
+ Authorization: `Bearer ${options.apiKey}`
42
+ }
43
+ });
44
+ }
45
+ /**
46
+ * Execute a script in a sandbox.
47
+ */
48
+ async executeScript(script, config) {
49
+ const response = await handleExecuteScript({
50
+ client: this.client,
51
+ body: {
52
+ script,
53
+ config
54
+ }
55
+ });
56
+ if (response.data) {
57
+ return response.data;
58
+ } else {
59
+ throw new Error("Failed to execute script");
60
+ }
61
+ }
62
+ /**
63
+ * Deploy a Web project to a sandbox.
64
+ */
65
+ async deployWeb(files, config) {
66
+ const response = await handleDeployWeb({
67
+ client: this.client,
68
+ body: {
69
+ files,
70
+ config
71
+ }
72
+ });
73
+ if (response.data) {
74
+ return response.data;
75
+ } else {
76
+ throw new Error("Failed to deploy Web project");
77
+ }
78
+ }
79
+ /**
80
+ * Deploy a Cloudstate project to a sandbox.
81
+ */
82
+ async deployCloudstate(body) {
83
+ const response = await handleDeployCloudstate({
84
+ client: this.client,
85
+ body
86
+ });
87
+ if (response.data) {
88
+ return response.data;
89
+ } else {
90
+ throw new Error("Failed to deploy Cloudstate project");
91
+ }
92
+ }
93
+ /**
94
+ * Get a backup of a Cloudstate project in a sandbox.
95
+ * @param id The ID of the Cloudstate project.
96
+ * @returns The backup of the Cloudstate project.
97
+ * @throws An error if the backup could not be retrieved.
98
+ */
99
+ async backupCloudstate(id) {
100
+ const response = await handleBackupCloudstate({
101
+ client: this.client,
102
+ path: {
103
+ id
104
+ }
105
+ });
106
+ if (response.data) {
107
+ return response.data;
108
+ } else {
109
+ throw new Error("Failed to get backup of Cloudstate project");
110
+ }
111
+ }
112
+ /**
113
+ * Get logs for a sandbox.
114
+ * @param id The ID of the sandbox.
115
+ * @returns The logs for the sandbox.
116
+ * @throws An error if the logs could not be retrieved.
117
+ */
118
+ async getLogs(id) {
119
+ const response = await handleGetLogs({
120
+ client: this.client,
121
+ path: {
122
+ id
123
+ }
124
+ });
125
+ if (response.data) {
126
+ return response.data;
127
+ } else {
128
+ throw new Error("Failed to get logs for sandbox");
129
+ }
130
+ }
131
+ }
132
+
133
+ export { FreestyleSandboxes };
@@ -0,0 +1,84 @@
1
+ type FreestyleCloudstateDeployConfiguration = {
2
+ /**
3
+ * ID of the project to deploy, if not provided will create a new project
4
+ */
5
+ projectId?: (string) | null;
6
+ /**
7
+ * The environment variables that the cloudstate deploy can access
8
+ */
9
+ envVars?: {
10
+ [key: string]: (string);
11
+ };
12
+ };
13
+ type FreestyleCloudstateDeployRequest = {
14
+ classes: string;
15
+ config?: FreestyleCloudstateDeployConfiguration;
16
+ };
17
+ type FreestyleCloudstateDeploySuccessResponse = {
18
+ /**
19
+ * The id of the project deployed to
20
+ */
21
+ projectId: string;
22
+ };
23
+ type FreestyleDeployWebConfiguration = {
24
+ /**
25
+ * The entrypoint file for the website
26
+ */
27
+ entrypoint?: (string) | null;
28
+ /**
29
+ * The custom domains for the website, eg. [\"subdomain.yourwebsite.com\"]. You may not include *.style.dev domains here, those are reserved for projectIds
30
+ */
31
+ domains?: Array<(string)> | null;
32
+ /**
33
+ * 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
34
+ */
35
+ projectId?: (string) | null;
36
+ /**
37
+ * 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.
38
+ */
39
+ nodeModules?: {
40
+ [key: string]: (string);
41
+ } | null;
42
+ /**
43
+ * The environment variables that the website can access
44
+ * e.g. { \"RESEND_API_KEY\": \"re_123456789\" }
45
+ */
46
+ envVars?: {
47
+ [key: string]: (string);
48
+ } | null;
49
+ };
50
+ type FreestyleDeployWebSuccessResponse = {
51
+ projectId: string;
52
+ };
53
+ type FreestyleExecureScriptResultSuccess = {
54
+ result: unknown;
55
+ };
56
+ type FreestyleExecuteScriptParamsConfiguration = {
57
+ /**
58
+ * The environment variables to set for the script
59
+ */
60
+ envVars?: {
61
+ [key: string]: (string);
62
+ };
63
+ /**
64
+ * The node modules to install for the script
65
+ */
66
+ nodeModules?: {
67
+ [key: string]: (string);
68
+ };
69
+ /**
70
+ * Tags for you to organize your scripts, useful for tracking what you're running
71
+ */
72
+ tags?: Array<(string)>;
73
+ /**
74
+ * The script timeout
75
+ */
76
+ timeout?: (string) | null;
77
+ };
78
+ type FreestyleLogResponseObject = {
79
+ message: string;
80
+ };
81
+ type HandleBackupCloudstateResponse = (Array<(number)>);
82
+ type HandleGetLogsResponse = (Array<FreestyleLogResponseObject>);
83
+
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 };
@@ -0,0 +1,3 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export * from './sdk.gen';
3
+ export * from './types.gen';
@@ -0,0 +1,61 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import { createClient, createConfig, type OptionsLegacyParser } from '@hey-api/client-fetch';
4
+ import type { HandleDeployCloudstateData, HandleDeployCloudstateError, HandleDeployCloudstateResponse, HandleBackupCloudstateError, HandleBackupCloudstateResponse, HandleExecuteScriptData, HandleExecuteScriptError, HandleExecuteScriptResponse, HandleDeployWebData, HandleDeployWebError, HandleDeployWebResponse, HandleGetLogsError, HandleGetLogsResponse } from './types.gen';
5
+
6
+ export const client = createClient(createConfig());
7
+
8
+ /**
9
+ * Deploy Cloudstate Project
10
+ * Deploy a cloudstate project
11
+ */
12
+ export const handleDeployCloudstate = <ThrowOnError extends boolean = false>(options: OptionsLegacyParser<HandleDeployCloudstateData, ThrowOnError>) => {
13
+ return (options?.client ?? client).post<HandleDeployCloudstateResponse, HandleDeployCloudstateError, ThrowOnError>({
14
+ ...options,
15
+ url: '/cloudstate/v1/deploy'
16
+ });
17
+ };
18
+
19
+ /**
20
+ * Get Backup of Cloudstate Project
21
+ * Get a backup of a cloudstate project
22
+ */
23
+ export const handleBackupCloudstate = <ThrowOnError extends boolean = false>(options?: OptionsLegacyParser<unknown, ThrowOnError>) => {
24
+ return (options?.client ?? client).get<HandleBackupCloudstateResponse, HandleBackupCloudstateError, ThrowOnError>({
25
+ ...options,
26
+ url: '/cloudstate/v1/projects/:id/backup'
27
+ });
28
+ };
29
+
30
+ /**
31
+ * Execute Code
32
+ * Send a TypeScript or JavaScript module, get the result
33
+ */
34
+ export const handleExecuteScript = <ThrowOnError extends boolean = false>(options: OptionsLegacyParser<HandleExecuteScriptData, ThrowOnError>) => {
35
+ return (options?.client ?? client).post<HandleExecuteScriptResponse, HandleExecuteScriptError, ThrowOnError>({
36
+ ...options,
37
+ url: '/execute/v1/script'
38
+ });
39
+ };
40
+
41
+ /**
42
+ * Deploy a Website
43
+ * Deploy a website. Files is a map of file paths to file contents. Configuration is optional and contains additional information about the deployment.
44
+ */
45
+ export const handleDeployWeb = <ThrowOnError extends boolean = false>(options: OptionsLegacyParser<HandleDeployWebData, ThrowOnError>) => {
46
+ return (options?.client ?? client).post<HandleDeployWebResponse, HandleDeployWebError, ThrowOnError>({
47
+ ...options,
48
+ url: '/web/v1/deploy'
49
+ });
50
+ };
51
+
52
+ /**
53
+ * Get Website Logs
54
+ * Get the logs for a project
55
+ */
56
+ export const handleGetLogs = <ThrowOnError extends boolean = false>(options?: OptionsLegacyParser<unknown, ThrowOnError>) => {
57
+ return (options?.client ?? client).get<HandleGetLogsResponse, HandleGetLogsError, ThrowOnError>({
58
+ ...options,
59
+ url: '/web/v1/projects/:id/logs'
60
+ });
61
+ };
@@ -0,0 +1,153 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ export type FreestyleCloudstateDeployConfiguration = {
4
+ /**
5
+ * ID of the project to deploy, if not provided will create a new project
6
+ */
7
+ projectId?: (string) | null;
8
+ /**
9
+ * The environment variables that the cloudstate deploy can access
10
+ */
11
+ envVars?: {
12
+ [key: string]: (string);
13
+ };
14
+ };
15
+
16
+ export type FreestyleCloudstateDeployErrorResponse = {
17
+ message: string;
18
+ };
19
+
20
+ export type FreestyleCloudstateDeployRequest = {
21
+ classes: string;
22
+ config?: FreestyleCloudstateDeployConfiguration;
23
+ };
24
+
25
+ export type FreestyleCloudstateDeploySuccessResponse = {
26
+ /**
27
+ * The id of the project deployed to
28
+ */
29
+ projectId: string;
30
+ };
31
+
32
+ export type FreestyleDeployWebConfiguration = {
33
+ /**
34
+ * The entrypoint file for the website
35
+ */
36
+ entrypoint?: (string) | null;
37
+ /**
38
+ * The custom domains for the website, eg. [\"subdomain.yourwebsite.com\"]. You may not include *.style.dev domains here, those are reserved for projectIds
39
+ */
40
+ domains?: Array<(string)> | null;
41
+ /**
42
+ * 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
43
+ */
44
+ projectId?: (string) | null;
45
+ /**
46
+ * 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.
47
+ */
48
+ nodeModules?: {
49
+ [key: string]: (string);
50
+ } | null;
51
+ /**
52
+ * The environment variables that the website can access
53
+ * e.g. { \"RESEND_API_KEY\": \"re_123456789\" }
54
+ */
55
+ envVars?: {
56
+ [key: string]: (string);
57
+ } | null;
58
+ };
59
+
60
+ export type FreestyleDeployWebErrorResponse = {
61
+ message: string;
62
+ };
63
+
64
+ export type FreestyleDeployWebPayload = {
65
+ /**
66
+ * The files to deploy, a map of file paths to file contents, e.g. { \"index.js\": \"your main", \"file2.js\": \"your helper\" }
67
+ *
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
+ */
70
+ files: {
71
+ [key: string]: (string);
72
+ };
73
+ config?: FreestyleDeployWebConfiguration;
74
+ };
75
+
76
+ export type FreestyleDeployWebSuccessResponse = {
77
+ projectId: string;
78
+ };
79
+
80
+ export type FreestyleExecureScriptResultError = {
81
+ error: string;
82
+ };
83
+
84
+ export type FreestyleExecureScriptResultSuccess = {
85
+ result: unknown;
86
+ };
87
+
88
+ export type FreestyleExecuteScriptParams = {
89
+ /**
90
+ * The JavaScript or TypeScript script to execute
91
+ */
92
+ script: string;
93
+ config?: FreestyleExecuteScriptParamsConfiguration;
94
+ };
95
+
96
+ export type FreestyleExecuteScriptParamsConfiguration = {
97
+ /**
98
+ * The environment variables to set for the script
99
+ */
100
+ envVars?: {
101
+ [key: string]: (string);
102
+ };
103
+ /**
104
+ * The node modules to install for the script
105
+ */
106
+ nodeModules?: {
107
+ [key: string]: (string);
108
+ };
109
+ /**
110
+ * Tags for you to organize your scripts, useful for tracking what you're running
111
+ */
112
+ tags?: Array<(string)>;
113
+ /**
114
+ * The script timeout
115
+ */
116
+ timeout?: (string) | null;
117
+ };
118
+
119
+ export type FreestyleLogResponseObject = {
120
+ message: string;
121
+ };
122
+
123
+ export type HandleDeployCloudstateData = {
124
+ body: FreestyleCloudstateDeployRequest;
125
+ };
126
+
127
+ export type HandleDeployCloudstateResponse = (FreestyleCloudstateDeploySuccessResponse);
128
+
129
+ export type HandleDeployCloudstateError = (FreestyleCloudstateDeployErrorResponse);
130
+
131
+ export type HandleBackupCloudstateResponse = (Array<(number)>);
132
+
133
+ export type HandleBackupCloudstateError = (unknown);
134
+
135
+ export type HandleExecuteScriptData = {
136
+ body: FreestyleExecuteScriptParams;
137
+ };
138
+
139
+ export type HandleExecuteScriptResponse = (FreestyleExecureScriptResultSuccess);
140
+
141
+ export type HandleExecuteScriptError = (FreestyleExecureScriptResultError);
142
+
143
+ export type HandleDeployWebData = {
144
+ body: FreestyleDeployWebPayload;
145
+ };
146
+
147
+ export type HandleDeployWebResponse = (FreestyleDeployWebSuccessResponse);
148
+
149
+ export type HandleDeployWebError = (FreestyleDeployWebErrorResponse);
150
+
151
+ export type HandleGetLogsResponse = (Array<FreestyleLogResponseObject>);
152
+
153
+ export type HandleGetLogsError = unknown;
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "@hey-api/openapi-ts";
2
+
3
+ export default defineConfig({
4
+ client: "@hey-api/client-fetch",
5
+ input: "./openapi.json",
6
+ output: "openapi/",
7
+ });
package/openapi.json ADDED
@@ -0,0 +1 @@
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."}]}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "freestyle-sandboxes",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.cts",
8
+ "exports": {
9
+ ".": {
10
+ "require": {
11
+ "types": "./dist/index.d.cts",
12
+ "default": "./dist/index.cjs"
13
+ },
14
+ "import": {
15
+ "types": "./dist/index.d.mts",
16
+ "default": "./dist/index.mjs"
17
+ }
18
+ },
19
+ "./ai": {
20
+ "require": {
21
+ "types": "./dist/ai/index.d.cts",
22
+ "default": "./dist/ai/index.cjs"
23
+ },
24
+ "import": {
25
+ "types": "./dist/ai/index.d.mts",
26
+ "default": "./dist/ai/index.mjs"
27
+ }
28
+ }
29
+ },
30
+ "scripts": {
31
+ "openapi": "openapi-ts",
32
+ "build": "pkgroll"
33
+ },
34
+ "keywords": [],
35
+ "author": "",
36
+ "license": "ISC",
37
+ "description": "",
38
+ "devDependencies": {
39
+ "@hey-api/openapi-ts": "^0.60.1",
40
+ "pkgroll": "^2.6.0"
41
+ },
42
+ "dependencies": {
43
+ "@hey-api/client-fetch": "^0.5.7",
44
+ "ai": "^4.0.25",
45
+ "zod": "^3.24.1"
46
+ }
47
+ }
@@ -0,0 +1,47 @@
1
+ import { FreestyleExecuteScriptParamsConfiguration } from "../../openapi";
2
+ import { FreestyleSandboxes } from "..";
3
+ import { tool } from "ai";
4
+ import { z } from "zod";
5
+
6
+ /**
7
+ * Execute a JavaScript or TypeScript script
8
+ *
9
+ * **Note: Unless you tell it, the AI won't be aware of any node_modules or environment variables you give it, you need to tell it in your prompt what it can use.**
10
+
11
+ *
12
+ * @param config - Configuration for the tool
13
+ * @param config.apiKey - The API key to use
14
+ *
15
+ */
16
+ export const executeTool = (
17
+ config: FreestyleExecuteScriptParamsConfiguration & {
18
+ apiKey: string;
19
+ }
20
+ ) => {
21
+ const api = new FreestyleSandboxes({
22
+ apiKey: config.apiKey,
23
+ });
24
+ return tool({
25
+ description: "Execute a JavaScript or TypeScript script",
26
+ parameters: z.object({
27
+ script: z.string().describe(`
28
+ The JavaScript or TypeScript script to execute, must be in the format of:
29
+
30
+ export default () => {
31
+ ... your code here ...
32
+ return output;
33
+ }
34
+
35
+ or for async functions:
36
+
37
+ export default async () => {
38
+ ... your code here ...
39
+ return output;
40
+ }
41
+ `),
42
+ }),
43
+ execute: async ({ script }) => {
44
+ return api.executeScript(script, config);
45
+ },
46
+ });
47
+ };
package/src/index.ts ADDED
@@ -0,0 +1,123 @@
1
+ import { Client, createClient } from "@hey-api/client-fetch";
2
+ import * as sandbox_openapi from "../openapi/index.ts";
3
+ export class FreestyleSandboxes {
4
+ private client: Client;
5
+ constructor(options: {
6
+ /**
7
+ * The base URL for the API.
8
+ */
9
+ baseUrl?: string;
10
+ /**
11
+ * The API key to use for requests.
12
+ */
13
+ apiKey: string;
14
+ }) {
15
+ this.client = createClient({
16
+ baseUrl: options.baseUrl ?? "https://api.freestyle.sh",
17
+ headers: {
18
+ Authorization: `Bearer ${options.apiKey}`,
19
+ },
20
+ });
21
+ }
22
+
23
+ /**
24
+ * Execute a script in a sandbox.
25
+ */
26
+ async executeScript(
27
+ script: string,
28
+ config: sandbox_openapi.FreestyleExecuteScriptParamsConfiguration
29
+ ): Promise<sandbox_openapi.FreestyleExecureScriptResultSuccess> {
30
+ const response = await sandbox_openapi.handleExecuteScript({
31
+ client: this.client,
32
+ body: {
33
+ script,
34
+ config: config,
35
+ },
36
+ });
37
+ if (response.data) {
38
+ return response.data;
39
+ } else {
40
+ throw new Error("Failed to execute script");
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Deploy a Web project to a sandbox.
46
+ */
47
+ async deployWeb(
48
+ files: Record<string, string>,
49
+ config: sandbox_openapi.FreestyleDeployWebConfiguration
50
+ ): Promise<sandbox_openapi.FreestyleDeployWebSuccessResponse> {
51
+ const response = await sandbox_openapi.handleDeployWeb({
52
+ client: this.client,
53
+ body: {
54
+ files,
55
+ config: config,
56
+ },
57
+ });
58
+ if (response.data) {
59
+ return response.data;
60
+ } else {
61
+ throw new Error("Failed to deploy Web project");
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Deploy a Cloudstate project to a sandbox.
67
+ */
68
+ async deployCloudstate(
69
+ body: sandbox_openapi.FreestyleCloudstateDeployRequest
70
+ ): Promise<sandbox_openapi.FreestyleCloudstateDeploySuccessResponse> {
71
+ const response = await sandbox_openapi.handleDeployCloudstate({
72
+ client: this.client,
73
+ body: body,
74
+ });
75
+ if (response.data) {
76
+ return response.data;
77
+ } else {
78
+ throw new Error("Failed to deploy Cloudstate project");
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Get a backup of a Cloudstate project in a sandbox.
84
+ * @param id The ID of the Cloudstate project.
85
+ * @returns The backup of the Cloudstate project.
86
+ * @throws An error if the backup could not be retrieved.
87
+ */
88
+ async backupCloudstate(
89
+ id: string
90
+ ): Promise<sandbox_openapi.HandleBackupCloudstateResponse> {
91
+ const response = await sandbox_openapi.handleBackupCloudstate({
92
+ client: this.client,
93
+ path: {
94
+ id: id,
95
+ },
96
+ });
97
+ if (response.data) {
98
+ return response.data;
99
+ } else {
100
+ throw new Error("Failed to get backup of Cloudstate project");
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Get logs for a sandbox.
106
+ * @param id The ID of the sandbox.
107
+ * @returns The logs for the sandbox.
108
+ * @throws An error if the logs could not be retrieved.
109
+ */
110
+ async getLogs(id: string): Promise<sandbox_openapi.HandleGetLogsResponse> {
111
+ const response = await sandbox_openapi.handleGetLogs({
112
+ client: this.client,
113
+ path: {
114
+ id: id,
115
+ },
116
+ });
117
+ if (response.data) {
118
+ return response.data;
119
+ } else {
120
+ throw new Error("Failed to get logs for sandbox");
121
+ }
122
+ }
123
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowImportingTsExtensions": true,
4
+ "lib": ["ESNext"]
5
+ }
6
+ }