@north-light/cli 0.3.734 → 0.3.735
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/core/runtime/runner/blaxel/client.d.ts +2 -0
- package/dist/core/runtime/runner/blaxel/client.js +1 -1
- package/dist/core/runtime/runner/blaxel/runner.js +2 -2
- package/package.json +3 -3
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/client.js +3 -0
- package/packages/crouter-api/dist/core/runtime/runner/blaxel/runner.js +3 -0
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
|
@@ -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=(
|
|
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
|
|
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}`,
|
|
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.
|
|
3
|
+
"version": "0.3.735",
|
|
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.
|
|
162
|
-
"@north-light/plugin": "0.3.
|
|
161
|
+
"@north-light/identity": "0.3.735",
|
|
162
|
+
"@north-light/plugin": "0.3.735",
|
|
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.
|
|
3
|
+
"version": "0.3.735",
|
|
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/plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.735",
|
|
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.
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
30
|
+
"@north-light/api": "0.3.735",
|
|
31
|
+
"@north-light/identity": "0.3.735"
|
|
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.
|
|
3
|
+
"version": "0.3.735",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.735",
|
|
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.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.735",
|
|
32
|
+
"@north-light/plugin": "0.3.735",
|
|
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.
|
|
11905
|
+
"version": "0.3.735",
|
|
11906
11906
|
"license": "UNLICENSED"
|
|
11907
11907
|
},
|
|
11908
11908
|
"packages/crouter-env-docker": {
|
|
11909
11909
|
"name": "@north-light/env-docker",
|
|
11910
|
-
"version": "0.3.
|
|
11910
|
+
"version": "0.3.735",
|
|
11911
11911
|
"license": "UNLICENSED"
|
|
11912
11912
|
},
|
|
11913
11913
|
"packages/crouter-identity": {
|
|
11914
11914
|
"name": "@north-light/identity",
|
|
11915
|
-
"version": "0.3.
|
|
11915
|
+
"version": "0.3.735",
|
|
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.
|
|
11923
|
+
"version": "0.3.735",
|
|
11924
11924
|
"license": "UNLICENSED",
|
|
11925
11925
|
"dependencies": {
|
|
11926
|
-
"@north-light/api": "0.3.
|
|
11927
|
-
"@north-light/identity": "0.3.
|
|
11926
|
+
"@north-light/api": "0.3.735",
|
|
11927
|
+
"@north-light/identity": "0.3.735"
|
|
11928
11928
|
}
|
|
11929
11929
|
},
|
|
11930
11930
|
"packages/crouter-sdk": {
|
|
11931
11931
|
"name": "@north-light/sdk",
|
|
11932
|
-
"version": "0.3.
|
|
11932
|
+
"version": "0.3.735",
|
|
11933
11933
|
"license": "UNLICENSED",
|
|
11934
11934
|
"dependencies": {
|
|
11935
|
-
"@north-light/api": "0.3.
|
|
11936
|
-
"@north-light/identity": "0.3.
|
|
11937
|
-
"@north-light/plugin": "0.3.
|
|
11935
|
+
"@north-light/api": "0.3.735",
|
|
11936
|
+
"@north-light/identity": "0.3.735",
|
|
11937
|
+
"@north-light/plugin": "0.3.735",
|
|
11938
11938
|
"jose": "^6.2.1"
|
|
11939
11939
|
},
|
|
11940
11940
|
"bin": {
|