@north-light/cli 0.3.734 → 0.3.736

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.
@@ -1,3 +1,3 @@
1
- var V=Object.defineProperty;var l=(e,s)=>V(e,"name",{value:s,configurable:!0});import{zstdCompressSync as X}from"node:zlib";import{blobStore as Z}from"../../blobs/index.js";import{openDb as v,withCanvasWrite as D}from"../../canvas/db.js";import{runAsPerson as x}from"../../canvas/person.js";import{insertImportedRevisions as ee}from"../../graph/documents.js";import{getById as te}from"../../graph/objects.js";import{bundleKeys as M,decodeRows as ne,rowKeys as N,SEQ_TABLES as ae}from"../bundle/layout.js";import{readCatalog as ie}from"./catalog.js";import{copyRows as se,decodeKeys as L,encodeKeys as B}from"./copy.js";import{pruneStaged as re,precheck as oe,renameClashingLegacyCharges as de,renameClashingProfiles as pe,rewriteConversationHeaders as ue,rewritePaths as ce,rewriteRequestPaths as le,takeRepoSyncedDocuments as fe}from"./prepare.js";import{boundSub as me,dropRefusedMessages as _e,checkSourcePerson as we,checkStagedBlobKeys as ge,checkStagedPersons as be,checkStagedReferences as he,checkStagedRequestKeys as ye}from"./bind.js";import{deleteBlobs as Ee,deleteRunBlobs as Se,deleteRunPrefix as ve,moveRunBlobs as Re}from"./blobs.js";import{dropStubRows as Ie,findFleetGrant as Oe,grantMissing as Pe,mapProfileIds as Te,renameClashingRepos as je,rewriteIds as ke,rewritePerson as Ce,scopeRepoIdentities as Ae}from"./rewrite.js";import{dropStaging as W,ImportLaneError as g,stage as De,stagingSchema as Me,targetSchema as Ne}from"./stage.js";import{verifyRun as Le}from"./verify.js";import{sandboxPathMap as Be,writeNodeFiles as We}from"./path-map.js";import{allStoreKeys as He,readPluginsStore as Ke,recordImportedActivations as Ue,writeStores as Fe}from"./stores.js";import{openImportGrants as Je}from"./open-grants.js";import{publishImportedPlugins as Ge}from"./publish-plugins.js";import{COPIED_TABLES as qe}from"../bundle/layout.js";import{emitEvent as $e}from"../../events/emit.js";import{ClaimLostError as Ye}from"../../../daemon/reconcilers/row-claim.js";const ze=10*6e4,Qe=30*6e4,R=l(()=>new Date().toISOString(),"now"),H=l(async(e,s)=>{await(await v()).prepare("UPDATE import_runs SET step = ? WHERE run_id = ?").run(s,e)},"setStep");async function Ve(e,s){const a=await e.get(M.source(s));if(a===null)throw new g("stage","bundle_invalid","source.json is missing");const n=JSON.parse(a.toString("utf8"));if(typeof n.rowParts!="object"||n.rowParts===null)throw new g("stage","bundle_invalid","source.json names no row parts");return n}l(Ve,"readSource");async function Xe(e,s,a,n,i,p,d){const o=[];for(const t of N(a.run_id,"grants",n)){const u=await e.get(t);if(u===null)throw new g("stage","bundle_invalid",`row file ${t} is missing`);o.push(...ne(u))}if(o.length===0)return;const w=o.map(t=>({sub:me(t.sub,n.person,a.person,"grants.sub"),grantee:t.grantee}));await d(a.run_id);const f=[];for(const t of w)await Oe(s,i,p,t.sub,t.grantee)===void 0&&f.push(t.grantee);if(f.length>0)throw Pe(f)}l(Xe,"ensureGrants");async function It(e,s,a={}){const n=a.blobs??await Z(),i=await v(),p=Me(e.run_id);let d="start";const o=l(async t=>{d=t,await s.assertOwned(),await H(e.run_id,t),await a.atStep?.(t)},"at");let w=e.state==="committed";const f=[];try{const t=await Ve(n,e.run_id);if(e.source_kind==="machine"&&t.installId!==e.source_install_id)throw new g("stage","bundle_invalid",`source.json names install ${t.installId}, the run is for ${e.source_install_id}`);t.installId=e.source_install_id;const u=await Ne(i),I=[...qe],b=await ie(i,u,[...I,"grants"]);if(!w){const m={},P=[],T=[],j=a.fleetRuntime??process.env.CRTR_RUNTIME??null;await we(i,u,t.person,e.person),await o("open-grants"),await Xe(n,i,e,t,u,j,a.openGrants??Je),await o("publish-plugins");const U=await Ke(n,e.run_id),E=await x(e.person,()=>Ge(U));if(E.unavailable.length>0){if(e.loaded_at===void 0||e.loaded_at===null)throw new g("publish-plugins","import_failed","a loading run has no loaded_at");if(Date.now()-Date.parse(e.loaded_at)>=ze)throw new g("publish-plugins","directory_unavailable",`the directory did not answer for: ${E.unavailable.slice(0,10).join(", ")}; rerun the import once it is reachable`,{plugins:E.unavailable});await s.assertOwned(),await H(e.run_id,"waiting_for_directory");return}T.push(...E.refused),await o("stage");const F=await De(i,e.run_id,t.counts,r=>N(e.run_id,r,t),r=>n.get(r));for(const[r,c]of Object.entries(F))m[r]={staged:c,inserted:0,mapped:0,dropped:0};const _={db:i,schema:p,target:u,catalog:b,sourcePerson:t.person,targetPerson:e.person,fleetRuntime:j,shippedBodies:t.shippedBodies??{}};await o("bind-staged");for(const[r,c]of Object.entries(await be(_)))h(m,r,c);for(const[r,c]of Object.entries(await ge(_)))h(m,r,c);await o("rewrite-person"),await Ce(_),await Ae(_),await o("prune");const J=await re(i,p,b,t),S=t.kind==="hosted"?Be(t.pathPrefixes??[]):[];await o("rewrite-paths"),await ce(i,p,S),await ue(i,p,S,n,e.run_id),await le(i,p),await ye(_);const G=await Te(_);await pe(i,p,u,t.installId,e.person),await o("rewrite-ids");const k=await ke(_,G);await o("drop");const q=await fe(i,p,u),$=await Ie(_);for(const[r,c]of Object.entries({...J}))h(m,r,c);for(const[r,c]of Object.entries($))h(m,r,c);for(const[r,c]of Object.entries(await _e(_,{installId:t.installId,person:e.person,runId:e.run_id})))h(m,r,c);await he(_,{installId:t.installId,person:e.person,runId:e.run_id}),await je(_),await de(i,p,u,t.installId),await o("pre-check");const Y=new Map([["messages",["seq"]],...ae.map(r=>[r,["seq"]])]);await oe(i,p,u,b,I,new Set,Y),await o("blobs"),await Re(i,p,u,e.person,n,e.run_id,f),await o("copy"),await D(async r=>{await s.assertOwned({extendLeaseMs:Qe});const c=await se({db:r,runId:e.run_id,schema:p,target:u,catalog:b,source:t,person:e.person,idMap:k,pathMap:S}),C=await et(r,e.run_id,q);C>0&&(c.inserted.revisions=(c.inserted.revisions??0)+C),await We(r,p,e.run_id,t);const A=await Fe({db:r,blobs:n,runId:e.run_id,person:e.person,objectMap:k.object});for(const[z,Q]of Object.entries(A.inserted))c.inserted[z]=Q.length;return P.push(...A.unresolvedPlugins),await r.prepare("UPDATE import_runs SET counts_json = ?, loaded_at = COALESCE(loaded_at, ?) WHERE run_id = ?").run(JSON.stringify({...xe(m,c),unresolved_plugins:P,refused_plugins:T}),R(),e.run_id),c}),w=!0,await a.atStep?.("committed")}await o("verify");const y=await Le(i,e.run_id,p,u,b,t.installId);if(await i.prepare("UPDATE import_runs SET verify_json = ? WHERE run_id = ?").run(JSON.stringify(y),e.run_id),!y.ok)throw new g("verify","verify_failed","the committed rows differ from the staged rows or an invariant failed",{differences:y.differences,invariants:y.invariants});await o("manifest");const O=M.manifest(e.run_id);await n.put(O,await tt(e.run_id)),await W(i,e.run_id);for(const m of He(e.run_id))await n.delete(m);await Se(n,e.run_id),await D(async m=>{await Ue(m,e.run_id,e.person),await m.prepare("UPDATE import_runs SET state = 'done', step = 'done', manifest_key = ?, finished_at = ? WHERE run_id = ?").run(O,R(),e.run_id)})}catch(t){if(t instanceof Ye)throw t;const u=Ze(t,d);$e({level:"error",event:"import.run.failed",error:t,fields:{run_id:e.run_id,step:u.step,code:u.code}}),await W(i,e.run_id).catch(()=>{}),w||await Ee(n,f,!0),await i.prepare("UPDATE import_runs SET state = 'failed', failure_json = ?, finished_at = ? WHERE run_id = ?").run(JSON.stringify(u),R(),e.run_id),await ve(n,e.run_id,{keepNodeFiles:w,bestEffort:!0})}}l(It,"processRun");function Ze(e,s){if(e instanceof g)return{step:e.step,code:e.code,message:e.message,...e.detail===void 0?{}:{detail:e.detail}};const a=e.code;return{step:s,code:typeof a=="string"?a:"import_failed",message:e instanceof Error?e.message:String(e)}}l(Ze,"failureOf");function h(e,s,a){(e[s]??={staged:0,inserted:0,mapped:0,dropped:0}).dropped+=a}l(h,"addDropped");function xe(e,s){for(const[a,n]of Object.entries(s.inserted))(e[a]??={staged:0,inserted:0,mapped:0,dropped:0}).inserted=n;for(const[a,n]of Object.entries(s.mapped))(e[a]??={staged:0,inserted:0,mapped:0,dropped:0}).mapped=n;return e}l(xe,"withInserted");async function et(e,s,a){const n=new Set((await e.prepareUncached("SELECT rev_id FROM revisions WHERE rev_id IN (SELECT jsonb_array_elements_text(?::jsonb))").all(JSON.stringify(a.map(d=>d.rev_id)))).map(d=>d.rev_id)),i=a.filter(d=>!n.has(d.rev_id)),p=new Map;for(const d of a)p.set(d.document,[...p.get(d.document)??[],d]);for(const[d,o]of p){const w=await te(e,d);w!==null&&await ee(e,w,o.map(f=>({rev_id:f.rev_id,parents:f.parents,body_hash:f.body_hash,rationale:f.rationale,created_at:f.created_at})))}return await K(e,s,"revisions",i.map(d=>[d.rev_id])),await K(e,s,"revision_parents",i.flatMap(d=>d.parents.map(o=>[d.rev_id,o]))),i.length}l(et,"arrive");async function K(e,s,a,n){if(n.length===0)return;const i=await e.prepare("SELECT inserted_keys FROM import_manifest WHERE run_id = ? AND table_name = ?").get(s,a);i===void 0?await e.prepare("INSERT INTO import_manifest (run_id, table_name, inserted_keys) VALUES (?, ?, ?)").run(s,a,B(n)):await e.prepare("UPDATE import_manifest SET inserted_keys = ? WHERE run_id = ? AND table_name = ?").run(B([...L(i.inserted_keys),...n]),s,a)}l(K,"appendManifest");async function tt(e){const a=await(await v()).prepare("SELECT table_name, inserted_keys FROM import_manifest WHERE run_id = ? ORDER BY table_name").all(e);return X(Buffer.from(a.map(n=>JSON.stringify({table:n.table_name,keys:L(n.inserted_keys)})).join(`
1
+ var X=Object.defineProperty;var l=(e,s)=>X(e,"name",{value:s,configurable:!0});import{zstdCompressSync as Z}from"node:zlib";import{blobStore as x}from"../../blobs/index.js";import{openDb as v,withCanvasWrite as D}from"../../canvas/db.js";import{runAsPerson as M}from"../../canvas/person.js";import{insertImportedRevisions as ee}from"../../graph/documents.js";import{getById as te}from"../../graph/objects.js";import{bundleKeys as N,decodeRows as ne,rowKeys as L,SEQ_TABLES as ae}from"../bundle/layout.js";import{readCatalog as ie}from"./catalog.js";import{copyRows as se,decodeKeys as B,encodeKeys as W}from"./copy.js";import{pruneStaged as re,precheck as oe,renameClashingLegacyCharges as de,renameClashingProfiles as pe,rewriteConversationHeaders as ue,rewritePaths as ce,rewriteRequestPaths as le,takeRepoSyncedDocuments as fe}from"./prepare.js";import{boundSub as me,dropRefusedMessages as _e,checkSourcePerson as we,checkStagedBlobKeys as ge,checkStagedPersons as be,checkStagedReferences as he,checkStagedRequestKeys as ye}from"./bind.js";import{deleteBlobs as Ee,deleteRunBlobs as Se,deleteRunPrefix as ve,moveRunBlobs as Re}from"./blobs.js";import{dropStubRows as Ie,findFleetGrant as Oe,grantMissing as Pe,mapProfileIds as Te,renameClashingRepos as je,rewriteIds as ke,rewritePerson as Ce,scopeRepoIdentities as Ae}from"./rewrite.js";import{dropStaging as H,ImportLaneError as g,stage as De,stagingSchema as Me,targetSchema as Ne}from"./stage.js";import{verifyRun as Le}from"./verify.js";import{sandboxPathMap as Be,writeNodeFiles as We}from"./path-map.js";import{allStoreKeys as He,readPluginsStore as Ke,recordImportedActivations as Ue,writeStores as Fe}from"./stores.js";import{openImportGrants as Je}from"./open-grants.js";import{publishImportedPlugins as Ge}from"./publish-plugins.js";import{COPIED_TABLES as qe}from"../bundle/layout.js";import{emitEvent as $e}from"../../events/emit.js";import{ClaimLostError as Ye}from"../../../daemon/reconcilers/row-claim.js";const ze=10*6e4,Qe=30*6e4,R=l(()=>new Date().toISOString(),"now"),K=l(async(e,s)=>{await(await v()).prepare("UPDATE import_runs SET step = ? WHERE run_id = ?").run(s,e)},"setStep");async function Ve(e,s){const a=await e.get(N.source(s));if(a===null)throw new g("stage","bundle_invalid","source.json is missing");const n=JSON.parse(a.toString("utf8"));if(typeof n.rowParts!="object"||n.rowParts===null)throw new g("stage","bundle_invalid","source.json names no row parts");return n}l(Ve,"readSource");async function Xe(e,s,a,n,i,p,d){const o=[];for(const t of L(a.run_id,"grants",n)){const u=await e.get(t);if(u===null)throw new g("stage","bundle_invalid",`row file ${t} is missing`);o.push(...ne(u))}if(o.length===0)return;const w=o.map(t=>({sub:me(t.sub,n.person,a.person,"grants.sub"),grantee:t.grantee}));await d(a.run_id);const f=[];for(const t of w)await Oe(s,i,p,t.sub,t.grantee)===void 0&&f.push(t.grantee);if(f.length>0)throw Pe(f)}l(Xe,"ensureGrants");async function It(e,s,a={}){const n=a.blobs??await x(),i=await v(),p=Me(e.run_id);let d="start";const o=l(async t=>{d=t,await s.assertOwned(),await K(e.run_id,t),await a.atStep?.(t)},"at");let w=e.state==="committed";const f=[];try{const t=await Ve(n,e.run_id);if(e.source_kind==="machine"&&t.installId!==e.source_install_id)throw new g("stage","bundle_invalid",`source.json names install ${t.installId}, the run is for ${e.source_install_id}`);t.installId=e.source_install_id;const u=await Ne(i),I=[...qe],b=await ie(i,u,[...I,"grants"]);if(!w){const m={},P=[],T=[],j=a.fleetRuntime??process.env.CRTR_RUNTIME??null;await we(i,u,t.person,e.person),await o("open-grants"),await Xe(n,i,e,t,u,j,a.openGrants??Je),await o("publish-plugins");const F=await Ke(n,e.run_id),E=await M(e.person,()=>Ge(F));if(E.unavailable.length>0){if(e.loaded_at===void 0||e.loaded_at===null)throw new g("publish-plugins","import_failed","a loading run has no loaded_at");if(Date.now()-Date.parse(e.loaded_at)>=ze)throw new g("publish-plugins","directory_unavailable",`the directory did not answer for: ${E.unavailable.slice(0,10).join(", ")}; rerun the import once it is reachable`,{plugins:E.unavailable});await s.assertOwned(),await K(e.run_id,"waiting_for_directory");return}T.push(...E.refused),await o("stage");const J=await De(i,e.run_id,t.counts,r=>L(e.run_id,r,t),r=>n.get(r));for(const[r,c]of Object.entries(J))m[r]={staged:c,inserted:0,mapped:0,dropped:0};const _={db:i,schema:p,target:u,catalog:b,sourcePerson:t.person,targetPerson:e.person,fleetRuntime:j,shippedBodies:t.shippedBodies??{}};await o("bind-staged");for(const[r,c]of Object.entries(await be(_)))h(m,r,c);for(const[r,c]of Object.entries(await ge(_)))h(m,r,c);await o("rewrite-person"),await Ce(_),await Ae(_),await o("prune");const G=await re(i,p,b,t),S=t.kind==="hosted"?Be(t.pathPrefixes??[]):[];await o("rewrite-paths"),await ce(i,p,S),await ue(i,p,S,n,e.run_id),await le(i,p),await ye(_);const q=await Te(_);await pe(i,p,u,t.installId,e.person),await o("rewrite-ids");const k=await ke(_,q);await o("drop");const $=await fe(i,p,u),Y=await Ie(_);for(const[r,c]of Object.entries({...G}))h(m,r,c);for(const[r,c]of Object.entries(Y))h(m,r,c);for(const[r,c]of Object.entries(await _e(_,{installId:t.installId,person:e.person,runId:e.run_id})))h(m,r,c);await he(_,{installId:t.installId,person:e.person,runId:e.run_id}),await je(_),await de(i,p,u,t.installId),await o("pre-check");const z=new Map([["messages",["seq"]],...ae.map(r=>[r,["seq"]])]);await oe(i,p,u,b,I,new Set,z),await o("blobs"),await Re(i,p,u,e.person,n,e.run_id,f),await o("copy"),await M(e.person,()=>D(async r=>{await s.assertOwned({extendLeaseMs:Qe});const c=await se({db:r,runId:e.run_id,schema:p,target:u,catalog:b,source:t,person:e.person,idMap:k,pathMap:S}),C=await et(r,e.run_id,$);C>0&&(c.inserted.revisions=(c.inserted.revisions??0)+C),await We(r,p,e.run_id,t);const A=await Fe({db:r,blobs:n,runId:e.run_id,person:e.person,objectMap:k.object});for(const[Q,V]of Object.entries(A.inserted))c.inserted[Q]=V.length;return P.push(...A.unresolvedPlugins),await r.prepare("UPDATE import_runs SET counts_json = ?, loaded_at = COALESCE(loaded_at, ?) WHERE run_id = ?").run(JSON.stringify({...xe(m,c),unresolved_plugins:P,refused_plugins:T}),R(),e.run_id),c})),w=!0,await a.atStep?.("committed")}await o("verify");const y=await Le(i,e.run_id,p,u,b,t.installId);if(await i.prepare("UPDATE import_runs SET verify_json = ? WHERE run_id = ?").run(JSON.stringify(y),e.run_id),!y.ok)throw new g("verify","verify_failed","the committed rows differ from the staged rows or an invariant failed",{differences:y.differences,invariants:y.invariants});await o("manifest");const O=N.manifest(e.run_id);await n.put(O,await tt(e.run_id)),await H(i,e.run_id);for(const m of He(e.run_id))await n.delete(m);await Se(n,e.run_id),await D(async m=>{await Ue(m,e.run_id,e.person),await m.prepare("UPDATE import_runs SET state = 'done', step = 'done', manifest_key = ?, finished_at = ? WHERE run_id = ?").run(O,R(),e.run_id)})}catch(t){if(t instanceof Ye)throw t;const u=Ze(t,d);$e({level:"error",event:"import.run.failed",error:t,fields:{run_id:e.run_id,step:u.step,code:u.code}}),await H(i,e.run_id).catch(()=>{}),w||await Ee(n,f,!0),await i.prepare("UPDATE import_runs SET state = 'failed', failure_json = ?, finished_at = ? WHERE run_id = ?").run(JSON.stringify(u),R(),e.run_id),await ve(n,e.run_id,{keepNodeFiles:w,bestEffort:!0})}}l(It,"processRun");function Ze(e,s){if(e instanceof g)return{step:e.step,code:e.code,message:e.message,...e.detail===void 0?{}:{detail:e.detail}};const a=e.code;return{step:s,code:typeof a=="string"?a:"import_failed",message:e instanceof Error?e.message:String(e)}}l(Ze,"failureOf");function h(e,s,a){(e[s]??={staged:0,inserted:0,mapped:0,dropped:0}).dropped+=a}l(h,"addDropped");function xe(e,s){for(const[a,n]of Object.entries(s.inserted))(e[a]??={staged:0,inserted:0,mapped:0,dropped:0}).inserted=n;for(const[a,n]of Object.entries(s.mapped))(e[a]??={staged:0,inserted:0,mapped:0,dropped:0}).mapped=n;return e}l(xe,"withInserted");async function et(e,s,a){const n=new Set((await e.prepareUncached("SELECT rev_id FROM revisions WHERE rev_id IN (SELECT jsonb_array_elements_text(?::jsonb))").all(JSON.stringify(a.map(d=>d.rev_id)))).map(d=>d.rev_id)),i=a.filter(d=>!n.has(d.rev_id)),p=new Map;for(const d of a)p.set(d.document,[...p.get(d.document)??[],d]);for(const[d,o]of p){const w=await te(e,d);w!==null&&await ee(e,w,o.map(f=>({rev_id:f.rev_id,parents:f.parents,body_hash:f.body_hash,rationale:f.rationale,created_at:f.created_at})))}return await U(e,s,"revisions",i.map(d=>[d.rev_id])),await U(e,s,"revision_parents",i.flatMap(d=>d.parents.map(o=>[d.rev_id,o]))),i.length}l(et,"arrive");async function U(e,s,a,n){if(n.length===0)return;const i=await e.prepare("SELECT inserted_keys FROM import_manifest WHERE run_id = ? AND table_name = ?").get(s,a);i===void 0?await e.prepare("INSERT INTO import_manifest (run_id, table_name, inserted_keys) VALUES (?, ?, ?)").run(s,a,W(n)):await e.prepare("UPDATE import_manifest SET inserted_keys = ? WHERE run_id = ? AND table_name = ?").run(W([...B(i.inserted_keys),...n]),s,a)}l(U,"appendManifest");async function tt(e){const a=await(await v()).prepare("SELECT table_name, inserted_keys FROM import_manifest WHERE run_id = ? ORDER BY table_name").all(e);return Z(Buffer.from(a.map(n=>JSON.stringify({table:n.table_name,keys:B(n.inserted_keys)})).join(`
2
2
  `)+`
3
3
  `))}l(tt,"manifestFile");export{Qe as COPY_LEASE_MS,ze as GRANT_WAIT_MS,It as processRun};
@@ -83,5 +83,7 @@ export interface BlaxelClient {
83
83
  /** Creates (or adopts) a private preview on `port` and returns its URL. */
84
84
  ensurePreview(sandboxName: string, previewName: string, port: number): Promise<string>;
85
85
  createPreviewToken(sandboxName: string, previewName: string, expiresAt: Date): Promise<PreviewToken>;
86
+ /** Deleting an absent preview (or one of an absent sandbox) is not an error. */
87
+ deletePreview(sandboxName: string, previewName: string): Promise<void>;
86
88
  }
87
89
  export declare function createBlaxelClient(config: BlaxelConfig): BlaxelClient;
@@ -1 +1 @@
1
- var $=Object.defineProperty;var p=(t,i)=>$(t,"name",{value:i,configurable:!0});function b(t=process.env){const i=p(a=>{const u=t[a];if(!u)throw new Error(`${a} is required for the Blaxel runner`);return u},"need");return{apiKey:i("BLAXEL_API_KEY"),workspace:i("BLAXEL_WORKSPACE"),region:i("BLAXEL_REGION")}}p(b,"blaxelConfigFromEnv");class w extends Error{static{p(this,"BlaxelApiError")}status;code;constructor(i,a,u){super(u),this.status=i,this.code=a,this.name="BlaxelApiError"}}const A=p(t=>t instanceof w&&t.status===404&&t.code==="WORKLOAD_UNAVAILABLE","isWorkloadUnavailable");function x(t){const i=t.metadata.url;if(!i)throw new Error(`Blaxel sandbox ${t.metadata.name} has no url`);return{name:t.metadata.name,url:i,state:t.state??null,status:t.status??null,image:t.spec?.runtime?.image??null}}p(x,"toInfo");function y(t,i){const a=t??{},u=typeof a.error=="object"&&a.error!==null?a.error:{},c=typeof u.code=="string"?u.code:typeof a.code=="string"?a.code:null,l=[u.message,a.message,a.error].find(e=>typeof e=="string")??i.slice(0,300);return{code:c,message:l}}p(y,"errorFields");function T(t){const i=t.fetch??fetch,a=t.controlUrl??"https://api.blaxel.ai/v0",u=p(()=>({authorization:`Bearer ${t.apiKey}`,"x-blaxel-workspace":t.workspace,"content-type":"application/json"}),"headers");async function c(e,s,o,r=[]){const n=await i(e,{method:s,headers:u(),...o===void 0?{}:{body:JSON.stringify(o)}}),f=await n.text();let d=null;if(f!=="")try{d=JSON.parse(f)}catch{d={raw:f}}if(!n.ok){const{code:m,message:E}=y(d,f);if(n.status===404&&m==="WORKLOAD_UNAVAILABLE"||!r.includes(n.status))throw new w(n.status,m,`Blaxel ${s} ${e} failed (${n.status}): ${E}`)}return{status:n.status,json:d}}p(c,"call");const l=encodeURIComponent;return{config:t,async createSandbox(e){const s=[...e.ports??[]].map(n=>({name:n.name,target:n.target,protocol:"HTTP"})),o={metadata:{name:e.name},spec:{runtime:{image:e.image,memory:e.memoryMb,...s.length>0?{ports:s}:{}},region:t.region,lifecycle:{expirationPolicies:[{type:"ttl-idle",value:"7d",action:"delete"}]}}},r=Date.now()+(t.deletingWaitMs??6e4);for(;;){const{status:n,json:f}=await c(`${a}/sandboxes`,"POST",o,[409]);if(n!==409)return{...x(f),created:!0};const d=await this.getSandbox(e.name);if(d!==null)return{...d,created:!1};if(Date.now()>=r)throw new Error(`Blaxel sandbox ${e.name} is still being deleted; its name did not free in time`);await new Promise(m=>setTimeout(m,1e3))}},async getSandbox(e){const{status:s,json:o}=await c(`${a}/sandboxes/${l(e)}`,"GET",void 0,[404]);if(s===404)return null;const r=o;return r.status==="DELETING"||r.status==="TERMINATED"?null:x(r)},async deleteSandbox(e){await c(`${a}/sandboxes/${l(e)}`,"DELETE",void 0,[404])},async startProcess(e,s){const{json:o}=await c(`${e.url}/process`,"POST",s);return o},async getProcess(e,s){const{status:o,json:r}=await c(`${e.url}/process/${l(s)}`,"GET",void 0,[404]);return o===404?null:r},async stopProcess(e,s){await c(`${e.url}/process/${l(s)}`,"DELETE",void 0,[404])},async killProcess(e,s){await c(`${e.url}/process/${l(s)}/kill`,"DELETE",void 0,[404])},async exec(e,s,o,r,n){return await this.startProcess(e,{name:s,command:o,waitForCompletion:!0,timeout:r,...n?{env:n}:{}})},async putFile(e,s,o,r="0644"){await c(`${e.url}/filesystem/${s.replace(/^\/+/,"").split("/").map(l).join("/")}`,"PUT",{content:o,permissions:r})},async ensurePreview(e,s,o){const{json:r}=await c(`${a}/sandboxes/${l(e)}/previews`,"POST",{metadata:{name:s},spec:{port:o,public:!1}},[409]),n=r?.spec?.url;if(n)return n;const d=(await c(`${a}/sandboxes/${l(e)}/previews`,"GET")).json.find(m=>m.metadata.name===s);if(!d)throw new Error(`Blaxel preview ${s} of ${e} not found`);return d.spec.url},async createPreviewToken(e,s,o){const{json:r}=await c(`${a}/sandboxes/${l(e)}/previews/${l(s)}/tokens`,"POST",{spec:{expiresAt:o.toISOString()}}),n=r.spec;return{token:n.token,expiresAt:n.expiresAt}}}}p(T,"createBlaxelClient");export{w as BlaxelApiError,b as blaxelConfigFromEnv,T as createBlaxelClient,A as isWorkloadUnavailable};
1
+ var $=Object.defineProperty;var p=(s,i)=>$(s,"name",{value:i,configurable:!0});function h(s=process.env){const i=p(a=>{const u=s[a];if(!u)throw new Error(`${a} is required for the Blaxel runner`);return u},"need");return{apiKey:i("BLAXEL_API_KEY"),workspace:i("BLAXEL_WORKSPACE"),region:i("BLAXEL_REGION")}}p(h,"blaxelConfigFromEnv");class m extends Error{static{p(this,"BlaxelApiError")}status;code;constructor(i,a,u){super(u),this.status=i,this.code=a,this.name="BlaxelApiError"}}const A=p(s=>s instanceof m&&s.status===404&&s.code==="WORKLOAD_UNAVAILABLE","isWorkloadUnavailable");function x(s){const i=s.metadata.url;if(!i)throw new Error(`Blaxel sandbox ${s.metadata.name} has no url`);return{name:s.metadata.name,url:i,state:s.state??null,status:s.status??null,image:s.spec?.runtime?.image??null}}p(x,"toInfo");function y(s,i){const a=s??{},u=typeof a.error=="object"&&a.error!==null?a.error:{},c=typeof u.code=="string"?u.code:typeof a.code=="string"?a.code:null,l=[u.message,a.message,a.error].find(e=>typeof e=="string")??i.slice(0,300);return{code:c,message:l}}p(y,"errorFields");function T(s){const i=s.fetch??fetch,a=s.controlUrl??"https://api.blaxel.ai/v0",u=p(()=>({authorization:`Bearer ${s.apiKey}`,"x-blaxel-workspace":s.workspace,"content-type":"application/json"}),"headers");async function c(e,t,o,r=[]){const n=await i(e,{method:t,headers:u(),...o===void 0?{}:{body:JSON.stringify(o)}}),f=await n.text();let d=null;if(f!=="")try{d=JSON.parse(f)}catch{d={raw:f}}if(!n.ok){const{code:w,message:E}=y(d,f);if(n.status===404&&w==="WORKLOAD_UNAVAILABLE"||!r.includes(n.status))throw new m(n.status,w,`Blaxel ${t} ${e} failed (${n.status}): ${E}`)}return{status:n.status,json:d}}p(c,"call");const l=encodeURIComponent;return{config:s,async createSandbox(e){const t=[...e.ports??[]].map(n=>({name:n.name,target:n.target,protocol:"HTTP"})),o={metadata:{name:e.name},spec:{runtime:{image:e.image,memory:e.memoryMb,...t.length>0?{ports:t}:{}},region:s.region,lifecycle:{expirationPolicies:[{type:"ttl-idle",value:"7d",action:"delete"}]}}},r=Date.now()+(s.deletingWaitMs??6e4);for(;;){const{status:n,json:f}=await c(`${a}/sandboxes`,"POST",o,[409]);if(n!==409)return{...x(f),created:!0};const d=await this.getSandbox(e.name);if(d!==null)return{...d,created:!1};if(Date.now()>=r)throw new Error(`Blaxel sandbox ${e.name} is still being deleted; its name did not free in time`);await new Promise(w=>setTimeout(w,1e3))}},async getSandbox(e){const{status:t,json:o}=await c(`${a}/sandboxes/${l(e)}`,"GET",void 0,[404]);if(t===404)return null;const r=o;return r.status==="DELETING"||r.status==="TERMINATED"?null:x(r)},async deleteSandbox(e){await c(`${a}/sandboxes/${l(e)}`,"DELETE",void 0,[404])},async startProcess(e,t){const{json:o}=await c(`${e.url}/process`,"POST",t);return o},async getProcess(e,t){const{status:o,json:r}=await c(`${e.url}/process/${l(t)}`,"GET",void 0,[404]);return o===404?null:r},async stopProcess(e,t){await c(`${e.url}/process/${l(t)}`,"DELETE",void 0,[404])},async killProcess(e,t){await c(`${e.url}/process/${l(t)}/kill`,"DELETE",void 0,[404])},async exec(e,t,o,r,n){return await this.startProcess(e,{name:t,command:o,waitForCompletion:!0,timeout:r,...n?{env:n}:{}})},async putFile(e,t,o,r="0644"){await c(`${e.url}/filesystem/${t.replace(/^\/+/,"").split("/").map(l).join("/")}`,"PUT",{content:o,permissions:r})},async ensurePreview(e,t,o){const{json:r}=await c(`${a}/sandboxes/${l(e)}/previews`,"POST",{metadata:{name:t},spec:{port:o,public:!1}},[409]),n=r?.spec?.url;if(n)return n;const d=(await c(`${a}/sandboxes/${l(e)}/previews`,"GET")).json.find(w=>w.metadata.name===t);if(!d)throw new Error(`Blaxel preview ${t} of ${e} not found`);return d.spec.url},async createPreviewToken(e,t,o){const{json:r}=await c(`${a}/sandboxes/${l(e)}/previews/${l(t)}/tokens`,"POST",{spec:{expiresAt:o.toISOString()}}),n=r.spec;return{token:n.token,expiresAt:n.expiresAt}},async deletePreview(e,t){await c(`${a}/sandboxes/${l(e)}/previews/${l(t)}`,"DELETE",void 0,[404])}}}p(T,"createBlaxelClient");export{m as BlaxelApiError,h as blaxelConfigFromEnv,T as createBlaxelClient,A as isWorkloadUnavailable};
@@ -1,3 +1,3 @@
1
- var h=Object.defineProperty;var c=(a,n)=>h(a,"name",{value:n,configurable:!0});import{mintExecutionToken as S}from"../../../canvas/node-tokens.js";import{BlaxelApiError as P,isWorkloadUnavailable as R}from"./client.js";const b=4180,p="view",T="node /opt/crtr/current/scripts/sandbox-start.mjs --wake",O=3,I=/^crtr-sandbox-start: failed (\S+)/m,A=2e3,E=c(a=>`broker-${a}`,"brokerProcessName"),l=c(a=>a,"sandboxNameFor"),_=c(a=>`cron-${a}`,"cronProcessName"),y=2e3,$="crtr",N="/opt/crtr/current/bin";function v(a){const n=`${a.logs}
1
+ var h=Object.defineProperty;var c=(a,n)=>h(a,"name",{value:n,configurable:!0});import{mintExecutionToken as P}from"../../../canvas/node-tokens.js";import{BlaxelApiError as S,isWorkloadUnavailable as R}from"./client.js";const b=4180,u="view",T="node /opt/crtr/current/scripts/sandbox-start.mjs --wake",O=3,A=/^crtr-sandbox-start: failed (\S+)/m,I=2e3,E=c(a=>`broker-${a}`,"brokerProcessName"),l=c(a=>a,"sandboxNameFor"),_=c(a=>`cron-${a}`,"cronProcessName"),y=2e3,$="crtr",v="/opt/crtr/current/bin";function N(a){const n=`${a.logs}
2
2
  ${a.stderr}
3
- ${a.stdout}`,u=(a.stderr||a.logs||a.stdout||"").trim().slice(-A);return{state:"failed",reason:I.exec(n)?.[1]??"start_failed",code:a.exitCode,...u===""?{}:{output:u}}}c(v,"failureOf");function U(a){const{client:n}=a,u=(a.stopGraceS??10)*1e3,f=new Map;async function x(t){return await n.getSandbox(l(t.nodeId))}c(x,"sandboxOf");async function k(t,r){if(!/^[A-Za-z0-9_-]+$/.test(r))throw new Error(`execution id ${JSON.stringify(r)} is not safe to name in a command`);const e=Math.max(1,Math.ceil(u/1e3)),o=`p='[b]roker-cli\\.js .*--epoch ${r}( |$)'; pkill -TERM -f "$p"; i=0; while pgrep -f "$p" >/dev/null && [ $i -lt ${e*5} ]; do sleep 0.2; i=$((i+1)); done; pkill -KILL -f "$p"; sleep 0.3; ! pgrep -f "$p"`;return(await n.exec(t,`stop-${r}-${Date.now()}`,o,e+20)).exitCode===0}return c(k,"brokerGone"),{kind:"blaxel",async start(t){const r=await a.launchContext(t),e=l(t.nodeId),o={name:e,image:r.image,memoryMb:r.memoryMb,ports:[{name:p,target:b}]};let i=await n.createSandbox(o);i.image!==r.image&&(await n.deleteSandbox(e),f.delete(e),i=await n.createSandbox(o));const d=E(t.executionId);if((await n.getProcess(i,d))?.status==="running")return{pid:null,exited:null};await n.ensurePreview(e,p,b);const g=await(a.mintToken??(m=>S(m.executionId,m.nodeId)))(t),w={...r.secrets,CRTR_API_URL:r.apiUrl,CRTR_EXECUTION_ID:t.executionId,CRTR_NODE_TOKEN:g,CRTR_RELEASE:t.release,CRTR_RELEASE_URL:r.releaseUrl,CRTR_RELEASE_SHA256:r.releaseSha256};return await n.startProcess(i,{name:d,command:a.bootstrap(),env:w,waitForCompletion:!1}),{pid:null,exited:null}},async wake(t){const r=await x(t);if(r===null)return"no_broker";try{const e=await n.exec(r,`wake-${t.executionId}-${Date.now()}`,`${T} ${t.executionId}`,30);if(e.exitCode===0)return"signalled";if(e.exitCode===O)return"no_broker";throw new Error(`wake of ${t.executionId} failed (exit ${e.exitCode}): ${(e.stderr||e.logs).slice(0,300)}`)}catch(e){if(R(e))return"no_broker";throw e}},async stop(t,r){try{const e=await x(t);if(e===null)return{confirmed:!0};const o=E(t.executionId),i=c(async()=>(await n.getProcess(e,o))?.status==="running","running");if(await i()){await n.stopProcess(e,o);const d=Date.now()+u;for(;Date.now()<d&&await i();)await new Promise(s=>setTimeout(s,250));if(await i()&&await n.killProcess(e,o),await i())return{confirmed:!1}}return{confirmed:await k(e,t.executionId)}}catch(e){return R(e)?{confirmed:!0}:{confirmed:!1,error:e instanceof Error?e:new Error(String(e))}}},async status(t,r){try{const e=await x(t);if(e===null)return{state:"gone"};if(r?.idle===!0)return{state:"running",pid:null};const o=await n.getProcess(e,E(t.executionId));return o===null?{state:"gone"}:o.status==="running"?{state:"running",pid:null}:o.status==="failed"||o.status==="completed"&&o.exitCode!==0?v(o):{state:"gone"}}catch(e){return R(e)?{state:"gone"}:{state:"unknown",error:e instanceof Error?e.message:String(e)}}},async delete(t){await n.deleteSandbox(l(t)),f.delete(l(t))},async viewerAddress(t){const r=l(t.nodeId),e=f.get(r);if(e&&e.expiresAt-Date.now()>5*6e4)return C(e.url,e.token);const o=await n.ensurePreview(r,p,b),i=new Date(Date.now()+60*6e4),{token:d}=await n.createPreviewToken(r,p,i);return f.set(r,{url:o,token:d,expiresAt:i.getTime()}),C(o,d)},async cronRun(t,r){const e=await n.getSandbox(l(t));if(e===null)throw new Error(`node ${t} has no sandbox, so the cron cannot run; the scheduler never starts a node to get one`);const o=_(r.runId),i=`exec nsenter -S "$(id -u ${$})" -G "$(id -g ${$})" bash -c "$CRTR_CRON_COMMAND"`,d={...r.env,CRTR_CRON_COMMAND:r.command,PATH:`${N}:/usr/local/bin:/usr/bin:/bin`};let s=await n.getProcess(e,o)??await n.startProcess(e,{name:o,command:i,workingDir:r.cwd,env:d,waitForCompletion:!1});const g=r.startedAtMs+r.timeoutS*1e3;for(;s.status==="running";){if(Date.now()>=g)return await n.killProcess(e,o),{exitCode:null,timedOut:!0,stdout:s.stdout,stderr:s.stderr};await new Promise(m=>setTimeout(m,y));let w;try{w=await n.getProcess(e,o)}catch{continue}if(w===null)return{exitCode:null,timedOut:!1,stdout:s.stdout,stderr:s.stderr,error:`process ${o} is gone from the sandbox, so its outcome is unknown`};s=w}return s.status==="completed"||s.status==="failed"?{exitCode:s.exitCode,timedOut:!1,stdout:s.stdout,stderr:s.stderr}:{exitCode:null,timedOut:!1,stdout:s.stdout,stderr:s.stderr,error:`process ${o} was ${s.status} from outside the run`}},async cronCancel(t,r){const e=await n.getSandbox(l(t));e!==null&&await n.killProcess(e,_(r))},async sandboxState(t){return(await x(t))?.state??null}}}c(U,"createBlaxelRunner");function C(a,n){return{kind:"wss",url:`${a.replace(/^https:/,"wss:")}/view`,headers:{"x-blaxel-preview-token":n}}}c(C,"viewer");export{b as BROKER_VIEW_PORT,P as BlaxelApiError,O as EXIT_NO_BROKER,I as FAILURE_LINE,T as WAKE_COMMAND,E as brokerProcessName,U as createBlaxelRunner,_ as cronProcessName,l as sandboxNameFor};
3
+ ${a.stdout}`,w=(a.stderr||a.logs||a.stdout||"").trim().slice(-I);return{state:"failed",reason:A.exec(n)?.[1]??"start_failed",code:a.exitCode,...w===""?{}:{output:w}}}c(N,"failureOf");function U(a){const{client:n}=a,w=(a.stopGraceS??10)*1e3,x=new Map;async function m(t){return await n.getSandbox(l(t.nodeId))}c(m,"sandboxOf");async function k(t,r){if(!/^[A-Za-z0-9_-]+$/.test(r))throw new Error(`execution id ${JSON.stringify(r)} is not safe to name in a command`);const e=Math.max(1,Math.ceil(w/1e3)),o=`p='[b]roker-cli\\.js .*--epoch ${r}( |$)'; pkill -TERM -f "$p"; i=0; while pgrep -f "$p" >/dev/null && [ $i -lt ${e*5} ]; do sleep 0.2; i=$((i+1)); done; pkill -KILL -f "$p"; sleep 0.3; ! pgrep -f "$p"`;return(await n.exec(t,`stop-${r}-${Date.now()}`,o,e+20)).exitCode===0}return c(k,"brokerGone"),{kind:"blaxel",async start(t){const r=await a.launchContext(t),e=l(t.nodeId),o={name:e,image:r.image,memoryMb:r.memoryMb,ports:[{name:u,target:b}]};let i=await n.createSandbox(o);i.image!==r.image&&(await n.deletePreview(e,u),await n.deleteSandbox(e),x.delete(e),i=await n.createSandbox(o));const d=E(t.executionId);if((await n.getProcess(i,d))?.status==="running")return{pid:null,exited:null};await n.ensurePreview(e,u,b);const g=await(a.mintToken??(p=>P(p.executionId,p.nodeId)))(t),f={...r.secrets,CRTR_API_URL:r.apiUrl,CRTR_EXECUTION_ID:t.executionId,CRTR_NODE_TOKEN:g,CRTR_RELEASE:t.release,CRTR_RELEASE_URL:r.releaseUrl,CRTR_RELEASE_SHA256:r.releaseSha256};return await n.startProcess(i,{name:d,command:a.bootstrap(),env:f,waitForCompletion:!1}),{pid:null,exited:null}},async wake(t){const r=await m(t);if(r===null)return"no_broker";try{const e=await n.exec(r,`wake-${t.executionId}-${Date.now()}`,`${T} ${t.executionId}`,30);if(e.exitCode===0)return"signalled";if(e.exitCode===O)return"no_broker";throw new Error(`wake of ${t.executionId} failed (exit ${e.exitCode}): ${(e.stderr||e.logs).slice(0,300)}`)}catch(e){if(R(e))return"no_broker";throw e}},async stop(t,r){try{const e=await m(t);if(e===null)return{confirmed:!0};const o=E(t.executionId),i=c(async()=>(await n.getProcess(e,o))?.status==="running","running");if(await i()){await n.stopProcess(e,o);const d=Date.now()+w;for(;Date.now()<d&&await i();)await new Promise(s=>setTimeout(s,250));if(await i()&&await n.killProcess(e,o),await i())return{confirmed:!1}}return{confirmed:await k(e,t.executionId)}}catch(e){return R(e)?{confirmed:!0}:{confirmed:!1,error:e instanceof Error?e:new Error(String(e))}}},async status(t,r){try{const e=await m(t);if(e===null)return{state:"gone"};if(r?.idle===!0)return{state:"running",pid:null};const o=await n.getProcess(e,E(t.executionId));return o===null?{state:"gone"}:o.status==="running"?{state:"running",pid:null}:o.status==="failed"||o.status==="completed"&&o.exitCode!==0?N(o):{state:"gone"}}catch(e){return R(e)?{state:"gone"}:{state:"unknown",error:e instanceof Error?e.message:String(e)}}},async delete(t){await n.deletePreview(l(t),u),await n.deleteSandbox(l(t)),x.delete(l(t))},async viewerAddress(t){const r=l(t.nodeId),e=x.get(r);if(e&&e.expiresAt-Date.now()>5*6e4)return C(e.url,e.token);const o=await n.ensurePreview(r,u,b),i=new Date(Date.now()+60*6e4),{token:d}=await n.createPreviewToken(r,u,i);return x.set(r,{url:o,token:d,expiresAt:i.getTime()}),C(o,d)},async cronRun(t,r){const e=await n.getSandbox(l(t));if(e===null)throw new Error(`node ${t} has no sandbox, so the cron cannot run; the scheduler never starts a node to get one`);const o=_(r.runId),i=`exec nsenter -S "$(id -u ${$})" -G "$(id -g ${$})" bash -c "$CRTR_CRON_COMMAND"`,d={...r.env,CRTR_CRON_COMMAND:r.command,PATH:`${v}:/usr/local/bin:/usr/bin:/bin`};let s=await n.getProcess(e,o)??await n.startProcess(e,{name:o,command:i,workingDir:r.cwd,env:d,waitForCompletion:!1});const g=r.startedAtMs+r.timeoutS*1e3;for(;s.status==="running";){if(Date.now()>=g)return await n.killProcess(e,o),{exitCode:null,timedOut:!0,stdout:s.stdout,stderr:s.stderr};await new Promise(p=>setTimeout(p,y));let f;try{f=await n.getProcess(e,o)}catch{continue}if(f===null)return{exitCode:null,timedOut:!1,stdout:s.stdout,stderr:s.stderr,error:`process ${o} is gone from the sandbox, so its outcome is unknown`};s=f}return s.status==="completed"||s.status==="failed"?{exitCode:s.exitCode,timedOut:!1,stdout:s.stdout,stderr:s.stderr}:{exitCode:null,timedOut:!1,stdout:s.stdout,stderr:s.stderr,error:`process ${o} was ${s.status} from outside the run`}},async cronCancel(t,r){const e=await n.getSandbox(l(t));e!==null&&await n.killProcess(e,_(r))},async sandboxState(t){return(await m(t))?.state??null}}}c(U,"createBlaxelRunner");function C(a,n){return{kind:"wss",url:`${a.replace(/^https:/,"wss:")}/view`,headers:{"x-blaxel-preview-token":n}}}c(C,"viewer");export{b as BROKER_VIEW_PORT,S as BlaxelApiError,O as EXIT_NO_BROKER,A as FAILURE_LINE,T as WAKE_COMMAND,E as brokerProcessName,U as createBlaxelRunner,_ as cronProcessName,l as sandboxNameFor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.734",
3
+ "version": "0.3.736",
4
4
  "description": "crtr — agent runtime with memory, plugins, and marketplaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -158,8 +158,8 @@
158
158
  },
159
159
  "license": "UNLICENSED",
160
160
  "dependencies": {
161
- "@north-light/identity": "0.3.734",
162
- "@north-light/plugin": "0.3.734",
161
+ "@north-light/identity": "0.3.736",
162
+ "@north-light/plugin": "0.3.736",
163
163
  "@earendil-works/chord": "1.5.2",
164
164
  "@earendil-works/pi-agent-core": "1.5.2",
165
165
  "@earendil-works/pi-ai": "1.5.2",
@@ -143,5 +143,8 @@ export function createBlaxelClient(config) {
143
143
  const spec = json.spec;
144
144
  return { token: spec.token, expiresAt: spec.expiresAt };
145
145
  },
146
+ async deletePreview(sandboxName, previewName) {
147
+ await call(`${control}/sandboxes/${encodeName(sandboxName)}/previews/${encodeName(previewName)}`, 'DELETE', undefined, [404]);
148
+ },
146
149
  };
147
150
  }
@@ -56,6 +56,7 @@ export function createBlaxelRunner(deps) {
56
56
  // "Name taken" means an earlier start created it: the client adopts it, files and all. One on an older image is replaced.
57
57
  let sandbox = await client.createSandbox(spec);
58
58
  if (sandbox.image !== context.image) {
59
+ await client.deletePreview(name, VIEW_PREVIEW);
59
60
  await client.deleteSandbox(name);
60
61
  previewTokens.delete(name);
61
62
  sandbox = await client.createSandbox(spec);
@@ -145,6 +146,8 @@ export function createBlaxelRunner(deps) {
145
146
  }
146
147
  },
147
148
  async delete(nodeId) {
149
+ // Blaxel counts a preview against the account quota until the preview itself is deleted; deleting the sandbox alone leaks it.
150
+ await client.deletePreview(sandboxNameFor(nodeId), VIEW_PREVIEW);
148
151
  await client.deleteSandbox(sandboxNameFor(nodeId));
149
152
  previewTokens.delete(sandboxNameFor(nodeId));
150
153
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.734",
3
+ "version": "0.3.736",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.734",
3
+ "version": "0.3.736",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.734",
3
+ "version": "0.3.736",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
28
28
  },
29
29
  "dependencies": {
30
- "@north-light/api": "0.3.734",
31
- "@north-light/identity": "0.3.734"
30
+ "@north-light/api": "0.3.736",
31
+ "@north-light/identity": "0.3.736"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.734",
3
+ "version": "0.3.736",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.734",
9
+ "version": "0.3.736",
10
10
  "hasInstallScript": true,
11
11
  "license": "UNLICENSED",
12
12
  "workspaces": [
@@ -28,8 +28,8 @@
28
28
  "@milkdown/preset-gfm": "^7.22.3",
29
29
  "@milkdown/prose": "^7.22.3",
30
30
  "@milkdown/utils": "^7.22.3",
31
- "@north-light/identity": "0.3.734",
32
- "@north-light/plugin": "0.3.734",
31
+ "@north-light/identity": "0.3.736",
32
+ "@north-light/plugin": "0.3.736",
33
33
  "cron-parser": "^5.6.0",
34
34
  "esbuild": "0.28.2",
35
35
  "jose": "^6.2.12",
@@ -11902,17 +11902,17 @@
11902
11902
  },
11903
11903
  "packages/crouter-api": {
11904
11904
  "name": "@north-light/api",
11905
- "version": "0.3.734",
11905
+ "version": "0.3.736",
11906
11906
  "license": "UNLICENSED"
11907
11907
  },
11908
11908
  "packages/crouter-env-docker": {
11909
11909
  "name": "@north-light/env-docker",
11910
- "version": "0.3.734",
11910
+ "version": "0.3.736",
11911
11911
  "license": "UNLICENSED"
11912
11912
  },
11913
11913
  "packages/crouter-identity": {
11914
11914
  "name": "@north-light/identity",
11915
- "version": "0.3.734",
11915
+ "version": "0.3.736",
11916
11916
  "license": "UNLICENSED",
11917
11917
  "dependencies": {
11918
11918
  "jose": "^6.2.1"
@@ -11920,21 +11920,21 @@
11920
11920
  },
11921
11921
  "packages/crouter-plugin": {
11922
11922
  "name": "@north-light/plugin",
11923
- "version": "0.3.734",
11923
+ "version": "0.3.736",
11924
11924
  "license": "UNLICENSED",
11925
11925
  "dependencies": {
11926
- "@north-light/api": "0.3.734",
11927
- "@north-light/identity": "0.3.734"
11926
+ "@north-light/api": "0.3.736",
11927
+ "@north-light/identity": "0.3.736"
11928
11928
  }
11929
11929
  },
11930
11930
  "packages/crouter-sdk": {
11931
11931
  "name": "@north-light/sdk",
11932
- "version": "0.3.734",
11932
+ "version": "0.3.736",
11933
11933
  "license": "UNLICENSED",
11934
11934
  "dependencies": {
11935
- "@north-light/api": "0.3.734",
11936
- "@north-light/identity": "0.3.734",
11937
- "@north-light/plugin": "0.3.734",
11935
+ "@north-light/api": "0.3.736",
11936
+ "@north-light/identity": "0.3.736",
11937
+ "@north-light/plugin": "0.3.736",
11938
11938
  "jose": "^6.2.1"
11939
11939
  },
11940
11940
  "bin": {