| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_FETCH_UI_HTML_H |
| 3 | #define SX_FETCH_UI_HTML_H |
| 4 | |
| 5 | static const char *UI_HTML = |
| 6 | "<!DOCTYPE html>\n" |
| 7 | "<html lang=\"en\">\n" |
| 8 | "<head>\n" |
| 9 | "<meta charset=\"utf-8\">\n" |
| 10 | "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" |
| 11 | "<title>fetch - URL to Markdown</title>\n" |
| 12 | "\001\n" |
| 13 | "<style>\n" |
| 14 | "*{box-sizing:border-box}\n" |
| 15 | "body{margin:0;padding:16px;background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;line-height:1.5}\n" |
| 16 | ".wrap{max-width:1080px;margin:0 auto}\n" |
| 17 | "h1{font-size:18px;margin:0 0 4px;font-weight:700}\n" |
| 18 | ".sub{color:var(--text-2);font-size:12.5px;margin-bottom:16px}\n" |
| 19 | ".card{background:var(--bg-card);border:1px solid var(--line);border-radius:12px;padding:14px;margin-bottom:14px}\n" |
| 20 | ".row{display:flex;gap:8px;flex-wrap:wrap;align-items:center}\n" |
| 21 | "input[type=text]{flex:1 1 320px;min-width:200px;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:9px;padding:8px 10px;font-family:var(--mono);font-size:12.5px}\n" |
| 22 | "input[type=number]{width:110px;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:9px;padding:8px 10px;font-family:var(--mono);font-size:12.5px}\n" |
| 23 | "label.chk{display:flex;align-items:center;gap:6px;color:var(--text-2);font-size:12.5px;user-select:none}\n" |
| 24 | "button{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:7px 16px;font-weight:600;cursor:pointer;font-size:13px}\n" |
| 25 | "button.sec{background:transparent;color:var(--blue);border:1px solid var(--line)}\n" |
| 26 | "button:disabled{opacity:.5;cursor:default}\n" |
| 27 | ".lbl{color:var(--text-2);font-size:12px;margin-right:2px}\n" |
| 28 | ".pill{display:inline-block;padding:2px 10px;border-radius:980px;font-size:11.5px;font-weight:600;border:1px solid var(--line);color:var(--text-2)}\n" |
| 29 | ".pill.ok{color:var(--green);border-color:var(--green)}\n" |
| 30 | ".pill.warn{color:var(--orange);border-color:var(--orange)}\n" |
| 31 | ".pill.bad{color:var(--red);border-color:var(--red)}\n" |
| 32 | ".meta{display:flex;gap:14px;flex-wrap:wrap;color:var(--text-2);font-size:12px;margin:8px 0}\n" |
| 33 | ".meta b{color:var(--text);font-weight:600;font-family:var(--mono)}\n" |
| 34 | "pre.out{background:var(--bg);border:1px solid var(--line);border-radius:10px;padding:12px;overflow:auto;max-height:560px;white-space:pre-wrap;word-break:break-word;font-family:var(--mono);font-size:12px;margin:0}\n" |
| 35 | ".tabs{display:flex;gap:6px;margin-bottom:10px}\n" |
| 36 | ".tab{padding:5px 14px;border-radius:980px;border:1px solid var(--line);background:transparent;color:var(--text-2);cursor:pointer;font-size:12.5px;font-weight:600}\n" |
| 37 | ".tab.on{background:var(--blue);border-color:var(--blue);color:#fff}\n" |
| 38 | ".pager{display:flex;gap:8px;align-items:center;margin-top:10px;flex-wrap:wrap}\n" |
| 39 | ".small{font-size:11.5px;color:var(--text-2)}\n" |
| 40 | ".err{color:var(--red)}\n" |
| 41 | ".grid{display:grid;grid-template-columns:1fr 1fr;gap:14px}\n" |
| 42 | "@media(max-width:860px){.grid{grid-template-columns:1fr}}\n" |
| 43 | ".pol{display:flex;align-items:center;gap:8px;font-size:12.5px;color:var(--text-2)}\n" |
| 44 | "h1 .tag{font-size:11px;color:var(--text-2);font-weight:500;margin-left:6px}\n" |
| 45 | "html.embedded .embed-hide{display:none}\n" |
| 46 | "</style>\n" |
| 47 | "</head>\n" |
| 48 | "<body>\n" |
| 49 | "<div class=\"wrap\">\n" |
| 50 | " <div class=\"embed-hide\" style=\"margin-bottom:10px;display:flex;gap:10px;align-items:center;justify-content:space-between\">\n" |
| 51 | " <a href=\"/\" style=\"color:var(--blue);text-decoration:none;font-weight:600\">← Back to Bot</a>\n" |
| 52 | " <button class=\"sec\" id=\"themeToggle\" type=\"button\" title=\"Toggle appearance\">Theme</button>\n" |
| 53 | " </div>\n" |
| 54 | " <h1>fetch<span class=\"tag\">URL to Markdown · MCP connector</span></h1>\n" |
| 55 | " <div class=\"sub\">Preview the <b>fetch</b> tool exactly as an agent sees it. Private, loopback and link-local targets are refused unless the operator allows them. TLS certificates are always verified.</div>\n" |
| 56 | "\n" |
| 57 | " <div class=\"card\">\n" |
| 58 | " <div class=\"row\">\n" |
| 59 | " <input type=\"text\" id=\"url\" placeholder=\"https://example.com/article\" spellcheck=\"false\" autocomplete=\"off\">\n" |
| 60 | " <button id=\"go\" onclick=\"doFetch()\">Fetch</button>\n" |
| 61 | " </div>\n" |
| 62 | " <div class=\"row\" style=\"margin-top:10px\">\n" |
| 63 | " <span class=\"lbl\">max_length</span><input type=\"number\" id=\"maxlen\" value=\"5000\" min=\"1\" max=\"100000\" step=\"1000\">\n" |
| 64 | " <span class=\"lbl\">start_index</span><input type=\"number\" id=\"start\" value=\"0\" min=\"0\" step=\"1\">\n" |
| 65 | " <label class=\"chk\"><input type=\"checkbox\" id=\"raw\"> raw (keep HTML)</label>\n" |
| 66 | " <span class=\"small\">redirects are followed up to 5 hops, each hop re-checked</span>\n" |
| 67 | " </div>\n" |
| 68 | " <div class=\"row\" style=\"margin-top:10px\">\n" |
| 69 | " <div class=\"pol\">\n" |
| 70 | " <label class=\"chk\"><input type=\"checkbox\" id=\"allowpriv\"> allow private/loopback (operator policy)</label>\n" |
| 71 | " <span class=\"small\">saved on the node</span>\n" |
| 72 | " </div>\n" |
| 73 | " </div>\n" |
| 74 | " </div>\n" |
| 75 | "\n" |
| 76 | " <div class=\"card\">\n" |
| 77 | " <div class=\"row\" style=\"justify-content:space-between\">\n" |
| 78 | " <div class=\"tabs\" style=\"margin:0\">\n" |
| 79 | " <button class=\"tab on\" id=\"tabmd\" onclick=\"setTab('md')\">Markdown</button>\n" |
| 80 | " <button class=\"tab\" id=\"tabraw\" onclick=\"setTab('raw')\">Raw HTML</button>\n" |
| 81 | " </div>\n" |
| 82 | " <div id=\"status\"><span class=\"pill\">idle</span></div>\n" |
| 83 | " </div>\n" |
| 84 | " <div class=\"meta\" id=\"meta\" style=\"display:none\">\n" |
| 85 | " <span>status <b id=\"mStatus\">-</b></span>\n" |
| 86 | " <span>type <b id=\"mType\">-</b></span>\n" |
| 87 | " <span>bytes <b id=\"mBytes\">-</b></span>\n" |
| 88 | " <span>content <b id=\"mLen\">-</b></span>\n" |
| 89 | " <span id=\"mRedirWrap\">redirected <b id=\"mRedir\">-</b></span>\n" |
| 90 | " </div>\n" |
| 91 | " <div id=\"mTitle\" class=\"small\" style=\"margin-bottom:6px\"></div>\n" |
| 92 | " <pre class=\"out\" id=\"out\">Enter a URL and press Fetch.</pre>\n" |
| 93 | " <div class=\"pager\" id=\"pager\" style=\"display:none\">\n" |
| 94 | " <button class=\"sec\" onclick=\"prevChunk()\">← Prev</button>\n" |
| 95 | " <span class=\"small\" id=\"pageInfo\"></span>\n" |
| 96 | " <button class=\"sec\" onclick=\"nextChunk()\">Next →</button>\n" |
| 97 | " <button class=\"sec\" onclick=\"copyOut()\">Copy visible</button>\n" |
| 98 | " </div>\n" |
| 99 | " </div>\n" |
| 100 | "\n" |
| 101 | " <div class=\"card\">\n" |
| 102 | " <div class=\"small\" style=\"font-weight:600;color:var(--text);margin-bottom:6px\">MCP tool (stdio <code>--mcp</code>)</div>\n" |
| 103 | " <pre class=\"out\" style=\"max-height:180px\" id=\"schema\">loading...</pre>\n" |
| 104 | " <div class=\"small\" style=\"margin-top:8px\">Register through <b>sx-connector-mcp</b>: the router exposes it as <code>connector_call</code> → <code>fetch</code>. Args: <code>url</code> (required), <code>max_length</code> (default 5000, cap 100000), <code>start_index</code> (default 0), <code>raw</code> (default false).</div>\n" |
| 105 | " </div>\n" |
| 106 | "</div>\n" |
| 107 | "<script>\n" |
| 108 | "var q=new URLSearchParams(location.search);\n" |
| 109 | "var HUB=q.get('plugin')||'';\n" |
| 110 | "var node=q.get('node')||'';\n" |
| 111 | "var sid=q.get('id')||'';\n" |
| 112 | "var pwd=q.get('pwd')||localStorage.getItem('bot_active_pwd')||'';\n" |
| 113 | "var PAGE=5000;\n" |
| 114 | "var lastContentLen=0;\n" |
| 115 | "\n" |
| 116 | "function api(action,arg){\n" |
| 117 | " var parts=[];\n" |
| 118 | " for(var k in arg) parts.push(encodeURIComponent(k)+'='+encodeURIComponent(arg[k]));\n" |
| 119 | " var qs='action='+encodeURIComponent(action)+(parts.length?'&'+parts.join('&'):'')\n" |
| 120 | " +(node?'&node='+encodeURIComponent(node):'')+(sid?'&id='+encodeURIComponent(sid):'')\n" |
| 121 | " +(pwd?'&pwd='+encodeURIComponent(pwd):'');\n" |
| 122 | " var u=HUB?('/plugins?plugin='+encodeURIComponent(HUB)+'&'+qs)\n" |
| 123 | " :('/plugin_fetch?'+qs);\n" |
| 124 | " var hdr=pwd?{'X-Bot-Password':pwd}:{};\n" |
| 125 | " return fetch(u,{headers:hdr}).then(function(r){\n" |
| 126 | " return r.json().then(function(d){\n" |
| 127 | " if(!r.ok&&!d.ok){d.error=(d.error||'request rejected')+' (http '+r.status+')';}\n" |
| 128 | " return d;\n" |
| 129 | " });\n" |
| 130 | " });\n" |
| 131 | "}\n" |
| 132 | "\n" |
| 133 | "function setTab(t){\n" |
| 134 | " document.getElementById('tabmd').classList.toggle('on',t==='md');\n" |
| 135 | " document.getElementById('tabraw').classList.toggle('on',t==='raw');\n" |
| 136 | " render();\n" |
| 137 | "}\n" |
| 138 | "function pill(cls,txt){document.getElementById('status').innerHTML='<span class=\"pill '+cls+'\">'+txt+'</span>';}\n" |
| 139 | "\n" |
| 140 | "var lastRaw='',lastMD='';\n" |
| 141 | "function render(){\n" |
| 142 | " var raw=document.getElementById('raw').checked;\n" |
| 143 | " var show=(document.getElementById('tabraw').classList.contains('on')||raw)?lastRaw:lastMD;\n" |
| 144 | " document.getElementById('out').textContent=show||'(empty)';\n" |
| 145 | "}\n" |
| 146 | "\n" |
| 147 | "function doFetch(){\n" |
| 148 | " var url=document.getElementById('url').value.trim();\n" |
| 149 | " var ml=parseInt(document.getElementById('maxlen').value||'5000',10);\n" |
| 150 | " var si=parseInt(document.getElementById('start').value||'0',10);\n" |
| 151 | " var raw=document.getElementById('raw').checked;\n" |
| 152 | " if(!url){pill('bad','enter a URL');return;}\n" |
| 153 | " pill('','fetching...');\n" |
| 154 | " document.getElementById('go').disabled=true;\n" |
| 155 | " api('fetch',{url:url,max_length:ml,start_index:si,raw:raw?'true':'false'})\n" |
| 156 | " .then(function(d){\n" |
| 157 | " document.getElementById('go').disabled=false;\n" |
| 158 | " if(!d.ok){pill('bad','failed');\n" |
| 159 | " document.getElementById('out').textContent=d.error||'fetch failed';\n" |
| 160 | " document.getElementById('meta').style.display='none';\n" |
| 161 | " document.getElementById('pager').style.display='none';\n" |
| 162 | " lastRaw='';lastMD='';\n" |
| 163 | " return;}\n" |
| 164 | " pill(d.status_code>=400?'bad':'ok','HTTP '+d.status_code);\n" |
| 165 | " lastMD=d.text||'';\n" |
| 166 | " lastRaw=d.raw_html||'';\n" |
| 167 | " lastContentLen=d.content_length||0;\n" |
| 168 | " document.getElementById('meta').style.display='flex';\n" |
| 169 | " document.getElementById('mStatus').textContent=d.status_code;\n" |
| 170 | " document.getElementById('mType').textContent=d.content_type||'-';\n" |
| 171 | " document.getElementById('mBytes').textContent=d.bytes_read;\n" |
| 172 | " document.getElementById('mLen').textContent=d.content_length;\n" |
| 173 | " document.getElementById('mRedir').textContent=d.redirected?'yes':'no';\n" |
| 174 | " document.getElementById('mTitle').textContent=d.title?('title: '+d.title):'';\n" |
| 175 | " PAGE=Math.max(500,Math.min(100000,ml||5000));\n" |
| 176 | " document.getElementById('pager').style.display=(lastContentLen>(si+PAGE))?'flex':'none';\n" |
| 177 | " render();\n" |
| 178 | " })\n" |
| 179 | " .catch(function(e){\n" |
| 180 | " document.getElementById('go').disabled=false;\n" |
| 181 | " pill('bad','error');\n" |
| 182 | " document.getElementById('out').textContent='Error: '+e;\n" |
| 183 | " });\n" |
| 184 | "}\n" |
| 185 | "\n" |
| 186 | "function chunk(){return parseInt(document.getElementById('start').value||'0',10);}\n" |
| 187 | "function setChunk(v){\n" |
| 188 | " v=Math.max(0,v);\n" |
| 189 | " document.getElementById('start').value=v;\n" |
| 190 | " doFetch();\n" |
| 191 | "}\n" |
| 192 | "function nextChunk(){setChunk(chunk()+PAGE);}\n" |
| 193 | "function prevChunk(){setChunk(chunk()-PAGE);}\n" |
| 194 | "\n" |
| 195 | "function copyOut(){\n" |
| 196 | " var t=document.getElementById('out').textContent;\n" |
| 197 | " if(navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(t);\n" |
| 198 | "}\n" |
| 199 | "\n" |
| 200 | "function loadPolicy(){\n" |
| 201 | " api('policy',{}).then(function(d){\n" |
| 202 | " if(d&&d.ok)document.getElementById('allowpriv').checked=!!d.allow_private;\n" |
| 203 | " }).catch(function(){});\n" |
| 204 | "}\n" |
| 205 | "document.getElementById('allowpriv').addEventListener('change',function(ev){\n" |
| 206 | " api('policy',{allow_private:ev.target.checked?'true':'false'}).catch(function(){});\n" |
| 207 | "});\n" |
| 208 | "\n" |
| 209 | "function loadSchema(){\n" |
| 210 | " api('info',{}).then(function(d){\n" |
| 211 | " if(d&&d.tool_schema)\n" |
| 212 | " document.getElementById('schema').textContent=JSON.stringify(d.tool_schema,null,2);\n" |
| 213 | " else document.getElementById('schema').textContent='(unavailable)';\n" |
| 214 | " if(d&&typeof d.allow_private==='boolean')\n" |
| 215 | " document.getElementById('allowpriv').checked=d.allow_private;\n" |
| 216 | " }).catch(function(){document.getElementById('schema').textContent='(unavailable)';});\n" |
| 217 | "}\n" |
| 218 | "\n" |
| 219 | "document.getElementById('url').addEventListener('keydown',function(e){\n" |
| 220 | " if(e.key==='Enter')doFetch();\n" |
| 221 | "});\n" |
| 222 | "if(q.get('url'))document.getElementById('url').value=q.get('url');\n" |
| 223 | "loadPolicy();\n" |
| 224 | "loadSchema();\n" |
| 225 | "if(q.get('url')&&q.get('autofetch'))doFetch();\n" |
| 226 | "</script>\n" |
| 227 | "\002</body>\n" |
| 228 | "</html>\n" |
| 229 | ; |
| 230 | |
| 231 | #endif /* SX_FETCH_UI_HTML_H */ |