freestyle-sandboxes 0.0.35 → 0.0.37

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
@@ -1,104 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var index = require('../index.cjs');
4
- var ai = require('ai');
5
- var zod = require('zod');
3
+ require('../index.cjs');
4
+ var index = require('../index-BBXyg0JQ.cjs');
5
+ require('zod');
6
6
  require('@hey-api/client-fetch');
7
7
 
8
- const executeCodeSchema = zod.z.object({
9
- script: zod.z.string().describe(`
10
- The JavaScript or TypeScript script to execute, must be in the format of:
11
8
 
12
- import { someModule } from "someModule";
13
- export default () => {
14
- ... your code here ...
15
- return output;
16
- }
17
9
 
18
- or for async functions:
19
-
20
- import { someModule } from "someModule";
21
-
22
- export default async () => {
23
- ... your code here ...
24
- return output;
25
- }
26
- `)
27
- });
28
- const executeCodeDescription = (envVars, nodeModules) => `Execute a JavaScript or TypeScript script.
29
- ${envVars.length > 0 ? `You can use the following environment variables: ${envVars}` : ""}
30
- ${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModules}` : "You cannot use any node modules."}`;
31
- const executeTool = (config) => {
32
- const api = new index.FreestyleSandboxes({
33
- ...config
34
- });
35
- const envVars = Object.keys(config.envVars ?? {}).join(", ");
36
- const nodeModules = Object.keys(config.nodeModules ?? {}).join(", ");
37
- return ai.tool({
38
- description: executeCodeDescription(envVars, nodeModules),
39
- parameters: executeCodeSchema,
40
- execute: async ({ script }) => {
41
- try {
42
- const res = await api.executeScript(script, config);
43
- return res;
44
- } catch (e) {
45
- console.log("ERROR: ", e.message);
46
- return {
47
- message: e.message,
48
- error: e.error
49
- };
50
- }
51
- }
52
- });
53
- };
54
- const deployWebTool = (config) => {
55
- const api = new index.FreestyleSandboxes({
56
- ...config
57
- });
58
- const envVars = Object.keys(config.envVars ?? {}).join(", ");
59
- const nodeModules = Object.keys(config.nodeModules ?? {}).join(", ");
60
- return ai.tool({
61
- description: `Deploy a Web project. ${envVars.length > 0 ? `You can use the following environment variables: ${envVars}` : ""}
62
- ${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModules}` : "You cannot use any node modules."}`,
63
- parameters: zod.z.object({
64
- files: zod.z.record(zod.z.string()).describe(`
65
- A record of file names and their contents to deploy. For example:
66
- {
67
- "index.js": "import http from 'node:http';\\nnconsole.log('starting server');\\n\\nconst server = http.createServer(async(req, res) => {\\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});",
68
- }
69
- `)
70
- }),
71
- execute: async ({ files }) => {
72
- const new_files = Object.keys(files).reduce((acc, key) => {
73
- acc[key] = { content: files[key] };
74
- return acc;
75
- }, {});
76
- try {
77
- const res = await api.deployWeb(
78
- {
79
- kind: "files",
80
- files: new_files
81
- },
82
- config
83
- );
84
- return res;
85
- } catch (e) {
86
- console.log("ERROR: ", e.message);
87
- return `Error deploying web project:
88
-
89
- ${JSON.stringify(
90
- files,
91
- null,
92
- 2
93
- )}
94
-
95
- Error: ${e.message}`;
96
- }
97
- }
98
- });
99
- };
100
-
101
- exports.deployWebTool = deployWebTool;
102
- exports.executeCodeDescription = executeCodeDescription;
103
- exports.executeCodeSchema = executeCodeSchema;
104
- exports.executeTool = executeTool;
10
+ exports.deployWebTool = index.deployWebTool;
11
+ exports.executeCodeDescription = index.executeCodeDescription;
12
+ exports.executeCodeSchema = index.executeCodeSchema;
13
+ exports.executeTool = index.executeTool;
@@ -1,6 +1,8 @@
1
- import * as ai from 'ai';
2
- import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecuteScriptResultSuccess, c as FreestyleDeployWebSuccessResponse } from '../types.gen-BuhQ5LpB.js';
1
+ import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecuteScriptResultSuccess, aR as HandleExecuteScriptError, c as FreestyleDeployWebSuccessResponse } from '../types.gen-BuhQ5LpB.js';
2
+ import { T as Tool, a as ToolExecutionOptions } from '../index.d-CXx1AdyW.js';
3
3
  import { z } from 'zod';
4
+ import 'node:http';
5
+ import 'http';
4
6
 
5
7
  declare const executeCodeSchema: z.ZodObject<{
6
8
  script: z.ZodString;
@@ -16,11 +18,19 @@ declare const executeCodeDescription: (envVars: string, nodeModules: string) =>
16
18
  *
17
19
  * @param config - Configuration for the tool
18
20
  * @param config.apiKey - The API key to use
19
- *
21
+ * @param {Function} [config.onResult] - Optional callback function to handle the result.
22
+ * @param {boolean} [config.truncateOutput=false] - Whether to truncate the result to 1000 characters and truncate individual logs to the first 250 characters; useful to prevent long outputs from filling the context window.
20
23
  */
21
24
  declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration & {
22
25
  apiKey: string;
23
- }) => ai.Tool<z.ZodObject<{
26
+ onResult?: (_v: {
27
+ input: {
28
+ script: string;
29
+ } & Record<string, unknown>;
30
+ result: FreestyleExecuteScriptResultSuccess | HandleExecuteScriptError;
31
+ }) => void | Promise<void>;
32
+ truncateOutput?: boolean;
33
+ }) => Tool<z.ZodObject<{
24
34
  script: z.ZodString;
25
35
  }, "strip", z.ZodTypeAny, {
26
36
  script?: string;
@@ -32,7 +42,7 @@ declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration &
32
42
  }> & {
33
43
  execute: (args: {
34
44
  script?: string;
35
- }, options: ai.ToolExecutionOptions) => PromiseLike<FreestyleExecuteScriptResultSuccess | {
45
+ }, options: ToolExecutionOptions) => PromiseLike<FreestyleExecuteScriptResultSuccess | {
36
46
  message: any;
37
47
  error: any;
38
48
  }>;
@@ -44,7 +54,7 @@ declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration &
44
54
  */
45
55
  declare const deployWebTool: (config: FreestyleExecuteScriptParamsConfiguration & {
46
56
  apiKey: string;
47
- }) => ai.Tool<z.ZodObject<{
57
+ }) => Tool<z.ZodObject<{
48
58
  files: z.ZodRecord<z.ZodString, z.ZodString>;
49
59
  }, "strip", z.ZodTypeAny, {
50
60
  files?: Record<string, string>;
@@ -53,7 +63,7 @@ declare const deployWebTool: (config: FreestyleExecuteScriptParamsConfiguration
53
63
  }>, string | FreestyleDeployWebSuccessResponse> & {
54
64
  execute: (args: {
55
65
  files?: Record<string, string>;
56
- }, options: ai.ToolExecutionOptions) => PromiseLike<string | FreestyleDeployWebSuccessResponse>;
66
+ }, options: ToolExecutionOptions) => PromiseLike<string | FreestyleDeployWebSuccessResponse>;
57
67
  };
58
68
 
59
69
  export { deployWebTool, executeCodeDescription, executeCodeSchema, executeTool };
@@ -1,6 +1,8 @@
1
- import * as ai from 'ai';
2
- import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecuteScriptResultSuccess, c as FreestyleDeployWebSuccessResponse } from '../types.gen-BuhQ5LpB.js';
1
+ import { F as FreestyleExecuteScriptParamsConfiguration, a as FreestyleExecuteScriptResultSuccess, aR as HandleExecuteScriptError, c as FreestyleDeployWebSuccessResponse } from '../types.gen-BuhQ5LpB.js';
2
+ import { T as Tool, a as ToolExecutionOptions } from '../index.d-CXx1AdyW.js';
3
3
  import { z } from 'zod';
4
+ import 'node:http';
5
+ import 'http';
4
6
 
5
7
  declare const executeCodeSchema: z.ZodObject<{
6
8
  script: z.ZodString;
@@ -16,11 +18,19 @@ declare const executeCodeDescription: (envVars: string, nodeModules: string) =>
16
18
  *
17
19
  * @param config - Configuration for the tool
18
20
  * @param config.apiKey - The API key to use
19
- *
21
+ * @param {Function} [config.onResult] - Optional callback function to handle the result.
22
+ * @param {boolean} [config.truncateOutput=false] - Whether to truncate the result to 1000 characters and truncate individual logs to the first 250 characters; useful to prevent long outputs from filling the context window.
20
23
  */
21
24
  declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration & {
22
25
  apiKey: string;
23
- }) => ai.Tool<z.ZodObject<{
26
+ onResult?: (_v: {
27
+ input: {
28
+ script: string;
29
+ } & Record<string, unknown>;
30
+ result: FreestyleExecuteScriptResultSuccess | HandleExecuteScriptError;
31
+ }) => void | Promise<void>;
32
+ truncateOutput?: boolean;
33
+ }) => Tool<z.ZodObject<{
24
34
  script: z.ZodString;
25
35
  }, "strip", z.ZodTypeAny, {
26
36
  script?: string;
@@ -32,7 +42,7 @@ declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration &
32
42
  }> & {
33
43
  execute: (args: {
34
44
  script?: string;
35
- }, options: ai.ToolExecutionOptions) => PromiseLike<FreestyleExecuteScriptResultSuccess | {
45
+ }, options: ToolExecutionOptions) => PromiseLike<FreestyleExecuteScriptResultSuccess | {
36
46
  message: any;
37
47
  error: any;
38
48
  }>;
@@ -44,7 +54,7 @@ declare const executeTool: (config: FreestyleExecuteScriptParamsConfiguration &
44
54
  */
45
55
  declare const deployWebTool: (config: FreestyleExecuteScriptParamsConfiguration & {
46
56
  apiKey: string;
47
- }) => ai.Tool<z.ZodObject<{
57
+ }) => Tool<z.ZodObject<{
48
58
  files: z.ZodRecord<z.ZodString, z.ZodString>;
49
59
  }, "strip", z.ZodTypeAny, {
50
60
  files?: Record<string, string>;
@@ -53,7 +63,7 @@ declare const deployWebTool: (config: FreestyleExecuteScriptParamsConfiguration
53
63
  }>, string | FreestyleDeployWebSuccessResponse> & {
54
64
  execute: (args: {
55
65
  files?: Record<string, string>;
56
- }, options: ai.ToolExecutionOptions) => PromiseLike<string | FreestyleDeployWebSuccessResponse>;
66
+ }, options: ToolExecutionOptions) => PromiseLike<string | FreestyleDeployWebSuccessResponse>;
57
67
  };
58
68
 
59
69
  export { deployWebTool, executeCodeDescription, executeCodeSchema, executeTool };
package/dist/ai/index.mjs CHANGED
@@ -1,99 +1,4 @@
1
- import { FreestyleSandboxes } from '../index.mjs';
2
- import { tool } from 'ai';
3
- import { z } from 'zod';
1
+ import '../index.mjs';
2
+ export { d as deployWebTool, e as executeCodeDescription, a as executeCodeSchema, b as executeTool } from '../index-DCF70Xbq.mjs';
3
+ import 'zod';
4
4
  import '@hey-api/client-fetch';
5
-
6
- const executeCodeSchema = z.object({
7
- script: z.string().describe(`
8
- The JavaScript or TypeScript script to execute, must be in the format of:
9
-
10
- import { someModule } from "someModule";
11
- export default () => {
12
- ... your code here ...
13
- return output;
14
- }
15
-
16
- or for async functions:
17
-
18
- import { someModule } from "someModule";
19
-
20
- export default async () => {
21
- ... your code here ...
22
- return output;
23
- }
24
- `)
25
- });
26
- const executeCodeDescription = (envVars, nodeModules) => `Execute a JavaScript or TypeScript script.
27
- ${envVars.length > 0 ? `You can use the following environment variables: ${envVars}` : ""}
28
- ${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModules}` : "You cannot use any node modules."}`;
29
- const executeTool = (config) => {
30
- const api = new FreestyleSandboxes({
31
- ...config
32
- });
33
- const envVars = Object.keys(config.envVars ?? {}).join(", ");
34
- const nodeModules = Object.keys(config.nodeModules ?? {}).join(", ");
35
- return tool({
36
- description: executeCodeDescription(envVars, nodeModules),
37
- parameters: executeCodeSchema,
38
- execute: async ({ script }) => {
39
- try {
40
- const res = await api.executeScript(script, config);
41
- return res;
42
- } catch (e) {
43
- console.log("ERROR: ", e.message);
44
- return {
45
- message: e.message,
46
- error: e.error
47
- };
48
- }
49
- }
50
- });
51
- };
52
- const deployWebTool = (config) => {
53
- const api = new FreestyleSandboxes({
54
- ...config
55
- });
56
- const envVars = Object.keys(config.envVars ?? {}).join(", ");
57
- const nodeModules = Object.keys(config.nodeModules ?? {}).join(", ");
58
- return tool({
59
- description: `Deploy a Web project. ${envVars.length > 0 ? `You can use the following environment variables: ${envVars}` : ""}
60
- ${nodeModules.length > 0 ? `You can use the following node modules: ${nodeModules}` : "You cannot use any node modules."}`,
61
- parameters: z.object({
62
- files: z.record(z.string()).describe(`
63
- A record of file names and their contents to deploy. For example:
64
- {
65
- "index.js": "import http from 'node:http';\\nnconsole.log('starting server');\\n\\nconst server = http.createServer(async(req, res) => {\\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});",
66
- }
67
- `)
68
- }),
69
- execute: async ({ files }) => {
70
- const new_files = Object.keys(files).reduce((acc, key) => {
71
- acc[key] = { content: files[key] };
72
- return acc;
73
- }, {});
74
- try {
75
- const res = await api.deployWeb(
76
- {
77
- kind: "files",
78
- files: new_files
79
- },
80
- config
81
- );
82
- return res;
83
- } catch (e) {
84
- console.log("ERROR: ", e.message);
85
- return `Error deploying web project:
86
-
87
- ${JSON.stringify(
88
- files,
89
- null,
90
- 2
91
- )}
92
-
93
- Error: ${e.message}`;
94
- }
95
- }
96
- });
97
- };
98
-
99
- export { deployWebTool, executeCodeDescription, executeCodeSchema, executeTool };