@oracle-agent/oracle 0.28.17 → 0.28.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- import{spawnSync as Lt}from"node:child_process";import{stdin as b,stdout as Ie}from"node:process";var te=Object.freeze([{key:"telegram",name:"telegram",hermes:["gateway","setup"],required:["TELEGRAM_BOT_TOKEN"],optional:["TELEGRAM_ALLOWED_USERS","TELEGRAM_PROXY"],note:"dms \xB7 groups \xB7 topics"},{key:"discord",name:"discord",hermes:["gateway","setup"],required:["DISCORD_BOT_TOKEN"],optional:["DISCORD_ALLOWED_USERS"],note:"dms \xB7 channels \xB7 threads"},{key:"slack",name:"slack",hermes:["gateway","setup"],required:["SLACK_BOT_TOKEN","SLACK_APP_TOKEN"],optional:["SLACK_ALLOWED_USERS"],note:"socket mode"},{key:"whatsapp",name:"whatsapp",hermes:["whatsapp"],required:[],optional:["WHATSAPP_ALLOWED_USERS","WHATSAPP_MODE"],note:"qr bridge"},{key:"whatsapp-cloud",name:"whatsapp cloud",hermes:["whatsapp-cloud"],required:[],optional:[],note:"business cloud api"},{key:"signal",name:"signal",hermes:["gateway","setup"],required:["SIGNAL_HTTP_URL","SIGNAL_ACCOUNT"],optional:["SIGNAL_ALLOWED_USERS"],note:"signal-cli rest bridge"},{key:"matrix",name:"matrix",hermes:["gateway","setup"],required:["MATRIX_HOMESERVER","MATRIX_ACCESS_TOKEN","MATRIX_USER_ID"],optional:["MATRIX_ALLOWED_USERS"],note:"rooms \xB7 dms"},{key:"mattermost",name:"mattermost",hermes:["gateway","setup"],required:["MATTERMOST_URL","MATTERMOST_TOKEN"],optional:["MATTERMOST_ALLOWED_USERS"],note:"channels \xB7 dms"},{key:"email",name:"email",hermes:["gateway","setup"],required:["EMAIL_ADDRESS","EMAIL_PASSWORD","EMAIL_IMAP_HOST","EMAIL_SMTP_HOST"],optional:[],note:"imap/smtp mailbox"},{key:"bluebubbles",name:"bluebubbles",hermes:["gateway","setup"],required:[],optional:[],note:"imessage via bluebubbles"},{key:"photon",name:"photon",hermes:["photon"],required:["PHOTON_PROJECT_ID","PHOTON_PROJECT_SECRET"],optional:["PHOTON_ALLOWED_USERS","PHOTON_HOME_CHANNEL"],note:"imessage via spectrum (no mac)"},{key:"homeassistant",name:"homeassistant",hermes:["gateway","setup"],required:["HASS_URL","HASS_TOKEN"],optional:[],note:"smart home"},{key:"webhook",name:"webhook",hermes:["gateway","setup"],required:[],optional:[],note:"http ingress"},{key:"api-server",name:"api server",hermes:["gateway","setup"],required:[],optional:[],note:"local http api"},{key:"dingtalk",name:"dingtalk",hermes:["gateway","setup"],required:[],optional:[],note:"dingtalk bot"},{key:"feishu",name:"feishu",hermes:["gateway","setup"],required:[],optional:[],note:"feishu / lark"},{key:"wecom",name:"wecom",hermes:["gateway","setup"],required:[],optional:[],note:"wecom"},{key:"weixin",name:"weixin",hermes:["gateway","setup"],required:[],optional:[],note:"weixin"},{key:"qqbot",name:"qqbot",hermes:["gateway","setup"],required:[],optional:[],note:"qq bot"}]);function ye(e){return String(e||"").trim().toLowerCase().replace(/^\/+/,"").replace(/\s+/g,"-")}function H(){return te.slice()}function j(e){let t=ye(e);if(!t)return null;for(let r of te)if(r.key===t||ye(r.name)===t)return r;return null}function ke({profile:e="oracle",statuses:t={}}={}){let r=["oracle setup","","one oracle. many models. every connected channel.",`profile: ${e}`,"","messaging platforms:",""];for(let o of te){let n=t[o.key]||"unset";r.push(` ${o.key.padEnd(16)} ${String(n).padEnd(8)} ${o.note}`)}return r.push(""),r.push("commands:"),r.push(" oracle setup this menu"),r.push(" oracle setup messaging open hermes gateway setup"),r.push(" oracle setup telegram configure telegram bot token"),r.push(" oracle setup discord configure discord bot token"),r.push(" oracle setup status show configured platforms (no secrets)"),r.push(" oracle setup gateway start/status hermes gateway"),r.push(" /setup same menu inside chat"),r.push(""),r.push("notes:"),r.push(" tokens stay in the hermes profile .env on this machine"),r.push(" oracle never prints bot tokens or app secrets"),r.push(" after setup: hermes -p oracle gateway restart"),r.join(`
1
+ import{spawnSync as Lt}from"node:child_process";import{stdin as b,stdout as Ie}from"node:process";var te=Object.freeze([{key:"telegram",name:"telegram",hermes:["gateway","setup"],required:["TELEGRAM_BOT_TOKEN"],optional:["TELEGRAM_ALLOWED_USERS","TELEGRAM_PROXY"],note:"dms \xB7 groups \xB7 topics"},{key:"discord",name:"discord",hermes:["gateway","setup"],required:["DISCORD_BOT_TOKEN"],optional:["DISCORD_ALLOWED_USERS"],note:"dms \xB7 channels \xB7 threads"},{key:"slack",name:"slack",hermes:["gateway","setup"],required:["SLACK_BOT_TOKEN","SLACK_APP_TOKEN"],optional:["SLACK_ALLOWED_USERS"],note:"socket mode"},{key:"whatsapp",name:"whatsapp",hermes:["whatsapp"],required:[],optional:["WHATSAPP_ALLOWED_USERS","WHATSAPP_MODE"],note:"qr bridge"},{key:"whatsapp-cloud",name:"whatsapp cloud",hermes:["whatsapp-cloud"],required:[],optional:[],note:"business cloud api"},{key:"signal",name:"signal",hermes:["gateway","setup"],required:["SIGNAL_HTTP_URL","SIGNAL_ACCOUNT"],optional:["SIGNAL_ALLOWED_USERS"],note:"signal-cli rest bridge"},{key:"matrix",name:"matrix",hermes:["gateway","setup"],required:["MATRIX_HOMESERVER","MATRIX_ACCESS_TOKEN","MATRIX_USER_ID"],optional:["MATRIX_ALLOWED_USERS"],note:"rooms \xB7 dms"},{key:"mattermost",name:"mattermost",hermes:["gateway","setup"],required:["MATTERMOST_URL","MATTERMOST_TOKEN"],optional:["MATTERMOST_ALLOWED_USERS"],note:"channels \xB7 dms"},{key:"email",name:"email",hermes:["gateway","setup"],required:["EMAIL_ADDRESS","EMAIL_PASSWORD","EMAIL_IMAP_HOST","EMAIL_SMTP_HOST"],optional:[],note:"imap/smtp mailbox"},{key:"bluebubbles",name:"bluebubbles",hermes:["gateway","setup"],required:[],optional:[],note:"imessage via bluebubbles"},{key:"photon",name:"photon",hermes:["photon"],required:["PHOTON_PROJECT_ID","PHOTON_PROJECT_SECRET"],optional:["PHOTON_ALLOWED_USERS","PHOTON_HOME_CHANNEL"],note:"imessage via spectrum (no mac)"},{key:"homeassistant",name:"homeassistant",hermes:["gateway","setup"],required:["HASS_URL","HASS_TOKEN"],optional:[],note:"smart home"},{key:"webhook",name:"webhook",hermes:["gateway","setup"],required:[],optional:[],note:"http ingress"},{key:"api-server",name:"api server",hermes:["gateway","setup"],required:[],optional:[],note:"local http api"},{key:"dingtalk",name:"dingtalk",hermes:["gateway","setup"],required:[],optional:[],note:"dingtalk bot"},{key:"feishu",name:"feishu",hermes:["gateway","setup"],required:[],optional:[],note:"feishu / lark"},{key:"wecom",name:"wecom",hermes:["gateway","setup"],required:[],optional:[],note:"wecom"},{key:"weixin",name:"weixin",hermes:["gateway","setup"],required:[],optional:[],note:"weixin"},{key:"qqbot",name:"qqbot",hermes:["gateway","setup"],required:[],optional:[],note:"qq bot"}]);function ye(e){return String(e||"").trim().toLowerCase().replace(/^\/+/,"").replace(/\s+/g,"-")}function H(){return te.slice()}function j(e){let t=ye(e);if(!t)return null;for(let r of te)if(r.key===t||ye(r.name)===t)return r;return null}function _e({profile:e="oracle",statuses:t={}}={}){let r=["oracle setup","","one oracle. many models. every connected channel.",`profile: ${e}`,"","messaging platforms:",""];for(let o of te){let n=t[o.key]||"unset";r.push(` ${o.key.padEnd(16)} ${String(n).padEnd(8)} ${o.note}`)}return r.push(""),r.push("commands:"),r.push(" oracle setup this menu"),r.push(" oracle setup messaging open hermes gateway setup"),r.push(" oracle setup telegram configure telegram bot token"),r.push(" oracle setup discord configure discord bot token"),r.push(" oracle setup status show configured platforms (no secrets)"),r.push(" oracle setup gateway start/status hermes gateway"),r.push(" /setup same menu inside chat"),r.push(""),r.push("notes:"),r.push(" tokens stay in the hermes profile .env on this machine"),r.push(" oracle never prints bot tokens or app secrets"),r.push(" after setup: hermes -p oracle gateway restart"),r.join(`
2
2
  `)+`
3
- `}import E from"node:fs";import Ye from"node:os";import re from"node:path";import N from"node:fs";import He from"node:os";import _ from"node:path";import{fileURLToPath as ze}from"node:url";var Be=_.dirname(ze(import.meta.url)),Ht=_.resolve(Be,"../..");function z(){return process.env.ORACLE_FAKE_HOME||He.homedir()}function qe(){return process.env.ORACLE_PUBLIC_DESKTOP==="1"}function S(){return qe()?process.env.ORACLE_CONFIG_DIR||_.join(z(),".config","oracle"):_.join(z(),".config","oracle")}function We(){return _.join(S(),"desk.json")}function Ve(){return _.join(S(),"env")}function L({force:e=!1}={}){if(L._done&&!e)return L._result||null;L._done=!0;let t={},r=(n,s)=>{if(s==null)return;let i=String(s).trim();i&&(process.env[n]!=null&&String(process.env[n]).trim()!==""||(process.env[n]=i,t[n]=i))};try{let n=Ve();if(N.existsSync(n))for(let s of N.readFileSync(n,"utf8").split(/\r?\n/)){let i=s.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*?)\s*$/);if(!i||i[2].startsWith("#"))continue;let a=i[2];(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),r(i[1],a)}}catch{}try{let n=We();if(N.existsSync(n)){let s=JSON.parse(N.readFileSync(n,"utf8"));s&&typeof s=="object"&&(r("ORACLE_DESK_URL",s.deskUrl||s.dataUrl||s.url),r("ORACLE_DATA_URL",s.dataUrl||s.deskUrl||s.url),r("ORACLE_API_URL",s.apiUrl||s.dataUrl||s.deskUrl),r("ORACLE_PUBLIC_URL",s.publicUrl||s.deskUrl||s.dataUrl),r("ORACLE_EXEC_URL",s.execUrl),r("MAD_DESK_URL",s.deskUrl||s.dataUrl))}}catch{}let o=process.env.ORACLE_DESK_URL||process.env.ORACLE_DATA_URL||"";return o&&(r("ORACLE_DESK_URL",o),r("ORACLE_DATA_URL",o),r("ORACLE_API_URL",o),r("ORACLE_PUBLIC_URL",o),r("MAD_DESK_URL",o)),L._result=Object.keys(t).length?t:null,L._result}try{L()}catch{}function M(){return process.env.HERMES_HOME?_.resolve(process.env.HERMES_HOME):_.join(z(),".hermes")}function x(e){return N.mkdirSync(e,{recursive:!0}),e}var Je=/(TOKEN|SECRET|PASSWORD|KEY|AUTH|PRIVATE|MNEMONIC|SEED)/i;function B(e="oracle"){return re.join(M(),"profiles",e,".env")}function Ge(e){let t={};for(let r of String(e||"").split(/\r?\n/)){let o=r.trim();if(!o||o.startsWith("#"))continue;let n=o.indexOf("=");if(n<=0)continue;let s=o.slice(0,n).trim(),i=o.slice(n+1).trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),t[s]=i}return t}function Se(e="oracle"){let t=B(e);return E.existsSync(t)?Ge(E.readFileSync(t,"utf8")):{}}function ve(e,t,r){if(!t||Je.test(t)===!1&&/[^A-Z0-9_]/.test(t),!/^[A-Z][A-Z0-9_]*$/.test(t)){let d=new Error(`invalid env key '${t}'`);throw d.code="BAD_KEY",d}if(r==null||String(r).trim()===""){let d=new Error(`empty value for ${t}`);throw d.code="EMPTY",d}let o=B(e);x(re.dirname(o));let n=E.existsSync(o)?E.readFileSync(o,"utf8"):"",s=n?n.split(/\r?\n/):[],i=[],a=!1,c=`${t}=${String(r)}`;for(let d of s)d.startsWith(`${t}=`)?(i.push(c),a=!0):(d.length||i.length)&&i.push(d);for(a||(i.length&&i[i.length-1]!==""&&i.push(""),i.push(c));i.length&&i[i.length-1]==="";)i.pop();i.push(""),E.writeFileSync(o,i.join(`
4
- `),{mode:384});try{E.chmodSync(o,384)}catch{}return{path:o,key:t,set:!0}}function q(e="oracle"){let t=Se(e),r={};for(let o of H()){if(!o.required.length){r[o.key]="manual";continue}let n=o.required.filter(s=>!String(t[s]||"").trim());r[o.key]=n.length?"unset":"ready"}return{profile:e,statuses:r,envPath:B(e)}}function W(e="oracle"){let{statuses:t}=q(e);return ke({profile:e,statuses:t})}function Ee(e,t,r,o={}){let n=j(t);if(!n){let p=new Error(`unknown platform '${t}'`);throw p.code="UNKNOWN_PLATFORM",p}if(!n.required.length){let p=new Error(`${n.key} uses hermes interactive setup (oracle setup messaging)`);throw p.code="NEEDS_INTERACTIVE",p}let i=n.required.filter(p=>/(TOKEN|PASSWORD|SECRET)$/i.test(p))[0]||(n.required.length===1?n.required[0]:null);if(!i){let p=new Error(`${n.key} has no single token field; provide each of [${n.required.join(", ")}] explicitly`);throw p.code="NEEDS_EXPLICIT_KEYS",p}let a=new Set([i,...Object.keys(o||{}).filter(p=>o[p]!=null&&String(o[p]).trim())]),c=Se(e),d=n.required.filter(p=>!a.has(p)&&!String(c[p]||"").trim());if(d.length){let p=new Error(`${n.key} also requires [${d.join(", ")}]; pass them explicitly (setup would otherwise be marked ready while unusable)`);throw p.code="MISSING_REQUIRED",p}ve(e,i,r);for(let[p,k]of Object.entries(o||{}))k!=null&&String(k).trim()&&ve(e,p,k);return{platform:n.key,set:n.required,profile:e,path:B(e)}}function Xe(){return re.join(S(),"setup-state.json")}function V(e={}){x(S());let t=Xe(),r={};if(E.existsSync(t))try{r=JSON.parse(E.readFileSync(t,"utf8"))}catch{r={}}let o={...r,...e,updatedAt:new Date().toISOString(),host:Ye.hostname()};return E.writeFileSync(t,JSON.stringify(o,null,2)+`
5
- `,{mode:384}),o}import _e from"node:fs";import I from"node:path";var Ze="0.19.0",Qt=`hermes-agent==${Ze}`;var Ae="0.12.1",er=Object.freeze({posix:Object.freeze({url:`https://github.com/astral-sh/uv/releases/download/${Ae}/uv-installer.sh`,sha256:"d3f5412d38c99f9d024901843bf98206f0d2c6dbe64df40d0b740e2751ca62c1"}),windows:Object.freeze({url:`https://github.com/astral-sh/uv/releases/download/${Ae}/uv-installer.ps1`,sha256:"b9ec035151bfbb11d616dbd69886498d885551489eddf095ea3c0ad59f640eb0"})});function Qe(){return I.join(S(),"runtime")}function et(){return I.join(Qe(),"venv")}function tt(e){let t=process.platform==="win32"?"Scripts":"bin",r=process.platform==="win32"?`${e}.exe`:e;return I.join(et(),t,r)}function rt(){return tt("hermes")}function ot(e){let t=process.platform==="win32"&&!I.extname(e)?["",".exe",".cmd",".bat"]:[""];for(let r of(process.env.PATH||"").split(I.delimiter))if(r)for(let o of t){let n=I.join(r,`${e}${o}`);try{if(_e.existsSync(n))return n}catch{}}return null}function xe(){if(process.env.ORACLE_HERMES_BIN)return{ok:!0,bin:process.env.ORACLE_HERMES_BIN,source:"env"};let e=rt();if(_e.existsSync(e))return{ok:!0,bin:e,source:"managed"};let t=ot("hermes");return t?{ok:!0,bin:t,source:"path"}:{ok:!1,bin:null,source:null}}import{createHash as nt,randomBytes as se,timingSafeEqual as st}from"node:crypto";import y from"node:fs";import A from"node:path";import it from"node:readline/promises";import{spawn as at,spawnSync as ct}from"node:child_process";var C=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.6",protocol:"responses"}}),ut=12e4;function lt(e={}){return typeof e.now=="function"?Number(e.now()):Date.now()}function T(e){let t=String(e||"").trim().toLowerCase();for(let[r,o]of Object.entries(C))if(o.aliases.includes(t))return r;throw new Error(`unsupported OAuth provider: ${e||"(empty)"}`)}function F(e){let t=T(e);return{id:t,...C[t]}}function w(e,t={}){if(!y.existsSync(e))return t;try{let r=JSON.parse(y.readFileSync(e,"utf8"));if(!r||typeof r!="object"||Array.isArray(r))throw new Error("invalid object");return r}catch{throw new Error(`credential store is unreadable or corrupt: ${A.basename(e)}`)}}function be(e){x(e),process.platform!=="win32"&&y.chmodSync(e,448)}function O(e,t){be(A.dirname(e));let r=`${e}.${process.pid}.${se(4).toString("hex")}.tmp`;y.writeFileSync(r,`${JSON.stringify(t,null,2)}
6
- `,{mode:384}),y.renameSync(r,e),process.platform!=="win32"&&y.chmodSync(e,384)}function pt(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 oe(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 $(e={}){let t=String(e.accessToken||e.access_token||"").trim(),r=String(e.refreshToken||e.refresh_token||"").trim(),o=Number(e.expiresAt||e.expires_at||0);if(Number.isFinite(o)&&o>=1e9&&o<1e12&&(o=o*1e3),!t)throw new Error("OAuth credential is missing access token");return{accessToken:t,refreshToken:r,expiresAt:Number.isFinite(o)?o: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||A.join(S(),"oauth.json"),r=e.metadataFile||A.join(A.dirname(t),"oauth-meta.json"),o=e.linksFile||A.join(A.dirname(t),"oauth-links.json"),n=()=>typeof e.now=="function"?Number(e.now()):Date.now(),s=e.spawnFn||ct,i=e.keychain!==!1&&process.env.ORACLE_AUTH_FILE_STORE!=="1"&&pt(s),a=i?"linux-secret-service":"private-file",c=`${t}.lock`;async function d(m){be(A.dirname(c));let h;for(let u=0;u<400;u+=1)try{h=y.openSync(c,"wx",384);break}catch(l){if(l?.code!=="EEXIST")throw l;try{Date.now()-y.statSync(c).mtimeMs>3e5&&y.unlinkSync(c)}catch{}await new Promise(f=>setTimeout(f,25))}if(h===void 0)throw new Error("timed out waiting for OAuth credential lock");try{return await m()}finally{try{y.closeSync(h)}catch{}try{y.unlinkSync(c)}catch{}}}function p(m,h="oauth"){return["application","oracle","kind",h,"provider",m]}function k(m){if(!y.existsSync(o))return null;let u=w(o,{providers:{}}).providers?.[m];if(!Array.isArray(u))return null;let l=[];for(let f of u)if(A.isAbsolute(String(f||"")))try{let g=w(f,{});if(m==="anthropic-oauth"&&g.claudeAiOauth){let P=$(g.claudeAiOauth);l.push({...P,refreshToken:"",source:"external-access-only"});continue}let v=g.credential_pool&&typeof g.credential_pool=="object"?g.credential_pool:null;if(v){let P=v[m]||v[m.replace(/-oauth$/,"")]||[],Fe=Array.isArray(P)?P:P?[P]:[];for(let ee of Fe)if(!(!ee||typeof ee!="object"))try{let Ke=$(ee);l.push({...Ke,refreshToken:"",source:"external-access-only"})}catch{}}}catch{}return l.length?l.find(f=>!f.expiresAt||f.expiresAt>n()+ut)||l[0]:null}function ge(m){let h=T(m);if(i){let f=s("secret-tool",["lookup",...p(h)],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});if(!f.error&&f.status===0&&String(f.stdout||"").trim())try{return $(JSON.parse(String(f.stdout).trim()))}catch{}return k(h)}let l=w(t,{providers:{}}).providers?.[h];if(l)try{return $(l)}catch{}return k(h)}function De(m,h){let u=T(m),l=$(h);if(i){let g=s("secret-tool",["store",`--label=Oracle ${u} OAuth`,...p(u)],{input:JSON.stringify(l),encoding:"utf8",stdio:["pipe","ignore","pipe"]});if(g.error||g.status!==0)throw new Error("OS credential store rejected OAuth credential");let v=w(r,{providers:{}});return v.providers||={},v.providers[u]={expiresAt:l.expiresAt,source:l.source},O(r,v),l}let f=w(t,{providers:{}});return f.providers||={},f.providers[u]=l,O(t,f),l}function Ue(m){let h=T(m);if(i){let f=s("secret-tool",["clear",...p(h)],{encoding:"utf8",stdio:["ignore","ignore","pipe"]}),g=w(r,{providers:{}});return g.providers&&delete g.providers[h],O(r,g),!f.error&&f.status===0}let u=w(t,{providers:{}}),l=!!u.providers?.[h];return u.providers&&delete u.providers[h],O(t,u),l}function we(m){let h=oe(m);if(i){let u=s("secret-tool",["lookup",...p(h,"api-key")],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});return u.error||u.status!==0?"":String(u.stdout||"").trim()}return String(w(t,{apiKeys:{}}).apiKeys?.[h]||"").trim()}function je(m,h){let u=oe(m),l=String(h||"").trim();if(!l)throw new Error("API key is empty");if(i){let g=s("secret-tool",["store",`--label=Oracle ${u} API key`,...p(u,"api-key")],{input:l,encoding:"utf8",stdio:["pipe","ignore","pipe"]});if(g.error||g.status!==0)throw new Error("OS credential store rejected API key");let v=w(r,{providers:{},apiKeys:{}});return v.apiKeys||={},v.apiKeys[u]={configured:!0},O(r,v),!0}let f=w(t,{providers:{},apiKeys:{}});return f.apiKeys||={},f.apiKeys[u]=l,O(t,f),!0}function Ne(m){let h=oe(m);if(i){let f=s("secret-tool",["clear",...p(h,"api-key")],{encoding:"utf8",stdio:["ignore","ignore","pipe"]}),g=w(r,{providers:{},apiKeys:{}});return g.apiKeys&&delete g.apiKeys[h],O(r,g),!f.error&&f.status===0}let u=w(t,{providers:{},apiKeys:{}}),l=!!u.apiKeys?.[h];return u.apiKeys&&delete u.apiKeys[h],O(t,u),l}function Me(){let m={},h={};if(i){let u=w(r,{providers:{},apiKeys:{}});for(let[l,f]of Object.entries(u.providers||{}))m[l]={loggedIn:!!ge(l),expiresAt:Number(f.expiresAt||0),source:String(f.source||"oracle"),storage:a};for(let l of Object.keys(u.apiKeys||{}))h[l]={configured:!!we(l),storage:a}}else{let u=w(t,{providers:{},apiKeys:{}});for(let[l,f]of Object.entries(u.providers||{}))m[l]={loggedIn:!!f?.accessToken,expiresAt:Number(f?.expiresAt||0),source:String(f?.source||"oracle"),storage:a};for(let[l,f]of Object.entries(u.apiKeys||{}))h[l]={configured:!!f,storage:a}}for(let u of Object.keys(C)){if(m[u])continue;let l=k(u);l&&(m[u]={loggedIn:!0,expiresAt:l.expiresAt,source:l.source,storage:"external-access-source"})}return{storage:a,providers:m,apiKeys:h}}return Object.freeze({file:t,storage:a,get:ge,set:De,remove:Ue,getApiKey:we,setApiKey:je,removeApiKey:Ne,status:Me,withLock:d})}var Oe;function D(){return Oe||=dt(),Oe}function ne(e){return Buffer.from(e).toString("base64url")}function ft(){let e=ne(se(32));return{verifier:e,challenge:ne(nt("sha256").update(e).digest()),state:ne(se(24))}}function ht(e,t){let r=Buffer.from(String(e||"")),o=Buffer.from(String(t||""));return r.length===o.length&&st(r,o)}function mt(e){let t=String(e),r=process.platform==="darwin"?["open",[t]]:process.platform==="win32"?["cmd.exe",["/d","/s","/c","start","",t]]:["xdg-open",[t]];try{return at(r[0],r[1],{detached:!0,stdio:"ignore"}).unref(),!0}catch{return!1}}function ie(e){return new URLSearchParams(e).toString()}async function R(e,t){if(!e?.ok){let o="";try{o=String((await e.json())?.error||"")}catch{}throw new Error(`${t} failed (HTTP ${e?.status||"unknown"}${o?`, ${o}`:""})`)}let r=await e.json();if(!r||typeof r!="object")throw new Error(`${t} returned invalid JSON`);return r}async function gt(e){if(e)return String(await e()).trim();let t=it.createInterface({input:process.stdin,output:process.stdout});try{return String(await t.question("Authorization code: ")).trim()}finally{t.close()}}function ae(e,t={}){let r=String(e.access_token||"").trim(),o=String(e.refresh_token||t.refreshToken||"").trim();if(!r)throw new Error("OAuth token response is missing access token");let n=Number(e.expires_in||3600);return $({accessToken:r,refreshToken:o,expiresAt:lt(t)+Math.max(1,n)*1e3,tokenType:e.token_type||"Bearer",idToken:e.id_token,source:"oracle",...t.discovery?{discovery:t.discovery}:{},...e.scope?{scope:e.scope}:{}})}async function wt(e){let t=C["anthropic-oauth"],r=e.pkce||ft(),o=new URLSearchParams({code:"true",client_id:t.clientId,response_type:"code",redirect_uri:t.redirectUri,scope:t.scope,code_challenge:r.challenge,code_challenge_method:"S256",state:r.state}),n=`${t.authorizeUrl}?${o}`;e.output(`Open: ${n}`),e.openFn(n);let s=await gt(e.inputFn),[i,a]=s.split("#",2);if(!i||!ht(a,r.state))throw new Error("Claude OAuth state mismatch");let c=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:i,state:a,redirect_uri:t.redirectUri,code_verifier:r.verifier})});return ae(await R(c,"Claude OAuth token exchange"),e)}async function yt(e){let t=C["openai-codex"],r=await R(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(!r.user_code||!r.device_auth_id)throw new Error("Codex device authorization returned incomplete data");let o=`${t.issuer}/codex/device`;e.output(`Open: ${o}`),e.output(`Code: ${r.user_code}`),e.openFn(o);let n=Math.max(3,Number(r.interval||5)),s;for(let a=0;a<Math.ceil(900/n);a+=1){await e.sleepFn(n*1e3);let c=await e.fetchFn(`${t.issuer}/api/accounts/deviceauth/token`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({device_auth_id:r.device_auth_id,user_code:r.user_code})});if(c.ok){s=await R(c,"Codex device authorization");break}if(![403,404].includes(c.status))throw new Error(`Codex device authorization failed (HTTP ${c.status})`)}if(!s)throw new Error("Codex device authorization timed out");let i=await e.fetchFn(t.tokenUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:ie({grant_type:"authorization_code",code:s.authorization_code,redirect_uri:`${t.issuer}/deviceauth/callback`,client_id:t.clientId,code_verifier:s.code_verifier})});return ae(await R(i,"Codex OAuth token exchange"),e)}function Y(e){let t=new URL(String(e)),r=t.hostname.toLowerCase();if(t.protocol!=="https:"||r!=="x.ai"&&!r.endsWith(".x.ai"))throw new Error("xAI OAuth discovery returned an untrusted endpoint");return t.toString()}async function kt(e){let t=C["xai-oauth"],r=await R(await e.fetchFn(t.discoveryUrl,{headers:{accept:"application/json"}}),"xAI OAuth discovery");Y(r.authorization_endpoint);let o=Y(r.token_endpoint),n=await R(await e.fetchFn(t.deviceUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},body:ie({client_id:t.clientId,scope:t.scope})}),"xAI device authorization");if(!n.device_code||!n.user_code||!n.verification_uri)throw new Error("xAI device authorization returned incomplete data");let s=Y(n.verification_uri_complete||n.verification_uri);e.output(`Open: ${s}`),e.output(`Code: ${n.user_code}`),e.openFn(s);let i=Math.max(1,Number(n.interval||5)),a=Math.ceil(Math.max(1,Number(n.expires_in||600))/i);for(let c=0;c<a;c+=1){let d=await e.fetchFn(o,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},body:ie({grant_type:"urn:ietf:params:oauth:grant-type:device_code",client_id:t.clientId,device_code:n.device_code})});if(d.ok){let k=await R(d,"xAI OAuth token exchange");return ae(k,{...e,discovery:{authorization_endpoint:Y(r.authorization_endpoint),token_endpoint:o}})}let p="";try{p=String((await d.json())?.error||"")}catch{}if(p==="slow_down")await e.sleepFn((i+1)*1e3);else if(p==="authorization_pending")await e.sleepFn(i*1e3);else throw new Error(`xAI OAuth token exchange failed (HTTP ${d.status}${p?`, ${p}`:""})`)}throw new Error("xAI device authorization timed out")}async function Te(e,t={}){let r=T(e),o={fetchFn:t.fetchFn||globalThis.fetch,inputFn:t.inputFn,sleepFn:t.sleepFn||(n=>new Promise(s=>setTimeout(s,n))),openFn:t.openFn||mt,output:t.output||(n=>process.stdout.write(`${n}
7
- `)),now:t.now,pkce:t.pkce};return r==="anthropic-oauth"?wt(o):r==="openai-codex"?yt(o):kt(o)}import X from"node:fs";import ce from"node:path";var vt=new Set(["openrouter","openai","anthropic","xai","deepseek","gemini","kimi","mistral","nous","custom","anthropic-oauth","openai-codex","xai-oauth"]);function J(e){return String(e||"").trim()||void 0}function St(e,{required:t=!1}={}){let r=J(e)?.toLowerCase();if(!r){if(t)throw new Error("model provider is required");return}if(!vt.has(r))throw new Error(`unsupported provider: ${r}`);return r}function Et(e,{required:t=!1}={}){let r=J(e);if(!r){if(t)throw new Error("model is required");return}if(r.includes("..")||r.startsWith("/")||!/^[a-zA-Z0-9._:/-]{1,200}$/.test(r))throw new Error("invalid model id");return r}function At(e){let t=J(e);if(!t||t.length>2048)throw new Error("invalid custom base URL");let r;try{r=new URL(t)}catch{throw new Error("invalid custom base URL")}let o=r.hostname.toLowerCase().replace(/^\[|\]$/g,""),n=o==="localhost"||o==="127.0.0.1"||o==="::1";if(r.protocol!=="https:"&&!(r.protocol==="http:"&&n)||r.username||r.password||r.search||r.hash)throw new Error("custom base URL must use HTTPS or loopback HTTP without credentials, query, or fragment");return r.toString().replace(/\/+$/,"")}function G({provider:e,model:t,baseUrl:r}={},{requireModel:o=!1}={}){let n=St(e),s=Et(t,{required:o});if(n==="custom")return{provider:n,...s?{model:s}:{},baseUrl:At(r)};if(J(r))throw new Error("baseUrl is only supported for the custom provider");return{...n?{provider:n}:{},...s?{model:s}:{}}}var _t=new Set(["auto","standalone","hermes","remote","arch"]);function xt(){return ce.join(S(),"model.json")}function U(e){return String(e||"").trim()||void 0}function Ot(e={}){let t=U(e.backend)?.toLowerCase()||"auto",r=G({provider:e.provider,model:e.model,baseUrl:e.baseUrl},{requireModel:t==="standalone"}),o=U(e.apiKeyEnv),n=Number.parseInt(String(e.contextLength||""),10),s=U(e.reasoningEffort),i=U(e.computeHost||e.remoteHost),a=U(e.computeUser||e.remoteUser),c=U(e.computePath||e.remotePath);if(!_t.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(o&&!/^[A-Z][A-Z0-9_]*$/.test(o))throw new Error("api key env must be an uppercase environment variable name");if(t==="remote"&&!i)throw new Error("remote backend requires computeHost");return{backend:t,...r,...o?{apiKeyEnv:o}:{},...Number.isFinite(n)&&n>0?{contextLength:n}:{},...s?{reasoningEffort:s}:{},...i?{computeHost:i}:{},...a?{computeUser:a}:{},...c?{computePath:c}:{}}}function Re(e){let t=Ot(e),r=xt();x(ce.dirname(r)),process.platform!=="win32"&&X.chmodSync(ce.dirname(r),448);let o=`${r}.${process.pid}.tmp`;return X.writeFileSync(o,`${JSON.stringify(t,null,2)}
3
+ `}import S from"node:fs";import Ye from"node:os";import re from"node:path";import N from"node:fs";import He from"node:os";import A from"node:path";import{fileURLToPath as ze}from"node:url";var Be=A.dirname(ze(import.meta.url)),Ht=A.resolve(Be,"../..");function z(){return process.env.ORACLE_FAKE_HOME||He.homedir()}function qe(){return process.env.ORACLE_PUBLIC_DESKTOP==="1"}function v(){return qe()?process.env.ORACLE_CONFIG_DIR||A.join(z(),".config","oracle"):A.join(z(),".config","oracle")}function We(){return A.join(v(),"desk.json")}function Ve(){return A.join(v(),"env")}function L({force:e=!1}={}){if(L._done&&!e)return L._result||null;L._done=!0;let t={},r=(n,s)=>{if(s==null)return;let i=String(s).trim();i&&(process.env[n]!=null&&String(process.env[n]).trim()!==""||(process.env[n]=i,t[n]=i))};try{let n=Ve();if(N.existsSync(n))for(let s of N.readFileSync(n,"utf8").split(/\r?\n/)){let i=s.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*?)\s*$/);if(!i||i[2].startsWith("#"))continue;let a=i[2];(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),r(i[1],a)}}catch{}try{let n=We();if(N.existsSync(n)){let s=JSON.parse(N.readFileSync(n,"utf8"));s&&typeof s=="object"&&(r("ORACLE_DESK_URL",s.deskUrl||s.dataUrl||s.url),r("ORACLE_DATA_URL",s.dataUrl||s.deskUrl||s.url),r("ORACLE_API_URL",s.apiUrl||s.dataUrl||s.deskUrl),r("ORACLE_PUBLIC_URL",s.publicUrl||s.deskUrl||s.dataUrl),r("ORACLE_EXEC_URL",s.execUrl),r("MAD_DESK_URL",s.deskUrl||s.dataUrl))}}catch{}let o=process.env.ORACLE_DESK_URL||process.env.ORACLE_DATA_URL||"";return o&&(r("ORACLE_DESK_URL",o),r("ORACLE_DATA_URL",o),r("ORACLE_API_URL",o),r("ORACLE_PUBLIC_URL",o),r("MAD_DESK_URL",o)),L._result=Object.keys(t).length?t:null,L._result}try{L()}catch{}function M(){return process.env.HERMES_HOME?A.resolve(process.env.HERMES_HOME):A.join(z(),".hermes")}function x(e){return N.mkdirSync(e,{recursive:!0}),e}var Je=/(TOKEN|SECRET|PASSWORD|KEY|AUTH|PRIVATE|MNEMONIC|SEED)/i;function B(e="oracle"){return re.join(M(),"profiles",e,".env")}function Ge(e){let t={};for(let r of String(e||"").split(/\r?\n/)){let o=r.trim();if(!o||o.startsWith("#"))continue;let n=o.indexOf("=");if(n<=0)continue;let s=o.slice(0,n).trim(),i=o.slice(n+1).trim();(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),t[s]=i}return t}function ve(e="oracle"){let t=B(e);return S.existsSync(t)?Ge(S.readFileSync(t,"utf8")):{}}function ke(e,t,r){if(!t||Je.test(t)===!1&&/[^A-Z0-9_]/.test(t),!/^[A-Z][A-Z0-9_]*$/.test(t)){let d=new Error(`invalid env key '${t}'`);throw d.code="BAD_KEY",d}if(r==null||String(r).trim()===""){let d=new Error(`empty value for ${t}`);throw d.code="EMPTY",d}let o=B(e);x(re.dirname(o));let n=S.existsSync(o)?S.readFileSync(o,"utf8"):"",s=n?n.split(/\r?\n/):[],i=[],a=!1,c=`${t}=${String(r)}`;for(let d of s)d.startsWith(`${t}=`)?(i.push(c),a=!0):(d.length||i.length)&&i.push(d);for(a||(i.length&&i[i.length-1]!==""&&i.push(""),i.push(c));i.length&&i[i.length-1]==="";)i.pop();i.push(""),S.writeFileSync(o,i.join(`
4
+ `),{mode:384});try{S.chmodSync(o,384)}catch{}return{path:o,key:t,set:!0}}function q(e="oracle"){let t=ve(e),r={};for(let o of H()){if(!o.required.length){r[o.key]="manual";continue}let n=o.required.filter(s=>!String(t[s]||"").trim());r[o.key]=n.length?"unset":"ready"}return{profile:e,statuses:r,envPath:B(e)}}function W(e="oracle"){let{statuses:t}=q(e);return _e({profile:e,statuses:t})}function Se(e,t,r,o={}){let n=j(t);if(!n){let p=new Error(`unknown platform '${t}'`);throw p.code="UNKNOWN_PLATFORM",p}if(!n.required.length){let p=new Error(`${n.key} uses hermes interactive setup (oracle setup messaging)`);throw p.code="NEEDS_INTERACTIVE",p}let i=n.required.filter(p=>/(TOKEN|PASSWORD|SECRET)$/i.test(p))[0]||(n.required.length===1?n.required[0]:null);if(!i){let p=new Error(`${n.key} has no single token field; provide each of [${n.required.join(", ")}] explicitly`);throw p.code="NEEDS_EXPLICIT_KEYS",p}let a=new Set([i,...Object.keys(o||{}).filter(p=>o[p]!=null&&String(o[p]).trim())]),c=ve(e),d=n.required.filter(p=>!a.has(p)&&!String(c[p]||"").trim());if(d.length){let p=new Error(`${n.key} also requires [${d.join(", ")}]; pass them explicitly (setup would otherwise be marked ready while unusable)`);throw p.code="MISSING_REQUIRED",p}ke(e,i,r);for(let[p,_]of Object.entries(o||{}))_!=null&&String(_).trim()&&ke(e,p,_);return{platform:n.key,set:n.required,profile:e,path:B(e)}}function Xe(){return re.join(v(),"setup-state.json")}function V(e={}){x(v());let t=Xe(),r={};if(S.existsSync(t))try{r=JSON.parse(S.readFileSync(t,"utf8"))}catch{r={}}let o={...r,...e,updatedAt:new Date().toISOString(),host:Ye.hostname()};return S.writeFileSync(t,JSON.stringify(o,null,2)+`
5
+ `,{mode:384}),o}import Ae from"node:fs";import I from"node:path";var Ze="0.19.0",Qt=`hermes-agent==${Ze}`;var Ee="0.12.1",er=Object.freeze({posix:Object.freeze({url:`https://github.com/astral-sh/uv/releases/download/${Ee}/uv-installer.sh`,sha256:"d3f5412d38c99f9d024901843bf98206f0d2c6dbe64df40d0b740e2751ca62c1"}),windows:Object.freeze({url:`https://github.com/astral-sh/uv/releases/download/${Ee}/uv-installer.ps1`,sha256:"b9ec035151bfbb11d616dbd69886498d885551489eddf095ea3c0ad59f640eb0"})});function Qe(){return I.join(v(),"runtime")}function et(){return I.join(Qe(),"venv")}function tt(e){let t=process.platform==="win32"?"Scripts":"bin",r=process.platform==="win32"?`${e}.exe`:e;return I.join(et(),t,r)}function rt(){return tt("hermes")}function ot(e){let t=process.platform==="win32"&&!I.extname(e)?["",".exe",".cmd",".bat"]:[""];for(let r of(process.env.PATH||"").split(I.delimiter))if(r)for(let o of t){let n=I.join(r,`${e}${o}`);try{if(Ae.existsSync(n))return n}catch{}}return null}function xe(){if(process.env.ORACLE_HERMES_BIN)return{ok:!0,bin:process.env.ORACLE_HERMES_BIN,source:"env"};let e=rt();if(Ae.existsSync(e))return{ok:!0,bin:e,source:"managed"};let t=ot("hermes");return t?{ok:!0,bin:t,source:"path"}:{ok:!1,bin:null,source:null}}import{createHash as nt,randomBytes as se,timingSafeEqual as st}from"node:crypto";import y from"node:fs";import E from"node:path";import it from"node:readline/promises";import{spawn as at,spawnSync as ct}from"node:child_process";var C=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.6",protocol:"responses"}}),ut=12e4;function lt(e={}){return typeof e.now=="function"?Number(e.now()):Date.now()}function T(e){let t=String(e||"").trim().toLowerCase();for(let[r,o]of Object.entries(C))if(o.aliases.includes(t))return r;throw new Error(`unsupported OAuth provider: ${e||"(empty)"}`)}function F(e){let t=T(e);return{id:t,...C[t]}}function w(e,t={}){if(!y.existsSync(e))return t;try{let r=JSON.parse(y.readFileSync(e,"utf8"));if(!r||typeof r!="object"||Array.isArray(r))throw new Error("invalid object");return r}catch{throw new Error(`credential store is unreadable or corrupt: ${E.basename(e)}`)}}function be(e){x(e),process.platform!=="win32"&&y.chmodSync(e,448)}function O(e,t){be(E.dirname(e));let r=`${e}.${process.pid}.${se(4).toString("hex")}.tmp`;y.writeFileSync(r,`${JSON.stringify(t,null,2)}
6
+ `,{mode:384}),y.renameSync(r,e),process.platform!=="win32"&&y.chmodSync(e,384)}function pt(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 oe(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 $(e={}){let t=String(e.accessToken||e.access_token||"").trim(),r=String(e.refreshToken||e.refresh_token||"").trim(),o=Number(e.expiresAt||e.expires_at||0);if(Number.isFinite(o)&&o>=1e9&&o<1e12&&(o=o*1e3),!t)throw new Error("OAuth credential is missing access token");return{accessToken:t,refreshToken:r,expiresAt:Number.isFinite(o)?o: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||E.join(v(),"oauth.json"),r=e.metadataFile||E.join(E.dirname(t),"oauth-meta.json"),o=e.linksFile||E.join(E.dirname(t),"oauth-links.json"),n=()=>typeof e.now=="function"?Number(e.now()):Date.now(),s=e.spawnFn||ct,i=e.keychain!==!1&&process.env.ORACLE_AUTH_FILE_STORE!=="1"&&pt(s),a=i?"linux-secret-service":"private-file",c=`${t}.lock`;async function d(m){be(E.dirname(c));let h;for(let u=0;u<400;u+=1)try{h=y.openSync(c,"wx",384);break}catch(l){if(l?.code!=="EEXIST")throw l;try{Date.now()-y.statSync(c).mtimeMs>3e5&&y.unlinkSync(c)}catch{}await new Promise(f=>setTimeout(f,25))}if(h===void 0)throw new Error("timed out waiting for OAuth credential lock");try{return await m()}finally{try{y.closeSync(h)}catch{}try{y.unlinkSync(c)}catch{}}}function p(m,h="oauth"){return["application","oracle","kind",h,"provider",m]}function _(m){if(!y.existsSync(o))return null;let u=w(o,{providers:{}}).providers?.[m];if(!Array.isArray(u))return null;let l=[];for(let f of u)if(E.isAbsolute(String(f||"")))try{let g=w(f,{});if(m==="anthropic-oauth"&&g.claudeAiOauth){let P=$(g.claudeAiOauth);l.push({...P,refreshToken:"",source:"external-access-only"});continue}let k=g.credential_pool&&typeof g.credential_pool=="object"?g.credential_pool:null;if(k){let P=k[m]||k[m.replace(/-oauth$/,"")]||[],Fe=Array.isArray(P)?P:P?[P]:[];for(let ee of Fe)if(!(!ee||typeof ee!="object"))try{let Ke=$(ee);l.push({...Ke,refreshToken:"",source:"external-access-only"})}catch{}}}catch{}return l.length?l.find(f=>!f.expiresAt||f.expiresAt>n()+ut)||l[0]:null}function ge(m){let h=T(m);if(i){let f=s("secret-tool",["lookup",...p(h)],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});if(!f.error&&f.status===0&&String(f.stdout||"").trim())try{return $(JSON.parse(String(f.stdout).trim()))}catch{}return _(h)}let l=w(t,{providers:{}}).providers?.[h];if(l)try{return $(l)}catch{}return _(h)}function De(m,h){let u=T(m),l=$(h);if(i){let g=s("secret-tool",["store",`--label=Oracle ${u} OAuth`,...p(u)],{input:JSON.stringify(l),encoding:"utf8",stdio:["pipe","ignore","pipe"]});if(g.error||g.status!==0)throw new Error("OS credential store rejected OAuth credential");let k=w(r,{providers:{}});return k.providers||={},k.providers[u]={expiresAt:l.expiresAt,source:l.source},O(r,k),l}let f=w(t,{providers:{}});return f.providers||={},f.providers[u]=l,O(t,f),l}function Ue(m){let h=T(m);if(i){let f=s("secret-tool",["clear",...p(h)],{encoding:"utf8",stdio:["ignore","ignore","pipe"]}),g=w(r,{providers:{}});return g.providers&&delete g.providers[h],O(r,g),!f.error&&f.status===0}let u=w(t,{providers:{}}),l=!!u.providers?.[h];return u.providers&&delete u.providers[h],O(t,u),l}function we(m){let h=oe(m);if(i){let u=s("secret-tool",["lookup",...p(h,"api-key")],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});return u.error||u.status!==0?"":String(u.stdout||"").trim()}return String(w(t,{apiKeys:{}}).apiKeys?.[h]||"").trim()}function je(m,h){let u=oe(m),l=String(h||"").trim();if(!l)throw new Error("API key is empty");if(i){let g=s("secret-tool",["store",`--label=Oracle ${u} API key`,...p(u,"api-key")],{input:l,encoding:"utf8",stdio:["pipe","ignore","pipe"]});if(g.error||g.status!==0)throw new Error("OS credential store rejected API key");let k=w(r,{providers:{},apiKeys:{}});return k.apiKeys||={},k.apiKeys[u]={configured:!0},O(r,k),!0}let f=w(t,{providers:{},apiKeys:{}});return f.apiKeys||={},f.apiKeys[u]=l,O(t,f),!0}function Ne(m){let h=oe(m);if(i){let f=s("secret-tool",["clear",...p(h,"api-key")],{encoding:"utf8",stdio:["ignore","ignore","pipe"]}),g=w(r,{providers:{},apiKeys:{}});return g.apiKeys&&delete g.apiKeys[h],O(r,g),!f.error&&f.status===0}let u=w(t,{providers:{},apiKeys:{}}),l=!!u.apiKeys?.[h];return u.apiKeys&&delete u.apiKeys[h],O(t,u),l}function Me(){let m={},h={};if(i){let u=w(r,{providers:{},apiKeys:{}});for(let[l,f]of Object.entries(u.providers||{}))m[l]={loggedIn:!!ge(l),expiresAt:Number(f.expiresAt||0),source:String(f.source||"oracle"),storage:a};for(let l of Object.keys(u.apiKeys||{}))h[l]={configured:!!we(l),storage:a}}else{let u=w(t,{providers:{},apiKeys:{}});for(let[l,f]of Object.entries(u.providers||{}))m[l]={loggedIn:!!f?.accessToken,expiresAt:Number(f?.expiresAt||0),source:String(f?.source||"oracle"),storage:a};for(let[l,f]of Object.entries(u.apiKeys||{}))h[l]={configured:!!f,storage:a}}for(let u of Object.keys(C)){if(m[u])continue;let l=_(u);l&&(m[u]={loggedIn:!0,expiresAt:l.expiresAt,source:l.source,storage:"external-access-source"})}return{storage:a,providers:m,apiKeys:h}}return Object.freeze({file:t,storage:a,get:ge,set:De,remove:Ue,getApiKey:we,setApiKey:je,removeApiKey:Ne,status:Me,withLock:d})}var Oe;function D(){return Oe||=dt(),Oe}function ne(e){return Buffer.from(e).toString("base64url")}function ft(){let e=ne(se(32));return{verifier:e,challenge:ne(nt("sha256").update(e).digest()),state:ne(se(24))}}function ht(e,t){let r=Buffer.from(String(e||"")),o=Buffer.from(String(t||""));return r.length===o.length&&st(r,o)}function mt(e){let t=String(e),r=process.platform==="darwin"?["open",[t]]:process.platform==="win32"?["cmd.exe",["/d","/s","/c","start","",t]]:["xdg-open",[t]];try{return at(r[0],r[1],{detached:!0,stdio:"ignore"}).unref(),!0}catch{return!1}}function ie(e){return new URLSearchParams(e).toString()}async function R(e,t){if(!e?.ok){let o="";try{o=String((await e.json())?.error||"")}catch{}throw new Error(`${t} failed (HTTP ${e?.status||"unknown"}${o?`, ${o}`:""})`)}let r=await e.json();if(!r||typeof r!="object")throw new Error(`${t} returned invalid JSON`);return r}async function gt(e){if(e)return String(await e()).trim();let t=it.createInterface({input:process.stdin,output:process.stdout});try{return String(await t.question("Authorization code: ")).trim()}finally{t.close()}}function ae(e,t={}){let r=String(e.access_token||"").trim(),o=String(e.refresh_token||t.refreshToken||"").trim();if(!r)throw new Error("OAuth token response is missing access token");let n=Number(e.expires_in||3600);return $({accessToken:r,refreshToken:o,expiresAt:lt(t)+Math.max(1,n)*1e3,tokenType:e.token_type||"Bearer",idToken:e.id_token,source:"oracle",...t.discovery?{discovery:t.discovery}:{},...e.scope?{scope:e.scope}:{}})}async function wt(e){let t=C["anthropic-oauth"],r=e.pkce||ft(),o=new URLSearchParams({code:"true",client_id:t.clientId,response_type:"code",redirect_uri:t.redirectUri,scope:t.scope,code_challenge:r.challenge,code_challenge_method:"S256",state:r.state}),n=`${t.authorizeUrl}?${o}`;e.output(`Open: ${n}`),e.openFn(n);let s=await gt(e.inputFn),[i,a]=s.split("#",2);if(!i||!ht(a,r.state))throw new Error("Claude OAuth state mismatch");let c=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:i,state:a,redirect_uri:t.redirectUri,code_verifier:r.verifier})});return ae(await R(c,"Claude OAuth token exchange"),e)}async function yt(e){let t=C["openai-codex"],r=await R(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(!r.user_code||!r.device_auth_id)throw new Error("Codex device authorization returned incomplete data");let o=`${t.issuer}/codex/device`;e.output(`Open: ${o}`),e.output(`Code: ${r.user_code}`),e.openFn(o);let n=Math.max(3,Number(r.interval||5)),s;for(let a=0;a<Math.ceil(900/n);a+=1){await e.sleepFn(n*1e3);let c=await e.fetchFn(`${t.issuer}/api/accounts/deviceauth/token`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({device_auth_id:r.device_auth_id,user_code:r.user_code})});if(c.ok){s=await R(c,"Codex device authorization");break}if(![403,404].includes(c.status))throw new Error(`Codex device authorization failed (HTTP ${c.status})`)}if(!s)throw new Error("Codex device authorization timed out");let i=await e.fetchFn(t.tokenUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded"},body:ie({grant_type:"authorization_code",code:s.authorization_code,redirect_uri:`${t.issuer}/deviceauth/callback`,client_id:t.clientId,code_verifier:s.code_verifier})});return ae(await R(i,"Codex OAuth token exchange"),e)}function Y(e){let t=new URL(String(e)),r=t.hostname.toLowerCase();if(t.protocol!=="https:"||r!=="x.ai"&&!r.endsWith(".x.ai"))throw new Error("xAI OAuth discovery returned an untrusted endpoint");return t.toString()}async function _t(e){let t=C["xai-oauth"],r=await R(await e.fetchFn(t.discoveryUrl,{headers:{accept:"application/json"}}),"xAI OAuth discovery");Y(r.authorization_endpoint);let o=Y(r.token_endpoint),n=await R(await e.fetchFn(t.deviceUrl,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},body:ie({client_id:t.clientId,scope:t.scope})}),"xAI device authorization");if(!n.device_code||!n.user_code||!n.verification_uri)throw new Error("xAI device authorization returned incomplete data");let s=Y(n.verification_uri_complete||n.verification_uri);e.output(`Open: ${s}`),e.output(`Code: ${n.user_code}`),e.openFn(s);let i=Math.max(1,Number(n.interval||5)),a=Math.ceil(Math.max(1,Number(n.expires_in||600))/i);for(let c=0;c<a;c+=1){let d=await e.fetchFn(o,{method:"POST",headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json"},body:ie({grant_type:"urn:ietf:params:oauth:grant-type:device_code",client_id:t.clientId,device_code:n.device_code})});if(d.ok){let _=await R(d,"xAI OAuth token exchange");return ae(_,{...e,discovery:{authorization_endpoint:Y(r.authorization_endpoint),token_endpoint:o}})}let p="";try{p=String((await d.json())?.error||"")}catch{}if(p==="slow_down")await e.sleepFn((i+1)*1e3);else if(p==="authorization_pending")await e.sleepFn(i*1e3);else throw new Error(`xAI OAuth token exchange failed (HTTP ${d.status}${p?`, ${p}`:""})`)}throw new Error("xAI device authorization timed out")}async function Te(e,t={}){let r=T(e),o={fetchFn:t.fetchFn||globalThis.fetch,inputFn:t.inputFn,sleepFn:t.sleepFn||(n=>new Promise(s=>setTimeout(s,n))),openFn:t.openFn||mt,output:t.output||(n=>process.stdout.write(`${n}
7
+ `)),now:t.now,pkce:t.pkce};return r==="anthropic-oauth"?wt(o):r==="openai-codex"?yt(o):_t(o)}import X from"node:fs";import ce from"node:path";var kt=new Set(["openrouter","openai","anthropic","xai","deepseek","gemini","kimi","mistral","nous","custom","anthropic-oauth","openai-codex","xai-oauth"]);function J(e){return String(e||"").trim()||void 0}function vt(e,{required:t=!1}={}){let r=J(e)?.toLowerCase();if(!r){if(t)throw new Error("model provider is required");return}if(!kt.has(r))throw new Error(`unsupported provider: ${r}`);return r}function St(e,{required:t=!1}={}){let r=J(e);if(!r){if(t)throw new Error("model is required");return}if(r.includes("..")||r.startsWith("/")||!/^[a-zA-Z0-9._:/-]{1,200}$/.test(r))throw new Error("invalid model id");return r}function Et(e){let t=J(e);if(!t||t.length>2048)throw new Error("invalid custom base URL");let r;try{r=new URL(t)}catch{throw new Error("invalid custom base URL")}let o=r.hostname.toLowerCase().replace(/^\[|\]$/g,""),n=o==="localhost"||o==="127.0.0.1"||o==="::1";if(r.protocol!=="https:"&&!(r.protocol==="http:"&&n)||r.username||r.password||r.search||r.hash)throw new Error("custom base URL must use HTTPS or loopback HTTP without credentials, query, or fragment");return r.toString().replace(/\/+$/,"")}function G({provider:e,model:t,baseUrl:r}={},{requireModel:o=!1}={}){let n=vt(e),s=St(t,{required:o});if(n==="custom")return{provider:n,...s?{model:s}:{},baseUrl:Et(r)};if(J(r))throw new Error("baseUrl is only supported for the custom provider");return{...n?{provider:n}:{},...s?{model:s}:{}}}var At=new Set(["auto","standalone","hermes","remote","arch"]);function xt(){return ce.join(v(),"model.json")}function U(e){return String(e||"").trim()||void 0}function Ot(e={}){let t=U(e.backend)?.toLowerCase()||"auto",r=G({provider:e.provider,model:e.model,baseUrl:e.baseUrl},{requireModel:t==="standalone"}),o=U(e.apiKeyEnv),n=Number.parseInt(String(e.contextLength||""),10),s=U(e.reasoningEffort),i=U(e.computeHost||e.remoteHost),a=U(e.computeUser||e.remoteUser),c=U(e.computePath||e.remotePath);if(!At.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(o&&!/^[A-Z][A-Z0-9_]*$/.test(o))throw new Error("api key env must be an uppercase environment variable name");if(t==="remote"&&!i)throw new Error("remote backend requires computeHost");return{backend:t,...r,...o?{apiKeyEnv:o}:{},...Number.isFinite(n)&&n>0?{contextLength:n}:{},...s?{reasoningEffort:s}:{},...i?{computeHost:i}:{},...a?{computeUser:a}:{},...c?{computePath:c}:{}}}function Re(e){let t=Ot(e),r=xt();x(ce.dirname(r)),process.platform!=="win32"&&X.chmodSync(ce.dirname(r),448);let o=`${r}.${process.pid}.tmp`;return X.writeFileSync(o,`${JSON.stringify(t,null,2)}
8
8
  `,{mode:384}),X.renameSync(o,r),process.platform!=="win32"&&X.chmodSync(r,384),t}var Pe=Object.freeze({openrouter:{model:"openrouter/auto"},openai:{model:"gpt-4.1-mini"},anthropic:{model:"claude-sonnet-4-6"},xai:{model:"grok-4.6"},deepseek:{model:"deepseek-chat"},gemini:{model:"gemini-2.5-flash"},kimi:{model:"kimi-k3"},mistral:{model:"mistral-large-latest"},nous:{model:"moonshotai/kimi-k3"},custom:{model:""}});function ue(e,t){let r=e.indexOf(t);return r>=0&&e[r+1]?e[r+1]:""}async function bt(){let e="";for await(let t of process.stdin)e+=t;return e.trim()}function Tt(e="API key: "){if(!process.stdin.isTTY||!process.stdin.setRawMode)throw new Error("non-interactive API-key input requires --stdin");return process.stdout.write(e),new Promise((t,r)=>{let o="",n=()=>{process.stdin.off("data",s),process.stdin.setRawMode(!1),process.stdin.pause(),process.stdout.write(`
9
9
  `)},s=i=>{let a=String(i);for(let c of a){if(c==="\r"||c===`
10
10
  `){n(),t(o.trim());return}if(c===""){n(),r(new Error("cancelled"));return}c==="\x7F"||c==="\b"?o=o.slice(0,-1):o+=c}};process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.on("data",s)})}function le(e,t,{baseUrl:r=""}={}){if(e==="custom"&&!String(r||"").trim())throw new Error("custom provider requires --base-url");return{backend:"standalone",...G({provider:e,model:t,baseUrl:r},{requireModel:!0})}}function Le(e,t,r={}){return Re(le(e,t,r))}function Rt(e){process.stdout.write(`storage: ${e.storage}
@@ -17,11 +17,11 @@ import{spawnSync as Lt}from"node:child_process";import{stdin as b,stdout as Ie}f
17
17
  `),0}if(r==="api-key"){let n=String(t.find(c=>!c.startsWith("-"))||"").trim().toLowerCase();if(!n)throw new Error("usage: oracle auth api-key PROVIDER [--stdin]");if(!Object.hasOwn(Pe,n))throw new Error(`unsupported API-key provider: ${n}`);let s=ue(t,"--model")||Pe[n].model,i=ue(t,"--base-url");le(n,s,{baseUrl:i});let a=t.includes("--stdin")?await bt():await Tt();return await o.withLock(async()=>{let c=o.getApiKey(n);o.setApiKey(n,a);try{Le(n,s,{baseUrl:i})}catch(d){throw c?o.setApiKey(n,c):o.removeApiKey(n),d}}),process.stdout.write(`${n}: API key configured in ${o.storage}
18
18
  `),0}if(r==="logout"){let n=String(t.find(a=>!a.startsWith("-"))||"").trim().toLowerCase();if(!n)throw new Error("usage: oracle auth logout PROVIDER");let s=!1;try{s=o.remove(T(n))}catch{}let i=o.removeApiKey(n);if(!s&&!i)throw new Error(`${n}: no local credential found`);return process.stdout.write(`${n}: local credential removed
19
19
  `),0}throw new Error(`unknown auth action: ${r}`)}catch(n){return process.stderr.write(`oracle auth: ${n.message}
20
- `),1}}};var kr=Object.freeze([["#EAF7FF"," \u2584\u2584\u2584\u2588\u2588\u2588\u2588\u2584\u2584\u2584"],["#D8F2FF"," \u2584\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584"],["#B8F0FF"," \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#ACDEEF","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#A5D9EB","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#9FCBDD","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#91C2D7","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#7FA9BE"," \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#60717F"," \u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580"],["#4A5A66"," \u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2580\u2580\u2580"]]);var vr=Object.freeze([" \u2588\u2588\u2588\u2593\u2593"," \u2588\u2588\u2588\u2588\u2588\u2593\u2593\u2592","\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2593\u2592\u2592"," \u2593\u2593\u2593\u2593\u2592\u2592\u2592\u2591"," \u2592\u2592\u2592\u2591\u2591\u2591"]);var Q=Object.freeze([[" \u2588\u2588\u2588\u2593\u2593"," \u2588\u2588\u2588\u2588\u2588\u2593\u2593\u2592","\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2593\u2592\u2592"," \u2593\u2593\u2593\u2593\u2592\u2592\u2592\u2591"," \u2592\u2592\u2592\u2591\u2591\u2591"],[" \u2593\u2588\u2588\u2588\u2593"," \u2592\u2593\u2593\u2588\u2588\u2588\u2588\u2588","\u2592\u2592\u2593\u2593\u2588\u2588\u2588\u2588\u2588\u2588"," \u2591\u2592\u2592\u2593\u2593\u2593\u2593\u2593"," \u2591\u2591\u2592\u2592\u2592\u2592"],[" \u2593\u2593\u2588\u2588\u2588"," \u2592\u2593\u2593\u2593\u2588\u2588\u2588\u2588","\u2592\u2592\u2593\u2593\u2593\u2588\u2588\u2588\u2588\u2588"," \u2591\u2592\u2592\u2592\u2593\u2593\u2593\u2593"," \u2591\u2591\u2591\u2592\u2592\u2592"],[" \u2591\u2592\u2592\u2593\u2593"," \u2591\u2592\u2592\u2593\u2593\u2593\u2593\u2593","\u2591\u2591\u2592\u2592\u2593\u2593\u2588\u2588\u2588\u2588"," \u2593\u2593\u2593\u2588\u2588\u2588\u2588\u2588\u2588"," \u2588\u2588\u2588\u2588\u2588\u2593"]]),Sr=Object.freeze([["#EAF7FF"," \u2588\u2588\u2588\u2588"],["#D8F2FF"," \u2591\u2591\u2588\u2588\u2588"],["#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"],["#ACDEEF"," \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"],["#A5D9EB","\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"],["#9FCBDD","\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"],["#91C2D7","\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"],["#60717F"," \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"]]);var pe=Object.freeze([{alias:"claude",label:"Claude",hint:"Anthropic subscription"},{alias:"codex",label:"Codex",hint:"OpenAI subscription"},{alias:"grok",label:"Grok",hint:"xAI subscription"}]),fe=Object.freeze([{id:"openrouter",label:"OpenRouter"},{id:"openai",label:"OpenAI"},{id:"anthropic",label:"Anthropic"},{id:"xai",label:"xAI"},{id:"deepseek",label:"DeepSeek"},{id:"gemini",label:"Gemini"},{id:"kimi",label:"Kimi"},{id:"mistral",label:"Mistral"},{id:"nous",label:"Nous"}]),he=Object.freeze([...pe.map((e,t)=>({n:t+1,id:e.alias,label:e.label,kind:"oauth",hint:e.hint})),...fe.map((e,t)=>({n:pe.length+t+1,id:e.id,label:e.label,kind:"api-key",hint:"API key"})),{n:pe.length+fe.length+1,id:"custom",label:"Custom",kind:"api-key",hint:"OpenAI-compatible"}]);function It(e){let t=String(e||"").trim().toLowerCase();if(!t||t==="skip")return{skip:!0};let r=he.find(o=>String(o.n)===t||o.id===t);return r||{unknown:!0,choice:t}}function Ce(e="sign in",t=0){let r=Q[t]||Q[0];return["",`${r[0]} oracle`,`${r[1]} ${e}`,r[2],r[3],r[4],""].join(`
20
+ `),1}}};var _r=Object.freeze([["#EAF7FF"," \u2584\u2584\u2584\u2588\u2588\u2588\u2588\u2584\u2584\u2584"],["#D8F2FF"," \u2584\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584"],["#B8F0FF"," \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#ACDEEF","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#A5D9EB","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#9FCBDD","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#91C2D7","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#7FA9BE"," \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"],["#60717F"," \u2580\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2580"],["#4A5A66"," \u2580\u2580\u2580\u2588\u2588\u2588\u2588\u2580\u2580\u2580"]]);var kr=Object.freeze([" \u2588\u2588\u2588\u2593\u2593"," \u2588\u2588\u2588\u2588\u2588\u2593\u2593\u2592","\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2593\u2592\u2592"," \u2593\u2593\u2593\u2593\u2592\u2592\u2592\u2591"," \u2592\u2592\u2592\u2591\u2591\u2591"]);var Q=Object.freeze([[" \u2588\u2588\u2588\u2593\u2593"," \u2588\u2588\u2588\u2588\u2588\u2593\u2593\u2592","\u2588\u2588\u2588\u2588\u2588\u2588\u2593\u2593\u2592\u2592"," \u2593\u2593\u2593\u2593\u2592\u2592\u2592\u2591"," \u2592\u2592\u2592\u2591\u2591\u2591"],[" \u2593\u2588\u2588\u2588\u2593"," \u2592\u2593\u2593\u2588\u2588\u2588\u2588\u2588","\u2592\u2592\u2593\u2593\u2588\u2588\u2588\u2588\u2588\u2588"," \u2591\u2592\u2592\u2593\u2593\u2593\u2593\u2593"," \u2591\u2591\u2592\u2592\u2592\u2592"],[" \u2593\u2593\u2588\u2588\u2588"," \u2592\u2593\u2593\u2593\u2588\u2588\u2588\u2588","\u2592\u2592\u2593\u2593\u2593\u2588\u2588\u2588\u2588\u2588"," \u2591\u2592\u2592\u2592\u2593\u2593\u2593\u2593"," \u2591\u2591\u2591\u2592\u2592\u2592"],[" \u2591\u2592\u2592\u2593\u2593"," \u2591\u2592\u2592\u2593\u2593\u2593\u2593\u2593","\u2591\u2591\u2592\u2592\u2593\u2593\u2588\u2588\u2588\u2588"," \u2593\u2593\u2593\u2588\u2588\u2588\u2588\u2588\u2588"," \u2588\u2588\u2588\u2588\u2588\u2593"]]),vr=Object.freeze([["#EAF7FF"," __ "],["#D8F2FF"," ____ _________ ______/ /__ "],["#B8F0FF"," / __ \\/ ___/ __ `/ ___/ / _ \\"],["#ACDEEF","/ /_/ / / / /_/ / /__/ / __/"],["#91C2D7","\\____/_/ \\__,_/\\___/_/\\___/ "]]);var pe=Object.freeze([{alias:"claude",label:"Claude",hint:"Anthropic subscription"},{alias:"codex",label:"Codex",hint:"OpenAI subscription"},{alias:"grok",label:"Grok",hint:"xAI subscription"}]),fe=Object.freeze([{id:"openrouter",label:"OpenRouter"},{id:"openai",label:"OpenAI"},{id:"anthropic",label:"Anthropic"},{id:"xai",label:"xAI"},{id:"deepseek",label:"DeepSeek"},{id:"gemini",label:"Gemini"},{id:"kimi",label:"Kimi"},{id:"mistral",label:"Mistral"},{id:"nous",label:"Nous"}]),he=Object.freeze([...pe.map((e,t)=>({n:t+1,id:e.alias,label:e.label,kind:"oauth",hint:e.hint})),...fe.map((e,t)=>({n:pe.length+t+1,id:e.id,label:e.label,kind:"api-key",hint:"API key"})),{n:pe.length+fe.length+1,id:"custom",label:"Custom",kind:"api-key",hint:"OpenAI-compatible"}]);function It(e){let t=String(e||"").trim().toLowerCase();if(!t||t==="skip")return{skip:!0};let r=he.find(o=>String(o.n)===t||o.id===t);return r||{unknown:!0,choice:t}}function Ce(e="sign in",t=0){let r=Q[t]||Q[0];return["",`${r[0]} oracle`,`${r[1]} ${e}`,r[2],r[3],r[4],""].join(`
21
21
  `)}async function $t(e){if(e.isTTY!==!0||process.env.NODE_TEST_CONTEXT||process.env.ORACLE_INSTALL_PLAIN==="1")return;let t=r=>new Promise(o=>setTimeout(o,r));for(let r=0;r<Q.length;r+=1)r>0&&e.write("\x1B[7A"),e.write(`${Ce("sign in",r)}
22
22
  `),await t(90)}async function $r({stdin:e=process.stdin,stdout:t=process.stdout,readLine:r,runAuth:o=n=>Z.run({argv:n})}={}){if(await $t(t),t.write(`${K()}
23
23
  `),t.write(`number or name \xB7 enter skips
24
- `),e.isTTY!==!0||t.isTTY!==!0)return{skipped:!0,reason:"non-tty"};t.write("> ");let n=r?await r():await new Promise(c=>{let d="",p=k=>{d+=String(k),(d.includes(`
24
+ `),e.isTTY!==!0||t.isTTY!==!0)return{skipped:!0,reason:"non-tty"};t.write("> ");let n=r?await r():await new Promise(c=>{let d="",p=_=>{d+=String(_),(d.includes(`
25
25
  `)||d.includes("\r"))&&(e.off("data",p),c(d.trim()))};e.on("data",p)}),s=It(n);if(s.skip)return{skipped:!0,reason:"skipped"};if(s.unknown)return t.write(`unknown choice '${s.choice}'
26
26
  `),{skipped:!0,reason:"unknown"};let i=s.kind==="oauth"?["login",s.id]:["api-key",s.id],a=await o(i);return{skipped:!1,choice:s.id,code:a}}function K(e=D().status()){let t=[Ce("sign in"),"sign in with a subscription",""];for(let r of he.filter(o=>o.kind==="oauth")){let o=F(r.id),n=e.providers?.[o.id]?.loggedIn===!0;t.push(` ${String(r.n).padStart(2)} ${r.label.padEnd(12)} ${n?"connected":"OAuth"}`)}t.push("","or use an API key","");for(let r of he.filter(o=>o.kind==="api-key")){let o=r.id==="custom"?!1:e.apiKeys?.[r.id]?.configured===!0;t.push(` ${String(r.n).padStart(2)} ${r.label.padEnd(12)} ${o?"configured":"not configured"}`)}return t.push("","Your key stays on this machine. Nothing is uploaded by Oracle.",""),t.join(`
27
27
  `)}function de(){return["oracle setup, configure standalone OAuth, messaging, and the local agent surface",""," oracle setup menu + platform status"," oracle setup status same, machine-friendly with --json"," oracle setup model show Claude, Codex, Grok, OpenRouter, DeepSeek, Nous, ..."," oracle setup model claude connect Anthropic OAuth + select standalone"," oracle setup model codex connect OpenAI OAuth + select standalone"," oracle setup model grok connect xAI OAuth + select standalone"," oracle setup model deepseek securely add a provider API key"," oracle setup model kimi securely add a Kimi API key"," oracle setup messaging open hermes gateway setup wizard"," oracle setup telegram set TELEGRAM_BOT_TOKEN for profile"," oracle setup discord set DISCORD_BOT_TOKEN for profile"," oracle setup slack set slack tokens"," oracle setup <platform> any supported hermes platform"," oracle setup gateway [status|restart|start|stop]"," oracle setup profile [name] default: oracle","","chat:"," /setup"," /setup telegram"," /setup status","","model credentials stay in the OS keychain or private ~/.config/oracle storage.","messaging tokens stay local in ~/.hermes/profiles/<profile>/.env","oracle never prints secrets."].join(`
@@ -39,7 +39,7 @@ Detect: oracle harness detect
39
39
  `),1;s.push(d)}let i=n.token||s[0]||"";if(!i&&!process.stdin.isTTY&&(i=await readStdinSecret()),!i)try{i=await $e(`${o.key} bot token`)}catch(c){if(c?.code==="NO_TTY")return process.stderr.write(`oracle setup ${o.key}: pipe the token on stdin (echo "$TOKEN" | oracle setup ${o.key}) or pass --token <value>
40
40
  `),1;throw c}if(!i)return process.stderr.write(`aborted: empty token
41
41
  `),1;let a={};if(n.allowedUsers&&(o.key==="telegram"&&(a.TELEGRAM_ALLOWED_USERS=n.allowedUsers),o.key==="discord"&&(a.DISCORD_ALLOWED_USERS=n.allowedUsers),o.key==="slack"&&(a.SLACK_ALLOWED_USERS=n.allowedUsers)),n.appToken&&o.key==="slack"&&(a.SLACK_APP_TOKEN=n.appToken),o.key==="slack"&&!a.SLACK_APP_TOKEN){let c=n.appToken||s[1]||"";if(!c&&process.stdin.isTTY&&(c=await $e("slack app token (xapp-...)")),!c)return process.stderr.write(`slack needs bot token + app token
42
- `),1;a.SLACK_APP_TOKEN=c}try{let c=Ee(e,o.key,i,a);return V({lastPlatform:o.key,profile:e,ready:!0}),process.stdout.write(`saved ${o.key} credentials for profile '${e}'
42
+ `),1;a.SLACK_APP_TOKEN=c}try{let c=Se(e,o.key,i,a);return V({lastPlatform:o.key,profile:e,ready:!0}),process.stdout.write(`saved ${o.key} credentials for profile '${e}'
43
43
  path: ${c.path}
44
44
  next: oracle setup gateway restart
45
45
  `),0}catch(c){return process.stderr.write(`oracle setup: ${c.message}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oracle-agent/oracle",
3
- "version": "0.28.17",
3
+ "version": "0.28.19",
4
4
  "description": "Oracle: standalone multichain agent control plane with an optional encrypted, loopback-only self-hosted signer.",
5
5
  "license": "BUSL-1.1",
6
6
  "type": "module",