@north-light/cli 0.3.705 → 0.3.706
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/daemon/machine-link/forward.d.ts +1 -1
- package/dist/daemon/machine-link/forward.js +1 -1
- package/package.json +3 -3
- package/packages/crouter-api/dist/daemon/machine-link/forward.js +12 -8
- 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
|
@@ -6,7 +6,7 @@ import { type MachineLinkRefusal } from './holder.js';
|
|
|
6
6
|
export declare const VIEW_BUFFER_LIMIT_BYTES: number;
|
|
7
7
|
/** A viewer channel to a node on a machine: over the link this process holds, or forwarded to the API process that does. */
|
|
8
8
|
export declare function openMachineView(environmentId: string, nodeId: string): BrokerViewLink;
|
|
9
|
-
/** Wait for the node's broker on the Mac to accept a viewer, retrying
|
|
9
|
+
/** Wait for the node's broker on the Mac to accept a viewer, retrying a channel that closes (its view.sock refused) after 250 ms; a pending channel is waited on, not replaced. The accepted channel, open, or null on the deadline or when the launch exits. A caller that does not use the channel destroys it. */
|
|
10
10
|
export declare function waitForMachineView(environmentId: string, nodeId: string, exited: Promise<unknown> | undefined, waitMs: number): Promise<BrokerViewLink | null>;
|
|
11
11
|
/** The environment id of a forwarded viewer upgrade path, or null for any other path. */
|
|
12
12
|
export declare function machineViewEnvironment(req: IncomingMessage): string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var x=Object.defineProperty;var a=(r,e)=>x(r,"name",{value:e,configurable:!0});import{EventEmitter as A}from"node:events";import{createHmac as I,timingSafeEqual as R}from"node:crypto";import{WebSocket as
|
|
1
|
+
var x=Object.defineProperty;var a=(r,e)=>x(r,"name",{value:e,configurable:!0});import{EventEmitter as A}from"node:events";import{createHmac as I,timingSafeEqual as R}from"node:crypto";import{WebSocket as m,WebSocketServer as P}from"ws";import{markAt as k}from"../../core/logged-step-timings.js";import{addStepTiming as T}from"../../core/step-timings.js";import{emitEvent as _}from"../../core/events/emit.js";import{openDb as B}from"../../core/canvas/db.js";import{loadSecretsKey as O}from"../../core/secrets/key.js";import{LINK_MAX_PAYLOAD_BYTES as v,parseFrame as g}from"./frames.js";import{apiAddress as D,heldLinkOf as E,MachineViewLink as S,UNROUTABLE_PREFIX as L}from"./holder.js";const y=8*1024*1024,$=1013,M=/^\/v1\/machines\/([A-Za-z0-9_-]+)\/view$/,U=new P({noServer:!0,maxPayload:v}),b=a(r=>I("sha256",O().key).update(`machine-view:${r}`).digest("hex"),"forwardToken");function q(r,e){const i=E(r);return i!==null?new S(i,e):new N(r,e)}a(q,"openMachineView");class N extends A{static{a(this,"ForwardedViewLink")}environmentId;nodeId;ws;ended=!1;failed=!1;queued=[];queuedBytes=0;constructor(e,i){super(),this.environmentId=e,this.nodeId=i;const s=performance.now();this.once("connect",()=>_({level:"info",event:"daemon.timing.forwarded_view_ready",node_id:this.nodeId,fields:{environment:this.environmentId,open_to_ready_ms:Math.round((performance.now()-s)*10)/10}})),this.dial().catch(n=>this.finish(n instanceof Error?n.message:String(n)))}get destroyed(){return this.ended}write(e){return this.ended?!1:this.ws?.readyState!==m.OPEN?(this.queuedBytes+=e.length,this.queuedBytes>y?(this.finish("machine view: the holder did not accept the channel before its queue filled"),!1):(this.queued.push(e),!0)):this.ws.bufferedAmount>y?(this.finish("machine view: the holder is not draining the channel"),!1):(this.sendData(e),!0)}destroy(){return this.ended||(this.ws?.readyState===m.OPEN&&this.ws.send(JSON.stringify({type:"view.close",channel:""})),this.finish(void 0)),this}sendData(e){this.ws?.send(JSON.stringify({type:"view.data",channel:"",bytes:Buffer.from(e).toString("base64")}))}async dial(){const e=await(await B()).prepare("SELECT api_address, lease_expires_at FROM machine_links WHERE environment = ?").get(this.environmentId);if(e===void 0||Date.parse(e.lease_expires_at)<=Date.now())throw new Error(`machine_offline: machine ${this.environmentId} has no live link`);if(e.api_address.startsWith(L))throw new Error(`machine_unreachable: the API process holding the link wrote ${e.api_address}; set CRTR_API_ADDRESS or listen on TCP`);if(e.api_address===D())throw new Error(`machine_offline: the link row names this API process (${e.api_address}) but it holds no link`);if(this.ended)return;const i=new URL(`/v1/machines/${encodeURIComponent(this.environmentId)}/view`,e.api_address.includes("://")?e.api_address:`ws://${e.api_address}`);i.protocol=i.protocol==="https:"?"wss:":i.protocol==="http:"?"ws:":i.protocol,i.searchParams.set("node",this.nodeId);const s=new m(i.toString(),{headers:{authorization:`Bearer ${b(this.environmentId)}`},maxPayload:v});this.ws=s,s.on("open",()=>{for(const n of this.queued.splice(0))this.sendData(n)}),s.on("unexpected-response",(n,t)=>{t.resume(),this.finish(t.statusCode===409?"machine_offline: the holder no longer holds the link":`machine view refused by ${e.api_address}: ${t.statusCode}`)}),s.on("message",n=>{const t=g(n);t!==null&&(t.type==="view.ready"?this.emit("connect"):t.type==="view.data"?this.emit("data",Buffer.from(t.bytes,"base64")):t.type==="view.close"&&this.finish(t.error))}),s.on("error",n=>this.finish(n.message)),s.on("close",()=>this.finish("machine view forward closed"))}finish(e){this.ended||(this.ended=!0,this.ws?.close(),e!==void 0&&!this.failed&&(this.failed=!0,this.emit("error",Object.assign(new Error(e),{code:"ECONNRESET"}))),this.emit("close",this.failed))}}function C(r,e,i,s){return new Promise(n=>{const t=q(r,e),c=Math.max(1,i-Date.now());let d=!1;const o=a(()=>{d||(d=!0,clearTimeout(l),n(null),t.destroy())},"giveUp"),l=setTimeout(()=>{_({level:"info",event:"daemon.timing.view_ready_timeout",node_id:e,fields:{channel:t.channel??"",timeout_ms:c}}),o()},c);s?.then(o),t.on("error",()=>{}),t.on("connect",()=>{d=!0,clearTimeout(l),n(t)}),t.on("close",()=>{d=!0,clearTimeout(l),n(null)})})}a(C,"openReadyMachineView");async function G(r,e,i,s){const n=Date.now()+s;let t=!1;i?.then(()=>{t=!0});for(let c=1;Date.now()<=n&&!t;c++){const d=performance.now(),o=await C(r,e,n,i);if(T(`probe_${c}_${o!==null?"ready":"failed"}_ms`,performance.now()-d),o!==null)return k("ready_received"),o;await new Promise(l=>setTimeout(l,250))}return null}a(G,"waitForMachineView");function Q(r){const e=M.exec(new URL(r.url??"/","http://runtime.local").pathname);return e===null?null:e[1]}a(Q,"machineViewEnvironment");function ee(r,e,i,s){const n=r.headers.authorization,t=/^Bearer (\S+)$/.exec(Array.isArray(n)?n[0]??"":n??"")?.[1]??"",c=Buffer.from(b(s)),d=Buffer.from(t);if(d.length!==c.length||!R(d,c))return{status:401,text:"Unauthorized",code:"unauthorized",message:"machine view forward credential refused"};const o=new URL(r.url??"/","http://runtime.local").searchParams.get("node");if(o===null||o==="")return{status:400,text:"Bad Request",code:"bad_request",message:"node is required"};const l=E(s);return l===null?{status:409,text:"Conflict",code:"machine_offline",message:"this API process holds no link for the machine"}:(U.handleUpgrade(r,e,i,f=>{const h=new S(l,o),p=a(u=>{f.readyState===m.OPEN&&f.send(JSON.stringify(u))},"send");h.on("connect",()=>p({type:"view.ready",channel:""})),h.on("data",u=>{if(f.bufferedAmount>y){h.destroy(),f.close($,"viewer too slow");return}p({type:"view.data",channel:"",bytes:u.toString("base64")})}),h.on("error",u=>p({type:"view.close",channel:"",error:u.message})),h.on("close",()=>f.close()),f.on("message",u=>{const w=g(u);w?.type==="view.data"?h.write(Buffer.from(w.bytes,"base64")):w?.type==="view.close"&&h.destroy()}),f.on("close",()=>h.destroy()),f.on("error",()=>h.destroy())}),null)}a(ee,"handleMachineViewUpgrade");export{y as VIEW_BUFFER_LIMIT_BYTES,ee as handleMachineViewUpgrade,Q as machineViewEnvironment,q as openMachineView,G as waitForMachineView};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.706",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -156,8 +156,8 @@
|
|
|
156
156
|
},
|
|
157
157
|
"license": "UNLICENSED",
|
|
158
158
|
"dependencies": {
|
|
159
|
-
"@north-light/identity": "0.3.
|
|
160
|
-
"@north-light/plugin": "0.3.
|
|
159
|
+
"@north-light/identity": "0.3.706",
|
|
160
|
+
"@north-light/plugin": "0.3.706",
|
|
161
161
|
"@earendil-works/chord": "1.5.2",
|
|
162
162
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
163
163
|
"@earendil-works/pi-ai": "1.5.2",
|
|
@@ -115,22 +115,26 @@ class ForwardedViewLink extends EventEmitter {
|
|
|
115
115
|
this.emit('close', this.failed);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
/** One readiness check: the Mac connected the node's view.sock
|
|
119
|
-
function openReadyMachineView(environmentId, nodeId,
|
|
118
|
+
/** One readiness check: the Mac connected the node's view.sock before `deadline`. A channel still pending is kept until it connects, closes, the deadline passes or the launch exits; the channel that connected is returned open, for the caller to use or destroy, and null when it closed, the deadline passed or the launch exited (a pending channel is destroyed then). */
|
|
119
|
+
function openReadyMachineView(environmentId, nodeId, deadline, exited) {
|
|
120
120
|
return new Promise((resolve) => {
|
|
121
121
|
const view = openMachineView(environmentId, nodeId);
|
|
122
|
+
const timeoutMs = Math.max(1, deadline - Date.now());
|
|
123
|
+
let settled = false;
|
|
124
|
+
const giveUp = () => { if (settled)
|
|
125
|
+
return; settled = true; clearTimeout(timer); resolve(null); view.destroy(); };
|
|
122
126
|
const timer = setTimeout(() => {
|
|
123
127
|
emitEvent({ level: 'info', event: 'daemon.timing.view_ready_timeout', node_id: nodeId, fields: { channel: view.channel ?? '', timeout_ms: timeoutMs } });
|
|
124
|
-
|
|
125
|
-
view.destroy();
|
|
128
|
+
giveUp();
|
|
126
129
|
}, timeoutMs);
|
|
130
|
+
void exited?.then(giveUp);
|
|
127
131
|
// The no-op error listener stays on the returned channel until its user attaches its own: an error before then must not throw.
|
|
128
132
|
view.on('error', () => { });
|
|
129
|
-
view.on('connect', () => { clearTimeout(timer); resolve(view); });
|
|
130
|
-
view.on('close', () => { clearTimeout(timer); resolve(null); });
|
|
133
|
+
view.on('connect', () => { settled = true; clearTimeout(timer); resolve(view); });
|
|
134
|
+
view.on('close', () => { settled = true; clearTimeout(timer); resolve(null); });
|
|
131
135
|
});
|
|
132
136
|
}
|
|
133
|
-
/** Wait for the node's broker on the Mac to accept a viewer, retrying
|
|
137
|
+
/** Wait for the node's broker on the Mac to accept a viewer, retrying a channel that closes (its view.sock refused) after 250 ms; a pending channel is waited on, not replaced. The accepted channel, open, or null on the deadline or when the launch exits. A caller that does not use the channel destroys it. */
|
|
134
138
|
export async function waitForMachineView(environmentId, nodeId, exited, waitMs) {
|
|
135
139
|
const deadline = Date.now() + waitMs;
|
|
136
140
|
let exitSeen = false;
|
|
@@ -138,7 +142,7 @@ export async function waitForMachineView(environmentId, nodeId, exited, waitMs)
|
|
|
138
142
|
// Each attempt's length and outcome land in the calling request's step timings (`probe_<n>_ready_ms` / `probe_<n>_failed_ms`), and `ready_received_at` marks the first ready.
|
|
139
143
|
for (let attempt = 1; Date.now() <= deadline && !exitSeen; attempt++) {
|
|
140
144
|
const started = performance.now();
|
|
141
|
-
const ready = await openReadyMachineView(environmentId, nodeId,
|
|
145
|
+
const ready = await openReadyMachineView(environmentId, nodeId, deadline, exited);
|
|
142
146
|
addStepTiming(`probe_${attempt}_${ready !== null ? 'ready' : 'failed'}_ms`, performance.now() - started);
|
|
143
147
|
if (ready !== null) {
|
|
144
148
|
markAt('ready_received');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.706",
|
|
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.706",
|
|
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.706",
|
|
31
|
+
"@north-light/identity": "0.3.706"
|
|
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.706",
|
|
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.706",
|
|
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.706",
|
|
32
|
+
"@north-light/plugin": "0.3.706",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -10667,17 +10667,17 @@
|
|
|
10667
10667
|
},
|
|
10668
10668
|
"packages/crouter-api": {
|
|
10669
10669
|
"name": "@north-light/api",
|
|
10670
|
-
"version": "0.3.
|
|
10670
|
+
"version": "0.3.706",
|
|
10671
10671
|
"license": "UNLICENSED"
|
|
10672
10672
|
},
|
|
10673
10673
|
"packages/crouter-env-docker": {
|
|
10674
10674
|
"name": "@north-light/env-docker",
|
|
10675
|
-
"version": "0.3.
|
|
10675
|
+
"version": "0.3.706",
|
|
10676
10676
|
"license": "UNLICENSED"
|
|
10677
10677
|
},
|
|
10678
10678
|
"packages/crouter-identity": {
|
|
10679
10679
|
"name": "@north-light/identity",
|
|
10680
|
-
"version": "0.3.
|
|
10680
|
+
"version": "0.3.706",
|
|
10681
10681
|
"license": "UNLICENSED",
|
|
10682
10682
|
"dependencies": {
|
|
10683
10683
|
"jose": "^6.2.1"
|
|
@@ -10685,21 +10685,21 @@
|
|
|
10685
10685
|
},
|
|
10686
10686
|
"packages/crouter-plugin": {
|
|
10687
10687
|
"name": "@north-light/plugin",
|
|
10688
|
-
"version": "0.3.
|
|
10688
|
+
"version": "0.3.706",
|
|
10689
10689
|
"license": "UNLICENSED",
|
|
10690
10690
|
"dependencies": {
|
|
10691
|
-
"@north-light/api": "0.3.
|
|
10692
|
-
"@north-light/identity": "0.3.
|
|
10691
|
+
"@north-light/api": "0.3.706",
|
|
10692
|
+
"@north-light/identity": "0.3.706"
|
|
10693
10693
|
}
|
|
10694
10694
|
},
|
|
10695
10695
|
"packages/crouter-sdk": {
|
|
10696
10696
|
"name": "@north-light/sdk",
|
|
10697
|
-
"version": "0.3.
|
|
10697
|
+
"version": "0.3.706",
|
|
10698
10698
|
"license": "UNLICENSED",
|
|
10699
10699
|
"dependencies": {
|
|
10700
|
-
"@north-light/api": "0.3.
|
|
10701
|
-
"@north-light/identity": "0.3.
|
|
10702
|
-
"@north-light/plugin": "0.3.
|
|
10700
|
+
"@north-light/api": "0.3.706",
|
|
10701
|
+
"@north-light/identity": "0.3.706",
|
|
10702
|
+
"@north-light/plugin": "0.3.706",
|
|
10703
10703
|
"jose": "^6.2.1"
|
|
10704
10704
|
},
|
|
10705
10705
|
"bin": {
|