Describe shell capabilities directly in model instructions
Browse filesFiles changed (5)
11 unmodified lines121314151617181911 unmodified linesUse your tools to inspect and change actual files. Never claim a command ran or a file changed without a successful tool result.When the user explicitly asks you to use a tool, call that tool even if you already know the answer.Working directory: /workspace. Use read, write, edit, and bash. Keep tool calls and answers concise.The bash tool is just-bash: a virtual shell with cat, ls, find, grep, sed, awk, jq, sort, wc, printf, pipes, redirects, and shell scripts.Use jq for JSON and awk for CSV and calculations in just-bash; python, python3, node, npm, native binaries, and network access are unavailable.You can create and edit text files, including HTML, CSS, JavaScript, and shell scripts. HTML may reference external assets by URL; writing such a reference does not require network access from the shell. Do not claim an external asset was fetched or tested.Interpret short follow-ups using the conversation and inspect the relevant files when needed.Inspect files before editing them. After changing files, verify the result with a tool. Finish with a short factual answer.`;11 unmodified lines121314151617181911 unmodified linesUse your tools to inspect and change actual files. Never claim a command ran or a file changed without a successful tool result.When the user explicitly asks you to use a tool, call that tool even if you already know the answer.Working directory: /workspace. Use read, write, edit, and bash. Keep tool calls and answers concise.The bash tool supports cat, ls, find, grep, sed, awk, jq, sort, wc, printf, pipes, redirects, and shell scripts.Use jq for JSON and awk for CSV and calculations; python, python3, node, npm, native binaries, and network access are unavailable.You can create and edit text files, including HTML, CSS, JavaScript, and shell scripts. HTML may reference external assets by URL; writing such a reference does not require network access from the shell. Do not claim an external asset was fetched or tested.Interpret short follow-ups using the conversation and inspect the relevant files when needed.Inspect files before editing them. After changing files, verify the result with a tool. Finish with a short factual answer.`;
1786 unmodified lines178717881789179017911792179317941786 unmodified linesUse your tools to inspect and change actual files. Never claim a command ran or a file changed without a successful tool result.When the user explicitly asks you to use a tool, call that tool even if you already know the answer.Working directory: /workspace. Use read, write, edit, and bash. Keep tool calls and answers concise.The bash tool is just-bash: a virtual shell with cat, ls, find, grep, sed, awk, jq, sort, wc, printf, pipes, redirects, and shell scripts.Use jq for JSON and awk for CSV and calculations in just-bash; python, python3, node, npm, native binaries, and network access are unavailable.You can create and edit text files, including HTML, CSS, JavaScript, and shell scripts. HTML may reference external assets by URL; writing such a reference does not require network access from the shell. Do not claim an external asset was fetched or tested.Interpret short follow-ups using the conversation and inspect the relevant files when needed.Inspect files before editing them. After changing files, verify the result with a tool. Finish with a short factual answer.`,tools:K9.tools,messages:e?.messages??[]},streamFn:G9.streamFn,toolExecution:`sequential`,afterToolCall:({result:e,isError:t})=>({isError:t||e.details?.exitCode!==void 0&&e.details.exitCode!==0}),shouldStopAfterTurn:({toolResults:e})=>{let t=++Z9>=12&&e.length>0;return t&&W9({type:`notice`,text:`Paused after 12 agent turns. Send a follow-up to continue.`}),t}}),q9.subscribe(async e=>{W9({type:`agent_event`,event:e}),(e.type===`tool_execution_end`||e.type===`agent_end`)&&await $9()});let n=await Q9();if(t)try{await J9?.save(n)}catch(e){W9({type:`persistence_error`,error:`Changes are in memory, but browser storage failed: `+e.message})}W9({type:`initialized`,...n})})();onmessage=async({data:e})=>{let{id:t,action:n,args:r={}}=e,i=e=>W9({type:`reply`,id:t,value:e});try{if(await JPe,n===`stop`)return X9?.abort(),q9.abort(),G9.stop(),i(!0);if(n===`snapshot`)return i(await Q9());if(n===`cache_status`)return i(await CI());if(Y9)throw Error(`Wait for the current operation or stop it first.`);Y9=!0,X9=new AbortController,W9({type:`busy`,action:n,cachedOnly:r.cachedOnly===!0});try{let e;if(n===`load`)await G9.load(r,X9.signal),e=G9.device;else if(n===`prompt`)Z9=0,await q9.prompt(r.text),e=await Q9();else if(n===`shell`)e=await K9.bash.exec(r.command,{signal:X9.signal}),await $9();else if(n===`write`)await K9.write(r.path,r.content),e=await $9();else if(n===`new_chat`)q9.reset(),e=await $9();else if(n===`read`)e=await K9.read(r.path);else throw Error(`Unknown action: `+n);i(e)}finally{Y9=!1,X9=void 0,W9({type:`idle`})}}catch(e){W9({type:`reply`,id:t,error:e?.name===`AbortError`?`Stopped.`:String(e?.message??e),errorName:e?.name,errorCode:e?.code})}};1786 unmodified lines178717881789179017911792179317941786 unmodified linesUse your tools to inspect and change actual files. Never claim a command ran or a file changed without a successful tool result.When the user explicitly asks you to use a tool, call that tool even if you already know the answer.Working directory: /workspace. Use read, write, edit, and bash. Keep tool calls and answers concise.The bash tool supports cat, ls, find, grep, sed, awk, jq, sort, wc, printf, pipes, redirects, and shell scripts.Use jq for JSON and awk for CSV and calculations; python, python3, node, npm, native binaries, and network access are unavailable.You can create and edit text files, including HTML, CSS, JavaScript, and shell scripts. HTML may reference external assets by URL; writing such a reference does not require network access from the shell. Do not claim an external asset was fetched or tested.Interpret short follow-ups using the conversation and inspect the relevant files when needed.Inspect files before editing them. After changing files, verify the result with a tool. Finish with a short factual answer.`,tools:K9.tools,messages:e?.messages??[]},streamFn:G9.streamFn,toolExecution:`sequential`,afterToolCall:({result:e,isError:t})=>({isError:t||e.details?.exitCode!==void 0&&e.details.exitCode!==0}),shouldStopAfterTurn:({toolResults:e})=>{let t=++Z9>=12&&e.length>0;return t&&W9({type:`notice`,text:`Paused after 12 agent turns. Send a follow-up to continue.`}),t}}),q9.subscribe(async e=>{W9({type:`agent_event`,event:e}),(e.type===`tool_execution_end`||e.type===`agent_end`)&&await $9()});let n=await Q9();if(t)try{await J9?.save(n)}catch(e){W9({type:`persistence_error`,error:`Changes are in memory, but browser storage failed: `+e.message})}W9({type:`initialized`,...n})})();onmessage=async({data:e})=>{let{id:t,action:n,args:r={}}=e,i=e=>W9({type:`reply`,id:t,value:e});try{if(await JPe,n===`stop`)return X9?.abort(),q9.abort(),G9.stop(),i(!0);if(n===`snapshot`)return i(await Q9());if(n===`cache_status`)return i(await CI());if(Y9)throw Error(`Wait for the current operation or stop it first.`);Y9=!0,X9=new AbortController,W9({type:`busy`,action:n,cachedOnly:r.cachedOnly===!0});try{let e;if(n===`load`)await G9.load(r,X9.signal),e=G9.device;else if(n===`prompt`)Z9=0,await q9.prompt(r.text),e=await Q9();else if(n===`shell`)e=await K9.bash.exec(r.command,{signal:X9.signal}),await $9();else if(n===`write`)await K9.write(r.path,r.content),e=await $9();else if(n===`new_chat`)q9.reset(),e=await $9();else if(n===`read`)e=await K9.read(r.path);else throw Error(`Unknown action: `+n);i(e)}finally{Y9=!1,X9=void 0,W9({type:`idle`})}}catch(e){W9({type:`reply`,id:t,error:e?.name===`AbortError`?`Stopped.`:String(e?.message??e),errorName:e?.name,errorCode:e?.code})}};
156 unmodified lines157158159160156 unmodified lines`)),r.style.height=`auto`,r.style.height=Math.min(104,Math.max(32,r.scrollHeight))+`px`,i.scrollTop=r.scrollTop,i.scrollLeft=r.scrollLeft,v()}function b(e){r.value=e,y(),r.setSelectionRange(e.length,e.length)}function x(){m||(d.length=0,a.replaceChildren(l.cloneNode(!0)),v())}function S(e,t,n){if(!t)return;let r=document.createElement(`pre`);r.className=n,r.textContent=Hg(t),e.append(r)}o.onsubmit=async e=>{e.preventDefault();let n=r.value;if(m||h||!n.trim())return;m=!0,u.at(-1)!==n&&u.push(n),u.length>50&&u.shift(),f=u.length,p=``,b(``),r.focus(),d.length||a.replaceChildren();let i=document.createElement(`section`);i.className=`shell-entry`;let o=document.createElement(`div`);o.className=`shell-entry-heading`;let s=document.createElement(`span`);s.className=`shell-prompt`,s.textContent=`$`;let c=document.createElement(`pre`);c.className=`shell-code`,c.append(Ug(Hg(n)));let l=document.createElement(`span`);l.className=`shell-status`,l.textContent=`Running…`,o.append(s,c,l),i.append(o),a.append(i),d.push(i),_();try{let e=await t(n),r=g();S(i,e.stdout,`shell-stdout`),S(i,e.stderr,`shell-stderr`),l.classList.add(e.exitCode===0?`success`:`error`),l.textContent=`[exit ${e.exitCode}]`,r&&_()}catch(e){let t=g();S(i,e.message,`shell-stderr`),l.classList.add(`error`),l.textContent=`[error]`,r.value||b(n),t&&_()}finally{for(;d.length>1&&(d.length>40||a.textContent.length>48e3);)d.shift().remove();m=!1,v()}},r.addEventListener(`input`,()=>{f=u.length,p=r.value,y()}),r.addEventListener(`scroll`,()=>{i.scrollTop=r.scrollTop,i.scrollLeft=r.scrollLeft}),r.addEventListener(`keydown`,e=>{if(e.isComposing||e.keyCode===229)return;if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),o.requestSubmit();return}if(e.ctrlKey&&e.key.toLowerCase()===`l`){e.preventDefault(),x();return}if(e.ctrlKey||e.altKey||e.metaKey||e.shiftKey||r.selectionStart!==r.selectionEnd)return;let t=!r.value.slice(0,r.selectionStart).includes(``),n=!r.value.slice(r.selectionEnd).includes(``);e.key===`ArrowUp`&&t&&f>0?(e.preventDefault(),f===u.length&&(p=r.value),b(u[--f])):e.key===`ArrowDown`&&n&&f<u.length&&(e.preventDefault(),b(++f===u.length?p:u[f]))}),c.onclick=()=>{x(),r.focus()};let C=0;return new ResizeObserver(([e])=>{e.contentRect.width!==C&&(C=e.contentRect.width,y())}).observe(r.parentElement),y(),{setBusy(e){h=e,v()}}}function Gg(e){let t=e.querySelector(`.runtime-value`),n=e.querySelector(`.runtime-sparkline`),r=e.querySelector(`.runtime-bars`),i=e.querySelector(`[role="status"]`),a=e.querySelector(`.runtime-engine`),o=e.querySelector(`.runtime-content`);new ResizeObserver(([t])=>{e.style.width=`calc(${Math.ceil(t.contentRect.width)}px + 2 * var(--runtime-padding))`}).observe(o);let s=!1,c,l=[],u;function d(o,s,d){clearTimeout(u),o!==c&&(i.textContent=d??`${s} in this browser.`),c=o,a.textContent=c===`tool`?`JavaScript`:`WebGPU`,e.dataset.state=c,t.textContent=s,n.setAttribute(`hidden`,``),e.title=d??`${s} in this browser.`,c!==`generating`&&(l=[],r.replaceChildren())}function f(){d(`idle`,s?`Ready`:`Idle`,s?`Model ready. Inference and tools run in this browser.`:`Model loads when you send a message. Inference and tools run in this browser.`)}function p(e){if(!Number.isFinite(e)||e<0){d(`generating`,`Generating…`);return}d(`generating`,`${e<10?e.toFixed(1):Math.round(e)} tok/s`,`Live token generation speed, including thinking tokens. Prompt-processing time is excluded.`),l.push(e),l.length>12&&l.shift();let t=Math.max(40,...l),i=[...Array(12-l.length).fill(null),...l];r.replaceChildren(...i.map((e,n)=>{if(e===null||e===0){let t=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`);return t.setAttribute(`cx`,String(n*4+1)),t.setAttribute(`cy`,`17`),t.setAttribute(`r`,`1`),t.setAttribute(`opacity`,e===null?`.35`:`.6`),t}let r=document.createElementNS(`http://www.w3.org/2000/svg`,`rect`),i=Math.max(2,Math.min(16,e/t*16));return r.setAttribute(`x`,String(n*4)),r.setAttribute(`y`,(18-i).toFixed(2)),r.setAttribute(`width`,`2`),r.setAttribute(`height`,i.toFixed(2)),r.setAttribute(`rx`,`1`),r})),n.removeAttribute(`hidden`),u=setTimeout(()=>{d(`generating`,`Generating…`),l=[],r.replaceChildren()},2e3)}return f(),{update(e){e.type===`loaded`?(s=!0,f()):e.type===`idle`||e.type===`initialized`?f():e.type===`fatal`?(s=!1,d(`error`,`Unavailable`)):e.type===`busy`?e.action===`load`?d(`loading`,`Loading…`,e.cachedOnly?`Loading local model…`:void 0):e.action===`prompt`?d(`prefill`,`Reading prompt…`):e.action===`shell`?d(`tool`,`Running bash…`):e.action===`read`?d(`tool`,`Reading file…`):e.action===`write`?d(`tool`,`Writing file…`):d(`working`,`Working…`):e.type===`load_progress`?d(`loading`,e.phase===`download`&&e.loaded<e.total?`Downloading ${Math.round(e.loaded/e.total*100)}%`:e.phase===`warmup`?`Warming up…`:`Preparing…`):e.type===`inference_activity`?e.phase===`prefill`?d(`prefill`,`Reading prompt…`):e.phase===`decode`?p(e.rate):(c===`generating`||c===`prefill`)&&d(`working`,`Working…`):e.type===`agent_event`&&e.event.type===`tool_execution_start`&&d(`tool`,{bash:`Running bash…`,read:`Reading file…`,write:`Writing file…`,edit:`Editing file…`}[e.event.toolName]??`Running tool…`)}}}var Kg={default:`#b0b0bd`,markdown:`#519aba`,csv:`#8dc149`,json:`#cbcb41`,javascript:`#cbcb41`,typescript:`#519aba`,react:`#519aba`,html:`#e37933`,css:`#519aba`,python:`#519aba`,shell:`#8dc149`,config:`#b0b0bd`,image:`#a074c4`,svg:`#a074c4`,git:`#e37933`,pdf:`#cc3e44`,zip:`#b0b0bd`,db:`#cbcb41`},qg={md:`markdown`,markdown:`markdown`,mdx:`markdown`,csv:`csv`,tsv:`csv`,json:`json`,jsonc:`json`,jsonl:`json`,js:`javascript`,mjs:`javascript`,cjs:`javascript`,ts:`typescript`,mts:`typescript`,cts:`typescript`,jsx:`react`,tsx:`react`,html:`html`,htm:`html`,xml:`html`,css:`css`,scss:`css`,sass:`css`,less:`css`,py:`python`,pyi:`python`,sh:`shell`,bash:`shell`,zsh:`shell`,fish:`shell`,yaml:`config`,yml:`config`,toml:`config`,ini:`config`,conf:`config`,env:`config`,png:`image`,jpg:`image`,jpeg:`image`,gif:`image`,webp:`image`,avif:`image`,ico:`image`,svg:`svg`,pdf:`pdf`,zip:`zip`,gz:`zip`,tar:`zip`,sql:`db`,sqlite:`db`,db:`db`};function Jg(e){let t=e.split(`/`).at(-1).toLowerCase();return[`.gitignore`,`.gitattributes`,`.gitmodules`].includes(t)?`git`:t===`.env`||t.startsWith(`.env.`)||t===`.editorconfig`?`config`:qg[t.split(`.`).at(-1)]??`default`}function Yg(e){let t=Jg(e),n=document.createElement(`span`);return n.className=`file-icon`,n.dataset.kind=t,n.setAttribute(`aria-hidden`,`true`),n.style.setProperty(`--file-color`,Kg[t]),n.style.setProperty(`--file-icon`,`url("${new URL(`file-icons/${t}.svg`,document.baseURI).href}")`),n}var Xg={html:`markup`,htm:`markup`,xml:`markup`,svg:`markup`,vue:`markup`,css:`css`,js:`javascript`,mjs:`javascript`,cjs:`javascript`,jsx:`jsx`,ts:`typescript`,mts:`typescript`,cts:`typescript`,tsx:`tsx`,json:`json`,ipynb:`json`,md:`markdown`,markdown:`markdown`,py:`python`,pyw:`python`,sh:`bash`,bash:`bash`,zsh:`bash`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sql:`sql`,csv:`csv`,c:`c`,h:`c`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,hpp:`cpp`,cs:`csharp`,java:`java`,go:`go`,rs:`rust`,diff:`diff`,patch:`diff`};function Zg(e=``){let t=e.split(`/`).at(-1).toLowerCase();return/^dockerfile(?:\.|$)/.test(t)?`docker`:/^\.(?:bashrc|bash_profile|zshrc|profile)$/.test(t)?`bash`:Xg[t.split(`.`).at(-1)]??null}function Qg(e){if(e.length>2e5)return!1;let t=1;for(let n=0;n<e.length;n++)if(e.charCodeAt(n)===10&&++t>5e3)return!1;return!0}function $g(e){let t=e.querySelector(`#editor`),n=e.querySelector(`#editor-highlight`),r=``,i=0,a,o,s,c=!1,l=!1,u;function d(){n.style.width=t.clientWidth+`px`,n.style.height=t.clientHeight+`px`,n.scrollTop=t.scrollTop,n.scrollLeft=t.scrollLeft}function f(){e.classList.remove(`is-highlighted`)}function p(){clearTimeout(o),s?.terminate(),s=void 0,c=!1}function m(){if(c||!u)return;let t=u;u=void 0;try{s||(s=new Worker(new URL(new URL(`editor-highlight.worker-oPpFVFqT.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),s.onmessage=({data:t})=>{clearTimeout(o),c=!1,t.id===i&&t.html!==null&&(n.innerHTML=t.html+``,d(),e.classList.add(`is-highlighted`)),m()},s.onerror=()=>{p(),u=void 0}),c=!0,s.postMessage(t),o=setTimeout(()=>{p(),m()},1500)}catch{p()}}function h(n=0){i++,clearTimeout(a),u=void 0,f();let o=Zg(r),s=t.value;if(e.dataset.language=o??`plain`,l||!s||!o||!Qg(s))return;let c=i;a=setTimeout(()=>{u={id:c,text:s,language:o},m()},n)}t.addEventListener(`input`,()=>h(80)),t.addEventListener(`compositionstart`,()=>{l=!0,h()}),t.addEventListener(`compositionend`,()=>{l=!1,h(80)}),t.addEventListener(`scroll`,d,{passive:!0});let g=new ResizeObserver(d);return g.observe(t),{setFile(e,n){if(r===e&&t.value===n)return;let i=r!==e;r=e,t.value!==n&&(t.value=n),i&&(t.scrollTop=0,t.scrollLeft=0),h()},dispose(){clearTimeout(a),p(),g.disconnect()}}}var $=e=>document.querySelector(e),e_=new Worker(new URL(new URL(`agent.worker-Dh8h4jNH.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),t_=new Map,n_=1,r_=!1,i_=!1,a_,o_=!1,s_={},c_=[],l_,u_,d_=new Promise(e=>{l_=e}),f_={events:[],generations:[],runtimeSamples:[],device:null,contextUsage:Mg([])},p_=Gg($(`#runtime-meter`)),m_=$g($(`.editor-input`)),h_=Lg($(`#pi-terminal`),{load:()=>d_.then(O_),prompt:e=>d_.then(()=>k_(e)),newChat:()=>d_.then(A_),stop:()=>v_(`stop`),shell:e=>{if(o_)throw Error(`Save your file edits before running commands.`);return v_(`shell`,{command:e})}}),g_=Rg($(`#model-dialog`),{load:O_,stop:()=>v_(`stop`),onClose:()=>h_.focus()}),__=Wg($(`.workspace > .terminal`),{run:async e=>{if(await d_,o_)throw Error(`Save your file edits before running commands.`);if(r_)throw Error(`Wait for Pi to finish or stop the current task first.`);return v_(`shell`,{command:e})}});function v_(e,t){return new Promise((n,r)=>{let i=n_++;t_.set(i,{resolve:n,reject:r}),e_.postMessage({id:i,action:e,args:t})})}function y_(e){$(`#notice`).textContent=e,$(`#notice`).hidden=!e}function b_(e){return window.self===window.top||!/denied|storage directory access/i.test(e)?e:($(`#open-tab`).href=location.href,$(`#open-tab`).hidden=!1,`Your browser blocked storage in this embedded app. Open the workspace in a new tab to load the model and save files.`)}function x_(){$(`#load`).disabled=r_||i_,$(`#load`).classList.toggle(`is-loaded`,i_),i_?$(`#load`).textContent=`Loaded`:r_||($(`#load`).textContent=`Load model`),$(`#load`).title=$(`#load-status`).textContent+` `+$(`#load-detail`).textContent,$(`#send`).disabled=r_,$(`#newline`).disabled=r_,h_.setState({busy:r_,loaded:i_,activity:$(`#activity`).textContent}),$(`#stop`).hidden=!r_;for(let e of[`#new-chat`,`#add-file`,`#upload`])$(e).disabled=r_;__.setBusy(r_),$(`#save`).disabled=r_||!a_||!o_,$(`#editor`).disabled=r_||!a_}function S_(){h_.setFiles(s_),$(`#files`).replaceChildren();for(let e of Object.keys(s_).sort()){let t=document.createElement(`button`),n=document.createElement(`span`);n.className=`file-name`,n.textContent=e.replace(/^\/workspace\//,``),t.append(Yg(e),n),t.title=e,t.classList.toggle(`selected`,e===a_),t.onclick=()=>C_(e),$(`#files`).append(t)}a_&&!o_&&m_.setFile(a_,s_[a_]??``)}function C_(e){if(u_=void 0,o_){y_(`Save the open file before selecting another file.`);return}a_=e,$(`#filename`).textContent=e,$(`#filetype`).replaceChildren(Yg(e)),S_(),x_()}function w_(){if(o_){u_=void 0;return}if(!u_||!Object.hasOwn(s_,u_))return;let e=u_,t=e!==a_;C_(e),t&&($(`#editor`).scrollTop=0,$(`#editor`).scrollLeft=0);let n=[...$(`#files`).children].find(t=>t.title===e);if(n){let e=n.getBoundingClientRect(),t=$(`#files`).getBoundingClientRect();e.top<t.top?$(`#files`).scrollTop+=e.top-t.top:e.bottom>t.bottom&&($(`#files`).scrollTop+=e.bottom-t.bottom)}}function T_(){h_.setMessages(c_)}function E_(e){f_.contextUsage=e,h_.setState({contextUsage:e})}e_.onmessage=({data:e})=>{if(p_.update(e),e.type===`inference_activity`&&(f_.runtimeSamples.push(e),f_.runtimeSamples.length>160&&f_.runtimeSamples.shift()),e.type===`reply`){let t=t_.get(e.id);t_.delete(e.id),e.error?t?.reject(Object.assign(Error(e.error),{name:e.errorName||`Error`,code:e.errorCode})):t?.resolve(e.value)}else if(e.type===`initialized`)s_=e.files,c_=e.messages,S_(),T_(),E_(Mg(c_)),s_[`/workspace/README.md`]&&C_(`/workspace/README.md`),document.activeElement===document.body&&h_.focus(),l_();else if(e.type===`busy`)e.action===`load`&&($(`#load`).textContent=`Loading…`),r_=!0,$(`#activity`).textContent=e.action===`prompt`?`Pi is working…`:e.action===`load`?e.cachedOnly?`Loading local model…`:`Loading model…`:`Working…`,x_();else if(e.type===`idle`)r_=!1,$(`#activity`).textContent=i_?`Ready · running on your device`:`Files and chat are saved on this device.`,x_();else if(e.type===`workspace`)s_=e.files,S_(),w_();else if(e.type===`device`)f_.device=e.device;else if(e.type===`load_progress`)g_.update(e),e.phase===`download`?($(`#progress`).hidden=!1,$(`#progress`).value=e.loaded/e.total*100,$(`#load-status`).textContent=e.loaded===e.total?`Download verified. Preparing model…`:`Downloading and verifying model…`,$(`#load-detail`).textContent=`${(e.loaded/1e9).toFixed(2)} / ${(e.total/1e9).toFixed(2)} GB · ${Math.round(e.loaded/e.total*100)}%${e.cached?` · ${(e.cached/1e9).toFixed(2)} GB cached`:``}`,$(`#load`).textContent=`Loading ${Math.round(e.loaded/e.total*100)}%`):($(`#load-status`).textContent=e.phase===`compile`?`Preparing WebGPU session…`:`Warming up GPU shaders…`,$(`#progress`).removeAttribute(`value`),$(`#load`).textContent=e.phase===`compile`?`Preparing…`:`Almost ready…`),$(`#load`).title=$(`#load-status`).textContent+` `+$(`#load-detail`).textContent;else if(e.type===`loaded`)i_=!0,f_.device=e.device,$(`#progress`).hidden=!0,$(`#load`).textContent=`Loaded`,$(`#load-status`).textContent=`Ready. Model inference and tools run entirely in this browser.`,$(`#load-detail`).textContent=e.cachedBytes?`Verified model restored from browser storage.`:`SHA-256 verified · model cached for next time.`,x_();else if(e.type===`agent_event`){let t=e.event;if(f_.events.push(t.type),f_.events.length>500&&f_.events.shift(),t.message){let e=c_.findIndex(e=>e.timestamp===t.message.timestamp&&e.role===t.message.role&&e.toolCallId===t.message.toolCallId);e<0?c_.push(t.message):c_[e]=t.message,T_()}t.type===`tool_execution_start`&&($(`#activity`).textContent=`Running ${t.toolName}…`),t.type===`tool_execution_end`&&t.toolName===`read`&&!t.isError&&typeof t.result?.details?.path==`string`&&(u_=t.result.details.path,w_()),t.type===`turn_start`&&($(`#activity`).textContent=`Pi is thinking…`),h_.setState({activity:$(`#activity`).textContent})}else e.type===`context_usage`?E_({inputTokens:e.inputTokens,outputTokens:e.outputTokens}):e.type===`generation`?(f_.generations.push(e),f_.generations.length>100&&f_.generations.shift()):e.type===`context_trim`?y_(`Older turns were left out of the model context. Your full chat remains saved.`):e.type===`notice`?y_(e.text):e.type===`persistence_error`?y_(b_(e.error)):e.type===`fatal`&&(i_=!1,y_(e.error),x_())},e_.onerror=e=>{p_.update({type:`fatal`});let t=Error(e.message||`The worker stopped. Reload to restore your saved workspace.`);y_(t.message);for(let e of t_.values())e.reject(t);t_.clear(),r_=!1,i_=!1,x_()};var D_=e=>async t=>{t?.preventDefault();try{await d_,await e(t)}catch(e){y_(e.message)}};async function O_({cachedOnly:e=!1}={}){y_(``);let t=new URLSearchParams(location.search);try{return await v_(`load`,{runtimeURL:new URL(`./runtime/`,location.href).href,local:t.get(`source`)===`local`,origin:location.origin,limit128:t.has(`limit128`),cachedOnly:e})}catch(e){throw e.message=b_(e.message),$(`#load-status`).textContent=e.message,$(`#progress`).hidden=!0,e}}async function k_(e){if(!e.trim())return;if(o_)throw Error(`Save your file edits before asking Pi to work on them.`);if(!i_){let t;if(await v_(`cache_status`))try{await O_({cachedOnly:!0})}catch(e){if(e.name===`AbortError`)throw e;e.code!==`MODEL_CACHE_MISS`&&(t=e.message)}if(!i_&&!await g_.request(e,{errorMessage:t}))throw new DOMException(`Message kept for later.`,`AbortError`)}y_(``);let t=await v_(`prompt`,{text:e});return c_=t.messages,T_(),t}$(`#load`).onclick=D_(O_),$(`#send`).onclick=()=>{h_.submit(),h_.focus()},$(`#newline`).onclick=()=>h_.newline(),$(`#stop`).onclick=D_(()=>v_(`stop`)),$(`.terminal-panel`).addEventListener(`click`,e=>{!e.defaultPrevented&&e.button===0&&e.target instanceof Element&&(e.target.closest(`#pi-terminal, button, a, input, textarea, select, label, summary, [role="button"], [contenteditable]`)||window.getSelection()?.isCollapsed!==!1&&h_.focus())});async function A_(){u_=void 0,c_=(await v_(`new_chat`)).messages,E_(Mg(c_)),h_.setMessages(c_,{reset:!0}),y_(``)}$(`#new-chat`).onclick=D_(A_),$(`#editor`).oninput=()=>{o_=!0,x_()},$(`#save`).onclick=D_(async()=>{await v_(`write`,{path:a_,content:$(`#editor`).value}),o_=!1,S_(),x_(),y_(``)}),$(`#add-file`).onclick=D_(async()=>{if(o_)throw Error(`Save the open file first.`);let e=window.prompt(`File path, relative to /workspace:`);if(!e?.trim())return;let t=e.startsWith(`/`)?e:`/workspace/`+e;if(Object.hasOwn(s_,t))throw Error(`That file already exists.`);await v_(`write`,{path:t,content:``}),C_(t)}),$(`#upload`).onchange=D_(async()=>{if(o_)throw Error(`Save the open file first.`);for(let e of $(`#upload`).files){if(e.size>1024**2)throw Error(`Import text files of 1 MiB or less.`);let t=await e.text();if(t.includes(`\0`))throw Error(`Import supports text files only.`);let n=`/workspace/`+e.name;if(Object.hasOwn(s_,n))throw Error(e.name+` already exists. Rename it before importing.`);await v_(`write`,{path:n,content:t}),C_(n)}$(`#upload`).value=``}),$(`#export`).onclick=D_(async()=>{let e=await v_(`snapshot`),t=URL.createObjectURL(new Blob([JSON.stringify(e,null,2)],{type:`application/json`})),n=document.createElement(`a`);n.href=t,n.download=`pi-workspace.json`,n.click(),setTimeout(()=>URL.revokeObjectURL(t),1e3)}),window.browserPi={ready:d_,load:O_,prompt:k_,rpc:v_,diagnostics:f_,terminal:h_,runtimeMeter:p_,get loaded(){return i_},get busy(){return r_}},x_();156 unmodified lines157158159160156 unmodified lines`)),r.style.height=`auto`,r.style.height=Math.min(104,Math.max(32,r.scrollHeight))+`px`,i.scrollTop=r.scrollTop,i.scrollLeft=r.scrollLeft,v()}function b(e){r.value=e,y(),r.setSelectionRange(e.length,e.length)}function x(){m||(d.length=0,a.replaceChildren(l.cloneNode(!0)),v())}function S(e,t,n){if(!t)return;let r=document.createElement(`pre`);r.className=n,r.textContent=Hg(t),e.append(r)}o.onsubmit=async e=>{e.preventDefault();let n=r.value;if(m||h||!n.trim())return;m=!0,u.at(-1)!==n&&u.push(n),u.length>50&&u.shift(),f=u.length,p=``,b(``),r.focus(),d.length||a.replaceChildren();let i=document.createElement(`section`);i.className=`shell-entry`;let o=document.createElement(`div`);o.className=`shell-entry-heading`;let s=document.createElement(`span`);s.className=`shell-prompt`,s.textContent=`$`;let c=document.createElement(`pre`);c.className=`shell-code`,c.append(Ug(Hg(n)));let l=document.createElement(`span`);l.className=`shell-status`,l.textContent=`Running…`,o.append(s,c,l),i.append(o),a.append(i),d.push(i),_();try{let e=await t(n),r=g();S(i,e.stdout,`shell-stdout`),S(i,e.stderr,`shell-stderr`),l.classList.add(e.exitCode===0?`success`:`error`),l.textContent=`[exit ${e.exitCode}]`,r&&_()}catch(e){let t=g();S(i,e.message,`shell-stderr`),l.classList.add(`error`),l.textContent=`[error]`,r.value||b(n),t&&_()}finally{for(;d.length>1&&(d.length>40||a.textContent.length>48e3);)d.shift().remove();m=!1,v()}},r.addEventListener(`input`,()=>{f=u.length,p=r.value,y()}),r.addEventListener(`scroll`,()=>{i.scrollTop=r.scrollTop,i.scrollLeft=r.scrollLeft}),r.addEventListener(`keydown`,e=>{if(e.isComposing||e.keyCode===229)return;if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),o.requestSubmit();return}if(e.ctrlKey&&e.key.toLowerCase()===`l`){e.preventDefault(),x();return}if(e.ctrlKey||e.altKey||e.metaKey||e.shiftKey||r.selectionStart!==r.selectionEnd)return;let t=!r.value.slice(0,r.selectionStart).includes(``),n=!r.value.slice(r.selectionEnd).includes(``);e.key===`ArrowUp`&&t&&f>0?(e.preventDefault(),f===u.length&&(p=r.value),b(u[--f])):e.key===`ArrowDown`&&n&&f<u.length&&(e.preventDefault(),b(++f===u.length?p:u[f]))}),c.onclick=()=>{x(),r.focus()};let C=0;return new ResizeObserver(([e])=>{e.contentRect.width!==C&&(C=e.contentRect.width,y())}).observe(r.parentElement),y(),{setBusy(e){h=e,v()}}}function Gg(e){let t=e.querySelector(`.runtime-value`),n=e.querySelector(`.runtime-sparkline`),r=e.querySelector(`.runtime-bars`),i=e.querySelector(`[role="status"]`),a=e.querySelector(`.runtime-engine`),o=e.querySelector(`.runtime-content`);new ResizeObserver(([t])=>{e.style.width=`calc(${Math.ceil(t.contentRect.width)}px + 2 * var(--runtime-padding))`}).observe(o);let s=!1,c,l=[],u;function d(o,s,d){clearTimeout(u),o!==c&&(i.textContent=d??`${s} in this browser.`),c=o,a.textContent=c===`tool`?`JavaScript`:`WebGPU`,e.dataset.state=c,t.textContent=s,n.setAttribute(`hidden`,``),e.title=d??`${s} in this browser.`,c!==`generating`&&(l=[],r.replaceChildren())}function f(){d(`idle`,s?`Ready`:`Idle`,s?`Model ready. Inference and tools run in this browser.`:`Model loads when you send a message. Inference and tools run in this browser.`)}function p(e){if(!Number.isFinite(e)||e<0){d(`generating`,`Generating…`);return}d(`generating`,`${e<10?e.toFixed(1):Math.round(e)} tok/s`,`Live token generation speed, including thinking tokens. Prompt-processing time is excluded.`),l.push(e),l.length>12&&l.shift();let t=Math.max(40,...l),i=[...Array(12-l.length).fill(null),...l];r.replaceChildren(...i.map((e,n)=>{if(e===null||e===0){let t=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`);return t.setAttribute(`cx`,String(n*4+1)),t.setAttribute(`cy`,`17`),t.setAttribute(`r`,`1`),t.setAttribute(`opacity`,e===null?`.35`:`.6`),t}let r=document.createElementNS(`http://www.w3.org/2000/svg`,`rect`),i=Math.max(2,Math.min(16,e/t*16));return r.setAttribute(`x`,String(n*4)),r.setAttribute(`y`,(18-i).toFixed(2)),r.setAttribute(`width`,`2`),r.setAttribute(`height`,i.toFixed(2)),r.setAttribute(`rx`,`1`),r})),n.removeAttribute(`hidden`),u=setTimeout(()=>{d(`generating`,`Generating…`),l=[],r.replaceChildren()},2e3)}return f(),{update(e){e.type===`loaded`?(s=!0,f()):e.type===`idle`||e.type===`initialized`?f():e.type===`fatal`?(s=!1,d(`error`,`Unavailable`)):e.type===`busy`?e.action===`load`?d(`loading`,`Loading…`,e.cachedOnly?`Loading local model…`:void 0):e.action===`prompt`?d(`prefill`,`Reading prompt…`):e.action===`shell`?d(`tool`,`Running bash…`):e.action===`read`?d(`tool`,`Reading file…`):e.action===`write`?d(`tool`,`Writing file…`):d(`working`,`Working…`):e.type===`load_progress`?d(`loading`,e.phase===`download`&&e.loaded<e.total?`Downloading ${Math.round(e.loaded/e.total*100)}%`:e.phase===`warmup`?`Warming up…`:`Preparing…`):e.type===`inference_activity`?e.phase===`prefill`?d(`prefill`,`Reading prompt…`):e.phase===`decode`?p(e.rate):(c===`generating`||c===`prefill`)&&d(`working`,`Working…`):e.type===`agent_event`&&e.event.type===`tool_execution_start`&&d(`tool`,{bash:`Running bash…`,read:`Reading file…`,write:`Writing file…`,edit:`Editing file…`}[e.event.toolName]??`Running tool…`)}}}var Kg={default:`#b0b0bd`,markdown:`#519aba`,csv:`#8dc149`,json:`#cbcb41`,javascript:`#cbcb41`,typescript:`#519aba`,react:`#519aba`,html:`#e37933`,css:`#519aba`,python:`#519aba`,shell:`#8dc149`,config:`#b0b0bd`,image:`#a074c4`,svg:`#a074c4`,git:`#e37933`,pdf:`#cc3e44`,zip:`#b0b0bd`,db:`#cbcb41`},qg={md:`markdown`,markdown:`markdown`,mdx:`markdown`,csv:`csv`,tsv:`csv`,json:`json`,jsonc:`json`,jsonl:`json`,js:`javascript`,mjs:`javascript`,cjs:`javascript`,ts:`typescript`,mts:`typescript`,cts:`typescript`,jsx:`react`,tsx:`react`,html:`html`,htm:`html`,xml:`html`,css:`css`,scss:`css`,sass:`css`,less:`css`,py:`python`,pyi:`python`,sh:`shell`,bash:`shell`,zsh:`shell`,fish:`shell`,yaml:`config`,yml:`config`,toml:`config`,ini:`config`,conf:`config`,env:`config`,png:`image`,jpg:`image`,jpeg:`image`,gif:`image`,webp:`image`,avif:`image`,ico:`image`,svg:`svg`,pdf:`pdf`,zip:`zip`,gz:`zip`,tar:`zip`,sql:`db`,sqlite:`db`,db:`db`};function Jg(e){let t=e.split(`/`).at(-1).toLowerCase();return[`.gitignore`,`.gitattributes`,`.gitmodules`].includes(t)?`git`:t===`.env`||t.startsWith(`.env.`)||t===`.editorconfig`?`config`:qg[t.split(`.`).at(-1)]??`default`}function Yg(e){let t=Jg(e),n=document.createElement(`span`);return n.className=`file-icon`,n.dataset.kind=t,n.setAttribute(`aria-hidden`,`true`),n.style.setProperty(`--file-color`,Kg[t]),n.style.setProperty(`--file-icon`,`url("${new URL(`file-icons/${t}.svg`,document.baseURI).href}")`),n}var Xg={html:`markup`,htm:`markup`,xml:`markup`,svg:`markup`,vue:`markup`,css:`css`,js:`javascript`,mjs:`javascript`,cjs:`javascript`,jsx:`jsx`,ts:`typescript`,mts:`typescript`,cts:`typescript`,tsx:`tsx`,json:`json`,ipynb:`json`,md:`markdown`,markdown:`markdown`,py:`python`,pyw:`python`,sh:`bash`,bash:`bash`,zsh:`bash`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sql:`sql`,csv:`csv`,c:`c`,h:`c`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,hpp:`cpp`,cs:`csharp`,java:`java`,go:`go`,rs:`rust`,diff:`diff`,patch:`diff`};function Zg(e=``){let t=e.split(`/`).at(-1).toLowerCase();return/^dockerfile(?:\.|$)/.test(t)?`docker`:/^\.(?:bashrc|bash_profile|zshrc|profile)$/.test(t)?`bash`:Xg[t.split(`.`).at(-1)]??null}function Qg(e){if(e.length>2e5)return!1;let t=1;for(let n=0;n<e.length;n++)if(e.charCodeAt(n)===10&&++t>5e3)return!1;return!0}function $g(e){let t=e.querySelector(`#editor`),n=e.querySelector(`#editor-highlight`),r=``,i=0,a,o,s,c=!1,l=!1,u;function d(){n.style.width=t.clientWidth+`px`,n.style.height=t.clientHeight+`px`,n.scrollTop=t.scrollTop,n.scrollLeft=t.scrollLeft}function f(){e.classList.remove(`is-highlighted`)}function p(){clearTimeout(o),s?.terminate(),s=void 0,c=!1}function m(){if(c||!u)return;let t=u;u=void 0;try{s||(s=new Worker(new URL(new URL(`editor-highlight.worker-oPpFVFqT.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),s.onmessage=({data:t})=>{clearTimeout(o),c=!1,t.id===i&&t.html!==null&&(n.innerHTML=t.html+``,d(),e.classList.add(`is-highlighted`)),m()},s.onerror=()=>{p(),u=void 0}),c=!0,s.postMessage(t),o=setTimeout(()=>{p(),m()},1500)}catch{p()}}function h(n=0){i++,clearTimeout(a),u=void 0,f();let o=Zg(r),s=t.value;if(e.dataset.language=o??`plain`,l||!s||!o||!Qg(s))return;let c=i;a=setTimeout(()=>{u={id:c,text:s,language:o},m()},n)}t.addEventListener(`input`,()=>h(80)),t.addEventListener(`compositionstart`,()=>{l=!0,h()}),t.addEventListener(`compositionend`,()=>{l=!1,h(80)}),t.addEventListener(`scroll`,d,{passive:!0});let g=new ResizeObserver(d);return g.observe(t),{setFile(e,n){if(r===e&&t.value===n)return;let i=r!==e;r=e,t.value!==n&&(t.value=n),i&&(t.scrollTop=0,t.scrollLeft=0),h()},dispose(){clearTimeout(a),p(),g.disconnect()}}}var $=e=>document.querySelector(e),e_=new Worker(new URL(new URL(`agent.worker-TGe-Bgx8.js`,import.meta.url).href,``+import.meta.url),{type:`module`}),t_=new Map,n_=1,r_=!1,i_=!1,a_,o_=!1,s_={},c_=[],l_,u_,d_=new Promise(e=>{l_=e}),f_={events:[],generations:[],runtimeSamples:[],device:null,contextUsage:Mg([])},p_=Gg($(`#runtime-meter`)),m_=$g($(`.editor-input`)),h_=Lg($(`#pi-terminal`),{load:()=>d_.then(O_),prompt:e=>d_.then(()=>k_(e)),newChat:()=>d_.then(A_),stop:()=>v_(`stop`),shell:e=>{if(o_)throw Error(`Save your file edits before running commands.`);return v_(`shell`,{command:e})}}),g_=Rg($(`#model-dialog`),{load:O_,stop:()=>v_(`stop`),onClose:()=>h_.focus()}),__=Wg($(`.workspace > .terminal`),{run:async e=>{if(await d_,o_)throw Error(`Save your file edits before running commands.`);if(r_)throw Error(`Wait for Pi to finish or stop the current task first.`);return v_(`shell`,{command:e})}});function v_(e,t){return new Promise((n,r)=>{let i=n_++;t_.set(i,{resolve:n,reject:r}),e_.postMessage({id:i,action:e,args:t})})}function y_(e){$(`#notice`).textContent=e,$(`#notice`).hidden=!e}function b_(e){return window.self===window.top||!/denied|storage directory access/i.test(e)?e:($(`#open-tab`).href=location.href,$(`#open-tab`).hidden=!1,`Your browser blocked storage in this embedded app. Open the workspace in a new tab to load the model and save files.`)}function x_(){$(`#load`).disabled=r_||i_,$(`#load`).classList.toggle(`is-loaded`,i_),i_?$(`#load`).textContent=`Loaded`:r_||($(`#load`).textContent=`Load model`),$(`#load`).title=$(`#load-status`).textContent+` `+$(`#load-detail`).textContent,$(`#send`).disabled=r_,$(`#newline`).disabled=r_,h_.setState({busy:r_,loaded:i_,activity:$(`#activity`).textContent}),$(`#stop`).hidden=!r_;for(let e of[`#new-chat`,`#add-file`,`#upload`])$(e).disabled=r_;__.setBusy(r_),$(`#save`).disabled=r_||!a_||!o_,$(`#editor`).disabled=r_||!a_}function S_(){h_.setFiles(s_),$(`#files`).replaceChildren();for(let e of Object.keys(s_).sort()){let t=document.createElement(`button`),n=document.createElement(`span`);n.className=`file-name`,n.textContent=e.replace(/^\/workspace\//,``),t.append(Yg(e),n),t.title=e,t.classList.toggle(`selected`,e===a_),t.onclick=()=>C_(e),$(`#files`).append(t)}a_&&!o_&&m_.setFile(a_,s_[a_]??``)}function C_(e){if(u_=void 0,o_){y_(`Save the open file before selecting another file.`);return}a_=e,$(`#filename`).textContent=e,$(`#filetype`).replaceChildren(Yg(e)),S_(),x_()}function w_(){if(o_){u_=void 0;return}if(!u_||!Object.hasOwn(s_,u_))return;let e=u_,t=e!==a_;C_(e),t&&($(`#editor`).scrollTop=0,$(`#editor`).scrollLeft=0);let n=[...$(`#files`).children].find(t=>t.title===e);if(n){let e=n.getBoundingClientRect(),t=$(`#files`).getBoundingClientRect();e.top<t.top?$(`#files`).scrollTop+=e.top-t.top:e.bottom>t.bottom&&($(`#files`).scrollTop+=e.bottom-t.bottom)}}function T_(){h_.setMessages(c_)}function E_(e){f_.contextUsage=e,h_.setState({contextUsage:e})}e_.onmessage=({data:e})=>{if(p_.update(e),e.type===`inference_activity`&&(f_.runtimeSamples.push(e),f_.runtimeSamples.length>160&&f_.runtimeSamples.shift()),e.type===`reply`){let t=t_.get(e.id);t_.delete(e.id),e.error?t?.reject(Object.assign(Error(e.error),{name:e.errorName||`Error`,code:e.errorCode})):t?.resolve(e.value)}else if(e.type===`initialized`)s_=e.files,c_=e.messages,S_(),T_(),E_(Mg(c_)),s_[`/workspace/README.md`]&&C_(`/workspace/README.md`),document.activeElement===document.body&&h_.focus(),l_();else if(e.type===`busy`)e.action===`load`&&($(`#load`).textContent=`Loading…`),r_=!0,$(`#activity`).textContent=e.action===`prompt`?`Pi is working…`:e.action===`load`?e.cachedOnly?`Loading local model…`:`Loading model…`:`Working…`,x_();else if(e.type===`idle`)r_=!1,$(`#activity`).textContent=i_?`Ready · running on your device`:`Files and chat are saved on this device.`,x_();else if(e.type===`workspace`)s_=e.files,S_(),w_();else if(e.type===`device`)f_.device=e.device;else if(e.type===`load_progress`)g_.update(e),e.phase===`download`?($(`#progress`).hidden=!1,$(`#progress`).value=e.loaded/e.total*100,$(`#load-status`).textContent=e.loaded===e.total?`Download verified. Preparing model…`:`Downloading and verifying model…`,$(`#load-detail`).textContent=`${(e.loaded/1e9).toFixed(2)} / ${(e.total/1e9).toFixed(2)} GB · ${Math.round(e.loaded/e.total*100)}%${e.cached?` · ${(e.cached/1e9).toFixed(2)} GB cached`:``}`,$(`#load`).textContent=`Loading ${Math.round(e.loaded/e.total*100)}%`):($(`#load-status`).textContent=e.phase===`compile`?`Preparing WebGPU session…`:`Warming up GPU shaders…`,$(`#progress`).removeAttribute(`value`),$(`#load`).textContent=e.phase===`compile`?`Preparing…`:`Almost ready…`),$(`#load`).title=$(`#load-status`).textContent+` `+$(`#load-detail`).textContent;else if(e.type===`loaded`)i_=!0,f_.device=e.device,$(`#progress`).hidden=!0,$(`#load`).textContent=`Loaded`,$(`#load-status`).textContent=`Ready. Model inference and tools run entirely in this browser.`,$(`#load-detail`).textContent=e.cachedBytes?`Verified model restored from browser storage.`:`SHA-256 verified · model cached for next time.`,x_();else if(e.type===`agent_event`){let t=e.event;if(f_.events.push(t.type),f_.events.length>500&&f_.events.shift(),t.message){let e=c_.findIndex(e=>e.timestamp===t.message.timestamp&&e.role===t.message.role&&e.toolCallId===t.message.toolCallId);e<0?c_.push(t.message):c_[e]=t.message,T_()}t.type===`tool_execution_start`&&($(`#activity`).textContent=`Running ${t.toolName}…`),t.type===`tool_execution_end`&&t.toolName===`read`&&!t.isError&&typeof t.result?.details?.path==`string`&&(u_=t.result.details.path,w_()),t.type===`turn_start`&&($(`#activity`).textContent=`Pi is thinking…`),h_.setState({activity:$(`#activity`).textContent})}else e.type===`context_usage`?E_({inputTokens:e.inputTokens,outputTokens:e.outputTokens}):e.type===`generation`?(f_.generations.push(e),f_.generations.length>100&&f_.generations.shift()):e.type===`context_trim`?y_(`Older turns were left out of the model context. Your full chat remains saved.`):e.type===`notice`?y_(e.text):e.type===`persistence_error`?y_(b_(e.error)):e.type===`fatal`&&(i_=!1,y_(e.error),x_())},e_.onerror=e=>{p_.update({type:`fatal`});let t=Error(e.message||`The worker stopped. Reload to restore your saved workspace.`);y_(t.message);for(let e of t_.values())e.reject(t);t_.clear(),r_=!1,i_=!1,x_()};var D_=e=>async t=>{t?.preventDefault();try{await d_,await e(t)}catch(e){y_(e.message)}};async function O_({cachedOnly:e=!1}={}){y_(``);let t=new URLSearchParams(location.search);try{return await v_(`load`,{runtimeURL:new URL(`./runtime/`,location.href).href,local:t.get(`source`)===`local`,origin:location.origin,limit128:t.has(`limit128`),cachedOnly:e})}catch(e){throw e.message=b_(e.message),$(`#load-status`).textContent=e.message,$(`#progress`).hidden=!0,e}}async function k_(e){if(!e.trim())return;if(o_)throw Error(`Save your file edits before asking Pi to work on them.`);if(!i_){let t;if(await v_(`cache_status`))try{await O_({cachedOnly:!0})}catch(e){if(e.name===`AbortError`)throw e;e.code!==`MODEL_CACHE_MISS`&&(t=e.message)}if(!i_&&!await g_.request(e,{errorMessage:t}))throw new DOMException(`Message kept for later.`,`AbortError`)}y_(``);let t=await v_(`prompt`,{text:e});return c_=t.messages,T_(),t}$(`#load`).onclick=D_(O_),$(`#send`).onclick=()=>{h_.submit(),h_.focus()},$(`#newline`).onclick=()=>h_.newline(),$(`#stop`).onclick=D_(()=>v_(`stop`)),$(`.terminal-panel`).addEventListener(`click`,e=>{!e.defaultPrevented&&e.button===0&&e.target instanceof Element&&(e.target.closest(`#pi-terminal, button, a, input, textarea, select, label, summary, [role="button"], [contenteditable]`)||window.getSelection()?.isCollapsed!==!1&&h_.focus())});async function A_(){u_=void 0,c_=(await v_(`new_chat`)).messages,E_(Mg(c_)),h_.setMessages(c_,{reset:!0}),y_(``)}$(`#new-chat`).onclick=D_(A_),$(`#editor`).oninput=()=>{o_=!0,x_()},$(`#save`).onclick=D_(async()=>{await v_(`write`,{path:a_,content:$(`#editor`).value}),o_=!1,S_(),x_(),y_(``)}),$(`#add-file`).onclick=D_(async()=>{if(o_)throw Error(`Save the open file first.`);let e=window.prompt(`File path, relative to /workspace:`);if(!e?.trim())return;let t=e.startsWith(`/`)?e:`/workspace/`+e;if(Object.hasOwn(s_,t))throw Error(`That file already exists.`);await v_(`write`,{path:t,content:``}),C_(t)}),$(`#upload`).onchange=D_(async()=>{if(o_)throw Error(`Save the open file first.`);for(let e of $(`#upload`).files){if(e.size>1024**2)throw Error(`Import text files of 1 MiB or less.`);let t=await e.text();if(t.includes(`\0`))throw Error(`Import supports text files only.`);let n=`/workspace/`+e.name;if(Object.hasOwn(s_,n))throw Error(e.name+` already exists. Rename it before importing.`);await v_(`write`,{path:n,content:t}),C_(n)}$(`#upload`).value=``}),$(`#export`).onclick=D_(async()=>{let e=await v_(`snapshot`),t=URL.createObjectURL(new Blob([JSON.stringify(e,null,2)],{type:`application/json`})),n=document.createElement(`a`);n.href=t,n.download=`pi-workspace.json`,n.click(),setTimeout(()=>URL.revokeObjectURL(t),1e3)}),window.browserPi={ready:d_,load:O_,prompt:k_,rpc:v_,diagnostics:f_,terminal:h_,runtimeMeter:p_,get loaded(){return i_},get busy(){return r_}},x_();
168 unmodified lines169170171172173174175176239 unmodified lines41641741841942042142242342442542642742842943043143243343443543643784 unmodified lines522523524525526527528168 unmodified lines"sha256": "f92958fc5397fff319591bbf7ea751d96719e9f07a46544036a26a91de90e5d8"},"app/src/agent.worker.mjs": {"bytes": 6613,"sha256": "30c0f6779c82442073a32e67bc0b66aa6bdd7c39e4fa56bfeabd5215f4a44da0"},"app/src/context-usage.mjs": {"bytes": 870,239 unmodified lines"bytes": 1679,"sha256": "eab9d66533efd95e346d22f3f455c4c77a85c1386e82e14f3e72c4fdbb8d9c16"},"assets/agent.worker-Dh8h4jNH.js": {"bytes": 2099024,"sha256": "caa8afcd243bf5a4dc1564365f32f6502258a49fe7110d1959f78110268b21a0"},"assets/editor-highlight.worker-oPpFVFqT.js": {"bytes": 61457,"sha256": "afbff552b13ac05ed7675b7e3e4232cffa8a544c68ec33634d798803472443d7"},"assets/index-BuQ89xEV.css": {"bytes": 26203,"sha256": "124f95e52fe537fc3b14d22c6128da96b80d8a8098a8d5bbf7e6cc1517173227"},"assets/index-DrI7tOtX.js": {"bytes": 758393,"sha256": "13788716bc94c7011f7d56b95e1e3dcd5f8297d7fa0e273e39a672a4108569b7"},"assets/ort-wasm-simd-threaded.asyncify-DMmc6YqF.wasm": {"bytes": 23567050,"sha256": "e0c0c6d3e73d43b8a249972f8358f845b08cc16fec3c80efafdf8bed40366786"84 unmodified lines},"index.html": {"bytes": 9277,"sha256": "177d4fc0a8ad90b35ddc5dea7615d732d49885a383b6e5b61f08caadbefb3e6d"},"licenses/dependencies.txt": {"bytes": 1386543,168 unmodified lines169170171172173174175176239 unmodified lines41641741841942042142242342442542642742842943043143243343443543643784 unmodified lines522523524525526527528168 unmodified lines"sha256": "f92958fc5397fff319591bbf7ea751d96719e9f07a46544036a26a91de90e5d8"},"app/src/agent.worker.mjs": {"bytes": 6574,"sha256": "1d50abbc1cfdffeda353d945a4f9cd5b61dc008b05677b82a68bcccc438621a2"},"app/src/context-usage.mjs": {"bytes": 870,239 unmodified lines"bytes": 1679,"sha256": "eab9d66533efd95e346d22f3f455c4c77a85c1386e82e14f3e72c4fdbb8d9c16"},"assets/agent.worker-TGe-Bgx8.js": {"bytes": 2098985,"sha256": "060d452a120d9b7e48f0ff776f8fa161c717609ff1a426d408b70e5e7016ddf0"},"assets/editor-highlight.worker-oPpFVFqT.js": {"bytes": 61457,"sha256": "afbff552b13ac05ed7675b7e3e4232cffa8a544c68ec33634d798803472443d7"},"assets/index-BhfwGLUh.js": {"bytes": 758393,"sha256": "9793aa45e80b876de808809fcfca985d9156346c09d67bb962fececb22f60d38"},"assets/index-BuQ89xEV.css": {"bytes": 26203,"sha256": "124f95e52fe537fc3b14d22c6128da96b80d8a8098a8d5bbf7e6cc1517173227"},"assets/ort-wasm-simd-threaded.asyncify-DMmc6YqF.wasm": {"bytes": 23567050,"sha256": "e0c0c6d3e73d43b8a249972f8358f845b08cc16fec3c80efafdf8bed40366786"84 unmodified lines},"index.html": {"bytes": 9277,"sha256": "e8b0e1137e70ff491db557da90e51c63373ededbf43d757c3162e9c981cb7f82"},"licenses/dependencies.txt": {"bytes": 1386543,
19 unmodified lines2021222324252619 unmodified lines<meta name="twitter:image" content="https://huggingface.co/spaces/Mike0021/MiniCPM5-2B-WebGPU-Pi/resolve/main/social-thumbnail-v1.png"><meta name="twitter:image:alt" content="Pi inside a browser window with the Chrome logo, in monochrome Macintosh style."><title>Pi · Coding agent in your browser</title><script type="module" crossorigin src="./assets/index-DrI7tOtX.js"></script><link rel="stylesheet" crossorigin href="./assets/index-BuQ89xEV.css"></head><body>19 unmodified lines2021222324252619 unmodified lines<meta name="twitter:image" content="https://huggingface.co/spaces/Mike0021/MiniCPM5-2B-WebGPU-Pi/resolve/main/social-thumbnail-v1.png"><meta name="twitter:image:alt" content="Pi inside a browser window with the Chrome logo, in monochrome Macintosh style."><title>Pi · Coding agent in your browser</title><script type="module" crossorigin src="./assets/index-BhfwGLUh.js"></script><link rel="stylesheet" crossorigin href="./assets/index-BuQ89xEV.css"></head><body>
app/src/agent.worker.mjs+2-2
assets/agent.worker-Dh8h4jNH.js → assets/agent.worker-TGe-Bgx8.jsRenamed+2-2
assets/index-DrI7tOtX.js → assets/index-BhfwGLUh.jsRenamed+1-1
deployment-manifest.json+10-10
index.html+1-1