freestyle-sandboxes 0.0.97 → 0.1.1

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 +4381 -0
  3. package/index.d.cts +9404 -0
  4. package/index.d.mts +9404 -0
  5. package/index.mjs +4367 -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
package/dist/index.cjs DELETED
@@ -1,1329 +0,0 @@
1
- 'use strict';
2
-
3
- var clientFetch = require('@hey-api/client-fetch');
4
-
5
- const client = clientFetch.createClient(clientFetch.createConfig());
6
- const handleDeployCloudstate = (options) => {
7
- return (options?.client ?? client).post({
8
- ...options,
9
- url: "/cloudstate/v1/deploy"
10
- });
11
- };
12
- const handleBackupCloudstate = (options) => {
13
- return (options?.client ?? client).get({
14
- ...options,
15
- url: "/cloudstate/v1/projects/{id}/backup"
16
- });
17
- };
18
- const handleVerifyWildcard = (options) => {
19
- return (options?.client ?? client).post({
20
- ...options,
21
- url: "/domains/v1/certs/{domain}/wildcard"
22
- });
23
- };
24
- const handleListDomains = (options) => {
25
- return (options?.client ?? client).get({
26
- ...options,
27
- url: "/domains/v1/domains"
28
- });
29
- };
30
- const handleListDomainMappings = (options) => {
31
- return (options?.client ?? client).get({
32
- ...options,
33
- url: "/domains/v1/mappings"
34
- });
35
- };
36
- const handleInsertDomainMapping = (options) => {
37
- return (options?.client ?? client).post({
38
- ...options,
39
- url: "/domains/v1/mappings/{domain}"
40
- });
41
- };
42
- const handleDeleteDomainMapping = (options) => {
43
- return (options?.client ?? client).delete({
44
- ...options,
45
- url: "/domains/v1/mappings/{domain}"
46
- });
47
- };
48
- const handleListDomainVerificationRequests = (options) => {
49
- return (options?.client ?? client).get({
50
- ...options,
51
- url: "/domains/v1/verifications"
52
- });
53
- };
54
- const handleVerifyDomain = (options) => {
55
- return (options?.client ?? client).put({
56
- ...options,
57
- url: "/domains/v1/verifications"
58
- });
59
- };
60
- const handleCreateDomainVerification = (options) => {
61
- return (options?.client ?? client).post({
62
- ...options,
63
- url: "/domains/v1/verifications"
64
- });
65
- };
66
- const handleDeleteDomainVerification = (options) => {
67
- return (options?.client ?? client).delete({
68
- ...options,
69
- url: "/domains/v1/verifications"
70
- });
71
- };
72
- const handleEphemeralDevServer = (options) => {
73
- return (options?.client ?? client).post({
74
- ...options,
75
- url: "/ephemeral/v1/dev-servers"
76
- });
77
- };
78
- const handleExecOnEphemeralDevServer = (options) => {
79
- return (options?.client ?? client).post({
80
- ...options,
81
- url: "/ephemeral/v1/dev-servers/exec"
82
- });
83
- };
84
- const handleWriteFileFromEphemeralDevServer = (options) => {
85
- return (options?.client ?? client).put({
86
- ...options,
87
- url: "/ephemeral/v1/dev-servers/files/{filepath}"
88
- });
89
- };
90
- const handleReadFileFromEphemeralDevServer = (options) => {
91
- return (options?.client ?? client).post({
92
- ...options,
93
- url: "/ephemeral/v1/dev-servers/files/{filepath}"
94
- });
95
- };
96
- const handleGitCommitPush = (options) => {
97
- return (options?.client ?? client).post({
98
- ...options,
99
- url: "/ephemeral/v1/dev-servers/git/commit-push"
100
- });
101
- };
102
- const handleShutdownDevServer = (options) => {
103
- return (options?.client ?? client).post({
104
- ...options,
105
- url: "/ephemeral/v1/dev-servers/shutdown"
106
- });
107
- };
108
- const handleDevServerStatus = (options) => {
109
- return (options?.client ?? client).get({
110
- ...options,
111
- url: "/ephemeral/v1/dev-servers/status"
112
- });
113
- };
114
- const handleListExecuteRuns = (options) => {
115
- return (options?.client ?? client).get({
116
- ...options,
117
- url: "/execute/v1/deployments"
118
- });
119
- };
120
- const handleGetExecuteRun = (options) => {
121
- return (options?.client ?? client).get({
122
- ...options,
123
- url: "/execute/v1/deployments/{deployment}"
124
- });
125
- };
126
- const handleExecuteScript = (options) => {
127
- return (options?.client ?? client).post({
128
- ...options,
129
- url: "/execute/v1/script"
130
- });
131
- };
132
- const handleCreateIdentity = (options) => {
133
- return (options?.client ?? client).post({
134
- ...options,
135
- url: "/git/v1/identity"
136
- });
137
- };
138
- const handleDeleteIdentity = (options) => {
139
- return (options?.client ?? client).delete({
140
- ...options,
141
- url: "/git/v1/identity/{identity}"
142
- });
143
- };
144
- const handleListPermissions = (options) => {
145
- return (options?.client ?? client).get({
146
- ...options,
147
- url: "/git/v1/identity/{identity}/permissions"
148
- });
149
- };
150
- const handleDescribePermission = (options) => {
151
- return (options?.client ?? client).get({
152
- ...options,
153
- url: "/git/v1/identity/{identity}/permissions/{repo}"
154
- });
155
- };
156
- const handleGrantPermission = (options) => {
157
- return (options?.client ?? client).post({
158
- ...options,
159
- url: "/git/v1/identity/{identity}/permissions/{repo}"
160
- });
161
- };
162
- const handleRevokePermission = (options) => {
163
- return (options?.client ?? client).delete({
164
- ...options,
165
- url: "/git/v1/identity/{identity}/permissions/{repo}"
166
- });
167
- };
168
- const handleUpdatePermission = (options) => {
169
- return (options?.client ?? client).patch({
170
- ...options,
171
- url: "/git/v1/identity/{identity}/permissions/{repo}"
172
- });
173
- };
174
- const handleListGitTokens = (options) => {
175
- return (options?.client ?? client).get({
176
- ...options,
177
- url: "/git/v1/identity/{identity}/tokens"
178
- });
179
- };
180
- const handleCreateGitToken = (options) => {
181
- return (options?.client ?? client).post({
182
- ...options,
183
- url: "/git/v1/identity/{identity}/tokens"
184
- });
185
- };
186
- const handleRevokeGitToken = (options) => {
187
- return (options?.client ?? client).delete({
188
- ...options,
189
- url: "/git/v1/identity/{identity}/tokens"
190
- });
191
- };
192
- const handleListRepositories = (options) => {
193
- return (options?.client ?? client).get({
194
- ...options,
195
- url: "/git/v1/repo"
196
- });
197
- };
198
- const handleCreateRepo = (options) => {
199
- return (options?.client ?? client).post({
200
- ...options,
201
- url: "/git/v1/repo"
202
- });
203
- };
204
- const handleGetDefaultBranch = (options) => {
205
- return (options?.client ?? client).get({
206
- ...options,
207
- url: "/git/v1/repo/{repo_id}/default-branch"
208
- });
209
- };
210
- const handleSetDefaultBranch = (options) => {
211
- return (options?.client ?? client).put({
212
- ...options,
213
- url: "/git/v1/repo/{repo_id}/default-branch"
214
- });
215
- };
216
- const getGithubSync = (options) => {
217
- return (options?.client ?? client).get({
218
- ...options,
219
- url: "/git/v1/repo/{repo_id}/github-sync"
220
- });
221
- };
222
- const configureGithubSync = (options) => {
223
- return (options?.client ?? client).post({
224
- ...options,
225
- url: "/git/v1/repo/{repo_id}/github-sync"
226
- });
227
- };
228
- const removeGithubSync = (options) => {
229
- return (options?.client ?? client).delete({
230
- ...options,
231
- url: "/git/v1/repo/{repo_id}/github-sync"
232
- });
233
- };
234
- const handleDeleteRepo = (options) => {
235
- return (options?.client ?? client).delete({
236
- ...options,
237
- url: "/git/v1/repo/{repo}"
238
- });
239
- };
240
- const handleGetContents = (options) => {
241
- return (options?.client ?? client).get({
242
- ...options,
243
- url: "/git/v1/repo/{repo}/contents/{path}"
244
- });
245
- };
246
- const handleListGitTriggers = (options) => {
247
- return (options?.client ?? client).get({
248
- ...options,
249
- url: "/git/v1/repo/{repo}/trigger"
250
- });
251
- };
252
- const handleCreateGitTrigger = (options) => {
253
- return (options?.client ?? client).post({
254
- ...options,
255
- url: "/git/v1/repo/{repo}/trigger"
256
- });
257
- };
258
- const handleDeleteGitTrigger = (options) => {
259
- return (options?.client ?? client).delete({
260
- ...options,
261
- url: "/git/v1/repo/{repo}/trigger/{trigger}"
262
- });
263
- };
264
- const handleGetLogs = (options) => {
265
- return (options?.client ?? client).get({
266
- ...options,
267
- url: "/observability/v1/logs"
268
- });
269
- };
270
- const handleDeployWebV2 = (options) => {
271
- return (options?.client ?? client).post({
272
- ...options,
273
- url: "/web/v1/deployment"
274
- });
275
- };
276
- const handleListWebDeploys = (options) => {
277
- return (options?.client ?? client).get({
278
- ...options,
279
- url: "/web/v1/deployments"
280
- });
281
- };
282
-
283
- class FreestyleSandboxes {
284
- client;
285
- options;
286
- constructor(options) {
287
- this.options = options ?? {};
288
- if (!options?.apiKey) {
289
- this.options.apiKey = process.env.FREESTYLE_API_KEY;
290
- }
291
- if (typeof Deno !== "undefined") {
292
- class FreestyleRequest extends Request {
293
- constructor(input, init) {
294
- if (init.client !== void 0) {
295
- console.warn("Unsupported client detected, using default client");
296
- delete init.client;
297
- }
298
- super(input, init);
299
- }
300
- }
301
- Request = FreestyleRequest;
302
- }
303
- this.client = clientFetch.createClient({
304
- baseUrl: this.options?.baseUrl ?? "https://api.freestyle.sh",
305
- headers: {
306
- Authorization: `Bearer ${this.options.apiKey}`,
307
- ...this.options?.headers
308
- }
309
- });
310
- }
311
- /**
312
- * Execute a script in a sandbox.
313
- */
314
- async executeScript(script, config) {
315
- const response = await handleExecuteScript({
316
- client: this.client,
317
- body: {
318
- script,
319
- config
320
- }
321
- });
322
- if (response.data) {
323
- return response.data;
324
- }
325
- throw {
326
- message: `Failed to execute script:
327
-
328
- ${script}
329
-
330
- Error:
331
-
332
- ${JSON.stringify(
333
- response
334
- )}`,
335
- error: response.error
336
- };
337
- }
338
- /**
339
- * Deploy a Web project to a sandbox.
340
- */
341
- async deployWeb(source, config) {
342
- const response = await handleDeployWebV2({
343
- client: this.client,
344
- body: {
345
- source,
346
- config
347
- }
348
- });
349
- if (response.data) {
350
- return response.data;
351
- }
352
- throw new Error(
353
- `Failed to deploy web project
354
-
355
- Status: ${response.response.status}
356
-
357
- Message: ${response.error}`
358
- );
359
- }
360
- /**
361
- * Deploy a Cloudstate project to a sandbox.
362
- */
363
- async deployCloudstate(body) {
364
- const response = await handleDeployCloudstate({
365
- client: this.client,
366
- body
367
- });
368
- if (response.data) {
369
- return response.data;
370
- }
371
- throw new Error("Failed to deploy Cloudstate project");
372
- }
373
- /**
374
- * Get a backup of a Cloudstate project in a sandbox.
375
- * @param id The ID of the Cloudstate project.
376
- * @returns The backup of the Cloudstate project.
377
- * @throws An error if the backup could not be retrieved.
378
- */
379
- async backupCloudstate(id) {
380
- const response = await handleBackupCloudstate({
381
- client: this.client,
382
- path: {
383
- id
384
- }
385
- });
386
- if (response.data) {
387
- return response.data;
388
- }
389
- throw new Error("Failed to get backup of Cloudstate project");
390
- }
391
- /**
392
- * Get logs for an execute run, or web deployment.
393
- * @param id The ID of the sandbox.
394
- * @returns The logs for the sandbox.
395
- * @throws An error if the logs could not be retrieved.
396
- */
397
- async getLogs(id) {
398
- const response = await handleGetLogs({
399
- client: this.client,
400
- query: {
401
- deploymentId: id
402
- }
403
- // path: {
404
- // id: id,
405
- // },
406
- });
407
- if (response.data) {
408
- return response.data;
409
- }
410
- throw new Error("Failed to get logs for sandbox");
411
- }
412
- /**
413
- * Create a a domain verification request.
414
- * @param domain The domain to verify.
415
- * @returns The domain verification token.
416
- */
417
- async createDomainVerificationRequest(domain) {
418
- const response = await handleCreateDomainVerification({
419
- client: this.client,
420
- body: {
421
- domain
422
- }
423
- });
424
- if (response.data) {
425
- return response.data;
426
- }
427
- throw new Error(response.error.message);
428
- }
429
- async verifyDomainVerificationRequest(id) {
430
- const response = await handleVerifyDomain({
431
- client: this.client,
432
- body: {
433
- id
434
- }
435
- });
436
- if (response.data) {
437
- return response.data;
438
- }
439
- throw new Error(
440
- `Failed to verify domain verification request with ID ${id}: ${response.error.message}`
441
- );
442
- }
443
- /**
444
- * Verify a domain. Note, this requires the domain verification token to be already set up.
445
- * @param domain The domain to verify.
446
- * @returns The domain verification request.
447
- */
448
- async verifyDomain(domain) {
449
- const response = await handleVerifyDomain({
450
- client: this.client,
451
- body: {
452
- domain
453
- }
454
- });
455
- if (response.data) {
456
- return response.data;
457
- }
458
- throw new Error(
459
- `Failed to verify domain ${domain}: ${response.error.message}`
460
- );
461
- }
462
- async listDomains() {
463
- const response = await handleListDomains({
464
- client: this.client
465
- });
466
- if (response.data) {
467
- return response.data;
468
- }
469
- throw new Error(`Failed to list domains
470
- ${response.error.message}`);
471
- }
472
- async listDomainVerificationRequests() {
473
- const response = await handleListDomainVerificationRequests(
474
- {
475
- client: this.client
476
- }
477
- );
478
- if (response.data) {
479
- return response.data;
480
- }
481
- throw new Error(
482
- `Failed to list domain verification requests
483
- ${response.error.message}`
484
- );
485
- }
486
- async deleteDomainVerificationRequest(domain, verificationCode) {
487
- const response = await handleDeleteDomainVerification({
488
- client: this.client,
489
- body: {
490
- domain,
491
- verificationCode
492
- }
493
- });
494
- if (response.data) {
495
- return response.data;
496
- }
497
- throw new Error(
498
- `Failed to delete domain verification request for domain ${domain}: ${response.error.message}`
499
- );
500
- }
501
- async listWebDeployments(limit, offset) {
502
- const response = await handleListWebDeploys({
503
- client: this.client,
504
- query: {
505
- limit: limit ?? 10,
506
- offset: offset ?? 0
507
- }
508
- });
509
- if (response.data) {
510
- return response.data;
511
- }
512
- throw new Error(
513
- `Failed to list web deployments
514
- ${response.error.message}`
515
- );
516
- }
517
- async listExecuteRuns(limit, offset) {
518
- const response = await handleListExecuteRuns({
519
- client: this.client,
520
- query: {
521
- limit: limit ?? 10,
522
- offset: offset ?? 0
523
- }
524
- });
525
- if (response.data) {
526
- return response.data;
527
- }
528
- throw new Error(`Failed to list execute runs
529
- ${response.error.message}`);
530
- }
531
- async getExecuteRun(id) {
532
- const response = await handleGetExecuteRun({
533
- client: this.client,
534
- path: {
535
- deployment: id
536
- }
537
- });
538
- if (response.data) {
539
- return response.data;
540
- }
541
- throw new Error(
542
- `Failed to get execute run with ID ${id}: ${response.error.message}`
543
- );
544
- }
545
- /** Provision a wildcard certificate for domain. */
546
- async provisionWildcard(domain) {
547
- const response = await handleVerifyWildcard({
548
- client: this.client,
549
- path: {
550
- domain
551
- }
552
- });
553
- if (response.data) {
554
- return response.data;
555
- }
556
- throw new Error(
557
- `Failed to provision wildcard for domain ${domain}: ${response.error.message}`
558
- );
559
- }
560
- /**
561
- * Insert a domain mapping for a deployment.
562
- */
563
- async insertDomainMapping({
564
- domain,
565
- deploymentId
566
- }) {
567
- const response = await handleInsertDomainMapping({
568
- client: this.client,
569
- path: {
570
- domain
571
- },
572
- body: {
573
- deploymentId
574
- }
575
- });
576
- if (response.data) {
577
- return response.data;
578
- }
579
- throw new Error(
580
- `Failed to insert domain mapping for domain ${domain} and deployment ${deploymentId}: ${response.error.message}`
581
- );
582
- }
583
- /**
584
- * Remove a domain mapping for a deployment.
585
- */
586
- async removeDomainMapping({
587
- domain
588
- }) {
589
- const response = await handleDeleteDomainMapping({
590
- client: this.client,
591
- path: {
592
- domain
593
- }
594
- });
595
- if (response.response.ok) {
596
- return;
597
- }
598
- throw new Error(
599
- `Failed to remove domain mapping for domain ${domain}: ${response.error}`
600
- );
601
- }
602
- async listDomainMappings({
603
- domain,
604
- domainOwnership,
605
- limit = 10,
606
- offset = 0
607
- }) {
608
- const response = await handleListDomainMappings({
609
- client: this.client,
610
- query: {
611
- limit,
612
- offset,
613
- domain,
614
- domainOwnership
615
- }
616
- });
617
- if (response.data) {
618
- return response.data;
619
- }
620
- throw new Error(
621
- `Failed to list domain mappings: ${JSON.stringify(response.error)}`
622
- );
623
- }
624
- /**
625
- * Create a new git repository.
626
- */
627
- async createGitRepository({
628
- name,
629
- public: pub = false,
630
- source,
631
- import: _import,
632
- defaultBranch,
633
- devServers
634
- }) {
635
- const response = await handleCreateRepo({
636
- client: this.client,
637
- body: {
638
- name,
639
- public: pub,
640
- source,
641
- import: _import,
642
- defaultBranch,
643
- devServers
644
- }
645
- });
646
- if (response.data) {
647
- return response.data;
648
- }
649
- throw new Error(
650
- `Failed to create git repository ${name}: ${response.error}`
651
- );
652
- }
653
- /**
654
- * List git repositories.
655
- */
656
- async listGitRepositories({
657
- limit = 10,
658
- offset = 0
659
- } = {}) {
660
- const response = await handleListRepositories({
661
- client: this.client,
662
- query: {
663
- limit,
664
- offset
665
- }
666
- });
667
- if (response.data) {
668
- return response.data;
669
- }
670
- throw new Error(`Failed to list git repositories: ${response.error}`);
671
- }
672
- /**
673
- * Delete a git repository.
674
- */
675
- async deleteGitRepository({
676
- repoId
677
- }) {
678
- const response = await handleDeleteRepo({
679
- client: this.client,
680
- path: {
681
- repo: repoId
682
- }
683
- });
684
- if (response.data) {
685
- return response.data;
686
- }
687
- throw new Error(
688
- `Failed to delete git repository ${repoId}: ${response.error}`
689
- );
690
- }
691
- /**
692
- * Create a new git identity.
693
- */
694
- async createGitIdentity() {
695
- const response = await handleCreateIdentity({
696
- client: this.client
697
- });
698
- if (response.data) {
699
- return response.data;
700
- }
701
- throw new Error(`Failed to create git identity: ${response.error}`);
702
- }
703
- /**
704
- * Delete a git identity.
705
- */
706
- async deleteGitIdentity({
707
- identityId
708
- }) {
709
- const response = await handleDeleteIdentity({
710
- client: this.client,
711
- path: {
712
- identity: identityId
713
- }
714
- });
715
- if (response.data) {
716
- return response.data;
717
- }
718
- throw new Error(`Failed to delete git identity: ${response.error}`);
719
- }
720
- /**
721
- * Grant a git identity access to a repository.
722
- */
723
- async grantGitPermission({
724
- repoId,
725
- identityId,
726
- permission
727
- }) {
728
- const response = await handleGrantPermission({
729
- client: this.client,
730
- path: {
731
- repo: repoId,
732
- identity: identityId
733
- },
734
- body: {
735
- permission
736
- }
737
- });
738
- if (response.data) {
739
- return response.data;
740
- }
741
- throw new Error(
742
- `Failed to grant access to git identity ${identityId} for repository ${repoId}: ${response.error}`
743
- );
744
- }
745
- /**
746
- * Update a git identity's permissions on a repository.
747
- */
748
- async updateGitPermission({
749
- repoId,
750
- identityId,
751
- permission
752
- }) {
753
- const response = await handleUpdatePermission({
754
- client: this.client,
755
- path: {
756
- repo: repoId,
757
- identity: identityId
758
- },
759
- body: {
760
- permission
761
- }
762
- });
763
- if (response.data) {
764
- return;
765
- }
766
- throw new Error(
767
- `Failed to update permission for git identity ${identityId} for repository ${repoId}: ${response.error}`
768
- );
769
- }
770
- /**
771
- * Revoke a git identity's access to a repository.
772
- */
773
- async revokeGitPermission({
774
- repoId,
775
- identityId
776
- }) {
777
- const response = await handleRevokePermission({
778
- client: this.client,
779
- path: {
780
- repo: repoId,
781
- identity: identityId
782
- }
783
- });
784
- if (response.data) {
785
- return;
786
- }
787
- throw new Error(
788
- `Failed to revoke access to git identity ${identityId} for repository ${repoId}: ${response.error}`
789
- );
790
- }
791
- /**
792
- * List access permissions for a git identity.
793
- */
794
- async listGitPermissions({
795
- identityId
796
- }) {
797
- const response = await handleListPermissions({
798
- client: this.client,
799
- path: {
800
- identity: identityId
801
- }
802
- });
803
- if (response.data) {
804
- return response.data;
805
- }
806
- throw new Error(
807
- `Failed to list permissions for git identity ${identityId}: ${response.error}`
808
- );
809
- }
810
- /**
811
- * Get the permission of a git identity on a repository.
812
- */
813
- async getGitPermission({
814
- repoId,
815
- identityId
816
- }) {
817
- const response = await handleDescribePermission({
818
- client: this.client,
819
- path: {
820
- repo: repoId,
821
- identity: identityId
822
- }
823
- });
824
- if (response.data) {
825
- return response.data;
826
- }
827
- throw new Error(
828
- `Failed to get permission for git identity ${identityId} on repository ${repoId}: ${response.error}`
829
- );
830
- }
831
- /**
832
- * Create a new git access token for an identity.
833
- */
834
- async createGitAccessToken({
835
- identityId
836
- }) {
837
- const response = await handleCreateGitToken({
838
- client: this.client,
839
- path: {
840
- identity: identityId
841
- }
842
- });
843
- if (response.data) {
844
- return response.data;
845
- }
846
- throw new Error(
847
- `Failed to create git access token: ${response.error.message}`
848
- );
849
- }
850
- /**
851
- * Revoke a git access token.
852
- */
853
- async revokeGitAccessToken({
854
- identityId,
855
- tokenId
856
- }) {
857
- const response = await handleRevokeGitToken({
858
- client: this.client,
859
- body: {
860
- tokenId
861
- },
862
- path: {
863
- identity: identityId
864
- }
865
- });
866
- if (response.data) {
867
- return;
868
- }
869
- throw new Error(
870
- `Failed to revoke git access token ${tokenId}: ${response.error.message}`
871
- );
872
- }
873
- /**
874
- * List git access tokens for an identity.
875
- */
876
- async listGitAccessTokens({
877
- identityId
878
- }) {
879
- const response = await handleListGitTokens({
880
- client: this.client,
881
- path: {
882
- identity: identityId
883
- }
884
- });
885
- if (response.data) {
886
- return response.data;
887
- }
888
- throw new Error(
889
- `Failed to list git access tokens: ${response.error.message}`
890
- );
891
- }
892
- /**
893
- * List git triggers for a repository.
894
- */
895
- async listGitTriggers({
896
- repoId
897
- }) {
898
- const response = await handleListGitTriggers({
899
- client: this.client,
900
- path: {
901
- repo: repoId
902
- }
903
- });
904
- if (response.data) {
905
- return response.data;
906
- }
907
- throw new Error(
908
- `Failed to list git triggers for repository ${repoId}: ${response.error.message}`
909
- );
910
- }
911
- /**
912
- * Create a git trigger for a repository.
913
- */
914
- async createGitTrigger({
915
- repoId,
916
- trigger,
917
- action
918
- }) {
919
- const response = await handleCreateGitTrigger({
920
- client: this.client,
921
- path: {
922
- repo: repoId
923
- },
924
- body: {
925
- trigger,
926
- action
927
- }
928
- });
929
- if (response.data) {
930
- return response.data;
931
- }
932
- throw new Error(
933
- `Failed to create git trigger for repository ${repoId}: ${response.error.message}`
934
- );
935
- }
936
- /**
937
- * Delete a git trigger.
938
- */
939
- async deleteGitTrigger({
940
- triggerId,
941
- repo
942
- }) {
943
- const response = await handleDeleteGitTrigger({
944
- client: this.client,
945
- path: {
946
- trigger: triggerId,
947
- repo
948
- }
949
- });
950
- if (response.data) {
951
- return;
952
- }
953
- throw new Error(
954
- `Failed to delete git trigger ${triggerId}: ${response.error.message}`
955
- );
956
- }
957
- /**
958
- * Set the default branch for a git repository.
959
- */
960
- async setGitRepoDefaultBranch({
961
- repoId,
962
- defaultBranch
963
- }) {
964
- const response = await handleSetDefaultBranch({
965
- client: this.client,
966
- path: {
967
- repo_id: repoId
968
- },
969
- body: {
970
- defaultBranch
971
- }
972
- });
973
- if (response.error) {
974
- throw new Error(`Failed to set default branch: ${response.error}`);
975
- }
976
- }
977
- /**
978
- * Get the default branch for a git repository.
979
- */
980
- async getGitRepoDefaultBranch({
981
- repoId
982
- }) {
983
- const response = await handleGetDefaultBranch({
984
- client: this.client,
985
- path: { repo_id: repoId }
986
- });
987
- if (response.data) {
988
- return response.data.defaultBranch;
989
- }
990
- throw new Error(
991
- `Failed to get default branch for repository ${repoId}: ${response.error}`
992
- );
993
- }
994
- /**
995
- * Get the contents of a git repository at the given path.
996
- */
997
- async getGitRepoContents({
998
- repoId,
999
- path,
1000
- ref
1001
- }) {
1002
- const response = await handleGetContents({
1003
- client: this.client,
1004
- path: {
1005
- repo: repoId,
1006
- path: path ?? "",
1007
- "*path": path ?? null
1008
- },
1009
- query: {
1010
- ref
1011
- }
1012
- });
1013
- if (response.data) {
1014
- return response.data;
1015
- }
1016
- throw new Error(
1017
- `Failed to get git repository contents: ${response.error.message}`
1018
- );
1019
- }
1020
- /**
1021
- * Configure a git repository to sync with GitHub.
1022
- */
1023
- async configureGitRepoGitHubSync({
1024
- repoId,
1025
- githubRepoName
1026
- }) {
1027
- const response = await configureGithubSync({
1028
- client: this.client,
1029
- path: {
1030
- repo_id: repoId
1031
- },
1032
- body: {
1033
- githubRepoName
1034
- }
1035
- });
1036
- if (response.error) {
1037
- throw new Error(`Failed to configure GitHub sync: ${response.error}`);
1038
- }
1039
- }
1040
- /**
1041
- * Remove the GitHub sync configuration for a git repository.
1042
- */
1043
- async removeGitRepoGitHubSync({ repoId }) {
1044
- const response = await removeGithubSync({
1045
- client: this.client,
1046
- path: {
1047
- repo_id: repoId
1048
- }
1049
- });
1050
- if (response.error) {
1051
- throw new Error(`Failed to remove GitHub sync: ${response.error}`);
1052
- }
1053
- }
1054
- /**
1055
- * Get the GitHub sync configuration for a git repository.
1056
- */
1057
- async getGitRepoGitHubSyncConfig({
1058
- repoId
1059
- }) {
1060
- const response = await getGithubSync({
1061
- client: this.client,
1062
- path: {
1063
- repo_id: repoId
1064
- }
1065
- });
1066
- if (response.response.status === 404) {
1067
- return null;
1068
- }
1069
- if (response.error) {
1070
- throw new Error(`Failed to get GitHub sync config: ${response.error}`);
1071
- }
1072
- return response.data ?? null;
1073
- }
1074
- /**
1075
- * Request a dev server for a repository. If a dev server is already running
1076
- * for that repository, it will return a url to that server. Dev servers are
1077
- * ephemeral so you should call this function every time you need a url. Do
1078
- * not store the url in your database!
1079
- */
1080
- async requestDevServer(options) {
1081
- function formatHook(serverUrl, repoUrl) {
1082
- const hook = serverUrl + "/__freestyle_dev_server/update/git?repo=" + encodeURIComponent(repoUrl);
1083
- return hook;
1084
- }
1085
- const response = await handleEphemeralDevServer({
1086
- client: this.client,
1087
- body: {
1088
- ...options,
1089
- // @ts-ignore
1090
- repo: options.repoUrl
1091
- }
1092
- });
1093
- if (response.error) {
1094
- throw new Error(
1095
- // @ts-ignore
1096
- `Failed to request dev server: ${response.error.message}`
1097
- );
1098
- }
1099
- if (response.data.isNew) {
1100
- const rId = options.repoId || options.repoUrl?.split("/").at(-1);
1101
- await this.createGitTrigger({
1102
- repoId: rId,
1103
- action: {
1104
- endpoint: formatHook(
1105
- response.data?.url,
1106
- options.repoUrl || `https://git.freestyle.sh/${rId}`
1107
- ),
1108
- action: "webhook"
1109
- },
1110
- trigger: {
1111
- event: "push"
1112
- }
1113
- });
1114
- }
1115
- if (!response.data) {
1116
- throw new Error(`Failed to request dev server: ${response.error}`);
1117
- }
1118
- const data = response.data;
1119
- const devServerInstance = {
1120
- repoId: options.repoId || options.repo || "",
1121
- kind: "repo",
1122
- gitRef: options.gitRef
1123
- };
1124
- const client = this.client;
1125
- const that = this;
1126
- return {
1127
- ...response.data,
1128
- isNew: data.isNew,
1129
- ephemeralUrl: data.ephemeralUrl ?? data.url,
1130
- mcpEphemeralUrl: data.mcpEphemeralUrl ?? data.url + "/mcp",
1131
- codeServerUrl: data.codeServerUrl ?? (data.ephemeralUrl ?? data.url) + "/__freestyle_code_server/?folder=/template",
1132
- async status() {
1133
- const response2 = await handleDevServerStatus({
1134
- client,
1135
- body: {
1136
- devServer: devServerInstance
1137
- }
1138
- });
1139
- if (response2.error) {
1140
- throw new Error(`Failed to get status: ${response2.error}`);
1141
- }
1142
- return {
1143
- installing: response2.data.installing,
1144
- devRunning: response2.data.devRunning
1145
- };
1146
- },
1147
- async commitAndPush(message) {
1148
- const response2 = await handleGitCommitPush({
1149
- client,
1150
- body: {
1151
- devServer: devServerInstance,
1152
- message
1153
- }
1154
- });
1155
- if (response2.error) {
1156
- throw new Error(`Failed to commit and push: ${response2.error}`);
1157
- }
1158
- },
1159
- async shutdown() {
1160
- const response2 = await handleShutdownDevServer({
1161
- client,
1162
- body: {
1163
- devServer: devServerInstance
1164
- }
1165
- });
1166
- if (response2.error) {
1167
- throw new Error(`Failed to shutdown dev server: ${response2.error}`);
1168
- }
1169
- return {
1170
- success: response2.data.success,
1171
- message: response2.data.message
1172
- };
1173
- },
1174
- fs: {
1175
- async ls(path = "") {
1176
- const response2 = await handleReadFileFromEphemeralDevServer({
1177
- client,
1178
- path: {
1179
- filepath: path,
1180
- "*filepath": path
1181
- },
1182
- body: {
1183
- devServer: devServerInstance,
1184
- encoding: "utf-8"
1185
- }
1186
- });
1187
- if (response2.error) {
1188
- throw new Error(`Failed to list directory: ${response2.error}`);
1189
- }
1190
- if (!response2.data?.content) {
1191
- return [];
1192
- }
1193
- if (response2.data.content.kind === "directory") {
1194
- return response2.data.content.files;
1195
- }
1196
- return [];
1197
- },
1198
- async *watch() {
1199
- const response2 = await that.fetch(
1200
- "/ephemeral/v1/dev-servers/watch-files",
1201
- {
1202
- method: "POST",
1203
- body: JSON.stringify({
1204
- devServer: {
1205
- repoId: devServerInstance.repoId,
1206
- kind: devServerInstance.kind
1207
- }
1208
- })
1209
- }
1210
- );
1211
- if (!response2.ok) {
1212
- throw new Error(
1213
- `Failed to fetch stream: ${response2.status} ${response2.statusText}`
1214
- );
1215
- }
1216
- if (!response2.body) {
1217
- throw new Error("Failed to fetch stream: No response body");
1218
- }
1219
- const reader = response2.body.getReader();
1220
- const decoder = new TextDecoder("utf-8");
1221
- let buffer = "";
1222
- while (true) {
1223
- const { done, value } = await reader.read();
1224
- if (done) break;
1225
- buffer += decoder.decode(value, { stream: true });
1226
- let newlineIndex;
1227
- while ((newlineIndex = buffer.indexOf("\n")) >= 0) {
1228
- const line = buffer.slice(0, newlineIndex).trim();
1229
- buffer = buffer.slice(newlineIndex + 1);
1230
- if (line) {
1231
- yield JSON.parse(line);
1232
- }
1233
- }
1234
- }
1235
- if (buffer.trim()) {
1236
- yield JSON.parse(buffer.trim());
1237
- }
1238
- },
1239
- async readFile(path, encoding = "utf-8") {
1240
- const response2 = await handleReadFileFromEphemeralDevServer({
1241
- client,
1242
- path: {
1243
- filepath: path,
1244
- "*filepath": path
1245
- },
1246
- body: {
1247
- devServer: devServerInstance,
1248
- encoding
1249
- }
1250
- });
1251
- if (response2.error) {
1252
- throw new Error(`Failed to read file: ${response2.error}`);
1253
- }
1254
- if (!response2.data?.content || response2.data.content.kind !== "file") {
1255
- throw new Error(`Not a file or file not found: ${path}`);
1256
- }
1257
- return response2.data.content.content;
1258
- },
1259
- async writeFile(path, content, encoding = "utf-8") {
1260
- const contentStr = typeof content === "string" ? content : Buffer.from(content).toString(encoding);
1261
- const response2 = await handleWriteFileFromEphemeralDevServer({
1262
- client,
1263
- path: {
1264
- filepath: path,
1265
- "*filepath": path
1266
- },
1267
- body: {
1268
- devServer: devServerInstance,
1269
- content: contentStr,
1270
- encoding
1271
- }
1272
- });
1273
- if (response2.error) {
1274
- throw new Error(
1275
- `Failed to write file: ${JSON.stringify(response2.error)}`
1276
- );
1277
- }
1278
- }
1279
- },
1280
- process: {
1281
- async exec(cmd, background = false) {
1282
- const response2 = await handleExecOnEphemeralDevServer(
1283
- {
1284
- client,
1285
- body: {
1286
- devServer: devServerInstance,
1287
- command: cmd,
1288
- background
1289
- }
1290
- }
1291
- );
1292
- if (response2.error) {
1293
- throw new Error(`Failed to execute command: ${response2.error}`);
1294
- }
1295
- return {
1296
- id: response2.data.id,
1297
- isNew: response2.data.isNew,
1298
- stdout: response2.data.stdout,
1299
- stderr: response2.data.stderr
1300
- };
1301
- }
1302
- }
1303
- };
1304
- }
1305
- fetch(path, init) {
1306
- const headers = new Headers(init?.headers);
1307
- for (const [key, value] of Object.entries(this.options.headers ?? {})) {
1308
- if (!headers.has(key)) {
1309
- headers.append(key, value);
1310
- }
1311
- }
1312
- if (!headers.has("Authorization")) {
1313
- headers.append("Authorization", `Bearer ${this.options.apiKey}`);
1314
- }
1315
- if (!headers.has("Content-Type")) {
1316
- headers.append("Content-Type", "application/json");
1317
- }
1318
- const url = new URL(
1319
- path,
1320
- this.options.baseUrl ?? "https://api.freestyle.sh"
1321
- );
1322
- return fetch(url, {
1323
- ...init ?? {},
1324
- headers
1325
- });
1326
- }
1327
- }
1328
-
1329
- exports.FreestyleSandboxes = FreestyleSandboxes;