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