freestyle-sandboxes 0.0.68 → 0.0.70

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 (60) hide show
  1. package/dist/ai/inde.d.cts +1 -1
  2. package/dist/ai/inde.d.mts +1 -1
  3. package/dist/ai/index.d.cts +1 -1
  4. package/dist/ai/index.d.mts +1 -1
  5. package/dist/inde.d.cts +103 -25
  6. package/dist/inde.d.mts +103 -25
  7. package/dist/index-BBXyg0JQ.cjs +3253 -0
  8. package/dist/index-BQHqnjZK.mjs +3231 -0
  9. package/dist/index-CEEa9WHp.cjs +3238 -0
  10. package/dist/index-D1ulQeJR.mjs +3247 -0
  11. package/dist/index-DCF70Xbq.mjs +3246 -0
  12. package/dist/index-H7UNEAjs.cjs +3254 -0
  13. package/dist/index.cjs +249 -12
  14. package/dist/index.d-CXx1AdyW.d.ts +4210 -0
  15. package/dist/index.d.cts +103 -25
  16. package/dist/index.d.mts +103 -25
  17. package/dist/index.mjs +249 -12
  18. package/dist/langgraph/inde.d.cts +1 -1
  19. package/dist/langgraph/inde.d.mts +1 -1
  20. package/dist/langgraph/index.d.cts +1 -1
  21. package/dist/langgraph/index.d.mts +1 -1
  22. package/dist/mastra/inde.d.cts +1 -1
  23. package/dist/mastra/inde.d.mts +1 -1
  24. package/dist/mastra/index.d.cts +1 -1
  25. package/dist/mastra/index.d.mts +1 -1
  26. package/dist/types.gen-1sd31qLV.d.ts +172 -0
  27. package/dist/types.gen-627pxroW.d.ts +830 -0
  28. package/dist/types.gen-BCdfx7yt.d.ts +760 -0
  29. package/dist/types.gen-BVXmFV7d.d.ts +1299 -0
  30. package/dist/types.gen-BaMKzqxQ.d.ts +233 -0
  31. package/dist/types.gen-BtK6PMQy.d.ts +195 -0
  32. package/dist/types.gen-BuhQ5LpB.d.ts +764 -0
  33. package/dist/types.gen-BzRtj_TA.d.ts +725 -0
  34. package/dist/types.gen-C03gaIPq.d.ts +297 -0
  35. package/dist/types.gen-CMuCas4r.d.ts +183 -0
  36. package/dist/types.gen-CZUnqmzP.d.ts +789 -0
  37. package/dist/types.gen-CnEkmbco.d.ts +314 -0
  38. package/dist/types.gen-DDYpuDzZ.d.ts +764 -0
  39. package/dist/types.gen-DHmdEOOa.d.ts +172 -0
  40. package/dist/types.gen-DLYohMJT.d.ts +382 -0
  41. package/dist/types.gen-DbTb_SrD.d.ts +156 -0
  42. package/dist/types.gen-DkQ-Dbs1.d.ts +764 -0
  43. package/dist/{types.gen-BoJEFWW-.d.ts → types.gen-DyY7Deri.d.ts} +55 -1
  44. package/dist/types.gen-MBZCvIhE.d.ts +311 -0
  45. package/dist/types.gen-YhJAHBw8.d.ts +233 -0
  46. package/dist/types.gen-cCnnhnB6.d.ts +182 -0
  47. package/dist/types.gen-mg_JNXrq.d.ts +830 -0
  48. package/dist/types.gen-uDTr6v-7.d.ts +731 -0
  49. package/dist/utils/inde.d.cts +1 -1
  50. package/dist/utils/inde.d.mts +1 -1
  51. package/dist/utils/index.d.cts +1 -1
  52. package/dist/utils/index.d.mts +1 -1
  53. package/openapi/sdk.gen.ts +71 -10
  54. package/openapi/types.gen.ts +233 -28
  55. package/openapi.json +1 -1
  56. package/package.json +2 -2
  57. package/src/dev-server.ts +92 -0
  58. package/src/index.ts +319 -27
  59. package/src/react/dev-server/index.tsx +3 -3
  60. package/.env +0 -1
package/dist/index.cjs CHANGED
@@ -57,6 +57,42 @@ const handleEphemeralDevServer = (options) => {
57
57
  url: "/ephemeral/v1/dev-servers"
58
58
  });
59
59
  };
60
+ const handleExecOnEphemeralDevServer = (options) => {
61
+ return (options?.client ?? client).post({
62
+ ...options,
63
+ url: "/ephemeral/v1/dev-servers/exec"
64
+ });
65
+ };
66
+ const handleWriteFileFromEphemeralDevServer = (options) => {
67
+ return (options?.client ?? client).put({
68
+ ...options,
69
+ url: "/ephemeral/v1/dev-servers/files/{*filepath}"
70
+ });
71
+ };
72
+ const handleReadFileFromEphemeralDevServer = (options) => {
73
+ return (options?.client ?? client).post({
74
+ ...options,
75
+ url: "/ephemeral/v1/dev-servers/files/{*filepath}"
76
+ });
77
+ };
78
+ const handleGitCommitPush = (options) => {
79
+ return (options?.client ?? client).post({
80
+ ...options,
81
+ url: "/ephemeral/v1/dev-servers/git/commit-push"
82
+ });
83
+ };
84
+ const handleShutdownDevServer = (options) => {
85
+ return (options?.client ?? client).post({
86
+ ...options,
87
+ url: "/ephemeral/v1/dev-servers/shutdown"
88
+ });
89
+ };
90
+ const handleDevServerStatus = (options) => {
91
+ return (options?.client ?? client).get({
92
+ ...options,
93
+ url: "/ephemeral/v1/dev-servers/status"
94
+ });
95
+ };
60
96
  const handleListExecuteRuns = (options) => {
61
97
  return (options?.client ?? client).get({
62
98
  ...options,
@@ -192,7 +228,17 @@ const handleListWebDeploys = (options) => {
192
228
 
193
229
  class FreestyleSandboxes {
194
230
  client;
231
+ options;
195
232
  constructor(options) {
233
+ this.options = options ?? {};
234
+ if (!options?.apiKey) {
235
+ this.options.apiKey = process.env.FREESTYLE_API_KEY;
236
+ }
237
+ if (!this.options.apiKey) {
238
+ throw new Error(
239
+ "No API key provided. Please set the FREESTYLE_API_KEY environment variable or configure apiKey when constructing FreestyleSandboxes."
240
+ );
241
+ }
196
242
  if (typeof Deno !== "undefined") {
197
243
  class FreestyleRequest extends Request {
198
244
  constructor(input, init) {
@@ -206,10 +252,10 @@ class FreestyleSandboxes {
206
252
  Request = FreestyleRequest;
207
253
  }
208
254
  this.client = clientFetch.createClient({
209
- baseUrl: options.baseUrl ?? "https://api.freestyle.sh",
255
+ baseUrl: this.options?.baseUrl ?? "https://api.freestyle.sh",
210
256
  headers: {
211
- Authorization: `Bearer ${options.apiKey}`,
212
- ...options.headers
257
+ Authorization: `Bearer ${this.options.apiKey}`,
258
+ ...this.options?.headers
213
259
  }
214
260
  });
215
261
  }
@@ -797,7 +843,7 @@ ${response.error.message}`);
797
843
  );
798
844
  }
799
845
  if (response.data.isNew) {
800
- const rId = options.repoId || options.repoUrl.split("/").at(-1);
846
+ const rId = options.repoId || options.repoUrl?.split("/").at(-1);
801
847
  await this.createGitTrigger({
802
848
  repoId: rId,
803
849
  action: {
@@ -815,17 +861,208 @@ ${response.error.message}`);
815
861
  if (!response.data) {
816
862
  throw new Error(`Failed to request dev server: ${response.error}`);
817
863
  }
864
+ const data = response.data;
865
+ const devServerInstance = {
866
+ repoId: options.repoId || options.repo || "",
867
+ kind: "repo"
868
+ };
869
+ const client = this.client;
870
+ const that = this;
818
871
  return {
819
- ...response.data,
820
- // @ts-ignore
821
- mcpEphemeralUrl: response.data.mcpEphemeralUrl || response.data.url + "/mcp",
822
- ephemeralUrl: response.data.ephemeralUrl ?? response.data.url,
823
- codeServerUrl: (
824
- // @ts-ignore
825
- response.data.codeServerUrl ?? response.data.ephemeralUrl + "/__freestyle_code_server/?folder=/template"
826
- )
872
+ isNew: data.isNew,
873
+ ephemeralUrl: data.ephemeralUrl ?? data.url,
874
+ mcpEphemeralUrl: data.mcpEphemeralUrl ?? data.url + "/mcp",
875
+ codeServerUrl: data.codeServerUrl ?? (data.ephemeralUrl ?? data.url) + "/__freestyle_code_server/?folder=/template",
876
+ async status() {
877
+ const response2 = await handleDevServerStatus({
878
+ client,
879
+ body: {
880
+ devServer: devServerInstance
881
+ }
882
+ });
883
+ if (response2.error) {
884
+ throw new Error(`Failed to get status: ${response2.error}`);
885
+ }
886
+ return {
887
+ installing: response2.data.installing,
888
+ devRunning: response2.data.devRunning
889
+ };
890
+ },
891
+ async commitAndPush(message) {
892
+ const response2 = await handleGitCommitPush({
893
+ client,
894
+ body: {
895
+ devServer: devServerInstance,
896
+ message
897
+ }
898
+ });
899
+ if (response2.error) {
900
+ throw new Error(`Failed to commit and push: ${response2.error}`);
901
+ }
902
+ },
903
+ async shutdown() {
904
+ const response2 = await handleShutdownDevServer({
905
+ client,
906
+ body: {
907
+ devServer: devServerInstance
908
+ }
909
+ });
910
+ if (response2.error) {
911
+ throw new Error(`Failed to shutdown dev server: ${response2.error}`);
912
+ }
913
+ return {
914
+ success: response2.data.success,
915
+ message: response2.data.message
916
+ };
917
+ },
918
+ fs: {
919
+ async ls(path = "") {
920
+ const response2 = await handleReadFileFromEphemeralDevServer({
921
+ client,
922
+ path: {
923
+ filepath: path
924
+ },
925
+ body: {
926
+ devServer: devServerInstance,
927
+ encoding: "utf-8"
928
+ }
929
+ });
930
+ if (response2.error) {
931
+ throw new Error(`Failed to list directory: ${response2.error}`);
932
+ }
933
+ if (!response2.data?.content) {
934
+ return [];
935
+ }
936
+ if (response2.data.content.kind === "directory") {
937
+ return response2.data.content.files;
938
+ }
939
+ return [];
940
+ },
941
+ async *watch() {
942
+ const response2 = await that.fetch(
943
+ "/ephemeral/v1/dev-servers/watch-files",
944
+ {
945
+ method: "POST",
946
+ body: JSON.stringify({
947
+ devServer: {
948
+ repoId: devServerInstance.repoId,
949
+ kind: devServerInstance.kind
950
+ }
951
+ })
952
+ }
953
+ );
954
+ if (!response2.ok) {
955
+ throw new Error(
956
+ `Failed to fetch stream: ${response2.status} ${response2.statusText}`
957
+ );
958
+ }
959
+ if (!response2.body) {
960
+ throw new Error("Failed to fetch stream: No response body");
961
+ }
962
+ const reader = response2.body.getReader();
963
+ const decoder = new TextDecoder("utf-8");
964
+ let buffer = "";
965
+ while (true) {
966
+ const { done, value } = await reader.read();
967
+ if (done) break;
968
+ buffer += decoder.decode(value, { stream: true });
969
+ let newlineIndex;
970
+ while ((newlineIndex = buffer.indexOf("\n")) >= 0) {
971
+ const line = buffer.slice(0, newlineIndex).trim();
972
+ buffer = buffer.slice(newlineIndex + 1);
973
+ if (line) {
974
+ yield JSON.parse(line);
975
+ }
976
+ }
977
+ }
978
+ if (buffer.trim()) {
979
+ yield JSON.parse(buffer.trim());
980
+ }
981
+ },
982
+ async readFile(path, encoding = "utf-8") {
983
+ const response2 = await handleReadFileFromEphemeralDevServer({
984
+ client,
985
+ path: {
986
+ filepath: path
987
+ },
988
+ body: {
989
+ devServer: devServerInstance,
990
+ encoding
991
+ }
992
+ });
993
+ if (response2.error) {
994
+ throw new Error(`Failed to read file: ${response2.error}`);
995
+ }
996
+ if (!response2.data?.content || response2.data.content.kind !== "file") {
997
+ throw new Error(`Not a file or file not found: ${path}`);
998
+ }
999
+ return response2.data.content.content;
1000
+ },
1001
+ async writeFile(path, content, encoding = "utf-8") {
1002
+ const contentStr = typeof content === "string" ? content : new TextDecoder(encoding).decode(content);
1003
+ const response2 = await handleWriteFileFromEphemeralDevServer({
1004
+ client,
1005
+ path: {
1006
+ filepath: path
1007
+ },
1008
+ body: {
1009
+ devServer: devServerInstance,
1010
+ content: contentStr,
1011
+ encoding
1012
+ }
1013
+ });
1014
+ if (response2.error) {
1015
+ throw new Error(`Failed to write file: ${response2.error}`);
1016
+ }
1017
+ }
1018
+ },
1019
+ process: {
1020
+ async exec(cmd, background = false) {
1021
+ const response2 = await handleExecOnEphemeralDevServer(
1022
+ {
1023
+ client,
1024
+ body: {
1025
+ devServer: devServerInstance,
1026
+ command: cmd,
1027
+ background
1028
+ }
1029
+ }
1030
+ );
1031
+ if (response2.error) {
1032
+ throw new Error(`Failed to execute command: ${response2.error}`);
1033
+ }
1034
+ return {
1035
+ id: response2.data.id,
1036
+ isNew: response2.data.isNew,
1037
+ stdout: response2.data.stdout,
1038
+ stderr: response2.data.stderr
1039
+ };
1040
+ }
1041
+ }
827
1042
  };
828
1043
  }
1044
+ fetch(path, init) {
1045
+ const headers = new Headers(init?.headers);
1046
+ for (const [key, value] of Object.entries(this.options.headers ?? {})) {
1047
+ if (!headers.has(key)) {
1048
+ headers.append(key, value);
1049
+ }
1050
+ }
1051
+ if (!headers.has("Authorization")) {
1052
+ headers.append("Authorization", `Bearer ${this.options.apiKey}`);
1053
+ }
1054
+ if (!headers.has("Content-Type")) {
1055
+ headers.append("Content-Type", "application/json");
1056
+ }
1057
+ const url = new URL(
1058
+ path,
1059
+ this.options.baseUrl ?? "https://api.freestyle.sh"
1060
+ );
1061
+ return fetch(url, {
1062
+ ...init ?? {},
1063
+ headers
1064
+ });
1065
+ }
829
1066
  }
830
1067
 
831
1068
  exports.FreestyleSandboxes = FreestyleSandboxes;