| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_CODEXLOGIN_UI_HTML_H |
| 3 | #define SX_CODEXLOGIN_UI_HTML_H |
| 4 | |
| 5 | static const char *UI_HTML = |
| 6 | "<!DOCTYPE html>\n" |
| 7 | "<html lang=\"en\"><head><meta charset=\"utf-8\">\n" |
| 8 | "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" |
| 9 | "<title>codex</title>\n" |
| 10 | "\001\n" |
| 11 | "<style>\n" |
| 12 | "*{box-sizing:border-box}\n" |
| 13 | "html,body{margin:0;min-height:100%}\n" |
| 14 | "body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;\n" |
| 15 | " line-height:1.5;-webkit-font-smoothing:antialiased}\n" |
| 16 | "#app{max-width:840px;margin:0 auto;padding:16px 16px 40px}\n" |
| 17 | ".hd{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-bottom:14px}\n" |
| 18 | ".hd .grow{flex:1 1 auto;min-width:0}\n" |
| 19 | ".hd h1{margin:0;font-size:18px;font-weight:650;letter-spacing:-.01em}\n" |
| 20 | ".hd .sub{font-size:11.5px;color:var(--text-2);margin-top:2px;white-space:nowrap;\n" |
| 21 | " overflow:hidden;text-overflow:ellipsis}\n" |
| 22 | ".pill{display:inline-flex;align-items:center;gap:6px;font-size:11.5px;font-weight:650;\n" |
| 23 | " padding:4px 10px;border-radius:999px;background:var(--surface-2);color:var(--text-2);\n" |
| 24 | " border:1px solid var(--line);white-space:nowrap}\n" |
| 25 | ".pill .dot{width:7px;height:7px;border-radius:50%;background:var(--gray);flex:0 0 auto}\n" |
| 26 | ".pill.ok{color:var(--green);border-color:rgba(48,209,88,.35)}\n" |
| 27 | ".pill.ok .dot{background:var(--green);box-shadow:0 0 0 3px rgba(48,209,88,.15)}\n" |
| 28 | ".pill.warn{color:var(--orange);border-color:rgba(255,159,10,.35)}\n" |
| 29 | ".pill.warn .dot{background:var(--orange)}\n" |
| 30 | ".pill.off .dot{background:var(--gray)}\n" |
| 31 | ".card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px;\n" |
| 32 | " padding:16px;margin-bottom:12px}\n" |
| 33 | ".card h2{margin:0 0 4px;font-size:13px;font-weight:700;letter-spacing:.08em;\n" |
| 34 | " text-transform:uppercase;color:var(--text-2)}\n" |
| 35 | ".card .lead{margin:0 0 12px;font-size:12.5px;color:var(--text-2)}\n" |
| 36 | ".row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}\n" |
| 37 | ".btn{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:7px 16px;\n" |
| 38 | " font-weight:600;font-size:13px;cursor:pointer;font-family:inherit;\n" |
| 39 | " transition:transform .12s var(--ease),opacity .12s}\n" |
| 40 | ".btn:active{transform:scale(.98)}\n" |
| 41 | ".btn:disabled{opacity:.5;cursor:default}\n" |
| 42 | ".btn.ghost{background:var(--surface-2);color:var(--text);border:1px solid var(--line)}\n" |
| 43 | ".btn.ghost:hover{background:var(--surface-hover);border-color:var(--line-2)}\n" |
| 44 | ".btn.danger{background:transparent;color:var(--red);border:1px solid rgba(255,69,58,.35)}\n" |
| 45 | "a.btn{display:inline-flex;align-items:center;gap:6px;text-decoration:none}\n" |
| 46 | ".kv{display:grid;grid-template-columns:132px minmax(0,1fr);gap:6px 12px;font-size:13px}\n" |
| 47 | ".kv .k{color:var(--text-2);font-size:12px}\n" |
| 48 | ".kv .v{font-family:var(--mono);font-size:12px;word-break:break-all}\n" |
| 49 | ".kv .v.plain{font-family:var(--font);font-size:13px}\n" |
| 50 | ".step{display:none}\n" |
| 51 | ".step.on{display:block}\n" |
| 52 | ".hint{margin:10px 0 0;font-size:12px;color:var(--text-2)}\n" |
| 53 | ".note{font-size:12.5px;margin-top:10px;display:none}\n" |
| 54 | ".note.show{display:block}\n" |
| 55 | ".note.err{color:var(--red)}\n" |
| 56 | ".note.ok{color:var(--green)}\n" |
| 57 | ".count{font-size:34px;font-weight:700;letter-spacing:-.02em;line-height:1.1}\n" |
| 58 | ".count small{font-size:13px;font-weight:600;color:var(--text-2);letter-spacing:0}\n" |
| 59 | ".bar{height:6px;border-radius:999px;background:var(--surface-2);overflow:hidden;margin-top:10px}\n" |
| 60 | ".bar .fill{display:block;height:100%;background:var(--green);border-radius:999px;\n" |
| 61 | " transition:width .3s var(--ease)}\n" |
| 62 | ".bar.warn .fill{background:var(--orange)}\n" |
| 63 | ".bar.err .fill{background:var(--red)}\n" |
| 64 | ".codebox{margin:12px 0 0;padding:16px;border-radius:12px;background:var(--code-bg);\n" |
| 65 | " border:1px solid var(--line);text-align:center}\n" |
| 66 | ".codebox .code{font-family:var(--mono);font-size:30px;font-weight:700;letter-spacing:.14em;\n" |
| 67 | " color:var(--text);margin-bottom:10px;word-break:break-all}\n" |
| 68 | ".codebox .code-empty{font-family:var(--mono);font-size:18px;color:var(--text-2);\n" |
| 69 | " letter-spacing:.08em}\n" |
| 70 | ".authurl{font-family:var(--mono);font-size:11.5px;color:var(--text-2);word-break:break-all;\n" |
| 71 | " background:var(--code-bg);border:1px solid var(--line);border-radius:10px;\n" |
| 72 | " padding:10px;margin-top:10px;max-height:120px;overflow:auto}\n" |
| 73 | ".pollbar{margin:12px 0 0;height:3px;border-radius:2px;background:var(--surface-2);\n" |
| 74 | " overflow:hidden}\n" |
| 75 | ".pollbar i{display:block;height:100%;width:0;background:var(--blue);\n" |
| 76 | " animation:pollslide 2s linear infinite}\n" |
| 77 | "@keyframes pollslide{0%{width:0}50%{width:100%}100%{width:0}}\n" |
| 78 | ".polllbl{font-size:11.5px;color:var(--text-2);margin:8px 0 0;display:flex;align-items:center;gap:6px}\n" |
| 79 | ".polllbl .spin{width:10px;height:10px;border-radius:50%;border:2px solid var(--line-2);\n" |
| 80 | " border-top-color:var(--blue);animation:spin 1s linear infinite;display:inline-block}\n" |
| 81 | "@keyframes spin{to{transform:rotate(360deg)}}\n" |
| 82 | ".acct{display:flex;align-items:center;gap:10px;padding:8px 0;border-top:1px solid var(--line);\n" |
| 83 | " font-size:13px;flex-wrap:wrap}\n" |
| 84 | ".acct:first-of-type{border-top:0}\n" |
| 85 | ".acct .nm{font-family:var(--mono);font-size:12px;flex:1 1 120px;min-width:0;\n" |
| 86 | " overflow:hidden;text-overflow:ellipsis}\n" |
| 87 | ".acct .tag{font-size:11px;color:var(--text-2)}\n" |
| 88 | ".acct .tag.ok{color:var(--green)}\n" |
| 89 | ".acct .tag.warn{color:var(--orange)}\n" |
| 90 | ".empty{padding:10px 0;color:var(--text-2);font-size:12.5px}\n" |
| 91 | ".toast{position:fixed;left:50%;bottom:18px;transform:translate(-50%,14px);opacity:0;\n" |
| 92 | " pointer-events:none;background:var(--modal-bg);border:1px solid var(--line-2);\n" |
| 93 | " color:var(--text);border-radius:999px;padding:8px 16px;font-size:12.5px;\n" |
| 94 | " box-shadow:var(--shadow-lg);transition:opacity .18s var(--ease),transform .18s var(--ease);\n" |
| 95 | " z-index:9;max-width:calc(100vw - 32px)}\n" |
| 96 | ".toast.show{opacity:1;transform:translate(-50%,0)}\n" |
| 97 | "#themeToggle{background:var(--surface-2);border:1px solid var(--line);color:var(--text);\n" |
| 98 | " border-radius:980px;padding:5px 12px;font-size:12px;font-weight:600;cursor:pointer;\n" |
| 99 | " font-family:inherit}\n" |
| 100 | "footer{display:flex;gap:10px;align-items:center;color:var(--text-2);font-size:11.5px;\n" |
| 101 | " margin-top:8px;flex-wrap:wrap}\n" |
| 102 | "@media (max-width:520px){\n" |
| 103 | " #app{padding:12px 12px 32px}\n" |
| 104 | " .kv{grid-template-columns:1fr;gap:2px 0}\n" |
| 105 | " .kv .k{margin-top:8px}\n" |
| 106 | " .card{padding:13px;border-radius:12px}\n" |
| 107 | " .count{font-size:28px}\n" |
| 108 | " .codebox .code{font-size:22px;letter-spacing:.1em}\n" |
| 109 | "}\n" |
| 110 | "</style>\n" |
| 111 | "</head>\n" |
| 112 | "<body>\n" |
| 113 | "<div id=\"app\">\n" |
| 114 | " <div class=\"hd\">\n" |
| 115 | " <div class=\"grow\">\n" |
| 116 | " <h1>OpenAI Codex</h1>\n" |
| 117 | " <div class=\"sub\" id=\"sub\">Device code login on this node</div>\n" |
| 118 | " </div>\n" |
| 119 | " <span class=\"pill off\" id=\"pill\"><span class=\"dot\"></span><span id=\"pillText\">Checking</span></span>\n" |
| 120 | " <button id=\"themeToggle\" class=\"embed-hide\" type=\"button\">Theme</button>\n" |
| 121 | " </div>\n" |
| 122 | "\n" |
| 123 | " <div class=\"card\">\n" |
| 124 | " <h2>Session</h2>\n" |
| 125 | " <p class=\"lead\" id=\"sessionLead\">Reading the local Codex credentials.</p>\n" |
| 126 | " <div class=\"count\" id=\"count\">-</div>\n" |
| 127 | " <div class=\"bar\" id=\"bar\"><span class=\"fill\" id=\"fill\" style=\"width:0%\"></span></div>\n" |
| 128 | " <div class=\"kv\" id=\"session\" style=\"margin-top:14px\"></div>\n" |
| 129 | " <div class=\"row\" style=\"margin-top:14px\">\n" |
| 130 | " <button class=\"btn ghost\" id=\"btnRefresh\" type=\"button\">Refresh Token Now</button>\n" |
| 131 | " <button class=\"btn ghost\" id=\"btnStartLogin\" type=\"button\">Start Codex Login</button>\n" |
| 132 | " <button class=\"btn ghost\" id=\"btnRelogin\" type=\"button\" hidden>Re-login (replace)</button>\n" |
| 133 | " <button class=\"btn ghost\" id=\"btnReload\" type=\"button\">Reload</button>\n" |
| 134 | " </div>\n" |
| 135 | " <div class=\"note\" id=\"sessionNote\"></div>\n" |
| 136 | " </div>\n" |
| 137 | "\n" |
| 138 | " <div class=\"card\">\n" |
| 139 | " <h2>Device flow</h2>\n" |
| 140 | " <p class=\"lead\">Codex signs in with a one-time user code. Copy it, open the link, approve,\n" |
| 141 | " and this panel updates itself.</p>\n" |
| 142 | "\n" |
| 143 | " <div class=\"step on\" id=\"stepIdle\">\n" |
| 144 | " <div class=\"empty\">No login in progress. Press <b>Start Codex Login</b> above to begin.</div>\n" |
| 145 | " </div>\n" |
| 146 | "\n" |
| 147 | " <div class=\"step\" id=\"stepActive\">\n" |
| 148 | " <div class=\"codebox\">\n" |
| 149 | " <div class=\"code\" id=\"userCode\">--</div>\n" |
| 150 | " <div class=\"row\" style=\"justify-content:center\">\n" |
| 151 | " <button class=\"btn\" id=\"btnCopyOpen\" type=\"button\">Copy Code & Open OpenAI</button>\n" |
| 152 | " </div>\n" |
| 153 | " </div>\n" |
| 154 | " <div class=\"authurl\" id=\"verifyUrl\"></div>\n" |
| 155 | " <div class=\"pollbar\"><i></i></div>\n" |
| 156 | " <div class=\"polllbl\"><span class=\"spin\"></span><span id=\"pollLabel\">Waiting for authorization in browser...</span></div>\n" |
| 157 | " <div class=\"row\" style=\"margin-top:12px\">\n" |
| 158 | " <button class=\"btn danger\" id=\"btnCancel\" type=\"button\">Cancel</button>\n" |
| 159 | " </div>\n" |
| 160 | " <div class=\"note\" id=\"flowNote\"></div>\n" |
| 161 | " </div>\n" |
| 162 | " </div>\n" |
| 163 | "\n" |
| 164 | " <div class=\"card\">\n" |
| 165 | " <h2>Named accounts</h2>\n" |
| 166 | " <p class=\"lead\">Every account file in the local accounts directory.</p>\n" |
| 167 | " <div id=\"accounts\"><div class=\"empty\">No named accounts.</div></div>\n" |
| 168 | " </div>\n" |
| 169 | "\n" |
| 170 | " <footer>\n" |
| 171 | " <span id=\"footInfo\">plugin_codex_login</span>\n" |
| 172 | " · <a href=\"https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-codex-login\">source</a>\n" |
| 173 | " </footer>\n" |
| 174 | "</div>\n" |
| 175 | "\n" |
| 176 | "<div class=\"toast\" id=\"toast\"></div>\n" |
| 177 | "\n" |
| 178 | "<script>\n" |
| 179 | "(function(){\n" |
| 180 | "var q=new URLSearchParams(location.search);\n" |
| 181 | "var node=q.get('node')||'';\n" |
| 182 | "var sid=q.get('id')||'';\n" |
| 183 | "var acct=q.get('account')||'';\n" |
| 184 | "var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||\n" |
| 185 | " localStorage.getItem('bot_active_pwd')||'';\n" |
| 186 | "\n" |
| 187 | "/* Two call routes. Getting this wrong is the most common plugin bug:\n" |
| 188 | " * page served through the hub (bot.scorpiox.net/plugins?plugin=...&node=..)\n" |
| 189 | " * -> call the hub proxy back: /plugins?plugin=plugin_codex_login&action=..\n" |
| 190 | " * opened directly on the node\n" |
| 191 | " * -> the plugin itself is the route: /plugin_codex_login?action=..\n" |
| 192 | " * Calling /plugins?plugin= on the node returns the discovery list, not us. */\n" |
| 193 | "var HUB=q.get('plugin')||'';\n" |
| 194 | "function url(action,extra){\n" |
| 195 | " return (HUB?'/plugins?plugin='+encodeURIComponent(HUB)+'&action=':'/plugin_codex_login?action=')+\n" |
| 196 | " encodeURIComponent(action)+\n" |
| 197 | " (extra?('&'+extra):'')+\n" |
| 198 | " (acct?'&account='+encodeURIComponent(acct):'')+\n" |
| 199 | " (node?'&node='+encodeURIComponent(node):'')+\n" |
| 200 | " (sid?'&id='+encodeURIComponent(sid):'')+\n" |
| 201 | " (pwd?'&pwd='+encodeURIComponent(pwd):'');\n" |
| 202 | "}\n" |
| 203 | "function hdr(){\n" |
| 204 | " var h={};\n" |
| 205 | " if(pwd)h['X-Bot-Password']=pwd;\n" |
| 206 | " return h;\n" |
| 207 | "}\n" |
| 208 | "function api(action,extra){\n" |
| 209 | " return fetch(url(action,extra),{headers:hdr()}).then(function(r){\n" |
| 210 | " return r.json().catch(function(){return {ok:false,error:'bad response'};});\n" |
| 211 | " });\n" |
| 212 | "}\n" |
| 213 | "\n" |
| 214 | "var $=function(id){return document.getElementById(id);};\n" |
| 215 | "function toast(msg){\n" |
| 216 | " var t=$('toast');t.textContent=msg;t.classList.add('show');\n" |
| 217 | " clearTimeout(t._t);t._t=setTimeout(function(){t.classList.remove('show');},2200);\n" |
| 218 | "}\n" |
| 219 | "function note(el,msg,kind){\n" |
| 220 | " if(typeof el==='string')el=$(el);\n" |
| 221 | " if(!el)return;\n" |
| 222 | " el.textContent=msg||'';\n" |
| 223 | " el.className='note'+(msg?' show '+(kind||''):'');\n" |
| 224 | "}\n" |
| 225 | "function kv(el,rows){\n" |
| 226 | " el.innerHTML='';\n" |
| 227 | " rows.forEach(function(r){\n" |
| 228 | " var a=document.createElement('div');a.className='k';a.textContent=r[0];\n" |
| 229 | " var b=document.createElement('div');b.className='v'+(r[2]?' plain':'');\n" |
| 230 | " b.textContent=r[1];el.appendChild(a);el.appendChild(b);\n" |
| 231 | " });\n" |
| 232 | "}\n" |
| 233 | "function fmtExpiry(sec){\n" |
| 234 | " if(typeof sec!=='number')return '-';\n" |
| 235 | " if(sec<=0)return 'expired';\n" |
| 236 | " if(sec<90)return sec+'s';\n" |
| 237 | " if(sec<5400)return Math.round(sec/60)+' min';\n" |
| 238 | " var h=Math.floor(sec/3600);\n" |
| 239 | " if(h<48)return h+' h '+(Math.floor((sec%3600)/60))+' min';\n" |
| 240 | " return Math.floor(h/24)+' days';\n" |
| 241 | "}\n" |
| 242 | "function fmtClock(sec){\n" |
| 243 | " if(typeof sec!=='number'||sec<=0)return '-';\n" |
| 244 | " var d=Math.floor(sec/86400),h=Math.floor((sec%86400)/3600),m=Math.floor((sec%3600)/60);\n" |
| 245 | " if(d>0)return d+'d '+h+'h';\n" |
| 246 | " if(h>0)return h+'h '+m+'m';\n" |
| 247 | " return m+'m';\n" |
| 248 | "}\n" |
| 249 | "function setPill(cls,text){\n" |
| 250 | " $('pill').className='pill '+cls;\n" |
| 251 | " $('pillText').textContent=text;\n" |
| 252 | "}\n" |
| 253 | "\n" |
| 254 | "var pollTimer=null;\n" |
| 255 | "var pollMs=5000;\n" |
| 256 | "var flowActive=false;\n" |
| 257 | "var flowVerify='';\n" |
| 258 | "var flowCode='';\n" |
| 259 | "\n" |
| 260 | "function startPollingUI(){\n" |
| 261 | " flowActive=true;\n" |
| 262 | " $('stepIdle').classList.remove('on');\n" |
| 263 | " $('stepActive').classList.add('on');\n" |
| 264 | " if(!pollTimer)pollTimer=setInterval(pollOnce,pollMs);\n" |
| 265 | "}\n" |
| 266 | "function stopPollingUI(){\n" |
| 267 | " flowActive=false;\n" |
| 268 | " if(pollTimer){clearInterval(pollTimer);pollTimer=null;}\n" |
| 269 | "}\n" |
| 270 | "function pollOnce(){\n" |
| 271 | " if(!flowActive)return;\n" |
| 272 | " api('poll').then(function(d){\n" |
| 273 | " if(!d||d.ok===false){note('flowNote','Poll error: '+(d&&d.error||'unknown'),'err');return;}\n" |
| 274 | " if(d.state==='done'||d.logged_in){\n" |
| 275 | " stopPollingUI();\n" |
| 276 | " $('stepIdle').classList.add('on');\n" |
| 277 | " $('stepActive').classList.remove('on');\n" |
| 278 | " $('pollLabel').textContent='Signed in';\n" |
| 279 | " note('flowNote','Signed in. The credential file has been written.','ok');\n" |
| 280 | " load();\n" |
| 281 | " }else if(d.state==='failed'){\n" |
| 282 | " stopPollingUI();\n" |
| 283 | " $('stepIdle').classList.add('on');\n" |
| 284 | " $('stepActive').classList.remove('on');\n" |
| 285 | " $('pollLabel').textContent='Login failed';\n" |
| 286 | " note('flowNote','Login failed: '+(d.error||'unknown')+(d.detail?(' - '+d.detail):''),'err');\n" |
| 287 | " load();\n" |
| 288 | " }else{\n" |
| 289 | " $('pollLabel').textContent='Waiting for authorization in browser...';\n" |
| 290 | " if(d.interval&&d.interval>0)pollMs=Math.max(1000,d.interval*1000);\n" |
| 291 | " if(d.logged_in)load();\n" |
| 292 | " }\n" |
| 293 | " }).catch(function(e){note('flowNote','Poll request failed: '+e,'err');});\n" |
| 294 | "}\n" |
| 295 | "\n" |
| 296 | "function render(st){\n" |
| 297 | " var li=!!st.logged_in, ex=!!st.expired, pend=!!st.pending;\n" |
| 298 | " if(li&&!ex)setPill('ok','Logged In');\n" |
| 299 | " else if(li&&ex)setPill('warn','Expired');\n" |
| 300 | " else if(pend)setPill('warn','Signing In');\n" |
| 301 | " else setPill('off','Not Connected');\n" |
| 302 | "\n" |
| 303 | " $('count').innerHTML='';\n" |
| 304 | " if(li&&!ex){\n" |
| 305 | " var s=document.createElement('span');s.textContent=fmtClock(st.expires_in_sec);\n" |
| 306 | " var sm=document.createElement('small');sm.textContent=' remaining';\n" |
| 307 | " $('count').appendChild(s);$('count').appendChild(sm);\n" |
| 308 | " }else if(li&&ex){\n" |
| 309 | " $('count').textContent='Token expired';\n" |
| 310 | " }else if(pend){\n" |
| 311 | " $('count').textContent='Device flow open';\n" |
| 312 | " }else{\n" |
| 313 | " $('count').textContent='No Codex session';\n" |
| 314 | " }\n" |
| 315 | "\n" |
| 316 | " var total=st.expires_in_sec>0?st.expires_in_sec:0;\n" |
| 317 | " var pct=0;\n" |
| 318 | " if(li&&total>0){\n" |
| 319 | " /* A one-hour token is the norm, so the bar is drawn against the window it\n" |
| 320 | " * actually has, capped at 24 h so a long-lived token still fills it. */\n" |
| 321 | " var win=total>86400?86400:total;\n" |
| 322 | " pct=Math.max(2,Math.min(100,Math.round(100*total/win)));\n" |
| 323 | " }\n" |
| 324 | " $('fill').style.width=pct+'%';\n" |
| 325 | " $('bar').className='bar'+(li&&ex?' err':(li&&pct<20?' warn':''));\n" |
| 326 | " if(!li)$('bar').className='bar';\n" |
| 327 | "\n" |
| 328 | " kv($('session'),[\n" |
| 329 | " ['Account', st.account||'-', true],\n" |
| 330 | " ['Logged in', st.logged_in?'yes':'no', true],\n" |
| 331 | " ['Token', st.logged_in?(st.expired?'expired':'valid, '+fmtExpiry(st.expires_in_sec)):'none', true],\n" |
| 332 | " ['Refresh token', st.has_refresh?'stored':'none', true],\n" |
| 333 | " ['Last refreshed', st.last_refresh?new Date(st.last_refresh*1000).toISOString().replace('T',' ').slice(0,19):'unknown', true],\n" |
| 334 | " ['Account id', st.account_id||'-'],\n" |
| 335 | " ['Login pending', st.pending?'yes':'no', true],\n" |
| 336 | " ['Login CLI', st.cli_present?'found':'not found', true],\n" |
| 337 | " ['Profile', st.profile_exists?(st.profile||'codex'):'not created', true],\n" |
| 338 | " ['Credentials', st.credentials_path||'-']\n" |
| 339 | " ]);\n" |
| 340 | "\n" |
| 341 | " $('btnRelogin').hidden=!li;\n" |
| 342 | " $('btnStartLogin').hidden=!!li;\n" |
| 343 | "\n" |
| 344 | " if(!li&&!pend)note('sessionNote','No Codex session on this node yet. Start a device login below.','ok');\n" |
| 345 | " else if(li&&ex)note('sessionNote','The token has expired. Press Refresh Token Now, or sign in again.','warn');\n" |
| 346 | " else note('sessionNote','');\n" |
| 347 | "\n" |
| 348 | " if(st.cli_present===false)\n" |
| 349 | " note('sessionNote','SCORPIOX CODE is not on this node: the login and refresh CLIs cannot be run here.','warn');\n" |
| 350 | "\n" |
| 351 | " var box=$('accounts');\n" |
| 352 | " box.innerHTML='';\n" |
| 353 | " var list=st.accounts||[];\n" |
| 354 | " if(!list.length){\n" |
| 355 | " var e=document.createElement('div');e.className='empty';\n" |
| 356 | " e.textContent='No named accounts.';box.appendChild(e);\n" |
| 357 | " }else{\n" |
| 358 | " list.forEach(function(a){\n" |
| 359 | " var row=document.createElement('div');row.className='acct';\n" |
| 360 | " var nm=document.createElement('div');nm.className='nm';nm.textContent=a.name;\n" |
| 361 | " var tg=document.createElement('div');\n" |
| 362 | " tg.className='tag '+(a.logged_in&&!a.expired?'ok':(a.logged_in?'warn':''));\n" |
| 363 | " tg.textContent=a.logged_in?(a.expired?'expired':'valid, '+fmtExpiry(a.expires_in_sec)):'empty';\n" |
| 364 | " var bt=document.createElement('button');\n" |
| 365 | " bt.className='btn ghost';bt.type='button';bt.textContent='Select';\n" |
| 366 | " bt.onclick=function(){acct=a.name;$('sub').textContent='account: '+a.name;load();};\n" |
| 367 | " row.appendChild(nm);row.appendChild(tg);row.appendChild(bt);\n" |
| 368 | " box.appendChild(row);\n" |
| 369 | " });\n" |
| 370 | " }\n" |
| 371 | " if(!$('sub').textContent||$('sub').textContent==='Device code login on this node'){\n" |
| 372 | " $('sub').textContent=(st.account&&st.account!=='default')?('account: '+st.account):'Device code login on this node';\n" |
| 373 | " }\n" |
| 374 | "}\n" |
| 375 | "\n" |
| 376 | "function load(){\n" |
| 377 | " api('status').then(function(d){\n" |
| 378 | " if(!d||d.ok===false){setPill('off','Not Connected');note('sessionNote','Error: '+(d&&d.error||'no response'),'err');return;}\n" |
| 379 | " render(d);\n" |
| 380 | " if(d.pending&&!flowActive){\n" |
| 381 | " /* A flow that was started elsewhere (or before a page reload) should\n" |
| 382 | " * still show its spinner; the code itself is not recoverable from the\n" |
| 383 | " * marker, so the panel says so rather than pretending. */\n" |
| 384 | " $('userCode').textContent='--';\n" |
| 385 | " $('verifyUrl').textContent='';\n" |
| 386 | " $('pollLabel').textContent='A device flow is already open on this node';\n" |
| 387 | " startPollingUI();\n" |
| 388 | " }\n" |
| 389 | " if(!d.pending&&flowActive)stopPollingUI();\n" |
| 390 | " }).catch(function(e){setPill('off','Not Connected');note('sessionNote','Request failed: '+e,'err');});\n" |
| 391 | "}\n" |
| 392 | "\n" |
| 393 | "function doStart(force){\n" |
| 394 | " note('sessionNote','');\n" |
| 395 | " $('btnStartLogin').disabled=true;\n" |
| 396 | " api('start',force?'force=1':'').then(function(d){\n" |
| 397 | " $('btnStartLogin').disabled=false;\n" |
| 398 | " if(!d||d.ok===false){\n" |
| 399 | " note('sessionNote','Start failed: '+(d&&d.error||'unknown')+(d.detail?(' - '+d.detail):''),'err');\n" |
| 400 | " return;\n" |
| 401 | " }\n" |
| 402 | " if(d.already_logged_in){\n" |
| 403 | " note('sessionNote','This node already has Codex credentials. Use Re-login to replace them.','warn');\n" |
| 404 | " load();\n" |
| 405 | " return;\n" |
| 406 | " }\n" |
| 407 | " flowVerify=d.verify_url||'';\n" |
| 408 | " flowCode=d.user_code||'';\n" |
| 409 | " $('userCode').textContent=flowCode||'--';\n" |
| 410 | " $('verifyUrl').textContent=flowVerify;\n" |
| 411 | " $('pollLabel').textContent='Waiting for authorization in browser...';\n" |
| 412 | " pollMs=Math.max(1000,(d.interval||5)*1000);\n" |
| 413 | " note('flowNote','','');\n" |
| 414 | " startPollingUI();\n" |
| 415 | " load();\n" |
| 416 | " }).catch(function(e){$('btnStartLogin').disabled=false;note('sessionNote','Start request failed: '+e,'err');});\n" |
| 417 | "}\n" |
| 418 | "\n" |
| 419 | "$('btnStartLogin').onclick=function(){doStart(false);};\n" |
| 420 | "$('btnRelogin').onclick=function(){doStart(true);};\n" |
| 421 | "$('btnReload').onclick=load;\n" |
| 422 | "$('btnCancel').onclick=function(){\n" |
| 423 | " stopPollingUI();\n" |
| 424 | " api('cancel').then(function(d){\n" |
| 425 | " $('stepIdle').classList.add('on');\n" |
| 426 | " $('stepActive').classList.remove('on');\n" |
| 427 | " note('flowNote',(d&&d.ok)?'Device flow cancelled.':'Cancel failed: '+((d&&d.error)||'unknown'),\n" |
| 428 | " (d&&d.ok)?'ok':'err');\n" |
| 429 | " load();\n" |
| 430 | " }).catch(function(e){note('flowNote','Cancel request failed: '+e,'err');});\n" |
| 431 | "};\n" |
| 432 | "$('btnRefresh').onclick=function(){\n" |
| 433 | " note('sessionNote','');\n" |
| 434 | " api('refresh').then(function(d){\n" |
| 435 | " if(!d||d.ok===false){\n" |
| 436 | " note('sessionNote','Refresh failed: '+(d&&d.error||'unknown')+(d.detail?(' - '+d.detail):''),'err');\n" |
| 437 | " return;\n" |
| 438 | " }\n" |
| 439 | " note('sessionNote','Token refreshed. New expiry: '+fmtExpiry(d.expires_in_sec)+'.','ok');\n" |
| 440 | " render(d);\n" |
| 441 | " }).catch(function(e){note('sessionNote','Refresh request failed: '+e,'err');});\n" |
| 442 | "};\n" |
| 443 | "$('btnCopyOpen').onclick=function(){\n" |
| 444 | " var done=function(){toast('Code copied. Open the link and approve.');};\n" |
| 445 | " if(navigator.clipboard&&navigator.clipboard.writeText){\n" |
| 446 | " navigator.clipboard.writeText(flowCode).then(done,function(){toast('Copy failed');});\n" |
| 447 | " }else{toast('Copy not available');}\n" |
| 448 | " if(flowVerify)window.open(flowVerify,'_blank','noopener');\n" |
| 449 | "};\n" |
| 450 | "\n" |
| 451 | "var tb=$('themeToggle');\n" |
| 452 | "if(tb)tb.onclick=function(){\n" |
| 453 | " if(window.sxApplyTheme)window.sxApplyTheme(window.sxTheme?window.sxTheme():'light');\n" |
| 454 | "};\n" |
| 455 | "$('footInfo').textContent='plugin_codex_login';\n" |
| 456 | "load();\n" |
| 457 | "})();\n" |
| 458 | "</script>\n" |
| 459 | "\002</body></html>\n" |
| 460 | ; |
| 461 | |
| 462 | #endif /* SX_CODEXLOGIN_UI_HTML_H */ |