freestyle-sandboxes 0.0.36 → 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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  var index$1 = require('../index.cjs');
4
4
  var zod = require('zod');
5
- var index = require('../index-CEEa9WHp.cjs');
5
+ var index = require('../index-BBXyg0JQ.cjs');
6
6
  require('@hey-api/client-fetch');
7
7
 
8
8
  var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
@@ -1,6 +1,6 @@
1
1
  import { FreestyleSandboxes } from '../index.mjs';
2
2
  import { z } from 'zod';
3
- import { g as getDefaultExportFromCjs, z as zodToJsonSchema, a as executeCodeSchema, e as executeCodeDescription } from '../index-BQHqnjZK.mjs';
3
+ import { g as getDefaultExportFromCjs, z as zodToJsonSchema, a as executeCodeSchema, e as executeCodeDescription } from '../index-DCF70Xbq.mjs';
4
4
  import '@hey-api/client-fetch';
5
5
 
6
6
  var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var zod = require('zod');
4
- var index = require('../index-CEEa9WHp.cjs');
4
+ var index = require('../index-BBXyg0JQ.cjs');
5
5
  var index$1 = require('../index.cjs');
6
6
  require('@hey-api/client-fetch');
7
7
 
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { e as executeCodeDescription, a as executeCodeSchema } from '../index-BQHqnjZK.mjs';
2
+ import { e as executeCodeDescription, a as executeCodeSchema } from '../index-DCF70Xbq.mjs';
3
3
  import { FreestyleSandboxes } from '../index.mjs';
4
4
  import '@hey-api/client-fetch';
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle-sandboxes",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
package/src/ai/index.ts CHANGED
@@ -1,7 +1,12 @@
1
- import { FreestyleExecuteScriptParamsConfiguration } from "../../openapi";
1
+ import {
2
+ FreestyleExecuteScriptParamsConfiguration,
3
+ FreestyleExecuteScriptResultSuccess,
4
+ HandleExecuteScriptError,
5
+ } from "../../openapi";
2
6
  import { FreestyleSandboxes } from "..";
3
7
  import { tool } from "ai";
4
8
  import { z } from "zod";
9
+ import { P } from "../../dist/types.gen-BuhQ5LpB";
5
10
 
6
11
  export const executeCodeSchema = z.object({
7
12
  script: z.string().describe(`
@@ -40,11 +45,19 @@ export const executeCodeDescription = (envVars: string, nodeModules: string) =>
40
45
  *
41
46
  * @param config - Configuration for the tool
42
47
  * @param config.apiKey - The API key to use
43
- *
48
+ * @param {Function} [config.onResult] - Optional callback function to handle the result.
49
+ * @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.
44
50
  */
45
51
  export const executeTool = (
46
52
  config: FreestyleExecuteScriptParamsConfiguration & {
47
53
  apiKey: string;
54
+ onResult?: (_v: {
55
+ input: {
56
+ script: string;
57
+ } & Record<string, unknown>;
58
+ result: FreestyleExecuteScriptResultSuccess | HandleExecuteScriptError;
59
+ }) => void | Promise<void>;
60
+ truncateOutput?: boolean;
48
61
  }
49
62
  ) => {
50
63
  const api = new FreestyleSandboxes({
@@ -56,9 +69,24 @@ export const executeTool = (
56
69
  return tool({
57
70
  description: executeCodeDescription(envVars, nodeModules),
58
71
  parameters: executeCodeSchema,
59
- execute: async ({ script }) => {
72
+ execute: async ({ script, ...otherParams }) => {
60
73
  try {
61
74
  const res = await api.executeScript(script, config);
75
+ if (config.onResult) {
76
+ await config.onResult({
77
+ result: res,
78
+ input: {
79
+ script,
80
+ ...otherParams,
81
+ },
82
+ });
83
+ }
84
+ if (config.truncateOutput) {
85
+ if ("output" in res) {
86
+ res.result = JSON.stringify(res.result).slice(0, 1000);
87
+ res.logs = res.logs.slice(0, 1000);
88
+ }
89
+ }
62
90
  return res;
63
91
  } catch (e) {
64
92
  console.log("ERROR: ", e.message);