freestyle-sandboxes 0.0.96 → 0.1.0

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.
Files changed (69) hide show
  1. package/README.md +39 -48
  2. package/index.cjs +4362 -0
  3. package/index.d.cts +9401 -0
  4. package/index.d.mts +9401 -0
  5. package/index.mjs +4348 -0
  6. package/package.json +16 -109
  7. package/dist/ai/inde.d.cts +0 -75
  8. package/dist/ai/inde.d.mts +0 -75
  9. package/dist/ai/index.cjs +0 -13
  10. package/dist/ai/index.d.cts +0 -75
  11. package/dist/ai/index.d.mts +0 -75
  12. package/dist/ai/index.mjs +0 -4
  13. package/dist/expo/inde.d.cts +0 -6
  14. package/dist/expo/inde.d.mts +0 -6
  15. package/dist/expo/index.cjs +0 -319
  16. package/dist/expo/index.d.cts +0 -6
  17. package/dist/expo/index.d.mts +0 -6
  18. package/dist/expo/index.mjs +0 -297
  19. package/dist/inde.d.cts +0 -373
  20. package/dist/inde.d.mts +0 -373
  21. package/dist/index-BKAG8L-o.mjs +0 -3061
  22. package/dist/index-DuOpIaWc.cjs +0 -3068
  23. package/dist/index.cjs +0 -1329
  24. package/dist/index.d-9H_wnIbz.d.ts +0 -4223
  25. package/dist/index.d.cts +0 -373
  26. package/dist/index.d.mts +0 -373
  27. package/dist/index.mjs +0 -1327
  28. package/dist/langgraph/inde.d.cts +0 -4180
  29. package/dist/langgraph/inde.d.mts +0 -4180
  30. package/dist/langgraph/index.cjs +0 -17155
  31. package/dist/langgraph/index.d.cts +0 -4180
  32. package/dist/langgraph/index.d.mts +0 -4180
  33. package/dist/langgraph/index.mjs +0 -17153
  34. package/dist/mastra/inde.d.cts +0 -2623
  35. package/dist/mastra/inde.d.mts +0 -2623
  36. package/dist/mastra/index.cjs +0 -55
  37. package/dist/mastra/index.d.cts +0 -2623
  38. package/dist/mastra/index.d.mts +0 -2623
  39. package/dist/mastra/index.mjs +0 -53
  40. package/dist/react/dev-server/index..d.cts +0 -33
  41. package/dist/react/dev-server/index..d.mts +0 -33
  42. package/dist/react/dev-server/index.cjs +0 -148
  43. package/dist/react/dev-server/index.d.cts +0 -33
  44. package/dist/react/dev-server/index.d.mts +0 -33
  45. package/dist/react/dev-server/index.mjs +0 -145
  46. package/dist/types.gen-CJa21P0C.d.ts +0 -1902
  47. package/dist/types.gen-DKjMRuu5.d.ts +0 -1898
  48. package/dist/utils/inde.d.cts +0 -10
  49. package/dist/utils/inde.d.mts +0 -10
  50. package/dist/utils/index.cjs +0 -100
  51. package/dist/utils/index.d.cts +0 -10
  52. package/dist/utils/index.d.mts +0 -10
  53. package/dist/utils/index.mjs +0 -75
  54. package/openapi/index.ts +0 -3
  55. package/openapi/sdk.gen.ts +0 -929
  56. package/openapi/types.gen.ts +0 -2234
  57. package/openapi-ts.config.ts +0 -7
  58. package/openapi.json +0 -1
  59. package/src/ai/index.ts +0 -164
  60. package/src/dev-server.ts +0 -95
  61. package/src/expo/_expo_internals.ts +0 -389
  62. package/src/expo/index.ts +0 -26
  63. package/src/index.ts +0 -1459
  64. package/src/langgraph/index.ts +0 -33
  65. package/src/mastra/index.ts +0 -38
  66. package/src/react/dev-server/index.tsx +0 -195
  67. package/src/react/dev-server/types.ts +0 -5
  68. package/src/utils/index.ts +0 -97
  69. package/tsconfig.json +0 -8
@@ -1,33 +0,0 @@
1
- import { FreestyleExecuteScriptParamsConfiguration } from "../../openapi";
2
- import { FreestyleSandboxes } from "..";
3
- // import { DynamicStructuredTool, tool } from "@langchain/core/tools";
4
- import { z } from "zod";
5
- import { executeCodeDescription, executeCodeSchema } from "../ai";
6
- import { DynamicTool, tool } from "@langchain/core/tools";
7
-
8
- export const executeTool = (
9
- config: FreestyleExecuteScriptParamsConfiguration & {
10
- apiKey: string;
11
- }
12
- ): DynamicTool => {
13
- const client = new FreestyleSandboxes({
14
- apiKey: config.apiKey,
15
- });
16
-
17
- // @ts-expect-error dumb langraph
18
- return tool(
19
- async ({ script }) => {
20
- return await client.executeScript(script, config);
21
- },
22
- {
23
- name: "executeTool",
24
- description: executeCodeDescription(
25
- Object.keys(config.envVars ?? {}).join(", "),
26
- Object.keys(config.nodeModules ?? {}).join(", ")
27
- ),
28
- schema: z.object({
29
- script: z.string(),
30
- }),
31
- }
32
- ) as unknown;
33
- };
@@ -1,38 +0,0 @@
1
- import { createTool } from "@mastra/core";
2
- import { z } from "zod";
3
- import { executeCodeDescription, executeCodeSchema } from "../ai";
4
- import type { FreestyleExecuteScriptParamsConfiguration } from "../../openapi";
5
- import { FreestyleSandboxes } from "..";
6
-
7
- export const executeTool = (
8
- config: FreestyleExecuteScriptParamsConfiguration & {
9
- apiKey: string;
10
- }
11
- ) => {
12
- const description = executeCodeDescription(
13
- Object.keys(config.envVars ?? {}).join(", "),
14
- Object.keys(config.nodeModules ?? {}).join(", ")
15
- );
16
-
17
- const client = new FreestyleSandboxes({
18
- apiKey: config.apiKey,
19
- });
20
-
21
- return createTool({
22
- id: "Execute a TypeScript or JavaScript Script",
23
- description,
24
- execute: async ({ context: { script } }) => {
25
- return await client.executeScript(script, config);
26
- },
27
- inputSchema: executeCodeSchema,
28
- outputSchema: z.object({
29
- logs: z.array(
30
- z.object({
31
- message: z.string(),
32
- type: z.string(),
33
- })
34
- ),
35
- result: z.unknown(),
36
- }),
37
- });
38
- };
@@ -1,195 +0,0 @@
1
- import {
2
- QueryClient,
3
- QueryClientProvider,
4
- useQuery,
5
- } from "@tanstack/react-query";
6
- import React from "react";
7
- import { RequestDevServerActions } from "./types";
8
-
9
- const queryClient = new QueryClient();
10
-
11
- export function DefaultLoadingComponent({
12
- installCommandRunning,
13
- }: {
14
- devCommandRunning: boolean;
15
- installCommandRunning: boolean;
16
- serverStarting: boolean;
17
- iframeLoading: boolean;
18
- }) {
19
- let loadingText = "Starting container...";
20
-
21
- if (installCommandRunning) {
22
- loadingText = "Installing dependencies...";
23
- } else {
24
- loadingText = "Starting dev server...";
25
- }
26
-
27
- return (
28
- <div
29
- style={{
30
- display: "flex",
31
- flexDirection: "column",
32
- alignItems: "center",
33
- justifyContent: "center",
34
- height: "100%",
35
- }}
36
- >
37
- {loadingText}
38
- </div>
39
- );
40
- }
41
-
42
- export interface FreestyleDevServerHandle {
43
- refresh: () => void;
44
- }
45
-
46
- export const FreestyleDevServer = React.forwardRef<
47
- FreestyleDevServerHandle,
48
- {
49
- repoId: string;
50
- loadingComponent?: (props: {
51
- devCommandRunning: boolean;
52
- installCommandRunning: boolean;
53
- serverStarting: boolean;
54
- iframeLoading: boolean;
55
- }) => React.ReactNode;
56
- actions: RequestDevServerActions;
57
- }
58
- >(({ loadingComponent, actions, repoId }, ref) => {
59
- return (
60
- <QueryClientProvider client={queryClient}>
61
- <FreestyleDevServerInner
62
- ref={ref}
63
- loadingComponent={loadingComponent ?? DefaultLoadingComponent}
64
- repoId={repoId}
65
- actions={actions}
66
- />
67
- </QueryClientProvider>
68
- );
69
- });
70
-
71
- const FreestyleDevServerInner = React.forwardRef<
72
- FreestyleDevServerHandle,
73
- {
74
- repoId: string;
75
- loadingComponent: (props: {
76
- devCommandRunning: boolean;
77
- installCommandRunning: boolean;
78
- serverStarting: boolean;
79
- iframeLoading: boolean;
80
- }) => React.ReactNode;
81
- actions: RequestDevServerActions;
82
- }
83
- >(({ repoId, loadingComponent, actions: { requestDevServer } }, ref) => {
84
- const { data, isLoading } = useQuery({
85
- queryKey: ["dev-server", repoId],
86
- queryFn: async () => await requestDevServer({ repoId: repoId }),
87
- refetchInterval: 1000,
88
- });
89
-
90
- const iframeRef = React.useRef<HTMLIFrameElement>(null);
91
- const [wasLoaded, setWasLoaded] = React.useState(false);
92
- const [iframeLoaded, setIframeLoaded] = React.useState(false);
93
-
94
- // Function to refresh the iframe
95
- const refreshIframe = React.useCallback(() => {
96
- if (iframeRef.current && data?.ephemeralUrl) {
97
- setIframeLoaded(false);
98
- const currentSrc = iframeRef.current.src;
99
- iframeRef.current.src = "";
100
- setTimeout(() => {
101
- if (iframeRef.current) {
102
- iframeRef.current.src = currentSrc;
103
- }
104
- }, 50);
105
- }
106
- }, [data?.ephemeralUrl]);
107
-
108
- // Expose refresh method through ref
109
- React.useImperativeHandle(
110
- ref,
111
- () => ({
112
- refresh: refreshIframe,
113
- }),
114
- [refreshIframe],
115
- );
116
-
117
- React.useMemo(() => {
118
- if (data?.devCommandRunning) {
119
- setWasLoaded(true);
120
- }
121
- }, [isLoading, data?.devCommandRunning]);
122
-
123
- React.useEffect(() => {
124
- function loadHandle() {
125
- setIframeLoaded(true);
126
- }
127
-
128
- iframeRef.current?.addEventListener("load", loadHandle);
129
- return () => {
130
- iframeRef.current?.removeEventListener("load", loadHandle);
131
- };
132
- }, []);
133
-
134
- if (isLoading) {
135
- return loadingComponent({
136
- devCommandRunning: false,
137
- installCommandRunning: false,
138
- serverStarting: true,
139
- iframeLoading: false,
140
- });
141
- }
142
-
143
- if (!data?.devCommandRunning && !wasLoaded) {
144
- return loadingComponent({
145
- devCommandRunning: data?.devCommandRunning ?? false,
146
- installCommandRunning: data?.installCommandRunning ?? false,
147
- serverStarting: false,
148
- iframeLoading: false,
149
- });
150
- }
151
-
152
- return (
153
- <div
154
- style={{
155
- display: "grid",
156
- gridTemplateRows: "1fr",
157
- gridTemplateColumns: "1fr",
158
- width: "100%",
159
- height: "100%",
160
- }}
161
- >
162
- {
163
- <div
164
- style={{
165
- width: "100%",
166
- height: "100%",
167
- border: "none",
168
- gridColumn: "1 / -1",
169
- gridRow: "1 / -1",
170
- visibility: iframeLoaded ? "hidden" : "visible",
171
- }}
172
- >
173
- {loadingComponent({
174
- devCommandRunning: data?.devCommandRunning ?? false,
175
- installCommandRunning: data?.installCommandRunning ?? false,
176
- serverStarting: false,
177
- iframeLoading: true,
178
- })}
179
- </div>
180
- }
181
- <iframe
182
- ref={iframeRef}
183
- sandbox="allow-scripts allow-same-origin allow-forms"
184
- src={data.ephemeralUrl}
185
- style={{
186
- width: "100%",
187
- height: "100%",
188
- border: "none",
189
- gridColumn: "1 / -1",
190
- gridRow: "1 / -1",
191
- }}
192
- />
193
- </div>
194
- );
195
- });
@@ -1,5 +0,0 @@
1
- export type RequestDevServerActions = {
2
- requestDevServer: (args: {
3
- repoId: string;
4
- }) => Promise<{ ephemeralUrl: string; devCommandRunning: boolean; installCommandRunning: boolean; }>;
5
- };
@@ -1,97 +0,0 @@
1
- import * as sandbox_openapi from "../../openapi/index.ts";
2
- import { glob, globSync } from "glob";
3
- import * as fs from "fs/promises";
4
- import * as fsSync from "fs";
5
- import * as path from "path";
6
-
7
- export const prepareDirForDeployment = async (
8
- directory: string
9
- ): Promise<sandbox_openapi.DeploymentSource> => {
10
- const files: sandbox_openapi.FreestyleDeployWebPayload["files"] = {};
11
-
12
- const patterns = await glob("**/*", {
13
- cwd: directory,
14
- nodir: true,
15
- ignore: ["**/node_modules/**"],
16
- absolute: false,
17
- dot: true,
18
- posix: true,
19
- });
20
-
21
- for (const relativePath of patterns) {
22
- try {
23
- const filePath = path.join(directory, relativePath);
24
- const content = await fs.readFile(filePath, "base64");
25
- files[relativePath] = {
26
- content,
27
- encoding: "base64",
28
- };
29
- } catch (error) {
30
- console.error(`Error reading file ${relativePath}:`, error);
31
- }
32
- }
33
-
34
- return {
35
- kind: "files",
36
- files,
37
- };
38
- };
39
-
40
- export const prepareDirForDeploymentSync = (
41
- directory: string
42
- ): sandbox_openapi.DeploymentSource => {
43
- const files: sandbox_openapi.FreestyleDeployWebPayload["files"] = {};
44
-
45
- const patterns = globSync("**/*", {
46
- cwd: directory,
47
- nodir: true,
48
- ignore: ["**/node_modules/**"],
49
- absolute: false,
50
- dot: true,
51
- posix: true,
52
- });
53
-
54
- for (const relativePath of patterns) {
55
- try {
56
- const filePath = path.join(directory, relativePath);
57
- const content = fsSync.readFileSync(filePath, "base64");
58
- files[relativePath] = {
59
- content,
60
- encoding: "base64",
61
- };
62
- } catch (error) {
63
- console.error(`Error reading file ${relativePath}:`, error);
64
- }
65
- }
66
-
67
- return {
68
- kind: "files",
69
- files,
70
- };
71
- };
72
-
73
- /**
74
- * This is in beta, and may not work as expected. **SUBJECT TO CHANGE.**
75
- */
76
- export const prepareNextJsForDeployment = async (
77
- directory: string
78
- ): Promise<sandbox_openapi.DeploymentSource> => {
79
- const publicDir = path.join(directory, "public");
80
- const nextPublicDestination = path.join(directory, ".next/standalone/public");
81
-
82
- const staticDir = path.join(directory, ".next/static");
83
- const nextStaticDestination = path.join(
84
- directory,
85
- ".next/standalone/.next/static"
86
- );
87
-
88
- // now copy everything from publicDir to nextPublicDestination
89
- // and everything from staticDir to nextStaticDestination
90
- await fs.mkdir(nextPublicDestination, { recursive: true });
91
- await fs.copyFile(publicDir, nextPublicDestination);
92
-
93
- await fs.mkdir(nextStaticDestination, { recursive: true });
94
- await fs.copyFile(staticDir, nextStaticDestination);
95
-
96
- return await prepareDirForDeployment(directory);
97
- };
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowImportingTsExtensions": true,
4
- "jsx": "react",
5
- "lib": ["ESNext", "DOM"],
6
- "esModuleInterop": true
7
- }
8
- }