freestyle-sandboxes 0.0.21 → 0.0.24
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/ai/index.cjs +0 -2
- package/dist/ai/index.mjs +0 -2
- package/dist/index.cjs +1 -3
- package/dist/index.mjs +1 -3
- package/openapi.json +1 -1
- package/package.json +2 -1
- package/src/ai/index.ts +0 -2
- package/src/index.ts +26 -29
- package/src/utils/index.ts +85 -0
package/dist/ai/index.cjs
CHANGED
package/dist/ai/index.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -237,9 +237,7 @@ Message: ${response.error?.message}`
|
|
|
237
237
|
if (response.data) {
|
|
238
238
|
return response.data;
|
|
239
239
|
} else {
|
|
240
|
-
throw new Error(
|
|
241
|
-
`Failed to create domain verification request for domain ${domain}: ${response.error.message}`
|
|
242
|
-
);
|
|
240
|
+
throw new Error(response.error.message);
|
|
243
241
|
}
|
|
244
242
|
}
|
|
245
243
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -235,9 +235,7 @@ Message: ${response.error?.message}`
|
|
|
235
235
|
if (response.data) {
|
|
236
236
|
return response.data;
|
|
237
237
|
} else {
|
|
238
|
-
throw new Error(
|
|
239
|
-
`Failed to create domain verification request for domain ${domain}: ${response.error.message}`
|
|
240
|
-
);
|
|
238
|
+
throw new Error(response.error.message);
|
|
241
239
|
}
|
|
242
240
|
}
|
|
243
241
|
/**
|
package/openapi.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"openapi":"3.1.0","info":{"title":"Freestyle Sandboxes","description":"\nFreestyle Sandboxes lets you deploy your users or AIs code. **Get your API Key at [admin.freestyle.sh](https://admin.freestyle.sh)**\n\nThey are broken up into 4 categories: [Web](#tag/web), [Execute](#tag/execute), [Cloudstate](#tag/cloudstate), and [Domains](#tag/domains).\n\n[Web](#tag/web): Send us the code for the website, we'll provision the certificates and get it hosted\n\n[Execute](#tag/execute): Send us a function, we'll run it and send you the output\n\n[Cloudstate](#tag/cloudstate): Our Opensource JavaScript Runtime used for cloud functions with persistent state\n\n[Domains](#tag/domains): Manage your domains, including verification and listing\n","contact":{"name":"Ben","email":"ben@freestyle.sh"},"license":{"name":""},"version":"0.1.0"},"servers":[{"url":"https://api.freestyle.sh","description":"Production"}],"paths":{"/cloudstate/v1/deploy":{"post":{"tags":["Cloudstate"],"summary":"Deploy Cloudstate Project","description":"Deploy a cloudstate project","operationId":"handle_deploy_cloudstate","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeployRequest"}}},"required":true},"responses":{"200":{"description":"successfully deployed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeploySuccessResponse"}}}},"500":{"description":"failed to deploy","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeployErrorResponse"}}}}}}},"/cloudstate/v1/projects/{id}/backup":{"get":{"tags":["Cloudstate"],"summary":"Get Backup of Cloudstate Project","description":"Get a backup of a cloudstate project","operationId":"handle_backup_cloudstate","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"successfully backed up","content":{"application/octet-stream":{"schema":{"type":"array","items":{"type":"integer","format":"int32","minimum":0}}}}},"500":{"description":"failed to backup"}}}},"/domains/v1/certs/{domain}/wildcard":{"post":{"tags":["Certs","Domains"],"summary":"Provision a wildcard certificate","description":"Provisions a wildcard certificate for a verified domain\n\n\nThis speeds up deploys on all subdomains of the domain. In order to use it, you must add the following record to your DNS config:\n\n`_acme-challenge.yourdomain.com` NS `dns.freestyle.sh`","operationId":"handle_verify_wildcard","responses":{"200":{"description":"Domain verified","content":{"application/json":{"schema":{"type":"object","required":["domain"],"properties":{"domain":{"type":"string","example":"example.com"}}}}}},"400":{"description":"Failed to preverify domain","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.provisionWildcard('example.com').then((cert) => {\n console.log(cert);\n});"}]}},"/domains/v1/domains":{"get":{"tags":["Domains"],"summary":"List domains for an account","description":"This lists the domains that an account has verified ownership of. This includes the *.style.dev domains the account has claimed.","operationId":"handle_list_domains","responses":{"200":{"description":"List of domains","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","required":["domain","createdAt"],"properties":{"domain":{"type":"string","example":"example.yourdomain.com"},"createdAt":{"type":"integer","format":"int64"}}}}}}},"400":{"description":"Failed to get domains","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.listDomains().then((response) => {\n console.log(response);\n});"}]}},"/domains/v1/verifications":{"get":{"tags":["Domains"],"summary":"List domain verification requests for an account","description":"Lists domain verification requests for the current account.","operationId":"handle_list_domain_verification_requests","responses":{"200":{"description":"List of verification codes","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","required":["verificationCode","domain","createdAt"],"properties":{"verificationCode":{"type":"string"},"domain":{"type":"string"},"createdAt":{"type":"integer","format":"int64"}}}}}}},"400":{"description":"Failed to get verification codes","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.listDomainVerificationRequests().then((response) => {\n console.log(response);\n});"}]},"put":{"tags":["Domains"],"summary":"Verify a domain","description":"This checks a pre-existing verification request for a domain. To create a verification request, call the [create domain verification](/#tag/domains/POST/domains/v1/verifications) endpoint. This endpoint will check if the domain has a TXT record with the verification code. If it does, the domain will be verified.","operationId":"handle_verify_domain","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleVerifyDomainRequest"}}},"required":true},"responses":{"200":{"description":"Domain verified","content":{"application/json":{"schema":{"type":"object","required":["domain"],"properties":{"domain":{"type":"string","example":"example.com"}}}}}},"400":{"description":"Failed to verify domain","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst api = new FreestyleSandboxes({\n apiKey: process.env.FREESTYLE_API_KEY!,\n});\n\napi\n .verifyDomain('example.com')\n .then((result) => {\n console.log('Successfully Verified Domain!');\n })\n .catch((error) => {\n console.error('Failed to verify domain: ', error);\n });"}]},"post":{"tags":["Domains"],"summary":"Create a domain verification request","description":"This creates a Freestyle Domain Verification Request. It returns a `verificationCode` for your domain. You need to place this code in a TXT record at `_freestyle_custom_hostname.thedomain.com`, then call the [verify domain](/#tag/domains/PUT/domains/v1/verifications) endpoint with the domain to verify it.","operationId":"handle_create_domain_verification","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDomainVerificationRequest"}}},"required":true},"responses":{"200":{"description":"Verification code created","content":{"application/json":{"schema":{"type":"object","required":["verificationCode","domain"],"properties":{"verificationCode":{"type":"string"},"domain":{"type":"string","example":"example.com"}}}}}},"400":{"description":"Failed to create verification code","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst api = new FreestyleSandboxes({\n apiKey: process.env.FREESTYLE_API_KEY!,\n});\n\napi.createDomainVerificationRequest('example.com').then((result) => {\n const verificationCode = result.verificationCode;\n // put this at a TXT record at _freestyle_custom_hostname.example.com\n});"}]},"delete":{"tags":["Domains"],"summary":"Delete a domain verification request","description":"This deletes a Freestyle Domain Verification Request. This does not remove the domain from the account if it has already been verified, however the verification code will no longer be valid.","operationId":"handle_delete_domain_verification","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeleteDomainVerificationRequest"}}},"required":true},"responses":{"200":{"description":"Verification code created","content":{"application/json":{"schema":{"type":"object","required":["verificationCode","domain"],"properties":{"verificationCode":{"type":"string"},"domain":{"type":"string","example":"example.com"}}}}}},"400":{"description":"Failed to create verification code","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}}}},"/execute/v1/deployments":{"get":{"tags":["Execute"],"summary":"List execute runs","description":"List execute runs.","operationId":"handle_list_execute_runs","parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":["integer","null"],"minimum":0}},{"name":"offset","in":"query","required":false,"schema":{"type":["integer","null"],"minimum":0}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["entries","total","offset"],"properties":{"entries":{"type":"array","items":{"$ref":"#/components/schemas/ExecuteLogEntry"}},"total":{"type":"integer","format":"int64","minimum":0},"offset":{"type":"integer","format":"int64","minimum":0}}}}}},"500":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.listExecuteRuns().then((runs) => {\n console.log(runs);\n});"}]}},"/execute/v1/deployments/{deployment}":{"get":{"tags":["Execute"],"summary":"Get information on execute run","description":"Get information on execute run","operationId":"handle_get_execute_run","parameters":[{"name":"deployment","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","required":["metadata","code"],"properties":{"metadata":{"$ref":"#/components/schemas/ExecuteLogEntry"},"code":{"$ref":"#/components/schemas/ExecuteRunInfo"}}}}}},"401":{"description":"Unauthorized access","content":{"application/json":{"schema":{"type":"object","description":"Unauthorized access","required":["message"],"properties":{"message":{"type":"string"}}}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"type":"object","description":"Not found","required":["message"],"properties":{"message":{"type":"string"}}}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"type":"object","description":"Internal server error","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.getExecuteRun('123e4567-e89b-12d3-a456-426614174000').then((runs) => {\n console.log(runs);\n});"}]}},"/execute/v1/script":{"post":{"tags":["Execute"],"summary":"Execute Code","description":"Send a TypeScript or JavaScript module, get the result","operationId":"handle_execute_script","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleExecuteScriptParams"}}},"required":true},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","required":["result","logs"],"properties":{"result":{},"logs":{"type":"array","items":{"$ref":"#/components/schemas/FreestyleJavaScriptLog"}}}}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.executeScript(\n `export default () => {\n let set1 = [1, 2, 3, 4, 5];\n let set2 = [4, 5, 6, 7, 8];\n\n // find the sum of every value of each set multiplied by every value of the other set\n\n let sum = 0;\n for (let i = 0; i < set1.length; i++) {\n for (let j = 0; j < set2.length; j++) {\n sum += set1[i] * set2[j];\n }\n }\n\n return sum;\n};`\n);"},{"label":"Vercel AI SDK","lang":"JavaScript","source":"import { executeTool } from 'freestyle-sandboxes/ai';\nimport { generateText } from 'ai';\n\nconst codeExecutor = executeTool({\n apiKey: 'your-api-key',\n});\n\nconst { text, steps } = await generateText({\n model: yourModel,\n tools: {\n codeExecutor,\n },\n maxSteps: 2,\n prompt:\n 'What is the sum of every number between 1 and 12 multiplied by itself?',\n});"},{"label":"Mastra AI SDK","lang":"JavaScript","source":"import { executeTool } from 'freestyle-sandboxes/mastra';\n\nconst mastra = new Mastra();\n\nconst modelConfig: ModelConfig = {\n provider: 'OPEN_AI',\n name: 'gpt-4',\n};\n\nconst llm = mastra.LLM(modelConfig);\n\nconst response = await llm.generate(\n 'Calculate the sum of every number between 13 and 19 divided by the sum of every number between 8 and 13',\n {\n tools: {\n executor: executeTool({\n apiKey: process.env.FREESTYLE_API_KEY!,\n }),\n },\n }\n);\n\nconsole.log('Response Steps:', response.steps);\nconsole.log('Response:', response.text);"},{"label":"LangGraph AI SDK","lang":"JavaScript","source":"import { createReactAgent } from '@langchain/langgraph/prebuilt';\nimport { ChatOpenAI } from '@langchain/openai';\nimport { executeTool } from 'freestyle-sandboxes/langgraph';\n\nconst model = new ChatOpenAI({ model: 'gpt-4o' });\n\nconst agent = createReactAgent({\n llm: model,\n tools: [\n executeTool({\n apiKey: process.env.FREESTYLE_API_KEY,\n nodeModules: {\n resend: '4.0.1',\n },\n envVars: {\n RESEND_API_KEY: process.env.RESEND_API_KEY,\n },\n }),\n ],\n});\n\nconst result = await agent.invoke(\n {\n messages: [\n { role: 'user', content: 'What is the factorial of 13 divided by 55^2' },\n ],\n },\n { configurable: { thread_id: 42 } }\n);\nconsole.log(result.messages.at(-1)?.content);"}]}},"/git/v1/repo":{"get":{"tags":["Git"],"summary":"List repositories","description":"List repositories.","operationId":"list_repositories_handler","parameters":[{"name":"limit","in":"query","description":"Maximum number of repositories to return","required":true,"schema":{"type":"integer","format":"int64","minimum":0}},{"name":"offset","in":"query","description":"Offset for the list of repositories","required":true,"schema":{"type":"integer","format":"int64","minimum":0}}],"responses":{"200":{"description":"List of repositories","content":{"application/json":{"schema":{"type":"object","required":["repositories","offset"],"properties":{"repositories":{"type":"array","items":{"$ref":"#/components/schemas/RepositoryInfo"}},"offset":{"type":"integer","format":"int64","minimum":0}}}}}},"400":{"description":"Invalid request","content":{"text/plain":{"schema":{"type":"string"}}}},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}}},"post":{"tags":["Git"],"summary":"Create a repository","description":"Create a repository. Once the repository is created, it will also be created on the Git server.\nThe repository name must be unique within your account.\n\nOnce created, you can then push your code to this repository.\n\nThe repo will be available at `git.freestyle.sh/{repo-id}`\n","operationId":"create_repo_handler","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateRepositoryRequest"}}},"required":true},"responses":{"200":{"description":"Repository created successfully","content":{"application/json":{"schema":{"type":"object","required":["repo_id"],"properties":{"repo_id":{"type":"string"}}}}}},"400":{"description":"Invalid request","content":{"text/plain":{"schema":{"type":"string"}}}},"409":{"description":"Repository already exists"},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/git/v1/repo/{repo}":{"delete":{"tags":["Git"],"summary":"Delete a repository","description":"Delete a repository. This is irreversible, and will also delete the repository on the Git server.","operationId":"delete_repo_handler","parameters":[{"name":"repo","in":"path","description":"The repository id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Repository deleted successfully"},"400":{"description":"Invalid request","content":{"text/plain":{"schema":{"type":"string"}}}},"403":{"description":"User does not have permission to delete this repository","content":{"text/plain":{"schema":{"type":"string"}}}},"404":{"description":"Repository does not exist"},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/observability/v1/logs":{"get":{"tags":["Observability"],"summary":"Deployment Logs","description":"Get the logs for a deployment","operationId":"handle_get_logs","parameters":[{"name":"deploymentId","in":"query","required":false,"schema":{"type":["string","null"]}},{"name":"domain","in":"query","required":false,"schema":{"type":["string","null"]}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleGetLogsResponse"}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.getLogs({\n deploymentId: 'deployment-id',\n}).then((response) => {\n console.log(response);\n});"}]}},"/web/v1/deploy":{"post":{"tags":["Web"],"summary":"Deploy a Website","description":"Deploy a website. Files is a map of file paths to file contents. Configuration is optional and contains additional information about the deployment.","operationId":"handle_deploy_web","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebPayload"}}},"required":true},"responses":{"200":{"description":"successfully deployed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebSuccessResponse"}}}},"400":{"description":"failed to deploy","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebErrorResponse"}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\nimport 'dotenv/config';\n\nconst api = new FreestyleSandboxes({\n apiKey: process.env.FREESTYLE_API_KEY!,\n});\n\napi\n .deployWeb({\n 'index.js': {\n content:`\n import http from 'node:http';\n console.log('starting server');\n\n const server = http.createServer(async(req, res) => {\n // wait 5 seconds before responding\n // await new Promise((resolve) => setTimeout(resolve, 5000));\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end('Welcome to New York its been waiting for you');\n });\n\n server.listen(3000, () => {\n console.log('Server is running at http://localhost:3000');\n });`,\n }})\n .then((result) => {\n console.log('Deployed website @ ', result.deploymentId);\n });\n"},{"label":"Vercel AI SDK","lang":"JavaScript","source":"import { deployWebTool } from 'freestyle-sandboxes/ai';\nimport { generateText } from 'ai';\n\nconst deployer = deployWebTool({\n apiKey: 'your-api-key',\n});\n\nconst { text, steps } = await generateText({\n model: yourModel,\n tools: {\n deployer,\n },\n maxSteps: 2,\n prompt:\n 'Deploy a website to subdomain.yourdomain.com that has all the lyrics to Sandstorm by Darude on the homepage',\n});"}]}},"/web/v1/deployments":{"get":{"tags":["Web"],"summary":"List web deploys","description":"List web deploys.","operationId":"handle_list_web_deploys","parameters":[{"name":"limit","in":"query","description":"Maximum number of repositories to return","required":true,"schema":{"type":"integer","format":"int64","minimum":0}},{"name":"offset","in":"query","description":"Offset for the list of repositories","required":true,"schema":{"type":"integer","format":"int64","minimum":0}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["entries","total","offset"],"properties":{"entries":{"type":"array","items":{"$ref":"#/components/schemas/DeploymentLogEntry"}},"total":{"type":"integer","format":"int64","minimum":0},"offset":{"type":"integer","format":"int64","minimum":0}}}}}},"500":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.listWebDeploys().then((response) => {\n console.log(response);\n});"}]}},"/web/v1/deployments/deployment/{deployment_id}":{"get":{"tags":["Web"],"summary":"Get information on web deploy","description":"Get information about a web deploy by its ID.","operationId":"handle_get_web_deploy_details","parameters":[{"name":"deployment_id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{}}}},"components":{"schemas":{"Behavior":{"type":"string","default":"exact","enum":["regex","exact"]},"CreateRepositoryRequest":{"type":"object","required":["name"],"properties":{"name":{"type":"string"}}},"DeploymentLogEntry":{"type":"object","required":["deploymentId","accountId","provisionedAt","timeout","state","domains","envVars"],"properties":{"deploymentId":{"type":"string","format":"uuid"},"accountId":{"type":"string"},"provisionedAt":{"type":"string","format":"date-time"},"timeout":{"type":"string"},"state":{"$ref":"#/components/schemas/DeploymentState"},"deployedAt":{"type":["string","null"],"format":"date-time"},"domains":{"type":"array","items":{"type":"string"}},"envVars":{"type":"object","additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}}}},"DeploymentState":{"type":"string","enum":["provisioning","deployed","failed"]},"ExecuteLogEntry":{"type":"object","required":["deployment","accountId","provisionedAt","state","envVars"],"properties":{"deployment":{"type":"string","format":"uuid"},"accountId":{"type":"string"},"provisionedAt":{"type":"string","format":"date-time"},"startedAt":{"type":["string","null"],"format":"date-time"},"duration":{"type":["string","null"]},"state":{"$ref":"#/components/schemas/ExecuteRunState"},"envVars":{"type":"object","additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}}}},"ExecuteRunInfo":{"type":"object","required":["code","nodeModules"],"properties":{"code":{"type":"string"},"nodeModules":{"type":"object","additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}}}},"ExecuteRunState":{"type":"string","enum":["starting","running","complete"]},"FreestyleCloudstateDeployConfiguration":{"type":"object","properties":{"domains":{"type":["array","null"],"items":{"type":"string"},"description":"ID of the project to deploy, if not provided will create a new project","default":null},"envVars":{"type":"object","description":"The environment variables that the cloudstate deploy can access","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}},"cloudstateDatabaseId":{"type":["string","null"],"default":null}}},"FreestyleCloudstateDeployErrorResponse":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}},"FreestyleCloudstateDeployRequest":{"type":"object","required":["classes"],"properties":{"classes":{"type":"string"},"config":{"$ref":"#/components/schemas/FreestyleCloudstateDeployConfiguration"}}},"FreestyleCloudstateDeploySuccessResponse":{"type":"object","required":["deploymentId","cloudstateDatabaseId"],"properties":{"deploymentId":{"type":"string"},"cloudstateDatabaseId":{"type":"string"}}},"FreestyleDeleteDomainVerificationRequest":{"type":"object","required":["domain","verificationCode"],"properties":{"domain":{"type":"string","description":"The domain to create a verification code for","example":"example.com"},"verificationCode":{"type":"string","description":"The verification code"}}},"FreestyleDeployWebConfiguration":{"type":"object","properties":{"entrypoint":{"type":["string","null"],"description":"The entrypoint file for the website","default":"index.js"},"domains":{"type":["array","null"],"items":{"type":"string"},"description":"The custom domains for the website, eg. [\\\"subdomain.yourwebsite.com\\\"]. You may include a single *.style.dev domain here.","example":["subdomain.yourdomain.com"],"default":null},"projectId":{"type":["string","null"],"description":"Project ID was our original way of tracking deployments together, it is now deprecated and will be removed in the future. Please use the domains field to specify the domains for your project.","default":null,"deprecated":true},"nodeModules":{"type":["object","null"],"description":"Node Modules to install for the website, a map of package names to versions, e.g. { \\\"express\\\": \\\"4.17.1\\\" }. If this and a package-lock.json are provided, the package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock is also provided, the versions here will override the versions in those lock files.","default":null,"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"resend":"4.0.1"}},"envVars":{"type":["object","null"],"description":"The environment variables that the website can access\ne.g. { \\\"RESEND_API_KEY\\\": \\\"re_123456789\\\" }","default":null,"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"RESEND_API_KEY":"re_123456789"}},"serverStartCheck":{"type":"boolean","default":false},"networkPermissions":{"type":["array","null"],"items":{"$ref":"#/components/schemas/FreestyleNetworkPermission"},"default":null}}},"FreestyleDeployWebErrorResponse":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}},"FreestyleDeployWebPayload":{"type":"object","required":["files"],"properties":{"files":{"type":"object","description":"The files to deploy, a map of file paths to file contents, e.g. { \\\"index.js\\\": {\\\"content\\\": \\\"your main\\\", \\\"encoding\\\": \\\"utf-8\\\"}, \\\"file2.js\\\": {\\\"content\\\": \\\"your helper\\\" } }\n\n**Do not include node modules in this bundle, they will not work**. Instead, includes a package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock, the node modules for the project will be installed from that lock file, or use the node_modules field in the configuration to specify the node modules to install.","additionalProperties":{"$ref":"#/components/schemas/FreestyleFile"},"propertyNames":{"type":"string"},"example":{"index.js":{"content":"import http from 'node:http';\\n// import { resolver } from './file2.js';\\n\\nconsole.log('starting server');\\n\\nconst server = http.createServer(async(req, res) => {\\n // wait 5 seconds before responding\\n // await new Promise((resolve) => setTimeout(resolve, 5000));\\n res.writeHead(200, { 'Content-Type': 'text/plain' });\\n res.end('Welcome to New York its been waiting for you');\\n});\\n\\nserver.listen(3000, () => {\\n console.log('Server is running at http://localhost:3000');\\n});"}}},"config":{"$ref":"#/components/schemas/FreestyleDeployWebConfiguration"}}},"FreestyleDeployWebSuccessResponse":{"type":"object","required":["deploymentId"],"properties":{"deploymentId":{"type":"string"},"domains":{"type":["array","null"],"items":{"type":"string"}},"projectId":{"type":["string","null"],"deprecated":true}}},"FreestyleDomainVerificationRequest":{"type":"object","required":["domain"],"properties":{"domain":{"type":"string","description":"The domain to create a verification code for","example":"example.com"}}},"FreestyleExecuteScriptParams":{"type":"object","required":["script"],"properties":{"script":{"type":"string","description":"The JavaScript or TypeScript script to execute","example":"export default () => {\n // get the value of the factorials of the numbers from 1 to 10 combined\n const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n function factorial(n) {\n if (n === 0) {\n return 1;\n }\n return n * factorial(n - 1);\n }\n\n const b = a.map(factorial);\n\n return b.reduce((a, b) => a + b);\n};\n"},"config":{"$ref":"#/components/schemas/FreestyleExecuteScriptParamsConfiguration"}}},"FreestyleExecuteScriptParamsConfiguration":{"type":"object","properties":{"envVars":{"type":"object","description":"The environment variables to set for the script","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"RESEND_API_KEY":"re_123456789"}},"nodeModules":{"type":"object","description":"The node modules to install for the script","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"resend":"4.0.1"}},"tags":{"type":"array","items":{"type":"string"},"description":"Tags for you to organize your scripts, useful for tracking what you're running","example":["email"],"default":[]},"timeout":{"type":["string","null"],"description":"The script timeout","default":null},"peerDependencyResolution":{"type":"boolean","description":"If false, we'll not resolve peer dependencies for the packages given, this can speed up execute performance, but will break packages with peers unless the peers are manually specified.","default":true},"networkPermissions":{"type":["array","null"],"items":{"$ref":"#/components/schemas/FreestyleNetworkPermission"},"default":null}}},"FreestyleExecuteScriptResultSuccess":{"type":"object","required":["result","logs"],"properties":{"result":{},"logs":{"type":"array","items":{"$ref":"#/components/schemas/FreestyleJavaScriptLog"}}}},"FreestyleFile":{"type":"object","required":["content"],"properties":{"content":{"type":"string","description":"The content of the file"},"encoding":{"type":"string","description":"The encoding of the file. Either **utf-8** or **base64**"}}},"FreestyleGetLogsResponse":{"type":"object","required":["logs"],"properties":{"logs":{"type":"array","items":{"$ref":"#/components/schemas/FreestyleLogResponseObject"}}}},"FreestyleJavaScriptLog":{"type":"object","required":["message","type"],"properties":{"message":{"type":"string","description":"The log message"},"type":{"type":"string","description":"The log level"}}},"FreestyleLogResponseObject":{"type":"object","required":["message","timestamp"],"properties":{"message":{"type":"string"},"timestamp":{"type":"string"}}},"FreestyleNetworkPermission":{"oneOf":[{"allOf":[{"$ref":"#/components/schemas/NetworkPermissionData"},{"type":"object","required":["action"],"properties":{"action":{"type":"string","enum":["allow"]}}}]},{"allOf":[{"$ref":"#/components/schemas/NetworkPermissionData"},{"type":"object","required":["action"],"properties":{"action":{"type":"string","enum":["deny"]}}}]}]},"FreestyleVerifyDomainRequest":{"type":"object","required":["domain"],"properties":{"domain":{"type":"string","example":"example.com"}}},"NetworkPermissionData":{"type":"object","required":["query"],"properties":{"query":{"type":"string"},"behavior":{"$ref":"#/components/schemas/Behavior"}}},"RepositoryInfo":{"type":"object","required":["id","name","ownerId"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"ownerId":{"type":"string"}}}},"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"tags":[{"name":"Web","description":"APIs for deploying websites. We handle node modules caching, scaling, certificates and the whole end to end process. Send the code using the [deploy](#tag/web/POST/web/v1/deploy) endpoint, and you'll get a full hosted website back. Works with any TypeScript or JavaScript codebase."},{"name":"Execute","description":"APIs for running code. Send the code using the [execute](#tag/execute/POST/execute/v1/execute) endpoint, and you'll get the output back. Works with any TypeScript or JavaScript code + handles any node modules and environment variables you want."},{"name":"Cloudstate","description":"APIs for running cloud functions with persistent state. [Cloudstate](https://github.com/freestyle-sh/cloudstate/) is an opensource, durable JavaScript runtime maintained by the Freestyle Team."},{"name":"Domains","description":"APIs for managing domains. This is only relevant when you want to start to deploy to custom domains. \nPlease read [this guide](https://github.com/freestyle-sh/sandbox_sdks/blob/main/docs/custom_domains.md) to understand how deployments work with custom domains."},{"name":"Git","description":"APIs for managing git repositories."}]}
|
|
1
|
+
{"openapi":"3.1.0","info":{"title":"Freestyle Sandboxes","description":"\nFreestyle Sandboxes lets you deploy your users or AIs code. **Get your API Key at [admin.freestyle.sh](https://admin.freestyle.sh)**\n\nThey are broken up into 5 categories: [Web](#tag/web), [Execute](#tag/execute), [Cloudstate](#tag/cloudstate), and [Domains](#tag/domains).\n\n[Web](#tag/web): Send us the code for the website, we'll provision the certificates and get it hosted\n\n[Execute](#tag/execute): Send us a function, we'll run it and send you the output\n\n[Cloudstate](#tag/cloudstate): Our Opensource JavaScript Runtime used for cloud functions with persistent state\n\n[Domains](#tag/domains): Manage your domains, including verification and listing\n\n[Git](#tag/git): Manage your git repositories\n","contact":{"name":"Ben","email":"ben@freestyle.sh"},"license":{"name":""},"version":"0.1.0"},"servers":[{"url":"https://api.freestyle.sh","description":"Production"}],"paths":{"/cloudstate/v1/deploy":{"post":{"tags":["Cloudstate"],"summary":"Deploy Cloudstate Project","description":"Deploy a cloudstate project","operationId":"handle_deploy_cloudstate","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeployRequest"}}},"required":true},"responses":{"200":{"description":"successfully deployed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeploySuccessResponse"}}}},"500":{"description":"failed to deploy","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleCloudstateDeployErrorResponse"}}}}}}},"/cloudstate/v1/projects/{id}/backup":{"get":{"tags":["Cloudstate"],"summary":"Get Backup of Cloudstate Project","description":"Get a backup of a cloudstate project","operationId":"handle_backup_cloudstate","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"successfully backed up","content":{"application/octet-stream":{"schema":{"type":"array","items":{"type":"integer","format":"int32","minimum":0}}}}},"500":{"description":"failed to backup"}}}},"/domains/v1/certs/{domain}/wildcard":{"post":{"tags":["Certs","Domains"],"summary":"Provision a wildcard certificate","description":"Provisions a wildcard certificate for a verified domain\n\n\nThis speeds up deploys on all subdomains of the domain. In order to use it, you must add the following record to your DNS config:\n\n`_acme-challenge.yourdomain.com` NS `dns.freestyle.sh`","operationId":"handle_verify_wildcard","responses":{"200":{"description":"Domain verified","content":{"application/json":{"schema":{"type":"object","required":["domain"],"properties":{"domain":{"type":"string","example":"example.com"}}}}}},"400":{"description":"Failed to preverify domain","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.provisionWildcard('example.com').then((cert) => {\n console.log(cert);\n});"}]}},"/domains/v1/domains":{"get":{"tags":["Domains"],"summary":"List domains for an account","description":"This lists the domains that an account has verified ownership of. This includes the *.style.dev domains the account has claimed.","operationId":"handle_list_domains","responses":{"200":{"description":"List of domains","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","required":["domain","createdAt"],"properties":{"domain":{"type":"string","example":"example.yourdomain.com"},"createdAt":{"type":"integer","format":"int64"}}}}}}},"400":{"description":"Failed to get domains","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.listDomains().then((response) => {\n console.log(response);\n});"}]}},"/domains/v1/verifications":{"get":{"tags":["Domains"],"summary":"List domain verification requests for an account","description":"Lists domain verification requests for the current account.","operationId":"handle_list_domain_verification_requests","responses":{"200":{"description":"List of verification codes","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","required":["verificationCode","domain","createdAt"],"properties":{"verificationCode":{"type":"string"},"domain":{"type":"string"},"createdAt":{"type":"integer","format":"int64"}}}}}}},"400":{"description":"Failed to get verification codes","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.listDomainVerificationRequests().then((response) => {\n console.log(response);\n});"}]},"put":{"tags":["Domains"],"summary":"Verify a domain","description":"This checks a pre-existing verification request for a domain. To create a verification request, call the [create domain verification](/#tag/domains/POST/domains/v1/verifications) endpoint. This endpoint will check if the domain has a TXT record with the verification code. If it does, the domain will be verified.","operationId":"handle_verify_domain","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleVerifyDomainRequest"}}},"required":true},"responses":{"200":{"description":"Domain verified","content":{"application/json":{"schema":{"type":"object","required":["domain"],"properties":{"domain":{"type":"string","example":"example.com"}}}}}},"400":{"description":"Failed to verify domain","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst api = new FreestyleSandboxes({\n apiKey: process.env.FREESTYLE_API_KEY!,\n});\n\napi\n .verifyDomain('example.com')\n .then((result) => {\n console.log('Successfully Verified Domain!');\n })\n .catch((error) => {\n console.error('Failed to verify domain: ', error);\n });"}]},"post":{"tags":["Domains"],"summary":"Create a domain verification request","description":"This creates a Freestyle Domain Verification Request. It returns a `verificationCode` for your domain. You need to place this code in a TXT record at `_freestyle_custom_hostname.thedomain.com`, then call the [verify domain](/#tag/domains/PUT/domains/v1/verifications) endpoint with the domain to verify it.","operationId":"handle_create_domain_verification","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDomainVerificationRequest"}}},"required":true},"responses":{"200":{"description":"Verification code created","content":{"application/json":{"schema":{"type":"object","required":["verificationCode","domain"],"properties":{"verificationCode":{"type":"string"},"domain":{"type":"string","example":"example.com"}}}}}},"400":{"description":"Failed to create verification code","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst api = new FreestyleSandboxes({\n apiKey: process.env.FREESTYLE_API_KEY!,\n});\n\napi.createDomainVerificationRequest('example.com').then((result) => {\n const verificationCode = result.verificationCode;\n // put this at a TXT record at _freestyle_custom_hostname.example.com\n});"}]},"delete":{"tags":["Domains"],"summary":"Delete a domain verification request","description":"This deletes a Freestyle Domain Verification Request. This does not remove the domain from the account if it has already been verified, however the verification code will no longer be valid.","operationId":"handle_delete_domain_verification","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeleteDomainVerificationRequest"}}},"required":true},"responses":{"200":{"description":"Verification code created","content":{"application/json":{"schema":{"type":"object","required":["verificationCode","domain"],"properties":{"verificationCode":{"type":"string"},"domain":{"type":"string","example":"example.com"}}}}}},"400":{"description":"Failed to create verification code","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}}}},"/execute/v1/deployments":{"get":{"tags":["Execute"],"summary":"List execute runs","description":"List execute runs.","operationId":"handle_list_execute_runs","parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":["integer","null"],"minimum":0}},{"name":"offset","in":"query","required":false,"schema":{"type":["integer","null"],"minimum":0}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["entries","total","offset"],"properties":{"entries":{"type":"array","items":{"$ref":"#/components/schemas/ExecuteLogEntry"}},"total":{"type":"integer","format":"int64","minimum":0},"offset":{"type":"integer","format":"int64","minimum":0}}}}}},"500":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.listExecuteRuns().then((runs) => {\n console.log(runs);\n});"}]}},"/execute/v1/deployments/{deployment}":{"get":{"tags":["Execute"],"summary":"Get information on execute run","description":"Get information on execute run","operationId":"handle_get_execute_run","parameters":[{"name":"deployment","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","required":["metadata","code"],"properties":{"metadata":{"$ref":"#/components/schemas/ExecuteLogEntry"},"code":{"$ref":"#/components/schemas/ExecuteRunInfo"}}}}}},"401":{"description":"Unauthorized access","content":{"application/json":{"schema":{"type":"object","description":"Unauthorized access","required":["message"],"properties":{"message":{"type":"string"}}}}}},"404":{"description":"Not found","content":{"application/json":{"schema":{"type":"object","description":"Not found","required":["message"],"properties":{"message":{"type":"string"}}}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"type":"object","description":"Internal server error","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.getExecuteRun('123e4567-e89b-12d3-a456-426614174000').then((runs) => {\n console.log(runs);\n});"}]}},"/execute/v1/script":{"post":{"tags":["Execute"],"summary":"Execute Code","description":"Send a TypeScript or JavaScript module, get the result","operationId":"handle_execute_script","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleExecuteScriptParams"}}},"required":true},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"type":"object","required":["result","logs"],"properties":{"result":{},"logs":{"type":"array","items":{"$ref":"#/components/schemas/FreestyleJavaScriptLog"}}}}}}},"400":{"description":"Error","content":{"application/json":{"schema":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.executeScript(\n `export default () => {\n let set1 = [1, 2, 3, 4, 5];\n let set2 = [4, 5, 6, 7, 8];\n\n // find the sum of every value of each set multiplied by every value of the other set\n\n let sum = 0;\n for (let i = 0; i < set1.length; i++) {\n for (let j = 0; j < set2.length; j++) {\n sum += set1[i] * set2[j];\n }\n }\n\n return sum;\n};`\n);"},{"label":"Vercel AI SDK","lang":"JavaScript","source":"import { executeTool } from 'freestyle-sandboxes/ai';\nimport { generateText } from 'ai';\n\nconst codeExecutor = executeTool({\n apiKey: 'your-api-key',\n});\n\nconst { text, steps } = await generateText({\n model: yourModel,\n tools: {\n codeExecutor,\n },\n maxSteps: 2,\n prompt:\n 'What is the sum of every number between 1 and 12 multiplied by itself?',\n});"},{"label":"Mastra AI SDK","lang":"JavaScript","source":"import { executeTool } from 'freestyle-sandboxes/mastra';\n\nconst mastra = new Mastra();\n\nconst modelConfig: ModelConfig = {\n provider: 'OPEN_AI',\n name: 'gpt-4',\n};\n\nconst llm = mastra.LLM(modelConfig);\n\nconst response = await llm.generate(\n 'Calculate the sum of every number between 13 and 19 divided by the sum of every number between 8 and 13',\n {\n tools: {\n executor: executeTool({\n apiKey: process.env.FREESTYLE_API_KEY!,\n }),\n },\n }\n);\n\nconsole.log('Response Steps:', response.steps);\nconsole.log('Response:', response.text);"},{"label":"LangGraph AI SDK","lang":"JavaScript","source":"import { createReactAgent } from '@langchain/langgraph/prebuilt';\nimport { ChatOpenAI } from '@langchain/openai';\nimport { executeTool } from 'freestyle-sandboxes/langgraph';\n\nconst model = new ChatOpenAI({ model: 'gpt-4o' });\n\nconst agent = createReactAgent({\n llm: model,\n tools: [\n executeTool({\n apiKey: process.env.FREESTYLE_API_KEY,\n nodeModules: {\n resend: '4.0.1',\n },\n envVars: {\n RESEND_API_KEY: process.env.RESEND_API_KEY,\n },\n }),\n ],\n});\n\nconst result = await agent.invoke(\n {\n messages: [\n { role: 'user', content: 'What is the factorial of 13 divided by 55^2' },\n ],\n },\n { configurable: { thread_id: 42 } }\n);\nconsole.log(result.messages.at(-1)?.content);"}]}},"/git/v1/repo":{"get":{"tags":["Git"],"summary":"List repositories","description":"List repositories.","operationId":"list_repositories_handler","parameters":[{"name":"limit","in":"query","description":"Maximum number of repositories to return","required":true,"schema":{"type":"integer","format":"int64","minimum":0}},{"name":"offset","in":"query","description":"Offset for the list of repositories","required":true,"schema":{"type":"integer","format":"int64","minimum":0}}],"responses":{"200":{"description":"List of repositories","content":{"application/json":{"schema":{"type":"object","required":["repositories","offset"],"properties":{"repositories":{"type":"array","items":{"$ref":"#/components/schemas/RepositoryInfo"}},"offset":{"type":"integer","format":"int64","minimum":0}}}}}},"400":{"description":"Invalid request","content":{"text/plain":{"schema":{"type":"string"}}}},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}}},"post":{"tags":["Git"],"summary":"Create a repository","description":"Create a repository. Once the repository is created, it will also be created on the Git server.\nThe repository name must be unique within your account.\n\nOnce created, you can then push your code to this repository.\n\nThe repo will be available at `git.freestyle.sh/{repo-id}`\n","operationId":"create_repo_handler","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateRepositoryRequest"}}},"required":true},"responses":{"200":{"description":"Repository created successfully","content":{"application/json":{"schema":{"type":"object","required":["repo_id"],"properties":{"repo_id":{"type":"string"}}}}}},"400":{"description":"Invalid request","content":{"text/plain":{"schema":{"type":"string"}}}},"409":{"description":"Repository already exists"},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/git/v1/repo/{repo}":{"delete":{"tags":["Git"],"summary":"Delete a repository","description":"Delete a repository. This is irreversible, and will also delete the repository on the Git server.","operationId":"delete_repo_handler","parameters":[{"name":"repo","in":"path","description":"The repository id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Repository deleted successfully"},"400":{"description":"Invalid request","content":{"text/plain":{"schema":{"type":"string"}}}},"403":{"description":"User does not have permission to delete this repository","content":{"text/plain":{"schema":{"type":"string"}}}},"404":{"description":"Repository does not exist"},"500":{"description":"Internal server error","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/observability/v1/logs":{"get":{"tags":["Observability"],"summary":"Deployment Logs","description":"Get the logs for a deployment","operationId":"handle_get_logs","parameters":[{"name":"deploymentId","in":"query","required":false,"schema":{"type":["string","null"]}},{"name":"domain","in":"query","required":false,"schema":{"type":["string","null"]}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleGetLogsResponse"}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.getLogs({\n deploymentId: 'deployment-id',\n}).then((response) => {\n console.log(response);\n});"}]}},"/web/v1/deploy":{"post":{"tags":["Web"],"summary":"Deploy a Website","description":"Deploy a website. Files is a map of file paths to file contents. Configuration is optional and contains additional information about the deployment.","operationId":"handle_deploy_web","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebPayload"}}},"required":true},"responses":{"200":{"description":"successfully deployed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebSuccessResponse"}}}},"400":{"description":"failed to deploy","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FreestyleDeployWebErrorResponse"}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\nimport 'dotenv/config';\n\nconst api = new FreestyleSandboxes({\n apiKey: process.env.FREESTYLE_API_KEY!,\n});\n\napi\n .deployWeb({\n 'index.js': {\n content:`\n import http from 'node:http';\n console.log('starting server');\n\n const server = http.createServer(async(req, res) => {\n // wait 5 seconds before responding\n // await new Promise((resolve) => setTimeout(resolve, 5000));\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end('Welcome to New York its been waiting for you');\n });\n\n server.listen(3000, () => {\n console.log('Server is running at http://localhost:3000');\n });`,\n }})\n .then((result) => {\n console.log('Deployed website @ ', result.deploymentId);\n });\n"},{"label":"Vercel AI SDK","lang":"JavaScript","source":"import { deployWebTool } from 'freestyle-sandboxes/ai';\nimport { generateText } from 'ai';\n\nconst deployer = deployWebTool({\n apiKey: 'your-api-key',\n});\n\nconst { text, steps } = await generateText({\n model: yourModel,\n tools: {\n deployer,\n },\n maxSteps: 2,\n prompt:\n 'Deploy a website to subdomain.yourdomain.com that has all the lyrics to Sandstorm by Darude on the homepage',\n});"}]}},"/web/v1/deployments":{"get":{"tags":["Web"],"summary":"List web deploys","description":"List web deploys.","operationId":"handle_list_web_deploys","parameters":[{"name":"limit","in":"query","description":"Maximum number of repositories to return","required":true,"schema":{"type":"integer","format":"int64","minimum":0}},{"name":"offset","in":"query","description":"Offset for the list of repositories","required":true,"schema":{"type":"integer","format":"int64","minimum":0}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["entries","total","offset"],"properties":{"entries":{"type":"array","items":{"$ref":"#/components/schemas/DeploymentLogEntry"}},"total":{"type":"integer","format":"int64","minimum":0},"offset":{"type":"integer","format":"int64","minimum":0}}}}}},"500":{"description":"","content":{"application/json":{"schema":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}},"x-codeSamples":[{"label":"Human SDK","lang":"JavaScript","source":"import { FreestyleSandboxes } from 'freestyle-sandboxes';\n\nconst sandboxes = new FreestyleSandboxes({\n apiKey: 'your-api-key',\n});\n\nsandboxes.listWebDeploys().then((response) => {\n console.log(response);\n});"}]}},"/web/v1/deployments/deployment/{deployment_id}":{"get":{"tags":["Web"],"summary":"Get information on web deploy","description":"Get information about a web deploy by its ID.","operationId":"handle_get_web_deploy_details","parameters":[{"name":"deployment_id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{}}}},"components":{"schemas":{"Behavior":{"type":"string","default":"exact","enum":["regex","exact"]},"CreateRepositoryRequest":{"type":"object","required":["name"],"properties":{"name":{"type":"string"}}},"DeploymentLogEntry":{"type":"object","required":["deploymentId","accountId","provisionedAt","timeout","state","domains","envVars"],"properties":{"deploymentId":{"type":"string","format":"uuid"},"accountId":{"type":"string"},"provisionedAt":{"type":"string","format":"date-time"},"timeout":{"type":"string"},"state":{"$ref":"#/components/schemas/DeploymentState"},"deployedAt":{"type":["string","null"],"format":"date-time"},"domains":{"type":"array","items":{"type":"string"}},"envVars":{"type":"object","additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}}}},"DeploymentState":{"type":"string","enum":["provisioning","deployed","failed"]},"ExecuteLogEntry":{"type":"object","required":["deployment","accountId","provisionedAt","state","envVars"],"properties":{"deployment":{"type":"string","format":"uuid"},"accountId":{"type":"string"},"provisionedAt":{"type":"string","format":"date-time"},"startedAt":{"type":["string","null"],"format":"date-time"},"duration":{"type":["string","null"]},"state":{"$ref":"#/components/schemas/ExecuteRunState"},"envVars":{"type":"object","additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}}}},"ExecuteRunInfo":{"type":"object","required":["code","nodeModules"],"properties":{"code":{"type":"string"},"nodeModules":{"type":"object","additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}}}},"ExecuteRunState":{"type":"string","enum":["starting","running","complete"]},"FreestyleCloudstateDeployConfiguration":{"type":"object","properties":{"domains":{"type":["array","null"],"items":{"type":"string"},"description":"ID of the project to deploy, if not provided will create a new project","default":null},"envVars":{"type":"object","description":"The environment variables that the cloudstate deploy can access","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"}},"cloudstateDatabaseId":{"type":["string","null"],"default":null}}},"FreestyleCloudstateDeployErrorResponse":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}},"FreestyleCloudstateDeployRequest":{"type":"object","required":["classes"],"properties":{"classes":{"type":"string"},"config":{"$ref":"#/components/schemas/FreestyleCloudstateDeployConfiguration"}}},"FreestyleCloudstateDeploySuccessResponse":{"type":"object","required":["deploymentId","cloudstateDatabaseId"],"properties":{"deploymentId":{"type":"string"},"cloudstateDatabaseId":{"type":"string"}}},"FreestyleDeleteDomainVerificationRequest":{"type":"object","required":["domain","verificationCode"],"properties":{"domain":{"type":"string","description":"The domain to create a verification code for","example":"example.com"},"verificationCode":{"type":"string","description":"The verification code"}}},"FreestyleDeployWebConfiguration":{"type":"object","properties":{"entrypoint":{"type":["string","null"],"description":"The entrypoint file for the website","default":"index.js"},"domains":{"type":["array","null"],"items":{"type":"string"},"description":"The custom domains for the website, eg. [\\\"subdomain.yourwebsite.com\\\"]. You may include a single *.style.dev domain here.","example":["subdomain.yourdomain.com"],"default":null},"projectId":{"type":["string","null"],"description":"Project ID was our original way of tracking deployments together, it is now deprecated and will be removed in the future. Please use the domains field to specify the domains for your project.","default":null,"deprecated":true},"nodeModules":{"type":["object","null"],"description":"Node Modules to install for the website, a map of package names to versions, e.g. { \\\"express\\\": \\\"4.17.1\\\" }. If this and a package-lock.json are provided, the package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock is also provided, the versions here will override the versions in those lock files.","default":null,"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"resend":"4.0.1"}},"envVars":{"type":["object","null"],"description":"The environment variables that the website can access\ne.g. { \\\"RESEND_API_KEY\\\": \\\"re_123456789\\\" }","default":null,"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"RESEND_API_KEY":"re_123456789"}},"serverStartCheck":{"type":"boolean","default":false},"networkPermissions":{"type":["array","null"],"items":{"$ref":"#/components/schemas/FreestyleNetworkPermission"},"default":null}}},"FreestyleDeployWebErrorResponse":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}},"FreestyleDeployWebPayload":{"type":"object","required":["files"],"properties":{"files":{"type":"object","description":"The files to deploy, a map of file paths to file contents, e.g. { \\\"index.js\\\": {\\\"content\\\": \\\"your main\\\", \\\"encoding\\\": \\\"utf-8\\\"}, \\\"file2.js\\\": {\\\"content\\\": \\\"your helper\\\" } }\n\n**Do not include node modules in this bundle, they will not work**. Instead, includes a package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock, the node modules for the project will be installed from that lock file, or use the node_modules field in the configuration to specify the node modules to install.","additionalProperties":{"$ref":"#/components/schemas/FreestyleFile"},"propertyNames":{"type":"string"},"example":{"index.js":{"content":"import http from 'node:http';\\n// import { resolver } from './file2.js';\\n\\nconsole.log('starting server');\\n\\nconst server = http.createServer(async(req, res) => {\\n // wait 5 seconds before responding\\n // await new Promise((resolve) => setTimeout(resolve, 5000));\\n res.writeHead(200, { 'Content-Type': 'text/plain' });\\n res.end('Welcome to New York its been waiting for you');\\n});\\n\\nserver.listen(3000, () => {\\n console.log('Server is running at http://localhost:3000');\\n});"}}},"config":{"$ref":"#/components/schemas/FreestyleDeployWebConfiguration"}}},"FreestyleDeployWebSuccessResponse":{"type":"object","required":["deploymentId"],"properties":{"deploymentId":{"type":"string"},"domains":{"type":["array","null"],"items":{"type":"string"}},"projectId":{"type":["string","null"],"deprecated":true}}},"FreestyleDomainVerificationRequest":{"type":"object","required":["domain"],"properties":{"domain":{"type":"string","description":"The domain to create a verification code for","example":"example.com"}}},"FreestyleExecuteScriptParams":{"type":"object","required":["script"],"properties":{"script":{"type":"string","description":"The JavaScript or TypeScript script to execute","example":"export default () => {\n // get the value of the factorials of the numbers from 1 to 10 combined\n const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n function factorial(n) {\n if (n === 0) {\n return 1;\n }\n return n * factorial(n - 1);\n }\n\n const b = a.map(factorial);\n\n return b.reduce((a, b) => a + b);\n};\n"},"config":{"$ref":"#/components/schemas/FreestyleExecuteScriptParamsConfiguration"}}},"FreestyleExecuteScriptParamsConfiguration":{"type":"object","properties":{"envVars":{"type":"object","description":"The environment variables to set for the script","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"RESEND_API_KEY":"re_123456789"}},"nodeModules":{"type":"object","description":"The node modules to install for the script","default":{},"additionalProperties":{"type":"string"},"propertyNames":{"type":"string"},"example":{"resend":"4.0.1"}},"tags":{"type":"array","items":{"type":"string"},"description":"Tags for you to organize your scripts, useful for tracking what you're running","example":["email"],"default":[]},"timeout":{"type":["string","null"],"description":"The script timeout","default":null},"peerDependencyResolution":{"type":"boolean","description":"If false, we'll not resolve peer dependencies for the packages given, this can speed up execute performance, but will break packages with peers unless the peers are manually specified.","default":true},"networkPermissions":{"type":["array","null"],"items":{"$ref":"#/components/schemas/FreestyleNetworkPermission"},"default":null}}},"FreestyleExecuteScriptResultSuccess":{"type":"object","required":["result","logs"],"properties":{"result":{},"logs":{"type":"array","items":{"$ref":"#/components/schemas/FreestyleJavaScriptLog"}}}},"FreestyleFile":{"type":"object","required":["content"],"properties":{"content":{"type":"string","description":"The content of the file"},"encoding":{"type":"string","description":"The encoding of the file. Either **utf-8** or **base64**"}}},"FreestyleGetLogsResponse":{"type":"object","required":["logs"],"properties":{"logs":{"type":"array","items":{"$ref":"#/components/schemas/FreestyleLogResponseObject"}}}},"FreestyleJavaScriptLog":{"type":"object","required":["message","type"],"properties":{"message":{"type":"string","description":"The log message"},"type":{"type":"string","description":"The log level"}}},"FreestyleLogResponseObject":{"type":"object","required":["message","timestamp"],"properties":{"message":{"type":"string"},"timestamp":{"type":"string"}}},"FreestyleNetworkPermission":{"oneOf":[{"allOf":[{"$ref":"#/components/schemas/NetworkPermissionData"},{"type":"object","required":["action"],"properties":{"action":{"type":"string","enum":["allow"]}}}]},{"allOf":[{"$ref":"#/components/schemas/NetworkPermissionData"},{"type":"object","required":["action"],"properties":{"action":{"type":"string","enum":["deny"]}}}]}]},"FreestyleVerifyDomainRequest":{"type":"object","required":["domain"],"properties":{"domain":{"type":"string","example":"example.com"}}},"NetworkPermissionData":{"type":"object","required":["query"],"properties":{"query":{"type":"string"},"behavior":{"$ref":"#/components/schemas/Behavior"}}},"RepositoryInfo":{"type":"object","required":["id","name","ownerId"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"ownerId":{"type":"string"}}}},"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}}},"tags":[{"name":"Web","description":"APIs for deploying websites. We handle node modules caching, scaling, certificates and the whole end to end process. Send the code using the [deploy](#tag/web/POST/web/v1/deploy) endpoint, and you'll get a full hosted website back. Works with any TypeScript or JavaScript codebase."},{"name":"Execute","description":"APIs for running code. Send the code using the [execute](#tag/execute/POST/execute/v1/execute) endpoint, and you'll get the output back. Works with any TypeScript or JavaScript code + handles any node modules and environment variables you want."},{"name":"Cloudstate","description":"APIs for running cloud functions with persistent state. [Cloudstate](https://github.com/freestyle-sh/cloudstate/) is an opensource, durable JavaScript runtime maintained by the Freestyle Team."},{"name":"Domains","description":"APIs for managing domains. This is only relevant when you want to start to deploy to custom domains. \nPlease read [this guide](https://github.com/freestyle-sh/sandbox_sdks/blob/main/docs/custom_domains.md) to understand how deployments work with custom domains."},{"name":"Git","description":"APIs for managing git repositories."}]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "freestyle-sandboxes",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"@langchain/langgraph": "^0.2.44",
|
|
66
66
|
"@mastra/core": "^0.1.27-alpha.66",
|
|
67
67
|
"ai": "^4.0.25",
|
|
68
|
+
"glob": "^11.0.1",
|
|
68
69
|
"humanlayer": "^0.7.0",
|
|
69
70
|
"openai": "^4.77.3",
|
|
70
71
|
"openapi": "^1.0.1",
|
package/src/ai/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -31,7 +31,7 @@ export class FreestyleSandboxes {
|
|
|
31
31
|
*/
|
|
32
32
|
async executeScript(
|
|
33
33
|
script: string,
|
|
34
|
-
config?: sandbox_openapi.FreestyleExecuteScriptParamsConfiguration
|
|
34
|
+
config?: sandbox_openapi.FreestyleExecuteScriptParamsConfiguration
|
|
35
35
|
): Promise<sandbox_openapi.FreestyleExecuteScriptResultSuccess> {
|
|
36
36
|
const response = await sandbox_openapi.handleExecuteScript({
|
|
37
37
|
client: this.client,
|
|
@@ -46,8 +46,8 @@ export class FreestyleSandboxes {
|
|
|
46
46
|
} else {
|
|
47
47
|
throw new Error(
|
|
48
48
|
`Failed to execute script: \n\n${script}\n\nError:\n\n${JSON.stringify(
|
|
49
|
-
response
|
|
50
|
-
)}
|
|
49
|
+
response
|
|
50
|
+
)}`
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -63,7 +63,7 @@ export class FreestyleSandboxes {
|
|
|
63
63
|
encoding?: string;
|
|
64
64
|
}
|
|
65
65
|
>,
|
|
66
|
-
config?: sandbox_openapi.FreestyleDeployWebConfiguration
|
|
66
|
+
config?: sandbox_openapi.FreestyleDeployWebConfiguration
|
|
67
67
|
): Promise<sandbox_openapi.FreestyleDeployWebSuccessResponse> {
|
|
68
68
|
const response = await sandbox_openapi.handleDeployWeb({
|
|
69
69
|
client: this.client,
|
|
@@ -76,7 +76,7 @@ export class FreestyleSandboxes {
|
|
|
76
76
|
return response.data;
|
|
77
77
|
} else {
|
|
78
78
|
throw new Error(
|
|
79
|
-
`Failed to deploy web project\n\nStatus: ${response.response.status}\n\nMessage: ${response.error?.message}
|
|
79
|
+
`Failed to deploy web project\n\nStatus: ${response.response.status}\n\nMessage: ${response.error?.message}`
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -85,7 +85,7 @@ export class FreestyleSandboxes {
|
|
|
85
85
|
* Deploy a Cloudstate project to a sandbox.
|
|
86
86
|
*/
|
|
87
87
|
async deployCloudstate(
|
|
88
|
-
body: sandbox_openapi.FreestyleCloudstateDeployRequest
|
|
88
|
+
body: sandbox_openapi.FreestyleCloudstateDeployRequest
|
|
89
89
|
): Promise<sandbox_openapi.FreestyleCloudstateDeploySuccessResponse> {
|
|
90
90
|
const response = await sandbox_openapi.handleDeployCloudstate({
|
|
91
91
|
client: this.client,
|
|
@@ -105,7 +105,7 @@ export class FreestyleSandboxes {
|
|
|
105
105
|
* @throws An error if the backup could not be retrieved.
|
|
106
106
|
*/
|
|
107
107
|
async backupCloudstate(
|
|
108
|
-
id: string
|
|
108
|
+
id: string
|
|
109
109
|
): Promise<sandbox_openapi.HandleBackupCloudstateResponse> {
|
|
110
110
|
const response = await sandbox_openapi.handleBackupCloudstate({
|
|
111
111
|
client: this.client,
|
|
@@ -149,7 +149,7 @@ export class FreestyleSandboxes {
|
|
|
149
149
|
* @returns The domain verification token.
|
|
150
150
|
*/
|
|
151
151
|
async createDomainVerificationRequest(
|
|
152
|
-
domain: string
|
|
152
|
+
domain: string
|
|
153
153
|
): Promise<sandbox_openapi.HandleCreateDomainVerificationResponse> {
|
|
154
154
|
const response = await sandbox_openapi.handleCreateDomainVerification({
|
|
155
155
|
client: this.client,
|
|
@@ -160,9 +160,7 @@ export class FreestyleSandboxes {
|
|
|
160
160
|
if (response.data) {
|
|
161
161
|
return response.data;
|
|
162
162
|
} else {
|
|
163
|
-
throw new Error(
|
|
164
|
-
`Failed to create domain verification request for domain ${domain}: ${response.error.message}`,
|
|
165
|
-
);
|
|
163
|
+
throw new Error(response.error.message);
|
|
166
164
|
}
|
|
167
165
|
}
|
|
168
166
|
|
|
@@ -172,7 +170,7 @@ export class FreestyleSandboxes {
|
|
|
172
170
|
* @returns The domain verification request.
|
|
173
171
|
*/
|
|
174
172
|
async verifyDomain(
|
|
175
|
-
domain: string
|
|
173
|
+
domain: string
|
|
176
174
|
): Promise<
|
|
177
175
|
| sandbox_openapi.HandleVerifyDomainResponse
|
|
178
176
|
| sandbox_openapi.HandleVerifyDomainError
|
|
@@ -187,7 +185,7 @@ export class FreestyleSandboxes {
|
|
|
187
185
|
return response.data;
|
|
188
186
|
} else {
|
|
189
187
|
throw new Error(
|
|
190
|
-
`Failed to verify domain ${domain}: ${response.error.message}
|
|
188
|
+
`Failed to verify domain ${domain}: ${response.error.message}`
|
|
191
189
|
);
|
|
192
190
|
}
|
|
193
191
|
}
|
|
@@ -207,21 +205,20 @@ export class FreestyleSandboxes {
|
|
|
207
205
|
const response = await sandbox_openapi.handleListDomainVerificationRequests(
|
|
208
206
|
{
|
|
209
207
|
client: this.client,
|
|
210
|
-
}
|
|
208
|
+
}
|
|
211
209
|
);
|
|
212
210
|
if (response.data) {
|
|
213
211
|
return response.data;
|
|
214
212
|
} else {
|
|
215
213
|
throw new Error(
|
|
216
|
-
"Failed to list domain verification requests\n" +
|
|
217
|
-
response.error.message,
|
|
214
|
+
"Failed to list domain verification requests\n" + response.error.message
|
|
218
215
|
);
|
|
219
216
|
}
|
|
220
217
|
}
|
|
221
218
|
|
|
222
219
|
async deleteDomainVerificationRequest(
|
|
223
220
|
domain: string,
|
|
224
|
-
verificationCode: string
|
|
221
|
+
verificationCode: string
|
|
225
222
|
): Promise<sandbox_openapi.HandleDeleteDomainVerificationResponse> {
|
|
226
223
|
const response = await sandbox_openapi.handleDeleteDomainVerification({
|
|
227
224
|
client: this.client,
|
|
@@ -234,14 +231,14 @@ export class FreestyleSandboxes {
|
|
|
234
231
|
return response.data;
|
|
235
232
|
} else {
|
|
236
233
|
throw new Error(
|
|
237
|
-
`Failed to delete domain verification request for domain ${domain}: ${response.error.message}
|
|
234
|
+
`Failed to delete domain verification request for domain ${domain}: ${response.error.message}`
|
|
238
235
|
);
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
238
|
|
|
242
239
|
async listWebDeployments(
|
|
243
240
|
limit?: number,
|
|
244
|
-
offset?: number
|
|
241
|
+
offset?: number
|
|
245
242
|
): Promise<sandbox_openapi.HandleListWebDeploysResponse> {
|
|
246
243
|
const response = await sandbox_openapi.handleListWebDeploys({
|
|
247
244
|
client: this.client,
|
|
@@ -254,14 +251,14 @@ export class FreestyleSandboxes {
|
|
|
254
251
|
return response.data;
|
|
255
252
|
} else {
|
|
256
253
|
throw new Error(
|
|
257
|
-
"Failed to list web deployments\n" + response.error.message
|
|
254
|
+
"Failed to list web deployments\n" + response.error.message
|
|
258
255
|
);
|
|
259
256
|
}
|
|
260
257
|
}
|
|
261
258
|
|
|
262
259
|
async listExecuteRuns(
|
|
263
260
|
limit?: number,
|
|
264
|
-
offset?: number
|
|
261
|
+
offset?: number
|
|
265
262
|
): Promise<sandbox_openapi.HandleListExecuteRunsResponse> {
|
|
266
263
|
const response = await sandbox_openapi.handleListExecuteRuns({
|
|
267
264
|
client: this.client,
|
|
@@ -278,7 +275,7 @@ export class FreestyleSandboxes {
|
|
|
278
275
|
}
|
|
279
276
|
|
|
280
277
|
async getExecuteRun(
|
|
281
|
-
id: string
|
|
278
|
+
id: string
|
|
282
279
|
): Promise<sandbox_openapi.HandleGetExecuteRunResponse> {
|
|
283
280
|
const response = await sandbox_openapi.handleGetExecuteRun({
|
|
284
281
|
client: this.client,
|
|
@@ -292,7 +289,7 @@ export class FreestyleSandboxes {
|
|
|
292
289
|
}
|
|
293
290
|
|
|
294
291
|
throw new Error(
|
|
295
|
-
`Failed to get execute run with ID ${id}: ${response.error.message}
|
|
292
|
+
`Failed to get execute run with ID ${id}: ${response.error.message}`
|
|
296
293
|
);
|
|
297
294
|
}
|
|
298
295
|
|
|
@@ -302,7 +299,7 @@ export class FreestyleSandboxes {
|
|
|
302
299
|
* @param name The name of the repository.
|
|
303
300
|
*/
|
|
304
301
|
async createGitRepository(
|
|
305
|
-
name: string
|
|
302
|
+
name: string
|
|
306
303
|
): Promise<sandbox_openapi.CreateRepoHandlerResponse> {
|
|
307
304
|
const response = await sandbox_openapi.createRepoHandler({
|
|
308
305
|
client: this.client,
|
|
@@ -314,7 +311,7 @@ export class FreestyleSandboxes {
|
|
|
314
311
|
return response.data;
|
|
315
312
|
}
|
|
316
313
|
throw new Error(
|
|
317
|
-
`Failed to create git repository ${name}: ${response.error}
|
|
314
|
+
`Failed to create git repository ${name}: ${response.error}`
|
|
318
315
|
);
|
|
319
316
|
}
|
|
320
317
|
|
|
@@ -326,7 +323,7 @@ export class FreestyleSandboxes {
|
|
|
326
323
|
*/
|
|
327
324
|
async listGitRepositories(
|
|
328
325
|
limit?: number,
|
|
329
|
-
offset?: number
|
|
326
|
+
offset?: number
|
|
330
327
|
): Promise<sandbox_openapi.ListRepositoriesHandlerResponse> {
|
|
331
328
|
const response = await sandbox_openapi.listRepositoriesHandler({
|
|
332
329
|
client: this.client,
|
|
@@ -347,7 +344,7 @@ export class FreestyleSandboxes {
|
|
|
347
344
|
* @param repositoryId The ID of the repository to delete.
|
|
348
345
|
*/
|
|
349
346
|
async deleteGitRepository(
|
|
350
|
-
repositoryId: string
|
|
347
|
+
repositoryId: string
|
|
351
348
|
): Promise<sandbox_openapi.DeleteRepoHandlerResponse> {
|
|
352
349
|
const response = await sandbox_openapi.deleteRepoHandler({
|
|
353
350
|
client: this.client,
|
|
@@ -360,7 +357,7 @@ export class FreestyleSandboxes {
|
|
|
360
357
|
return response.data;
|
|
361
358
|
} else {
|
|
362
359
|
throw new Error(
|
|
363
|
-
`Failed to delete git repository ${repositoryId}: ${response.error}
|
|
360
|
+
`Failed to delete git repository ${repositoryId}: ${response.error}`
|
|
364
361
|
);
|
|
365
362
|
}
|
|
366
363
|
}
|
|
@@ -378,7 +375,7 @@ export class FreestyleSandboxes {
|
|
|
378
375
|
return response.data;
|
|
379
376
|
} else {
|
|
380
377
|
throw new Error(
|
|
381
|
-
`Failed to provision wildcard for domain ${domain}: ${response.error.message}
|
|
378
|
+
`Failed to provision wildcard for domain ${domain}: ${response.error.message}`
|
|
382
379
|
);
|
|
383
380
|
}
|
|
384
381
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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.FreestyleDeployWebPayload["files"]> => {
|
|
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
|
+
});
|
|
18
|
+
|
|
19
|
+
for (const relativePath of patterns) {
|
|
20
|
+
try {
|
|
21
|
+
const filePath = path.join(directory, relativePath);
|
|
22
|
+
const content = await fs.readFile(filePath, "base64");
|
|
23
|
+
files[relativePath] = {
|
|
24
|
+
content,
|
|
25
|
+
encoding: "base64",
|
|
26
|
+
};
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(`Error reading file ${relativePath}:`, error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return files;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const prepareDirForDeploymentSync = (directory: string) => {
|
|
36
|
+
const files: sandbox_openapi.FreestyleDeployWebPayload["files"] = {};
|
|
37
|
+
|
|
38
|
+
const patterns = globSync("**/*", {
|
|
39
|
+
cwd: directory,
|
|
40
|
+
nodir: true,
|
|
41
|
+
ignore: ["**/node_modules/**"],
|
|
42
|
+
absolute: false,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
for (const relativePath of patterns) {
|
|
46
|
+
try {
|
|
47
|
+
const filePath = path.join(directory, relativePath);
|
|
48
|
+
const content = fsSync.readFileSync(filePath, "base64");
|
|
49
|
+
files[relativePath] = {
|
|
50
|
+
content,
|
|
51
|
+
encoding: "base64",
|
|
52
|
+
};
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(`Error reading file ${relativePath}:`, error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return files;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* This is in beta, and may not work as expected. SUBJECT TO CHANGE.
|
|
63
|
+
*/
|
|
64
|
+
export const prepareNextJsForDeployment = async (
|
|
65
|
+
directory: string
|
|
66
|
+
): Promise<sandbox_openapi.FreestyleDeployWebPayload["files"]> => {
|
|
67
|
+
const publicDir = path.join(directory, "public");
|
|
68
|
+
const nextPublicDestination = path.join(directory, ".next/standalone/public");
|
|
69
|
+
|
|
70
|
+
const staticDir = path.join(directory, ".next/static");
|
|
71
|
+
const nextStaticDestination = path.join(
|
|
72
|
+
directory,
|
|
73
|
+
".next/standalone/.next/static"
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// now copy everything from publicDir to nextPublicDestination
|
|
77
|
+
// and everything from staticDir to nextStaticDestination
|
|
78
|
+
await fs.mkdir(nextPublicDestination, { recursive: true });
|
|
79
|
+
await fs.copyFile(publicDir, nextPublicDestination);
|
|
80
|
+
|
|
81
|
+
await fs.mkdir(nextStaticDestination, { recursive: true });
|
|
82
|
+
await fs.copyFile(staticDir, nextStaticDestination);
|
|
83
|
+
|
|
84
|
+
return await prepareDirForDeployment(directory);
|
|
85
|
+
};
|