@north-light/cli 0.3.600 → 0.3.602

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,4 +1,4 @@
1
- var N=Object.defineProperty;var t=(e,r)=>N(e,"name",{value:r,configurable:!0});import{createHash as O}from"node:crypto";import{parseScope as h}from"@north-light/identity";import{openDb as d,withCanvasWrite as m}from"../canvas/db.js";import{isUnsandboxedMachine as j}from"../runtime/unsandboxed.js";import{replaceWrittenBy as A,userSubject as b}from"../permissions/facts.js";import{GROUP_TYPE as R}from"../permissions/builtin.js";const D=["not_started","pending","ready","failed","unavailable"],k=["ultra","strong","medium","light"];function I(){const e=process.env.CRTR_RUNTIME;return e?{sql:" AND runtime = ?",args:[e]}:{sql:"",args:[]}}t(I,"runtimeScope");async function c(e,r,n=[]){const s=I();return await(await d()).prepare(`SELECT ${e} FROM grants WHERE ${r}${s.sql}`).all(...n,...s.args)}t(c,"grantRows");async function u(e,r,n=[]){return(await c(e,r,n))[0]}t(u,"grantRow");function l(e){if(!Array.isArray(e))throw new TypeError("grant scopes must be a list");return e.map(r=>{if(!r||typeof r!="object"||typeof r.scope!="string"||!["always","ask"].includes(r.mode))throw new TypeError("invalid grant scope entry");return{scope:r.scope,mode:r.mode}})}t(l,"entries");function L(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const{state:r,message:n,next:s,step:a}=e;return typeof r!="string"||!D.includes(r)||n!==void 0&&typeof n!="string"||a!==void 0&&typeof a!="string"||typeof s!="string"||!s?null:{state:r,...n===void 0?{}:{message:n},next:s,...a===void 0?{}:{step:a}}}t(L,"dependencyOf");function x(e){if(!e||typeof e!="object"||Array.isArray(e))return{};const r={};for(const[n,s]of Object.entries(e)){const a=L(s);a&&(r[n]=a)}return r}t(x,"dependenciesOf");function C(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const{base_url:r,rungs:n}=e;if(typeof r!="string"||!r||!n||typeof n!="object"||Array.isArray(n))return null;const s={};for(const a of k){const o=n[a];typeof o=="string"&&o&&(s[a]=o)}return Object.keys(s).length?{base_url:r.replace(/\/+$/,""),rungs:s}:null}t(C,"inferenceEndpointOf");function f(e){if(e.computed_rev!==e.rev||e.scopes_json===null||e.resolved_scopes_json===null)throw new TypeError("grant columns are not computed for this revision");return{id:e.id,runtime:e.runtime,sub:e.sub,grantee:e.grantee,rev:e.rev,scopes:l(JSON.parse(e.scopes_json)),resolved_scopes:l(JSON.parse(e.resolved_scopes_json)),spend_cap:e.spend_cap,expires_at:e.expires_at,status:e.status,revoked_at:e.revoked_at,approved_at:e.approved_at,payer:e.payer,dependencies:x(JSON.parse(e.dependencies_json??"{}")),run_notice_url:e.run_notice_url??null,inference_endpoint:e.inference_endpoint_json?C(JSON.parse(e.inference_endpoint_json)):null,synced_at:e.synced_at??""}}t(f,"record");function p(e){if(!e||e.status!=="active")return null;try{return $(f(e))}catch(r){if(r instanceof TypeError||r instanceof SyntaxError)return null;throw r}}t(p,"active");function g(e){return e.grantee!=="app:terminal"&&j()}t(g,"mirrorOnly");async function Y(){return(await G()).filter(e=>!g(e))}t(Y,"localGrants");const E="[A-Za-z0-9_-]{1,64}",M=new RegExp(`^(${E}):(${E})$`);function F(e){const r=new Set;for(const n of e)if(n.status==="active")for(const{scope:s}of n.resolved_scopes){const a=M.exec(s);a&&a[1]!=="crtr"&&r.add(a[1])}return[...r].sort()}t(F,"providerIdsFromGrants");async function Z(e){const r=await c("*","sub = ? AND status = 'active'",[e]);return new Set(F(r.flatMap(n=>{try{return[f(n)]}catch(s){if(s instanceof TypeError||s instanceof SyntaxError)return[];throw s}})))}t(Z,"grantedProviderIds");function K(e,r){return e.source_marketplace===null&&e.source_path===null&&r.has(e.name)}t(K,"isProviderBundleRow");async function Q(e){return(await c("*","sub = ? AND status = 'active'",[e])).flatMap(n=>{const s=p(n);return s===null?[]:[s]})}t(Q,"activeGrantsOfPerson");async function G(){return(await c("*","true")).flatMap(e=>{try{return[f(e)]}catch(r){if(r instanceof TypeError||r instanceof SyntaxError)return[];throw r}})}t(G,"allGrants");function U(e){return e.expires_at!==null&&!(Date.parse(e.expires_at)>Date.now())}t(U,"grantExpired");function $(e){if(e.status!=="active"||U(e))return null;try{const r=e.resolved_scopes.map(({scope:n})=>h(n));return{...e,resolved:e.resolved_scopes.flatMap(({mode:n},s)=>n==="always"?[r[s]]:[])}}catch(r){if(r instanceof TypeError||r instanceof SyntaxError)return null;throw r}}t($,"activeRecord");function v(e){return Array.isArray(e)?`[${e.map(v).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).sort().filter(r=>e[r]!==void 0).map(r=>`${JSON.stringify(r)}:${v(e[r])}`).join(",")}}`:JSON.stringify(e)??"null"}t(v,"canonicalJson");function ee(e){const r={rev:e.rev,resolved_scopes:e.resolved_scopes,spend_cap:e.spend_cap,payer:e.payer,dependencies:e.dependencies??{},...e.inference_endpoint?{inference_endpoint:e.inference_endpoint}:{}};return O("sha256").update(v(r)).digest("base64url").slice(0,22)}t(ee,"grantVersion");async function re(e){return!!await u("1","id = ?",[e])}t(re,"hasGrant");async function ne(e){return await u("rev, status","id = ?",[e])??null}t(ne,"grantSyncState");async function te(e,r){return await u("rev, status","grantee = ? AND sub = ?",[e,r])??null}t(te,"grantSyncStateFor");async function P(e){const r=await u("*","id = ?",[e]);if(!r)return null;try{return f(r)}catch(n){if(n instanceof TypeError||n instanceof SyntaxError)return null;throw n}}t(P,"grantRecord");async function se(e){const r=await u("*","id = ?",[e]);if(!r)return{standing:"inactive",rev:null,sub:null,grantee:null,status:null,removal_done_at:null,record:null};const n={rev:r.rev,sub:r.sub,grantee:r.grantee,status:r.status,removal_done_at:r.removal_done_at??null};if(r.status!=="active")return{...n,standing:"inactive",record:null};if(r.computed_rev!==r.rev)return{...n,standing:"lagging",record:null};const s=p(r);return s===null?{...n,standing:"inactive",record:null}:{...n,standing:"active",record:s}}t(se,"grantStanding");async function ae(e){return(await c("id",e)).map(r=>r.id)}t(ae,"grantIdsWhere");async function oe(e){return(e?(await P(e))?.payer:null)??"user"}t(oe,"payerOfGrant");async function W(e){return p(await u("*","id = ?",[e]))}t(W,"activeGrant");async function ie(e,r){return p(await u("*","grantee = ? AND sub = ?",[e,r]))}t(ie,"grantFor");async function ce(e){if(g({grantee:e}))return null;const r=await c("*","grantee = ? AND status = 'active'",[e]);if(r.length>1)throw new Error(`multiple active grants for ${e}`);return p(r[0])}t(ce,"activeGrantForApp");async function ue(e){const r=await W(e);return r&&r.run_notice_url&&!g(r)?{url:r.run_notice_url,sub:r.sub,grantee:r.grantee}:null}t(ue,"runNoticeTarget");async function pe(e){const r=await c("*","grantee = 'app:terminal' AND sub = ? AND status = 'active'",[e]);if(r.length>1)throw new Error(`multiple active terminal grants for ${e}`);return p(r[0])}t(pe,"terminalGrant");async function de(){return(await(await d()).prepare("SELECT value FROM runtime_state WHERE key = 'grants_source'").get())?.value??null}t(de,"grantsSource");async function le(e){return(await(await d()).prepare("SELECT value FROM runtime_state WHERE key = 'grants_source'").get())?.value===e}t(le,"hasSyncedGrants");async function fe(e){return(await e.prepare("SELECT value FROM runtime_state WHERE key = 'grants_source'").get())?.value!=="local"?0:(await e.prepare("DELETE FROM runtime_state WHERE key = 'grants_source'").run(),Number((await e.prepare("DELETE FROM grants").run()).changes))}t(fe,"dropLocalGrantMirror");async function _e(){return await m(async e=>Number((await e.prepare("UPDATE grants SET computed_rev = rev WHERE computed_rev IS NULL AND scopes_json IS NOT NULL AND resolved_scopes_json IS NOT NULL").run()).changes))}t(_e,"backfillComputedRev");function ye(e){if(e===void 0)return[];if(!Array.isArray(e))throw new TypeError("invalid grant sync response");return e.map(r=>{const{team:n,members:s}=r??{};if(typeof n!="string"||!/^team:\S+$/.test(n)||!Array.isArray(s)||s.some(a=>typeof a!="string"||!/^user:[^\s*]+$/.test(a)))throw new TypeError("invalid grant sync response");return{team:n,members:s}})}t(ye,"teamsOf");async function ge(e,r,n,s=[]){const a=new Set;for(const o of e){if(a.has(o.id)||!o.id||!o.runtime||!o.sub||!o.grantee||!Number.isInteger(o.rev)||!["active","revoked","removed"].includes(o.status))throw new TypeError("invalid grant sync response");a.add(o.id),l(o.scopes),l(o.resolved_scopes)}await m(async o=>{let _=0;const y=[...a];_+=Number((await(y.length?o.prepareUncached(`DELETE FROM grants WHERE id NOT IN (${y.map(()=>"?").join(",")})`).run(...y):o.prepareUncached("DELETE FROM grants").run())).changes);const S=o.prepare(`INSERT INTO grants
1
+ var N=Object.defineProperty;var t=(e,r)=>N(e,"name",{value:r,configurable:!0});import{createHash as O}from"node:crypto";import{parseScope as h}from"@north-light/identity";import{openDb as d,withCanvasWrite as m}from"../canvas/db.js";import{isUnsandboxedMachine as j}from"../runtime/unsandboxed.js";import{replaceWrittenBy as A,userSubject as b}from"../permissions/facts.js";import{GROUP_TYPE as R}from"../permissions/builtin.js";const D=["not_started","pending","ready","failed","unavailable"],k=["ultra","strong","medium","light"];function I(){const e=process.env.CRTR_RUNTIME;return e?{sql:" AND runtime = ?",args:[e]}:{sql:"",args:[]}}t(I,"runtimeScope");async function c(e,r,n=[]){const s=I();return await(await d()).prepare(`SELECT ${e} FROM grants WHERE (${r})${s.sql}`).all(...n,...s.args)}t(c,"grantRows");async function u(e,r,n=[]){return(await c(e,r,n))[0]}t(u,"grantRow");function l(e){if(!Array.isArray(e))throw new TypeError("grant scopes must be a list");return e.map(r=>{if(!r||typeof r!="object"||typeof r.scope!="string"||!["always","ask"].includes(r.mode))throw new TypeError("invalid grant scope entry");return{scope:r.scope,mode:r.mode}})}t(l,"entries");function L(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const{state:r,message:n,next:s,step:a}=e;return typeof r!="string"||!D.includes(r)||n!==void 0&&typeof n!="string"||a!==void 0&&typeof a!="string"||typeof s!="string"||!s?null:{state:r,...n===void 0?{}:{message:n},next:s,...a===void 0?{}:{step:a}}}t(L,"dependencyOf");function x(e){if(!e||typeof e!="object"||Array.isArray(e))return{};const r={};for(const[n,s]of Object.entries(e)){const a=L(s);a&&(r[n]=a)}return r}t(x,"dependenciesOf");function C(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const{base_url:r,rungs:n}=e;if(typeof r!="string"||!r||!n||typeof n!="object"||Array.isArray(n))return null;const s={};for(const a of k){const o=n[a];typeof o=="string"&&o&&(s[a]=o)}return Object.keys(s).length?{base_url:r.replace(/\/+$/,""),rungs:s}:null}t(C,"inferenceEndpointOf");function f(e){if(e.computed_rev!==e.rev||e.scopes_json===null||e.resolved_scopes_json===null)throw new TypeError("grant columns are not computed for this revision");return{id:e.id,runtime:e.runtime,sub:e.sub,grantee:e.grantee,rev:e.rev,scopes:l(JSON.parse(e.scopes_json)),resolved_scopes:l(JSON.parse(e.resolved_scopes_json)),spend_cap:e.spend_cap,expires_at:e.expires_at,status:e.status,revoked_at:e.revoked_at,approved_at:e.approved_at,payer:e.payer,dependencies:x(JSON.parse(e.dependencies_json??"{}")),run_notice_url:e.run_notice_url??null,inference_endpoint:e.inference_endpoint_json?C(JSON.parse(e.inference_endpoint_json)):null,synced_at:e.synced_at??""}}t(f,"record");function p(e){if(!e||e.status!=="active")return null;try{return $(f(e))}catch(r){if(r instanceof TypeError||r instanceof SyntaxError)return null;throw r}}t(p,"active");function g(e){return e.grantee!=="app:terminal"&&j()}t(g,"mirrorOnly");async function Y(){return(await G()).filter(e=>!g(e))}t(Y,"localGrants");const E="[A-Za-z0-9_-]{1,64}",M=new RegExp(`^(${E}):(${E})$`);function F(e){const r=new Set;for(const n of e)if(n.status==="active")for(const{scope:s}of n.resolved_scopes){const a=M.exec(s);a&&a[1]!=="crtr"&&r.add(a[1])}return[...r].sort()}t(F,"providerIdsFromGrants");async function Z(e){const r=await c("*","sub = ? AND status = 'active'",[e]);return new Set(F(r.flatMap(n=>{try{return[f(n)]}catch(s){if(s instanceof TypeError||s instanceof SyntaxError)return[];throw s}})))}t(Z,"grantedProviderIds");function K(e,r){return e.source_marketplace===null&&e.source_path===null&&r.has(e.name)}t(K,"isProviderBundleRow");async function Q(e){return(await c("*","sub = ? AND status = 'active'",[e])).flatMap(n=>{const s=p(n);return s===null?[]:[s]})}t(Q,"activeGrantsOfPerson");async function G(){return(await c("*","true")).flatMap(e=>{try{return[f(e)]}catch(r){if(r instanceof TypeError||r instanceof SyntaxError)return[];throw r}})}t(G,"allGrants");function U(e){return e.expires_at!==null&&!(Date.parse(e.expires_at)>Date.now())}t(U,"grantExpired");function $(e){if(e.status!=="active"||U(e))return null;try{const r=e.resolved_scopes.map(({scope:n})=>h(n));return{...e,resolved:e.resolved_scopes.flatMap(({mode:n},s)=>n==="always"?[r[s]]:[])}}catch(r){if(r instanceof TypeError||r instanceof SyntaxError)return null;throw r}}t($,"activeRecord");function v(e){return Array.isArray(e)?`[${e.map(v).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).sort().filter(r=>e[r]!==void 0).map(r=>`${JSON.stringify(r)}:${v(e[r])}`).join(",")}}`:JSON.stringify(e)??"null"}t(v,"canonicalJson");function ee(e){const r={rev:e.rev,resolved_scopes:e.resolved_scopes,spend_cap:e.spend_cap,payer:e.payer,dependencies:e.dependencies??{},...e.inference_endpoint?{inference_endpoint:e.inference_endpoint}:{}};return O("sha256").update(v(r)).digest("base64url").slice(0,22)}t(ee,"grantVersion");async function re(e){return!!await u("1","id = ?",[e])}t(re,"hasGrant");async function ne(e){return await u("rev, status","id = ?",[e])??null}t(ne,"grantSyncState");async function te(e,r){return await u("rev, status","grantee = ? AND sub = ?",[e,r])??null}t(te,"grantSyncStateFor");async function P(e){const r=await u("*","id = ?",[e]);if(!r)return null;try{return f(r)}catch(n){if(n instanceof TypeError||n instanceof SyntaxError)return null;throw n}}t(P,"grantRecord");async function se(e){const r=await u("*","id = ?",[e]);if(!r)return{standing:"inactive",rev:null,sub:null,grantee:null,status:null,removal_done_at:null,record:null};const n={rev:r.rev,sub:r.sub,grantee:r.grantee,status:r.status,removal_done_at:r.removal_done_at??null};if(r.status!=="active")return{...n,standing:"inactive",record:null};if(r.computed_rev!==r.rev)return{...n,standing:"lagging",record:null};const s=p(r);return s===null?{...n,standing:"inactive",record:null}:{...n,standing:"active",record:s}}t(se,"grantStanding");async function ae(e){return(await c("id",e)).map(r=>r.id)}t(ae,"grantIdsWhere");async function oe(e){return(e?(await P(e))?.payer:null)??"user"}t(oe,"payerOfGrant");async function W(e){return p(await u("*","id = ?",[e]))}t(W,"activeGrant");async function ie(e,r){return p(await u("*","grantee = ? AND sub = ?",[e,r]))}t(ie,"grantFor");async function ce(e){if(g({grantee:e}))return null;const r=await c("*","grantee = ? AND status = 'active'",[e]);if(r.length>1)throw new Error(`multiple active grants for ${e}`);return p(r[0])}t(ce,"activeGrantForApp");async function ue(e){const r=await W(e);return r&&r.run_notice_url&&!g(r)?{url:r.run_notice_url,sub:r.sub,grantee:r.grantee}:null}t(ue,"runNoticeTarget");async function pe(e){const r=await c("*","grantee = 'app:terminal' AND sub = ? AND status = 'active'",[e]);if(r.length>1)throw new Error(`multiple active terminal grants for ${e}`);return p(r[0])}t(pe,"terminalGrant");async function de(){return(await(await d()).prepare("SELECT value FROM runtime_state WHERE key = 'grants_source'").get())?.value??null}t(de,"grantsSource");async function le(e){return(await(await d()).prepare("SELECT value FROM runtime_state WHERE key = 'grants_source'").get())?.value===e}t(le,"hasSyncedGrants");async function fe(e){return(await e.prepare("SELECT value FROM runtime_state WHERE key = 'grants_source'").get())?.value!=="local"?0:(await e.prepare("DELETE FROM runtime_state WHERE key = 'grants_source'").run(),Number((await e.prepare("DELETE FROM grants").run()).changes))}t(fe,"dropLocalGrantMirror");async function _e(){return await m(async e=>Number((await e.prepare("UPDATE grants SET computed_rev = rev WHERE computed_rev IS NULL AND scopes_json IS NOT NULL AND resolved_scopes_json IS NOT NULL").run()).changes))}t(_e,"backfillComputedRev");function ye(e){if(e===void 0)return[];if(!Array.isArray(e))throw new TypeError("invalid grant sync response");return e.map(r=>{const{team:n,members:s}=r??{};if(typeof n!="string"||!/^team:\S+$/.test(n)||!Array.isArray(s)||s.some(a=>typeof a!="string"||!/^user:[^\s*]+$/.test(a)))throw new TypeError("invalid grant sync response");return{team:n,members:s}})}t(ye,"teamsOf");async function ge(e,r,n,s=[]){const a=new Set;for(const o of e){if(a.has(o.id)||!o.id||!o.runtime||!o.sub||!o.grantee||!Number.isInteger(o.rev)||!["active","revoked","removed"].includes(o.status))throw new TypeError("invalid grant sync response");a.add(o.id),l(o.scopes),l(o.resolved_scopes)}await m(async o=>{let _=0;const y=[...a];_+=Number((await(y.length?o.prepareUncached(`DELETE FROM grants WHERE id NOT IN (${y.map(()=>"?").join(",")})`).run(...y):o.prepareUncached("DELETE FROM grants").run())).changes);const S=o.prepare(`INSERT INTO grants
2
2
  (id, runtime, sub, grantee, rev, scopes_json, resolved_scopes_json, spend_cap, expires_at,
3
3
  status, revoked_at, approved_at, payer, dependencies_json, run_notice_url, inference_endpoint_json, synced_at, computed_rev)
4
4
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
@@ -5,8 +5,8 @@ import { ProviderError } from './errors.js';
5
5
  export declare const LIBS_SEARCH_PATH = "/v1/libs/search";
6
6
  export declare const LIBS_BUNDLE_PATH = "/v1/libs/bundle";
7
7
  export declare const LIBS_REPORT_PATH = "/v1/libs/report";
8
- /** The device wire version libs routes and bundled execs are served at. */
9
- export declare const LIBS_MAJOR = 2;
8
+ /** The first device wire major that serves libs routes and bundled execs; every later major keeps them. */
9
+ export declare const LIBS_MIN_MAJOR = 2;
10
10
  export declare const isLibsSearch: (major: number, tool: string) => boolean;
11
11
  /** An exec whose code may import a library. The relay does the exact leading-import parse; a false positive costs one round trip. */
12
12
  export declare function wantsBundling(major: number, tool: string, args: Record<string, unknown>): boolean;
@@ -1 +1 @@
1
- var T=Object.defineProperty;var a=(e,r)=>T(e,"name",{value:r,configurable:!0});import{ProviderError as p}from"./errors.js";import{deviceDeps as w,deviceFailure as C,deviceUnreachable as _}from"./device.js";const $="/v1/libs/search",L="/v1/libs/bundle",R="/v1/libs/report",A=2,x=1e4,E=/@(northlight|vallum)\//,j=1e3,M=2e3,D=300,X=a((e,r)=>e===A&&r==="browser libs","isLibsSearch");function W(e,r,n){return e===A&&r==="browser executor exec"&&typeof n.code=="string"&&E.test(n.code)}a(W,"wantsBundling");function O(e){const r=e["retry-after"],n=Array.isArray(r)?r[0]:r,t=n===void 0?NaN:Number(n);return Number.isFinite(t)&&t>=0?t:void 0}a(O,"retryAfterSeconds");function U(e,r){const n=r.body?.error,t=n&&typeof n=="object"&&typeof n.code=="string"?n.code:void 0,o=n&&typeof n=="object"&&typeof n.message=="string"?n.message:void 0,i=C(e.machine,r.status,t,o,r.body);if(i!==null)return i;const s=e.mapFailure(r.status,r.body,r.headers),d=r.status===503?O(r.headers):void 0;return d===void 0||s.retry_after_s!==void 0?s:new p("provider_unavailable",s.message,{origin:s.origin,details:s.details,...s.param?{param:s.param}:{},retry_after_s:d})}a(U,"libsFailure");const N=a(e=>_(e.machine,"timeout",""),"budgetSpent");async function v(e,r,n,t){const o=e.deadlineAt-Date.now();if(o<=0)throw N(e);const i=await w.current.call(e.machine.machine_id,{method:"POST",path:r,body:{...n,version:t,deadline_at:e.deadlineAt}},{envelope:e.envelope,device:!0,signal:AbortSignal.any([e.signal,AbortSignal.timeout(o)])});if(e.signal.aborted)throw e.signal.reason??new Error("provider call aborted");if("unreachable"in i)throw _(e.machine,i.unreachable.reason,i.unreachable.message);if(i.status<200||i.status>=300)throw U(e,i);const s=i.body&&typeof i.body=="object"&&!Array.isArray(i.body)?i.body.result:void 0;if(!s||typeof s!="object"||Array.isArray(s))throw new p("provider_bad_response","the libraries result is not a JSON object",{origin:"provider",details:{status:i.status,message:"the libraries result is not a JSON object"}});return s}a(v,"libsRequest");function q(e,r,n){return v(e,$,{arguments:r},n)}a(q,"callLibsSearch");const b=a(e=>Array.isArray(e)&&e.every(r=>typeof r=="string")?e:null,"strings");function P(e){if(!Array.isArray(e))return null;const r=[];for(const n of e){const t=n,o=b(t?.domains),i=b(t?.writes);if(!t||typeof t.id!="string"||typeof t.name!="string"||o===null||i===null)return null;r.push({id:t.id,name:t.name,domains:o,writes:i})}return r}a(P,"parseServices");async function z(e,r,n){const t=await v(e,L,{code:r.code},n);if(t.bundled===!1)return null;const o=b(t.domains),i=P(t.services);if(t.bundled!==!0||typeof t.bundle!="string"||o===null||i===null||typeof t.release!="string")throw new p("provider_bad_response","the libraries bundle answer is malformed",{origin:"provider",details:{status:200,message:"the libraries bundle answer is malformed"}});const{code:s,...d}=r;return{arguments:{...d,bundle:t.bundle,domains:o},release:t.release,services:i}}a(z,"bundleExec");const S=a(e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0,"object"),l=a(e=>typeof e=="string"?e.slice(0,M):void 0,"text"),y=a(e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,"finite");function k(e){if(!Array.isArray(e))return[];const r=[];for(const n of e.slice(0,j)){const t=S(n),o=l(t?.service),i=l(t?.fn);if(!t||o===void 0||i===void 0)continue;const s=l(t.errorClass),d=y(t.status),u=l(t.upstreamCode);r.push({service:o,fn:i,ok:t.ok===!0,durationMs:Math.max(0,Math.round(y(t.durationMs)??0)),...s!==void 0&&{errorClass:s},...d!==void 0&&{status:d},...u!==void 0&&{upstreamCode:u},...typeof t.wasDispatched=="boolean"&&{wasDispatched:t.wasDispatched}})}return r}a(k,"sanitizeCalls");function F(e,r){let n;try{n=new URL(e).hostname.toLowerCase()}catch{return!1}return r.some(t=>{const o=t.toLowerCase().replace(/^\*\./,"").replace(/^\./,"");return n===o||n.endsWith(`.${o}`)})}a(F,"hostMatches");function B(e,r,n){for(const t of e){if(t.ok||t.errorClass!=="Unauthenticated")continue;const o=r.find(s=>s.id===t.service);if(!o||o.domains.length===0||F(n,o.domains))continue;let i=n;try{i=new URL(n).hostname||n}catch{}return`${o.name} is not on ${i} (it runs on ${o.domains.join(", ")})`}}a(B,"offSiteCall");function f(e,r,n,t,o){return new p(e,n,{status:r,origin:"provider",details:{code:e,message:n,next:t,status:r},...o===void 0?{}:{retry_after_s:o}})}a(f,"outcomeError");function Y(e,r){const n=S(e.envelope);if(!n||typeof e.url!="string")return{calls:[],error:f("js_exception",409,"The page returned a result that could not be read","Run the code again; if it keeps happening, report it")};const t=e.url,o=k(n.calls),i=l(e.warning);if(!("error"in n))return{calls:o,result:{result:n.result===void 0?null:n.result,url:t,calls:o,...i!==void 0&&{warning:i}}};const s=l(n.error)??"The script threw",d=i===void 0?"":` ${i}`,u=l(n.errorClass),h=a(c=>({calls:o,error:c}),"fail"),g=o.filter(c=>c.wasDispatched===!0&&r.find(m=>m.id===c.service)?.writes.includes(c.fn)===!0);if(g.length>0)return h(f("outcome_unknown",409,`The script threw after ${g.map(c=>`${c.service}.${c.fn}`).join(", ")} was sent, so it may have taken effect: ${s}`,`Check the site before repeating this action; do not retry blindly.${d}`));if(u==="Unauthenticated"){const c=B(o,r,t);return h((c??i)!==void 0?f("wrong_site",409,`The executor is on the wrong site, not signed out: ${c??i} (${s})`,"Create the executor on the service's own site (browser executor create --url https://\u2026) or navigate it there, then run the code again"):f("site_signed_out",409,`The site is signed out in this Chrome profile: ${s}`,"Sign in to the service in Chrome through the Northlight Desktop menu's Open Chrome profile, then run the code again"))}if(u==="RateLimited"){const c=y(n.retryAfterS),m=c!==void 0&&c>=1?Math.ceil(c):D;return h(f("rate_limited",429,s,`Wait for Retry-After seconds, then run the code again.${d}`,m))}return h(u==="ContractDrift"?f("lib_broken",502,`The library no longer matches the site: ${s}`,`Do not retry; the library needs a fix. Use a different approach for now.${d}`):f("js_exception",409,u&&u!=="Unknown"?`${u}: ${s}`:s,`Fix the code or its arguments and run it again.${d}`))}a(Y,"mapLibOutcome");function G(e,r,n,t){if(t.some(o=>!o.ok))try{w.current.call(e.machine_id,{method:"POST",path:R,body:{release:n,calls:t}},{envelope:r,device:!0,signal:AbortSignal.timeout(x)}).catch(()=>{})}catch{}}a(G,"reportLibCalls");export{L as LIBS_BUNDLE_PATH,A as LIBS_MAJOR,R as LIBS_REPORT_PATH,$ as LIBS_SEARCH_PATH,z as bundleExec,q as callLibsSearch,X as isLibsSearch,Y as mapLibOutcome,G as reportLibCalls,k as sanitizeCalls,W as wantsBundling};
1
+ var T=Object.defineProperty;var a=(e,r)=>T(e,"name",{value:r,configurable:!0});import{ProviderError as p}from"./errors.js";import{deviceDeps as w,deviceFailure as C,deviceUnreachable as _}from"./device.js";const $="/v1/libs/search",L="/v1/libs/bundle",R="/v1/libs/report",A=2,x=1e4,E=/@(northlight|vallum)\//,M=1e3,j=2e3,D=300,X=a((e,r)=>e>=A&&r==="browser libs","isLibsSearch");function W(e,r,n){return e>=A&&r==="browser executor exec"&&typeof n.code=="string"&&E.test(n.code)}a(W,"wantsBundling");function O(e){const r=e["retry-after"],n=Array.isArray(r)?r[0]:r,t=n===void 0?NaN:Number(n);return Number.isFinite(t)&&t>=0?t:void 0}a(O,"retryAfterSeconds");function N(e,r){const n=r.body?.error,t=n&&typeof n=="object"&&typeof n.code=="string"?n.code:void 0,o=n&&typeof n=="object"&&typeof n.message=="string"?n.message:void 0,i=C(e.machine,r.status,t,o,r.body);if(i!==null)return i;const s=e.mapFailure(r.status,r.body,r.headers),d=r.status===503?O(r.headers):void 0;return d===void 0||s.retry_after_s!==void 0?s:new p("provider_unavailable",s.message,{origin:s.origin,details:s.details,...s.param?{param:s.param}:{},retry_after_s:d})}a(N,"libsFailure");const U=a(e=>_(e.machine,"timeout",""),"budgetSpent");async function v(e,r,n,t){const o=e.deadlineAt-Date.now();if(o<=0)throw U(e);const i=await w.current.call(e.machine.machine_id,{method:"POST",path:r,body:{...n,version:t,deadline_at:e.deadlineAt}},{envelope:e.envelope,device:!0,signal:AbortSignal.any([e.signal,AbortSignal.timeout(o)])});if(e.signal.aborted)throw e.signal.reason??new Error("provider call aborted");if("unreachable"in i)throw _(e.machine,i.unreachable.reason,i.unreachable.message);if(i.status<200||i.status>=300)throw N(e,i);const s=i.body&&typeof i.body=="object"&&!Array.isArray(i.body)?i.body.result:void 0;if(!s||typeof s!="object"||Array.isArray(s))throw new p("provider_bad_response","the libraries result is not a JSON object",{origin:"provider",details:{status:i.status,message:"the libraries result is not a JSON object"}});return s}a(v,"libsRequest");function q(e,r,n){return v(e,$,{arguments:r},n)}a(q,"callLibsSearch");const b=a(e=>Array.isArray(e)&&e.every(r=>typeof r=="string")?e:null,"strings");function P(e){if(!Array.isArray(e))return null;const r=[];for(const n of e){const t=n,o=b(t?.domains),i=b(t?.writes);if(!t||typeof t.id!="string"||typeof t.name!="string"||o===null||i===null)return null;r.push({id:t.id,name:t.name,domains:o,writes:i})}return r}a(P,"parseServices");async function z(e,r,n){const t=await v(e,L,{code:r.code},n);if(t.bundled===!1)return null;const o=b(t.domains),i=P(t.services);if(t.bundled!==!0||typeof t.bundle!="string"||o===null||i===null||typeof t.release!="string")throw new p("provider_bad_response","the libraries bundle answer is malformed",{origin:"provider",details:{status:200,message:"the libraries bundle answer is malformed"}});const{code:s,...d}=r;return{arguments:{...d,bundle:t.bundle,domains:o},release:t.release,services:i}}a(z,"bundleExec");const S=a(e=>e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0,"object"),l=a(e=>typeof e=="string"?e.slice(0,j):void 0,"text"),y=a(e=>typeof e=="number"&&Number.isFinite(e)?e:void 0,"finite");function k(e){if(!Array.isArray(e))return[];const r=[];for(const n of e.slice(0,M)){const t=S(n),o=l(t?.service),i=l(t?.fn);if(!t||o===void 0||i===void 0)continue;const s=l(t.errorClass),d=y(t.status),u=l(t.upstreamCode);r.push({service:o,fn:i,ok:t.ok===!0,durationMs:Math.max(0,Math.round(y(t.durationMs)??0)),...s!==void 0&&{errorClass:s},...d!==void 0&&{status:d},...u!==void 0&&{upstreamCode:u},...typeof t.wasDispatched=="boolean"&&{wasDispatched:t.wasDispatched}})}return r}a(k,"sanitizeCalls");function F(e,r){let n;try{n=new URL(e).hostname.toLowerCase()}catch{return!1}return r.some(t=>{const o=t.toLowerCase().replace(/^\*\./,"").replace(/^\./,"");return n===o||n.endsWith(`.${o}`)})}a(F,"hostMatches");function I(e,r,n){for(const t of e){if(t.ok||t.errorClass!=="Unauthenticated")continue;const o=r.find(s=>s.id===t.service);if(!o||o.domains.length===0||F(n,o.domains))continue;let i=n;try{i=new URL(n).hostname||n}catch{}return`${o.name} is not on ${i} (it runs on ${o.domains.join(", ")})`}}a(I,"offSiteCall");function f(e,r,n,t,o){return new p(e,n,{status:r,origin:"provider",details:{code:e,message:n,next:t,status:r},...o===void 0?{}:{retry_after_s:o}})}a(f,"outcomeError");function Y(e,r){const n=S(e.envelope);if(!n||typeof e.url!="string")return{calls:[],error:f("js_exception",409,"The page returned a result that could not be read","Run the code again; if it keeps happening, report it")};const t=e.url,o=k(n.calls),i=l(e.warning);if(!("error"in n))return{calls:o,result:{result:n.result===void 0?null:n.result,url:t,calls:o,...i!==void 0&&{warning:i}}};const s=l(n.error)??"The script threw",d=i===void 0?"":` ${i}`,u=l(n.errorClass),h=a(c=>({calls:o,error:c}),"fail"),g=o.filter(c=>c.wasDispatched===!0&&r.find(m=>m.id===c.service)?.writes.includes(c.fn)===!0);if(g.length>0)return h(f("outcome_unknown",409,`The script threw after ${g.map(c=>`${c.service}.${c.fn}`).join(", ")} was sent, so it may have taken effect: ${s}`,`Check the site before repeating this action; do not retry blindly.${d}`));if(u==="Unauthenticated"){const c=I(o,r,t);return h((c??i)!==void 0?f("wrong_site",409,`The executor is on the wrong site, not signed out: ${c??i} (${s})`,"Create the executor on the service's own site (browser executor create --url https://\u2026) or navigate it there, then run the code again"):f("site_signed_out",409,`The site is signed out in this Chrome profile: ${s}`,"Sign in to the service in Chrome through the Northlight Desktop menu's Open Chrome profile, then run the code again"))}if(u==="RateLimited"){const c=y(n.retryAfterS),m=c!==void 0&&c>=1?Math.ceil(c):D;return h(f("rate_limited",429,s,`Wait for Retry-After seconds, then run the code again.${d}`,m))}return h(u==="ContractDrift"?f("lib_broken",502,`The library no longer matches the site: ${s}`,`Do not retry; the library needs a fix. Use a different approach for now.${d}`):f("js_exception",409,u&&u!=="Unknown"?`${u}: ${s}`:s,`Fix the code or its arguments and run it again.${d}`))}a(Y,"mapLibOutcome");function G(e,r,n,t){if(t.some(o=>!o.ok))try{w.current.call(e.machine_id,{method:"POST",path:R,body:{release:n,calls:t}},{envelope:r,device:!0,signal:AbortSignal.timeout(x)}).catch(()=>{})}catch{}}a(G,"reportLibCalls");export{L as LIBS_BUNDLE_PATH,A as LIBS_MIN_MAJOR,R as LIBS_REPORT_PATH,$ as LIBS_SEARCH_PATH,z as bundleExec,q as callLibsSearch,X as isLibsSearch,Y as mapLibOutcome,G as reportLibCalls,k as sanitizeCalls,W as wantsBundling};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.600",
3
+ "version": "0.3.602",
4
4
  "description": "crtr — agent runtime with memory, plugins, and marketplaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -145,7 +145,7 @@
145
145
  },
146
146
  "license": "UNLICENSED",
147
147
  "dependencies": {
148
- "@north-light/identity": "0.3.600",
148
+ "@north-light/identity": "0.3.602",
149
149
  "@earendil-works/chord": "1.1.0",
150
150
  "@earendil-works/pi-agent-core": "1.1.0",
151
151
  "@earendil-works/pi-ai": "1.1.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.600",
3
+ "version": "0.3.602",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.600",
3
+ "version": "0.3.602",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.600",
9
+ "version": "0.3.602",
10
10
  "hasInstallScript": true,
11
11
  "license": "UNLICENSED",
12
12
  "workspaces": [
@@ -28,7 +28,7 @@
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.600",
31
+ "@north-light/identity": "0.3.602",
32
32
  "cron-parser": "^5.6.0",
33
33
  "esbuild": "^0.27.7",
34
34
  "jose": "^6.2.12",
@@ -11956,17 +11956,17 @@
11956
11956
  },
11957
11957
  "packages/crouter-api": {
11958
11958
  "name": "@north-light/api",
11959
- "version": "0.3.600",
11959
+ "version": "0.3.602",
11960
11960
  "license": "UNLICENSED"
11961
11961
  },
11962
11962
  "packages/crouter-env-docker": {
11963
11963
  "name": "@north-light/env-docker",
11964
- "version": "0.3.600",
11964
+ "version": "0.3.602",
11965
11965
  "license": "UNLICENSED"
11966
11966
  },
11967
11967
  "packages/crouter-identity": {
11968
11968
  "name": "@north-light/identity",
11969
- "version": "0.3.600",
11969
+ "version": "0.3.602",
11970
11970
  "license": "UNLICENSED",
11971
11971
  "dependencies": {
11972
11972
  "jose": "^6.2.1"
@@ -11974,21 +11974,21 @@
11974
11974
  },
11975
11975
  "packages/crouter-plugin": {
11976
11976
  "name": "@north-light/plugin",
11977
- "version": "0.3.600",
11977
+ "version": "0.3.602",
11978
11978
  "license": "UNLICENSED",
11979
11979
  "dependencies": {
11980
- "@north-light/api": "0.3.600",
11981
- "@north-light/identity": "0.3.600"
11980
+ "@north-light/api": "0.3.602",
11981
+ "@north-light/identity": "0.3.602"
11982
11982
  }
11983
11983
  },
11984
11984
  "packages/crouter-sdk": {
11985
11985
  "name": "@north-light/sdk",
11986
- "version": "0.3.600",
11986
+ "version": "0.3.602",
11987
11987
  "license": "UNLICENSED",
11988
11988
  "dependencies": {
11989
- "@north-light/api": "0.3.600",
11990
- "@north-light/identity": "0.3.600",
11991
- "@north-light/plugin": "0.3.600",
11989
+ "@north-light/api": "0.3.602",
11990
+ "@north-light/identity": "0.3.602",
11991
+ "@north-light/plugin": "0.3.602",
11992
11992
  "jose": "^6.2.1"
11993
11993
  },
11994
11994
  "bin": {