@opencoredev/sandbox-sdk 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +9 -6
- package/dist/ai.js +1 -1
- package/dist/chunk-0eeyc0aq.js +4 -0
- package/dist/chunk-0wp6x4wb.js +2 -0
- package/dist/chunk-2999xbh7.js +2 -0
- package/dist/chunk-3h6c1ack.js +2 -0
- package/dist/{chunk-q5vqajhg.js → chunk-7rkcx5cx.js} +2 -2
- package/dist/{chunk-hzbssbep.js → chunk-7s9pxk1v.js} +4 -4
- package/dist/chunk-aek8n3a4.js +78 -0
- package/dist/{chunk-8786zrns.js → chunk-aq6fmgdx.js} +2 -2
- package/dist/chunk-drhcb2hx.js +2 -0
- package/dist/chunk-ek44atpe.js +2 -0
- package/dist/chunk-g5n5xcmp.js +0 -0
- package/dist/chunk-kdecey83.js +290 -0
- package/dist/{chunk-bd481sb7.js → chunk-pdgnaxp9.js} +2 -2
- package/dist/{chunk-k60b4r27.js → chunk-qfhee1t8.js} +2 -2
- package/dist/chunk-rx9318sh.js +5 -0
- package/dist/chunk-sjnk17y5.js +26 -0
- package/dist/chunk-w8nk1xf2.js +17 -0
- package/dist/{chunk-bfzdkjjw.js → chunk-x05t86n3.js} +2 -2
- package/dist/{chunk-nw845a93.js → chunk-x4rrgmxf.js} +10 -10
- package/dist/chunk-xqtzts2q.js +1 -0
- package/dist/errors.d.ts +19 -9
- package/dist/files.d.ts +2 -5
- package/dist/http.d.ts +3 -0
- package/dist/index.d.ts +24 -3
- package/dist/index.js +1 -1
- package/dist/mastra.js +1 -1
- package/dist/memory.js +1 -1
- package/dist/openai.js +1 -1
- package/dist/provider.d.ts +127 -7
- package/dist/provider.js +1 -1
- package/dist/providers/agentos/index.js +2 -2
- package/dist/providers/baseten/errors.d.ts +6 -0
- package/dist/providers/baseten/execute.d.ts +68 -0
- package/dist/providers/baseten/index.d.ts +3 -0
- package/dist/providers/baseten/index.js +97 -0
- package/dist/providers/baseten/provider.d.ts +39 -0
- package/dist/providers/boat/index.js +1 -1
- package/dist/providers/boxd/errors.d.ts +25 -3
- package/dist/providers/boxd/index.js +14 -14
- package/dist/providers/boxd/provider.d.ts +16 -2
- package/dist/providers/daytona/api.d.ts +2 -2
- package/dist/providers/daytona/index.js +15 -15
- package/dist/providers/e2b/envd.d.ts +32 -2
- package/dist/providers/e2b/errors.d.ts +1 -2
- package/dist/providers/e2b/index.d.ts +40 -4
- package/dist/providers/e2b/index.js +1 -1
- package/dist/providers/e2b/narrow.d.ts +7 -0
- package/dist/providers/freestyle/execute.d.ts +3 -1
- package/dist/providers/freestyle/index.js +7 -16
- package/dist/providers/instabox/api.d.ts +56 -0
- package/dist/providers/instabox/errors.d.ts +49 -0
- package/dist/providers/instabox/index.d.ts +4 -0
- package/dist/providers/instabox/index.js +7 -0
- package/dist/providers/instabox/provider.d.ts +28 -0
- package/dist/providers/local/index.js +2 -2
- package/dist/providers/modal/errors.d.ts +4 -0
- package/dist/providers/modal/index.d.ts +14 -0
- package/dist/providers/modal/index.js +2 -0
- package/dist/providers/modal/provider.d.ts +94 -0
- package/dist/providers/modal/transport.d.ts +50 -0
- package/dist/providers/railway/index.js +1 -1
- package/dist/providers/sandboxer/index.js +1 -1
- package/dist/providers/superserve/execute.d.ts +3 -1
- package/dist/providers/superserve/index.js +22 -24
- package/dist/providers/tenki/deadline.d.ts +1 -1
- package/dist/providers/tenki/index.js +16 -26
- package/dist/providers/tenki/provider.d.ts +12 -12
- package/dist/providers/tenki/records.d.ts +1 -1
- package/dist/providers/upstash/index.js +11 -11
- package/dist/providers/upstash/provider.d.ts +1 -1
- package/dist/providers/vercel/index.js +1 -1
- package/dist/providers/vercel/transport.d.ts +1 -1
- package/dist/run.d.ts +9 -0
- package/dist/shared/guest.d.ts +28 -1
- package/dist/shared/native-error.d.ts +2 -0
- package/dist/streams.d.ts +2 -1
- package/dist/testing.js +3 -3
- package/dist/tools.js +1 -1
- package/dist/types.d.ts +37 -14
- package/dist/version.d.ts +4 -0
- package/package.json +28 -4
- package/dist/chunk-23tjmd39.js +0 -8
- package/dist/chunk-6a3wkj84.js +0 -2
- package/dist/chunk-8wq767xb.js +0 -17
- package/dist/chunk-9w9rddra.js +0 -2
- package/dist/chunk-ckym4cht.js +0 -23
- package/dist/chunk-hgrwyjrb.js +0 -2
- package/dist/chunk-kk1hw8wa.js +0 -1
- package/dist/chunk-vz47a139.js +0 -5
- package/dist/chunk-x681p5d2.js +0 -68
- package/dist/chunk-xgxfy2n8.js +0 -4
package/dist/chunk-vz47a139.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{l}from"./chunk-23tjmd39.js";import{z,ie}from"./chunk-bfzdkjjw.js";import{m}from"./chunk-bd481sb7.js";import{d,y,x,h,v,k}from"./chunk-6a3wkj84.js";import{f}from"./chunk-9w9rddra.js";import{t,o,r,e,i,c,a}from"./chunk-xgxfy2n8.js";import{deflateRawSync as Ue,inflateRawSync as ze}from"node:zlib";import{posix as Fe}from"node:path";var Te=/^[a-z][a-z0-9_]{0,63}$/;function B(n="boat",s="Boat",p="BOAT_API_KEY",I=!1){function b(E,U){if(E instanceof e)return E;let _=m(E),C=_.responseStatus,j="provider";if(C===401||C===403)j="auth";else if(C===404)j="not_found";else if(C===402||C===429)j="quota";else if(C===400)j="invalid_argument";else if(C===408||_.name==="TimeoutError")j="timeout";else if(C!==void 0&&C>=500)j="unavailable";else if(_.name==="AbortError")j="aborted";let P=j==="auth"?`Set ${p} to a valid ${s} API key.`:`Check the sandbox and ${s} service before retrying.`,W=_.apiCode!==void 0&&Te.test(_.apiCode)?` ${_.apiCode}`:"",Y=I&&C!==void 0?` (HTTP ${C}${W})`:"",J=i(E,{code:j,status:C===void 0?void 0:`HTTP ${C}${W}`,redact:c([process.env[p]])});return new e(`${s} request failed${Y}: ${a(j,J.detail)}. ${P}`,{code:j,provider:n,sandboxId:U,hint:P,retryable:j==="unavailable"||j==="quota",cause:J.cause})}function A(E,U="provider",_){let C=E.replaceAll("Boat",s);return new e(U==="auth"?C:`${C}. Check the ${s} provider configuration and retry.`,{code:U,provider:n,sandboxId:_})}return{boatError:b,failure:A}}var Ee={idleMs:60000,retryWindowMs:60000,retryDelayMs:1000},fe=(n,s)=>{let p=n[s];return o(p)&&Number.isSafeInteger(p)&&p>=0?p:void 0};function Ne(n,s){if(!f(n)||!t(n.type))throw s("a frame has no type");switch(n.type){case"stdout":case"stderr":{if(!("data"in n)||!t(n.data))throw s("an output frame has no data");let p=fe(n,"nextOffset");return{type:n.type,data:n.data,nextOffset:p}}case"attached":case"heartbeat":case"reconnect":{let p=fe(n,"stdoutOffset"),I=fe(n,"stderrOffset");return{type:n.type,stdoutOffset:p,stderrOffset:I}}case"exit":{let p="exitCode"in n?n.exitCode:void 0;if(p!==null&&!o(p))throw s("the exit frame has no exit code","outcome_unknown");return{type:"exit",exitCode:p,timedOut:"timedOut"in n&&n.timedOut===!0}}case"error":return{type:"error"};default:return{type:"other"}}}function je(n){let s=z(n);if(s)return s==="disconnected"||s==="truncated";return n instanceof e&&(n.code==="unavailable"||n.code==="timeout")}async function*ge(n,s,p,I){let{signal:b}=I,A=I.timing??Ee,E=n.label,U=()=>new e(`${E} command stream aborted. The signal was cancelled.`,{code:"aborted",provider:n.provider,sandboxId:s}),_=(W,Y="provider")=>new e(`${E} command stream is invalid: ${W}. Check the ${E} service and retry.`,{code:Y,provider:n.provider,sandboxId:s}),C={stdout:0,stderr:0},j=!1,P;for(;;){if(b.aborted)throw U();try{let W=await n.stream({method:"GET",path:"/sandboxes/{sandboxId}/commands/{processId}/stream",params:{sandboxId:s,processId:p},sandboxId:s,query:{stdoutOffset:C.stdout,stderrOffset:C.stderr},signal:b,startupTimeoutMs:A.idleMs,idleTimeoutMs:A.idleMs});if(j=!0,!W.body)throw new e(`${E} command stream has no body. The connection will be retried.`,{code:"unavailable",provider:n.provider,sandboxId:s,retryable:!0});let Y=!1;for await(let J of ie(W.body,{provider:n.provider,sandboxId:s,signal:b})){P=void 0;let F=Ne(J,_);switch(F.type){case"stdout":case"stderr":if(F.nextOffset!==void 0){if(F.nextOffset<=C[F.type])break;C[F.type]=F.nextOffset}if(F.data)yield{type:F.type,data:F.data};break;case"exit":case"error":yield F;return;case"attached":C.stdout=F.stdoutOffset??C.stdout,C.stderr=F.stderrOffset??C.stderr;break;case"heartbeat":case"reconnect":C.stdout=Math.max(C.stdout,F.stdoutOffset??0),C.stderr=Math.max(C.stderr,F.stderrOffset??0),Y=F.type==="reconnect";break;case"other":break;default:return F}if(Y)break}if(Y)continue;throw new e(`${E} command stream ended before the command did. The connection will be retried.`,{code:"unavailable",provider:n.provider,sandboxId:s,retryable:!0})}catch(W){if(b.aborted)throw U();if(P??=Date.now(),!j||!je(W)||Date.now()-P>=A.retryWindowMs)throw W;try{await y(A.retryDelayMs,d(A.retryWindowMs,b),n.provider)}catch{throw U()}}}}function me(n){return x({provider:n.provider,label:n.label,defaultPlane:"api",planes:{api:{baseUrl:n.baseUrl,auth:()=>({authorization:`Bearer ${n.credentials()}`})}},timeoutMs:n.timeoutMs,secrets:n.secrets,idempotencyHeader:"Idempotency-Key",authHint:`Set ${n.keyEnv} to a valid ${n.label} API key.`,retries:n.retries,fetch:n.fetch})}function ke(n,s,p,I){return new e(`${s} returned an invalid ${p}. Check the ${s} provider configuration and retry.`,{code:"provider",provider:n,sandboxId:I})}function Se(n,s,p){if(!r(n)||n===null||!("id"in n)||!t(n.id)||!n.id)throw ke(s,p,"sandbox");let I="name"in n&&t(n.name)?n.name:"",b="state"in n&&t(n.state)?n.state:"",A="createdAt"in n&&(t(n.createdAt)||o(n.createdAt))?new Date(n.createdAt).getTime():Number.NaN;return{id:n.id,name:I,state:b,createdAt:A,raw:n}}function ve(n,s,p){return Se(r(n)&&"sandbox"in n?n.sandbox:void 0,s,p)}function $e(n,s,p){if(!r(n)||n===null||!("sandboxes"in n)||!Array.isArray(n.sandboxes))throw ke(s,p,"sandbox list");let I=n.sandboxes.map((_)=>Se(_,s,p)),b="pageInfo"in n?n.pageInfo:void 0,A=r(b)&&"hasMore"in b&&b.hasMore===!0,E=r(b)&&b!==null&&"nextCursor"in b&&t(b.nextCursor)?b.nextCursor:void 0,U={sandboxes:I,hasMore:A};if(E!==void 0)U.nextCursor=E;return U}function qe(n){if(!r(n)||n===null)return{kind:"unknown"};if("stdout"in n&&t(n.stdout)&&"stderr"in n&&t(n.stderr)&&"exitCode"in n&&(n.exitCode===null||o(n.exitCode))){let s="stdoutTruncated"in n&&n.stdoutTruncated===!0||"stderrTruncated"in n&&n.stderrTruncated===!0;return{kind:"finished",stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode,truncated:s}}if("processId"in n&&o(n.processId))return{kind:"started",processId:n.processId};return{kind:"unknown"}}async function te(n,s,p,I=!1){let b={method:"POST",path:"/sandboxes/{sandboxId}/commands",params:{sandboxId:s},sandboxId:s,body:p};return qe((await(I?n.cleanup(b):n.request(b))).json())}async function se(n,s,p){await n.request({method:"PUT",path:"/sandboxes/{sandboxId}/files",params:{sandboxId:s},sandboxId:s,body:p})}async function Ie(n,s,p){let I=await n.json({method:"DELETE",path:"/sandboxes/{sandboxId}/commands/{processId}",params:{sandboxId:s,processId:p},sandboxId:s});return r(I)&&"running"in I?I.running:void 0}var le=`flock -x /tmp/.sandbox-sdk-workspace-ready.lock sh -c 'if [ ! -f /tmp/.sandbox-sdk/prepared-workspace ]; then sudo mkdir -p /workspace && sudo chown "$(id -u):$(id -g)" /workspace && command -v node git tar setsid nohup mkfifo sed base64 >/dev/null && mkdir -p /tmp/.sandbox-sdk && touch /tmp/.sandbox-sdk/prepared-workspace || exit 1; fi' || exit 1`,T=(n)=>`'${n.replaceAll("'","'\\''")}'`,de=4194304;async function pe(n,s,p,I,b){let A=Array.from({length:Math.max(1,Math.ceil(I.length/de))},(U,_)=>`${p}/part-${_}`),E=await te(n,s,{command:`mkdir -p /tmp/.sandbox-sdk && mkdir -m 700 -- ${T(p)} && (umask 077 && touch -- ${A.map(T).join(" ")})`,timeoutSeconds:60});if(E.kind!=="finished"||E.exitCode!==0)throw b("Boat could not prepare private staging","provider",s);for(let[U,_]of A.entries())await se(n,s,{path:_,content:Buffer.from(I.subarray(U*de,(U+1)*de)).toString("base64"),encoding:"base64"});return A}async function Be(n,s,p,I={},b=new Map,A=B(),E={}){let{boatError:U,failure:_}=A;if(p.signal?.aborted)return{exitCode:null,timedOut:!0};let C=new AbortController,j=!1,P=()=>{},W=new Promise((w)=>{P=()=>{j=!0,w("cancelled")}}),Y=setTimeout(P,p.timeoutMs);p.signal?.addEventListener("abort",P,{once:!0});let J,F=!1,X=!1,Z,ae=!1,Q,u=`/tmp/.sandbox-sdk-setup-${crypto.randomUUID()}`;async function g(){if(J===void 0)return;try{if(await Ie(n,s,J)!==!1)throw _("Boat did not confirm process-tree cancellation","outcome_unknown",s)}catch{throw _("Remote cancellation could not be confirmed; destroy the sandbox before retrying","outcome_unknown",s)}}try{let w=Object.entries(p.env).filter(([O,R])=>!Object.entries(l).some(([ne,ce])=>O===ne&&R===ce)&&I[O]!==R),S=Object.entries(l).filter(([O,R])=>p.env[O]===R).map(([O,R])=>`export ${T(`${O}=${R}`)}`).join("; ");if(S)S+="; ";let N="/tmp/.sandbox-sdk/changes.git/sdk.index",D=w.filter(([O,R])=>O==="GIT_INDEX_FILE"&&R===N);w=w.filter(([O,R])=>O!=="GIT_INDEX_FILE"||R!==N);for(let[O,R]of D)S+=`export ${T(`${O}=${R}`)}; `;if(w.length){let O=JSON.stringify(w),R=p.envMode==="sandbox"?b.get(O):void 0;if(R)S+=`. ${T(await R)} || exit 1; `;else{Q=`/tmp/.sandbox-sdk/env-${crypto.randomUUID()}`;let ne=`${Q}/env`,ce=Q,he=(async()=>{let we=await te(n,s,{command:`node -e ${T("const f=require('fs');f.mkdirSync('/tmp/.sandbox-sdk',{recursive:true});f.mkdirSync(process.argv[1],{mode:0o700});f.writeFileSync(process.argv[1]+'/env','',{flag:'wx',mode:0o600})")} ${T(ce)}`,timeoutSeconds:60});if(we.kind!=="finished"||we.exitCode!==0)throw _("Boat could not prepare command environment","provider",s);return await se(n,s,{path:ne,content:w.map(([Ae,Pe])=>`export ${T(`${Ae}=${Pe}`)}`).join(`
|
|
2
|
-
`)+`
|
|
3
|
-
`,encoding:"utf8"}),ne})();if(p.envMode==="sandbox")b.set(O,he);try{await he}catch(xe){if(p.envMode==="sandbox")b.delete(O);throw xe}if(p.envMode==="sandbox")Q=void 0,S+=`. ${T(ne)} || exit 1; `;else S+=`chmod 600 ${T(ne)} && . ${T(ne)} && /bin/rm -f -- ${T(ne)} && /bin/rmdir -- ${T(ce)} || exit 1; `}}let L=Buffer.from(p.stdin??""),H="/dev/null",G="",re="";if(L.length){Z=`/tmp/.sandbox-sdk/stdin-${crypto.randomUUID()}`;let O=await pe(n,s,Z,L,_);if(H=O.length===1?`${Z}/part-0`:`${Z}/stdin`,O.length>1)re=`(umask 077 && cat -- ${O.map(T).join(" ")} > ${T(H)}) || { echo setup-failed > ${T(u)}; exit 125; }; `;G=`/bin/rm -rf -- ${T(Z)}; `}if(j)return{exitCode:null,timedOut:!0};let ee=`(${le}) || { echo setup-failed > ${T(u)}; exit 125; }; ${re}{ ${G}(${S}cd ${T(p.cwd)} && exec sh -c ${T(p.command)}); } < ${T(H)}`;X=!0;let K=await te(n,s,{command:ee,detached:!0});if(K.kind!=="started"||!Number.isSafeInteger(K.processId)||K.processId<1)throw _("Boat did not confirm a detached process ID","outcome_unknown",s);if(J=K.processId,p.signal?.aborted)P();let V=(async()=>{for await(let O of ge(E.http??n,s,K.processId,{signal:C.signal,timing:E.timing}))if(O.type==="stdout"||O.type==="stderr")p.onChunk({stream:O.type,text:O.data});else if(O.type==="exit")return F=!0,ae=O.exitCode!==125,{exitCode:O.exitCode,timedOut:O.timedOut};else if(O.type==="error")throw _("Boat command stream failed","provider",s);throw _("Boat stream ended without an exit result","outcome_unknown",s)})();V.catch(()=>{});let oe=await Promise.race([V,W]);if(oe==="cancelled"||j)return await g(),C.abort(),await V.catch(()=>{}),{exitCode:null,timedOut:!0};if(!oe.timedOut&&oe.exitCode===125){let O=await te(n,s,{command:`if [ -f ${T(u)} ]; then cat ${T(u)}; rm -f -- ${T(u)}; fi`,timeoutSeconds:10});if(O.kind!=="finished"||O.exitCode!==0)throw _("Boat could not confirm command initialization","outcome_unknown",s);if(O.stdout.trim()==="setup-failed")throw _("Boat workspace initialization failed; the requested command did not run","provider",s)}return oe}catch(w){if(J!==void 0&&!F)await g();if(X&&J===void 0&&!["auth","quota","invalid_argument","not_found"].includes(U(w,s).code))throw _("Command launch outcome is unknown; inspect or destroy the sandbox before retrying","outcome_unknown",s);throw w}finally{if(C.abort(),clearTimeout(Y),p.signal?.removeEventListener("abort",P),Q)await te(n,s,{command:`rm -rf -- ${T(Q)}`,timeoutSeconds:10},!0).catch(()=>{});if(Z&&!ae)await te(n,s,{command:`rm -rf -- ${T(Z)}`,timeoutSeconds:10},!0).catch(()=>{})}}var He={name:"boat",label:"Boat",keyEnv:"BOAT_API_KEY",baseEnv:"BOAT_API_BASE",baseUrl:"https://boat.dev/api/v1"},ue="@boatdev/sdk",ye="sandbox-sdk:1:",Ce={"sandbox-sdk":"1"},Je={small:"small",medium:"default",large:"large"};function De(n,s,p){let I={...n.labels};delete I["sandbox-sdk"];let b=JSON.stringify([n.key??null,I]);if(Buffer.byteLength(b)>65536)throw s("Key and labels exceed the metadata size limit","unsupported");let A=ye+Ue(b).toString("base64url");if(A.length>120)throw s(`Key and labels exceed ${p}'s encoded name budget; shorten them`,"unsupported");return A}function Me(n){if(!n.startsWith(ye))return;try{let s=JSON.parse(ze(Buffer.from(n.slice(ye.length),"base64url"),{maxOutputLength:65536}).toString());if(!Array.isArray(s)||s.length!==2)return;let[p,I]=s;if(p!==null&&!t(p))return;if(!r(I)||I===null||Array.isArray(I))return;let b={};for(let[A,E]of Object.entries(I)){if(!t(E))return;Object.defineProperty(b,A,{value:E,enumerable:!0,writable:!0,configurable:!0})}return p===null?{labels:{...b,...Ce}}:{key:p,labels:{...b,...Ce}}}catch{return}}function be(n,s,p,I=[]){let b=Me(n.name);if(!b)throw s("Sandbox has no valid SDK metadata; connect an SDK-created sandbox","not_found",n.id);let A=n.createdAt;if(!Number.isFinite(A))throw s(`${p} returned no valid creation timestamp`,"provider",n.id);return{id:n.id,...b,createdAt:A,state:I.includes(n.state)?"paused":["ready","idle","running"].includes(n.state)?"running":"stopped"}}function Oe(n,s,p){if(!r(n)||n===null||!("path"in n)||!t(n.path)||!("type"in n)||!("size"in n)||!o(n.size)||!("modifiedAt"in n)||!o(n.modifiedAt))throw s(`Invalid file metadata from ${p}`);let I=n.type;if(I!=="file"&&I!=="directory"&&I!=="symlink")throw s(`Invalid file type from ${p}`);return{path:n.path,type:I,size:n.size,modifiedAt:n.modifiedAt}}var _e="const fs=require('fs'),p=require('path');const stat=x=>{const s=fs.lstatSync(x);return {path:x,type:s.isSymbolicLink()?'symlink':s.isDirectory()?'directory':'file',size:s.size,modifiedAt:s.mtimeMs}};";function q(n={},s=He){let{failure:p,boatError:I}=B(s.name,s.label,s.keyEnv,s.name!=="boat"),b=s.label,A=new Map,E=new Map,U=n.requestTimeoutMs??90000,_=()=>n.apiKey??process.env[s.keyEnv];function C(){let u=_();if(!u)throw p(`${b} API key is missing. Authentication is required. Set ${s.keyEnv} or pass apiKey.`,"auth");if(!Number.isSafeInteger(U)||U<=0)throw p("requestTimeoutMs must be a positive integer","invalid_argument");return u}let j={provider:s.name,label:b,keyEnv:s.keyEnv,baseUrl:()=>n.baseUrl??n.apiUrl??(s.baseEnv?process.env[s.baseEnv]:void 0)??s.baseUrl,credentials:C,secrets:()=>[_()],timeoutMs:Number.isSafeInteger(U)&&U>0?U:90000},P=me(j),W=me({...j,retries:0}),Y=(u)=>{let g=ve(u,s.name,b);return s.observe?.(g),g};async function J(u,g){try{return await u()}catch(w){throw I(w,g)}}async function F(u,g,w=!1,M=!1){let S=await te(P,u,{command:M?`${le}; ${g}`:g,timeoutSeconds:60});if(S.kind!=="finished")throw p(`${b} returned an unexpected detached result`,"outcome_unknown",u);if(S.truncated)throw p(`${b} truncated operation output; no partial file data was returned`,"provider",u);if(S.exitCode!==0)throw p(w&&S.exitCode===44?"File does not exist":`${b} file or setup operation failed`,w&&S.exitCode===44?"file_not_found":"provider",u);return S.stdout}let X=(u,g,w=[])=>J(()=>F(u,`node -e ${T(`try {${g}} catch(e) {process.exit(e.code==='ENOENT'?44:45)}`)} ${w.map(T).join(" ")}`,!0,w.some((M)=>M==="/workspace"||M.startsWith("/workspace/"))),u);async function Z(u,g,w,M){let S=[];for(let N=0;N<M;N+=16384){let D=Math.min(16384,M-N),L=await X(u,"const f=require('fs'),fd=f.openSync(process.argv[1],'r');try{const b=Buffer.alloc(Number(process.argv[3]));const n=f.readSync(fd,b,0,b.length,Number(process.argv[2]));process.stdout.write(b.subarray(0,n).toString('base64'))}finally{f.closeSync(fd)}",[g,String(w+N),String(D)]),H=Buffer.from(L,"base64");if(S.push(H),H.length<D)break}return new Uint8Array(Buffer.concat(S))}let ae={package:ue,async connect(u,g){let w=v(u,"Configuration",[{...s.sdkConfiguration,basePath:j.baseUrl(),accessToken:C()}],ue),M=v(u,"BoatApi",[w],ue);if(g===void 0)return M;let S=await k(M,"get",[{sandboxId:g}],ue);return{client:M,sandbox:r(S)?"sandbox"in S?S.sandbox:void 0:void 0}}},Q={name:s.name,keyMode:"best-effort",capabilities:new Set(["size"]),create:(u)=>J(async()=>{if(u.network!==void 0&&u.network!=="all")throw p(`${b} network policy is unsupported by this adapter`,"unsupported");if(u.size!==void 0&&!t(u.size))throw p(`${b} supports small, medium and large presets; custom sizes are unavailable`,"unsupported");if(u.timeoutMs!==void 0)throw p(`${b} auto-stop archives the VM and restarts while its agent works, so it is not a hard lifetime; timeoutMs is unsupported. Set the provider's ttlSeconds option instead`,"unsupported");if(u.idleTimeoutMs!==void 0&&!s.idleStop)throw p(`${b} has no idle timer; idleTimeoutMs is unsupported`,"unsupported");let{ttlSeconds:g,snapshots:w,monitoring:M,org:S}=n;if(g!==void 0&&g!==null&&(!Number.isSafeInteger(g)||g<1||g>2592000))throw p("ttlSeconds must be null or an integer from 1 to 2592000","invalid_argument");let N;if(u.idleTimeoutMs!==void 0){if(N=Math.ceil(u.idleTimeoutMs/60000),N>10080)throw p(`${b} idle pause is at most 7 days`,"invalid_argument");if(w===!1)throw p(`${b} idle pause needs snapshots; drop idleTimeoutMs or snapshots: false`,"invalid_argument")}if(u.from!==void 0&&!s.createFrom)throw p(`${b} snapshots are not supported by this adapter`,"unsupported");let D=De(u,p,b);if(u.signal?.aborted)throw p("Creation was aborted","aborted");let L=crypto.randomUUID(),H={noEnv:!0,from:u.from,env:u.env,type:u.size===void 0?n.machine??n.type:Je[u.size],ttlSeconds:g,snapshots:w,monitoring:M,org:S,idleStopMinutes:N,...s.createFields},G=d(j.timeoutMs),re=()=>p(`${b} create outcome remains unknown; recover with idempotency key ${L} and the same request body within 24 hours`,"outcome_unknown"),ee;for(let V=0;V<3;V++)try{ee=Y(await W.json({method:"POST",path:"/sandboxes",body:H,idempotencyKey:L,deadline:G}));break}catch(oe){let O=I(oe).code;if(["auth","invalid_argument","quota","not_found"].includes(O))throw oe;let R=250*(V+1);if(V===2||R>=G.remaining())throw re();await y(R,G,s.name).catch(()=>{throw re()})}if(!ee)throw p(`${b} returned no sandbox after create`,"outcome_unknown");let K=ee.id;E.set(K,{...u.env});try{if(u.signal?.aborted)throw p("Creation was aborted","aborted");let V=Y(await P.json({method:"PATCH",path:"/sandboxes/{sandboxId}",params:{sandboxId:K},sandboxId:K,body:{name:D},deadline:G}));if(u.signal?.aborted)throw p("Creation was aborted","aborted");if(V.name!==D)return await Q.connect(K);return{...be(V,p,b,s.pausedStates),state:"running"}}catch(V){throw await Q.destroy(K),V}}),connect:(u)=>J(async()=>be(Y(await P.json({method:"GET",path:"/sandboxes/{sandboxId}",params:{sandboxId:u},sandboxId:u})),p,b,s.pausedStates),u),list:(u)=>J(async()=>{let g=[],w,M=new Set;do{let S=$e(await P.json({method:"GET",path:"/sandboxes",query:{limit:200,cursor:w}}),s.name,b);for(let D of S.sandboxes){if(s.observe?.(D),!Me(D.name))continue;let L=be(D,p,b,s.pausedStates);if(Object.entries(u).every(([H,G])=>L.labels[H]===G))g.push(L)}if(!S.hasMore)break;let N=S.nextCursor;if(!N||M.has(N))throw p(`${b} returned an invalid pagination cursor`);M.add(N),w=N}while(w!==void 0);return g}),async find(u){return(await Q.list({})).find((g)=>g.key===u)},destroy:(u)=>J(async()=>{try{if(s.destroy)await s.destroy(P,u);else await P.request({method:"DELETE",path:"/sandboxes/{sandboxId}",params:{sandboxId:u},sandboxId:u,headers:{"X-Ascii-Confirm-Delete":u}})}catch(g){if(I(g).code!=="not_found")throw g}E.delete(u),A.delete(u)},u),exec:(u,g)=>J(async()=>{let w=A.get(u);if(!w)w=new Map,A.set(u,w);return Be(P,u,g,E.get(u),w,{failure:p,boatError:I},{http:W})},u),files:{writeCreatesParents:!0,writeSupportsMode:!0,readRange:(u,g,w)=>Z(u,g,w.offset,w.length),read:async(u,g)=>{let w=await X(u,"const f=require('fs'),fd=f.openSync(process.argv[1],'r');try{const size=f.fstatSync(fd).size,b=Buffer.alloc(Math.min(size,16384)),n=f.readSync(fd,b,0,b.length,0);process.stdout.write(size+'\\n'+b.subarray(0,n).toString('base64'))}finally{f.closeSync(fd)}",[g]),M=w.indexOf(`
|
|
4
|
-
`),S=Number(w.slice(0,M));if(M<0||!Number.isSafeInteger(S)||S<0)throw p(`Invalid ${b} file size`);let N=Buffer.from(w.slice(M+1),"base64");if(S<=16384)return new Uint8Array(N);if(S<=1048576)return new Uint8Array(Buffer.concat([N,await Z(u,g,N.length,S-N.length)]));if(s.downloadMaxBytes!==void 0&&S>s.downloadMaxBytes)return new Uint8Array(Buffer.concat([N,await Z(u,g,N.length,S-N.length)]));return J(async()=>{let D=`/tmp/.sandbox-sdk/download-${crypto.randomUUID()}`,L=`${D}/file`;try{let H=Number(await X(u,"const f=require('fs');f.mkdirSync('/tmp/.sandbox-sdk',{recursive:true});f.mkdirSync(process.argv[2],{mode:0o700});f.copyFileSync(process.argv[1],process.argv[2]+'/file');process.stdout.write(String(f.statSync(process.argv[2]+'/file').size))",[g,D]));if(!Number.isSafeInteger(H)||H<0)throw p("Invalid staged file size","provider",u);if(s.download){let K=await s.download(P,u,L);if(K.length!==H)throw p("Incomplete artifact download","provider",u);return K}let G=await P.json({method:"POST",path:"/sandboxes/{sandboxId}/files/download-url",params:{sandboxId:u},sandboxId:u,body:{path:L,ttlSeconds:300},readOnly:!0}),re=r(G)&&G!==null&&"url"in G&&t(G.url)?G.url:void 0;if(!re)throw p(`${b} returned no signed download URL`,"provider",u);let ee;try{ee=(await P.request({method:"GET",path:re,auth:!1,sandboxId:u,maxBytes:H+1})).body}catch(K){let V=I(K,u).code;throw p("Signed file download failed",V==="aborted"||V==="timeout"?V:"unavailable",u)}if(ee.length!==H)throw p("Incomplete signed file download","provider",u);return ee}finally{await X(u,"require('fs').rmSync(process.argv[1],{recursive:true,force:true})",[D]).catch(()=>{})}},u)},write:(u,g,w,M={})=>J(async()=>{let{mode:S}=M;if(S!==void 0&&(!Number.isSafeInteger(S)||S<0||S>4095))throw p("mode must be an integer from 0 to 0o7777","invalid_argument",u);let N=Fe.normalize(g);if(S===void 0&&w.length<=de&&(N.startsWith("/home/user/")||N.startsWith("/tmp/")))try{await se(P,u,{path:g,content:Buffer.from(w).toString("base64"),encoding:"base64"});return}catch(H){if(I(H).code!=="invalid_argument")throw H}let D=`/tmp/.sandbox-sdk/write-${crypto.randomUUID()}`,L=!1;try{let H=await pe(P,u,D,w,p);await X(u,"const f=require('fs'),[d,dir,n,m]=process.argv.slice(1);try{f.mkdirSync(require('path').dirname(d),{recursive:true});const fd=f.openSync(d,'w',m?0o600:0o666);try{if(m)f.fchmodSync(fd,Number(m));for(let i=0;i<Number(n);i++)f.writeFileSync(fd,f.readFileSync(dir+'/part-'+i))}finally{f.closeSync(fd)}}finally{f.rmSync(dir,{recursive:true,force:true})}",[g,D,String(H.length),S===void 0?"":String(S)]),L=!0}finally{if(!L)await X(u,"require('fs').rmSync(process.argv[1],{recursive:true,force:true})",[D]).catch(()=>{})}},u),stat:async(u,g)=>{let w=JSON.parse(await X(u,_e+"process.stdout.write(JSON.stringify(stat(process.argv[1])))",[g]));return Oe(w,p,b)},list:async(u,g)=>{let w=JSON.parse(await X(u,_e+"process.stdout.write(JSON.stringify(fs.readdirSync(process.argv[1]).map(x=>stat(p.join(process.argv[1],x)))))",[g]));if(!Array.isArray(w))throw p(`Invalid ${b} directory listing`);return w.map((M)=>Oe(M,p,b))},mkdir:async(u,g)=>{await X(u,"require('fs').mkdirSync(process.argv[1],{recursive:true})",[g])},remove:async(u,g,w)=>{await X(u,"require('fs').rmSync(process.argv[1],{recursive:process.argv[2]==='true'})",[g,String(w.recursive)])}},previewUrl:(u,g)=>J(async()=>{let w=await P.json({method:"POST",path:"/sandboxes/{sandboxId}/host",params:{sandboxId:u},sandboxId:u,body:{port:g}});if(!r(w)||w===null||!("url"in w)||!t(w.url)||!w.url)throw p(`${b} returned no preview URL`,"provider",u);if(s.preview)return s.preview(w.url);let M=new URL(w.url),S=M.searchParams.get("_token");if(S){if(!/^[A-Za-z0-9._~-]+$/.test(S))throw p("Invalid preview token","provider",u);return M.searchParams.delete("_token"),{url:M.toString(),headers:{Cookie:`_port_auth=${S}`}}}if("isProtected"in w&&w.isProtected===!0||"access"in w&&w.access==="private")throw p("Protected preview returned no token","provider",u);return{url:M.toString()}},u),native:(u)=>h({http:P,placeholder:"sandboxId",sandboxId:u,sdk:ae}),api:h({http:P,placeholder:"sandboxId",sdk:ae})};return{provider:Q,http:P}}
|
|
5
|
-
export{B,q};
|
package/dist/chunk-x681p5d2.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import{n}from"./chunk-2ts3evzh.js";import{t,o,r,e}from"./chunk-xgxfy2n8.js";var p=(s,...f)=>`python3 -c ${n(s)} ${f.map(n).join(" ")}`,b=`def stdin_file():
|
|
2
|
-
try: return os.fdopen(os.memfd_create('sandbox-sdk-stdin'),'w+b')
|
|
3
|
-
except (AttributeError,OSError):
|
|
4
|
-
import tempfile
|
|
5
|
-
return tempfile.TemporaryFile()
|
|
6
|
-
class Process:
|
|
7
|
-
# A missing cwd fails the command, not the supervisor: the shell reports it on stderr and exits 2.
|
|
8
|
-
def argv(self,v):
|
|
9
|
-
try: os.chdir(v['cwd']); return ['sh','-c',v['command']]
|
|
10
|
-
except OSError: return ['sh','-c','cd "$1" || exit 2','sh',v['cwd']]
|
|
11
|
-
def __init__(self,v,env,stdin,session=False):
|
|
12
|
-
if not all(hasattr(os,name) for name in ['posix_spawn','waitstatus_to_exitcode']):
|
|
13
|
-
self.legacy(v,env,stdin,session); return
|
|
14
|
-
directory=os.open('.',os.O_RDONLY)
|
|
15
|
-
r,w=os.pipe(); e,x=os.pipe()
|
|
16
|
-
try:
|
|
17
|
-
argv=self.argv(v)
|
|
18
|
-
error=FileNotFoundError(2,os.strerror(2),'sh')
|
|
19
|
-
signals=[getattr(signal,s) for s in ['SIGPIPE','SIGXFZ','SIGXFSZ'] if hasattr(signal,s)]
|
|
20
|
-
for path in os.get_exec_path(env):
|
|
21
|
-
try:
|
|
22
|
-
self.pid=os.posix_spawn(os.path.join(path,'sh'),argv,env,file_actions=[(os.POSIX_SPAWN_DUP2,stdin.fileno(),0),(os.POSIX_SPAWN_DUP2,w,1),(os.POSIX_SPAWN_DUP2,x,2)],setsid=session,setsigdef=signals)
|
|
23
|
-
break
|
|
24
|
-
except (FileNotFoundError,NotADirectoryError): pass
|
|
25
|
-
except OSError as failure:
|
|
26
|
-
if failure.errno==38: raise NotImplementedError()
|
|
27
|
-
error=failure
|
|
28
|
-
else: raise error
|
|
29
|
-
except NotImplementedError:
|
|
30
|
-
os.close(r); os.close(e)
|
|
31
|
-
self.legacy(v,env,stdin,session); return
|
|
32
|
-
except BaseException:
|
|
33
|
-
os.close(r); os.close(e); raise
|
|
34
|
-
finally:
|
|
35
|
-
os.fchdir(directory); os.close(directory); os.close(w); os.close(x)
|
|
36
|
-
self.stdout=os.fdopen(r,'rb',buffering=0); self.stderr=os.fdopen(e,'rb',buffering=0)
|
|
37
|
-
self.code=None
|
|
38
|
-
def legacy(self,v,env,stdin,session):
|
|
39
|
-
import subprocess
|
|
40
|
-
directory=os.open('.',os.O_RDONLY)
|
|
41
|
-
try: self.child=subprocess.Popen(self.argv(v),env=env,stdin=stdin,stdout=subprocess.PIPE,stderr=subprocess.PIPE,start_new_session=session)
|
|
42
|
-
finally: os.fchdir(directory); os.close(directory)
|
|
43
|
-
self.pid=self.child.pid; self.stdout=self.child.stdout; self.stderr=self.child.stderr
|
|
44
|
-
def poll(self):
|
|
45
|
-
if hasattr(self,'child'): return self.child.poll()
|
|
46
|
-
if self.code is None:
|
|
47
|
-
pid,status=os.waitpid(self.pid,os.WNOHANG)
|
|
48
|
-
if pid: self.code=os.waitstatus_to_exitcode(status)
|
|
49
|
-
return self.code
|
|
50
|
-
def wait(self):
|
|
51
|
-
if hasattr(self,'child'): return self.child.wait()
|
|
52
|
-
if self.code is None: self.code=os.waitstatus_to_exitcode(os.waitpid(self.pid,0)[1])
|
|
53
|
-
return self.code
|
|
54
|
-
`,u=(s,f,y="provider")=>new e(`${f}. Check the ${s.name} sandbox before retrying.`,{code:y,provider:s.name}),_=`import os,sys,json,stat
|
|
55
|
-
p=sys.argv[1]
|
|
56
|
-
def info(p):
|
|
57
|
-
s=os.lstat(p)
|
|
58
|
-
return dict(path=p,type='symlink' if stat.S_ISLNK(s.st_mode) else 'directory' if stat.S_ISDIR(s.st_mode) else 'file',size=s.st_size,modifiedAt=s.st_mtime*1000)
|
|
59
|
-
try: print(json.dumps([info(os.path.join(p,n)) for n in os.listdir(p)] if sys.argv[2]=='list' else info(p)))
|
|
60
|
-
except FileNotFoundError: print('SDK_FILE_NOT_FOUND')`,h="import os,sys; os.makedirs(os.path.dirname(sys.argv[1]),exist_ok=True)",w="import os,sys; os.makedirs(sys.argv[1],exist_ok=True)",g=`import os,sys,shutil
|
|
61
|
-
p=sys.argv[1]
|
|
62
|
-
try:
|
|
63
|
-
if os.path.isdir(p) and not os.path.islink(p):
|
|
64
|
-
if sys.argv[2]=='true': shutil.rmtree(p)
|
|
65
|
-
else: os.rmdir(p)
|
|
66
|
-
else: os.unlink(p)
|
|
67
|
-
except FileNotFoundError: print('SDK_FILE_NOT_FOUND')`;function L(s){return r(s)&&"path"in s&&t(s.path)&&"type"in s&&(s.type==="file"||s.type==="directory"||s.type==="symlink")&&"size"in s&&o(s.size)&&"modifiedAt"in s&&o(s.modifiedAt)}function F(s){return{path:s.path,type:s.type,size:s.size,modifiedAt:s.modifiedAt}}function R(s,f){let y=async(i,a,l)=>{let d=await s(i),c=await d.raw(p(_,a,l));if(c.trim()==="SDK_FILE_NOT_FOUND")throw u(d,"File does not exist","file_not_found");let m=JSON.parse(c);return{g:d,value:m}};return{writeCreatesParents:!0,readRange:(i,a,l)=>f(i,async()=>(await s(i)).read(a,l)),read:(i,a)=>f(i,async()=>(await s(i)).read(a)),write:(i,a,l,d)=>f(i,async()=>{let c=await s(i);try{await f(i,()=>c.upload(a,l,d?.mode))}catch(m){if(!(m instanceof e)||!["not_found","file_not_found"].includes(m.code))throw m;await c.raw(p(h,a)),await c.upload(a,l,d?.mode)}}),stat:(i,a)=>f(i,async()=>{let{g:l,value:d}=await y(i,a,"stat");if(!L(d))throw u(l,"Invalid file metadata");return F(d)}),list:(i,a)=>f(i,async()=>{let{g:l,value:d}=await y(i,a,"list");if(!Array.isArray(d))throw u(l,"Invalid directory listing");return d.map((c)=>{if(!L(c))throw u(l,"Invalid file metadata");return F(c)})}),mkdir:(i,a)=>f(i,async()=>{await(await s(i)).raw(p(w,a))}),remove:(i,a,l)=>f(i,async()=>{let d=await s(i);if((await d.raw(p(g,a,String(l.recursive)))).trim()==="SDK_FILE_NOT_FOUND")throw u(d,"File does not exist","file_not_found")})}}
|
|
68
|
-
export{p,b,L,F,R};
|
package/dist/chunk-xgxfy2n8.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
function t(n){return typeof n==="string"}function o(n){return typeof n==="number"}function I(n){return typeof n==="boolean"}function r(n){return typeof n==="object"&&n!==null}var f={auth:"Set the provider's API key environment variable or pass it to the provider factory.",not_found:"Create a new sandbox, or pass a key to createSandbox so it recreates one for you.",quota:"Wait and retry, destroy unused sandboxes with reapSandboxes, or raise the provider plan.",unavailable:"Retry with backoff. Check the provider's status page if it persists.",unsupported:"Remove the option or choose a provider that supports it. Check box.capabilities.",timeout:"Retry, or raise the relevant timeout option.",aborted:"Retry with a fresh AbortSignal if you still need the result.",outcome_unknown:"Check the sandbox state before retrying. If in doubt, destroy it.",process_exited:"Read the exit code and log tail in the message, fix the command, and start it again.",port_not_ready:"Check that the server listens on 0.0.0.0 and the right port, then read its logs.",edit_not_found:"Read the file again and use text that is in it.",edit_not_unique:"Add surrounding lines to find so it matches exactly once.",file_not_found:"Check the path. Relative paths resolve against /workspace.",invalid_argument:"Fix the input. Retrying the same call will not help.",provider:"Read the message and cause. Report it if it looks like an SDK bug."};class e extends Error{code;retryable;hint;provider;sandboxId;constructor(n,d){super(n,{cause:d.cause});this.name="SandboxError",this.code=d.code,this.retryable=d.retryable??!1,this.hint=d.hint??f[d.code]??f.provider,this.provider=d.provider??"unknown",this.sandboxId=d.sandboxId}static{Object.defineProperty(this,"name",{value:"SandboxError"})}[Symbol.for("nodejs.util.inspect.custom")](n,d,u){let l=this.stack??"",p=l.indexOf(`
|
|
2
|
-
at `)>=0?l.slice(l.indexOf(`
|
|
3
|
-
at `)):"",h={code:this.code,provider:this.provider,sandboxId:this.sandboxId,retryable:this.retryable,hint:this.hint,cause:this.cause};return`SandboxError [${this.code}]: ${this.message}${p} ${u(h,d)}`}}function C(n){return n instanceof e&&(n.code==="file_not_found"||n.code==="not_found")}class S{values=new Set;add(n){for(let d of n)if(d)this.values.add(d)}text(n){for(let d of[...this.values].sort((u,l)=>l.length-u.length))n=n.split(d).join("[REDACTED]");return n}get secrets(){return[...this.values].sort((n,d)=>d.length-n.length)}get maxLength(){return Math.max(1,...[...this.values].map((n)=>n.length))}error(n,d,u){if(n instanceof e)return new e(g(this.text(n.message)),{code:n.code,retryable:n.retryable,hint:g(this.text(n.hint)),provider:d,sandboxId:u,cause:n.cause===void 0?void 0:D(this.text(n.cause instanceof Error?n.cause.message:String(n.cause)))});let l=D(this.text(n instanceof Error?n.message:t(n)?n:"Non-Error value thrown"));return new e(`${l}. Provider request failed. Check the provider settings and retry.`,{code:"provider",hint:f.provider,provider:d,sandboxId:u,cause:w(n,(p)=>this.text(p))})}}var v=[[/https?:\/\/[^\s"'<>]+/gi,"[URL REDACTED]"],[/(\bauthorization["']?\s*[:=]\s*)(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\r\n;]+)/gi,"$1[REDACTED]"],[/\bBearer\s+[^\s"',;]+/gi,"Bearer [REDACTED]"],[/((?:["']?(?:api[-_]?key|access[-_]?token|token|password|secret)["']?)\s*[:=]\s*)(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s,;]+)/gi,"$1[REDACTED]"]];function g(n){for(let[d,u]of v)n=n.replace(d,u);return n}function D(n){return g(n).replace(/\p{Cc}+/gu," ").slice(0,1000)}function w(n,d=(l)=>l,u=0){if(!(n instanceof Error))return;let l=D(d(n.message?`${n.name}: ${n.message}`:n.name)),p=u<2?w(n.cause,d,u+1):void 0;return p===void 0?l:`${l}; caused by ${p}`}var b={auth:"the credentials are missing or were rejected",not_found:"the sandbox does not exist",quota:"a provider limit or billing stopped the request",unavailable:"the service is down or unreachable",unsupported:"the provider cannot do what was asked",timeout:"the operation took too long",aborted:"the request was aborted",outcome_unknown:"the request may or may not have happened",process_exited:"the process exited before it was ready",port_not_ready:"the port did not become ready",edit_not_found:"the text to replace was not found",edit_not_unique:"the text to replace matched more than once",file_not_found:"the path does not exist",invalid_argument:"the provider rejected the request as invalid",provider:"the provider returned an unexpected error"};function i(n,d){let l=!(d.known??d.code!=="provider")&&d.status===void 0?w(n,d.redact):void 0,p=[n instanceof Error?n.name:void 0,d.status].filter((h)=>h!==void 0).join(" ");return{detail:l,cause:l??(p||void 0)}}function se(n){return Object.assign(Error(JSON.stringify(n)),n)}function c(n){let d=new S;for(let u of n)if(u)d.add([u]);return(u)=>d.text(u)}function a(n,d){return d??b[n]}function fe(n){if(n===400||n===422)return"invalid_argument";if(n===401||n===403)return"auth";if(n===402||n===429)return"quota";if(n===404||n===410)return"not_found";if(n===408||n===504)return"timeout";if(n===413)return"unsupported";if(n>=500&&n<=599)return"unavailable";return"provider"}function s(n){throw new e(`${n}. The request is invalid. Check the supplied options.`,{code:"invalid_argument"})}
|
|
4
|
-
export{t,o,I,r,e,C,S,D,w,i,se,c,a,fe,s};
|