freestyle-sandboxes 0.0.63 → 0.0.65

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/inde.d.cts CHANGED
@@ -180,7 +180,7 @@ declare class FreestyleSandboxes {
180
180
  * ephemeral so you should call this function every time you need a url. Do
181
181
  * not store the url in your database!
182
182
  */
183
- requestDevServer({ repoUrl, repoId, baseId, }: {
183
+ requestDevServer(options: {
184
184
  /**
185
185
  * @deprecated
186
186
  */
@@ -188,10 +188,11 @@ declare class FreestyleSandboxes {
188
188
  repoId?: string;
189
189
  repo?: string;
190
190
  baseId?: string;
191
+ devCommand?: string;
191
192
  }): Promise<{
192
193
  mcpEphemeralUrl: any;
193
194
  ephemeralUrl: string;
194
- codeServerUrl: string;
195
+ codeServerUrl: any;
195
196
  url: string;
196
197
  isNew: boolean;
197
198
  devCommandRunning: boolean;
package/dist/inde.d.mts CHANGED
@@ -180,7 +180,7 @@ declare class FreestyleSandboxes {
180
180
  * ephemeral so you should call this function every time you need a url. Do
181
181
  * not store the url in your database!
182
182
  */
183
- requestDevServer({ repoUrl, repoId, baseId, }: {
183
+ requestDevServer(options: {
184
184
  /**
185
185
  * @deprecated
186
186
  */
@@ -188,10 +188,11 @@ declare class FreestyleSandboxes {
188
188
  repoId?: string;
189
189
  repo?: string;
190
190
  baseId?: string;
191
+ devCommand?: string;
191
192
  }): Promise<{
192
193
  mcpEphemeralUrl: any;
193
194
  ephemeralUrl: string;
194
- codeServerUrl: string;
195
+ codeServerUrl: any;
195
196
  url: string;
196
197
  isNew: boolean;
197
198
  devCommandRunning: boolean;
package/dist/index.cjs CHANGED
@@ -777,30 +777,31 @@ ${response.error.message}`);
777
777
  * ephemeral so you should call this function every time you need a url. Do
778
778
  * not store the url in your database!
779
779
  */
780
- async requestDevServer({
781
- repoUrl,
782
- repoId,
783
- baseId
784
- }) {
785
- function formatHook(serverUrl, repoUrl2) {
786
- const hook = serverUrl + "/__freestyle_dev_server/update/git?repo=" + encodeURIComponent(repoUrl2);
780
+ async requestDevServer(options) {
781
+ function formatHook(serverUrl, repoUrl) {
782
+ const hook = serverUrl + "/__freestyle_dev_server/update/git?repo=" + encodeURIComponent(repoUrl);
787
783
  return hook;
788
784
  }
789
785
  const response = await handleEphemeralDevServer({
790
786
  client: this.client,
791
787
  body: {
788
+ ...options,
792
789
  // @ts-ignore
793
- repo: repoUrl,
794
- repoId,
795
- baseId
790
+ repo: options.repoUrl
796
791
  }
797
792
  });
793
+ if (response.error) {
794
+ throw new Error(`Failed to request dev server: ${response.error}`);
795
+ }
798
796
  if (response.data.isNew) {
799
- const rId = repoId || repoUrl.split("/").at(-1);
797
+ const rId = options.repoId || options.repoUrl.split("/").at(-1);
800
798
  await this.createGitTrigger({
801
799
  repoId: rId,
802
800
  action: {
803
- endpoint: formatHook(response.data?.url, repoUrl || `https://git.freestyle.sh/${rId}`),
801
+ endpoint: formatHook(
802
+ response.data?.url,
803
+ options.repoUrl || `https://git.freestyle.sh/${rId}`
804
+ ),
804
805
  action: "webhook"
805
806
  },
806
807
  trigger: {
@@ -815,9 +816,11 @@ ${response.error.message}`);
815
816
  ...response.data,
816
817
  // @ts-ignore
817
818
  mcpEphemeralUrl: response.data.mcpEphemeralUrl || response.data.url + "/mcp",
818
- // @ts-ignore
819
819
  ephemeralUrl: response.data.ephemeralUrl ?? response.data.url,
820
- codeServerUrl: response.data.ephemeralUrl + "/__freestyle_code_server/?folder=/template"
820
+ codeServerUrl: (
821
+ // @ts-ignore
822
+ response.data.codeServerUrl ?? response.data.ephemeralUrl + "/__freestyle_code_server/?folder=/template"
823
+ )
821
824
  };
822
825
  }
823
826
  }
package/dist/index.d.cts CHANGED
@@ -180,7 +180,7 @@ declare class FreestyleSandboxes {
180
180
  * ephemeral so you should call this function every time you need a url. Do
181
181
  * not store the url in your database!
182
182
  */
183
- requestDevServer({ repoUrl, repoId, baseId, }: {
183
+ requestDevServer(options: {
184
184
  /**
185
185
  * @deprecated
186
186
  */
@@ -188,10 +188,11 @@ declare class FreestyleSandboxes {
188
188
  repoId?: string;
189
189
  repo?: string;
190
190
  baseId?: string;
191
+ devCommand?: string;
191
192
  }): Promise<{
192
193
  mcpEphemeralUrl: any;
193
194
  ephemeralUrl: string;
194
- codeServerUrl: string;
195
+ codeServerUrl: any;
195
196
  url: string;
196
197
  isNew: boolean;
197
198
  devCommandRunning: boolean;
package/dist/index.d.mts CHANGED
@@ -180,7 +180,7 @@ declare class FreestyleSandboxes {
180
180
  * ephemeral so you should call this function every time you need a url. Do
181
181
  * not store the url in your database!
182
182
  */
183
- requestDevServer({ repoUrl, repoId, baseId, }: {
183
+ requestDevServer(options: {
184
184
  /**
185
185
  * @deprecated
186
186
  */
@@ -188,10 +188,11 @@ declare class FreestyleSandboxes {
188
188
  repoId?: string;
189
189
  repo?: string;
190
190
  baseId?: string;
191
+ devCommand?: string;
191
192
  }): Promise<{
192
193
  mcpEphemeralUrl: any;
193
194
  ephemeralUrl: string;
194
- codeServerUrl: string;
195
+ codeServerUrl: any;
195
196
  url: string;
196
197
  isNew: boolean;
197
198
  devCommandRunning: boolean;
package/dist/index.mjs CHANGED
@@ -775,30 +775,31 @@ ${response.error.message}`);
775
775
  * ephemeral so you should call this function every time you need a url. Do
776
776
  * not store the url in your database!
777
777
  */
778
- async requestDevServer({
779
- repoUrl,
780
- repoId,
781
- baseId
782
- }) {
783
- function formatHook(serverUrl, repoUrl2) {
784
- const hook = serverUrl + "/__freestyle_dev_server/update/git?repo=" + encodeURIComponent(repoUrl2);
778
+ async requestDevServer(options) {
779
+ function formatHook(serverUrl, repoUrl) {
780
+ const hook = serverUrl + "/__freestyle_dev_server/update/git?repo=" + encodeURIComponent(repoUrl);
785
781
  return hook;
786
782
  }
787
783
  const response = await handleEphemeralDevServer({
788
784
  client: this.client,
789
785
  body: {
786
+ ...options,
790
787
  // @ts-ignore
791
- repo: repoUrl,
792
- repoId,
793
- baseId
788
+ repo: options.repoUrl
794
789
  }
795
790
  });
791
+ if (response.error) {
792
+ throw new Error(`Failed to request dev server: ${response.error}`);
793
+ }
796
794
  if (response.data.isNew) {
797
- const rId = repoId || repoUrl.split("/").at(-1);
795
+ const rId = options.repoId || options.repoUrl.split("/").at(-1);
798
796
  await this.createGitTrigger({
799
797
  repoId: rId,
800
798
  action: {
801
- endpoint: formatHook(response.data?.url, repoUrl || `https://git.freestyle.sh/${rId}`),
799
+ endpoint: formatHook(
800
+ response.data?.url,
801
+ options.repoUrl || `https://git.freestyle.sh/${rId}`
802
+ ),
802
803
  action: "webhook"
803
804
  },
804
805
  trigger: {
@@ -813,9 +814,11 @@ ${response.error.message}`);
813
814
  ...response.data,
814
815
  // @ts-ignore
815
816
  mcpEphemeralUrl: response.data.mcpEphemeralUrl || response.data.url + "/mcp",
816
- // @ts-ignore
817
817
  ephemeralUrl: response.data.ephemeralUrl ?? response.data.url,
818
- codeServerUrl: response.data.ephemeralUrl + "/__freestyle_code_server/?folder=/template"
818
+ codeServerUrl: (
819
+ // @ts-ignore
820
+ response.data.codeServerUrl ?? response.data.ephemeralUrl + "/__freestyle_code_server/?folder=/template"
821
+ )
819
822
  };
820
823
  }
821
824
  }
@@ -52,15 +52,6 @@ function FreestyleDevServerInner({
52
52
  refetchInterval: 1e3
53
53
  });
54
54
  const ref = React.useRef(null);
55
- React.useEffect(() => {
56
- if (!data?.ephemeralUrl) return;
57
- const interval = setInterval(() => {
58
- if (ref.current) {
59
- ref.current.src = data.ephemeralUrl;
60
- }
61
- }, 45 * 1e3);
62
- return () => clearInterval(interval);
63
- }, [data?.ephemeralUrl]);
64
55
  const [wasLoaded, setWasLoaded] = React.useState(false);
65
56
  const [iframeLoaded, setIframeLoaded] = React.useState(false);
66
57
  React.useMemo(() => {
@@ -69,9 +60,13 @@ function FreestyleDevServerInner({
69
60
  }
70
61
  }, [isLoading, data?.devCommandRunning]);
71
62
  React.useEffect(() => {
72
- ref.current?.addEventListener("load", () => {
63
+ function loadHandle() {
73
64
  setIframeLoaded(true);
74
- });
65
+ }
66
+ ref.current?.addEventListener("load", loadHandle);
67
+ return () => {
68
+ ref.current?.removeEventListener("load", loadHandle);
69
+ };
75
70
  }, [ref]);
76
71
  if (isLoading) {
77
72
  return loadingComponent({
@@ -50,15 +50,6 @@ function FreestyleDevServerInner({
50
50
  refetchInterval: 1e3
51
51
  });
52
52
  const ref = React.useRef(null);
53
- React.useEffect(() => {
54
- if (!data?.ephemeralUrl) return;
55
- const interval = setInterval(() => {
56
- if (ref.current) {
57
- ref.current.src = data.ephemeralUrl;
58
- }
59
- }, 45 * 1e3);
60
- return () => clearInterval(interval);
61
- }, [data?.ephemeralUrl]);
62
53
  const [wasLoaded, setWasLoaded] = React.useState(false);
63
54
  const [iframeLoaded, setIframeLoaded] = React.useState(false);
64
55
  React.useMemo(() => {
@@ -67,9 +58,13 @@ function FreestyleDevServerInner({
67
58
  }
68
59
  }, [isLoading, data?.devCommandRunning]);
69
60
  React.useEffect(() => {
70
- ref.current?.addEventListener("load", () => {
61
+ function loadHandle() {
71
62
  setIframeLoaded(true);
72
- });
63
+ }
64
+ ref.current?.addEventListener("load", loadHandle);
65
+ return () => {
66
+ ref.current?.removeEventListener("load", loadHandle);
67
+ };
73
68
  }, [ref]);
74
69
  if (isLoading) {
75
70
  return loadingComponent({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle-sandboxes",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
package/src/index.ts CHANGED
@@ -797,17 +797,15 @@ export class FreestyleSandboxes {
797
797
  * ephemeral so you should call this function every time you need a url. Do
798
798
  * not store the url in your database!
799
799
  */
800
- async requestDevServer({
801
- repoUrl,
802
- repoId,
803
- baseId,
804
- }: {
800
+ async requestDevServer(options: {
805
801
  /**
806
802
  * @deprecated
807
803
  */
808
- repoUrl?: string,
809
- repoId?: string, repo?: string,
810
- baseId?: string,
804
+ repoUrl?: string;
805
+ repoId?: string;
806
+ repo?: string;
807
+ baseId?: string;
808
+ devCommand?: string;
811
809
  }) {
812
810
  function formatHook(serverUrl: string, repoUrl: string) {
813
811
  const hook =
@@ -820,21 +818,27 @@ export class FreestyleSandboxes {
820
818
  const response = await sandbox_openapi.handleEphemeralDevServer({
821
819
  client: this.client,
822
820
  body: {
821
+ ...options,
823
822
  // @ts-ignore
824
- repo: repoUrl,
825
- repoId: repoId,
826
- baseId: baseId
823
+ repo: options.repoUrl,
827
824
  },
828
825
  });
829
826
 
827
+ if (response.error) {
828
+ throw new Error(`Failed to request dev server: ${response.error}`);
829
+ }
830
+
830
831
  if (response.data.isNew) {
831
- const rId = repoId || repoUrl.split("/").at(-1)!;
832
+ const rId = options.repoId || options.repoUrl.split("/").at(-1)!;
832
833
 
833
834
  await this.createGitTrigger({
834
835
  repoId: rId,
835
836
  action: {
836
- endpoint: formatHook(response.data?.url!, repoUrl || `https://git.freestyle.sh/${rId}`),
837
- action: "webhook"
837
+ endpoint: formatHook(
838
+ response.data?.url!,
839
+ options.repoUrl || `https://git.freestyle.sh/${rId}`
840
+ ),
841
+ action: "webhook",
838
842
  },
839
843
  trigger: {
840
844
  event: "push",
@@ -850,9 +854,12 @@ export class FreestyleSandboxes {
850
854
  // @ts-ignore
851
855
  mcpEphemeralUrl:
852
856
  (response.data as any).mcpEphemeralUrl || response.data.url + "/mcp",
853
- // @ts-ignore
854
857
  ephemeralUrl: response.data.ephemeralUrl ?? response.data.url,
855
- codeServerUrl: response.data.ephemeralUrl + "/__freestyle_code_server/?folder=/template",
858
+ codeServerUrl:
859
+ // @ts-ignore
860
+ response.data.codeServerUrl ??
861
+ response.data.ephemeralUrl +
862
+ "/__freestyle_code_server/?folder=/template",
856
863
  };
857
864
  }
858
865
  }
@@ -84,21 +84,7 @@ function FreestyleDevServerInner({
84
84
  refetchInterval: 1000,
85
85
  });
86
86
 
87
- // keep reloading the iframe because there's a bug where the websocket
88
- // connection to the dev server is closed every 1 minute
89
87
  const ref = React.useRef<HTMLIFrameElement>(null);
90
- React.useEffect(() => {
91
- if (!data?.ephemeralUrl) return;
92
-
93
- const interval = setInterval(() => {
94
- if (ref.current) {
95
- ref.current.src = data.ephemeralUrl;
96
- }
97
- }, 45 * 1000);
98
-
99
- return () => clearInterval(interval);
100
- }, [data?.ephemeralUrl]);
101
-
102
88
  const [wasLoaded, setWasLoaded] = React.useState(false);
103
89
  const [iframeLoaded, setIframeLoaded] = React.useState(false);
104
90
 
@@ -109,9 +95,14 @@ function FreestyleDevServerInner({
109
95
  }, [isLoading, data?.devCommandRunning]);
110
96
 
111
97
  React.useEffect(() => {
112
- ref.current?.addEventListener("load", () => {
98
+ function loadHandle() {
113
99
  setIframeLoaded(true);
114
- });
100
+ }
101
+
102
+ ref.current?.addEventListener("load", loadHandle);
103
+ return () => {
104
+ ref.current?.removeEventListener("load", loadHandle);
105
+ };
115
106
  }, [ref]);
116
107
 
117
108
  if (isLoading) {