@north-light/cli 0.3.597 → 0.3.599
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/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/charges.d.ts +22 -0
- package/dist/api/dto/charges.js +1 -0
- package/dist/api/dto/modelauth.d.ts +26 -0
- package/dist/api/dto/node-outcomes.d.ts +4 -0
- package/dist/api/error-codes.d.ts +5 -0
- package/dist/api/error-codes.js +1 -1
- package/dist/builtin-memory/crouter-sdk/release-notes.md +11 -0
- package/dist/clients/attach/viewer.js +374 -374
- package/dist/commands/sys/join.js +1 -1
- package/dist/core/auth-file.d.ts +3 -11
- package/dist/core/auth-file.js +1 -1
- package/dist/core/canvas/export-sqlite.js +1 -1
- package/dist/core/canvas/person.js +7 -7
- package/dist/core/canvas/recovery.js +2 -2
- package/dist/core/canvas/schema-pg/012-charge-admission.sql +62 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/canvas/types.d.ts +3 -0
- package/dist/core/grants/hosted-endpoint.d.ts +28 -0
- package/dist/core/grants/hosted-endpoint.js +1 -0
- package/dist/core/grants/sync.js +1 -1
- package/dist/core/import/load/run.js +2 -2
- package/dist/core/import/load/stage.d.ts +1 -1
- package/dist/core/import/load/stage.js +1 -1
- package/dist/core/import/load/stores.d.ts +2 -0
- package/dist/core/import/load/stores.js +2 -2
- package/dist/core/ledger/charges.js +1 -1
- package/dist/core/ledger/check.js +1 -1
- package/dist/core/ledger/chunks.js +2 -2
- package/dist/core/ledger/read.js +1 -1
- package/dist/core/ledger/types.d.ts +8 -0
- package/dist/core/llm/owner-candidates.d.ts +17 -0
- package/dist/core/llm/owner-candidates.js +1 -0
- package/dist/core/llm/run.js +2 -2
- package/dist/core/model-auth/activations.d.ts +37 -0
- package/dist/core/model-auth/activations.js +1 -0
- package/dist/core/model-auth/flows.js +1 -1
- package/dist/core/model-auth/handoff-jti.d.ts +10 -1
- package/dist/core/model-auth/handoff-jti.js +1 -1
- package/dist/core/model-auth/key-routes.d.ts +30 -0
- package/dist/core/model-auth/key-routes.js +1 -0
- package/dist/core/model-auth/readiness.d.ts +8 -1
- package/dist/core/model-auth/readiness.js +1 -1
- package/dist/core/model-config.js +1 -1
- package/dist/core/model-routes-pool.d.ts +2 -0
- package/dist/core/model-routes-pool.js +1 -1
- package/dist/core/model-routes.d.ts +12 -3
- package/dist/core/model-routes.js +1 -1
- package/dist/core/provider-failure.d.ts +5 -0
- package/dist/core/provider-failure.js +1 -1
- package/dist/core/providers/call.js +1 -1
- package/dist/core/runtime/broker/fault-retry.js +1 -1
- package/dist/core/runtime/broker/model-adapter.d.ts +6 -1
- package/dist/core/runtime/broker/model-adapter.js +3 -3
- package/dist/core/runtime/front-door.js +8 -8
- package/dist/core/runtime/launch-target.d.ts +2 -0
- package/dist/core/runtime/launch-target.js +1 -1
- package/dist/daemon/api/app-listener.js +12 -12
- package/dist/daemon/api/handlers/llm.js +3 -3
- package/dist/daemon/api/handlers/modelauth.js +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/key-signin.d.ts +9 -0
- package/dist/daemon/api/key-signin.js +124 -0
- package/dist/daemon/api/principal.d.ts +8 -3
- package/dist/daemon/api/principal.js +1 -1
- package/dist/daemon/api/server.js +1 -1
- package/dist/daemon/api/vendor-signin.d.ts +28 -1
- package/dist/daemon/api/vendor-signin.js +42 -24
- package/dist/daemon/cron/authority.js +1 -1
- package/dist/daemon/crtrd.js +12 -12
- package/dist/daemon/reconcilers/broker-supervision.d.ts +2 -2
- package/dist/daemon/reconcilers/broker-supervision.js +2 -2
- package/dist/daemon/reconcilers/ledger-r2.js +6 -6
- package/docs/sdk/release-notes.md +11 -0
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +13 -13
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var S=Object.defineProperty;var l=(e,r)=>S(e,"name",{value:r,configurable:!0});import{randomBytes as _,randomUUID as T}from"node:crypto";import{isCloudRole as $,runAsPerson as C}from"../../core/canvas/person.js";import{directoryIssuer as E}from"../../core/directory/issuer.js";import{emitEvent as v}from"../../core/events/emit.js";import{activationRecorded as I,awaitActivationAck as A}from"../../core/model-auth/activations.js";import{consumeHandoffJti as P,handoffActivation as R,handoffJtiConsumed as g,linkHandoffActivation as j,releaseHandoffJti as U}from"../../core/model-auth/handoff-jti.js";import{KEY_ROUTE_PROVIDERS as y,KeyRouteError as b,isKeyRouteProvider as L,keyRouteModels as O,saveKeyRoute as N,validateKeyRouteModels as H}from"../../core/model-auth/key-routes.js";import{RunError as u}from"../../core/runs/operations.js";import{loadPersonSettings as M}from"../../core/scoped-state/person-rows.js";import{personHasSnapshot as Y}from"../../core/scoped-state/person-store.js";import{unauthorizedHandoff as p}from"./principal.js";import{bearer as K,handleVendorSignIn as q,icon as m,isVendorSignInPath as w,jsonBody as B,page as G,sendJson as k,verifyOwnerHandoff as J}from"./vendor-signin.js";const f="/signin/key",h=`${f}/session`,z={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter",moonshotai:"Moonshot (Kimi)"};function pe(e){return w(e)||e===f||e===h}l(pe,"isRuntimeSignInPath");async function me(e,r,t,n){if(w(t.pathname)){await q(e,r,t,n);return}const a=e.method??"GET";if(t.pathname===f&&a==="GET"){F(r,n);return}const s=t.pathname===h&&a==="GET"?D:t.pathname===f&&a==="POST"?V:void 0;if(s===void 0)throw new u(404,"not_found","unknown operation");const o=await J(n,K(e),"model_credential");if(!$()){await s(e,r,t,n,o);return}await C(o.sub,async()=>{Y()||await M(o.sub),await s(e,r,t,n,o)})}l(me,"handleRuntimeSignIn");async function D(e,r,t,n,a){if(await g(a.jti))throw p("model_credential");const s=t.searchParams.getAll("return_to");let o;try{o=s.length===1?new URL(s[0]).origin:void 0}catch{o=void 0}if(o!==new URL(n.issuer).origin)throw new u(400,"invalid_request","return_to must be an absolute URL on the directory origin","return_to");const c=await Promise.all(y.map(async d=>({id:d,name:z[d],models:(await O(d)).map(i=>({...i,tools:!0}))})));k(r,200,{providers:c})}l(D,"session");async function V(e,r,t,n,a){const s=await B(e),o=s.api_key;if(o===void 0){const i=await R(a.jti);if(i===void 0)throw p("model_credential");await x(r,i);return}if(await g(a.jti))throw p("model_credential");const c=s.provider;if(typeof c!="string"||!L(c))throw new u(400,"invalid_request",`provider must be one of ${y.join(", ")}`,"provider");if(typeof o!="string"||o.trim()==="")throw new u(400,"invalid_request","api_key is required","api_key");try{await H(c,s.models)}catch(i){throw i instanceof b?new u(400,"invalid_request",i.message,"models"):i}if(E()===null)throw new u(503,"runtime_starting","this runtime has not joined a directory yet");if(!await P(a.jti,a.exp))throw p("model_credential");const d=T();await j(a.jti,d);try{if((await N(c,o.trim(),s.models,d)).activationId===null)throw new u(503,"runtime_starting","this runtime has not joined a directory yet")}catch(i){throw await I(d)||await U(a.jti),v({level:"error",event:"key_signin.save_failed",error:i,fields:{provider:c}}),i instanceof b?new u(400,"invalid_request",i.message,"models"):i}v({level:"info",event:"key_signin.saved",fields:{provider:c,activation_id:d}}),await x(r,d)}l(V,"save");async function x(e,r){const t=await A(r);k(e,200,t.status==="acknowledged"?{status:"active",trial:t.trial}:{status:"saved",ack:"pending"})}l(x,"answer");function F(e,r){const t=_(16).toString("base64");e.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store","Referrer-Policy":"no-referrer","X-Content-Type-Options":"nosniff","Content-Security-Policy":`default-src 'none'; script-src 'nonce-${t}'; style-src 'nonce-${t}'; connect-src 'self'; form-action 'none'; base-uri 'none'; frame-ancestors 'none'`}),e.end(Z(t,new URL(r.issuer).origin))}l(F,"servePage");const X=[{id:"ultra",label:"Ultra"},{id:"strong",label:"Strong"},{id:"medium",label:"Medium"},{id:"light",label:"Light"}],Q=`
|
|
2
|
+
.lead{color:var(--muted)}
|
|
3
|
+
select,input[type=password]{width:100%;min-width:0;height:2.75rem;padding:0 .875rem;background:var(--surface);color:var(--text);border:1px solid var(--line-strong);border-radius:8px;font:400 .9375rem/1.5 var(--sans)}
|
|
4
|
+
input[type=password]{height:3rem;font-family:var(--mono)}
|
|
5
|
+
select:focus,input[type=password]:focus{outline:2px solid var(--focus);outline-offset:2px}
|
|
6
|
+
select:disabled{color:var(--disabled);border-color:var(--line);cursor:default}
|
|
7
|
+
select[aria-invalid=true],input[type=password][aria-invalid=true]{border-color:var(--danger-line)}
|
|
8
|
+
fieldset{margin:0;padding:0;border:0;display:flex;flex-direction:column;gap:.75rem;min-width:0}
|
|
9
|
+
legend{padding:0;margin-bottom:.25rem;font-weight:500}
|
|
10
|
+
.strengths{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:.75rem}
|
|
11
|
+
#key-form{gap:1.25rem}
|
|
12
|
+
.alert.info{background:var(--zone)}
|
|
13
|
+
.alert.info>.ic{color:var(--muted)}
|
|
14
|
+
.done-mark{display:flex;align-items:center;justify-content:center;width:3.5rem;height:3.5rem;flex:none;border-radius:12px;background:var(--accent-subtle);color:var(--accent-fg)}
|
|
15
|
+
.done-mark .ic{width:1.5rem;height:1.5rem}
|
|
16
|
+
.loading{display:flex;align-items:center;gap:.75rem;color:var(--muted)}
|
|
17
|
+
.loading .spin{width:1rem;height:1rem;color:var(--accent-fg);fill:none;stroke:currentColor;stroke-width:3;stroke-linecap:round}
|
|
18
|
+
@media (prefers-reduced-motion:no-preference){.loading .spin{animation:spin 1s linear infinite}}
|
|
19
|
+
@media (max-width:30rem){.strengths{grid-template-columns:minmax(0,1fr)}}
|
|
20
|
+
`,W=`
|
|
21
|
+
(function(){
|
|
22
|
+
function $(id){return document.getElementById(id);}
|
|
23
|
+
var frag=new URLSearchParams(location.hash.slice(1));
|
|
24
|
+
var cfg=JSON.parse($('cfg').textContent);
|
|
25
|
+
var handoff=frag.get('handoff'),returnTo=frag.get('return_to');
|
|
26
|
+
history.replaceState(null,'',location.pathname);
|
|
27
|
+
// Only a return_to on the directory's origin is ever linked or redirected to.
|
|
28
|
+
try{if(returnTo&&new URL(returnTo).origin!==cfg.directory)returnTo=null;}catch(e){returnTo=null;}
|
|
29
|
+
var auth={'Authorization':'Bearer '+handoff};
|
|
30
|
+
var providers=[];
|
|
31
|
+
function show(id){['loading','form-card','pending-card','done-card','stop-card'].forEach(function(x){$(x).hidden=x!==id;});}
|
|
32
|
+
function stop(title,text){$('stop-title').textContent=title;$('stop-text').textContent=text;$('stop-back').hidden=!returnTo;show('stop-card');}
|
|
33
|
+
function backUrl(status){var u=new URL(returnTo);if(status)u.searchParams.set('status',status);return u.toString();}
|
|
34
|
+
function used(){stop('This link no longer works','It has expired or was already used. Go back to your account and choose Add an API key again.');}
|
|
35
|
+
if(returnTo){$('stop-back').href=backUrl();}
|
|
36
|
+
if(!handoff||!returnTo){stop('This link is incomplete','Go back to your account and choose Add an API key again.');return;}
|
|
37
|
+
function setError(msg){$('error-text').textContent=msg;$('error').className=msg?'err on':'err';}
|
|
38
|
+
var form=$('key-form'),providerSel=$('provider'),keyInput=$('api-key'),strengths=['ultra','strong','medium','light'];
|
|
39
|
+
function fillModels(){
|
|
40
|
+
var p=providers.filter(function(x){return x.id===providerSel.value;})[0];
|
|
41
|
+
strengths.forEach(function(s){
|
|
42
|
+
var sel=$('model-'+s);sel.innerHTML='';sel.removeAttribute('aria-invalid');
|
|
43
|
+
var none=document.createElement('option');none.value='';none.textContent=p?'Choose a model':'Choose a provider first';none.disabled=true;none.selected=true;sel.appendChild(none);
|
|
44
|
+
(p?p.models:[]).forEach(function(m){var o=document.createElement('option');o.value=p.id+'/'+m.id;o.textContent=m.name;sel.appendChild(o);});
|
|
45
|
+
sel.disabled=!p;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
fetch('${h}?return_to='+encodeURIComponent(returnTo),{headers:auth})
|
|
49
|
+
.then(function(r){return r.json().then(function(b){return {s:r.status,b:b};});})
|
|
50
|
+
.then(function(x){
|
|
51
|
+
if(x.s===401){used();return;}
|
|
52
|
+
if(x.s!==200){stop('Something went wrong',(x.b&&x.b.error&&x.b.error.message)||'Your runtime could not load this page. Try again in a moment.');return;}
|
|
53
|
+
providers=x.b.providers;
|
|
54
|
+
providers.forEach(function(p){var o=document.createElement('option');o.value=p.id;o.textContent=p.name;providerSel.appendChild(o);});
|
|
55
|
+
fillModels();show('form-card');
|
|
56
|
+
})
|
|
57
|
+
.catch(function(){stop('Could not reach your runtime','Check your connection and reload this page.');});
|
|
58
|
+
providerSel.addEventListener('change',fillModels);
|
|
59
|
+
function post(body){
|
|
60
|
+
return fetch('${f}',{method:'POST',headers:Object.assign({'Content-Type':'application/json'},auth),body:JSON.stringify(body)})
|
|
61
|
+
.then(function(r){return r.json().then(function(b){return {s:r.status,b:b};});});
|
|
62
|
+
}
|
|
63
|
+
function outcome(x){
|
|
64
|
+
if(x.s===200&&x.b.status==='active'){$('done-back').href=backUrl('connected');show('done-card');$('done-back').focus();return true;}
|
|
65
|
+
if(x.s===200&&x.b.status==='saved'){show('pending-card');return true;}
|
|
66
|
+
if(x.s===401){used();return true;}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
form.addEventListener('submit',function(e){
|
|
70
|
+
e.preventDefault();setError('');
|
|
71
|
+
var bad=null;
|
|
72
|
+
if(!providerSel.value)bad=bad||providerSel;
|
|
73
|
+
keyInput.removeAttribute('aria-invalid');
|
|
74
|
+
if(!keyInput.value.trim()){keyInput.setAttribute('aria-invalid','true');bad=bad||keyInput;}
|
|
75
|
+
var models={};
|
|
76
|
+
strengths.forEach(function(s){var sel=$('model-'+s);sel.removeAttribute('aria-invalid');if(!sel.value){sel.setAttribute('aria-invalid','true');bad=bad||sel;}else models[s]=sel.value;});
|
|
77
|
+
if(bad){setError(!providerSel.value?'Choose a provider.':!keyInput.value.trim()?'Paste your API key.':'Choose a model for every strength.');bad.focus();return;}
|
|
78
|
+
var button=$('save');button.disabled=true;$('save-label').textContent='Saving\\u2026';
|
|
79
|
+
post({provider:providerSel.value,api_key:keyInput.value.trim(),models:models}).then(function(x){
|
|
80
|
+
// A 401 may mean this handoff's save already went through and its answer was lost: ask for that save's acknowledgement.
|
|
81
|
+
return x.s===401?post({}):x;
|
|
82
|
+
}).then(function(x){
|
|
83
|
+
if(outcome(x)){keyInput.value='';return;}
|
|
84
|
+
setError((x.b&&x.b.error&&x.b.error.message)||'Your key was not saved. Try again.');
|
|
85
|
+
}).catch(function(){setError('Could not reach your runtime. Try again.');})
|
|
86
|
+
.then(function(){button.disabled=false;$('save-label').textContent='Save key';});
|
|
87
|
+
});
|
|
88
|
+
$('retry').addEventListener('click',function(){
|
|
89
|
+
var button=$('retry');button.disabled=true;
|
|
90
|
+
// The handoff's save is already stored: a retry carries no key and only asks for that save's acknowledgement.
|
|
91
|
+
post({}).then(function(x){if(!outcome(x)){$('pending-text').textContent='Northlight still has not confirmed it. Try again in a moment.';}})
|
|
92
|
+
.catch(function(){$('pending-text').textContent='Could not reach your runtime. Try again in a moment.';})
|
|
93
|
+
.then(function(){button.disabled=false;});
|
|
94
|
+
});
|
|
95
|
+
})();
|
|
96
|
+
`;function Z(e,r){const t=l(n=>`<div class="field"><label for="model-${n.id}">${n.label}</label><select id="model-${n.id}" name="${n.id}" required disabled></select></div>`,"strengthField");return G({nonce:e,title:"Add an API key",style:Q,script:W,config:{directory:r},body:`<div class="card" id="loading"><div class="loading" aria-live="polite">
|
|
97
|
+
<svg class="spin" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M21 12a9 9 0 1 1-9-9"/></svg><span>Loading\u2026</span></div></div>
|
|
98
|
+
<div class="card" id="form-card" hidden>
|
|
99
|
+
<div><h1>Add an API key</h1><p class="lead">Your key goes straight to your runtime, where it is stored encrypted.</p></div>
|
|
100
|
+
<form id="key-form" autocomplete="off" novalidate>
|
|
101
|
+
<div class="field"><label for="provider">Provider</label><select id="provider" name="provider" required><option value="" disabled selected>Choose a provider</option></select></div>
|
|
102
|
+
<div class="field"><label for="api-key">API key</label><input type="password" id="api-key" name="api_key" required spellcheck="false" autocapitalize="off" autocomplete="off"></div>
|
|
103
|
+
<fieldset><legend>Model for each strength</legend>
|
|
104
|
+
<p class="small">Northlight's apps ask for a strength, from Ultra (the most capable) to Light (the fastest). The model you choose for a strength answers those requests.</p>
|
|
105
|
+
<div class="strengths">${X.map(t).join("")}</div>
|
|
106
|
+
</fieldset>
|
|
107
|
+
<div class="alert info">${m("alert")}<div class="text">Some models may not work well with Northlight's apps.</div></div>
|
|
108
|
+
<div id="error" class="err" role="alert">${m("alert")}<span id="error-text"></span></div>
|
|
109
|
+
<button class="btn primary lg wide" type="submit" id="save"><span id="save-label">Save key</span></button>
|
|
110
|
+
</form>
|
|
111
|
+
</div>
|
|
112
|
+
<div class="card" id="pending-card" hidden>
|
|
113
|
+
<div class="alert" role="alert">${m("warn")}<div class="text"><strong>Your key is saved, but the switch is not confirmed yet</strong><span id="pending-text">Northlight has not confirmed the change. Try again in a moment.</span></div>
|
|
114
|
+
<div class="act"><button class="btn primary sm" type="button" id="retry">Try again</button></div></div>
|
|
115
|
+
</div>
|
|
116
|
+
<div class="card" id="done-card" hidden>
|
|
117
|
+
<div class="head"><div class="done-mark">${m("check")}</div><h1>Your API key is on</h1></div>
|
|
118
|
+
<p>Your agents now use your key.</p>
|
|
119
|
+
<a class="btn primary lg wide" id="done-back" href="#">Back to your account</a>
|
|
120
|
+
</div>
|
|
121
|
+
<div class="card" id="stop-card" hidden>
|
|
122
|
+
<div><h1 id="stop-title"></h1><p class="lead" id="stop-text"></p></div>
|
|
123
|
+
<a class="btn" id="stop-back" href="#" hidden>Back to your account</a>
|
|
124
|
+
</div>`})}l(Z,"keyPage");export{f as KEY_SIGNIN_PATH,me as handleRuntimeSignIn,pe as isRuntimeSignInPath,Z as keyPage};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JwksCache, type CallToken, type Scope } from '@north-light/identity';
|
|
2
2
|
import type { ActiveGrant, GrantDependencies, GrantScope } from '../../core/grants/mirror.js';
|
|
3
|
+
import { RunError } from '../../core/runs/operations.js';
|
|
3
4
|
import { type NoticeTicket } from './sync-notice.js';
|
|
4
5
|
export interface AppPrincipal {
|
|
5
6
|
sub: string;
|
|
@@ -13,7 +14,11 @@ export interface AppPrincipal {
|
|
|
13
14
|
dependencies: GrantDependencies;
|
|
14
15
|
exp: number;
|
|
15
16
|
}
|
|
16
|
-
/**
|
|
17
|
+
/** What a directory handoff authorizes: a vendor sign-in, or saving an API key with its model mapping. */
|
|
18
|
+
export type HandoffPurpose = 'vendor_sign_in' | 'model_credential';
|
|
19
|
+
/** The 401 for a handoff that does not verify; one message per purpose, shared by the resolver and the vendor and key pages. */
|
|
20
|
+
export declare function unauthorizedHandoff(purpose: HandoffPurpose): RunError;
|
|
21
|
+
/** A verified directory handoff (directory spec, Interfaces → Runtime). */
|
|
17
22
|
export interface VendorHandoff {
|
|
18
23
|
sub: string;
|
|
19
24
|
jti: string;
|
|
@@ -38,11 +43,11 @@ export declare class AppPrincipalResolver {
|
|
|
38
43
|
/** A directory sync notice authorizes one grant sync and nothing else.
|
|
39
44
|
* Returns null for a replay of a notice already accepted. */
|
|
40
45
|
verifySyncNotice(authorization: string | undefined): Promise<NoticeTicket | null>;
|
|
41
|
-
/** Verify a directory `
|
|
46
|
+
/** Verify a directory handoff for `purpose`: ES256 signature against the
|
|
42
47
|
* JWKS mirror, `iss`, `aud`, `exp`, `purpose`, and that `jti` and `sub` are
|
|
43
48
|
* present (runtime spec §7 "Vendor sign-in page", RT-LLM-52). The owner and
|
|
44
49
|
* single-use `jti` checks are the caller's. Every failure is 401. */
|
|
45
|
-
verifyHandoff(token: string | undefined): Promise<VendorHandoff>;
|
|
50
|
+
verifyHandoff(token: string | undefined, accepted: HandoffPurpose): Promise<VendorHandoff>;
|
|
46
51
|
/** Verify a directory read token (`Authorization: Bearer <ES256 JWT>`): signature
|
|
47
52
|
* against the JWKS mirror, `iss`, `aud`, `exp`, and that `purpose` is exactly
|
|
48
53
|
* the one this route accepts. It names no owner and is not single-use, so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var v=Object.defineProperty;var o=(a,e)=>v(a,"name",{value:e,configurable:!0});import{covers as m,JwksCache as p,MissingRevClaimError as _,verifyCallToken as b}from"@north-light/identity";import{createLocalJWKSet as l,decodeProtectedHeader as h,jwtVerify as f}from"jose";import{callerGrantOf as k,coverGrant as x}from"../../core/grants/cover.js";import{RunError as n}from"../../core/runs/operations.js";import{NoticeLedger as E}from"./sync-notice.js";function C(a){return new n(401,"unauthorized",a==="vendor_sign_in"?"invalid vendor sign-in handoff":"invalid key handoff")}o(C,"unauthorizedHandoff");class q{static{o(this,"AppPrincipalResolver")}issuer;audience;syncGrants;cache;ready=!1;timer;constructor(e,t,r,i){this.issuer=e,this.audience=t,this.syncGrants=r,this.cache=new p(e,fetch,i),this.load(),this.timer=setInterval(()=>{this.ready||this.load()},5e3),this.timer.unref()}async load(){try{await this.cache.load(),this.ready=!0}catch{}}isReady(){return this.ready}get jwks(){return this.cache}close(){this.timer&&clearInterval(this.timer)}ledger=new E;async verifySyncNotice(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");return this.ledger.accept(e,this.cache,this.issuer,this.audience)}async verifyHandoff(e,t){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const r=o(()=>C(t),"refuse");if(!e)throw r();let i;try{const u=h(e);if(u.alg!=="ES256")throw r();const g=await this.cache.forKid(u.kid);({payload:i}=await f(e,l(g),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp","jti","sub"]}))}catch{throw r()}const{sub:s,jti:c,exp:d,purpose:w,aud:y}=i;if(w!==t||y!==this.audience||typeof s!="string"||typeof c!="string"||c===""||typeof d!="number")throw r();return{sub:s,jti:c,exp:d}}async verifyDirectoryRead(e,t){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");const r=o(()=>new n(401,"unauthorized","invalid directory token"),"refuse");if(!e?.startsWith("Bearer ")||e.length<=7)throw r();const i=e.slice(7);let s;try{const c=h(i);if(c.alg!=="ES256")throw r();const d=await this.cache.forKid(c.kid);({payload:s}=await f(i,l(d),{issuer:this.issuer,audience:this.audience,algorithms:["ES256"],requiredClaims:["exp"]}))}catch{throw r()}if(s.purpose!==t||s.aud!==this.audience)throw r()}async verifyCall(e){if(!this.ready)throw new n(503,"runtime_starting","runtime_starting");if(!e?.startsWith("Bearer ")||e.length<=7)throw new n(401,"unauthorized","a directory access token is required");const t=e.slice(7);try{if(h(t).alg!=="ES256")throw new Error("Invalid call token header");return await b({token:t,jwks:this.cache,issuer:this.issuer,audience:this.audience})}catch(r){throw r instanceof _?new n(401,"unauthorized",r.message):new n(401,"unauthorized","invalid directory access token")}}async resolve(e,t){return this.resolveVerified(await this.verifyCall(e),t)}async resolveVerified(e,t){const r=e.chain[0],i=e.claims;if(e.chain.length!==1||!r||!r.sub.startsWith("app:")||r.grant===void 0||r.rev===void 0||!/^[A-Za-z0-9_-]{1,64}$/.test(i.client_id)||i.grantee!==void 0&&i.grantee!==r.sub||i.rev!==void 0&&i.rev!==r.rev)throw new n(401,"unauthorized","invalid directory access token");const s=await x(r.grant,r.rev,e.sub,r.sub,this.syncGrants);if(t&&!s.resolved.some(c=>m(c,t)))throw new n(403,"scope_missing",`missing scope ${t}`,void 0,void 0,t);return{sub:e.sub,grantee:r.sub,client_id:i.client_id,grant:r.grant,rev:s.rev,resolved:s.resolved,resolved_scopes:s.resolved_scopes,spend_cap:s.spend_cap,dependencies:s.dependencies??{},exp:i.exp}}}async function H(a){return await k(a.grant,a.sub,a.grantee)}o(H,"callerGrant");export{q as AppPrincipalResolver,H as callerGrant,C as unauthorizedHandoff};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ie=Object.defineProperty;var s=(e,r)=>Ie(e,"name",{value:r,configurable:!0});import{IMPORT_TOKEN_PREFIX as ze,importPrincipalFor as He}from"./import-auth.js";import{createServer as ie}from"node:http";import{createServer as Le}from"node:https";import{chmodSync as Be,existsSync as G,readFileSync as se,unlinkSync as ae}from"node:fs";import{MINIMUM_RUNTIME_VERSION_HEADER as le,RUNTIME_VERSION_HEADER as Y,minimumRuntimeRefusal as xe}from"../../api/runtime-version.js";import{CONTRACT_HEADER as K,CONTRACT_LEVEL as ce,REQUIRED_CONTRACT_HEADER as ue,contractRefusal as De}from"../../api/contract.js";import{crtrVersion as X}from"../../shared/crtr-version.js";import{apiSocketPath as Me}from"../../core/canvas/paths.js";import{resolveNodeToken as Fe}from"../../core/canvas/node-tokens.js";import{isCloudRole as H,runAsPerson as $}from"../../core/canvas/person.js";import{personBearerVerifier as pe}from"./auth/person-bearer.js";import{personHasSnapshot as Z}from"../../core/scoped-state/person-store.js";import{loadPersonSettings as Q}from"../../core/scoped-state/person-rows.js";import{AppPrincipalResolver as Ve}from"./principal.js";import{createAppRequestHandler as $e}from"./app-listener.js";import{decodeJwt as Je}from"jose";import{handleVendorSignIn as We,isVendorSignInPath as je}from"./vendor-signin.js";import{RunError as S}from"../../core/runs/operations.js";import{removeVendorAccount as Ge,vendorStatus as Ye}from"./handlers/vendor-status.js";import{toErrorBody as Ke}from"./map.js";import{CONTROL_BODY_MAX_BYTES as Xe}from"../../core/llm/body-limits.js";import{grantFor as Ze,hasSyncedGrants as Qe}from"../../core/grants/mirror.js";import{readConfig as de}from"../../core/config.js";import{directoryIssuer as qe}from"../../core/directory/issuer.js";import{peerUid as er}from"../../native/linux.js";import{findScopedApiToken as rr,getApiToken as tr,listScopedApiTokens as nr}from"../../core/secrets.js";import{emitEvent as A}from"../../core/events/emit.js";import{envCrtrdTcp as or,envCrtrdToken as ir}from"../../shared/env.js";import{Router as fe,actsAsPerson as me}from"./router.js";import{handleAttachUpgrade as sr,refuseUpgrade as y}from"./bridge.js";import{handleMachineLinkUpgrade as ar,machineLinkEnvironment as lr,setApiAddress as cr}from"../machine-link/holder.js";import{handleMachineViewUpgrade as ur,machineViewEnvironment as pr}from"../machine-link/forward.js";import{boundDaemonControl as dr}from"../control.js";import{attachRoutes as fr,mayAttachNode as ge}from"./handlers/attach.js";import{peerRoutes as mr}from"../peer/handlers.js";import{bashJobRoutes as gr}from"./handlers/bash-jobs.js";import{bashRoutes as hr}from"./handlers/bash.js";import{hookExecRoutes as Rr}from"./handlers/hook-exec.js";import{brokerOperationRoutes as he}from"./handlers/broker-ops.js";import{brokerSignalRoutes as Ar,brokerSignalStreams as yr}from"./handlers/broker-signals.js";import{brokerRecoveryRoutes as Re,nodeFaultRoutes as vr}from"./handlers/broker-recovery.js";import{canvasRoutes as _r}from"./handlers/canvas.js";import{conversationRoutes as wr}from"./handlers/conversations.js";import{chatInventoryRoutes as Er}from"./handlers/chat-inventory.js";import{daemonRoutes as Sr}from"./handlers/daemon.js";import{fileRoutes as br}from"./handlers/files.js";import{focusRoutes as Tr}from"./handlers/focus.js";import{analyticsRoutes as Cr}from"./handlers/analytics.js";import{memoryReadsRoutes as kr}from"./handlers/memory-reads.js";import{memoryRoutes as Ur}from"./handlers/memory.js";import{healthRoutes as Or}from"./handlers/health.js";import{humanRequestRoutes as Pr}from"./handlers/human-requests.js";import{inboxRoutes as Nr}from"./handlers/inbox.js";import{feedbackCommentRoutes as Ir}from"./handlers/feedback-comments.js";import{objectRoutes as zr}from"./handlers/objects.js";import{shareRoutes as Hr}from"./handlers/shares.js";import{customObjectRoutes as Lr}from"./handlers/custom-objects.js";import{docRoutes as Br}from"./handlers/docs.js";import{deliveryRoutes as Ae}from"./handlers/delivery.js";import{deliveryRetryRoutes as xr}from"./handlers/delivery-retry.js";import{packageDocRoutes as Dr}from"./handlers/package-docs.js";import{documentAccessRoutes as Mr}from"./handlers/document-access.js";import{pluginAppRoutes as Fr}from"./handlers/plugin-app-token.js";import{brokerMailRoutes as ye,messageRoutes as Vr}from"./handlers/messages.js";import{modelAuthRoutes as $r}from"./handlers/modelauth.js";import{llmRoutes as Jr}from"./handlers/llm.js";import{providerRoutes as Wr}from"./handlers/providers.js";import{modelConfigRoutes as jr}from"./handlers/model-config.js";import{settingsRoutes as Gr}from"./handlers/settings.js";import{nodeRoutes as Yr}from"./handlers/nodes.js";import{nodeRecordRoutes as Kr}from"./handlers/node-records.js";import{nodeOutcomeRoutes as Xr}from"./handlers/node-outcomes.js";import{nodeEventRoutes as Zr}from"./handlers/node-events.js";import{profileRoutes as Qr}from"./handlers/profiles.js";import{prospectiveChatInventoryRoutes as qr}from"./handlers/prospective-chat-inventory.js";import{reportRoutes as et}from"./handlers/reports.js";import{runRoutes as rt}from"./handlers/run-routes.js";import{reviewCommentRoutes as tt}from"./handlers/review-comments.js";import{reviewRoutes as nt}from"./handlers/reviews.js";import{subscriptionRoutes as ot}from"./handlers/subscriptions.js";import{structuredRequestRoutes as it}from"./handlers/structured-requests.js";import{cronRoutes as st}from"./handlers/crons.js";import{setCronRequestHandler as ve}from"../cron/run-socket.js";import{RUN_TOKEN_PREFIX as at,cronPrincipalForRunToken as lt}from"../cron/run-token.js";import{worktreeRoutes as ct}from"./handlers/worktree.js";import{limitsRoutes as ut}from"./handlers/limits.js";import{chargeRoutes as pt,spendLimitRoutes as dt}from"./handlers/charges.js";import{executionStartRoutes as ft}from"./handlers/execution-start.js";import{machineCredentialRoutes as mt}from"./handlers/machine-credential.js";import{importRoutes as gt}from"./handlers/imports.js";import{gitCredentialRoutes as ht}from"./handlers/git-credential.js";function Rt(e){return new fe().registerAll(Or(e)).registerAll(Sr).registerAll(Hr).registerAll(Yr).registerAll(Kr).registerAll(Xr).registerAll(xr).registerAll(Zr).registerAll(gr).registerAll(hr).registerAll(Rr).registerAll(he).registerAll(Ar).registerAll(Ae).registerAll(Re).registerAll(vr).registerAll(ct).registerAll(ut).registerAll(pt).registerAll(ft).registerAll(mt).registerAll(gt).registerAll(ht).registerAll(dt).registerAll(ye).registerAll(Vr).registerAll(et).registerAll(rt).registerAll(it).registerAll(fr).registerAll(_r).registerAll(wr).registerAll(Cr).registerAll(kr).registerAll(Ur).registerAll(br).registerAll(zr).registerAll(Lr).registerAll(Br).registerAll(Dr).registerAll(Mr).registerAll(Fr).registerAll(Tr).registerAll(ot).registerAll(st).registerAll(Qr).registerAll($r).registerAll(Jr).registerAll(Wr).registerAll(jr).registerAll(Gr).registerAll(nt).registerAll(tt).registerAll(Nr).registerAll(Pr).registerAll(Er).registerAll(qr).registerAll(Ir).registerAll(mr)}s(Rt,"buildRouter");function At(e,r){if(e.toUpperCase()!=="GET")return null;const o=r.split("/").filter(u=>u.length>0);if(o.length!==4||o[0]!=="v1"||o[1]!=="nodes"||o[3]!=="attach")return null;const a=o[2];return a===void 0||a===""?null:decodeURIComponent(a)}s(At,"attachNodeId");function yt(e){const r=e.trim();if(r==="")return null;const o=r.lastIndexOf(":");if(o<0)return null;const a=r.slice(0,o),u=r.slice(o+1),d=Number(u);return!Number.isInteger(d)||d<0||d>65535?null:{host:a===""?"0.0.0.0":a,port:d}}s(yt,"parseTcp");function vt(e,r){return`${e.includes(":")?`[${e}]`:e}:${r}`}s(vt,"formatTcpAddress");const P={code:"unauthorized",message:"missing or invalid bearer token"},L={code:"owner_only",message:"attach is owner-only; a scoped token does not reach it"},M={code:"person_bearer_not_supported",message:"this listener accepts a person bearer only on a cloud role with CRTR_DIRECTORY_URL and CRTR_PUBLIC_API_URL set; call with a node, app or public token"},q={class:"anonymous",app:"",node:"",run:null,uid:-1,sub:"",grant:null,client_id:null,scopes:[]},B=new WeakMap;function F(e){return B.get(e)}s(F,"socketPrincipal");async function _e(e,r){const o=process.platform==="linux"?er(e.socket):null,a=e.headers.authorization;if(a===void 0)return o===null||r.has(o)?{class:"person"}:"unauthorized";if(typeof a!="string"||!a.startsWith("Bearer "))return"unauthorized";if(a.slice(7).startsWith("crtr_pub_"))return q;if(a.slice(7).startsWith(ee)){const u=be(a.slice(7));return u!==void 0&&(o===null||r.has(o))?u.principal:"unauthorized"}return we(a.slice(7),o)}s(_e,"resolveSocketPrincipal");async function we(e,r){const o=await Fe(e);if(!o||r!==null&&r!==o.uid)return"unauthorized";const a=qe();if(a&&!H()&&!await Qe(a))return"runtime_starting";const u=o.grant??(await Ze("app:terminal",o.sub))?.id??null;return{class:"broker",...o,grant:u}}s(we,"brokerPrincipal");function Ee(e){if(!(e.class==="anonymous"||e.class==="import"))return e.sub!==void 0&&e.sub!==""?e.sub:void 0}s(Ee,"requestPerson");function Se(e,r){r.class==="broker"&&A({event:"api.request.principal",level:r.app==="app:terminal"?"debug":"info",node_id:r.node,fields:{principal:`${r.app} node:${r.node}`,method:e.method,path:e.url}})}s(Se,"noteBrokerRequest");const ee="crtr_app_";function be(e){const r=e.startsWith(ee)?rr(e):void 0;return r===void 0?void 0:{principal:{class:"app",app:r.grantee,scopes:r.scopes},ceiling:r.scopes}}s(be,"appBearer");function _t(e){const r=new Map;for(const o of nr("user"))r.set(o.token,{principal:{class:"app",app:o.grantee,scopes:o.scopes},ceiling:o.scopes});return e!==void 0&&r.set(e,{principal:{class:"person"},ceiling:null}),r}s(_t,"resolveBearers");function wt(e){try{return Je(e).act!==void 0}catch{return!1}}s(wt,"carriesAct");const Et=/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/;function k(e,r){return e!==void 0&&(e.reason=r),"unauthorized"}s(k,"deny");async function Te(e,r,o){const a=e.headers.authorization;if(a===void 0&&(e.method??"GET").toUpperCase()==="GET"&&(e.url??"").split("?")[0]==="/healthz")return{principal:q,ceiling:null};if(typeof a!="string"||!a.startsWith("Bearer "))return k(o,a===void 0?"no_authorization_header":"not_a_bearer");const u=a.slice(7);if(u.startsWith("crtr_pub_"))return{principal:q,ceiling:null};if(u.startsWith(ee))return be(u)??k(o,"app_token_unknown");if(u.startsWith(at)){const _=await lt(u);return _===null?k(o,"run_token_invalid_or_settled"):{principal:_,ceiling:null}}const d=r.get(u);if(d!==void 0)return d;const R=He(u);if(R!==null)return{principal:R,ceiling:null};if(u.startsWith(ze))return k(o,"import_token_invalid");if(Et.test(u)){if(H()&&wt(u)){const x=W();if(x===null)return"person_bearer";try{const w=await x.verifyCall(a);return w.chain[0]?.sub.startsWith("app:")?{call:w}:k(o,"call_token_presenter_not_an_app")}catch(w){return w instanceof S&&w.status===503?"runtime_starting":k(o,`call_token_${w instanceof S?w.code:"invalid"}`)}}const _=H()?pe():null;if(_===null)return"person_bearer";const U=await _.verify(u);return U===null?k(o,"person_bearer_not_verified"):{principal:{class:"person",sub:U},ceiling:null}}const m=await we(u,null);return m==="unauthorized"?k(o,"node_token_unknown"):typeof m=="string"?m:{principal:m,ceiling:null}}s(Te,"authorizeTcp");let J;function W(){if(J!==void 0)return J;const e=process.env.CRTR_DIRECTORY_URL||void 0,r=process.env.CRTR_PUBLIC_API_URL||void 0;return J=e===void 0||r===void 0?null:new Ve(e,r,async()=>{}),J}s(W,"cloudCallResolver");let Ce;function St(){const e=W();if(e===null)throw new S(503,"runtime_starting","app calls are not configured on this listener");return Ce??=$e(e,async()=>!0,async()=>{}),Ce}s(St,"cloudAppCalls");async function bt(e,r){N(r),I(r);const o=W();try{if(o===null)throw new S(503,"runtime_starting","vendor sign-in is not configured on this listener");await We(e,r,new URL(e.url??"/","http://runtime.local"),o)}catch(a){if(!(a instanceof S))throw a;if(r.headersSent){r.destroy();return}r.writeHead(a.status,{"content-type":"application/json; charset=utf-8","cache-control":"no-store"}),r.end(JSON.stringify({error:{code:a.code,message:a.message,...a.param?{param:a.param}:{},origin:"runtime"}}))}}s(bt,"serveVendorSignIn");function Tt(){const e=process.env.CRTRD_TLS_CERT||void 0,r=process.env.CRTRD_TLS_KEY||void 0;if(e===void 0&&r===void 0)return null;if(e===void 0||r===void 0)throw new Error("CRTRD_TLS_CERT and CRTRD_TLS_KEY must be set together");return{cert:se(e),key:se(r)}}s(Tt,"tcpTls");function N(e){e.setHeader(Y,X()),e.setHeader(K,ce)}s(N,"advertiseRuntime");function I(e){e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Expose-Headers",`${Y}, ${K}`)}s(I,"exposeRuntimeHeaders");function Ct(e,r){return(e.method??"GET").toUpperCase()!=="OPTIONS"?!1:(N(r),r.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Expose-Headers":`${Y}, ${K}`,"Access-Control-Allow-Headers":`authorization, content-type, ${le.toLowerCase()}, ${ue.toLowerCase()}`,"Access-Control-Allow-Methods":"GET, POST, PATCH, PUT, DELETE, OPTIONS","Access-Control-Max-Age":"600"}),r.end(),!0)}s(Ct,"answerPreflight");function j(e,r=!1){N(e),r&&I(e),e.writeHead(401,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{...P,origin:"runtime"}}))}s(j,"writeUnauthorized");function kt(e){N(e),I(e),e.writeHead(401,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{...M,origin:"runtime"}}))}s(kt,"writePersonBearerRefused");const Ut={"/v1/runtime/vendor-status":{method:"GET",purpose:"vendor_status"},"/v1/runtime/vendor-account-remove":{method:"POST",purpose:"vendor_account_remove"}};async function Ot(e,r){if(!H())return!1;const o=new URL(e.url??"/","http://runtime.local").pathname,a=Ut[o];if(a===void 0||e.method!==a.method)return!1;const u=s((d,R)=>{N(r),I(r),r.writeHead(d,{"content-type":"application/json; charset=utf-8"}),r.end(JSON.stringify(R))},"answer");try{const d=pe();if(d===null)throw new S(401,M.code,M.message);const R=e.headers.authorization,m=R?.startsWith("Bearer ")?await d.verifyPurpose(R.slice(7),a.purpose):null;if(m===null)throw new S(401,"unauthorized","invalid directory token");const _=a.purpose==="vendor_status"?void 0:await Pt(e);u(200,await $(m,async()=>a.purpose==="vendor_status"?Ye():await Ge(_)))}catch(d){const{status:R,body:m}=Ke(d);u(R,m)}return!0}s(Ot,"serveCloudVendorRoute");async function Pt(e){const r=[];let o=0;for await(const a of e){if(o+=a.length,o>Xe)throw new S(400,"invalid_request","request body too large");r.push(a)}if(o!==0)try{return JSON.parse(Buffer.concat(r).toString("utf8"))}catch{throw new S(400,"invalid_request","invalid JSON body")}}s(Pt,"readVendorBody");function ke(e){N(e),e.writeHead(503,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{code:"runtime_starting",message:"grant sync is not ready",type:"server_error",origin:"runtime",retryable:!0}}))}s(ke,"writeRuntimeStarting");function Nt(e,r){e.writeHead(503,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{code:"startup_blocked",message:r,origin:"runtime"}}))}s(Nt,"writeStartupBlocked");function Ue(e,r,o){return new Promise(a=>{if(o===void 0){try{e.closeAllConnections()}catch{}e.close(()=>a());return}const u=[];e.close(()=>{for(const m of u)clearTimeout(m);a()});for(const m of r)m.destroy();const d=setInterval(()=>e.closeIdleConnections(),250),R=setTimeout(()=>e.closeAllConnections(),o);u.push(d,R),e.closeIdleConnections()})}s(Ue,"closeServer");function vo(e={}){let r=null;const o=Rt(()=>r),a=new fe().registerAll(he).registerAll(Ae).registerAll(Re).registerAll(ye),u=s((t,n)=>{const c=dr()?.startupBlock()??null;return c===null||t==="GET"&&(n==="/healthz"||n==="/v1/status"||n==="/v1/ready")||t==="POST"&&(n==="/v1/daemon/migrate"||n==="/v1/daemon/admit")||c.phase==="recovering"&&a.match(t,n)!==null?null:c},"startupBlockFor"),d=e.socketPath??Me(),R=new Set([process.getuid?.()??0,...de("user").runtime?.person_uids??[]]),m=s((t,n,c)=>{N(n);const p=s(i=>Array.isArray(i)?i[0]:i,"first"),O=p(t.headers[le.toLowerCase()]),h=xe(O,X())??De(p(t.headers[ue.toLowerCase()]),ce,{legacyMinimum:O,runtimeVersion:X()});if(h!==null){n.writeHead(h.status,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:h.code,message:h.message,type:"invalid_request_error",origin:"runtime",retryable:!1,..."param"in h?{param:h.param}:{details:h.details}}}));return}const E=s(i=>{const l=F(t);A({event:"api.request.failed",level:"error",...l?.class==="broker"?{node_id:l.node}:{},error:i instanceof Error?i:new Error(String(i))});try{n.headersSent||n.writeHead(500,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:"internal",message:"internal error",origin:"runtime"}}))}catch{}},"internalFailure");let T;try{T=new URL(t.url??"/","http://127.0.0.1")}catch{try{n.writeHead(400,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:"invalid_request",message:"request URL is invalid",origin:"runtime"}}))}catch{}return}try{const i=u((t.method??"GET").toUpperCase(),T.pathname);if(i!==null){Nt(n,i.message);return}const l=F(t)??{class:"person"},f=Ee(l),g=s(()=>o.handle(t,n,c,l),"handled");(f===void 0?g():$(f,s(async()=>{Z()||await Q(f),await g()},"handledAsPerson"))).catch(E)}catch(i){E(i)}},"onRequest"),_=s(async(t,n,c)=>{const p=F(t);return p===void 0||me(p)||await ge(p,"either",c)?!0:(y(n,404,"Not Found","node_not_found",`no node ${c}`),!1)},"authorizeAttachUpgrade"),U=new Set,x=s((t,n,c)=>{U.add(n),n.once("close",()=>U.delete(n)),n.on("error",()=>{});try{const p=new URL(t.url??"/","http://127.0.0.1"),O=u((t.method??"GET").toUpperCase(),p.pathname);if(O!==null){y(n,503,"Service Unavailable","startup_blocked",O.message);return}const h=At(t.method??"GET",p.pathname);if(h===null){n.destroy();return}const E=(()=>{const i=F(t);return i===void 0?void 0:Ee(i)})(),T=s(()=>_(t,n,h).then(i=>i?sr(t,n,c,h,async l=>{const f=F(t);return f===void 0||me(f)||await ge(f,l,h)}):void 0),"attach");(E===void 0?T():$(E,async()=>{Z()||await Q(E),await T()})).catch(()=>{try{n.destroy()}catch{}})}catch{try{n.destroy()}catch{}}},"onUpgrade"),w=s(t=>{t.on("error",n=>{A({event:"api.server.failed",level:"error",error:n})})},"bindErrorHandler"),Oe=s(async(t,n)=>{try{const c=await _e(t,R);if(c==="unauthorized"){A({event:"api.principal.denied",level:"warn",fields:{method:t.method}}),j(n);return}if(c==="runtime_starting"){ke(n);return}B.set(t,c),Se(t,c),m(t,n,c.class==="app"?c.scopes:null)}catch(c){A({event:"api.principal.failed",level:"error",error:c instanceof Error?c:new Error(String(c))}),j(n)}},"onSocketRequest"),D=ie((t,n)=>{Oe(t,n).catch(c=>A({event:"api.principal.failed",level:"error",error:c instanceof Error?c:new Error(String(c))}))}),Pe=s(async(t,n,c)=>{try{const p=await _e(t,R);if(p==="unauthorized"||p==="runtime_starting"){p==="unauthorized"&&A({event:"api.principal.denied",level:"warn",fields:{method:t.method}}),y(n,p==="unauthorized"?401:503,"Unauthorized",p,"socket principal unavailable");return}if(p.class!=="person"&&p.class!=="broker"){y(n,403,"Forbidden",L.code,L.message);return}B.set(t,p),x(t,n,c)}catch(p){A({event:"api.principal.failed",level:"error",error:p instanceof Error?p:new Error(String(p))}),y(n,401,"Unauthorized",P.code,P.message)}},"onSocketUpgrade");D.on("upgrade",(t,n,c)=>{Pe(t,n,c).catch(p=>A({event:"api.principal.failed",level:"error",error:p instanceof Error?p:new Error(String(p))}))}),ve((t,n,c)=>{B.set(t,c),m(t,n,null)});let re=!1,te,ne;const Ne=new Promise((t,n)=>{te=t,ne=n});D.once("listening",()=>{re=!0,te()}),D.on("error",t=>{A({event:"api.server.failed",level:"error",error:t}),re||ne(t)});try{G(d)&&ae(d)}catch{}D.listen(d,()=>{try{Be(d,process.platform==="linux"&&G("/run/crtr/launcher.sock")?438:384)}catch(t){A({event:"api.socket.chmod_failed",level:"error",error:t instanceof Error?t:new Error(String(t))})}});let b;const V=e.tcp??or()??de("user").api.tcp;if(V!==void 0&&V!==""){const t=yt(V);if(t===null)A({event:"api.tcp.invalid",level:"error",error:new Error(`invalid CRTRD_TCP/--tcp spec: ${V}`)});else{H()&&W();const n=e.token??ir()??tr("user"),c=_t(n),p=s(async(i,l)=>{if(Ct(i,l))return;if(H()&&je(new URL(i.url??"/","http://runtime.local").pathname)){await bt(i,l);return}if(await Ot(i,l))return;const f={},g=await Te(i,c,f);if(g==="runtime_starting"){I(l),ke(l);return}if(g==="person_bearer"){kt(l);return}if(g==="unauthorized"){A({event:"api.principal.denied",level:"warn",fields:{method:i.method,listener:"tcp",path:new URL(i.url??"/","http://runtime.local").pathname,reason:f.reason??"unknown"}}),j(l,!0);return}if("call"in g){I(l);const z=g.call.sub;await $(z,async()=>{Z()||await Q(z),await St()(i,l,g.call)});return}B.set(i,g.principal),Se(i,g.principal),I(l),m(i,l,g.ceiling)},"tcpOnRequest"),O=s(async(i,l,f)=>{const g=lr(i);if(g!==null){const v=await ar(i,l,f,g);v!==null&&y(l,v.status,v.text,v.code,v.message);return}const z=pr(i);if(z!==null){const v=ur(i,l,f,z);v!==null&&y(l,v.status,v.text,v.code,v.message);return}const C=await Te(i,c);if(C==="runtime_starting"){y(l,503,"Service Unavailable","runtime_starting","grant sync is not ready");return}if(C==="person_bearer"){y(l,401,"Unauthorized",M.code,M.message);return}if(C==="unauthorized"){y(l,401,"Unauthorized",P.code,P.message);return}if("call"in C){y(l,403,"Forbidden",L.code,L.message);return}if(C.ceiling!==null||C.principal.class==="anonymous"||C.principal.class==="import"){y(l,403,"Forbidden",L.code,L.message);return}B.set(i,C.principal),x(i,l,f)},"tcpOnUpgrade"),h=s(i=>{A({event:"api.principal.failed",level:"error",error:i instanceof Error?i:new Error(String(i))})},"failed"),E=s((i,l)=>{p(i,l).catch(f=>{h(f),l.headersSent?l.destroy():j(l,!0)})},"listener"),T=Tt();b=T===null?ie(E):Le(T,E),b.on("upgrade",(i,l,f)=>{l.on("error",()=>{}),O(i,l,f).catch(g=>{h(g),y(l,401,"Unauthorized",P.code,P.message)})}),w(b),b.once("listening",()=>{const i=b?.address();if(i!==null&&typeof i=="object"){const{address:l,port:f}=i;r=vt(l,f),l!=="0.0.0.0"&&l!=="::"&&cr(r)}}),b.listen(t.port,t.host)}}let oe=!1;return{ready:Ne,tcpAddress:s(()=>r,"tcpAddress"),close:s(async(t={})=>{if(!oe){oe=!0,ve(null),yr.close(),await Promise.all([Ue(D,U,t.graceMs),b!==void 0?Ue(b,U,t.graceMs):Promise.resolve()]);try{G(d)&&ae(d)}catch{}}},"close")}}s(vo,"createApiServer");export{Rt as buildRouter,Ue as closeServer,vo as createApiServer,F as socketPrincipal};
|
|
1
|
+
var Ie=Object.defineProperty;var s=(e,r)=>Ie(e,"name",{value:r,configurable:!0});import{IMPORT_TOKEN_PREFIX as ze,importPrincipalFor as He}from"./import-auth.js";import{createServer as ie}from"node:http";import{createServer as Le}from"node:https";import{chmodSync as Be,existsSync as G,readFileSync as se,unlinkSync as ae}from"node:fs";import{MINIMUM_RUNTIME_VERSION_HEADER as le,RUNTIME_VERSION_HEADER as Y,minimumRuntimeRefusal as xe}from"../../api/runtime-version.js";import{CONTRACT_HEADER as K,CONTRACT_LEVEL as ce,REQUIRED_CONTRACT_HEADER as ue,contractRefusal as De}from"../../api/contract.js";import{crtrVersion as X}from"../../shared/crtr-version.js";import{apiSocketPath as Me}from"../../core/canvas/paths.js";import{resolveNodeToken as Fe}from"../../core/canvas/node-tokens.js";import{isCloudRole as H,runAsPerson as J}from"../../core/canvas/person.js";import{personBearerVerifier as pe}from"./auth/person-bearer.js";import{personHasSnapshot as Z}from"../../core/scoped-state/person-store.js";import{loadPersonSettings as Q}from"../../core/scoped-state/person-rows.js";import{AppPrincipalResolver as $e}from"./principal.js";import{createAppRequestHandler as Je}from"./app-listener.js";import{decodeJwt as We}from"jose";import{handleRuntimeSignIn as je,isRuntimeSignInPath as Ve}from"./key-signin.js";import{RunError as S}from"../../core/runs/operations.js";import{removeVendorAccount as Ge,vendorStatus as Ye}from"./handlers/vendor-status.js";import{toErrorBody as Ke}from"./map.js";import{CONTROL_BODY_MAX_BYTES as Xe}from"../../core/llm/body-limits.js";import{grantFor as Ze,hasSyncedGrants as Qe}from"../../core/grants/mirror.js";import{readConfig as de}from"../../core/config.js";import{directoryIssuer as qe}from"../../core/directory/issuer.js";import{peerUid as er}from"../../native/linux.js";import{findScopedApiToken as rr,getApiToken as tr,listScopedApiTokens as nr}from"../../core/secrets.js";import{emitEvent as A}from"../../core/events/emit.js";import{envCrtrdTcp as or,envCrtrdToken as ir}from"../../shared/env.js";import{Router as fe,actsAsPerson as me}from"./router.js";import{handleAttachUpgrade as sr,refuseUpgrade as y}from"./bridge.js";import{handleMachineLinkUpgrade as ar,machineLinkEnvironment as lr,setApiAddress as cr}from"../machine-link/holder.js";import{handleMachineViewUpgrade as ur,machineViewEnvironment as pr}from"../machine-link/forward.js";import{boundDaemonControl as dr}from"../control.js";import{attachRoutes as fr,mayAttachNode as ge}from"./handlers/attach.js";import{peerRoutes as mr}from"../peer/handlers.js";import{bashJobRoutes as gr}from"./handlers/bash-jobs.js";import{bashRoutes as hr}from"./handlers/bash.js";import{hookExecRoutes as Rr}from"./handlers/hook-exec.js";import{brokerOperationRoutes as he}from"./handlers/broker-ops.js";import{brokerSignalRoutes as Ar,brokerSignalStreams as yr}from"./handlers/broker-signals.js";import{brokerRecoveryRoutes as Re,nodeFaultRoutes as _r}from"./handlers/broker-recovery.js";import{canvasRoutes as vr}from"./handlers/canvas.js";import{conversationRoutes as wr}from"./handlers/conversations.js";import{chatInventoryRoutes as Er}from"./handlers/chat-inventory.js";import{daemonRoutes as Sr}from"./handlers/daemon.js";import{fileRoutes as br}from"./handlers/files.js";import{focusRoutes as Tr}from"./handlers/focus.js";import{analyticsRoutes as Cr}from"./handlers/analytics.js";import{memoryReadsRoutes as kr}from"./handlers/memory-reads.js";import{memoryRoutes as Ur}from"./handlers/memory.js";import{healthRoutes as Or}from"./handlers/health.js";import{humanRequestRoutes as Pr}from"./handlers/human-requests.js";import{inboxRoutes as Nr}from"./handlers/inbox.js";import{feedbackCommentRoutes as Ir}from"./handlers/feedback-comments.js";import{objectRoutes as zr}from"./handlers/objects.js";import{shareRoutes as Hr}from"./handlers/shares.js";import{customObjectRoutes as Lr}from"./handlers/custom-objects.js";import{docRoutes as Br}from"./handlers/docs.js";import{deliveryRoutes as Ae}from"./handlers/delivery.js";import{deliveryRetryRoutes as xr}from"./handlers/delivery-retry.js";import{packageDocRoutes as Dr}from"./handlers/package-docs.js";import{documentAccessRoutes as Mr}from"./handlers/document-access.js";import{pluginAppRoutes as Fr}from"./handlers/plugin-app-token.js";import{brokerMailRoutes as ye,messageRoutes as $r}from"./handlers/messages.js";import{modelAuthRoutes as Jr}from"./handlers/modelauth.js";import{llmRoutes as Wr}from"./handlers/llm.js";import{providerRoutes as jr}from"./handlers/providers.js";import{modelConfigRoutes as Vr}from"./handlers/model-config.js";import{settingsRoutes as Gr}from"./handlers/settings.js";import{nodeRoutes as Yr}from"./handlers/nodes.js";import{nodeRecordRoutes as Kr}from"./handlers/node-records.js";import{nodeOutcomeRoutes as Xr}from"./handlers/node-outcomes.js";import{nodeEventRoutes as Zr}from"./handlers/node-events.js";import{profileRoutes as Qr}from"./handlers/profiles.js";import{prospectiveChatInventoryRoutes as qr}from"./handlers/prospective-chat-inventory.js";import{reportRoutes as et}from"./handlers/reports.js";import{runRoutes as rt}from"./handlers/run-routes.js";import{reviewCommentRoutes as tt}from"./handlers/review-comments.js";import{reviewRoutes as nt}from"./handlers/reviews.js";import{subscriptionRoutes as ot}from"./handlers/subscriptions.js";import{structuredRequestRoutes as it}from"./handlers/structured-requests.js";import{cronRoutes as st}from"./handlers/crons.js";import{setCronRequestHandler as _e}from"../cron/run-socket.js";import{RUN_TOKEN_PREFIX as at,cronPrincipalForRunToken as lt}from"../cron/run-token.js";import{worktreeRoutes as ct}from"./handlers/worktree.js";import{limitsRoutes as ut}from"./handlers/limits.js";import{chargeRoutes as pt,spendLimitRoutes as dt}from"./handlers/charges.js";import{executionStartRoutes as ft}from"./handlers/execution-start.js";import{machineCredentialRoutes as mt}from"./handlers/machine-credential.js";import{importRoutes as gt}from"./handlers/imports.js";import{gitCredentialRoutes as ht}from"./handlers/git-credential.js";function Rt(e){return new fe().registerAll(Or(e)).registerAll(Sr).registerAll(Hr).registerAll(Yr).registerAll(Kr).registerAll(Xr).registerAll(xr).registerAll(Zr).registerAll(gr).registerAll(hr).registerAll(Rr).registerAll(he).registerAll(Ar).registerAll(Ae).registerAll(Re).registerAll(_r).registerAll(ct).registerAll(ut).registerAll(pt).registerAll(ft).registerAll(mt).registerAll(gt).registerAll(ht).registerAll(dt).registerAll(ye).registerAll($r).registerAll(et).registerAll(rt).registerAll(it).registerAll(fr).registerAll(vr).registerAll(wr).registerAll(Cr).registerAll(kr).registerAll(Ur).registerAll(br).registerAll(zr).registerAll(Lr).registerAll(Br).registerAll(Dr).registerAll(Mr).registerAll(Fr).registerAll(Tr).registerAll(ot).registerAll(st).registerAll(Qr).registerAll(Jr).registerAll(Wr).registerAll(jr).registerAll(Vr).registerAll(Gr).registerAll(nt).registerAll(tt).registerAll(Nr).registerAll(Pr).registerAll(Er).registerAll(qr).registerAll(Ir).registerAll(mr)}s(Rt,"buildRouter");function At(e,r){if(e.toUpperCase()!=="GET")return null;const o=r.split("/").filter(u=>u.length>0);if(o.length!==4||o[0]!=="v1"||o[1]!=="nodes"||o[3]!=="attach")return null;const a=o[2];return a===void 0||a===""?null:decodeURIComponent(a)}s(At,"attachNodeId");function yt(e){const r=e.trim();if(r==="")return null;const o=r.lastIndexOf(":");if(o<0)return null;const a=r.slice(0,o),u=r.slice(o+1),d=Number(u);return!Number.isInteger(d)||d<0||d>65535?null:{host:a===""?"0.0.0.0":a,port:d}}s(yt,"parseTcp");function _t(e,r){return`${e.includes(":")?`[${e}]`:e}:${r}`}s(_t,"formatTcpAddress");const P={code:"unauthorized",message:"missing or invalid bearer token"},L={code:"owner_only",message:"attach is owner-only; a scoped token does not reach it"},M={code:"person_bearer_not_supported",message:"this listener accepts a person bearer only on a cloud role with CRTR_DIRECTORY_URL and CRTR_PUBLIC_API_URL set; call with a node, app or public token"},q={class:"anonymous",app:"",node:"",run:null,uid:-1,sub:"",grant:null,client_id:null,scopes:[]},B=new WeakMap;function F(e){return B.get(e)}s(F,"socketPrincipal");async function ve(e,r){const o=process.platform==="linux"?er(e.socket):null,a=e.headers.authorization;if(a===void 0)return o===null||r.has(o)?{class:"person"}:"unauthorized";if(typeof a!="string"||!a.startsWith("Bearer "))return"unauthorized";if(a.slice(7).startsWith("crtr_pub_"))return q;if(a.slice(7).startsWith(ee)){const u=be(a.slice(7));return u!==void 0&&(o===null||r.has(o))?u.principal:"unauthorized"}return we(a.slice(7),o)}s(ve,"resolveSocketPrincipal");async function we(e,r){const o=await Fe(e);if(!o||r!==null&&r!==o.uid)return"unauthorized";const a=qe();if(a&&!H()&&!await Qe(a))return"runtime_starting";const u=o.grant??(await Ze("app:terminal",o.sub))?.id??null;return{class:"broker",...o,grant:u}}s(we,"brokerPrincipal");function Ee(e){if(!(e.class==="anonymous"||e.class==="import"))return e.sub!==void 0&&e.sub!==""?e.sub:void 0}s(Ee,"requestPerson");function Se(e,r){r.class==="broker"&&A({event:"api.request.principal",level:r.app==="app:terminal"?"debug":"info",node_id:r.node,fields:{principal:`${r.app} node:${r.node}`,method:e.method,path:e.url}})}s(Se,"noteBrokerRequest");const ee="crtr_app_";function be(e){const r=e.startsWith(ee)?rr(e):void 0;return r===void 0?void 0:{principal:{class:"app",app:r.grantee,scopes:r.scopes},ceiling:r.scopes}}s(be,"appBearer");function vt(e){const r=new Map;for(const o of nr("user"))r.set(o.token,{principal:{class:"app",app:o.grantee,scopes:o.scopes},ceiling:o.scopes});return e!==void 0&&r.set(e,{principal:{class:"person"},ceiling:null}),r}s(vt,"resolveBearers");function wt(e){try{return We(e).act!==void 0}catch{return!1}}s(wt,"carriesAct");const Et=/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/;function k(e,r){return e!==void 0&&(e.reason=r),"unauthorized"}s(k,"deny");async function Te(e,r,o){const a=e.headers.authorization;if(a===void 0&&(e.method??"GET").toUpperCase()==="GET"&&(e.url??"").split("?")[0]==="/healthz")return{principal:q,ceiling:null};if(typeof a!="string"||!a.startsWith("Bearer "))return k(o,a===void 0?"no_authorization_header":"not_a_bearer");const u=a.slice(7);if(u.startsWith("crtr_pub_"))return{principal:q,ceiling:null};if(u.startsWith(ee))return be(u)??k(o,"app_token_unknown");if(u.startsWith(at)){const v=await lt(u);return v===null?k(o,"run_token_invalid_or_settled"):{principal:v,ceiling:null}}const d=r.get(u);if(d!==void 0)return d;const R=He(u);if(R!==null)return{principal:R,ceiling:null};if(u.startsWith(ze))return k(o,"import_token_invalid");if(Et.test(u)){if(H()&&wt(u)){const x=j();if(x===null)return"person_bearer";try{const w=await x.verifyCall(a);return w.chain[0]?.sub.startsWith("app:")?{call:w}:k(o,"call_token_presenter_not_an_app")}catch(w){return w instanceof S&&w.status===503?"runtime_starting":k(o,`call_token_${w instanceof S?w.code:"invalid"}`)}}const v=H()?pe():null;if(v===null)return"person_bearer";const U=await v.verify(u);return U===null?k(o,"person_bearer_not_verified"):{principal:{class:"person",sub:U},ceiling:null}}const m=await we(u,null);return m==="unauthorized"?k(o,"node_token_unknown"):typeof m=="string"?m:{principal:m,ceiling:null}}s(Te,"authorizeTcp");let W;function j(){if(W!==void 0)return W;const e=process.env.CRTR_DIRECTORY_URL||void 0,r=process.env.CRTR_PUBLIC_API_URL||void 0;return W=e===void 0||r===void 0?null:new $e(e,r,async()=>{}),W}s(j,"cloudCallResolver");let Ce;function St(){const e=j();if(e===null)throw new S(503,"runtime_starting","app calls are not configured on this listener");return Ce??=Je(e,async()=>!0,async()=>{}),Ce}s(St,"cloudAppCalls");async function bt(e,r){N(r),I(r);const o=j();try{if(o===null)throw new S(503,"runtime_starting","sign-in is not configured on this listener");await je(e,r,new URL(e.url??"/","http://runtime.local"),o)}catch(a){if(!(a instanceof S))throw a;if(r.headersSent){r.destroy();return}r.writeHead(a.status,{"content-type":"application/json; charset=utf-8","cache-control":"no-store"}),r.end(JSON.stringify({error:{code:a.code,message:a.message,...a.param?{param:a.param}:{},origin:"runtime"}}))}}s(bt,"serveRuntimeSignIn");function Tt(){const e=process.env.CRTRD_TLS_CERT||void 0,r=process.env.CRTRD_TLS_KEY||void 0;if(e===void 0&&r===void 0)return null;if(e===void 0||r===void 0)throw new Error("CRTRD_TLS_CERT and CRTRD_TLS_KEY must be set together");return{cert:se(e),key:se(r)}}s(Tt,"tcpTls");function N(e){e.setHeader(Y,X()),e.setHeader(K,ce)}s(N,"advertiseRuntime");function I(e){e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Expose-Headers",`${Y}, ${K}`)}s(I,"exposeRuntimeHeaders");function Ct(e,r){return(e.method??"GET").toUpperCase()!=="OPTIONS"?!1:(N(r),r.writeHead(204,{"Access-Control-Allow-Origin":"*","Access-Control-Expose-Headers":`${Y}, ${K}`,"Access-Control-Allow-Headers":`authorization, content-type, ${le.toLowerCase()}, ${ue.toLowerCase()}`,"Access-Control-Allow-Methods":"GET, POST, PATCH, PUT, DELETE, OPTIONS","Access-Control-Max-Age":"600"}),r.end(),!0)}s(Ct,"answerPreflight");function V(e,r=!1){N(e),r&&I(e),e.writeHead(401,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{...P,origin:"runtime"}}))}s(V,"writeUnauthorized");function kt(e){N(e),I(e),e.writeHead(401,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{...M,origin:"runtime"}}))}s(kt,"writePersonBearerRefused");const Ut={"/v1/runtime/vendor-status":{method:"GET",purpose:"vendor_status"},"/v1/runtime/vendor-account-remove":{method:"POST",purpose:"vendor_account_remove"}};async function Ot(e,r){if(!H())return!1;const o=new URL(e.url??"/","http://runtime.local").pathname,a=Ut[o];if(a===void 0||e.method!==a.method)return!1;const u=s((d,R)=>{N(r),I(r),r.writeHead(d,{"content-type":"application/json; charset=utf-8"}),r.end(JSON.stringify(R))},"answer");try{const d=pe();if(d===null)throw new S(401,M.code,M.message);const R=e.headers.authorization,m=R?.startsWith("Bearer ")?await d.verifyPurpose(R.slice(7),a.purpose):null;if(m===null)throw new S(401,"unauthorized","invalid directory token");const v=a.purpose==="vendor_status"?void 0:await Pt(e);u(200,await J(m,async()=>a.purpose==="vendor_status"?Ye():await Ge(v)))}catch(d){const{status:R,body:m}=Ke(d);u(R,m)}return!0}s(Ot,"serveCloudVendorRoute");async function Pt(e){const r=[];let o=0;for await(const a of e){if(o+=a.length,o>Xe)throw new S(400,"invalid_request","request body too large");r.push(a)}if(o!==0)try{return JSON.parse(Buffer.concat(r).toString("utf8"))}catch{throw new S(400,"invalid_request","invalid JSON body")}}s(Pt,"readVendorBody");function ke(e){N(e),e.writeHead(503,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{code:"runtime_starting",message:"grant sync is not ready",type:"server_error",origin:"runtime",retryable:!0}}))}s(ke,"writeRuntimeStarting");function Nt(e,r){e.writeHead(503,{"content-type":"application/json; charset=utf-8"}),e.end(JSON.stringify({error:{code:"startup_blocked",message:r,origin:"runtime"}}))}s(Nt,"writeStartupBlocked");function Ue(e,r,o){return new Promise(a=>{if(o===void 0){try{e.closeAllConnections()}catch{}e.close(()=>a());return}const u=[];e.close(()=>{for(const m of u)clearTimeout(m);a()});for(const m of r)m.destroy();const d=setInterval(()=>e.closeIdleConnections(),250),R=setTimeout(()=>e.closeAllConnections(),o);u.push(d,R),e.closeIdleConnections()})}s(Ue,"closeServer");function _o(e={}){let r=null;const o=Rt(()=>r),a=new fe().registerAll(he).registerAll(Ae).registerAll(Re).registerAll(ye),u=s((t,n)=>{const c=dr()?.startupBlock()??null;return c===null||t==="GET"&&(n==="/healthz"||n==="/v1/status"||n==="/v1/ready")||t==="POST"&&(n==="/v1/daemon/migrate"||n==="/v1/daemon/admit")||c.phase==="recovering"&&a.match(t,n)!==null?null:c},"startupBlockFor"),d=e.socketPath??Me(),R=new Set([process.getuid?.()??0,...de("user").runtime?.person_uids??[]]),m=s((t,n,c)=>{N(n);const p=s(i=>Array.isArray(i)?i[0]:i,"first"),O=p(t.headers[le.toLowerCase()]),h=xe(O,X())??De(p(t.headers[ue.toLowerCase()]),ce,{legacyMinimum:O,runtimeVersion:X()});if(h!==null){n.writeHead(h.status,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:h.code,message:h.message,type:"invalid_request_error",origin:"runtime",retryable:!1,..."param"in h?{param:h.param}:{details:h.details}}}));return}const E=s(i=>{const l=F(t);A({event:"api.request.failed",level:"error",...l?.class==="broker"?{node_id:l.node}:{},error:i instanceof Error?i:new Error(String(i))});try{n.headersSent||n.writeHead(500,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:"internal",message:"internal error",origin:"runtime"}}))}catch{}},"internalFailure");let T;try{T=new URL(t.url??"/","http://127.0.0.1")}catch{try{n.writeHead(400,{"content-type":"application/json; charset=utf-8"}),n.end(JSON.stringify({error:{code:"invalid_request",message:"request URL is invalid",origin:"runtime"}}))}catch{}return}try{const i=u((t.method??"GET").toUpperCase(),T.pathname);if(i!==null){Nt(n,i.message);return}const l=F(t)??{class:"person"},f=Ee(l),g=s(()=>o.handle(t,n,c,l),"handled");(f===void 0?g():J(f,s(async()=>{Z()||await Q(f),await g()},"handledAsPerson"))).catch(E)}catch(i){E(i)}},"onRequest"),v=s(async(t,n,c)=>{const p=F(t);return p===void 0||me(p)||await ge(p,"either",c)?!0:(y(n,404,"Not Found","node_not_found",`no node ${c}`),!1)},"authorizeAttachUpgrade"),U=new Set,x=s((t,n,c)=>{U.add(n),n.once("close",()=>U.delete(n)),n.on("error",()=>{});try{const p=new URL(t.url??"/","http://127.0.0.1"),O=u((t.method??"GET").toUpperCase(),p.pathname);if(O!==null){y(n,503,"Service Unavailable","startup_blocked",O.message);return}const h=At(t.method??"GET",p.pathname);if(h===null){n.destroy();return}const E=(()=>{const i=F(t);return i===void 0?void 0:Ee(i)})(),T=s(()=>v(t,n,h).then(i=>i?sr(t,n,c,h,async l=>{const f=F(t);return f===void 0||me(f)||await ge(f,l,h)}):void 0),"attach");(E===void 0?T():J(E,async()=>{Z()||await Q(E),await T()})).catch(()=>{try{n.destroy()}catch{}})}catch{try{n.destroy()}catch{}}},"onUpgrade"),w=s(t=>{t.on("error",n=>{A({event:"api.server.failed",level:"error",error:n})})},"bindErrorHandler"),Oe=s(async(t,n)=>{try{const c=await ve(t,R);if(c==="unauthorized"){A({event:"api.principal.denied",level:"warn",fields:{method:t.method}}),V(n);return}if(c==="runtime_starting"){ke(n);return}B.set(t,c),Se(t,c),m(t,n,c.class==="app"?c.scopes:null)}catch(c){A({event:"api.principal.failed",level:"error",error:c instanceof Error?c:new Error(String(c))}),V(n)}},"onSocketRequest"),D=ie((t,n)=>{Oe(t,n).catch(c=>A({event:"api.principal.failed",level:"error",error:c instanceof Error?c:new Error(String(c))}))}),Pe=s(async(t,n,c)=>{try{const p=await ve(t,R);if(p==="unauthorized"||p==="runtime_starting"){p==="unauthorized"&&A({event:"api.principal.denied",level:"warn",fields:{method:t.method}}),y(n,p==="unauthorized"?401:503,"Unauthorized",p,"socket principal unavailable");return}if(p.class!=="person"&&p.class!=="broker"){y(n,403,"Forbidden",L.code,L.message);return}B.set(t,p),x(t,n,c)}catch(p){A({event:"api.principal.failed",level:"error",error:p instanceof Error?p:new Error(String(p))}),y(n,401,"Unauthorized",P.code,P.message)}},"onSocketUpgrade");D.on("upgrade",(t,n,c)=>{Pe(t,n,c).catch(p=>A({event:"api.principal.failed",level:"error",error:p instanceof Error?p:new Error(String(p))}))}),_e((t,n,c)=>{B.set(t,c),m(t,n,null)});let re=!1,te,ne;const Ne=new Promise((t,n)=>{te=t,ne=n});D.once("listening",()=>{re=!0,te()}),D.on("error",t=>{A({event:"api.server.failed",level:"error",error:t}),re||ne(t)});try{G(d)&&ae(d)}catch{}D.listen(d,()=>{try{Be(d,process.platform==="linux"&&G("/run/crtr/launcher.sock")?438:384)}catch(t){A({event:"api.socket.chmod_failed",level:"error",error:t instanceof Error?t:new Error(String(t))})}});let b;const $=e.tcp??or()??de("user").api.tcp;if($!==void 0&&$!==""){const t=yt($);if(t===null)A({event:"api.tcp.invalid",level:"error",error:new Error(`invalid CRTRD_TCP/--tcp spec: ${$}`)});else{H()&&j();const n=e.token??ir()??tr("user"),c=vt(n),p=s(async(i,l)=>{if(Ct(i,l))return;if(H()&&Ve(new URL(i.url??"/","http://runtime.local").pathname)){await bt(i,l);return}if(await Ot(i,l))return;const f={},g=await Te(i,c,f);if(g==="runtime_starting"){I(l),ke(l);return}if(g==="person_bearer"){kt(l);return}if(g==="unauthorized"){A({event:"api.principal.denied",level:"warn",fields:{method:i.method,listener:"tcp",path:new URL(i.url??"/","http://runtime.local").pathname,reason:f.reason??"unknown"}}),V(l,!0);return}if("call"in g){I(l);const z=g.call.sub;await J(z,async()=>{Z()||await Q(z),await St()(i,l,g.call)});return}B.set(i,g.principal),Se(i,g.principal),I(l),m(i,l,g.ceiling)},"tcpOnRequest"),O=s(async(i,l,f)=>{const g=lr(i);if(g!==null){const _=await ar(i,l,f,g);_!==null&&y(l,_.status,_.text,_.code,_.message);return}const z=pr(i);if(z!==null){const _=ur(i,l,f,z);_!==null&&y(l,_.status,_.text,_.code,_.message);return}const C=await Te(i,c);if(C==="runtime_starting"){y(l,503,"Service Unavailable","runtime_starting","grant sync is not ready");return}if(C==="person_bearer"){y(l,401,"Unauthorized",M.code,M.message);return}if(C==="unauthorized"){y(l,401,"Unauthorized",P.code,P.message);return}if("call"in C){y(l,403,"Forbidden",L.code,L.message);return}if(C.ceiling!==null||C.principal.class==="anonymous"||C.principal.class==="import"){y(l,403,"Forbidden",L.code,L.message);return}B.set(i,C.principal),x(i,l,f)},"tcpOnUpgrade"),h=s(i=>{A({event:"api.principal.failed",level:"error",error:i instanceof Error?i:new Error(String(i))})},"failed"),E=s((i,l)=>{p(i,l).catch(f=>{h(f),l.headersSent?l.destroy():V(l,!0)})},"listener"),T=Tt();b=T===null?ie(E):Le(T,E),b.on("upgrade",(i,l,f)=>{l.on("error",()=>{}),O(i,l,f).catch(g=>{h(g),y(l,401,"Unauthorized",P.code,P.message)})}),w(b),b.once("listening",()=>{const i=b?.address();if(i!==null&&typeof i=="object"){const{address:l,port:f}=i;r=_t(l,f),l!=="0.0.0.0"&&l!=="::"&&cr(r)}}),b.listen(t.port,t.host)}}let oe=!1;return{ready:Ne,tcpAddress:s(()=>r,"tcpAddress"),close:s(async(t={})=>{if(!oe){oe=!0,_e(null),yr.close(),await Promise.all([Ue(D,U,t.graceMs),b!==void 0?Ue(b,U,t.graceMs):Promise.resolve()]);try{G(d)&&ae(d)}catch{}}},"close")}}s(_o,"createApiServer");export{Rt as buildRouter,Ue as closeServer,_o as createApiServer,F as socketPrincipal};
|
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
import { type StartedFlow } from '../../core/model-auth/flows.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type AppPrincipalResolver, type HandoffPurpose, type VendorHandoff } from './principal.js';
|
|
4
4
|
export declare const VENDOR_SIGNIN_PATH = "/signin/vendor";
|
|
5
5
|
export declare function isVendorSignInPath(pathname: string): boolean;
|
|
6
|
+
/** RT-LLM-52's checks beyond the signature and claims: `sub` is this runtime's owner. A cloud role serves many people, so any `user:` sub is
|
|
7
|
+
* accepted there and the request then runs as that person. */
|
|
8
|
+
export declare function verifyOwnerHandoff(principal: AppPrincipalResolver, token: string | undefined, purpose?: HandoffPurpose): Promise<VendorHandoff>;
|
|
9
|
+
export declare function bearer(req: IncomingMessage): string | undefined;
|
|
6
10
|
export declare function escapeHtml(value: string): string;
|
|
11
|
+
export declare function sendJson(res: ServerResponse, status: number, body: unknown): void;
|
|
12
|
+
export declare function jsonBody(req: IncomingMessage): Promise<Record<string, unknown>>;
|
|
13
|
+
export declare const STYLE = "\n:root{color-scheme:light dark;\n--canvas:#f0f2f4;--surface:#fff;--sunken:#e5e7ea;--zone:#e5e7ea;--neutral:#e5e7ea;--neutral-hover:#d7d9dc;--neutral-pressed:#cbcdd0;\n--accent:#217f51;--accent-hover:#1e6e46;--accent-pressed:#1a5e3c;--accent-border:#217f51;--accent-subtle:#d5f7e1;--accent-fg:#1e6e46;--on-accent:#fff;\n--warning-bg:#fcedd4;--warning-fg:#8f5200;--danger-bg:#fce5e2;--danger-fg:#bf2a1f;--danger-line:#bf2a1f;\n--text:#15171a;--muted:#505256;--disabled:#919498;--line:#d7d9dc;--line-strong:#787b7f;--focus:#217f51;\n--sans:system-ui,-apple-system,'Segoe UI',Roboto,'Helvetica Neue',Arial,sans-serif;\n--mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}\n@media (prefers-color-scheme:dark){:root{\n--canvas:#0e1012;--surface:#181a1d;--sunken:#212326;--zone:#212326;--neutral:#212326;--neutral-hover:#2f3134;--neutral-pressed:#3c3e41;\n--accent:#217f51;--accent-hover:#1e6e46;--accent-pressed:#1a5e3c;--accent-border:#09b972;--accent-subtle:#072d1a;--accent-fg:#5ada97;--on-accent:#fff;\n--warning-bg:#35260f;--warning-fg:#f4b45a;--danger-bg:#3b1715;--danger-fg:#ff8175;--danger-line:#d0342a;\n--text:#f0f2f4;--muted:#acaeb2;--disabled:#505256;--line:#2f3134;--line-strong:#787b7f;--focus:#5ada97}}\n*,*::before,*::after{box-sizing:border-box}\n[hidden]{display:none!important}\nbody{margin:0;min-height:100vh;min-height:100dvh;display:flex;flex-direction:column;background:var(--canvas);color:var(--text);font:400 .9375rem/1.5333 var(--sans);-webkit-text-size-adjust:100%}\np,h1,ol{margin:0}\na{color:inherit}\n:focus-visible{outline:2px solid var(--focus);outline-offset:2px}\n.top{display:flex;align-items:center;gap:.5rem;height:3.5rem;flex:none;padding:0 1rem;background:var(--surface);border-bottom:1px solid var(--line)}\n.top svg{width:20px;height:20px;color:#09b972}\n.top span{font-weight:600}\nmain{flex:1;display:flex;flex-direction:column;align-items:center;padding:2.5rem 1rem}\n.col{width:100%;max-width:36rem}\n.card{display:flex;flex-direction:column;gap:1.5rem;padding:1.5rem;background:var(--surface);border:1px solid var(--line);border-radius:12px}\n.head{display:flex;align-items:center;gap:1rem}\n.logo{position:relative;flex:none;width:3.5rem;height:3.5rem;border-radius:12px;overflow:hidden}\n.logo svg{display:block;width:100%;height:100%}\n.logo::after{content:\"\";position:absolute;inset:0;border:1px solid var(--line);border-radius:inherit}\nh1{font-size:1.25rem;line-height:1.3;font-weight:600;letter-spacing:-.02em}\n.steps{list-style:none;padding:0;display:flex;flex-direction:column;gap:1.25rem}\n.steps>li{display:flex;gap:.875rem}\n.n{position:relative;flex:none;display:flex;align-items:center;justify-content:center;width:1.75rem;height:1.75rem;border-radius:9999px;background:var(--neutral);font-size:.8125rem;font-weight:500;font-variant-numeric:tabular-nums}\n.n svg{display:none;width:1rem;height:1rem}\nli.done .n{background:var(--accent-subtle);color:var(--accent-fg)}\nli.done .n span{display:none}\nli.done .n svg{display:block}\n.body{flex:1;min-width:0;display:flex;flex-direction:column;gap:.625rem;padding-top:.125rem}\n.title{font-weight:500}\n.small{font-size:.84375rem;line-height:1.4815;color:var(--muted)}\n.ic{flex:none;width:1rem;height:1rem;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}\n.btn{display:inline-flex;align-items:center;justify-content:center;gap:.5rem;min-height:2.5rem;padding:.4rem 1.125rem;border:1px solid transparent;border-radius:8px;background:var(--neutral);color:var(--text);font:500 .9375rem/1.3 var(--sans);text-align:center;text-decoration:none;cursor:pointer;overflow-wrap:break-word;transition:background-color .12s cubic-bezier(.2,0,0,1)}\n.btn:hover{background:var(--neutral-hover)}\n.btn:active{background:var(--neutral-pressed)}\n.btn.primary{background:var(--accent);border-color:var(--accent-border);color:var(--on-accent)}\n.btn.primary:hover{background:var(--accent-hover)}\n.btn.primary:active{background:var(--accent-pressed)}\n.btn.sm{min-height:2rem;padding:.25rem .75rem;font-size:.84375rem}\n.btn.lg{min-height:3rem;padding:.5rem 1.375rem}\n.btn.wide{width:100%}\n.btn:disabled,.btn[aria-disabled=true]{opacity:.4;cursor:default;pointer-events:none}\n.field{display:flex;flex-direction:column;gap:.375rem}\nlabel{width:fit-content;font-size:.8125rem;line-height:1.2308;font-weight:500}\ninput[type=text]{width:100%;min-width:0;height:3rem;padding:0 .875rem;background:var(--surface);color:var(--text);border:1px solid var(--line-strong);border-radius:8px;font:400 .9375rem/1.5 var(--mono)}\ninput[type=text]:focus{outline:2px solid var(--focus);outline-offset:2px}\ninput[type=text][aria-invalid=true]{border-color:var(--danger-line)}\nform{display:flex;flex-direction:column;gap:.75rem}\n.err{display:none;align-items:flex-start;gap:.375rem;color:var(--danger-fg);font-size:.84375rem;line-height:1.4815}\n.err.on{display:flex}\n.err .ic{margin-top:.125rem}\n.alert{display:flex;flex-wrap:wrap;align-items:flex-start;gap:.75rem;padding:.75rem .875rem;border-radius:8px;background:var(--warning-bg);font-size:.84375rem;line-height:1.4815}\n.alert>.ic{width:1.125rem;height:1.125rem;margin-top:1px;color:var(--warning-fg)}\n.alert .text{flex:1 1 12rem;min-width:0}\n.alert strong{display:block;font-weight:600}\n.alert .act{flex:none;align-self:center}\n.codebox{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;padding:1rem;border-radius:12px;background:var(--sunken)}\n.code{flex:1 1 auto;min-width:0;font:600 clamp(1.25rem,7vw,1.75rem)/1.2143 var(--mono);letter-spacing:.18em;overflow-wrap:anywhere}\n.code.expired{color:var(--disabled);text-decoration:line-through}\n.badge{display:inline-flex;align-items:center;gap:.375rem;height:1.25rem;padding:0 .375rem;border-radius:6px;background:var(--danger-bg);color:var(--danger-fg);font-size:.8125rem;font-weight:500;white-space:nowrap}\n.badge::before{content:\"\";width:.375rem;height:.375rem;border-radius:9999px;background:currentColor}\n.wait{display:flex;align-items:center;gap:.75rem;padding:.75rem 1rem;border-radius:12px;background:var(--zone)}\n.wait .spin{width:1rem;height:1rem;color:var(--accent-fg);fill:none;stroke:currentColor;stroke-width:3;stroke-linecap:round}\n.wait .msg{flex:1;min-width:0;display:flex;flex-direction:column;font-size:.84375rem;line-height:1.4815}\n.wait .msg b{font-weight:500}\n.wait .msg span{color:var(--muted)}\n.clock{display:flex;align-items:center;gap:.375rem;color:var(--muted);font-size:.84375rem;font-variant-numeric:tabular-nums}\n.clock .ic{width:.875rem;height:.875rem}\n.sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}\n.foot{flex:none;display:flex;justify-content:center;padding:0 1rem 2rem;color:var(--muted);font-size:.84375rem;line-height:1.4815;text-align:center}\n.foot a{color:var(--text);text-underline-offset:2px}\n.foot a:hover{color:var(--accent-fg)}\n@media (prefers-reduced-motion:no-preference){.wait .spin{animation:spin 1s linear infinite}}\n@keyframes spin{to{transform:rotate(360deg)}}\n@media (min-width:40rem){.top{padding:0 1.5rem}main{padding:3.5rem 1rem}}\n@media (max-width:30rem){.card{padding:1.25rem}.btn{padding-left:.875rem;padding-right:.875rem}#device-link{font-size:.84375rem}.steps>li{gap:.75rem}.alert .act{margin-left:1.875rem}}\n";
|
|
14
|
+
export declare const ICONS: {
|
|
15
|
+
readonly arrow: "<path d=\"M7 7h10v10\"/><path d=\"M7 17 17 7\"/>";
|
|
16
|
+
readonly copy: "<rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/>";
|
|
17
|
+
readonly clock: "<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 6v6l4 2\"/>";
|
|
18
|
+
readonly warn: "<path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\"/><path d=\"M12 9v4\"/><path d=\"M12 17h.01\"/>";
|
|
19
|
+
readonly alert: "<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 8v4\"/><path d=\"M12 16h.01\"/>";
|
|
20
|
+
readonly check: "<path d=\"M20 6 9 18l-5-5\"/>";
|
|
21
|
+
};
|
|
22
|
+
export declare function icon(name: keyof typeof ICONS, extra?: string): string;
|
|
23
|
+
export declare const BRAND_MARK = "<svg viewBox=\"-77.5 12 931 931\" aria-hidden=\"true\" focusable=\"false\"><path fill=\"currentColor\" d=\"M234 294m0 0h2l-1 5-6 16-5 15-6 25-4 23-2 22-1 5v47l5 38 5 26 6 22 10 24 8 16 9 14 14 19 13 16 11 13 9 11 11 12 7 8 13 16 11 14 14 19 12 19 12 23 7 17 6 23 3 14 3-1 5-15 20-84 6-24 6-21 10-33 10-25 8-16 8-15 8-12 9-12 8-10 9-10 7-8 6-7 20-20h2l2-4 17-17 7-8 10-13 14-21 8-16 8-18 5-15 2-7 2 1 6 36 2 18v41l-4 28-5 19-7 19-10 21-8 13-10 15-13 17-11 13-12 14-9 10-7 8-9 11h-2l-2 4-9 11-14 19-8 12-15 25-11 21-12 26-9 23-5 12-13 38-12 39-5 18-5 17h-2l-9-29-9-27-14-38-13-29-8-16-11-18-10-13-7-9-25-25-3-2v-2l-3-1v-2l-4-2-10-9-8-7-14-12-20-18-13-13-9-11-12-16-12-20-12-25-7-19-6-23-4-24-1-11-1-3v-39l3-23 6-27 7-23 5-11 11-23 9-16 10-14 8-11 9-11 10-11zM430 22m0 0h2v2h2l7 8 10 11 9 11 12 16 9 15 8 16 6 15 5 19 2 11 1 12v18l-1 16-5 24-5 16-7 15-9 17-7 11-10 15-10 13-9 11-13 14-7 8-11 12-7 8-13 16-11 15-13 20-10 18-8 16-7 18-5 15-4 18-2 14-1 27 2 24 3 17 5 23 8 30 12 36 9 28 3 8 4 12v2l-4-2-68-102-13-22-11-23-9-24-7-26-4-23-2-16v-31l3-25 6-27 7-21 7-15 8-16 14-21 11-14 26-30 12-13 8-10h2l2-4 10-11 7-9 14-19 7-10 13-24 7-19 4-15 3-14 3-22 2-24v-20l-2-31zM615 384m0 0 2 1 6 36 2 18v41l-4 28-5 19-7 19-10 21-8 13-10 15-13 17-11 13-12 14-9 10-7 8-9 11h-2l-2 4-9 11-14 19-8 12-15 25-11 21-2 5h-3l-2 2h-13l-6-5-11-6 1-9h-2l2-14-2 3 1-8 9-36 6-21 10-33 10-25 8-16 8-15 8-12 9-12 8-10 9-10 7-8 6-7 20-20h2l2-4 17-17 7-8 10-13 14-21 8-16 8-18 5-15zM557 254m0 0 2 1 4 16 2 16v34l-2 18-5 20-8 24-14 28-10 16-11 16-13 15-12 14-11 13-11 14-14 19-12 20-8 16-7 19-6 20-4 20-4 35-3 41-3 52-4 28-1 3h-2l-8-42-10-52-7-33-7-43v-54l4-24 5-17 8-20 10-19 7-10 10-13 9-11 19-19 8-7 16-15 8-7 9-9 8-7 11-11 1-2h2l2-4 11-13 10-14 11-17 9-19 8-21zM185 615m0 0 4 5 6 10 9 12 2 1 3 5 5-2 1-1h8l5 5 2 3 7 3 6 3 4 5 8 6 5 3v2h2v2h6l4 3 6 1 1 8 10 3 4 2 9 2 5 6 6 1h6l8 8 7 1 9 7h5l1-4-4-6-10-13-7-9-1-3h-2l-7-9v-3l7 6 7 9 11 14 14 19 12 19 12 23 7 17 6 23 3 14 3-1 5-15 10-42 5-22h2l1-4 1 4-1 8h-2l3 4-1 8 11 6 5 4h13l4-3-1 6-8 17-9 23-5 12-13 38-12 39-5 18-5 17h-2l-9-29-9-27-14-38-13-29-8-16-11-18-10-13-7-9-25-25-3-2v-2l-3-1v-2l-4-2-10-9-8-7-14-12-20-18-13-13-9-11-12-16-9-15zM369 553m0 0h1l1 43 2 3 3 4-1 6-1 1v7l1 2 1 15 7 1 5-2 5 1v-2l3-1 4 1 1-2h-3l1-3 6-2 2 11-1 8-3 12h2v2l3-1 2-12h-2l1-4 1-1 3-21 4-21h1v10l-4 30-3 34-4 69-4 28-1 3h-2l-8-42-10-52-7-33-6-37zM430 22m0 0h2v2h2l7 8 10 11 9 11 4 5 1 5 2 4 1 7 2 2-1 3-5-1h-7l-8-2-5 1v7l-1 1h-5l-2-8-1-2-1-15h-2l-2-31zM417 598m0 0h1v10l-4 30-3 34-4 69-4 28-1 3h-2l-7-37-1-16h8l2 1v-2h2l1-2 2-35v-13l-2-3-3-5-1-8 1-9-1-4-5-2v-2l-3-1v-2l3-1 4 1 1-2h-3l1-3 6-2 2 11-1 8-3 12h2v2l3-1 2-12h-2l1-4 1-1 3-21zM417 598m0 0h1v10l-4 30-3 34-1 17h-2v15l-1 12h-1v-18l1-17v-13l-2-3-3-5-1-8 1-9-1-4-5-2v-2l-3-1v-2l3-1 4 1 1-2h-3l1-3 6-2 2 11-1 8-3 12h2v2l3-1 2-12h-2l1-4 1-1 3-21zM310 619m0 0 4 2 4 6 5 8 7 9 3 5 2-1 2 1 2 10 6-1 2 1v2h-5l3 7 9 13 6 9 3 1v-2l-4-14h3l5 16 3 8 4 12v2l-4-2-60-90zM255 597m0 0 5 3 12 16 9 11 11 13 9 11 11 12 4 5-1 3-7-7-4-1-7-4v-2l-4-2-4-4 4 1 3-1v-3l-5-2-3-5v-2h-2l-6-8v-2l-3-1-1-2-8-1 1-2-2-8-3-4v-2h-2l-4-6-3-4zM425 181m0 0 7 1 1 3 12 2 2 3 3 1v-2h3l1 3-6 2-1 3h-2v2h-2l-1 7-5 1-2-5 2-3h3l1-5-3 1-3 3-1-4-5-2v-5h-6l-3-3zM369 553m0 0h1l1 43 2 3 3 4-1 6-1 1v7l1 2 1 15 2 1h-2l3 13 2 10v5l-3-4-5-25-4-26zM340 614m0 0 1 2h2l6 20 6 18 3 15-2-1-5-15-2-4v-5h-6l-3-2-9-2 2-3v2l5-4h4 2l-1-5-3-12zM296 649m0 0 5 2 11 12 4 5-1 3-7-7-4-1-7-4v-2l-4-2-4-4 4 1 3-1zM403 625m0 0h2l2 11-1 8-2 7-2 1v-9l-1-4-5-2v-2l-3-1v-2l3-1 4 1 1-2h-3l1-3zM417 598m0 0h1v10l-4 30-2 24h-1l-1-17h-2l1-4 1-1 3-21zM163 561m0 0 2 3 5 16 2 6 2 1 3 9 2 4 4-1 1-2 1 3h-2l-2 5 3 6-1 2-3-3-11-24-4-11-2-10zM439 685m0 0 1 2h9l3 4v6l7 2 3 7-4-1-6-4-5-4v-7h-9l-2-2zM369 553m0 0h1l1 43 2 3 3 4-1 6-1 1-1 7-2-2v-7h-2zM434 687m0 0h1v6l-3 9-7 29-4 5 1-8 9-36zM317 672m0 0 6 4 9 11 11 14 6 8v2l-4-2-10-13-7-9-1-3h-2l-7-9zM276 622m0 0 5 5 11 13 7 8-1 2-7-4-3-5v-2h-2l-6-8v-2l-3-1-2-4zM310 619m0 0 4 2 4 6 5 8 7 9-1 4-4-5-8-11-7-11zM416 172m0 0 2 1-1 7h-2v5l4-1-1 3-5 2-3-1v-7l4-8zM381 664m0 0 2 4 6 27v5l-1-2h-2l-5-24zM443 655m0 0 1 4-7 25-1 2h-2l1-7 6-22h2zM163 561m0 0 2 3 5 16 2 6 2 1v5l-2 1-7-18-2-10zM490 702m0 0 1 3-10 15-3 5-4 3v-5l5-5 7-11zM387 698m0 0 1 2h2l3 16v14h-1l-5-26zM426 139m0 0 1 3-1 5-7 22-2-1 2-9 5-18h2zM466 739m0 0h2l-1 6-8 15-3 1 2-7 7-12zM411 636m0 0h2v12l-1 14h-1l-1-17h-2l1-4zM349 645m0 0h3l3 9 3 15-2-1-5-15-2-4zM335 694m0 0 5 3 9 12v2l-4-2-10-13zM386 633m0 0 7 1-3 2-4 1-2 4h-4l-2-6h5zM547 287m0 0 3 2-3 7-1 5h-2l-1 4-2-1 1-5zM557 254m0 0 2 1 3 13-4-1 1-2h-2l-1 3-1-3zM560 311m0 0 3 1-2 5-3 6-9-3v-1l9-1zM409 664m0 0h1v25h-1l-2-24zM340 614m0 0 1 2h2l4 16-4-2-3-12zM438 705m0 0 10 2 1 7-3-1-4-4h-5zM502 685m0 0 1 3-8 11-3 1 2-5zM422 191m0 0 4 1 3 4-2 4-5-3zM359 675m0 0h3l4 13-1 4-4-9zM225 599m0 0 5 2 12 6-3 1-9-4-6-3zM255 597m0 0 5 3 6 8-1 2-3-1-4-6-3-4zM414 180m0 0h1v5l4-1-1 3-5 2-3-1 1-5zM341 665m0 0 3 1 6 9-1 4-8-12zM370 608m0 0h1l1 9 3 1-2 10h-1l-2-12zM439 671m0 0 1 2-4 13h-2l1-7 3-7zM341 658m0 0 6 1v2h-5l-1 5-3-3 1-4zM373 625m0 0h2l1 9 2 1h-2l-1 5h-1l-1-6zM185 615m0 0 4 5 5 8-1 3-4-5-4-7zM434 687m0 0h1v6l-3 9-2 3 1-13zM385 686m0 0h2l2 9v5l-1-2h-2l-1-5zM390 711m0 0h2l1 8v11h-1l-2-10zM355 657m0 0 2 3 4 12v3l-3-1-2-10zM413 624m0 0h1v14l-1-2h-2l1-11zM494 120m0 0h2l2 6v10l-2-3-2-9zM163 561m0 0 2 3 4 13-1 3v-2h-2l-3-13zM489 106m0 0h2l4 10-2 4-4-11zM230 609m0 0 5 1 4 5 3 2-6-1-3-3v-2l-3-1zM392 660m0 0h2v2h2l5 5 2 1-1 4-10-10zM254 615m0 0 8 1 1 1v5l-2-1v-2l-6-2zM190 587m0 0 6 1 2-1 4 2 1 3-13-2zM417 598m0 0h1v10l-1 5-2-1 1-9zM273 545m0 0 2 3 3 8v3h-2l-3-8z\"/></svg>";
|
|
24
|
+
export declare const HELP_EMAIL = "team@northlight.ai";
|
|
25
|
+
/** The runtime sign-in page shell: header, one card column, footer, the JSON config block and one nonce'd script (`SCRIPT` unless given). */
|
|
26
|
+
export declare function page(input: {
|
|
27
|
+
nonce: string;
|
|
28
|
+
title: string;
|
|
29
|
+
body: string;
|
|
30
|
+
config: Record<string, unknown>;
|
|
31
|
+
script?: string;
|
|
32
|
+
style?: string;
|
|
33
|
+
}): string;
|
|
7
34
|
export declare function anthropicPage(flow: StartedFlow, nonce: string, returnTo: string, handoff: string): string;
|
|
8
35
|
export declare function openaiPage(flow: StartedFlow, nonce: string, returnTo: string, handoff: string, now?: number): string;
|
|
9
36
|
/** Serve one `/signin/vendor*` request; errors propagate as RunErrors so the
|