@oracle-agent/oracle 0.15.0 → 0.17.0
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/assets/profiles/oracle/SOUL.md +14 -0
- package/dist/bin/desk-server.mjs +17 -16
- package/dist/bin/oracle-data-mcp.mjs +7 -6
- package/dist/bin/oracle-public-server.mjs +4 -4
- package/dist/bin/oracle-route.mjs +9 -9
- package/dist/bin/oracle-scan.mjs +9 -9
- package/dist/bin/oracle.mjs +20 -17
- package/dist/cli/commands/auth.mjs +12 -12
- package/dist/cli/commands/bootstrap.mjs +7 -7
- package/dist/cli/commands/chain.mjs +15 -15
- package/dist/cli/commands/chat.mjs +34 -34
- package/dist/cli/commands/doctor.mjs +5 -5
- package/dist/cli/commands/eval.mjs +18 -0
- package/dist/cli/commands/fees.mjs +4 -4
- package/dist/cli/commands/mcp.mjs +46 -22
- package/dist/cli/commands/model.mjs +37 -37
- package/dist/cli/commands/plugins.mjs +35 -35
- package/dist/cli/commands/setup.mjs +27 -27
- package/dist/cli/commands/sign.mjs +19 -2
- package/dist/cli/commands/strategy.mjs +18 -0
- package/dist/cli/commands/swap.mjs +19 -19
- package/dist/data/desk-data.mjs +13 -13
- package/dist/index.mjs +18 -18
- package/dist/router/index.mjs +2 -2
- package/dist/scanner/index.mjs +4 -4
- package/dist/strategy/index.mjs +3 -0
- package/package.json +2 -1
- package/public/oracle-splash/_variants/ice.html +3 -3
- package/public/oracle-splash/_variants/ivory.html +3 -3
- package/public/oracle-splash/downloads/index.html +4 -4
- package/public/oracle-splash/index.html +8 -9
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,{mode:384}),M.renameSync(n,e),process.platform!=="win32"&&M.chmodSync(e,384)}function go(e){if(process.platform!=="linux")return!1;let t=e("secret-tool",["--version"],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});return!t.error&&t.status===0}function ot(e){let t=String(e||"").trim().toLowerCase();if(!/^[a-z0-9][a-z0-9._-]*$/.test(t))throw new Error(`invalid API-key provider: ${e||"(empty)"}`);return t}function me(e={}){let t=String(e.accessToken||e.access_token||"").trim(),n=String(e.refreshToken||e.refresh_token||"").trim(),r=Number(e.expiresAt||e.expires_at||0);if(!t)throw new Error("OAuth credential is missing access token");return{accessToken:t,refreshToken:n,expiresAt:Number.isFinite(r)?r:0,tokenType:String(e.tokenType||e.token_type||"Bearer"),source:String(e.source||"oracle"),...e.discovery?{discovery:e.discovery}:{},...e.scope?{scope:e.scope}:{},...e.idToken||e.id_token?{idToken:String(e.idToken||e.id_token)}:{}}}function ut(e={}){let t=e.file||re.join(Y(),"oauth.json"),n=e.metadataFile||re.join(re.dirname(t),"oauth-meta.json"),r=e.spawnFn||yo,o=e.keychain!==!1&&process.env.ORACLE_AUTH_FILE_STORE!=="1"&&go(r),i=o?"linux-secret-service":"private-file",c=`${t}.lock`;async function a(b){wn(re.dirname(c));let m;for(let h=0;h<400;h+=1)try{m=M.openSync(c,"wx",384);break}catch(l){if(l?.code!=="EEXIST")throw l;try{Date.now()-M.statSync(c).mtimeMs>3e5&&M.unlinkSync(c)}catch{}await new Promise(d=>setTimeout(d,25))}if(m===void 0)throw new Error("timed out waiting for OAuth credential lock");try{return await b()}finally{try{M.closeSync(m)}catch{}try{M.unlinkSync(c)}catch{}}}function u(b,m="oauth"){return["application","oracle","kind",m,"provider",b]}function s(b){let m=H(b);if(o){let d=r("secret-tool",["lookup",...u(m)],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});if(d.error||d.status!==0||!String(d.stdout||"").trim())return null;try{return me(JSON.parse(String(d.stdout).trim()))}catch{return null}}let l=N(t,{providers:{}}).providers?.[m];if(!l)return null;try{return me(l)}catch{return null}}function f(b,m){let h=H(b),l=me(m);if(o){let w=r("secret-tool",["store",`--label=Oracle ${h} OAuth`,...u(h)],{input:JSON.stringify(l),encoding:"utf8",stdio:["pipe","ignore","pipe"]});if(w.error||w.status!==0)throw new Error("OS credential store rejected OAuth credential");let O=N(n,{providers:{}});return O.providers||={},O.providers[h]={expiresAt:l.expiresAt,source:l.source},W(n,O),l}let d=N(t,{providers:{}});return d.providers||={},d.providers[h]=l,W(t,d),l}function p(b){let m=H(b);if(o){let d=r("secret-tool",["clear",...u(m)],{encoding:"utf8",stdio:["ignore","ignore","pipe"]}),w=N(n,{providers:{}});return w.providers&&delete w.providers[m],W(n,w),!d.error&&d.status===0}let h=N(t,{providers:{}}),l=!!h.providers?.[m];return h.providers&&delete h.providers[m],W(t,h),l}function y(b){let m=ot(b);if(o){let h=r("secret-tool",["lookup",...u(m,"api-key")],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});return h.error||h.status!==0?"":String(h.stdout||"").trim()}return String(N(t,{apiKeys:{}}).apiKeys?.[m]||"").trim()}function x(b,m){let h=ot(b),l=String(m||"").trim();if(!l)throw new Error("API key is empty");if(o){let w=r("secret-tool",["store",`--label=Oracle ${h} API key`,...u(h,"api-key")],{input:l,encoding:"utf8",stdio:["pipe","ignore","pipe"]});if(w.error||w.status!==0)throw new Error("OS credential store rejected API key");let O=N(n,{providers:{},apiKeys:{}});return O.apiKeys||={},O.apiKeys[h]={configured:!0},W(n,O),!0}let d=N(t,{providers:{},apiKeys:{}});return d.apiKeys||={},d.apiKeys[h]=l,W(t,d),!0}function _(b){let m=ot(b);if(o){let d=r("secret-tool",["clear",...u(m,"api-key")],{encoding:"utf8",stdio:["ignore","ignore","pipe"]}),w=N(n,{providers:{},apiKeys:{}});return w.apiKeys&&delete w.apiKeys[m],W(n,w),!d.error&&d.status===0}let h=N(t,{providers:{},apiKeys:{}}),l=!!h.apiKeys?.[m];return h.apiKeys&&delete h.apiKeys[m],W(t,h),l}function v(){let b={},m={};if(o){let h=N(n,{providers:{},apiKeys:{}});for(let[l,d]of Object.entries(h.providers||{}))b[l]={loggedIn:!!s(l),expiresAt:Number(d.expiresAt||0),source:String(d.source||"oracle"),storage:i};for(let l of Object.keys(h.apiKeys||{}))m[l]={configured:!!y(l),storage:i}}else{let h=N(t,{providers:{},apiKeys:{}});for(let[l,d]of Object.entries(h.providers||{}))b[l]={loggedIn:!!d?.accessToken,expiresAt:Number(d?.expiresAt||0),source:String(d?.source||"oracle"),storage:i};for(let[l,d]of Object.entries(h.apiKeys||{}))m[l]={configured:!!d,storage:i}}return{storage:i,providers:b,apiKeys:m}}return Object.freeze({file:t,storage:i,get:s,set:f,remove:p,getApiKey:y,setApiKey:x,removeApiKey:_,status:v,withLock:a})}function ie(){return _n||=ut(),_n}function it(e){return Buffer.from(e).toString("base64url")}function bo(){let e=it(st(32));return{verifier:e,challenge:it(po("sha256").update(e).digest()),state:it(st(24))}}function _o(e,t){let n=Buffer.from(String(e||"")),r=Buffer.from(String(t||""));return n.length===r.length&&mo(n,r)}function wo(e){let t=String(e),n=process.platform==="darwin"?["open",[t]]:process.platform==="win32"?["cmd.exe",["/d","/s","/c","start","",t]]:["xdg-open",[t]];try{return xo(n[0],n[1],{detached:!0,stdio:"ignore"}).unref(),!0}catch{return!1}}function Ce(e){return new URLSearchParams(e).toString()}async function q(e,t){if(!e?.ok){let r="";try{r=String((await e.json())?.error||"")}catch{}throw new Error(`${t} failed (HTTP ${e?.status||"unknown"}${r?`, ${r}`:""})`)}let n=await e.json();if(!n||typeof n!="object")throw new Error(`${t} returned invalid JSON`);return n}async function vo(e){if(e)return String(await e()).trim();let t=ho.createInterface({input:process.stdin,output:process.stdout});try{return String(await t.question("Authorization code: ")).trim()}finally{t.close()}}function Ie(e,t={}){let n=String(e.access_token||"").trim(),r=String(e.refresh_token||t.refreshToken||"").trim();if(!n)throw new Error("OAuth token response is missing access token");let o=Number(e.expires_in||3600);return me({accessToken:n,refreshToken:r,expiresAt:ct(t)+Math.max(1,o)*1e3,tokenType:e.token_type||"Bearer",idToken:e.id_token,source:"oracle",...t.discovery?{discovery:t.discovery}:{},...e.scope?{scope:e.scope}:{}})}async function So(e){let t=oe["anthropic-oauth"],n=e.pkce||bo(),r=new URLSearchParams({code:"true",client_id:t.clientId,response_type:"code",redirect_uri:t.redirectUri,scope:t.scope,code_challenge:n.challenge,code_challenge_method:"S256",state:n.state}),o=`${t.authorizeUrl}?${r}`;e.output(`Open: ${o}`),e.openFn(o);let i=await vo(e.inputFn),[c,a]=i.split("#",2);if(!c||!_o(a,n.state))throw new Error("Claude OAuth state mismatch");let u=await e.fetchFn(t.tokenUrl,{method:"POST",headers:{"content-type":"application/json","user-agent":"axios/1.7.9"},body:JSON.stringify({grant_type:"authorization_code",client_id:t.clientId,code:c,state:a,redirect_uri:t.redirectUri,code_verifier:n.verifier})});return Ie(await q(u,"Claude OAuth token exchange"),e)}async function ko(e){let t=oe["openai-codex"],n=await q(await e.fetchFn(`${t.issuer}/api/accounts/deviceauth/usercode`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({client_id:t.clientId})}),"Codex device authorization");if(!n.user_code||!n.device_auth_id)throw new Error("Codex device authorization returned incomplete data");let r=`${t.issuer}/codex/device`;e.output(`Open: ${r}`),e.output(`Code: ${n.user_code}`),e.openFn(r);let o=Math.max(3,Number(n.interval||5)),i;for(let a=0;a<Math.ceil(900/o);a+=1){await e.sleepFn(o*1e3);let u=await e.fetchFn(`${t.issuer}/api/accounts/deviceauth/token`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({device_auth_id:n.device_auth_id,user_code:n.user_code})});if(u.ok){i=await q(u,"Codex device authorization");break}if(![403,404].includes(u.status))throw new Error(`Codex device authorization failed (HTTP ${u.status})`)}if(!i)throw new Error("Codex device authorization timed out");let c=await e.fetchFn(t.tokenUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:Ce({grant_type:"authorization_code",code:i.authorization_code,redirect_uri:`${t.issuer}/deviceauth/callback`,client_id:t.clientId,code_verifier:i.code_verifier})});return Ie(await q(c,"Codex OAuth token exchange"),e)}function J(e){let t=new URL(String(e)),n=t.hostname.toLowerCase();if(t.protocol!=="https:"||n!=="x.ai"&&!n.endsWith(".x.ai"))throw new Error("xAI OAuth discovery returned an untrusted endpoint");return t.toString()}async function Eo(e){let t=oe["xai-oauth"],n=await q(await e.fetchFn(t.discoveryUrl,{headers:{accept:"application/json"}}),"xAI OAuth discovery");J(n.authorization_endpoint);let r=J(n.token_endpoint),o=await q(await e.fetchFn(t.deviceUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},body:Ce({client_id:t.clientId,scope:t.scope})}),"xAI device authorization");if(!o.device_code||!o.user_code||!o.verification_uri)throw new Error("xAI device authorization returned incomplete data");let i=J(o.verification_uri_complete||o.verification_uri);e.output(`Open: ${i}`),e.output(`Code: ${o.user_code}`),e.openFn(i);let c=Math.max(1,Number(o.interval||5)),a=Math.ceil(Math.max(1,Number(o.expires_in||600))/c);for(let u=0;u<a;u+=1){let s=await e.fetchFn(r,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},body:Ce({grant_type:"urn:ietf:params:oauth:grant-type:device_code",client_id:t.clientId,device_code:o.device_code})});if(s.ok){let p=await q(s,"xAI OAuth token exchange");return Ie(p,{...e,discovery:{authorization_endpoint:J(n.authorization_endpoint),token_endpoint:r}})}let f="";try{f=String((await s.json())?.error||"")}catch{}if(f==="slow_down")await e.sleepFn((c+1)*1e3);else if(f==="authorization_pending")await e.sleepFn(c*1e3);else throw new Error(`xAI OAuth token exchange failed (HTTP ${s.status}${f?`, ${f}`:""})`)}throw new Error("xAI device authorization timed out")}async function vn(e,t={}){let n=H(e),r={fetchFn:t.fetchFn||globalThis.fetch,inputFn:t.inputFn,sleepFn:t.sleepFn||(o=>new Promise(i=>setTimeout(i,o))),openFn:t.openFn||wo,output:t.output||(o=>process.stdout.write(`${o}
|
|
3
|
-
`)),now:t.now,pkce:t.pkce};return n==="anthropic-oauth"?
|
|
4
|
-
`),o(1))}),i.once("exit",(f,p)=>{if(
|
|
5
|
-
`,{mode:384}),
|
|
6
|
-
`)}catch(
|
|
7
|
-
`}):e===9?P({name:"tab",sequence:" "}):e===127?P({name:"backspace",sequence:"\x7F"}):e===8?P({name:"backspace",sequence:"\b"}):e>=1&&e<=26?P({name:String.fromCharCode(e+96),ctrl:!0,sequence:String.fromCharCode(e)}):P({name:"unknown",sequence:String.fromCharCode(e)})}function br(e){let t=/^\u001b[\[O](\d*)(?:;(\d+))?(.)$/s.exec(e);if(!t)return P({name:"unknown",sequence:e});let n=t[1]===""?null:Number(t[1]),r=t[2]===void 0?null:Number(t[2]),o=t[3],i=null,c=r;if(o==="~"?i=xr[n]??null:(i=hr[o]??null,c===null&&n!==null&&n>1&&(c=n)),!i)return P({name:"unknown",sequence:e});let a=c===null?0:Math.max(0,c-1);return P({name:i,shift:(a&1)!==0,meta:(a&2)!==0,ctrl:(a&4)!==0,sequence:e})}function _r(e,t,n,r){let o=()=>(n.push(P({name:"escape",sequence:"\x1B"})),1);if(t+1>=e.length)return r?o():0;let i=e[t+1];if(i===91||i===79){let s=t+2;for(;s<e.length&&!yr(e[s]);)s+=1;return s>=e.length?r?o():0:(n.push(br(e.toString("utf8",t,s+1))),s+1-t)}if(i===27)return o();let c=It(i);if(t+1+c>e.length)return r?o():0;let a=e.toString("utf8",t+1,t+1+c),u=a.toLowerCase();return n.push(P({name:u,meta:!0,shift:a!==u,sequence:`\x1B${a}`})),1+c}function Ot(e,t){let n=[],r=0;for(;r<e.length;){let o=e[r];if(o===27){let c=_r(e,r,n,t);if(c===0)return{keys:n,rest:Buffer.from(e.subarray(r))};r+=c;continue}if(o<32||o===127){n.push(gr(o)),r+=1;continue}let i=It(o);if(r+i>e.length)return t?(n.push(At(e.toString("utf8",r))),{keys:n,rest:fe}):{keys:n,rest:Buffer.from(e.subarray(r))};n.push(At(e.toString("utf8",r,r+i))),r+=i}return{keys:n,rest:fe}}function Ct(e){return Buffer.isBuffer(e)?e:e==null?fe:typeof e=="string"?Buffer.from(e,"utf8"):Buffer.from(e)}function wr(){let e=fe;return{push(t){let n=e.length===0?Ct(t):Buffer.concat([e,Ct(t)]),{keys:r,rest:o}=Ot(n,!1);return e=o,r},flush(){if(e.length===0)return[];let{keys:t}=Ot(e,!0);return e=fe,t},get pending(){return e.length}}}function vr({history:e=[]}={}){let t=[...e];return{buffer:"",cursor:0,history:t,historyIndex:t.length,draft:""}}function Pe(e,t){if(t<=0)return 0;let n=t-1,r=e.charCodeAt(n);if(r>=56320&&r<=57343&&n>0){let o=e.charCodeAt(n-1);if(o>=55296&&o<=56319)return n-1}return n}function Ne(e,t){if(t>=e.length)return e.length;let n=e.charCodeAt(t);return n>=55296&&n<=56319&&t+1<e.length?t+2:t+1}function E(e,t){return{...e,...t}}function Lt(e,t){return E(e,{...t,historyIndex:e.history.length,draft:""})}function Sr(e){if(e.ctrl||e.meta||!e.sequence||mr.has(e.name))return!1;for(let t of e.sequence){let n=t.codePointAt(0);if(n<32||n===127)return!1}return!0}function kr(e,t){let n=t;for(;n>0&&/\s/.test(e[n-1]);)n-=1;for(;n>0&&!/\s/.test(e[n-1]);)n-=1;return n}function Er(e){if(e.historyIndex<=0)return{state:E(e,{}),action:null};let t=e.historyIndex>=e.history.length,n=e.historyIndex-1,r=e.history[n]??"";return{state:E(e,{buffer:r,cursor:r.length,historyIndex:n,draft:t?e.buffer:e.draft}),action:null}}function Ar(e){if(e.historyIndex>=e.history.length)return{state:E(e,{}),action:null};let t=e.historyIndex+1,n=t>=e.history.length,r=n?e.draft:e.history[t]??"";return{state:E(e,{buffer:r,cursor:r.length,historyIndex:t,draft:n?"":e.draft}),action:null}}function Or(e){let t=e.buffer.trim();if(t==="")return{state:Lt(e,{buffer:"",cursor:0}),action:null};let n=e.history[e.history.length-1]===t?[...e.history]:[...e.history,t];return{state:E(e,{buffer:"",cursor:0,history:n,historyIndex:n.length,draft:""}),action:{type:"submit",value:t}}}function Cr(e,t){if(!t)return{state:E(e,{}),action:null};let{buffer:n,cursor:r}=e;if(t.ctrl&&!t.meta)switch(t.name){case"c":return{state:Lt(e,{buffer:"",cursor:0}),action:{type:"cancel"}};case"d":return n===""?{state:E(e,{}),action:{type:"eof"}}:{state:E(e,{}),action:null};case"l":return{state:E(e,{}),action:{type:"clear"}};case"a":return{state:E(e,{cursor:0}),action:null};case"e":return{state:E(e,{cursor:n.length}),action:null};case"u":return{state:E(e,{buffer:n.slice(r),cursor:0}),action:null};case"k":return{state:E(e,{buffer:n.slice(0,r)}),action:null};case"w":{let o=kr(n,r);return{state:E(e,{buffer:n.slice(0,o)+n.slice(r),cursor:o}),action:null}}case"b":return{state:E(e,{cursor:Pe(n,r)}),action:null};case"f":return{state:E(e,{cursor:Ne(n,r)}),action:null};default:return{state:E(e,{}),action:null}}switch(t.name){case"return":return Or(e);case"left":return{state:E(e,{cursor:Pe(n,r)}),action:null};case"right":return{state:E(e,{cursor:Ne(n,r)}),action:null};case"home":return{state:E(e,{cursor:0}),action:null};case"end":return{state:E(e,{cursor:n.length}),action:null};case"up":return Er(e);case"down":return Ar(e);case"backspace":{if(r===0)return{state:E(e,{}),action:null};let o=Pe(n,r);return{state:E(e,{buffer:n.slice(0,o)+n.slice(r),cursor:o}),action:null}}case"delete":{if(r>=n.length)return{state:E(e,{}),action:null};let o=Ne(n,r);return{state:E(e,{buffer:n.slice(0,r)+n.slice(o)}),action:null}}default:break}if(Sr(t)){let o=t.sequence;return{state:E(e,{buffer:n.slice(0,r)+o+n.slice(r),cursor:r+o.length}),action:null}}return{state:E(e,{}),action:null}}function $t(e={}){let{stdin:t,stdout:n,history:r=[],onSubmit:o,onCancel:i,onEof:c,onClear:a,onRender:u}=e,s=t??process.stdin,f=n??process.stdout,p=wr(),y={submit:o,cancel:i,eof:c,clear:a},x=vr({history:r}),_=!1,v=!1,b=!1,m=l=>{if(!l)return;let d=y[l.type];typeof d=="function"&&d(l.value,x)},h=l=>{for(let d of p.push(l)){let w=Cr(x,d);x=w.state,m(w.action),typeof u=="function"&&u(x)}};return{start(){_||(_=!0,s.isTTY&&typeof s.setRawMode=="function"&&(b=s.isRaw===!0,s.setRawMode(!0),v=!0),typeof s.resume=="function"&&s.resume(),s.on("data",h),typeof u=="function"&&u(x))},stop(){_&&(_=!1,typeof s.off=="function"?s.off("data",h):typeof s.removeListener=="function"&&s.removeListener("data",h),v&&typeof s.setRawMode=="function"&&(s.setRawMode(b),v=!1),typeof s.pause=="function"&&s.pause())},getState(){return x},setState(l){return x=l,x},write(l){f&&typeof f.write=="function"&&f.write(l)},get isRunning(){return _}}}var je="\x1B[?25l",be="\x1B[?25h",Tt="\x1B[2K",_e="\x1B[0J";var Ir="\x1B\\[[0-9;?]*[a-zA-Z]";function Nt(){return new RegExp(Ir,"g")}function Lr(e){return String(e??"").replace(Nt(),"")}function Rt(e,t){return t.some(([n,r])=>e>=n&&e<=r)}function jt(e){return e===0||e<32||e>=127&&e<160||Rt(e,[[768,879],[1155,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1552,1562],[1611,1631],[1648,1648],[1750,1757],[1759,1764],[1767,1768],[1770,1773],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2070,2073],[2075,2083],[2085,2087],[2089,2093],[2137,2139],[2259,2273],[2275,2307],[2362,2364],[2369,2376],[2381,2381],[2385,2391],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2641,2641],[2672,2673],[2677,2677],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2884],[2893,2893],[2902,2902],[2914,2915],[2946,2946],[3008,3008],[3021,3021],[3072,3072],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3170,3171],[3201,3201],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3329,3329],[3393,3396],[3405,3405],[3426,3427],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3981,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4151],[4153,4154],[4157,4158],[4184,4185],[4190,4192],[4209,4212],[4226,4226],[4229,4230],[4237,4237],[4253,4253],[4957,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6277,6278],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6683,6683],[6742,6742],[6744,6750],[6752,6752],[6754,6754],[6757,6764],[6771,6780],[6783,6783],[6832,6911],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7040,7041],[7074,7077],[7080,7081],[7083,7085],[7142,7142],[7144,7145],[7149,7149],[7151,7153],[7212,7219],[7222,7223],[7376,7378],[7380,7392],[7394,7400],[7405,7405],[7412,7412],[7416,7417],[7616,7679],[8203,8207],[8234,8238],[8288,8292],[8294,8303],[8400,8447],[65024,65039],[65056,65071],[917760,917999]])?0:Rt(e,[[4352,4447],[8986,8987],[9001,9002],[9193,9196],[9200,9200],[9203,9203],[9725,9726],[9748,9749],[9800,9811],[9855,9855],[9875,9875],[9889,9889],[9898,9899],[9917,9918],[9924,9925],[9934,9934],[9940,9940],[9962,9962],[9970,9971],[9973,9973],[9978,9978],[9981,9981],[9989,9989],[9994,9995],[10024,10024],[10060,10060],[10062,10062],[10067,10069],[10071,10071],[10133,10135],[10160,10160],[10175,10175],[11035,11036],[11088,11088],[11093,11093],[11904,12350],[12352,42191],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[127744,128591],[129280,129535],[131072,262141]])?2:1}function $r(e){let t=0;for(let n of Array.from(e))t+=jt(n.codePointAt(0));return t}function Tr(e){return $r(Lr(e))}function Rr(e){return/^\u001b\[0*m$/.test(e)}function Pt(e,t){let n="",r=0;for(let o of Array.from(e)){let i=jt(o.codePointAt(0));if(r+i>t)break;n+=o,r+=i}return{text:n,width:r}}function Pr(e,t){let n=String(e??"");if(t<=0)return"";if(Tr(n)<=t)return n;let r=Nt(),o="",i=0,c=!1,a=0,u=r.exec(n);for(;u!==null;){let f=Pt(n.slice(a,u.index),t-i);if(o+=f.text,i+=f.width,i>=t)return c?`${o}\x1B[0m`:o;o+=u[0],u[0].endsWith("m")&&(c=!Rr(u[0])),a=u.index+u[0].length,u=r.exec(n)}let s=Pt(n.slice(a),t-i);return o+=s.text,c?`${o}\x1B[0m`:o}function Nr(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function Mt({stdout:e,rows:t,columns:n}={}){if(!e||typeof e.write!="function")throw new TypeError("createRenderer requires a stdout with a write(string) method");let r=Number.isFinite(t)?Math.trunc(t):null,o=Number.isFinite(n)?Math.trunc(n):null,i=r??(Number.isFinite(e.rows)?Math.trunc(e.rows):24),c=o??(Number.isFinite(e.columns)?Math.trunc(e.columns):80),a=[],u=0,s=null,f=!1,p=!1,y=()=>{r===null&&(i=Number.isFinite(e.rows)?Math.trunc(e.rows):24),o===null&&(c=Number.isFinite(e.columns)?Math.trunc(e.columns):80),f=!0},x=typeof e.on=="function";x&&e.on("resize",y);function _(m){let h=m-u;return u=m,h===0?"":h<0?`\x1B[${-h}A`:`\x1B[${h}B`}function v(m){let l=(Array.isArray(m)?m:[]).map(d=>Pr(String(d??""),c));if(s!==null)for(l.length>s&&(l=l.slice(0,s));l.length<s;)l.push("");return l}function b(m){if(!f&&Nr(a,m))return;let h=[je];f&&a.length>0&&(h.push(_(0),"\r",_e),a=[],u=0),f=!1;let l=Math.min(a.length,m.length);for(let d=0;d<l;d+=1)a[d]!==m[d]&&h.push(_(d),"\r",Tt,m[d]);if(m.length>a.length){a.length>0&&h.push(_(a.length-1));for(let d=a.length;d<m.length;d+=1)d>0&&h.push(`
|
|
8
|
-
`),h.push("\r",
|
|
1
|
+
var zn=Object.defineProperty;var bt=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(r){throw n=[r],r}};var Yn=(e,t)=>{for(var n in t)zn(e,n,{get:t[n],enumerable:!0})};import le from"node:fs";import Jn from"node:os";import W from"node:path";import{fileURLToPath as Vn}from"node:url";function fe(){return process.env.ORACLE_FAKE_HOME||Jn.homedir()}function Qn(){return process.env.ORACLE_PUBLIC_DESKTOP==="1"}function D(){return Qn()?process.env.ORACLE_CONFIG_DIR||W.join(fe(),".config","oracle"):W.join(fe(),".config","oracle")}function Zn(){return W.join(D(),"desk.json")}function er(){return W.join(D(),"env")}function Z({force:e=!1}={}){if(Z._done&&!e)return Z._result||null;Z._done=!0;let t={},n=(o,i)=>{if(i==null)return;let s=String(i).trim();s&&(process.env[o]!=null&&String(process.env[o]).trim()!==""||(process.env[o]=s,t[o]=s))};try{let o=er();if(le.existsSync(o))for(let i of le.readFileSync(o,"utf8").split(/\r?\n/)){let s=i.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*?)\s*$/);if(!s||s[2].startsWith("#"))continue;let a=s[2];(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),n(s[1],a)}}catch{}try{let o=Zn();if(le.existsSync(o)){let i=JSON.parse(le.readFileSync(o,"utf8"));i&&typeof i=="object"&&(n("ORACLE_DESK_URL",i.deskUrl||i.dataUrl||i.url),n("ORACLE_DATA_URL",i.dataUrl||i.deskUrl||i.url),n("ORACLE_API_URL",i.apiUrl||i.dataUrl||i.deskUrl),n("ORACLE_PUBLIC_URL",i.publicUrl||i.deskUrl||i.dataUrl),n("ORACLE_EXEC_URL",i.execUrl),n("MAD_DESK_URL",i.deskUrl||i.dataUrl))}}catch{}let r=process.env.ORACLE_DESK_URL||process.env.ORACLE_DATA_URL||"";return r&&(n("ORACLE_DESK_URL",r),n("ORACLE_DATA_URL",r),n("ORACLE_API_URL",r),n("ORACLE_PUBLIC_URL",r),n("MAD_DESK_URL",r)),Z._result=Object.keys(t).length?t:null,Z._result}function B(){return process.env.HERMES_HOME?W.resolve(process.env.HERMES_HOME):W.join(fe(),".hermes")}function P(e){return le.mkdirSync(e,{recursive:!0}),e}var Xn,U,J=bt(()=>{Xn=W.dirname(Vn(import.meta.url)),U=W.resolve(Xn,"../..");try{Z()}catch{}});var Ln={};Yn(Ln,{createOAuthStore:()=>dt,default:()=>To,getOAuthStore:()=>ce,hasOAuthCredentials:()=>Cn,loginOAuth:()=>An,oauthProviderConfig:()=>ft,oauthProviderId:()=>q,oauthRuntimeConfig:()=>In,refreshOAuthCredentials:()=>pt,resolveOAuthCredentials:()=>On});import{createHash as bo,randomBytes as ut,timingSafeEqual as _o}from"node:crypto";import M from"node:fs";import ie from"node:path";import wo from"node:readline/promises";import{spawn as vo,spawnSync as So}from"node:child_process";function lt(e={}){return typeof e.now=="function"?Number(e.now()):Date.now()}function q(e){let t=String(e||"").trim().toLowerCase();for(let[n,r]of Object.entries(se))if(r.aliases.includes(t))return n;throw new Error(`unsupported OAuth provider: ${e||"(empty)"}`)}function ft(e){let t=q(e);return{id:t,...se[t]}}function j(e,t={}){if(!M.existsSync(e))return t;try{let n=JSON.parse(M.readFileSync(e,"utf8"));if(!n||typeof n!="object"||Array.isArray(n))throw new Error("invalid object");return n}catch{throw new Error(`credential store is unreadable or corrupt: ${ie.basename(e)}`)}}function En(e){P(e),process.platform!=="win32"&&M.chmodSync(e,448)}function G(e,t){En(ie.dirname(e));let n=`${e}.${process.pid}.${ut(4).toString("hex")}.tmp`;M.writeFileSync(n,`${JSON.stringify(t,null,2)}
|
|
2
|
+
`,{mode:384}),M.renameSync(n,e),process.platform!=="win32"&&M.chmodSync(e,384)}function ko(e){if(process.platform!=="linux")return!1;let t=e("secret-tool",["--version"],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});return!t.error&&t.status===0}function ct(e){let t=String(e||"").trim().toLowerCase();if(!/^[a-z0-9][a-z0-9._-]*$/.test(t))throw new Error(`invalid API-key provider: ${e||"(empty)"}`);return t}function xe(e={}){let t=String(e.accessToken||e.access_token||"").trim(),n=String(e.refreshToken||e.refresh_token||"").trim(),r=Number(e.expiresAt||e.expires_at||0);if(!t)throw new Error("OAuth credential is missing access token");return{accessToken:t,refreshToken:n,expiresAt:Number.isFinite(r)?r:0,tokenType:String(e.tokenType||e.token_type||"Bearer"),source:String(e.source||"oracle"),...e.discovery?{discovery:e.discovery}:{},...e.scope?{scope:e.scope}:{},...e.idToken||e.id_token?{idToken:String(e.idToken||e.id_token)}:{}}}function dt(e={}){let t=e.file||ie.join(D(),"oauth.json"),n=e.metadataFile||ie.join(ie.dirname(t),"oauth-meta.json"),r=e.spawnFn||So,o=e.keychain!==!1&&process.env.ORACLE_AUTH_FILE_STORE!=="1"&&ko(r),i=o?"linux-secret-service":"private-file",s=`${t}.lock`;async function a(b){En(ie.dirname(s));let m;for(let h=0;h<400;h+=1)try{m=M.openSync(s,"wx",384);break}catch(l){if(l?.code!=="EEXIST")throw l;try{Date.now()-M.statSync(s).mtimeMs>3e5&&M.unlinkSync(s)}catch{}await new Promise(d=>setTimeout(d,25))}if(m===void 0)throw new Error("timed out waiting for OAuth credential lock");try{return await b()}finally{try{M.closeSync(m)}catch{}try{M.unlinkSync(s)}catch{}}}function u(b,m="oauth"){return["application","oracle","kind",m,"provider",b]}function c(b){let m=q(b);if(o){let d=r("secret-tool",["lookup",...u(m)],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});if(d.error||d.status!==0||!String(d.stdout||"").trim())return null;try{return xe(JSON.parse(String(d.stdout).trim()))}catch{return null}}let l=j(t,{providers:{}}).providers?.[m];if(!l)return null;try{return xe(l)}catch{return null}}function f(b,m){let h=q(b),l=xe(m);if(o){let w=r("secret-tool",["store",`--label=Oracle ${h} OAuth`,...u(h)],{input:JSON.stringify(l),encoding:"utf8",stdio:["pipe","ignore","pipe"]});if(w.error||w.status!==0)throw new Error("OS credential store rejected OAuth credential");let O=j(n,{providers:{}});return O.providers||={},O.providers[h]={expiresAt:l.expiresAt,source:l.source},G(n,O),l}let d=j(t,{providers:{}});return d.providers||={},d.providers[h]=l,G(t,d),l}function p(b){let m=q(b);if(o){let d=r("secret-tool",["clear",...u(m)],{encoding:"utf8",stdio:["ignore","ignore","pipe"]}),w=j(n,{providers:{}});return w.providers&&delete w.providers[m],G(n,w),!d.error&&d.status===0}let h=j(t,{providers:{}}),l=!!h.providers?.[m];return h.providers&&delete h.providers[m],G(t,h),l}function y(b){let m=ct(b);if(o){let h=r("secret-tool",["lookup",...u(m,"api-key")],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});return h.error||h.status!==0?"":String(h.stdout||"").trim()}return String(j(t,{apiKeys:{}}).apiKeys?.[m]||"").trim()}function x(b,m){let h=ct(b),l=String(m||"").trim();if(!l)throw new Error("API key is empty");if(o){let w=r("secret-tool",["store",`--label=Oracle ${h} API key`,...u(h,"api-key")],{input:l,encoding:"utf8",stdio:["pipe","ignore","pipe"]});if(w.error||w.status!==0)throw new Error("OS credential store rejected API key");let O=j(n,{providers:{},apiKeys:{}});return O.apiKeys||={},O.apiKeys[h]={configured:!0},G(n,O),!0}let d=j(t,{providers:{},apiKeys:{}});return d.apiKeys||={},d.apiKeys[h]=l,G(t,d),!0}function _(b){let m=ct(b);if(o){let d=r("secret-tool",["clear",...u(m,"api-key")],{encoding:"utf8",stdio:["ignore","ignore","pipe"]}),w=j(n,{providers:{},apiKeys:{}});return w.apiKeys&&delete w.apiKeys[m],G(n,w),!d.error&&d.status===0}let h=j(t,{providers:{},apiKeys:{}}),l=!!h.apiKeys?.[m];return h.apiKeys&&delete h.apiKeys[m],G(t,h),l}function v(){let b={},m={};if(o){let h=j(n,{providers:{},apiKeys:{}});for(let[l,d]of Object.entries(h.providers||{}))b[l]={loggedIn:!!c(l),expiresAt:Number(d.expiresAt||0),source:String(d.source||"oracle"),storage:i};for(let l of Object.keys(h.apiKeys||{}))m[l]={configured:!!y(l),storage:i}}else{let h=j(t,{providers:{},apiKeys:{}});for(let[l,d]of Object.entries(h.providers||{}))b[l]={loggedIn:!!d?.accessToken,expiresAt:Number(d?.expiresAt||0),source:String(d?.source||"oracle"),storage:i};for(let[l,d]of Object.entries(h.apiKeys||{}))m[l]={configured:!!d,storage:i}}return{storage:i,providers:b,apiKeys:m}}return Object.freeze({file:t,storage:i,get:c,set:f,remove:p,getApiKey:y,setApiKey:x,removeApiKey:_,status:v,withLock:a})}function ce(){return kn||=dt(),kn}function at(e){return Buffer.from(e).toString("base64url")}function Eo(){let e=at(ut(32));return{verifier:e,challenge:at(bo("sha256").update(e).digest()),state:at(ut(24))}}function Ao(e,t){let n=Buffer.from(String(e||"")),r=Buffer.from(String(t||""));return n.length===r.length&&_o(n,r)}function Oo(e){let t=String(e),n=process.platform==="darwin"?["open",[t]]:process.platform==="win32"?["cmd.exe",["/d","/s","/c","start","",t]]:["xdg-open",[t]];try{return vo(n[0],n[1],{detached:!0,stdio:"ignore"}).unref(),!0}catch{return!1}}function Le(e){return new URLSearchParams(e).toString()}async function z(e,t){if(!e?.ok){let r="";try{r=String((await e.json())?.error||"")}catch{}throw new Error(`${t} failed (HTTP ${e?.status||"unknown"}${r?`, ${r}`:""})`)}let n=await e.json();if(!n||typeof n!="object")throw new Error(`${t} returned invalid JSON`);return n}async function Co(e){if(e)return String(await e()).trim();let t=wo.createInterface({input:process.stdin,output:process.stdout});try{return String(await t.question("Authorization code: ")).trim()}finally{t.close()}}function Re(e,t={}){let n=String(e.access_token||"").trim(),r=String(e.refresh_token||t.refreshToken||"").trim();if(!n)throw new Error("OAuth token response is missing access token");let o=Number(e.expires_in||3600);return xe({accessToken:n,refreshToken:r,expiresAt:lt(t)+Math.max(1,o)*1e3,tokenType:e.token_type||"Bearer",idToken:e.id_token,source:"oracle",...t.discovery?{discovery:t.discovery}:{},...e.scope?{scope:e.scope}:{}})}async function Io(e){let t=se["anthropic-oauth"],n=e.pkce||Eo(),r=new URLSearchParams({code:"true",client_id:t.clientId,response_type:"code",redirect_uri:t.redirectUri,scope:t.scope,code_challenge:n.challenge,code_challenge_method:"S256",state:n.state}),o=`${t.authorizeUrl}?${r}`;e.output(`Open: ${o}`),e.openFn(o);let i=await Co(e.inputFn),[s,a]=i.split("#",2);if(!s||!Ao(a,n.state))throw new Error("Claude OAuth state mismatch");let u=await e.fetchFn(t.tokenUrl,{method:"POST",headers:{"content-type":"application/json","user-agent":"axios/1.7.9"},body:JSON.stringify({grant_type:"authorization_code",client_id:t.clientId,code:s,state:a,redirect_uri:t.redirectUri,code_verifier:n.verifier})});return Re(await z(u,"Claude OAuth token exchange"),e)}async function Lo(e){let t=se["openai-codex"],n=await z(await e.fetchFn(`${t.issuer}/api/accounts/deviceauth/usercode`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({client_id:t.clientId})}),"Codex device authorization");if(!n.user_code||!n.device_auth_id)throw new Error("Codex device authorization returned incomplete data");let r=`${t.issuer}/codex/device`;e.output(`Open: ${r}`),e.output(`Code: ${n.user_code}`),e.openFn(r);let o=Math.max(3,Number(n.interval||5)),i;for(let a=0;a<Math.ceil(900/o);a+=1){await e.sleepFn(o*1e3);let u=await e.fetchFn(`${t.issuer}/api/accounts/deviceauth/token`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({device_auth_id:n.device_auth_id,user_code:n.user_code})});if(u.ok){i=await z(u,"Codex device authorization");break}if(![403,404].includes(u.status))throw new Error(`Codex device authorization failed (HTTP ${u.status})`)}if(!i)throw new Error("Codex device authorization timed out");let s=await e.fetchFn(t.tokenUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:Le({grant_type:"authorization_code",code:i.authorization_code,redirect_uri:`${t.issuer}/deviceauth/callback`,client_id:t.clientId,code_verifier:i.code_verifier})});return Re(await z(s,"Codex OAuth token exchange"),e)}function V(e){let t=new URL(String(e)),n=t.hostname.toLowerCase();if(t.protocol!=="https:"||n!=="x.ai"&&!n.endsWith(".x.ai"))throw new Error("xAI OAuth discovery returned an untrusted endpoint");return t.toString()}async function Ro(e){let t=se["xai-oauth"],n=await z(await e.fetchFn(t.discoveryUrl,{headers:{accept:"application/json"}}),"xAI OAuth discovery");V(n.authorization_endpoint);let r=V(n.token_endpoint),o=await z(await e.fetchFn(t.deviceUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},body:Le({client_id:t.clientId,scope:t.scope})}),"xAI device authorization");if(!o.device_code||!o.user_code||!o.verification_uri)throw new Error("xAI device authorization returned incomplete data");let i=V(o.verification_uri_complete||o.verification_uri);e.output(`Open: ${i}`),e.output(`Code: ${o.user_code}`),e.openFn(i);let s=Math.max(1,Number(o.interval||5)),a=Math.ceil(Math.max(1,Number(o.expires_in||600))/s);for(let u=0;u<a;u+=1){let c=await e.fetchFn(r,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},body:Le({grant_type:"urn:ietf:params:oauth:grant-type:device_code",client_id:t.clientId,device_code:o.device_code})});if(c.ok){let p=await z(c,"xAI OAuth token exchange");return Re(p,{...e,discovery:{authorization_endpoint:V(n.authorization_endpoint),token_endpoint:r}})}let f="";try{f=String((await c.json())?.error||"")}catch{}if(f==="slow_down")await e.sleepFn((s+1)*1e3);else if(f==="authorization_pending")await e.sleepFn(s*1e3);else throw new Error(`xAI OAuth token exchange failed (HTTP ${c.status}${f?`, ${f}`:""})`)}throw new Error("xAI device authorization timed out")}async function An(e,t={}){let n=q(e),r={fetchFn:t.fetchFn||globalThis.fetch,inputFn:t.inputFn,sleepFn:t.sleepFn||(o=>new Promise(i=>setTimeout(i,o))),openFn:t.openFn||Oo,output:t.output||(o=>process.stdout.write(`${o}
|
|
3
|
+
`)),now:t.now,pkce:t.pkce};return n==="anthropic-oauth"?Io(r):n==="openai-codex"?Lo(r):Ro(r)}async function pt(e,t,n={}){let r=q(e),o=se[r],i=xe(t);if(!i.refreshToken)throw new Error(`${r} OAuth credential cannot refresh; run oracle auth login`);let s=i.discovery,a,u=n.fetchFn||globalThis.fetch;if(r==="xai-oauth"){if(!s?.token_endpoint){let p=await u(o.discoveryUrl),y=await z(p,"xAI OAuth discovery");s={...y.authorization_endpoint?{authorization_endpoint:V(y.authorization_endpoint)}:{},token_endpoint:V(y.token_endpoint)}}a=V(s.token_endpoint)}else a=o.tokenUrl;let c=await u(a,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json",...r==="anthropic-oauth"?{"user-agent":"axios/1.7.9"}:{}},body:Le({grant_type:"refresh_token",refresh_token:i.refreshToken,client_id:o.clientId})}),f=await z(c,`${r} OAuth refresh`);return Re(f,{...n,refreshToken:i.refreshToken,discovery:s})}async function On(e,t={}){let n=q(e),r=t.store||ce(),o=r.get(n);if(!o)throw new Error(`${n} OAuth is not logged in; run oracle auth login ${e}`);let i=lt(t);if(!o.expiresAt||o.expiresAt>i+Sn)return o;let s=async()=>{let a=r.get(n);if(!a)throw new Error(`${n} OAuth is not logged in; run oracle auth login ${e}`);let u=lt(t);if(!a.expiresAt||a.expiresAt>u+Sn)return a;let c=await pt(n,a,t);return r.set(n,c),c};return typeof r.withLock=="function"?r.withLock(s):s()}function Cn(e,t={}){try{return!!(t.store||ce()).get(e)?.accessToken}catch{return!1}}function In(e){let t=ft(e);return{kind:"standalone",provider:t.id,model:t.model,baseUrl:t.baseUrl,authType:"oauth",protocol:t.protocol}}var se,Sn,kn,To,mt=bt(()=>{J();se=Object.freeze({"anthropic-oauth":{aliases:["anthropic-oauth","anthropic","claude","claude-oauth"],clientId:"9d1c250a-e61b-44d9-88ed-5944d1962f5e",authorizeUrl:"https://claude.ai/oauth/authorize",tokenUrl:"https://platform.claude.com/v1/oauth/token",redirectUri:"https://console.anthropic.com/oauth/code/callback",scope:"org:create_api_key user:profile user:inference",baseUrl:"https://api.anthropic.com/v1",model:"claude-sonnet-4-6",protocol:"anthropic-messages"},"openai-codex":{aliases:["openai-codex","openai-oauth","codex","codex-oauth"],clientId:"app_EMoamEEZ73f0CkXaXp7hrann",issuer:"https://auth.openai.com",tokenUrl:"https://auth.openai.com/oauth/token",baseUrl:"https://chatgpt.com/backend-api/codex",model:"gpt-5.6-sol",protocol:"responses"},"xai-oauth":{aliases:["xai-oauth","xai","grok","grok-oauth"],clientId:"b1a00492-073a-47ea-816f-4c329264a828",issuer:"https://auth.x.ai",discoveryUrl:"https://auth.x.ai/.well-known/openid-configuration",deviceUrl:"https://auth.x.ai/oauth2/device/code",scope:"openid profile email offline_access grok-cli:access api:access",baseUrl:"https://api.x.ai/v1",model:"grok-4.5",protocol:"responses"}}),Sn=12e4;To={createOAuthStore:dt,getOAuthStore:ce,hasOAuthCredentials:Cn,loginOAuth:An,oauthProviderConfig:ft,oauthProviderId:q,oauthRuntimeConfig:In,refreshOAuthCredentials:pt,resolveOAuthCredentials:On}});import{spawn as Wn}from"node:child_process";var Gn=["SIGINT","SIGTERM","SIGHUP"];function Q(e,t=[],n={},r=e){return new Promise(o=>{let i=Wn(e,t,n),s=!1,a=null,u=new Map(Gn.map(f=>[f,()=>{a||=f,i.exitCode===null&&i.signalCode===null&&i.kill(f)}]));for(let[f,p]of u)process.on(f,p);let c=()=>{for(let[f,p]of u)process.off(f,p)};i.once("error",f=>{s||(s=!0,c(),process.stderr.write(`oracle: could not start ${r}: ${f.message}
|
|
4
|
+
`),o(1))}),i.once("exit",(f,p)=>{if(s)return;s=!0,c();let y=a||p;if(y){process.kill(process.pid,y);return}o(f??1)})})}import wt from"node:fs";import ee from"node:path";J();var tr="0.19.0",$i=`hermes-agent==${tr}`;var _t="0.12.1",Pi=Object.freeze({posix:Object.freeze({url:`https://github.com/astral-sh/uv/releases/download/${_t}/uv-installer.sh`,sha256:"d3f5412d38c99f9d024901843bf98206f0d2c6dbe64df40d0b740e2751ca62c1"}),windows:Object.freeze({url:`https://github.com/astral-sh/uv/releases/download/${_t}/uv-installer.ps1`,sha256:"b9ec035151bfbb11d616dbd69886498d885551489eddf095ea3c0ad59f640eb0"})});function nr(){return ee.join(D(),"runtime")}function rr(){return ee.join(nr(),"venv")}function or(e){let t=process.platform==="win32"?"Scripts":"bin",n=process.platform==="win32"?`${e}.exe`:e;return ee.join(rr(),t,n)}function ir(){return or("hermes")}function sr(e){let t=process.platform==="win32"&&!ee.extname(e)?["",".exe",".cmd",".bat"]:[""];for(let n of(process.env.PATH||"").split(ee.delimiter))if(n)for(let r of t){let o=ee.join(n,`${e}${r}`);try{if(wt.existsSync(o))return o}catch{}}return null}function de(){if(process.env.ORACLE_HERMES_BIN)return{ok:!0,bin:process.env.ORACLE_HERMES_BIN,source:"env"};let e=sr("hermes");if(e)return{ok:!0,bin:e,source:"path"};let t=ir();return wt.existsSync(t)?{ok:!0,bin:t,source:"managed"}:{ok:!1,bin:null,source:null}}J();import te from"node:fs";import Pe from"node:path";var cr=new Set(["auto","standalone","hermes","remote","arch"]),ar=new Set(["openrouter","openai","xai","deepseek","gemini","custom","anthropic-oauth","openai-codex","xai-oauth"]);function vt(){return Pe.join(D(),"model.json")}function K(e){return String(e||"").trim()||void 0}function St(e={}){let t=K(e.backend)?.toLowerCase()||"auto",n=K(e.provider)?.toLowerCase(),r=K(e.model),o=K(e.baseUrl)?.replace(/\/+$/,""),i=K(e.apiKeyEnv),s=Number.parseInt(String(e.contextLength||""),10),a=K(e.reasoningEffort),u=K(e.computeHost||e.remoteHost),c=K(e.computeUser||e.remoteUser),f=K(e.computePath||e.remotePath);if(!cr.has(t))throw new Error(`unsupported backend: ${t}`);if(process.env.ORACLE_PUBLIC_DESKTOP==="1"&&["remote","arch"].includes(t))throw new Error("remote compute backends are disabled in the public desktop");if(n&&!ar.has(n))throw new Error(`unsupported provider: ${n}`);if(o&&n!=="custom")throw new Error("baseUrl is only supported for the custom provider");if(i&&!/^[A-Z][A-Z0-9_]*$/.test(i))throw new Error("api key env must be an uppercase environment variable name");if(n==="custom"&&!o)throw new Error("custom provider requires baseUrl");if(t==="standalone"&&!r)throw new Error("standalone backend requires a model");if(t==="remote"&&!u)throw new Error("remote backend requires computeHost");return{backend:t,...n?{provider:n}:{},...r?{model:r}:{},...o?{baseUrl:o}:{},...i?{apiKeyEnv:i}:{},...Number.isFinite(s)&&s>0?{contextLength:s}:{},...a?{reasoningEffort:a}:{},...u?{computeHost:u}:{},...c?{computeUser:c}:{},...f?{computePath:f}:{}}}function pe(){let e=vt();if(!te.existsSync(e))return null;try{return St(JSON.parse(te.readFileSync(e,"utf8")))}catch{return null}}function kt(e){let t=St(e),n=vt();P(Pe.dirname(n)),process.platform!=="win32"&&te.chmodSync(Pe.dirname(n),448);let r=`${n}.${process.pid}.tmp`;return te.writeFileSync(r,`${JSON.stringify(t,null,2)}
|
|
5
|
+
`,{mode:384}),te.renameSync(r,n),process.platform!=="win32"&&te.chmodSync(n,384),t}J();import A from"node:fs";import S from"node:path";import{spawnSync as oi}from"node:child_process";import At from"node:fs";import lr from"node:path";var ur=Object.freeze([{key:"hyperliquid",aliases:["hl","hyperevm","hype","999"],chainId:999,name:"hyperliquid",kind:"evm",family:"hyperliquid",agent:"hyperliquid-agent",note:"perps \xB7 hip-3/4 \xB7 hyperevm 999",build:!0},{key:"ethereum",aliases:["eth","mainnet","1"],chainId:1,name:"ethereum",kind:"evm",family:"evm",agent:"oracle",note:"l1 \xB7 bridge hub",build:!0},{key:"base",aliases:["8453"],chainId:8453,name:"base",kind:"evm",family:"evm",agent:"oracle",note:"evm l2",build:!0},{key:"arbitrum",aliases:["arb","42161"],chainId:42161,name:"arbitrum",kind:"evm",family:"evm",agent:"oracle",note:"evm l2",build:!0},{key:"optimism",aliases:["op","10"],chainId:10,name:"optimism",kind:"evm",family:"evm",agent:"oracle",note:"op mainnet",build:!0},{key:"polygon",aliases:["matic","137"],chainId:137,name:"polygon",kind:"evm",family:"evm",agent:"oracle",note:"evm l2",build:!0},{key:"bsc",aliases:["bnb","56"],chainId:56,name:"bnb chain",kind:"evm",family:"evm",agent:"oracle",note:"bsc",build:!0},{key:"avalanche",aliases:["avax","43114"],chainId:43114,name:"avalanche",kind:"evm",family:"evm",agent:"oracle",note:"c-chain",build:!0},{key:"abstract",aliases:["abs","2741"],chainId:2741,name:"abstract",kind:"evm",family:"evm",agent:"oracle",note:"open / add agent",build:!0},{key:"stable",aliases:["988"],chainId:988,name:"stable",kind:"evm",family:"stable",agent:"stable-agent",note:"usdt0 gas \xB7 stable agent",build:!0},{key:"robinhood",aliases:["rh","4663"],chainId:4663,name:"robinhood",kind:"evm",family:"robinhood",agent:"robinhood-agent",note:"rh chain 4663",build:!0},{key:"solana",aliases:["sol"],chainId:"SOL",name:"solana",kind:"svm",family:"solana",agent:"solana-agent",note:"jup \xB7 nfts \xB7 dexs",build:!0},{key:"bitcoin",aliases:["btc"],chainId:"BTC",name:"bitcoin",kind:"utxo",family:"bitcoin",agent:"bitcoin-agent",note:"ord \xB7 runes \xB7 l1",build:!0},{key:"polymarket",aliases:["poly","polygon-poly"],chainId:137,name:"polymarket",kind:"venue",family:"polymarket",agent:"polymarket-agent",note:"prediction markets (polygon venue)",build:!1}]);function Ne(e){return String(e||"").trim().toLowerCase().replace(/^\/+/,"").replace(/\s+/g,"-")}function Et(e){let t=Ne(e);if(!t)return null;for(let n of ur)if(n.key===t||String(n.chainId).toLowerCase()===t||(n.aliases||[]).map(Ne).includes(t)||Ne(n.name)===t)return n;return null}J();function fr(){return lr.join(D(),"active-chain.json")}function dr(){let e=fr();if(!At.existsSync(e))return null;try{let t=JSON.parse(At.readFileSync(e,"utf8"));if(!t||typeof t!="object"||!t.key)return null;let n=Et(t.key);return n?{key:n.key,chainId:n.chainId,name:n.name,agent:n.agent,selectedAt:t.selectedAt||null}:null}catch{return null}}function _e(e={}){let t=dr(),n={...process.env,...e};return t&&(n.ORACLE_ACTIVE_CHAIN=t.key,n.ORACLE_ACTIVE_CHAIN_ID=String(t.chainId),n.ORACLE_ACTIVE_AGENT=t.agent||"oracle"),n}import{EventEmitter as zr}from"node:events";import{spawn as pr}from"node:child_process";import{EventEmitter as mr}from"node:events";import{createInterface as Ot}from"node:readline";var hr=15e3,xr=12e4;function yr(e){let t=typeof e=="string"?e:e?.message||"Gateway request failed",n=new Error(t);return n.error=e,n}function gr(e){let t=Buffer.from(e);if(t.length<=4096)return e;let n=t.length-4096;return`${t.subarray(0,4096).toString("utf8")} ... [truncated ${n} bytes]`}function Ct({python:e,pythonArgs:t=[],cwd:n,env:r,spawnFn:o=pr,startupTimeoutMs:i=hr,requestTimeoutMs:s=xr}={}){let a=new mr,u=new Map,c=null,f=1,p=null,y=null,x=!1;function _(d){a.listenerCount("error")>0&&a.emit("error",d)}function v(d){for(let w of u.values())clearTimeout(w.timer),w.reject(d);u.clear()}function b(d){if(!("id"in d)){a.emit("event",d);return}let w=u.get(d.id);w&&(u.delete(d.id),clearTimeout(w.timer),"error"in d?w.reject(yr(d.error)):w.resolve(d.result))}function m(){return p||(p=new Promise((d,w)=>{let O=!1,k,g=C=>{O||(O=!0,clearTimeout(k),C?w(C):d())};try{c=o(e,[...t,"-m","tui_gateway.entry"],{cwd:n,env:r})}catch(C){g(C),_(C);return}let L=Ot({input:c.stdout}),Y=Ot({input:c.stderr});L.on("line",C=>{let F;try{F=JSON.parse(C)}catch{a.emit("log",C);return}g(),b(F)}),Y.on("line",C=>a.emit("log",gr(C))),c.once("error",C=>{g(C),v(C),_(C)}),c.once("exit",(C,F)=>{x=!0;let ae=new Error(`Gateway exited with code ${C} and signal ${F}`);g(ae),v(ae),a.emit("exit",{code:C,signal:F})}),k=setTimeout(()=>{g(new Error(`Gateway startup timed out after ${i} ms`))},i)}),p)}function h(d,w){if(!c||x)return Promise.reject(new Error("Gateway is not running"));let O=f++;return new Promise((k,g)=>{let L=setTimeout(()=>{u.delete(O),g(new Error(`Gateway request ${O} timed out after ${s} ms`))},s);u.set(O,{resolve:k,reject:g,timer:L});try{c.stdin.write(`${JSON.stringify({id:O,method:d,params:w})}
|
|
6
|
+
`)}catch(Y){clearTimeout(L),u.delete(O),g(Y)}})}function l(){if(y)return y;if(!c||x)return Promise.resolve();let d=new Error("Gateway stopped while requests were pending");return v(d),y=new Promise(w=>{c.once("exit",w);try{c.kill()}catch{w()}}),y}return{start:m,request:h,stop:l,on(d,w){return a.on(d,w),this},off(d,w){return a.off(d,w),this}}}var me=Buffer.alloc(0),br=new Set(["return","backspace","tab","escape","up","down","left","right","home","end","delete","insert","pageup","pagedown","unknown"]),_r={A:"up",B:"down",C:"right",D:"left",H:"home",F:"end",P:"f1",Q:"f2",R:"f3",S:"f4"},wr={1:"home",2:"insert",3:"delete",4:"end",5:"pageup",6:"pagedown",7:"home",8:"end"};function N({name:e=null,ctrl:t=!1,meta:n=!1,shift:r=!1,sequence:o=""}){return{name:e,ctrl:t,meta:n,shift:r,sequence:o}}function Tt(e){return e<128?1:e>=240?4:e>=224?3:e>=192?2:1}function vr(e){return e>=64&&e<=126}function It(e){let t=e.toLowerCase();return N({name:t,shift:e!==t,sequence:e})}function Sr(e){return e===13?N({name:"return",sequence:"\r"}):e===10?N({name:"return",sequence:`
|
|
7
|
+
`}):e===9?N({name:"tab",sequence:" "}):e===127?N({name:"backspace",sequence:"\x7F"}):e===8?N({name:"backspace",sequence:"\b"}):e>=1&&e<=26?N({name:String.fromCharCode(e+96),ctrl:!0,sequence:String.fromCharCode(e)}):N({name:"unknown",sequence:String.fromCharCode(e)})}function kr(e){let t=/^\u001b[\[O](\d*)(?:;(\d+))?(.)$/s.exec(e);if(!t)return N({name:"unknown",sequence:e});let n=t[1]===""?null:Number(t[1]),r=t[2]===void 0?null:Number(t[2]),o=t[3],i=null,s=r;if(o==="~"?i=wr[n]??null:(i=_r[o]??null,s===null&&n!==null&&n>1&&(s=n)),!i)return N({name:"unknown",sequence:e});let a=s===null?0:Math.max(0,s-1);return N({name:i,shift:(a&1)!==0,meta:(a&2)!==0,ctrl:(a&4)!==0,sequence:e})}function Er(e,t,n,r){let o=()=>(n.push(N({name:"escape",sequence:"\x1B"})),1);if(t+1>=e.length)return r?o():0;let i=e[t+1];if(i===91||i===79){let c=t+2;for(;c<e.length&&!vr(e[c]);)c+=1;return c>=e.length?r?o():0:(n.push(kr(e.toString("utf8",t,c+1))),c+1-t)}if(i===27)return o();let s=Tt(i);if(t+1+s>e.length)return r?o():0;let a=e.toString("utf8",t+1,t+1+s),u=a.toLowerCase();return n.push(N({name:u,meta:!0,shift:a!==u,sequence:`\x1B${a}`})),1+s}function Lt(e,t){let n=[],r=0;for(;r<e.length;){let o=e[r];if(o===27){let s=Er(e,r,n,t);if(s===0)return{keys:n,rest:Buffer.from(e.subarray(r))};r+=s;continue}if(o<32||o===127){n.push(Sr(o)),r+=1;continue}let i=Tt(o);if(r+i>e.length)return t?(n.push(It(e.toString("utf8",r))),{keys:n,rest:me}):{keys:n,rest:Buffer.from(e.subarray(r))};n.push(It(e.toString("utf8",r,r+i))),r+=i}return{keys:n,rest:me}}function Rt(e){return Buffer.isBuffer(e)?e:e==null?me:typeof e=="string"?Buffer.from(e,"utf8"):Buffer.from(e)}function Ar(){let e=me;return{push(t){let n=e.length===0?Rt(t):Buffer.concat([e,Rt(t)]),{keys:r,rest:o}=Lt(n,!1);return e=o,r},flush(){if(e.length===0)return[];let{keys:t}=Lt(e,!0);return e=me,t},get pending(){return e.length}}}function Or({history:e=[]}={}){let t=[...e];return{buffer:"",cursor:0,history:t,historyIndex:t.length,draft:""}}function je(e,t){if(t<=0)return 0;let n=t-1,r=e.charCodeAt(n);if(r>=56320&&r<=57343&&n>0){let o=e.charCodeAt(n-1);if(o>=55296&&o<=56319)return n-1}return n}function Fe(e,t){if(t>=e.length)return e.length;let n=e.charCodeAt(t);return n>=55296&&n<=56319&&t+1<e.length?t+2:t+1}function E(e,t){return{...e,...t}}function $t(e,t){return E(e,{...t,historyIndex:e.history.length,draft:""})}function Cr(e){if(e.ctrl||e.meta||!e.sequence||br.has(e.name))return!1;for(let t of e.sequence){let n=t.codePointAt(0);if(n<32||n===127)return!1}return!0}function Ir(e,t){let n=t;for(;n>0&&/\s/.test(e[n-1]);)n-=1;for(;n>0&&!/\s/.test(e[n-1]);)n-=1;return n}function Lr(e){if(e.historyIndex<=0)return{state:E(e,{}),action:null};let t=e.historyIndex>=e.history.length,n=e.historyIndex-1,r=e.history[n]??"";return{state:E(e,{buffer:r,cursor:r.length,historyIndex:n,draft:t?e.buffer:e.draft}),action:null}}function Rr(e){if(e.historyIndex>=e.history.length)return{state:E(e,{}),action:null};let t=e.historyIndex+1,n=t>=e.history.length,r=n?e.draft:e.history[t]??"";return{state:E(e,{buffer:r,cursor:r.length,historyIndex:t,draft:n?"":e.draft}),action:null}}function Tr(e){let t=e.buffer.trim();if(t==="")return{state:$t(e,{buffer:"",cursor:0}),action:null};let n=e.history[e.history.length-1]===t?[...e.history]:[...e.history,t];return{state:E(e,{buffer:"",cursor:0,history:n,historyIndex:n.length,draft:""}),action:{type:"submit",value:t}}}function $r(e,t){if(!t)return{state:E(e,{}),action:null};let{buffer:n,cursor:r}=e;if(t.ctrl&&!t.meta)switch(t.name){case"c":return{state:$t(e,{buffer:"",cursor:0}),action:{type:"cancel"}};case"d":return n===""?{state:E(e,{}),action:{type:"eof"}}:{state:E(e,{}),action:null};case"l":return{state:E(e,{}),action:{type:"clear"}};case"a":return{state:E(e,{cursor:0}),action:null};case"e":return{state:E(e,{cursor:n.length}),action:null};case"u":return{state:E(e,{buffer:n.slice(r),cursor:0}),action:null};case"k":return{state:E(e,{buffer:n.slice(0,r)}),action:null};case"w":{let o=Ir(n,r);return{state:E(e,{buffer:n.slice(0,o)+n.slice(r),cursor:o}),action:null}}case"b":return{state:E(e,{cursor:je(n,r)}),action:null};case"f":return{state:E(e,{cursor:Fe(n,r)}),action:null};default:return{state:E(e,{}),action:null}}switch(t.name){case"return":return Tr(e);case"left":return{state:E(e,{cursor:je(n,r)}),action:null};case"right":return{state:E(e,{cursor:Fe(n,r)}),action:null};case"home":return{state:E(e,{cursor:0}),action:null};case"end":return{state:E(e,{cursor:n.length}),action:null};case"up":return Lr(e);case"down":return Rr(e);case"backspace":{if(r===0)return{state:E(e,{}),action:null};let o=je(n,r);return{state:E(e,{buffer:n.slice(0,o)+n.slice(r),cursor:o}),action:null}}case"delete":{if(r>=n.length)return{state:E(e,{}),action:null};let o=Fe(n,r);return{state:E(e,{buffer:n.slice(0,r)+n.slice(o)}),action:null}}default:break}if(Cr(t)){let o=t.sequence;return{state:E(e,{buffer:n.slice(0,r)+o+n.slice(r),cursor:r+o.length}),action:null}}return{state:E(e,{}),action:null}}function Pt(e={}){let{stdin:t,stdout:n,history:r=[],onSubmit:o,onCancel:i,onEof:s,onClear:a,onRender:u}=e,c=t??process.stdin,f=n??process.stdout,p=Ar(),y={submit:o,cancel:i,eof:s,clear:a},x=Or({history:r}),_=!1,v=!1,b=!1,m=l=>{if(!l)return;let d=y[l.type];typeof d=="function"&&d(l.value,x)},h=l=>{for(let d of p.push(l)){let w=$r(x,d);x=w.state,m(w.action),typeof u=="function"&&u(x)}};return{start(){_||(_=!0,c.isTTY&&typeof c.setRawMode=="function"&&(b=c.isRaw===!0,c.setRawMode(!0),v=!0),typeof c.resume=="function"&&c.resume(),c.on("data",h),typeof u=="function"&&u(x))},stop(){_&&(_=!1,typeof c.off=="function"?c.off("data",h):typeof c.removeListener=="function"&&c.removeListener("data",h),v&&typeof c.setRawMode=="function"&&(c.setRawMode(b),v=!1),typeof c.pause=="function"&&c.pause())},getState(){return x},setState(l){return x=l,x},write(l){f&&typeof f.write=="function"&&f.write(l)},get isRunning(){return _}}}var Me="\x1B[?25l",we="\x1B[?25h",Nt="\x1B[2K",ve="\x1B[0J";var Pr="\x1B\\[[0-9;?]*[a-zA-Z]";function Mt(){return new RegExp(Pr,"g")}function Nr(e){return String(e??"").replace(Mt(),"")}function jt(e,t){return t.some(([n,r])=>e>=n&&e<=r)}function Ut(e){return e===0||e<32||e>=127&&e<160||jt(e,[[768,879],[1155,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1552,1562],[1611,1631],[1648,1648],[1750,1757],[1759,1764],[1767,1768],[1770,1773],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2070,2073],[2075,2083],[2085,2087],[2089,2093],[2137,2139],[2259,2273],[2275,2307],[2362,2364],[2369,2376],[2381,2381],[2385,2391],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2641,2641],[2672,2673],[2677,2677],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2884],[2893,2893],[2902,2902],[2914,2915],[2946,2946],[3008,3008],[3021,3021],[3072,3072],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3170,3171],[3201,3201],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3329,3329],[3393,3396],[3405,3405],[3426,3427],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3981,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4151],[4153,4154],[4157,4158],[4184,4185],[4190,4192],[4209,4212],[4226,4226],[4229,4230],[4237,4237],[4253,4253],[4957,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6277,6278],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6683,6683],[6742,6742],[6744,6750],[6752,6752],[6754,6754],[6757,6764],[6771,6780],[6783,6783],[6832,6911],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7040,7041],[7074,7077],[7080,7081],[7083,7085],[7142,7142],[7144,7145],[7149,7149],[7151,7153],[7212,7219],[7222,7223],[7376,7378],[7380,7392],[7394,7400],[7405,7405],[7412,7412],[7416,7417],[7616,7679],[8203,8207],[8234,8238],[8288,8292],[8294,8303],[8400,8447],[65024,65039],[65056,65071],[917760,917999]])?0:jt(e,[[4352,4447],[8986,8987],[9001,9002],[9193,9196],[9200,9200],[9203,9203],[9725,9726],[9748,9749],[9800,9811],[9855,9855],[9875,9875],[9889,9889],[9898,9899],[9917,9918],[9924,9925],[9934,9934],[9940,9940],[9962,9962],[9970,9971],[9973,9973],[9978,9978],[9981,9981],[9989,9989],[9994,9995],[10024,10024],[10060,10060],[10062,10062],[10067,10069],[10071,10071],[10133,10135],[10160,10160],[10175,10175],[11035,11036],[11088,11088],[11093,11093],[11904,12350],[12352,42191],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[127744,128591],[129280,129535],[131072,262141]])?2:1}function jr(e){let t=0;for(let n of Array.from(e))t+=Ut(n.codePointAt(0));return t}function Fr(e){return jr(Nr(e))}function Mr(e){return/^\u001b\[0*m$/.test(e)}function Ft(e,t){let n="",r=0;for(let o of Array.from(e)){let i=Ut(o.codePointAt(0));if(r+i>t)break;n+=o,r+=i}return{text:n,width:r}}function Ur(e,t){let n=String(e??"");if(t<=0)return"";if(Fr(n)<=t)return n;let r=Mt(),o="",i=0,s=!1,a=0,u=r.exec(n);for(;u!==null;){let f=Ft(n.slice(a,u.index),t-i);if(o+=f.text,i+=f.width,i>=t)return s?`${o}\x1B[0m`:o;o+=u[0],u[0].endsWith("m")&&(s=!Mr(u[0])),a=u.index+u[0].length,u=r.exec(n)}let c=Ft(n.slice(a),t-i);return o+=c.text,s?`${o}\x1B[0m`:o}function Dr(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function Dt({stdout:e,rows:t,columns:n}={}){if(!e||typeof e.write!="function")throw new TypeError("createRenderer requires a stdout with a write(string) method");let r=Number.isFinite(t)?Math.trunc(t):null,o=Number.isFinite(n)?Math.trunc(n):null,i=r??(Number.isFinite(e.rows)?Math.trunc(e.rows):24),s=o??(Number.isFinite(e.columns)?Math.trunc(e.columns):80),a=[],u=0,c=null,f=!1,p=!1,y=()=>{r===null&&(i=Number.isFinite(e.rows)?Math.trunc(e.rows):24),o===null&&(s=Number.isFinite(e.columns)?Math.trunc(e.columns):80),f=!0},x=typeof e.on=="function";x&&e.on("resize",y);function _(m){let h=m-u;return u=m,h===0?"":h<0?`\x1B[${-h}A`:`\x1B[${h}B`}function v(m){let l=(Array.isArray(m)?m:[]).map(d=>Ur(String(d??""),s));if(c!==null)for(l.length>c&&(l=l.slice(0,c));l.length<c;)l.push("");return l}function b(m){if(!f&&Dr(a,m))return;let h=[Me];f&&a.length>0&&(h.push(_(0),"\r",ve),a=[],u=0),f=!1;let l=Math.min(a.length,m.length);for(let d=0;d<l;d+=1)a[d]!==m[d]&&h.push(_(d),"\r",Nt,m[d]);if(m.length>a.length){a.length>0&&h.push(_(a.length-1));for(let d=a.length;d<m.length;d+=1)d>0&&h.push(`
|
|
8
|
+
`),h.push("\r",Nt,m[d]),u=d}else m.length<a.length&&h.push(_(m.length),"\r",ve);m.length>0&&h.push(_(m.length-1)),h.push(we),a=m,e.write(h.join(""))}return{render(m){p||b(v(m))},writeAbove(m){if(p)return;let h=String(m??""),l=Me;a.length>0&&(l+=`${_(0)}\r${ve}`),l+=h.endsWith(`
|
|
9
9
|
`)||h===""?h:`${h}
|
|
10
|
-
`,e.write(l);let d=a;a=[],u=0,d.length>0?b(d):e.write(
|
|
11
|
-
`)){if(o===""){r.push("");continue}let i="",
|
|
12
|
-
`)}function v(){let k=
|
|
13
|
-
`),g=k[k.length-1]||"";
|
|
14
|
-
`),
|
|
10
|
+
`,e.write(l);let d=a;a=[],u=0,d.length>0?b(d):e.write(we)},clear(){if(p)return;let m=Me;a.length>0&&(m+=`${_(0)}\r${ve}`),m+=we,e.write(m),a=[],u=0,f=!1},setLines(m){c=Number.isFinite(m)&&m>=0?Math.trunc(m):null},getLines(){return a.slice()},getSize(){return{rows:i,columns:s}},dispose(){if(!p){if(p=!0,x){let m=typeof e.off=="function"?e.off:e.removeListener;typeof m=="function"&&m.call(e,"resize",y)}e.write(we)}}}}var R=Object.freeze({accent:"#B8F0FF",prompt:"#B8F0FF",banner_title:"#B8F0FF",banner_accent:"#91C2D7",ui_label:"#A5D9EB",banner_text:"#EAF2F8",status_bar_strong:"#EAF2F8",banner_border:"#455867",input_rule:"#455867",session_border:"#455867",banner_dim:"#60717F",status_bar_dim:"#60717F",status_bar_bg:"#11161B",status_bar_text:"#91A2B1",ok:"#7EE7B5",error:"#FF7B7B",warn:"#F0C674",bad:"#FF9B71",selection_bg:"#23313B"});function Br(e){if(typeof e!="string")return null;let t=e.startsWith("#")?e.slice(1):e;if(!/^(?:[\da-f]{3}|[\da-f]{6})$/i.test(t))return null;let n=t.length===3?[...t].map(r=>r.repeat(2)).join(""):t;return{r:Number.parseInt(n.slice(0,2),16),g:Number.parseInt(n.slice(2,4),16),b:Number.parseInt(n.slice(4,6),16)}}function Bt(e,t,n){let r=Br(t);return r?`\x1B[${e};2;${r.r};${r.g};${r.b}m${String(n)}\x1B[0m`:String(n)}function Ue({color:e=!0}={}){return e&&!Object.hasOwn(process.env,"NO_COLOR")?Object.freeze({fg:(n,r)=>Bt(38,n,r),bg:(n,r)=>Bt(48,n,r),bold:n=>`\x1B[1m${String(n)}\x1B[0m`,dim:n=>`\x1B[2m${String(n)}\x1B[0m`}):Object.freeze({fg:(n,r)=>String(r),bg:(n,r)=>String(r),bold:n=>String(n),dim:n=>String(n)})}var Qi=Ue();function Kt(e){return String(e).replace(/\u001B\[[0-9;]*m/g,"")}var Ht=Object.freeze([["#B8F0FF"," \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 "],["#B8F0FF"," \u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588 \u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588 "],["#ACDEEF"," \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2591\u2591 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2591\u2591 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588 "],["#A5D9EB"," \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588\u2591\u2591\u2591 "],["#9FCBDD"," \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588 "],["#B8F0FF"," \u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591 "]]),De="THE FUTURE IS AGENTIC / by DEMI",Be=/\u001B\[[0-9;]*m/g;function zt(e){if(new RegExp("\\p{Mark}","u").test(e))return 0;let t=e.codePointAt(0);return t===8205||t===65039?0:t>=4352&&(t<=4447||t===9001||t===9002||t>=11904&&t<=42191&&t!==12351||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65040&&t<=65049||t>=65072&&t<=65135||t>=65280&&t<=65376||t>=65504&&t<=65510||t>=127744&&t<=129791||t>=131072&&t<=262141)?2:t<32||t>=127&&t<160?0:1}function H(e){return[...Kt(e)].reduce((t,n)=>t+zt(n),0)}function He(e,t){if(t<=0)return"";let n=String(e).split(/(\u001B\[[0-9;]*m)/g),r="",o=0,i=!1;for(let s of n)if(s){if(Be.test(s)){Be.lastIndex=0,r+=s,i=s!=="\x1B[0m";continue}Be.lastIndex=0;for(let a of s){let u=zt(a);if(o+u>t)return i?`${r}\x1B[0m`:r;r+=a,o+=u}}return r}function ne(e,t,n="left"){let r=Math.max(0,Math.floor(Number(t)||0)),o=He(String(e),r),i=Math.max(0,r-H(o));if(n==="right")return`${" ".repeat(i)}${o}`;if(n==="center"){let s=Math.floor(i/2);return`${" ".repeat(s)}${o}${" ".repeat(i-s)}`}return`${o}${" ".repeat(i)}`}function qe(e,t){let n=Math.max(1,Math.floor(Number(t)||1)),r=[];for(let o of String(e??"").split(`
|
|
11
|
+
`)){if(o===""){r.push("");continue}let i="",s=0;for(let a of o.split(" ")){let u=H(a);if(s>0&&s+1+u>n&&(r.push(i),i="",s=0),u>n){s>0&&(r.push(i),i="",s=0);let c=a;for(;H(c)>n;){let f=He(c,n);r.push(f),c=c.slice(f.length)}i=c,s=H(c);continue}i=s===0?a:`${i} ${a}`,s=s===0?u:s+1+u}r.push(i)}return r}function Kr(e){let t=Math.max(0,Math.floor(Number(e)||0)),n=Math.max(36,Math.min(t-4,76)),r=Math.max(0,Math.floor((t-n)/2)),o=r+3,i=Math.max(0,n-6);return{target:t,panelWidth:n,panelLeft:r,contentLeft:o,inner:i}}function Hr(e){let t=1/0,n=-1;for(let r of e)for(let o=0;o<r.length;o+=1)r[o]!==" "&&(o<t&&(t=o),o>n&&(n=o));return n<0?{offset:0,width:0}:{offset:t,width:n-t+1}}function qt(e,t,n=0){let{target:r,contentLeft:o,inner:i}=e,a=Math.round((r-t)/2)-n-o,u=Math.max(0,i-t-n);return Math.max(0,Math.min(u,a))}function ze({width:e,palette:t}){let n=Kr(e),{target:r,panelWidth:o,panelLeft:i,inner:s}=n;if(r<72||s<=0)return[ne(t.bold(t.fg(R.accent,"oracle")),r,"center"),ne(t.fg(R.banner_text,De),r,"center")];let a=Ht.map(([,l])=>l),{offset:u,width:c}=Hr(a),f=" ".repeat(qt(n,c,u)),p=" ".repeat(qt(n,H(De))),y=[];for(let[l,d]of Ht)y.push(t.bold(t.fg(l,`${f}${d.replace(/\s+$/,"")}`)));y.push(""),y.push(t.bold(t.fg(R.banner_text,`${p}${De}`)));let x=l=>t.fg(R.banner_border,l),_=" ".repeat(i),v="\u2500".repeat(Math.max(0,o-2)),b=l=>ne(`${_}${l}`,r),m=[b(`${x("\u256D")}${x(v)}${x("\u256E")}`)],h=b(`${x("\u2502")}${" ".repeat(Math.max(0,o-2))}${x("\u2502")}`);m.push(h);for(let l of y)m.push(b(`${x("\u2502")} ${ne(l,s)} ${x("\u2502")}`));return m.push(h),m.push(b(`${x("\u2570")}${x(v)}${x("\u256F")}`)),m}function Yt({lines:e,width:t,palette:n,title:r=""}){let o=Math.max(2,Math.floor(Number(t)||0)),i=Math.max(0,o-2),s=He(String(r),Math.max(0,i-2)),a=s?` ${s} `:"",u=`${a}${"\u2500".repeat(Math.max(0,i-H(a)))}`,c=f=>n.fg(R.banner_border,f);return[`${c("\u256D")}${c(u)}${c("\u256E")}`,...e.map(f=>`${c("\u2502")}${ne(f,i)}${c("\u2502")}`),`${c("\u2570")}${c("\u2500".repeat(i))}${c("\u256F")}`]}function Ke(e){let t=Number(e);return Number.isFinite(t)?t>=1e6?`${(t/1e6).toFixed(1).replace(/\.0$/,"")}M`:t>=1e3?`${(t/1e3).toFixed(0)}K`:String(Math.round(t)):"0"}function qr(e,t){let n=Math.max(0,Math.floor(Number(t)||0)),r=Number(e),o=Number.isFinite(r)?Math.min(100,Math.max(0,r)):0,i=Math.round(n*o/100);return`${"\u2588".repeat(i)}${"\u2591".repeat(n-i)}`}function Se(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return"0s";let n=Math.floor(t/1e3);if(n<60)return`${n}s`;let r=Math.floor(n/60),o=n%60;return r<60?`${r}m${String(o).padStart(2,"0")}s`:`${Math.floor(r/60)}h${String(r%60).padStart(2,"0")}m`}function Wt({model:e,contextTokens:t,contextLength:n,percent:r,effort:o,thinking:i,chain:s,width:a,palette:u}){let c=Math.max(0,Math.floor(Number(a)||0)),f=u.fg(R.status_bar_dim," / "),p=c>=120?12:c>=60?8:4,y=Number(n)>0?`${Ke(t)}/${Ke(n)}`:Ke(t),x=Number.isFinite(Number(r))?`${Math.round(Number(r))}%`:"0%",_=[{text:String(e??""),strong:!0}];Number(n)>0&&_.push({text:`ctx ${qr(r,p)} ${y} ${x}`}),o&&_.push({text:String(o)}),i&&_.push({text:String(i)}),typeof s=="string"&&s.length>0&&_.push({text:s});let v=_,b=h=>h.reduce((l,d,w)=>l+H(d.text)+(w>0?3:0),0);for(;v.length>1&&b(v)>c;)v=v.slice(0,-1);let m=v.map(h=>h.strong?u.fg(R.status_bar_strong,h.text):u.fg(R.status_bar_text,h.text)).join(f);return u.bg(R.status_bar_bg,ne(m,c))}var Yr=6;function Wr(e=[]){let t={pass:[],query:null,model:null,provider:null,quiet:!1,cont:!1};for(let n=0;n<e.length;n+=1){let r=e[n];if((r==="-q"||r==="--query")&&e[n+1]){t.query=e[++n],t.pass.push("-q",t.query);continue}if((r==="--model"||r==="-m")&&e[n+1]){t.model=e[++n],t.pass.push("--model",t.model);continue}if(r==="--provider"&&e[n+1]){t.provider=e[++n],t.pass.push("--provider",t.provider);continue}if(r==="--quiet"||r==="-Q"){t.quiet=!0,t.pass.push(r);continue}if(r==="--continue"||r==="-c"){t.cont=!0,t.pass.push("--continue");continue}t.pass.push(r)}return t}function Ye(e,t){if(!t||typeof t!="object")return;let n=Number(t.context_used??t.context_tokens??t.input??t.prompt),r=Number(t.context_max??t.context_length);Number.isFinite(n)&&n>0&&(e.contextTokens=n),Number.isFinite(r)&&r>0&&(e.contextLength=r);let o=Number(t.context_percent);Number.isFinite(o)?e.contextPercent=o:e.contextLength>0&&(e.contextPercent=Math.round(e.contextTokens/e.contextLength*100))}function Gr(e){let t=e.width,n=`${e.promptLabel} `,r=Math.max(1,t-2-H(n)),o=e.buffer||"",i=Math.max(0,Math.min(e.cursor??o.length,o.length)),s=0;i>r&&(s=i-r);let a=o.slice(s,s+r),u=i-s,c=a.slice(0,u),f=a.slice(u,u+1)||" ",p=a.slice(u+1),y=e.palette;return[`${y.fg(R.accent,n)}${c}${y.bg(R.selection_bg,f)}${p}`]}function Jr(e){let t=e.width,n=[];if(e.liveLines.length>0){for(let r of e.liveLines.slice(-Yr))n.push(r);n.push("")}return n.push(...Yt({lines:Gr(e),width:t,palette:e.palette,title:"Ask Oracle \u203A"})),n.push(Wt({model:e.model,contextTokens:e.contextTokens,contextLength:e.contextLength,percent:e.contextPercent,effort:e.effort,thinking:e.thinking,chain:e.chain,width:t,palette:e.palette})),n}function Vr(e){let t=e?.params||e||{};return{type:t.type||e?.type||"",sessionId:t.session_id||e?.session_id||"",payload:t.payload||e?.payload||{}}}function ke(e={}){return typeof e.text=="string"?e.text:typeof e.rendered=="string"?e.rendered:typeof e.message=="string"?e.message:""}function Xr(e={}){let t=e.stdout||process.stdout,n=e.stdin||process.stdin,r=Math.max(20,Number(t.columns||e.columns||80)),o=e.palette||Ue({color:t.isTTY!==!1}),i=e.renderer||Dt({stdout:t,rows:t.rows,columns:r}),s=e.client||Ct({python:e.python,pythonArgs:e.pythonArgs||[],cwd:e.cwd||process.cwd(),env:e.env||process.env,spawnFn:e.spawnFn,startupTimeoutMs:e.startupTimeoutMs,requestTimeoutMs:e.requestTimeoutMs}),a=new zr,u=e.now||(()=>Date.now()),c={palette:o,width:r,promptLabel:"oracle \u203A",buffer:"",cursor:0,model:e.model||"model",contextTokens:0,contextLength:0,contextPercent:0,effort:e.effort||"",thinking:"0s",chain:(e.env||process.env).ORACLE_ACTIVE_CHAIN||"",busy:!1,cancelled:!1,sessionId:null,assistantBuffer:"",flushedLines:0,liveLines:[],startedAt:0},f=null,p=null,y={renderer:i,state:c};function x(){i.render(Jr(c))}function _(k){i.writeAbove(`${k}
|
|
12
|
+
`)}function v(){let k=c.assistantBuffer.split(`
|
|
13
|
+
`),g=k[k.length-1]||"";c.liveLines=g?qe(g,c.width):[]}function b({final:k=!1}={}){let g=c.assistantBuffer.split(`
|
|
14
|
+
`),L=k?g.length:g.length-1,Y=!1;for(;c.flushedLines<L;){let C=g[c.flushedLines];for(let F of qe(C,c.width))_(F);c.flushedLines+=1,Y=!0}return k?c.liveLines=[]:v(),Y}function m(){p||(p=setInterval(()=>{c.busy&&(c.thinking=Se(u()-c.startedAt),x())},250),typeof p.unref=="function"&&p.unref())}function h(){p&&(clearInterval(p),p=null)}async function l(k){let g=String(k||"").trim();if(g){if(g==="/exit"||g==="/quit"){await O();return}if(g==="/clear"){i.clear();for(let L of ze({width:c.width,palette:o}))_(L);x();return}c.busy=!0,c.assistantBuffer="",c.flushedLines=0,c.liveLines=[],c.startedAt=u(),c.thinking="0s",_(`${o.bold(o.fg(R.prompt,"you"))} ${g}`),_(""),m(),x(),await s.request("prompt.submit",{session_id:c.sessionId,text:g})}}function d(k){let g=Vr(k);if(g.type!=="gateway.ready"){if(g.type==="session.info"&&g.payload){g.payload.model&&(c.model=g.payload.model),g.payload.reasoning_effort&&(c.effort=g.payload.reasoning_effort),Ye(c,g.payload.usage),x();return}if(g.type==="message.start"){c.busy=!0,c.cancelled=!1,c.assistantBuffer="",c.flushedLines=0,c.liveLines=[],_(o.bold(o.fg(R.accent,"oracle"))),x();return}if(g.type==="thinking.delta"||g.type==="reasoning.delta"){if(c.cancelled)return;ke(g.payload).trim()&&(c.thinking=`${Se(u()-c.startedAt)}`),x();return}if(g.type==="message.delta"){if(c.cancelled)return;c.assistantBuffer+=ke(g.payload),b(),x();return}if(g.type==="message.complete"){if(c.cancelled){c.cancelled=!1;return}let L=ke(g.payload);L&&L.length>=c.assistantBuffer.length&&(c.assistantBuffer=L),b({final:!0}),_(""),c.busy=!1,h(),Ye(c,g.payload?.usage||g.payload?.context),c.thinking=Se(u()-c.startedAt),x();return}g.type==="error"&&(c.busy=!1,h(),_(o.fg(R.error,`error: ${ke(g.payload)||"unknown"}`)),x())}}async function w(){await s.start(),s.on("event",d),s.on("log",g=>a.emit("log",g)),s.on("error",g=>a.emit("error",g));let k=await s.request("session.create",{cols:c.width,cwd:e.cwd||process.cwd(),source:"cli",profile:e.profile||"oracle",close_on_disconnect:!0,...e.model?{model:e.model}:{},...e.provider?{provider:e.provider}:{}});c.sessionId=k.session_id,c.model=k.info?.model||c.model,k.info?.reasoning_effort&&(c.effort=k.info.reasoning_effort),Ye(c,k.info?.usage);for(let g of ze({width:c.width,palette:o}))_(g);_(""),x(),f=Pt({stdin:n,stdout:t,onSubmit:g=>{l(g).catch(L=>a.emit("error",L))},onCancel:()=>{c.busy&&(c.busy=!1,c.cancelled=!0,h(),b({final:!0}),_(o.fg(R.warn,"interrupted")),_(""),x(),s.request("session.interrupt",{session_id:c.sessionId}).catch(g=>a.emit("error",g)))},onEof:()=>{O().catch(g=>a.emit("error",g))},onClear:()=>{i.clear(),x()},onRender:g=>{c.buffer=g.buffer||"",c.cursor=g.cursor??c.buffer.length,x()}}),f.start()}async function O(){h(),f&&f.stop(),i.dispose(),await s.stop(),a.emit("stop")}return Object.freeze({start:w,stop:O,on:a.on.bind(a),off:a.off.bind(a),state:c,handleEvent:d,submit:l})}async function We({hermesPython:e,client:t,tuiFactory:n=Xr,args:r=[],env:o=process.env,cwd:i=process.cwd(),stdout:s=process.stdout,stdin:a=process.stdin}={}){let u=Wr(r);if(u.query)return{native:!1,pass:u.pass};if(!a.isTTY||!s.isTTY)return{native:!1,pass:u.pass};if(o.ORACLE_NATIVE_TUI==="0")return{native:!1,pass:u.pass};let c=e;if(!t&&!c)return{native:!1,pass:u.pass};let f=_e({...o,ORACLE_CHAT_SURFACE:"1",ORACLE_PROFILE:"oracle",ORACLE_NODE_BIN:process.execPath}),p=n({...t?{client:t}:{},...c?{python:c.command,pythonArgs:c.prefix||[]}:{},cwd:i,env:f,stdin:a,stdout:s,model:u.model,provider:u.provider,profile:"oracle"});return p.on("log",y=>{o.ORACLE_CLI_DEBUG&&process.stderr.write(`${y}
|
|
15
15
|
`)}),p.on("error",y=>{process.stderr.write(`oracle chat: ${y.message}
|
|
16
|
-
`)}),await p.start(),new Promise(y=>{let x=!1,_=async()=>{x||(x=!0,await p.stop(),y({native:!0,code:0}))};p.on("stop",()=>{x||(x=!0,y({native:!0,code:0}))}),process.once("SIGINT",_),process.once("SIGTERM",_)})}import
|
|
17
|
-
`)}function
|
|
18
|
-
`)}var
|
|
19
|
-
`)[0].replace(/^#+\s*/,"").trim()||o,e.push({name:o,description:i,path:n,size:r.length})}}catch{}return e}function
|
|
16
|
+
`)}),await p.start(),new Promise(y=>{let x=!1,_=async()=>{x||(x=!0,await p.stop(),y({native:!0,code:0}))};p.on("stop",()=>{x||(x=!0,y({native:!0,code:0}))}),process.once("SIGINT",_),process.once("SIGTERM",_)})}import Qr from"node:fs";import Gt from"node:path";var Jt=Object.freeze({openrouter:{key:"OPENROUTER_API_KEY",baseUrl:"https://openrouter.ai/api/v1",model:"openrouter/auto"},openai:{key:"OPENAI_API_KEY",baseUrl:"https://api.openai.com/v1",model:"gpt-4.1-mini"},xai:{key:"XAI_API_KEY",baseUrl:"https://api.x.ai/v1",model:"grok-4-latest"},deepseek:{key:"DEEPSEEK_API_KEY",baseUrl:"https://api.deepseek.com/v1",model:"deepseek-chat"},gemini:{key:"GEMINI_API_KEY",alternateKey:"GOOGLE_API_KEY",baseUrl:"https://generativelanguage.googleapis.com/v1beta/openai",model:"gemini-2.5-flash"}}),Zr=Object.freeze({"anthropic-oauth":{key:"ANTHROPIC_API_KEY",baseUrl:"https://api.anthropic.com/v1",model:"claude-sonnet-4-20250514",protocol:"anthropic-messages"},"openai-codex":{key:"OPENAI_API_KEY",baseUrl:"https://chatgpt.com/backend-api/codex",model:"gpt-5.4",protocol:"responses"},"xai-oauth":{key:"XAI_API_KEY",baseUrl:"https://api.x.ai/v1",model:"grok-4-latest",protocol:"responses"}});function eo(e,t){let n=Number(e);return Number.isSafeInteger(n)&&n>0?n:t}function to(e,t){let n=String(e.ORACLE_PROVIDER||t.provider||"").trim().toLowerCase();if(n)return n;if(e.ORACLE_BASE_URL||t.baseUrl)return"custom";for(let[r,o]of Object.entries(Jt))if(e[o.key]||o.alternateKey&&e[o.alternateKey])return r;return null}function no(e=process.env,t={},n=()=>!1,r=()=>""){let o=to(e,t);if(!o)return null;let i=Zr[o],s=Jt[o]||i,a=String(e.ORACLE_API_KEY_ENV||t.apiKeyEnv||""),u=String(e.ORACLE_API_KEY||a&&e[a]||s&&(e[s.key]||s.alternateKey&&e[s.alternateKey])||r(o)||""),c=String(i?i.baseUrl:o==="custom"?e.ORACLE_BASE_URL||t.baseUrl||"":s?.baseUrl||"").replace(/\/+$/,""),f=String(e.ORACLE_MODEL||t.model||s?.model||"");if(!c||!f)return null;let p=!!(i&&n(o));return i&&!p||!i&&o!=="custom"&&!u?null:{kind:"standalone",provider:o,model:f,baseUrl:c,...p?{authType:"oauth",protocol:i.protocol}:{apiKey:u},contextLength:eo(e.ORACLE_CONTEXT_LENGTH||t.contextLength,128e3),reasoningEffort:String(e.ORACLE_REASONING_EFFORT||t.reasoningEffort||"high")}}function re(e=""){return["Oracle runs its own native chat \u2014 no Hermes or external agent required.","Set OPENROUTER_API_KEY, run `oracle auth login claude|codex|grok`, or configure a custom OpenAI-compatible endpoint.","`oracle harness detect` finds any Agent Plugins-compatible clients installed on this machine.",e].filter(Boolean).join(`
|
|
17
|
+
`)}function ro(e=process.env,t={}){if(e.ORACLE_PUBLIC_DESKTOP==="1"||e.ORACLE_REMOTE_COMPUTE_DISABLE==="1")return null;let n=String(e.ORACLE_CHAT_BACKEND||t.backend||"auto").trim().toLowerCase(),r=String(e.ORACLE_COMPUTE_HOST||t.computeHost||"").trim();if(!["remote","arch"].includes(n)&&!e.ORACLE_COMPUTE_HOST||!r)return null;let o=String(e.ORACLE_COMPUTE_USER||t.computeUser||"").trim(),i=String(e.ORACLE_COMPUTE_PATH||t.computePath||"$HOME/.local/bin:/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin").trim();return{kind:"remote",host:r,user:o,path:i}}var oo=Object.freeze([{name:"oracle",bin:"oracle",label:"Oracle Native (default)",kind:"oracle"},{name:"hermes",bin:"hermes",label:"Hermes Agent",kind:"hermes"},{name:"opencode",bin:"opencode",label:"OpenCode",kind:"mcp"},{name:"claude",bin:"claude",label:"Claude Code",kind:"mcp"},{name:"codex",bin:"codex",label:"OpenAI Codex CLI",kind:"mcp"},{name:"cursor",bin:"cursor",label:"Cursor IDE",kind:"mcp"},{name:"windsurf",bin:"windsurf",label:"Windsurf",kind:"mcp"},{name:"aider",bin:"aider",label:"Aider",kind:"mcp"},{name:"continue",bin:"continue",label:"Continue",kind:"mcp"}]);function io(e){for(let t of(process.env.PATH||"").split(Gt.delimiter)){let n=Gt.join(t,e);try{if(Qr.existsSync(n))return n}catch{}}return null}function Vt({env:e=process.env,hermes:t={ok:!1},storedConfig:n=null,oauthAvailable:r=()=>!1,apiKeyResolver:o=()=>""}={}){let i=String(e.ORACLE_CHAT_BACKEND||n?.backend||"auto").trim().toLowerCase(),s=ro(e,n||{});if(i==="remote"||i==="arch")return s?{kind:"remote",config:s}:{kind:"unconfigured",reason:re(`${i} compute backend was requested, but no compute host is configured.`)};let a=no(e,n||{},r,o);if(i==="standalone")return a?{kind:"standalone",config:a}:{kind:"unconfigured",reason:re("ORACLE_CHAT_BACKEND=standalone was requested, but no standalone model is configured.")};if(i==="hermes")return t?.ok?{kind:"hermes",bin:t.bin}:{kind:"unconfigured",reason:re("ORACLE_CHAT_BACKEND=hermes was requested, but Hermes was not found.")};if(i!=="auto"){for(let u of oo)if(u.name===i){let c=io(u.bin);return c?{kind:"harness",harness:{...u,path:c}}:{kind:"unconfigured",reason:re(`ORACLE_CHAT_BACKEND=${i} was requested, but ${u.bin} was not found on PATH.`)}}return{kind:"unconfigured",reason:re(`Unknown ORACLE_CHAT_BACKEND value: ${i}`)}}return s?{kind:"remote",config:s}:a?{kind:"standalone",config:a}:t?.ok?{kind:"hermes",bin:t.bin}:{kind:"unconfigured",reason:re()}}J();import $o from"node:fs";import Pn from"node:path";import{randomUUID as Rn}from"node:crypto";import{EventEmitter as Po}from"node:events";import{spawnSync as No}from"node:child_process";import Ee from"node:fs";import Xt from"node:path";import{homedir as so}from"node:os";var Je=process.env.ORACLE_CONFIG_DIR||Xt.join(so(),".config","oracle"),Qt=Xt.join(Je,"memory.json"),Ge=2200;function Zt(e){Ee.existsSync(e)||Ee.mkdirSync(e,{recursive:!0})}function Ve(){Zt(Je);try{let e=Ee.readFileSync(Qt,"utf8");return JSON.parse(e)}catch{return{version:1,updatedAt:new Date().toISOString(),entries:[]}}}function en(e){Zt(Je),e.updatedAt=new Date().toISOString(),Ee.writeFileSync(Qt,JSON.stringify(e,null,2),{mode:384})}function tn(e,t){let n=Ve(),r=n.entries.findIndex(o=>o.key===e);for(r>=0?n.entries[r]={key:e,content:t,addedAt:new Date().toISOString()}:n.entries.push({key:e,content:t,addedAt:new Date().toISOString()});JSON.stringify(n.entries).length>Ge&&n.entries.length>1;)n.entries.shift();en(n)}function nn(e){let t=Ve(),n=t.entries.length;return t.entries=t.entries.filter(r=>r.key!==e),t.entries.length<n?(en(t),{ok:!0}):{ok:!1}}function rn(){let e=Ve();if(e.entries.length===0)return"";let t=JSON.stringify(e.entries).length,n=Math.round(t/Ge*100),r=e.entries.map(o=>`${o.key}: ${o.content}`);return["\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550",`MEMORY [${n}% \u2014 ${t}/${Ge} chars]`,"\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550",...r].join(`
|
|
18
|
+
`)}var on=[{type:"function",function:{name:"memory_add",description:"Save a durable fact to memory for future sessions.",parameters:{type:"object",properties:{key:{type:"string",description:"Short unique key"},content:{type:"string",description:"The fact to remember"}},required:["key","content"],additionalProperties:!1}}},{type:"function",function:{name:"memory_remove",description:"Remove a memory entry by key.",parameters:{type:"object",properties:{key:{type:"string",description:"The key to remove"}},required:["key"],additionalProperties:!1}}}];import I from"node:fs";import Ae from"node:path";import{homedir as co}from"node:os";var ao=process.env.ORACLE_CONFIG_DIR||Ae.join(co(),".config","oracle"),oe=Ae.join(ao,"skills"),uo=/^[a-z0-9][a-z0-9_-]{0,63}$/;function Xe(e){I.existsSync(e)||I.mkdirSync(e,{recursive:!0,mode:448});let t=I.lstatSync(e);if(t.isSymbolicLink()||!t.isDirectory())throw new Error("skills directory must be a real directory")}function sn(){return I.constants.O_NOFOLLOW||0}function cn(e){let t=I.lstatSync(e);if(t.isSymbolicLink()||!t.isFile())return null;let n=I.openSync(e,I.constants.O_RDONLY|sn());try{return I.readFileSync(n,"utf8")}finally{I.closeSync(n)}}function lo(e,t){if(I.existsSync(e)){let r=I.lstatSync(e);if(r.isSymbolicLink()||!r.isFile())throw new Error("skill path must be a regular file")}let n=I.openSync(e,I.constants.O_WRONLY|I.constants.O_CREAT|I.constants.O_TRUNC|sn(),384);try{I.writeFileSync(n,t)}finally{I.closeSync(n)}try{I.chmodSync(e,384)}catch{}}function an(e){let t=String(e??"").trim();if(!uo.test(t))throw new Error("invalid skill name");return Ae.join(oe,`${t}.md`)}function Qe(){let e=[];try{Xe(oe);for(let t of I.readdirSync(oe,{withFileTypes:!0})){if(!t.isFile()||!t.name.endsWith(".md"))continue;let n=Ae.join(oe,t.name),r=cn(n);if(r===null)continue;let o=t.name.replace(/\.md$/,""),i="",s=r.match(/^description:\s*(.+)$/m);s?i=s[1].trim():i=r.split(`
|
|
19
|
+
`)[0].replace(/^#+\s*/,"").trim()||o,e.push({name:o,description:i,path:n,size:r.length})}}catch{}return e}function Ze(e){try{Xe(oe);let t=an(e);return cn(t)}catch{return null}}function un(e){let t=Qe();if(t.length===0)return`## Skills
|
|
20
20
|
No skills installed. Use skill_create to save a successful workflow.
|
|
21
|
-
`;let n=t;if(e){let o=e.toLowerCase();n=[...t].sort((i,
|
|
22
|
-
`)}function
|
|
23
|
-
[truncated ${t.length-
|
|
21
|
+
`;let n=t;if(e){let o=e.toLowerCase();n=[...t].sort((i,s)=>{let a=(i.name.toLowerCase().includes(o)?2:0)+(i.description.toLowerCase().includes(o)?1:0);return(s.name.toLowerCase().includes(o)?2:0)+(s.description.toLowerCase().includes(o)?1:0)-a})}return["## Skills","Available (use skill_load <name>):",...n.map(o=>`- **${o.name}**: ${o.description}`)].join(`
|
|
22
|
+
`)}function ln(e,t){Xe(oe);let n=an(e);if(I.existsSync(n)&&!I.lstatSync(n).isFile())throw new Error("skill path must be a regular file");lo(n,t)}var fn=[{type:"function",function:{name:"skill_load",description:"Load full content of a skill by name.",parameters:{type:"object",properties:{name:{type:"string",pattern:"^[a-z0-9][a-z0-9_-]{0,63}$",description:"Skill name using lowercase letters, digits, hyphens, or underscores"}},required:["name"],additionalProperties:!1}}},{type:"function",function:{name:"skill_create",description:"Save a new skill from a workflow or pattern.",parameters:{type:"object",properties:{name:{type:"string",pattern:"^[a-z0-9][a-z0-9_-]{0,63}$",description:"Lowercase letters, digits, hyphens, or underscores"},content:{type:"string",description:"Full SKILL.md content"}},required:["name","content"],additionalProperties:!1}}},{type:"function",function:{name:"skill_list",description:"List all installed skills.",parameters:{type:"object",properties:{},additionalProperties:!1}}}];import Oe from"node:fs";import pn from"node:path";import{homedir as fo}from"node:os";import{EventEmitter as po}from"node:events";var et=process.env.ORACLE_CONFIG_DIR||pn.join(fo(),".config","oracle"),mn=pn.join(et,"cron.json");function hn(e){Oe.existsSync(e)||Oe.mkdirSync(e,{recursive:!0})}function he(){hn(et);try{return JSON.parse(Oe.readFileSync(mn,"utf8"))}catch{return{version:1,jobs:[]}}}function tt(e){hn(et),Oe.writeFileSync(mn,JSON.stringify(e,null,2),{mode:384})}function Ce(e){let t=String(e||"").toLowerCase().trim(),n=t.match(/^every\s+(\d+)\s*m/i);if(n)return parseInt(n[1])*6e4;let r=t.match(/^every\s+(\d+)\s*h/i);return r?parseInt(r[1])*36e5:t.includes("daily")?864e5:t.includes("hourly")?36e5:t.split(/\s+/).length===5?6e4:null}function nt(){return he().jobs}function rt(e){let t=he(),n=`cron_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`,r=Ce(e.schedule)||36e5,o={...e,id:n,createdAt:new Date().toISOString(),nextRunAt:new Date(Date.now()+r).toISOString()};return t.jobs.push(o),tt(t),o}function ot(e){let t=he(),n=t.jobs.length;return t.jobs=t.jobs.filter(r=>r.id!==e),t.jobs.length<n?(tt(t),!0):!1}function dn(e){let t=he(),n=t.jobs.find(i=>i.id===e);if(!n)return;n.lastRunAt=new Date().toISOString();let r=Ce(n.schedule)||36e5,o=n.lastRunAt?new Date(n.lastRunAt).getTime():Date.now();n.nextRunAt=new Date(o+r).toISOString(),tt(t)}function xn(e){let t=new po,n=new Map;function r(){let i=he();for(let s of i.jobs){if(!s.enabled)continue;let a=Ce(s.schedule);if(!a)continue;let u=setInterval(async()=>{try{t.emit("run",{id:s.id,name:s.name}),await e(s.prompt,s.skills),dn(s.id),t.emit("complete",{id:s.id,name:s.name})}catch(c){t.emit("error",{id:s.id,name:s.name,error:c})}},a);n.set(s.id,u)}t.emit("started",{count:n.size})}function o(){for(let[i,s]of n)clearInterval(s),n.delete(i);t.emit("stopped")}return{on:t.on.bind(t),off:t.off.bind(t),once:t.once.bind(t),emit:t.emit.bind(t),start:r,stop:o,add:i=>{let s=rt(i);if(s.enabled){let a=Ce(s.schedule);if(a){let u=setInterval(async()=>{try{t.emit("run",{id:s.id,name:s.name}),await e(s.prompt,s.skills),dn(s.id),t.emit("complete",{id:s.id,name:s.name})}catch(c){t.emit("error",{id:s.id,name:s.name,error:c})}},a);n.set(s.id,u)}}return s},remove:i=>{let s=n.get(i);return s&&(clearInterval(s),n.delete(i)),ot(i)},list:nt}}var yn=[{type:"function",function:{name:"cron_add",description:"Schedule a recurring agent job.",parameters:{type:"object",properties:{name:{type:"string",description:"Human-readable name"},schedule:{type:"string",description:"'every 30m', 'daily', 'every 6h'"},prompt:{type:"string",description:"Agent prompt to run on schedule"},skills:{type:"array",items:{type:"string"},description:"Optional skill names"}},required:["name","schedule","prompt"],additionalProperties:!1}}},{type:"function",function:{name:"cron_list",description:"List all scheduled cron jobs.",parameters:{type:"object",properties:{},additionalProperties:!1}}},{type:"function",function:{name:"cron_remove",description:"Remove a cron job by id.",parameters:{type:"object",properties:{id:{type:"string",description:"Job id from cron_list"}},required:["id"],additionalProperties:!1}}}];var Ie=[],mo=5,ho=1;function gn(e){Ie.push(e),Ie.length>20&&Ie.shift()}function bn(){let e=Ie.slice(-3);if(e.length<1)return null;let t=e[e.length-1];return t.toolCalls>=mo&&t.errors===0?{shouldCreate:!0,suggestion:`You completed a ${t.toolCalls}-step workflow. Save it as a skill with skill_create.`}:e.filter(r=>r.errors>0&&r.recovered).length>=ho&&t.toolCalls>=3?{shouldCreate:!0,suggestion:"You recovered from errors. Save the corrected approach as a skill."}:{shouldCreate:!1,suggestion:"No skill suggestions yet."}}var _n=[{type:"function",function:{name:"meta_analyze",description:"Analyze recent interactions and suggest skills to create.",parameters:{type:"object",properties:{},additionalProperties:!1}}}];import{homedir as it}from"node:os";import{join as st}from"node:path";var wn=process.env.ORACLE_PUBLIC_DESKTOP==="1",xo=wn?process.env.ORACLE_CONFIG_DIR||st(it(),".config","oracle"):st(it(),".config","oracle"),Ts=wn?xo:st(it(),".config","mad-desk");function yo(e,t,n=""){let r=process.env[e];if(r!=null&&String(r).trim()!=="")return r;let o=t?process.env[t]:void 0;return o!=null&&String(o).trim()!==""?o:n}var go=["0","false","off","no"];function vn(e,t,n=!0){let r=String(yo(e,t,"")).trim().toLowerCase();return r===""?n:!go.includes(r)}var jo=new Set(["chain","data","scan","route","prepare"]),Fo=new Set(["list","show"]),Mo=new Set(["call","catalog","health"]),Uo=new Set(["swap","bridge","prepare","prepare-bridge"]),Do=Object.freeze({"anthropic-oauth":"https://api.anthropic.com/v1","openai-codex":"https://chatgpt.com/backend-api/codex","xai-oauth":"https://api.x.ai/v1"}),ht=2e4,Tn=6,Bo=Object.freeze({type:"function",function:{name:"oracle_cli",description:"Run a bounded read or prepare-only Oracle CLI command. It cannot sign or broadcast transactions.",parameters:{type:"object",properties:{argv:{type:"array",items:{type:"string"},minItems:1,maxItems:24,description:'Arguments after the oracle executable, for example ["scan","chains"] or ["data","health"].'}},required:["argv"],additionalProperties:!1}}}),yt=Object.freeze([Bo,...on,...fn,...yn,..._n]);function $n(e){let t=String(e||"");return t.length<=ht?t:`${t.slice(0,ht)}
|
|
23
|
+
[truncated ${t.length-ht} chars]`}async function Ko(e,t,n){switch(e){case"oracle_cli":return n(t.argv);case"memory_add":return tn(t.key,t.content),{ok:!0,stored:t.key};case"memory_remove":return nn(t.key);case"skill_load":{let r=Ze(t.name);return r?{ok:!0,name:t.name,content:r}:{ok:!1,error:`skill not found: ${t.name}`}}case"skill_create":return ln(t.name,t.content),{ok:!0,created:t.name};case"skill_list":return{ok:!0,skills:Qe().map(o=>({name:o.name,description:o.description}))};case"cron_add":return{ok:!0,job:rt({name:t.name,schedule:t.schedule,prompt:t.prompt,skills:t.skills||[],enabled:!0})};case"cron_list":return{ok:!0,jobs:nt()};case"cron_remove":return{ok:ot(t.id),removed:t.id};case"meta_analyze":return{ok:!0,...bn()||{shouldCreate:!1,suggestion:"No skill suggestions yet."}};default:return{ok:!1,error:`unknown tool: ${e}`}}}function Ho(e){if(!Array.isArray(e)||e.length===0||e.length>24)return"argv must contain 1 to 24 arguments";if(e.some(n=>typeof n!="string"||n.length>1e3))return"every argument must be a string no longer than 1000 characters";let t=e[0];return jo.has(t)?t==="chain"&&!Fo.has(e[1]||"list")?`command not allowed: chain${e[1]?` ${e[1]}`:""}`:t==="data"&&!Mo.has(e[1]||"")?`command not allowed: data${e[1]?` ${e[1]}`:""}`:t==="route"&&!Uo.has(e[1]||"")?`command not allowed: route${e[1]?` ${e[1]}`:""}`:null:`command not allowed: ${t}`}async function qo(e,t={}){let n=Ho(e);if(n)return{ok:!1,error:n};let r=t.spawnFn||No,o=t.packageRoot||U,i=r(process.execPath,[Pn.join(o,"bin","oracle.mjs"),...e],{encoding:"utf8",timeout:t.timeoutMs||45e3,maxBuffer:1024*1024,env:{...process.env,ORACLE_CHAT_TOOL:"1"}});return i.error?{ok:!1,error:i.error.message}:{ok:i.status===0,status:typeof i.status=="number"?i.status:1,stdout:$n(i.stdout),stderr:$n(i.stderr)}}function zo(){let e=Pn.join(U,"profiles","oracle","SOUL.md"),t=$o.readFileSync(e,"utf8"),n=rn(),r=un(),o=[t.trim()];return n&&o.push(n),o.push(r),o.push("You have tools for Oracle CLI commands, durable memory, skills, cron scheduling, and meta-learning.","Use memory_add to persist facts. Use skill_create to save successful workflows. Use cron_add to schedule recurring tasks."),o.join(`
|
|
24
24
|
|
|
25
|
-
`)}function
|
|
26
|
-
`);!
|
|
25
|
+
`)}function Yo(e,t,n={}){return{method:"event",params:{type:e,session_id:t,payload:n}}}async function Wo(e){return new Error(`model request failed (HTTP ${e?.status||"unknown"})`)}async function*gt(e){if(!e?.ok)throw await Wo(e);if(!e.body)throw new Error("model response had no body");let t=e.body.getReader(),n=new TextDecoder,r="";for(;;){let{value:i,done:s}=await t.read();r+=n.decode(i||new Uint8Array,{stream:!s});let a=r.split(/\r?\n\r?\n/);r=a.pop()||"";for(let u of a){let c=u.split(/\r?\n/).filter(f=>f.startsWith("data:")).map(f=>f.slice(5).trimStart()).join(`
|
|
26
|
+
`);!c||c==="[DONE]"||(yield JSON.parse(c))}if(s)break}let o=r.trim();if(o.startsWith("data:")){let i=o.slice(5).trim();i&&i!=="[DONE]"&&(yield JSON.parse(i))}}function Go(e,t){let n=Number(t.index||0),r=e.get(n)||{id:"",type:"function",function:{name:"",arguments:""}};t.id&&(r.id+=t.id),t.type&&(r.type=t.type),t.function?.name&&(r.function.name+=t.function.name),t.function?.arguments&&(r.function.arguments+=t.function.arguments),e.set(n,r)}function Jo(e,t){let n=Number(e?.prompt_tokens||e?.input_tokens||0),r=Number(e?.completion_tokens||e?.output_tokens||0);return{context_used:n,context_max:t,context_percent:t>0?Math.round(n/t*100):0,input:n,output:r}}function Vo(){return yt.map(e=>({type:"function",name:e.function.name,description:e.function.description,parameters:e.function.parameters,strict:!1}))}function Xo(){return yt.map(e=>({name:e.function.name,description:e.function.description,input_schema:e.function.parameters}))}function xt(e,t,n){let r=Array.isArray(n)?n:[{type:"text",text:String(n||"")}],o=e.at(-1);o?.role===t?o.content.push(...r):e.push({role:t,content:r})}function Qo(e){let t=[];for(let n of e)if(n.role!=="system"){if(n.role==="user"){xt(t,"user",[{type:"text",text:String(n.content||"")}]);continue}if(n.role==="assistant"){let r=[];n.content&&r.push({type:"text",text:String(n.content)});for(let o of n.tool_calls||[]){let i={};try{i=JSON.parse(o.function?.arguments||"{}")}catch{}r.push({type:"tool_use",id:o.id,name:o.function?.name,input:i})}r.length&&xt(t,"assistant",r);continue}n.role==="tool"&&xt(t,"user",[{type:"tool_result",tool_use_id:n.tool_call_id,content:String(n.content||"")}])}return t}function Zo(e){let t=[];for(let n of e)if(n.role!=="system"){if(n.role==="user"){t.push({role:"user",content:[{type:"input_text",text:String(n.content||"")}]});continue}if(n.role==="assistant"){n.content&&t.push({role:"assistant",status:"completed",content:[{type:"output_text",text:String(n.content)}]});for(let r of n.tool_calls||[])t.push({type:"function_call",id:r.response_item_id||void 0,call_id:r.id,name:r.function?.name,arguments:r.function?.arguments||"{}"});continue}n.role==="tool"&&t.push({type:"function_call_output",call_id:n.tool_call_id,output:String(n.content||"")})}return t.map(n=>Object.fromEntries(Object.entries(n).filter(([,r])=>r!==void 0)))}function ei(e){try{let t=JSON.parse(Buffer.from(String(e).split(".")[1],"base64url").toString("utf8"));return String(t?.["https://api.openai.com/auth"]?.chatgpt_account_id||"")}catch{return""}}async function ti({config:e,messages:t,fetchFn:n,signal:r,onText:o}){let i=await n(`${e.baseUrl}/chat/completions`,{method:"POST",headers:{"content-type":"application/json",...e.apiKey?{Authorization:`Bearer ${e.apiKey}`}:{},...e.provider==="openrouter"?{"HTTP-Referer":"https://oracle-agent.dev","X-Title":"Oracle CLI"}:{}},body:JSON.stringify({model:e.model,messages:t,tools:yt,tool_choice:"auto",stream:!0,stream_options:{include_usage:!0}}),signal:r}),s=new Map,a="",u=null;for await(let c of gt(i)){c.usage&&(u=c.usage);let f=c.choices?.[0]?.delta||{};typeof f.content=="string"&&f.content&&(a+=f.content,o(f.content));for(let p of f.tool_calls||[])Go(s,p)}return{text:a,usage:u,toolCalls:[...s.entries()].sort(([c],[f])=>c-f).map(([,c])=>c)}}async function ni({config:e,messages:t,persona:n,credential:r,fetchFn:o,signal:i,onText:s}){let a=await o(`${e.baseUrl}/messages`,{method:"POST",headers:{"content-type":"application/json",accept:"text/event-stream",Authorization:`Bearer ${r.accessToken}`,"anthropic-version":"2023-06-01","anthropic-beta":"interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14,claude-code-20250219,oauth-2025-04-20","user-agent":`claude-code/${process.env.ORACLE_CLAUDE_CODE_VERSION||"2.1.220"} (external, cli)`,"x-app":"cli"},body:JSON.stringify({model:e.model,max_tokens:Number(e.maxOutputTokens||8192),system:[{type:"text",text:"You are Claude Code, Anthropic's official CLI for Claude."},{type:"text",text:n}],messages:Qo(t),tools:Xo(),tool_choice:{type:"auto"},stream:!0}),signal:i}),u=new Map,c="",f=null;for await(let p of gt(a)){if(p.type==="message_start"&&(f={...f||{},...p.message?.usage||{}}),p.type==="message_delta"&&(f={...f||{},...p.usage||{}}),p.type==="content_block_start"&&p.content_block?.type==="tool_use"){let y=p.content_block;u.set(Number(p.index||0),{id:y.id,type:"function",function:{name:y.name,arguments:y.input&&Object.keys(y.input).length?JSON.stringify(y.input):""}})}if(p.type==="content_block_delta"&&p.delta?.type==="text_delta"&&(c+=p.delta.text||"",p.delta.text&&s(p.delta.text)),p.type==="content_block_delta"&&p.delta?.type==="input_json_delta"){let y=Number(p.index||0),x=u.get(y);x&&(x.function.arguments+=p.delta.partial_json||"")}if(p.type==="error")throw new Error(p.error?.message||"Claude stream failed")}return{text:c,usage:f,toolCalls:[...u.entries()].sort(([p],[y])=>p-y).map(([,p])=>(p.function.arguments||(p.function.arguments="{}"),p))}}async function ri({config:e,messages:t,persona:n,sessionId:r,credential:o,fetchFn:i,signal:s,onText:a}){let u=e.provider==="openai-codex",c=u?ei(o.accessToken):"",f={"content-type":"application/json",accept:"text/event-stream",Authorization:`Bearer ${o.accessToken}`,...u?{"user-agent":"codex_cli_rs/0.0.0 (Oracle CLI)",originator:"codex_cli_rs",...c?{"ChatGPT-Account-ID":c}:{},session_id:r,"x-client-request-id":r}:{"x-grok-conv-id":r}},p={model:e.model,instructions:n,input:Zo(t),tools:Vo(),tool_choice:"auto",parallel_tool_calls:!0,store:!1,stream:!0,...u?{reasoning:{effort:e.reasoningEffort||"high",summary:"auto"}}:{}},y=await i(`${e.baseUrl}/responses`,{method:"POST",headers:f,body:JSON.stringify(p),signal:s}),x=new Map,_="",v=null;for await(let b of gt(y)){b.type==="response.output_text.delta"&&typeof b.delta=="string"&&(_+=b.delta,a(b.delta));let m=b.item;if((b.type==="response.output_item.added"||b.type==="response.output_item.done")&&m?.type==="function_call"){let h=String(m.call_id||m.id||b.output_index||x.size);x.set(h,{id:m.call_id||m.id,response_item_id:m.id,type:"function",function:{name:m.name,arguments:m.arguments||"{}"}})}if(b.type==="response.function_call_arguments.delta"){let h=String(b.call_id||b.item_id||b.output_index||""),l=x.get(h);l&&(l.function.arguments+=b.delta||"")}if(b.type==="response.completed"&&(v=b.response?.usage||v),b.type==="response.failed"||b.type==="error")throw new Error(b.response?.error?.message||b.error?.message||"Responses stream failed")}return{text:_,usage:v,toolCalls:[...x.values()]}}function Nn(e={}){let t=e.config;if(!t?.baseUrl||!t?.model)throw new Error("standalone model configuration is incomplete");if(t.authType==="oauth"){let l=Do[t.provider],d=String(t.baseUrl).replace(/\/+$/,"");if(!l||d!==l)throw new Error(`${t.provider||"unknown"} OAuth endpoint is not trusted`)}let n=new Po,r=e.fetchFn||globalThis.fetch,o=e.toolRunner||(l=>qo(l,e)),i=e.credentialProvider||(async l=>{let{resolveOAuthCredentials:d}=await Promise.resolve().then(()=>(mt(),Ln));return d(l)}),s=e.persona||zo(),a=e.sessionId||`oracle-${Rn()}`,u=[],c=null,f=!1,p=!1,y=xn(async(l,d)=>{if(f)return;let w=(d||[]).map(k=>{let g=Ze(k);return g?`## Skill: ${k}
|
|
27
27
|
${g}`:null}).filter(Boolean),O=w.length>0?`
|
|
28
28
|
|
|
29
29
|
${w.join(`
|
|
30
30
|
|
|
31
|
-
`)}`:"";await v(`${l}${O}`)});
|
|
32
|
-
`),
|
|
33
|
-
`),
|
|
34
|
-
`,{mode:384}),{ok:!0,marker:o}}function
|
|
35
|
-
`)}function
|
|
31
|
+
`)}`:"";await v(`${l}${O}`)});vn("ORACLE_CRON_ENABLED","MAD_CRON_ENABLED",!0)&&(y.on("run",l=>x("cron.run",l)),y.on("complete",l=>x("cron.complete",l)),y.on("error",l=>x("cron.error",l)),y.start());function x(l,d={}){n.emit("event",Yo(l,a,d))}function _(l){x("error",{message:l?.message||String(l)}),n.listenerCount("error")>0&&n.emit("error",l)}async function v(l){p=!0,c=new AbortController;let d=[{role:"system",content:s},...u,{role:"user",content:l}],w="",O=null,k=!1;try{for(let g=0;g<Tn;g+=1){let L=t.authType==="oauth"?await i(t.provider):null,Y=X=>{k||(x("message.start",{}),k=!0),w+=X,x("message.delta",{text:X})},C={config:t,messages:d,persona:s,sessionId:a,credential:L,fetchFn:r,signal:c.signal,onText:Y},F=t.protocol==="anthropic-messages"?await ni(C):t.protocol==="responses"?await ri(C):await ti(C),ae=F.text,ue=F.toolCalls;if(O=F.usage||O,ue.length===0){d.push({role:"assistant",content:ae}),u=d.slice(1),k||x("message.start",{}),x("message.complete",{text:w,usage:Jo(O,t.contextLength)});return}d.push({role:"assistant",content:ae||null,tool_calls:ue});let qn=ue.length,ge=0;for(let X of ue){let be;try{let $e=JSON.parse(X.function.arguments||"{}");be=await Ko(X.function.name,$e,o)}catch($e){be={ok:!1,error:`invalid tool arguments: ${$e.message}`},ge++}be.ok||ge++,d.push({role:"tool",tool_call_id:X.id||`call_${Rn()}`,content:JSON.stringify(be)})}gn({userMessage:l,toolCalls:qn,errors:ge,recovered:ge>0?!!ue.length:!1,durationMs:0})}throw new Error(`agent exceeded ${Tn} tool steps`)}catch(g){g?.name!=="AbortError"&&_(g)}finally{p=!1,c=null}}async function b(){if(f)throw new Error("standalone client is stopped")}async function m(l,d={}){if(f)throw new Error("standalone client is stopped");if(l==="session.create")return x("session.info",{model:d.model||t.model,reasoning_effort:t.reasoningEffort,usage:{context_max:t.contextLength},backend:"standalone"}),{session_id:a,info:{model:d.model||t.model,reasoning_effort:t.reasoningEffort,usage:{context_max:t.contextLength},backend:"standalone"}};if(l==="prompt.submit"){if(p)throw new Error("a turn is already active");let w=String(d.text||"").trim();if(!w)throw new Error("prompt text is required");return queueMicrotask(()=>{v(w).catch(_)}),{accepted:!0}}if(l==="session.interrupt"){let w=!!(c&&p);return c?.abort(),{interrupted:w}}if(l==="session.usage")return{calls:0,input:0,output:0,total:0};throw new Error(`unsupported standalone method: ${l}`)}async function h(){f||(f=!0,c?.abort(),y.stop())}return Object.freeze({start:b,request:m,stop:h,on:n.on.bind(n),off:n.off.bind(n)})}async function jn({client:e,text:t,stdout:n=process.stdout,stderr:r=process.stderr}={}){if(!e)throw new Error("standalone client is required");await e.start();let o=await e.request("session.create",{source:"cli"}),i="",s=!1;try{return await new Promise((a,u)=>{let c=f=>{let p=f?.params?.type,y=f?.params?.payload||{};if(p==="message.delta"&&typeof y.text=="string"){i+=y.text,n.write(y.text);return}if(p==="message.complete"){!i&&y.text&&n.write(String(y.text)),n.write(`
|
|
32
|
+
`),s=!0,a(0);return}if(p==="error"){let x=y.message||y.text||"standalone chat failed";r.write(`oracle chat: ${x}
|
|
33
|
+
`),s=!0,u(new Error(x))}};e.on("event",c),e.request("prompt.submit",{session_id:o.session_id,text:t}).catch(f=>{s||(s=!0,u(f))})})}finally{await e.stop()}}mt();var T="oracle",ye="oracle";function Kn(e){if(e==="hermes"){let t=de();return t.ok?t.bin:null}for(let t of(process.env.PATH||"").split(S.delimiter)){let n=S.join(t,e);try{if(A.existsSync(n))return n}catch{}}return null}function Fn(e){try{let t=A.readFileSync(e,"utf8").split(/\r?\n/,1)[0];if(!t.startsWith("#!"))return null;let n=t.slice(2).trim().split(/\s+/);if(n[0]?.endsWith("/env")&&n[1]?.startsWith("python"))return{command:n[0],prefix:[n[1]]};if(S.basename(n[0]||"").startsWith("python"))return{command:n[0],prefix:n.slice(1)}}catch{}return null}function Hn(e){let t=Fn(e);if(t)return t;try{let r=A.readFileSync(e,"utf8").match(/["']([^"'\r\n]+\/bin\/hermes)["']/);if(r)return Fn(r[1])}catch{}return null}function ii(){return S.join(U,"src","cli","oracle-harness.py")}function Te(e,t){let n=ii(),r=process.env.ORACLE_PLAIN_HARNESS==="0"?null:Hn(e);return r&&A.existsSync(n)?{command:r.command,args:[...r.prefix,n,...t]}:{command:e,args:t}}function si(){return S.join(U,"skins","oracle.yaml")}function ci(e=T){let t=S.join(U,"profiles","oracle","SOUL.md");if(!A.existsSync(t))return{ok:!1,reason:"oracle persona missing from package"};let n=S.join(B(),"profiles",e,"SOUL.md");return A.existsSync(n)&&!A.readFileSync(n,"utf8").startsWith("You are Hermes Agent, an intelligent AI assistant created by Nous Research.")?{ok:!0,reused:!0}:(P(S.dirname(n)),A.copyFileSync(t,n),{ok:!0,reused:!1})}function ai(e=T){let t=si();if(!A.existsSync(t))return{ok:!1,reason:"skin missing from package"};let n=S.join(B(),"skins"),r=S.join(B(),"profiles",e,"skins");P(n),P(r);let o=A.readFileSync(t,"utf8");return A.writeFileSync(S.join(n,`${ye}.yaml`),o),A.writeFileSync(S.join(r,`${ye}.yaml`),o),{ok:!0,skin:ye}}function ui(e=T){let t=S.join(B(),"profiles",e,"config.yaml");if(!A.existsSync(t))return{ok:!1,reason:"profile config missing"};let n=Kn("oracle")||S.join(U,"bin","oracle.mjs"),r=S.join(B(),"profiles",e,"oracle");P(r);let o={profile:e,skin:ye,oracleBin:n,commands:{chain:[n,"chain"],setup:[n,"setup"]},updatedAt:new Date().toISOString()};return A.writeFileSync(S.join(r,"chat-surface.json"),JSON.stringify(o,null,2)+`
|
|
34
|
+
`,{mode:384}),{ok:!0,marker:o}}function li(e=T){let t=S.join(U,"skills","oracle-chat");if(!A.existsSync(t))return{ok:!1,reason:"oracle-chat skill missing"};let n=S.join(B(),"profiles",e,"skills","oracle-chat");P(n);for(let r of A.readdirSync(t)){let o=S.join(t,r),i=S.join(n,r);A.statSync(o).isFile()&&A.copyFileSync(o,i)}for(let r of["chain","setup"]){let o=S.join(B(),"profiles",e,"skills",r);P(o);let i=S.join(t,`${r}.SKILL.md`),s=S.join(t,"SKILL.md"),a=A.existsSync(i)?A.readFileSync(i,"utf8"):A.readFileSync(s,"utf8");A.writeFileSync(S.join(o,"SKILL.md"),a)}return{ok:!0}}function fi(e=T){let t=Kn("hermes");if(!t)return{ok:!1,reason:"hermes missing"};let n=oi(t,["-p",e,"config","set","display.skin",ye],{encoding:"utf8",timeout:3e4});return n.status!==0?{ok:!1,reason:(n.stderr||n.stdout||"config set failed").trim()}:{ok:!0}}function Mn(e){if(!A.existsSync(e))return!1;let t=A.readFileSync(e,"utf8");if(/^model:\s*\S+/m.test(t))return!0;let n=t.match(/^model:\s*\n((?:[ \t]+.*(?:\n|$))*)/m)?.[1]||"";return/^\s+(?:default|provider):\s*\S+/m.test(n)}function di(e=T){let t=B();if(A.existsSync(S.join(t,"auth.json"))||A.existsSync(S.join(t,"profiles",e,"auth.json")))return!0;let n=["OPENROUTER_API_KEY","ANTHROPIC_API_KEY","OPENAI_API_KEY","XAI_API_KEY","GOOGLE_API_KEY","GEMINI_API_KEY","DEEPSEEK_API_KEY","HF_TOKEN","GLM_API_KEY","KIMI_API_KEY","MINIMAX_API_KEY"];if(n.some(r=>process.env[r]))return!0;for(let r of[S.join(t,".env"),S.join(t,"profiles",e,".env")]){if(!A.existsSync(r))continue;let o=A.readFileSync(r,"utf8");if(n.some(i=>new RegExp(`^${i}=.+`,"m").test(o)))return!0}return!1}function Un(e=T){let t=B();return Mn(S.join(t,"config.yaml"))||Mn(S.join(t,"profiles",e,"config.yaml"))||di(e)}function Dn(){return["oracle chat, filled lowercase oracle chat",""," oracle chat open interactive oracle chat",' oracle chat -q "..." one-shot query'," oracle chat --model <m> use a model for this session"," oracle chat --print-banner show filled oracle banner only","","inside chat:"," /chain list/select chains"," /setup messaging setup menu"," /model switch models (still one oracle persona)","","brand: filled lowercase oracle / classic boxed layout"].join(`
|
|
35
|
+
`)}function pi(){let e=Number(process.stdout?.columns||process.env.COLUMNS||80);return Number.isFinite(e)&&e>0?Math.floor(e):80}function mi(e){return Array.from(String(e)).length}function hi(e,t){let n=e.map(s=>s.trimEnd()),r=Math.max(0,...n.map(s=>mi(s))),o=Math.max(0,Math.floor((t-r)/2)),i=" ".repeat(o);return n.map(s=>s?`${i}${s}`:"")}function Bn(e){return`'${String(e).replace(/'/g,"'\\''")}'`}function xi(e){return e.user?`${e.user}@${e.host}`:e.host}function yi(e,t){let n=e.path||"$HOME/.local/bin:/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin",r=["oracle","chat",...t].map(Bn).join(" ");return[/^[A-Za-z0-9_:$/.~+-]+$/.test(n)?`export PATH=${n}`:`export PATH=${Bn(n)}`,"export ORACLE_REMOTE_COMPUTE_DISABLE=1","export ORACLE_CHAT_BACKEND=auto",r].join("; ")}function gi(){let e=[""," \u2588\u2588\u2588\u2588"," \u2591\u2591\u2588\u2588\u2588"," \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588"," \u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588 \u2591\u2591\u2591\u2591\u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588","\u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2591\u2591 \u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2591\u2591 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2588\u2588\u2588 \u2591\u2588\u2588\u2588 \u2591\u2588\u2588\u2588\u2591\u2591\u2591","\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2591\u2591\u2588\u2588\u2588\u2588\u2588\u2588"," \u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591 \u2591\u2591\u2591\u2591\u2591\u2591",""];process.stdout.write(hi(e,pi()).join(`
|
|
36
36
|
`)+`
|
|
37
|
-
`)}function
|
|
38
|
-
`),0;if(t.includes("--print-banner"))return
|
|
39
|
-
`),1;if(i.kind==="remote")return
|
|
37
|
+
`)}function bi(e){let t={pass:[],query:null,model:null,provider:null};for(let n=0;n<e.length;n+=1){let r=e[n];if((r==="--model"||r==="-m")&&e[n+1]){t.model=e[++n],t.pass.push("--model",t.model);continue}if(r==="--provider"&&e[n+1]){t.provider=e[++n],t.pass.push("--provider",t.provider);continue}if((r==="-q"||r==="--query")&&e[n+1]){t.query=e[++n],t.pass.push("-q",t.query);continue}if(r==="--quiet"||r==="-Q"){t.pass.push("--quiet");continue}if(r==="--continue"||r==="-c"){t.pass.push("--continue");continue}t.pass.push(r)}return t}var lc={name:"chat",summary:"open the one oracle chat surface (telegram-like, multi-model)",group:"read",usage:Dn(),async run(e){let t=[...e.argv];if(t.includes("-h")||t.includes("--help"))return process.stdout.write(Dn()+`
|
|
38
|
+
`),0;if(t.includes("--print-banner"))return gi(),0;let n=bi(t),r={...process.env,...n.model?{ORACLE_MODEL:n.model}:{},...n.provider?{ORACLE_PROVIDER:n.provider}:{}},o=ce(),i=Vt({env:r,hermes:de(),storedConfig:pe(),oauthAvailable:_=>!!o.get(_),apiKeyResolver:_=>o.getApiKey(_)});if(i.kind==="unconfigured")return process.stderr.write(`${i.reason}
|
|
39
|
+
`),1;if(i.kind==="remote")return Q("ssh",["-o","BatchMode=yes","-o","ConnectTimeout=12",xi(i.config),yi(i.config,n.pass)],{stdio:"inherit",env:process.env},"oracle-remote-compute");let s=_e({ORACLE_CHAT_SURFACE:"1",ORACLE_PROFILE:T,ORACLE_NODE_BIN:process.execPath,ORACLE_CLI_ENTRY:S.join(U,"bin","oracle.mjs")});if(i.kind==="standalone"){let _=Nn({config:{...i.config,...n.model?{model:n.model}:{}}});if(n.query)try{return await jn({client:_,text:n.query,stdout:process.stdout,stderr:process.stderr})}catch{return 1}let v=await We({client:_,args:t,env:s,cwd:process.cwd(),stdin:process.stdin,stdout:process.stdout});return v.native?v.code:(process.stderr.write(process.env.ORACLE_NATIVE_TUI==="0"?`oracle standalone chat requires the native TUI; remove ORACLE_NATIVE_TUI=0
|
|
40
40
|
`:`oracle standalone chat requires an interactive TTY or -q <query>
|
|
41
|
-
`),1)}let a=i.bin;
|
|
42
|
-
`);let
|
|
41
|
+
`),1)}let a=i.bin;ci(T),ai(T),li(T);let u=fi(T);ui(T),!u.ok&&process.env.ORACLE_CLI_DEBUG&&process.stderr.write(`oracle chat: skin note: ${u.reason}
|
|
42
|
+
`);let c=!!(n.model||n.provider);if(!Un(T)&&!c){if(!process.stdin.isTTY||!process.stdout.isTTY)return process.stderr.write(`oracle chat needs a configured model
|
|
43
43
|
run: oracle model
|
|
44
44
|
`),1;process.stdout.write(`choose oracle's model before first chat
|
|
45
45
|
|
|
46
|
-
`);let _=
|
|
47
|
-
`)}var
|
|
48
|
-
`),0;let n=
|
|
46
|
+
`);let _=Te(a,["-p",T,"model"]),v=await Q(_.command,_.args,{stdio:"inherit",env:process.env},"oracle-model");if(v!==0||!Un(T))return v||1}let f=["-p",T,"chat"],p=Hn(a),y=await We({hermesPython:p,args:t,env:s,cwd:process.cwd(),stdin:process.stdin,stdout:process.stdout});if(y.native)return y.code;let x=Te(a,[...f,...n.pass]);return Q(x.command,x.args,{stdio:"inherit",env:s},"oracle-chat")}};function $(e,t){let n=e.indexOf(t);return n>=0&&e[n+1]?e[n+1]:null}function _i(e){let t=$(e,"--backend"),n=$(e,"--provider"),r=$(e,"--model")||$(e,"-m"),o=$(e,"--base-url"),i=$(e,"--api-key-env"),s=$(e,"--context-length"),a=$(e,"--reasoning-effort"),u=$(e,"--compute-host")||$(e,"--remote-host"),c=$(e,"--compute-user")||$(e,"--remote-user"),f=$(e,"--compute-path")||$(e,"--remote-path");if(!t&&!!!(n||r||o||i||s||a||u||c||f))return null;let y={...pe()||{}};return n&&(delete y.apiKeyEnv,(n!=="custom"||n!==y.provider)&&delete y.baseUrl),{...y,backend:t||"standalone",...n?{provider:n}:{},...r?{model:r}:{},...o?{baseUrl:o}:{},...i?{apiKeyEnv:i}:{},...s?{contextLength:s}:{},...a?{reasoningEffort:a}:{},...u?{computeHost:u}:{},...c?{computeUser:c}:{},...f?{computePath:f}:{}}}function wi(){return["oracle model, choose standalone model settings or open Hermes' picker",""," oracle model"," oracle model --show"," oracle model --backend standalone --provider openrouter --model openrouter/auto"," oracle model --backend remote --compute-host <host>"," oracle model --backend auto","","standalone keys stay in environment variables, never model.json:"," OPENROUTER_API_KEY, OPENAI_API_KEY, XAI_API_KEY, DEEPSEEK_API_KEY, GEMINI_API_KEY"].join(`
|
|
47
|
+
`)}var xc={name:"model",summary:"choose Oracle's standalone model or existing Hermes provider",group:"read",usage:wi(),async run(e){let t=[...e.argv];if(t.includes("--show"))return process.stdout.write(`${JSON.stringify(pe()||{backend:"auto"},null,2)}
|
|
48
|
+
`),0;let n=_i(t);if(n)try{let i=kt(n);return process.stdout.write(`oracle model: ${i.backend}`),i.provider&&process.stdout.write(` / ${i.provider}`),i.model&&process.stdout.write(` / ${i.model}`),process.stdout.write(`
|
|
49
49
|
`),i.backend==="standalone"&&i.apiKeyEnv&&process.stdout.write(`key source: ${i.apiKeyEnv}
|
|
50
50
|
`),0}catch(i){return process.stderr.write(`oracle model: ${i.message}
|
|
51
|
-
`),1}let r=
|
|
51
|
+
`),1}let r=de();if(!r.ok)return process.stderr.write(`Oracle standalone chat does not require Hermes.
|
|
52
52
|
Configure a provider with: oracle model --backend standalone --provider openrouter --model openrouter/auto
|
|
53
53
|
Then set OPENROUTER_API_KEY.
|
|
54
|
-
`),1;let o=
|
|
54
|
+
`),1;let o=Te(r.bin,["-p","oracle","model",...t]);return Q(o.command,o.args,{stdio:"inherit",env:process.env},"oracle-model")}};export{xc as default};
|