@chainingintention/pi-web-cn 1.202606.16 → 1.202606.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{w as a,J as p,$ as h,A as m,X as g,U as f,_ as v,a0 as b}from"./vendor-editor-core-Bc1A7SO7.js";import{g as y,r as w,p as C,h as x,c as j,m as _,j as k,a as u}from"./vendor-editor-languages-D0CnB2js.js";import{d as E}from"./vendor-editor-legacy-B4QLsWF8.js";import{i as H,b as O,a as S,n as d,e as P,t as L}from"./index-Bv6Wa4z_.js";var D=Object.defineProperty,F=Object.getOwnPropertyDescriptor,i=(e,o,n,s)=>{for(var t=s>1?void 0:s?F(o,n):o,c=e.length-1,l;c>=0;c--)(l=e[c])&&(t=(s?l(o,n,t):l(t))||t);return s&&t&&D(o,n,t),t};let r=class extends H{constructor(){super(...arguments),this.content=""}firstUpdated(){this.recreateEditor()}updated(e){(e.has("content")||e.has("language"))&&this.recreateEditor()}disconnectedCallback(){this.view?.destroy(),this.view=void 0,super.disconnectedCallback()}render(){return O`<div class="host"></div>`}recreateEditor(){this.editorHost&&(this.view?.destroy(),this.view=new a({parent:this.editorHost,state:p.create({doc:this.content,extensions:[h(),m.of(g),f(v,{fallback:!0}),p.readOnly.of(!0),a.editable.of(!1),a.lineWrapping,M,...R(this.language)]})}))}};r.styles=S`
1
+ import{w as a,J as p,$ as h,A as m,X as g,U as f,_ as v,a0 as b}from"./vendor-editor-core-Bc1A7SO7.js";import{g as y,r as w,p as C,h as x,c as j,m as _,j as k,a as u}from"./vendor-editor-languages-D0CnB2js.js";import{d as E}from"./vendor-editor-legacy-B4QLsWF8.js";import{i as H,b as O,a as S,n as d,e as P,t as L}from"./index-BdQ-j_1w.js";var D=Object.defineProperty,F=Object.getOwnPropertyDescriptor,i=(e,o,n,s)=>{for(var t=s>1?void 0:s?F(o,n):o,c=e.length-1,l;c>=0;c--)(l=e[c])&&(t=(s?l(o,n,t):l(t))||t);return s&&t&&D(o,n,t),t};let r=class extends H{constructor(){super(...arguments),this.content=""}firstUpdated(){this.recreateEditor()}updated(e){(e.has("content")||e.has("language"))&&this.recreateEditor()}disconnectedCallback(){this.view?.destroy(),this.view=void 0,super.disconnectedCallback()}render(){return O`<div class="host"></div>`}recreateEditor(){this.editorHost&&(this.view?.destroy(),this.view=new a({parent:this.editorHost,state:p.create({doc:this.content,extensions:[h(),m.of(g),f(v,{fallback:!0}),p.readOnly.of(!0),a.editable.of(!1),a.lineWrapping,M,...R(this.language)]})}))}};r.styles=S`
2
2
  :host { display: block; min-height: 0; height: 100%; }
3
3
  .host { height: 100%; min-height: 0; overflow: auto; }
4
4
  `;i([d()],r.prototype,"content",2);i([d()],r.prototype,"language",2);i([P(".host")],r.prototype,"editorHost",2);r=i([L("code-viewer")],r);const M=a.theme({"&":{height:"100%",color:"var(--pi-text)",backgroundColor:"var(--pi-bg)",fontSize:"12px"},".cm-scroller":{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",lineHeight:"1.45"},".cm-gutters":{backgroundColor:"var(--pi-bg)",color:"var(--pi-dim)",borderRight:"1px solid var(--pi-border-muted)"},".cm-activeLineGutter":{backgroundColor:"transparent"},".cm-activeLine":{backgroundColor:"transparent"},".cm-content":{caretColor:"transparent"},"&.cm-focused":{outline:"none"}});function R(e){if(e===void 0)return[];switch(e){case"typescript":return[u({typescript:!0})];case"javascript":return[u()];case"json":return[k()];case"markdown":return[_()];case"css":return[j()];case"html":return[x()];case"python":return[C()];case"rust":return[w()];case"go":return[y()];case"diff":return[b.define(E)];default:return[]}}export{r as CodeViewer};
@@ -1,4 +1,4 @@
1
- import{a as E,n as m,i as K,b as l,t as R,c as h,s as D,d as w,f as _,e as F,r as c}from"./index-Bv6Wa4z_.js";import{D as T,o as S}from"./vendor-terminal-DjQ08hXu.js";import"./vendor-editor-core-Bc1A7SO7.js";import"./vendor-editor-languages-D0CnB2js.js";const $="pi-web.terminal.softKeys",N="(pointer: coarse), (max-width: 760px)";function z(e,t){return e??t}function V(e){if(e==="true")return!0;if(e==="false")return!1}function P(){return typeof window<"u"&&"matchMedia"in window?window.matchMedia(N):void 0}function M(e){return e?.matches===!0}function j(e=P()){return z(O(),M(e))}function B(){return O()!==void 0}function O(e=A()){if(e!==void 0)try{return V(e.getItem($))}catch{return}}function H(e,t=A()){if(t!==void 0)try{t.setItem($,String(e))}catch{}}function A(){if(!(typeof window>"u"))try{return window.localStorage}catch{return}}const U=[{id:"escape",label:"Esc",ariaLabel:"Escape",title:"发送 Escape"},{id:"tab",label:"Tab",ariaLabel:"Tab",title:"发送 Tab"},{id:"ctrl-c",label:"Ctrl+C",ariaLabel:"Control C",title:"中断前台进程"},{id:"ctrl-d",label:"Ctrl+D",ariaLabel:"Control D",title:"发送 EOF / 关闭输入"},{id:"ctrl-z",label:"Ctrl+Z",ariaLabel:"Control Z",title:"挂起前台进程"},{id:"ctrl-l",label:"Ctrl+L",ariaLabel:"Control L",title:"清屏 / 重绘终端"},{id:"ctrl-r",label:"Ctrl+R",ariaLabel:"Control R",title:"反向搜索历史"},{id:"ctrl-u",label:"Ctrl+U",ariaLabel:"Control U",title:"删除到行首"},{id:"ctrl-w",label:"Ctrl+W",ariaLabel:"Control W",title:"删除上一个单词"},{id:"arrow-left",label:"←",ariaLabel:"左箭头",title:"向左移动"},{id:"arrow-up",label:"↑",ariaLabel:"上箭头",title:"向上移动 / 上一条命令"},{id:"arrow-down",label:"↓",ariaLabel:"下箭头",title:"向下移动 / 下一条命令"},{id:"arrow-right",label:"→",ariaLabel:"右箭头",title:"向右移动"},{id:"home",label:"Home",ariaLabel:"Home",title:"移动到开头"},{id:"end",label:"End",ariaLabel:"End",title:"移动到末尾"},{id:"page-up",label:"PgUp",ariaLabel:"向上翻页",title:"向上翻页"},{id:"page-down",label:"PgDn",ariaLabel:"向下翻页",title:"向下翻页"},{id:"delete",label:"Del",ariaLabel:"Delete",title:"向前删除"},{id:"backspace",label:"⌫",ariaLabel:"Backspace",title:"退格"},{id:"meta-backward-word",label:"M-B",ariaLabel:"Meta B",title:"向后移动一个单词"},{id:"meta-forward-word",label:"M-F",ariaLabel:"Meta F",title:"向前移动一个单词"}],d="\x1B",q="";function Y(e,t){switch(e){case"escape":return d;case"tab":return" ";case"ctrl-c":return p("c");case"ctrl-d":return p("d");case"ctrl-z":return p("z");case"ctrl-l":return p("l");case"ctrl-r":return p("r");case"ctrl-u":return p("u");case"ctrl-w":return p("w");case"arrow-left":return b("D",t);case"arrow-up":return b("A",t);case"arrow-down":return b("B",t);case"arrow-right":return b("C",t);case"home":return x("H",t);case"end":return x("F",t);case"page-up":return`${d}[5~`;case"page-down":return`${d}[6~`;case"delete":return`${d}[3~`;case"backspace":return q;case"meta-backward-word":return`${d}b`;case"meta-forward-word":return`${d}f`}}function p(e){return String.fromCharCode(e.toUpperCase().charCodeAt(0)-64)}function b(e,t){return t?.applicationCursorKeysMode===!0?`${d}O${e}`:`${d}[${e}`}function x(e,t){return t?.applicationCursorKeysMode===!0?`${d}O${e}`:`${d}[${e}`}var W=Object.defineProperty,X=Object.getOwnPropertyDescriptor,y=(e,t,i,n)=>{for(var r=n>1?void 0:n?X(t,i):t,a=e.length-1,u;a>=0;a--)(u=e[a])&&(r=(n?u(t,i,r):u(r))||r);return n&&r&&W(t,i,r),r};const J=8,Z=500;let f=class extends K{constructor(){super(...arguments),this.refocusOnClick=!0,this.onInput=()=>{},this.lastPointerFinishedAt=0}sendSoftKey(e,t){this.onInput(Y(e.id,this.modes),t)}onSoftKeyPointerDown(e,t){e.pointerType==="mouse"&&e.button!==0||(e.preventDefault(),this.pointerStart={pointerId:e.pointerId,key:t,clientX:e.clientX,clientY:e.clientY})}onSoftKeyPointerMove(e){const t=this.pointerStart;t?.pointerId===e.pointerId&&I(t,e)&&this.finishSoftKeyPointer()}onSoftKeyPointerUp(e,t){const i=this.pointerStart;i?.pointerId===e.pointerId&&(e.preventDefault(),this.finishSoftKeyPointer(),!(i.key.id!==t.id||I(i,e))&&this.sendSoftKey(t,{refocus:e.pointerType==="mouse"}))}onSoftKeyPointerCancel(e){this.pointerStart?.pointerId===e.pointerId&&this.finishSoftKeyPointer()}finishSoftKeyPointer(){this.pointerStart=void 0,this.lastPointerFinishedAt=Date.now()}onSoftKeyClick(e,t){if(Date.now()-this.lastPointerFinishedAt<Z){e.preventDefault();return}this.sendSoftKey(t,{refocus:this.refocusOnClick})}render(){return l`
1
+ import{a as E,n as m,i as K,b as l,t as R,c as h,s as D,d as w,f as _,e as F,r as c}from"./index-BdQ-j_1w.js";import{D as T,o as S}from"./vendor-terminal-DjQ08hXu.js";import"./vendor-editor-core-Bc1A7SO7.js";import"./vendor-editor-languages-D0CnB2js.js";const $="pi-web.terminal.softKeys",N="(pointer: coarse), (max-width: 760px)";function z(e,t){return e??t}function V(e){if(e==="true")return!0;if(e==="false")return!1}function P(){return typeof window<"u"&&"matchMedia"in window?window.matchMedia(N):void 0}function M(e){return e?.matches===!0}function j(e=P()){return z(O(),M(e))}function B(){return O()!==void 0}function O(e=A()){if(e!==void 0)try{return V(e.getItem($))}catch{return}}function H(e,t=A()){if(t!==void 0)try{t.setItem($,String(e))}catch{}}function A(){if(!(typeof window>"u"))try{return window.localStorage}catch{return}}const U=[{id:"escape",label:"Esc",ariaLabel:"Escape",title:"发送 Escape"},{id:"tab",label:"Tab",ariaLabel:"Tab",title:"发送 Tab"},{id:"ctrl-c",label:"Ctrl+C",ariaLabel:"Control C",title:"中断前台进程"},{id:"ctrl-d",label:"Ctrl+D",ariaLabel:"Control D",title:"发送 EOF / 关闭输入"},{id:"ctrl-z",label:"Ctrl+Z",ariaLabel:"Control Z",title:"挂起前台进程"},{id:"ctrl-l",label:"Ctrl+L",ariaLabel:"Control L",title:"清屏 / 重绘终端"},{id:"ctrl-r",label:"Ctrl+R",ariaLabel:"Control R",title:"反向搜索历史"},{id:"ctrl-u",label:"Ctrl+U",ariaLabel:"Control U",title:"删除到行首"},{id:"ctrl-w",label:"Ctrl+W",ariaLabel:"Control W",title:"删除上一个单词"},{id:"arrow-left",label:"←",ariaLabel:"左箭头",title:"向左移动"},{id:"arrow-up",label:"↑",ariaLabel:"上箭头",title:"向上移动 / 上一条命令"},{id:"arrow-down",label:"↓",ariaLabel:"下箭头",title:"向下移动 / 下一条命令"},{id:"arrow-right",label:"→",ariaLabel:"右箭头",title:"向右移动"},{id:"home",label:"Home",ariaLabel:"Home",title:"移动到开头"},{id:"end",label:"End",ariaLabel:"End",title:"移动到末尾"},{id:"page-up",label:"PgUp",ariaLabel:"向上翻页",title:"向上翻页"},{id:"page-down",label:"PgDn",ariaLabel:"向下翻页",title:"向下翻页"},{id:"delete",label:"Del",ariaLabel:"Delete",title:"向前删除"},{id:"backspace",label:"⌫",ariaLabel:"Backspace",title:"退格"},{id:"meta-backward-word",label:"M-B",ariaLabel:"Meta B",title:"向后移动一个单词"},{id:"meta-forward-word",label:"M-F",ariaLabel:"Meta F",title:"向前移动一个单词"}],d="\x1B",q="";function Y(e,t){switch(e){case"escape":return d;case"tab":return" ";case"ctrl-c":return p("c");case"ctrl-d":return p("d");case"ctrl-z":return p("z");case"ctrl-l":return p("l");case"ctrl-r":return p("r");case"ctrl-u":return p("u");case"ctrl-w":return p("w");case"arrow-left":return b("D",t);case"arrow-up":return b("A",t);case"arrow-down":return b("B",t);case"arrow-right":return b("C",t);case"home":return x("H",t);case"end":return x("F",t);case"page-up":return`${d}[5~`;case"page-down":return`${d}[6~`;case"delete":return`${d}[3~`;case"backspace":return q;case"meta-backward-word":return`${d}b`;case"meta-forward-word":return`${d}f`}}function p(e){return String.fromCharCode(e.toUpperCase().charCodeAt(0)-64)}function b(e,t){return t?.applicationCursorKeysMode===!0?`${d}O${e}`:`${d}[${e}`}function x(e,t){return t?.applicationCursorKeysMode===!0?`${d}O${e}`:`${d}[${e}`}var W=Object.defineProperty,X=Object.getOwnPropertyDescriptor,y=(e,t,i,n)=>{for(var r=n>1?void 0:n?X(t,i):t,a=e.length-1,u;a>=0;a--)(u=e[a])&&(r=(n?u(t,i,r):u(r))||r);return n&&r&&W(t,i,r),r};const J=8,Z=500;let f=class extends K{constructor(){super(...arguments),this.refocusOnClick=!0,this.onInput=()=>{},this.lastPointerFinishedAt=0}sendSoftKey(e,t){this.onInput(Y(e.id,this.modes),t)}onSoftKeyPointerDown(e,t){e.pointerType==="mouse"&&e.button!==0||(e.preventDefault(),this.pointerStart={pointerId:e.pointerId,key:t,clientX:e.clientX,clientY:e.clientY})}onSoftKeyPointerMove(e){const t=this.pointerStart;t?.pointerId===e.pointerId&&I(t,e)&&this.finishSoftKeyPointer()}onSoftKeyPointerUp(e,t){const i=this.pointerStart;i?.pointerId===e.pointerId&&(e.preventDefault(),this.finishSoftKeyPointer(),!(i.key.id!==t.id||I(i,e))&&this.sendSoftKey(t,{refocus:e.pointerType==="mouse"}))}onSoftKeyPointerCancel(e){this.pointerStart?.pointerId===e.pointerId&&this.finishSoftKeyPointer()}finishSoftKeyPointer(){this.pointerStart=void 0,this.lastPointerFinishedAt=Date.now()}onSoftKeyClick(e,t){if(Date.now()-this.lastPointerFinishedAt<Z){e.preventDefault();return}this.sendSoftKey(t,{refocus:this.refocusOnClick})}render(){return l`
2
2
  <div class="terminal-soft-keys" role="toolbar" aria-label="终端快捷键">
3
3
  ${U.map(e=>l`
4
4
  <button
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodeViewer-rwuQkhmb.js","assets/vendor-editor-core-Bc1A7SO7.js","assets/vendor-editor-languages-D0CnB2js.js","assets/vendor-editor-legacy-B4QLsWF8.js","assets/TerminalPanel-BTDv_JgG.js","assets/vendor-terminal-DjQ08hXu.js","assets/vendor-terminal-DDGTF8rc.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodeViewer-BFn0HY4O.js","assets/vendor-editor-core-Bc1A7SO7.js","assets/vendor-editor-languages-D0CnB2js.js","assets/vendor-editor-legacy-B4QLsWF8.js","assets/TerminalPanel-CiYd2dqB.js","assets/vendor-terminal-DjQ08hXu.js","assets/vendor-terminal-DDGTF8rc.css"])))=>i.map(i=>d[i]);
2
2
  import{Q as Co,w as rt,J as Vi,R as Za,S as Xa,G as Ya,U as ec,V as tc,A as ic,W as sc,X as oc,Y as rc,Z as Mo,x as To,_ as nc}from"./vendor-editor-core-Bc1A7SO7.js";import{m as ac,i as cc,d as lc}from"./vendor-editor-languages-D0CnB2js.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))s(o);new MutationObserver(o=>{for(const r of o)if(r.type==="childList")for(const n of r.addedNodes)n.tagName==="LINK"&&n.rel==="modulepreload"&&s(n)}).observe(document,{childList:!0,subtree:!0});function i(o){const r={};return o.integrity&&(r.integrity=o.integrity),o.referrerPolicy&&(r.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?r.credentials="include":o.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function s(o){if(o.ep)return;o.ep=!0;const r=i(o);fetch(o.href,r)}})();const ri=globalThis,Bs=ri.ShadowRoot&&(ri.ShadyCSS===void 0||ri.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Us=Symbol(),Ao=new WeakMap;let fn=class{constructor(t,i,s){if(this._$cssResult$=!0,s!==Us)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=i}get styleSheet(){let t=this.o;const i=this.t;if(Bs&&t===void 0){const s=i!==void 0&&i.length===1;s&&(t=Ao.get(i)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&Ao.set(i,t))}return t}toString(){return this.cssText}};const dc=e=>new fn(typeof e=="string"?e:e+"",void 0,Us),_=(e,...t)=>{const i=e.length===1?e[0]:t.reduce((s,o,r)=>s+(n=>{if(n._$cssResult$===!0)return n.cssText;if(typeof n=="number")return n;throw Error("Value passed to 'css' function must be a 'css' function result: "+n+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(o)+e[r+1],e[0]);return new fn(i,e,Us)},pc=(e,t)=>{if(Bs)e.adoptedStyleSheets=t.map(i=>i instanceof CSSStyleSheet?i:i.styleSheet);else for(const i of t){const s=document.createElement("style"),o=ri.litNonce;o!==void 0&&s.setAttribute("nonce",o),s.textContent=i.cssText,e.appendChild(s)}},Eo=Bs?e=>e:e=>e instanceof CSSStyleSheet?(t=>{let i="";for(const s of t.cssRules)i+=s.cssText;return dc(i)})(e):e;const{is:hc,defineProperty:uc,getOwnPropertyDescriptor:fc,getOwnPropertyNames:gc,getOwnPropertySymbols:mc,getPrototypeOf:vc}=Object,Wi=globalThis,Do=Wi.trustedTypes,bc=Do?Do.emptyScript:"",wc=Wi.reactiveElementPolyfillSupport,Tt=(e,t)=>e,hi={toAttribute(e,t){switch(t){case Boolean:e=e?bc:null;break;case Object:case Array:e=e==null?e:JSON.stringify(e)}return e},fromAttribute(e,t){let i=e;switch(t){case Boolean:i=e!==null;break;case Number:i=e===null?null:Number(e);break;case Object:case Array:try{i=JSON.parse(e)}catch{i=null}}return i}},Hs=(e,t)=>!hc(e,t),Wo={attribute:!0,type:String,converter:hi,reflect:!1,useDefault:!1,hasChanged:Hs};Symbol.metadata??=Symbol("metadata"),Wi.litPropertyMetadata??=new WeakMap;let lt=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,i=Wo){if(i.state&&(i.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((i=Object.create(i)).wrapped=!0),this.elementProperties.set(t,i),!i.noAccessor){const s=Symbol(),o=this.getPropertyDescriptor(t,s,i);o!==void 0&&uc(this.prototype,t,o)}}static getPropertyDescriptor(t,i,s){const{get:o,set:r}=fc(this.prototype,t)??{get(){return this[i]},set(n){this[i]=n}};return{get:o,set(n){const a=o?.call(this);r?.call(this,n),this.requestUpdate(t,a,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??Wo}static _$Ei(){if(this.hasOwnProperty(Tt("elementProperties")))return;const t=vc(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(Tt("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(Tt("properties"))){const i=this.properties,s=[...gc(i),...mc(i)];for(const o of s)this.createProperty(o,i[o])}const t=this[Symbol.metadata];if(t!==null){const i=litPropertyMetadata.get(t);if(i!==void 0)for(const[s,o]of i)this.elementProperties.set(s,o)}this._$Eh=new Map;for(const[i,s]of this.elementProperties){const o=this._$Eu(i,s);o!==void 0&&this._$Eh.set(o,i)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const i=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const o of s)i.unshift(Eo(o))}else t!==void 0&&i.push(Eo(t));return i}static _$Eu(t,i){const s=i.attribute;return s===!1?void 0:typeof s=="string"?s:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this))}addController(t){(this._$EO??=new Set).add(t),this.renderRoot!==void 0&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,i=this.constructor.elementProperties;for(const s of i.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return pc(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(t=>t.hostConnected?.())}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.())}attributeChangedCallback(t,i,s){this._$AK(t,s)}_$ET(t,i){const s=this.constructor.elementProperties.get(t),o=this.constructor._$Eu(t,s);if(o!==void 0&&s.reflect===!0){const r=(s.converter?.toAttribute!==void 0?s.converter:hi).toAttribute(i,s.type);this._$Em=t,r==null?this.removeAttribute(o):this.setAttribute(o,r),this._$Em=null}}_$AK(t,i){const s=this.constructor,o=s._$Eh.get(t);if(o!==void 0&&this._$Em!==o){const r=s.getPropertyOptions(o),n=typeof r.converter=="function"?{fromAttribute:r.converter}:r.converter?.fromAttribute!==void 0?r.converter:hi;this._$Em=o;const a=n.fromAttribute(i,r.type);this[o]=a??this._$Ej?.get(o)??a,this._$Em=null}}requestUpdate(t,i,s,o=!1,r){if(t!==void 0){const n=this.constructor;if(o===!1&&(r=this[t]),s??=n.getPropertyOptions(t),!((s.hasChanged??Hs)(r,i)||s.useDefault&&s.reflect&&r===this._$Ej?.get(t)&&!this.hasAttribute(n._$Eu(t,s))))return;this.C(t,i,s)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,i,{useDefault:s,reflect:o,wrapped:r},n){s&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,n??i??this[t]),r!==!0||n!==void 0)||(this._$AL.has(t)||(this.hasUpdated||s||(i=void 0),this._$AL.set(t,i)),o===!0&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(i){Promise.reject(i)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[o,r]of this._$Ep)this[o]=r;this._$Ep=void 0}const s=this.constructor.elementProperties;if(s.size>0)for(const[o,r]of s){const{wrapped:n}=r,a=this[o];n!==!0||this._$AL.has(o)||a===void 0||this.C(o,void 0,r,a)}}let t=!1;const i=this._$AL;try{t=this.shouldUpdate(i),t?(this.willUpdate(i),this._$EO?.forEach(s=>s.hostUpdate?.()),this.update(i)):this._$EM()}catch(s){throw t=!1,this._$EM(),s}t&&this._$AE(i)}willUpdate(t){}_$AE(t){this._$EO?.forEach(i=>i.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach(i=>this._$ET(i,this[i])),this._$EM()}updated(t){}firstUpdated(t){}};lt.elementStyles=[],lt.shadowRootOptions={mode:"open"},lt[Tt("elementProperties")]=new Map,lt[Tt("finalized")]=new Map,wc?.({ReactiveElement:lt}),(Wi.reactiveElementVersions??=[]).push("2.1.2");const qs=globalThis,_o=e=>e,ui=qs.trustedTypes,Lo=ui?ui.createPolicy("lit-html",{createHTML:e=>e}):void 0,gn="$lit$",Be=`lit$${Math.random().toFixed(9).slice(2)}$`,mn="?"+Be,yc=`<${mn}>`,Ze=document,Dt=()=>Ze.createComment(""),Wt=e=>e===null||typeof e!="object"&&typeof e!="function",Ks=Array.isArray,Sc=e=>Ks(e)||typeof e?.[Symbol.iterator]=="function",Gi=`[
3
3
  \f\r]`,wt=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Oo=/-->/g,jo=/>/g,qe=RegExp(`>|${Gi}(?:([^\\s"'>=/]+)(${Gi}*=${Gi}*(?:[^
4
4
  \f\r"'\`<>=]|("|')|))|$)`,"g"),Fo=/'/g,zo=/"/g,vn=/^(?:script|style|textarea|title)$/i,bn=e=>(t,...i)=>({_$litType$:e,strings:t,values:i}),c=bn(1),ue=bn(2),Ue=Symbol.for("lit-noChange"),F=Symbol.for("lit-nothing"),No=new WeakMap,Je=Ze.createTreeWalker(Ze,129);function wn(e,t){if(!Ks(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return Lo!==void 0?Lo.createHTML(t):t}const xc=(e,t)=>{const i=e.length-1,s=[];let o,r=t===2?"<svg>":t===3?"<math>":"",n=wt;for(let a=0;a<i;a++){const l=e[a];let p,u,h=-1,g=0;for(;g<l.length&&(n.lastIndex=g,u=n.exec(l),u!==null);)g=n.lastIndex,n===wt?u[1]==="!--"?n=Oo:u[1]!==void 0?n=jo:u[2]!==void 0?(vn.test(u[2])&&(o=RegExp("</"+u[2],"g")),n=qe):u[3]!==void 0&&(n=qe):n===qe?u[0]===">"?(n=o??wt,h=-1):u[1]===void 0?h=-2:(h=n.lastIndex-u[2].length,p=u[1],n=u[3]===void 0?qe:u[3]==='"'?zo:Fo):n===zo||n===Fo?n=qe:n===Oo||n===jo?n=wt:(n=qe,o=void 0);const w=n===qe&&e[a+1].startsWith("/>")?" ":"";r+=n===wt?l+yc:h>=0?(s.push(p),l.slice(0,h)+gn+l.slice(h)+Be+w):l+Be+(h===-2?a:w)}return[wn(e,r+(e[i]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]};class _t{constructor({strings:t,_$litType$:i},s){let o;this.parts=[];let r=0,n=0;const a=t.length-1,l=this.parts,[p,u]=xc(t,i);if(this.el=_t.createElement(p,s),Je.currentNode=this.el.content,i===2||i===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(o=Je.nextNode())!==null&&l.length<a;){if(o.nodeType===1){if(o.hasAttributes())for(const h of o.getAttributeNames())if(h.endsWith(gn)){const g=u[n++],w=o.getAttribute(h).split(Be),P=/([.?@])?(.*)/.exec(g);l.push({type:1,index:r,name:P[2],strings:w,ctor:P[1]==="."?$c:P[1]==="?"?Pc:P[1]==="@"?Rc:_i}),o.removeAttribute(h)}else h.startsWith(Be)&&(l.push({type:6,index:r}),o.removeAttribute(h));if(vn.test(o.tagName)){const h=o.textContent.split(Be),g=h.length-1;if(g>0){o.textContent=ui?ui.emptyScript:"";for(let w=0;w<g;w++)o.append(h[w],Dt()),Je.nextNode(),l.push({type:2,index:++r});o.append(h[g],Dt())}}}else if(o.nodeType===8)if(o.data===mn)l.push({type:2,index:r});else{let h=-1;for(;(h=o.data.indexOf(Be,h+1))!==-1;)l.push({type:7,index:r}),h+=Be.length-1}r++}}static createElement(t,i){const s=Ze.createElement("template");return s.innerHTML=t,s}}function pt(e,t,i=e,s){if(t===Ue)return t;let o=s!==void 0?i._$Co?.[s]:i._$Cl;const r=Wt(t)?void 0:t._$litDirective$;return o?.constructor!==r&&(o?._$AO?.(!1),r===void 0?o=void 0:(o=new r(e),o._$AT(e,i,s)),s!==void 0?(i._$Co??=[])[s]=o:i._$Cl=o),o!==void 0&&(t=pt(e,o._$AS(e,t.values),o,s)),t}class kc{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,o=(t?.creationScope??Ze).importNode(i,!0);Je.currentNode=o;let r=Je.nextNode(),n=0,a=0,l=s[0];for(;l!==void 0;){if(n===l.index){let p;l.type===2?p=new ft(r,r.nextSibling,this,t):l.type===1?p=new l.ctor(r,l.name,l.strings,this,t):l.type===6&&(p=new Ic(r,this,t)),this._$AV.push(p),l=s[++a]}n!==l?.index&&(r=Je.nextNode(),n++)}return Je.currentNode=Ze,o}p(t){let i=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++}}class ft{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,o){this.type=2,this._$AH=F,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=o,this._$Cv=o?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return i!==void 0&&t?.nodeType===11&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=pt(this,t,i),Wt(t)?t===F||t==null||t===""?(this._$AH!==F&&this._$AR(),this._$AH=F):t!==this._$AH&&t!==Ue&&this._(t):t._$litType$!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):Sc(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==F&&Wt(this._$AH)?this._$AA.nextSibling.data=t:this.T(Ze.createTextNode(t)),this._$AH=t}$(t){const{values:i,_$litType$:s}=t,o=typeof s=="number"?this._$AC(t):(s.el===void 0&&(s.el=_t.createElement(wn(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===o)this._$AH.p(i);else{const r=new kc(o,this),n=r.u(this.options);r.p(i),this.T(n),this._$AH=r}}_$AC(t){let i=No.get(t.strings);return i===void 0&&No.set(t.strings,i=new _t(t)),i}k(t){Ks(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,o=0;for(const r of t)o===i.length?i.push(s=new ft(this.O(Dt()),this.O(Dt()),this,this.options)):s=i[o],s._$AI(r),o++;o<i.length&&(this._$AR(s&&s._$AB.nextSibling,o),i.length=o)}_$AR(t=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);t!==this._$AB;){const s=_o(t).nextSibling;_o(t).remove(),t=s}}setConnected(t){this._$AM===void 0&&(this._$Cv=t,this._$AP?.(t))}}let _i=class{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,o,r){this.type=1,this._$AH=F,this._$AN=void 0,this.element=t,this.name=i,this._$AM=o,this.options=r,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=F}_$AI(t,i=this,s,o){const r=this.strings;let n=!1;if(r===void 0)t=pt(this,t,i,0),n=!Wt(t)||t!==this._$AH&&t!==Ue,n&&(this._$AH=t);else{const a=t;let l,p;for(t=r[0],l=0;l<r.length-1;l++)p=pt(this,a[s+l],i,l),p===Ue&&(p=this._$AH[l]),n||=!Wt(p)||p!==this._$AH[l],p===F?t=F:t!==F&&(t+=(p??"")+r[l+1]),this._$AH[l]=p}n&&!o&&this.j(t)}j(t){t===F?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}},$c=class extends _i{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===F?void 0:t}},Pc=class extends _i{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==F)}},Rc=class extends _i{constructor(t,i,s,o,r){super(t,i,s,o,r),this.type=5}_$AI(t,i=this){if((t=pt(this,t,i,0)??F)===Ue)return;const s=this._$AH,o=t===F&&s!==F||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,r=t!==F&&(s===F||o);o&&this.element.removeEventListener(this.name,this,s),r&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}},Ic=class{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){pt(this,t)}};const Cc={I:ft},Mc=qs.litHtmlPolyfillSupport;Mc?.(_t,ft),(qs.litHtmlVersions??=[]).push("3.3.3");const Tc=(e,t,i)=>{const s=i?.renderBefore??t;let o=s._$litPart$;if(o===void 0){const r=i?.renderBefore??null;s._$litPart$=o=new ft(t.insertBefore(Dt(),r),r,void 0,i??{})}return o._$AI(e),o};const Vs=globalThis;let M=class extends lt{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=Tc(i,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Ue}};M._$litElement$=!0,M.finalized=!0,Vs.litElementHydrateSupport?.({LitElement:M});const Ac=Vs.litElementPolyfillSupport;Ac?.({LitElement:M});(Vs.litElementVersions??=[]).push("4.2.2");const D=e=>(t,i)=>{i!==void 0?i.addInitializer(()=>{customElements.define(e,t)}):customElements.define(e,t)};const Ec={attribute:!0,type:String,converter:hi,reflect:!1,hasChanged:Hs},Dc=(e=Ec,t,i)=>{const{kind:s,metadata:o}=i;let r=globalThis.litPropertyMetadata.get(o);if(r===void 0&&globalThis.litPropertyMetadata.set(o,r=new Map),s==="setter"&&((e=Object.create(e)).wrapped=!0),r.set(i.name,e),s==="accessor"){const{name:n}=i;return{set(a){const l=t.get.call(this);t.set.call(this,a),this.requestUpdate(n,l,e,!0,a)},init(a){return a!==void 0&&this.C(n,void 0,e,a),a}}}if(s==="setter"){const{name:n}=i;return function(a){const l=this[n];t.call(this,a),this.requestUpdate(n,l,e,!0,a)}}throw Error("Unsupported decorator location: "+s)};function d(e){return(t,i)=>typeof i=="object"?Dc(e,t,i):((s,o,r)=>{const n=o.hasOwnProperty(r);return o.constructor.createProperty(r,s),n?Object.getOwnPropertyDescriptor(o,r):void 0})(e,t,i)}function S(e){return d({...e,state:!0,attribute:!1})}const Wc=(e,t,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.decorate&&typeof t!="object"&&Object.defineProperty(e,t,i),i);function B(e,t){return(i,s,o)=>{const r=n=>n.renderRoot?.querySelector(e)??null;return Wc(i,s,{get(){return r(this)}})}}function yn(e,t=Lc()){if(t===void 0)return e;const i=_c(t);if(i===void 0)return e;const s=new URL(e,t.origin);return s.searchParams.set("embed",i.embed),s.searchParams.set("token",i.token),`${s.pathname}${s.search}${s.hash}`}function _c(e){const t=e.searchParams.get("embed"),i=e.searchParams.get("token")?.trim();if(!(t!=="management"||i===void 0||i===""))return{embed:t,token:i}}function Lc(){if(typeof globalThis.location>"u")return;const e=globalThis.location;if(typeof e.href=="string"&&e.href!=="")return new URL(e.href);const t=typeof e.protocol=="string"&&e.protocol!==""?e.protocol:"http:",i=typeof e.host=="string"&&e.host!==""?e.host:"localhost",s=typeof e.search=="string"?e.search:"";return new URL(`${t}//${i}/${s}`)}async function v(e,t,i){const s=new Headers(i?.headers);i?.body!==void 0&&s.set("content-type","application/json");const o=await fetch(yn(e),{...i,headers:s});if(!o.ok){const n=await o.json().catch(()=>({}));throw new Error(Oc(n)??o.statusText)}const r=await o.json();return t(r)}function Oc(e){if(jc(e))return typeof e.error=="string"?e.error:void 0}function jc(e){return typeof e=="object"&&e!==null}const ht={sessionsDeleteArchived:"sessions.deleteArchived",sessionsReload:"sessions.reload",promptAttachments:"prompt.attachments"},Fc=Object.values(ht),zc=new Set(Fc);function Nc(e){return typeof e=="string"&&zc.has(e)}function Lt(e,t){return e?.capabilities?.includes(t)===!0}function At(e){return typeof e=="object"&&e!==null}function b(e){if(!At(e))throw new Error("Expected object response");return e}function m(e,t){const i=e[t];if(typeof i!="string")throw new Error(`Expected string field: ${t}`);return i}function $(e,t){const i=e[t];if(i!==void 0){if(typeof i!="string")throw new Error(`Expected optional string field: ${t}`);return i}}function se(e,t){const i=e[t];if(typeof i!="number")throw new Error(`Expected number field: ${t}`);return i}function E(e,t){const i=e[t];if(typeof i!="boolean")throw new Error(`Expected boolean field: ${t}`);return i}function z(e){return t=>{if(!Array.isArray(t))throw new Error("Expected array response");return t.map(e)}}function Bc(e){if(!Array.isArray(e))throw new Error("Expected array response");return e}function Uc(e,t){if(!Array.isArray(e)||!e.every(i=>typeof i=="string"))throw new Error(`Expected string array field: ${t}`);return e}function Hc(e){if(Array.isArray(e))return{messages:e,start:0,total:e.length};const t=b(e);return{messages:Bc(t.messages),start:se(t,"start"),total:se(t,"total")}}function qc(e){const t=b(e);return z(Sn)(t.machines)}function Sn(e){const t=b(e),i=Gc(t,"kind"),s=$(t,"baseUrl"),o=xn(t,"status"),r=$(t,"statusMessage");return{id:m(t,"id"),name:m(t,"name"),kind:i,...s===void 0?{}:{baseUrl:s},createdAt:m(t,"createdAt"),updatedAt:m(t,"updatedAt"),...o===void 0?{}:{status:o},...r===void 0?{}:{statusMessage:r}}}function Kc(e){const t=b(e),i=xn(t,"status"),s=$(t,"error");return{machineId:m(t,"machineId"),ok:E(t,"ok"),checkedAt:m(t,"checkedAt"),...i===void 0?{}:{status:i},...t.web===void 0?{}:{web:fi(t.web)},...t.sessiond===void 0?{}:{sessiond:fi(t.sessiond)},...s===void 0?{}:{error:s}}}function Vc(e){const t=b(e),i=$(t,"error");return{machineId:m(t,"machineId"),ok:E(t,"ok"),checkedAt:m(t,"checkedAt"),...y("packageName",$(t,"packageName")),...y("generatedAt",$(t,"generatedAt")),...t.components===void 0?{}:{components:Pn(t.components)},...t.capabilities===void 0?{}:{capabilities:Gs(t.capabilities)},...i===void 0?{}:{error:i}}}function Gc(e,t){const i=m(e,t);if(i!=="local"&&i!=="remote")throw new Error(`Expected machine kind field: ${t}`);return i}function xn(e,t){const i=$(e,t);if(i!==void 0){if(i!=="unknown"&&i!=="online"&&i!=="offline"&&i!=="error")throw new Error(`Expected machine status field: ${t}`);return i}}function Bo(e){const t=b(e);return{id:m(t,"id"),name:m(t,"name"),path:m(t,"path"),createdAt:m(t,"createdAt")}}function Jc(e){const t=b(e),i=$(t,"branch");return{id:m(t,"id"),projectId:m(t,"projectId"),path:m(t,"path"),label:m(t,"label"),...i===void 0?{}:{branch:i},isMain:E(t,"isMain"),isGitRepo:E(t,"isGitRepo"),isGitWorktree:E(t,"isGitWorktree")}}function Ss(e){const t=b(e);return{path:m(t,"path"),size:se(t,"size"),modifiedAt:m(t,"modifiedAt")}}function Ji(e){const t=b(e);return{path:m(t,"path")}}function Uo(e){const t=b(e);if(t.deleted!==!0)throw new Error("Expected deleted response");return{deleted:!0,path:m(t,"path")}}function xs(e){const t=b(e),i=$(t,"name"),s=$(t,"parentSessionPath"),o=$(t,"archivedAt");return{id:m(t,"id"),path:m(t,"path"),cwd:m(t,"cwd"),...i===void 0?{}:{name:i},created:m(t,"created"),modified:m(t,"modified"),messageCount:se(t,"messageCount"),firstMessage:m(t,"firstMessage"),...s===void 0?{}:{parentSessionPath:s},...t.archived===!0?{archived:!0}:{},...o===void 0?{}:{archivedAt:o}}}function yt(e){const t=b(e);return{sessionId:m(t,"sessionId"),isStreaming:E(t,"isStreaming"),isCompacting:E(t,"isCompacting"),isBashRunning:E(t,"isBashRunning"),pendingMessageCount:se(t,"pendingMessageCount"),queuedMessages:t.queuedMessages===void 0?[]:z(Qc)(t.queuedMessages),...y("messageCount",Pe(t,"messageCount")),tokens:Zc(t.tokens),cost:se(t,"cost"),...el(t.model),...ul(t.contextUsage),...y("thinkingLevel",$(t,"thinkingLevel"))}}function Qc(e){const t=b(e),i=m(t,"kind");if(i!=="steer"&&i!=="followUp")throw new Error("Invalid queued message kind");return{kind:i,text:m(t,"text"),...y("imageCount",Pe(t,"imageCount"))}}function Zc(e){const t=b(e);return{input:se(t,"input"),output:se(t,"output"),cacheRead:se(t,"cacheRead"),cacheWrite:se(t,"cacheWrite"),total:se(t,"total")}}function kn(e){const t=b(e);return{...y("provider",$(t,"provider")),...y("id",$(t,"id")),...y("name",$(t,"name")),...y("contextWindow",Pe(t,"contextWindow")),...y("reasoning",t.reasoning),...y("input",Xc(t.input))}}function Xc(e){if(e!==void 0){if(!Array.isArray(e))throw new Error("Invalid model input");return e.map(Yc)}}function Yc(e){if(e==="text"||e==="image")return e;throw new Error("Invalid model input")}function el(e){return e===void 0?{}:{model:kn(e)}}function tl(e){const t=b(e);return{models:z(kn)(t.models)}}function il(e){if(typeof e!="string")throw new Error("Invalid thinking level");return e}function sl(e){const t=b(e);return{levels:z(il)(t.levels)}}function ol(e){if(e!=="oauth"&&e!=="api_key")throw new Error("Invalid auth type");return e}function rl(e){if(e!=="stored"&&e!=="runtime"&&e!=="environment"&&e!=="fallback"&&e!=="models_json_key"&&e!=="models_json_command")throw new Error("Invalid auth status source");return e}function nl(e){const t=b(e),i=t.source===void 0?void 0:rl(t.source);return{configured:E(t,"configured"),...y("source",i),...y("label",$(t,"label"))}}function al(e){const t=b(e);return{id:m(t,"id"),name:m(t,"name"),authType:ol(t.authType),status:nl(t.status)}}function cl(e){const t=b(e);return{providers:z(al)(t.providers)}}function Gt(e){const t=b(e);return{flowId:m(t,"flowId"),providerId:m(t,"providerId"),providerName:m(t,"providerName"),status:ll(t.status),progress:z(s=>{if(typeof s!="string")throw new Error("Expected progress item string");return s})(t.progress),...y("error",$(t,"error")),...y("auth",dl(t.auth)),...y("prompt",pl(t.prompt)),...y("select",hl(t.select))}}function ll(e){if(e!=="running"&&e!=="complete"&&e!=="error"&&e!=="cancelled")throw new Error("Invalid OAuth flow status");return e}function dl(e){if(e===void 0)return;const t=b(e);return{url:m(t,"url"),...y("instructions",$(t,"instructions"))}}function pl(e){if(e===void 0)return;const t=b(e),i=m(t,"kind");if(i!=="prompt"&&i!=="manual")throw new Error("Invalid OAuth prompt kind");return{requestId:m(t,"requestId"),message:m(t,"message"),kind:i,...y("placeholder",$(t,"placeholder")),...t.allowEmpty===!0?{allowEmpty:!0}:{}}}function hl(e){if(e===void 0)return;const t=b(e);return{requestId:m(t,"requestId"),message:m(t,"message"),options:z(In)(t.options)}}function ul(e){if(e===void 0)return{};const t=b(e);return{contextUsage:{tokens:Zo(t,"tokens"),contextWindow:se(t,"contextWindow"),percent:Zo(t,"percent")}}}function fl(e){const t=b(e),i=m(t,"source");if(i!=="extension"&&i!=="prompt"&&i!=="skill"&&i!=="builtin")throw new Error("Invalid command source");return{name:m(t,"name"),source:i,...y("description",$(t,"description"))}}function $n(e){const t=b(e),i=m(t,"kind");if(i!=="tracked"&&i!=="untracked"&&i!=="other")throw new Error("Invalid file kind");return{path:m(t,"path"),kind:i}}function gl(e){const t=b(e);return{path:m(t,"path"),entries:z(ml)(t.entries),scannedAt:m(t,"scannedAt"),truncated:E(t,"truncated")}}function ml(e){const t=b(e),i=m(t,"type");if(i!=="file"&&i!=="directory"&&i!=="symlink")throw new Error("Invalid file tree entry type");return{name:m(t,"name"),path:m(t,"path"),type:i,...y("size",Pe(t,"size")),...y("modifiedAt",$(t,"modifiedAt"))}}function vl(e){const t=b(e),i=m(t,"encoding");if(i!=="utf8")throw new Error("Invalid file encoding");return{path:m(t,"path"),...y("language",$(t,"language")),...y("mediaType",bl(t.mediaType)),...y("mimeType",$(t,"mimeType")),encoding:i,size:se(t,"size"),modifiedAt:m(t,"modifiedAt"),content:m(t,"content"),truncated:E(t,"truncated"),binary:E(t,"binary")}}function bl(e){if(e!==void 0){if(e!=="image")throw new Error("Invalid file media type");return e}}function wl(e){const t=b(e);return{isGitRepo:E(t,"isGitRepo"),hash:m(t,"hash"),...y("branch",$(t,"branch")),...y("upstream",$(t,"upstream")),...y("ahead",Pe(t,"ahead")),...y("behind",Pe(t,"behind")),files:z(yl)(t.files)}}function yl(e){const t=b(e);return{path:m(t,"path"),...y("oldPath",$(t,"oldPath")),index:Ho(t.index),workingTree:Ho(t.workingTree)}}function Ho(e){switch(e){case"unmodified":case"modified":case"added":case"deleted":case"renamed":case"copied":case"untracked":case"ignored":case"conflicted":return e;default:throw new Error("Invalid git file state")}}function Sl(e){const t=b(e);return{...y("path",$(t,"path")),staged:E(t,"staged"),hash:m(t,"hash"),diff:m(t,"diff"),truncated:E(t,"truncated")}}function Qi(e){const t=b(e);return{id:m(t,"id"),cwd:m(t,"cwd"),name:m(t,"name"),createdAt:m(t,"createdAt"),exited:E(t,"exited"),...y("exitCode",Pe(t,"exitCode")),...y("commandRunId",$(t,"commandRunId"))}}function Et(e){const t=b(e);return{id:m(t,"id"),origin:m(t,"origin"),projectId:m(t,"projectId"),workspaceId:m(t,"workspaceId"),terminalId:m(t,"terminalId"),title:m(t,"title"),command:m(t,"command"),status:xl(t.status),...y("exitCode",Pe(t,"exitCode")),createdAt:m(t,"createdAt"),...y("startedAt",$(t,"startedAt")),...y("completedAt",$(t,"completedAt")),metadata:kl(t.metadata,"metadata")}}function xl(e){if(e!=="queued"&&e!=="running"&&e!=="succeeded"&&e!=="failed")throw new Error("Invalid terminal command run status");return e}function kl(e,t){const i=b(e);return Object.fromEntries(Object.entries(i).map(([s,o])=>{if(typeof o!="string")throw new Error(`Expected string record field: ${t}.${s}`);return[s,o]}))}function $l(e){const t=b(e);return{cwd:m(t,"cwd"),hasSessionActivity:E(t,"hasSessionActivity"),hasTerminalActivity:E(t,"hasTerminalActivity"),updatedAt:m(t,"updatedAt")}}function Pl(e){const t=b(e);return{workspaces:z($l)(t.workspaces),generatedAt:m(t,"generatedAt")}}function qo(e){const t=b(e);return{path:m(t,"path"),exists:E(t,"exists"),config:Ko(t.config),effectiveConfig:Ko(t.effectiveConfig),envOverrides:Ml(t.envOverrides)}}function Ko(e){const t=b(e);return{...y("host",$(t,"host")),...y("port",Pe(t,"port")),...y("allowedHosts",Rl(t.allowedHosts)),...y("shortcuts",Il(t.shortcuts)),...y("plugins",Cl(t.plugins)),...y("spawnSessions",Qo(t,"spawnSessions")),...y("subsessions",Qo(t,"subsessions"))}}function Rl(e){if(e!==void 0){if(e===!0)return!0;if(Array.isArray(e)&&e.every(t=>typeof t=="string"))return e;throw new Error("Invalid PI WEB allowedHosts field")}}function Il(e){if(e!==void 0){if(!At(e)||Array.isArray(e))throw new Error("Invalid PI WEB shortcuts field");return Object.fromEntries(Object.entries(e).map(([t,i])=>{if(i!==null&&(typeof i!="string"||i===""))throw new Error("Invalid PI WEB shortcut field");return[t,i]}))}}function Cl(e){if(e!==void 0){if(!At(e)||Array.isArray(e))throw new Error("Invalid PI WEB plugins field");return Object.fromEntries(Object.entries(e).map(([t,i])=>{if(!At(i)||Array.isArray(i))throw new Error("Invalid PI WEB plugin config field");const s=i.enabled;if(s!==void 0&&typeof s!="boolean")throw new Error("Invalid PI WEB plugin enabled field");const o=i.settings;if(o!==void 0&&(!At(o)||Array.isArray(o)))throw new Error("Invalid PI WEB plugin settings field");return[t,i]}))}}function Ml(e){const t=b(e);return{host:E(t,"host"),port:E(t,"port"),allowedHosts:E(t,"allowedHosts"),spawnSessions:E(t,"spawnSessions"),subsessions:E(t,"subsessions")}}function Tl(e){const t=b(e);return{plugins:z(Al)(t.plugins)}}function Al(e){const t=b(e);return{id:m(t,"id"),module:m(t,"module"),source:m(t,"source"),scope:El(t.scope),machineSpecific:Dl(t.machineSpecific,"machineSpecific")??!1,enabled:E(t,"enabled")}}function El(e){if(e!=="bundled"&&e!=="local"&&e!=="user"&&e!=="project")throw new Error("Invalid PI WEB plugin scope");return e}function Dl(e,t){if(e!==void 0){if(typeof e!="boolean")throw new Error(`Expected optional boolean field: ${t}`);return e}}function Wl(e){const t=b(e);return{packageName:m(t,"packageName"),generatedAt:m(t,"generatedAt"),components:Ll(t.components),release:jl(t.release),commands:Fl(t.commands),messages:z(zl)(t.messages)}}function _l(e){const t=b(e);return{packageName:m(t,"packageName"),generatedAt:m(t,"generatedAt"),components:Pn(t.components),capabilities:Gs(t.capabilities)}}function Ll(e){const t=b(e);return{web:fi(t.web),sessiond:fi(t.sessiond)}}function Pn(e){const t=b(e);return{web:Vo(t.web),sessiond:Vo(t.sessiond)}}function Vo(e){const t=b(e);return{component:Rn(t.component),label:m(t,"label"),...y("runtimeVersion",$(t,"runtimeVersion")),available:E(t,"available"),capabilities:Gs(t.capabilities),...y("error",$(t,"error"))}}function fi(e){const t=b(e);return{component:Rn(t.component),label:m(t,"label"),...y("runtimeVersion",$(t,"runtimeVersion")),...y("installedVersion",$(t,"installedVersion")),stale:E(t,"stale"),available:E(t,"available"),...y("installation",Ol(t.installation)),...y("error",$(t,"error"))}}function Ol(e){if(e===void 0)return;const t=b(e),i=m(t,"kind");if(i!=="pi-package"&&i!=="npm-global"&&i!=="local"&&i!=="unknown")throw new Error("Invalid PI WEB installation kind");const s=t.scope;if(s!==void 0&&s!=="user"&&s!=="project")throw new Error("Invalid PI WEB installation scope");return{kind:i,...y("path",$(t,"path")),...y("source",$(t,"source")),...s===void 0?{}:{scope:s},...y("npmRoot",$(t,"npmRoot"))}}function jl(e){const t=b(e);return{packageName:m(t,"packageName"),...y("latestVersion",$(t,"latestVersion")),updateAvailable:E(t,"updateAvailable"),...y("checkedAt",$(t,"checkedAt")),...t.skipped===!0?{skipped:!0}:{},...y("error",$(t,"error"))}}function Fl(e){const t=b(e);return{...y("update",$(t,"update")),...y("restart",$(t,"restart")),...y("restartWeb",$(t,"restartWeb")),...y("restartSessiond",$(t,"restartSessiond")),...y("status",$(t,"status"))}}function zl(e){const t=b(e);return{id:m(t,"id"),severity:Nl(t.severity),title:m(t,"title"),body:m(t,"body"),...y("command",$(t,"command"))}}function Rn(e){if(e!=="web"&&e!=="sessiond")throw new Error("Invalid PI WEB service component");return e}function Gs(e){if(!Array.isArray(e)||!e.every(Nc))throw new Error("Invalid PI WEB capabilities");return e}function Nl(e){if(e!=="info"&&e!=="warning"&&e!=="error")throw new Error("Invalid PI WEB status severity");return e}function Go(e){const t=b(e),i=m(t,"type");if(i==="unsupported")return{type:i,message:m(t,"message")};if(i==="select")return{type:i,requestId:m(t,"requestId"),title:m(t,"title"),options:z(In)(t.options)};if(i==="done")return{type:i,...y("message",$(t,"message")),...Bl(t.session),...y("promptDraft",$(t,"promptDraft"))};throw new Error("Invalid command result type")}function In(e){const t=b(e);return{value:m(t,"value"),label:m(t,"label"),...y("description",$(t,"description"))}}function Bl(e){return e===void 0?{}:{session:xs(e)}}function Jt(e){if(b(e).accepted!==!0)throw new Error("Expected accepted response");return{accepted:!0}}function Ul(e){const t=b(e);return z(Hl)(t.attachments)}function Hl(e){const t=b(e);return{path:m(t,"path"),mimeType:m(t,"mimeType"),size:se(t,"size")}}function ks(e){if(b(e).closed!==!0)throw new Error("Expected closed response");return{closed:!0}}function ql(e){if(b(e).aborted!==!0)throw new Error("Expected aborted response");return{aborted:!0}}function Kl(e){if(b(e).stopped!==!0)throw new Error("Expected stopped response");return{stopped:!0}}function Jo(e){const t=b(e);if(t.archived!==!0)throw new Error("Expected archived response");const i=t.sessionIds===void 0?void 0:Uc(t.sessionIds,"sessionIds"),s=Pe(t,"archivedCount"),o=Pe(t,"skippedAlreadyArchivedCount");return{archived:!0,...i===void 0?{}:{sessionIds:i},...s===void 0?{}:{archivedCount:s},...o===void 0?{}:{skippedAlreadyArchivedCount:o}}}function Vl(e){if(b(e).restored!==!0)throw new Error("Expected restored response");return{restored:!0}}function Gl(e){if(b(e).deleted!==!0)throw new Error("Expected deleted response");return{deleted:!0}}function Jl(e){if(b(e).detached!==!0)throw new Error("Expected detached response");return{detached:!0}}function Ql(e){if(b(e).reloaded!==!0)throw new Error("Expected reloaded response");return{reloaded:!0}}function Qo(e,t){const i=e[t];if(i!==void 0){if(typeof i!="boolean")throw new Error(`Invalid PI WEB ${t} field`);return i}}function Pe(e,t){const i=e[t];if(i!==void 0){if(typeof i!="number")throw new Error(`Expected optional number field: ${t}`);return i}}function Zo(e,t){const i=e[t];if(i===null)return null;if(typeof i!="number")throw new Error(`Expected number|null field: ${t}`);return i}function y(e,t){return t===void 0?{}:{[e]:t}}function Zl(e){return typeof e=="string"?e:e.id}function Xl(e){return typeof e=="string"?void 0:e.cwd}function Yl(e,t,i,s){const o=new URLSearchParams;s?.path!==void 0&&o.set("path",s.path),s?.staged===!0&&o.set("staged","true");const r=o.toString();return`/api/machines/${encodeURIComponent(e)}/projects/${encodeURIComponent(t)}/workspaces/${encodeURIComponent(i)}/git/diff${r?`?${r}`:""}`}function ed(e,t,i="local"){const s=new URLSearchParams,o=Xl(e);o!==void 0&&o!==""&&s.set("cwd",o),t?.limit!==void 0&&s.set("limit",String(t.limit)),t?.before!==void 0&&s.set("before",String(t.before));const r=s.toString();return`/api/machines/${encodeURIComponent(i)}/sessions/${encodeURIComponent(Zl(e))}/messages${r===""?"":`?${r}`}`}function td(e,t,i,s){const o=new URLSearchParams;return o.set("path",i),s?.modifiedAt!==void 0&&o.set("v",s.modifiedAt),`${`/api/machines/${encodeURIComponent(s?.machineId??"local")}`}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file/preview?${o.toString()}`}function Cn(e,t,i,s){const o=new URLSearchParams;o.set("path",i);const r=`/api/machines/${encodeURIComponent(s?.machineId??"local")}`;return yn(`${r}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file/download?${o.toString()}`)}const R=(e="local")=>`/api/machines/${encodeURIComponent(e)}`;function id(e){return typeof e=="string"?e:e.id}function Mn(e){return typeof e=="string"?void 0:e.cwd}function Tn(e,t="local"){return`${R(t)}/sessions/${encodeURIComponent(id(e))}`}function V(e,t,i="local"){return`${Tn(e,i)}/${t}`}function Qt(e,t,i="local"){return`${V(e,t,i)}${An(e)}`}function sd(e,t="local"){return`${Tn(e,t)}${An(e)}`}function An(e){const t=Mn(e);return t===void 0||t===""?"":`?${new URLSearchParams({cwd:t}).toString()}`}function J(e,t={}){const i=Mn(e);return JSON.stringify(i===void 0||i===""?t:{cwd:i,...t})}const En={piWebStatus:(e="local")=>v(e==="local"?"/api/pi-web/status":`${R(e)}/pi-web/status`,Wl),piWebRuntime:()=>v("/api/pi-web/runtime",_l)},od={machines:()=>v("/api/machines",qc),addMachine:e=>v("/api/machines",Sn,{method:"POST",body:JSON.stringify(e)}),deleteMachine:e=>v(`/api/machines/${encodeURIComponent(e)}`,t=>t,{method:"DELETE"}),health:e=>v(`/api/machines/${encodeURIComponent(e)}/health`,Kc),runtime:e=>v(`/api/machines/${encodeURIComponent(e)}/runtime`,Vc)},gi={config:()=>v("/api/config",qo),saveConfig:e=>v("/api/config",qo,{method:"PUT",body:JSON.stringify({config:e})})},$s={plugins:()=>v("/api/plugins",Tl)},Dn={workspaceActivity:(e="local")=>v(`${R(e)}/activity`,Pl)},rd={projects:(e="local")=>v(`${R(e)}/projects`,z(Bo)),addProject:(e,t,i,s="local")=>v(`${R(s)}/projects`,Bo,{method:"POST",body:JSON.stringify({path:e,name:t,create:i})}),closeProject:(e,t="local")=>v(`${R(t)}/projects/${encodeURIComponent(e)}`,ks,{method:"DELETE"}),projectDirectories:(e,t="local")=>v(`${R(t)}/project-directories?q=${encodeURIComponent(e)}`,z($n))},Ps={workspaces:(e,t="local")=>v(`${R(t)}/projects/${e}/workspaces`,z(Jc)),deleteWorkspace:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}`,Et,{method:"DELETE"}),workspaceTree:(e,t,i="",s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/tree?path=${encodeURIComponent(i)}`,gl),workspaceFile:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file?path=${encodeURIComponent(i)}`,vl),uploadWorkspaceFile:async(e,t,i,s,o="local")=>o==="local"?pd(e,t,i,s):v(`${R(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file`,Ss,{method:"POST",body:JSON.stringify({path:i,contentBase64:await ld(s)})}),createWorkspaceFile:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file`,Ss,{method:"POST",body:JSON.stringify({path:i,contentBase64:""})}),moveWorkspaceFile:(e,t,i,s,o="local")=>v(`${R(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file`,Ji,{method:"PATCH",body:JSON.stringify({fromPath:i,toPath:s})}),deleteWorkspaceFile:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file?path=${encodeURIComponent(i)}`,Uo,{method:"DELETE"}),createWorkspaceDirectory:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/directory`,Ji,{method:"POST",body:JSON.stringify({path:i})}),moveWorkspaceDirectory:(e,t,i,s,o="local")=>v(`${R(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/directory`,Ji,{method:"PATCH",body:JSON.stringify({fromPath:i,toPath:s})}),deleteWorkspaceDirectory:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/directory?path=${encodeURIComponent(i)}`,Uo,{method:"DELETE"}),workspaceDownloadUrl:(e,t,i,s="local")=>Cn(e,t,i,{machineId:s}),downloadWorkspaceFile:(e,t,i,s="local")=>hd(e,t,i,s)},nd={sessions:(e,t="local")=>v(`${R(t)}/sessions?cwd=${encodeURIComponent(e)}`,z(xs)),startSession:(e,t="local")=>v(`${R(t)}/sessions`,xs,{method:"POST",body:JSON.stringify({cwd:e})}),messages:(e,t,i="local")=>v(ed(e,t,i),Hc),status:(e,t="local")=>v(Qt(e,"status",t),yt),models:(e,t="local")=>v(Qt(e,"models",t),tl),setModel:(e,t,i,s="local")=>v(V(e,"model",s),yt,{method:"POST",body:J(e,{provider:t,modelId:i})}),cycleModel:(e,t,i="local")=>v(V(e,"model/cycle",i),yt,{method:"POST",body:J(e,{direction:t})}),thinkingLevels:(e,t="local")=>v(Qt(e,"thinking-levels",t),sl),setThinkingLevel:(e,t,i="local")=>v(V(e,"thinking-level",i),yt,{method:"POST",body:J(e,{level:t})}),cycleThinkingLevel:(e,t="local")=>v(V(e,"thinking-level/cycle",t),yt,{method:"POST",body:J(e)}),commands:(e,t="local")=>v(Qt(e,"commands",t),z(fl)),prompt:(e,t,i,s="local",o)=>v(V(e,"prompt",s),Jt,{method:"POST",body:J(e,{text:t,...i===void 0?{}:{streamingBehavior:i},...o!==void 0&&o.length>0?{attachments:o}:{}})}),saveAttachments:(e,t,i="local",s)=>v(V(e,"attachments",i),Ul,{method:"POST",body:J(e,{attachments:t,...s===void 0?{}:{folder:s}})}),shell:(e,t,i="local")=>v(V(e,"shell",i),Jt,{method:"POST",body:J(e,{text:t})}),runCommand:(e,t,i="local")=>v(V(e,"commands/run",i),Go,{method:"POST",body:J(e,{text:t})}),respondToCommand:(e,t,i,s="local")=>v(V(e,"commands/respond",s),Go,{method:"POST",body:J(e,{requestId:t,value:i})}),abort:(e,t="local")=>v(V(e,"abort",t),ql,{method:"POST",body:J(e)}),stop:(e,t="local")=>v(V(e,"stop",t),Kl,{method:"POST",body:J(e)}),archive:(e,t="local")=>v(V(e,"archive",t),Jo,{method:"POST",body:J(e)}),archiveWithDescendants:(e,t="local")=>v(V(e,"archive-tree",t),Jo,{method:"POST",body:J(e)}),restore:(e,t="local")=>v(V(e,"restore",t),Vl,{method:"POST",body:J(e)}),deleteArchived:(e,t="local")=>v(sd(e,t),Gl,{method:"DELETE"}),detachParent:(e,t="local")=>v(V(e,"detach-parent",t),Jl,{method:"POST",body:J(e)}),reloadSession:(e,t="local")=>v(V(e,"reload",t),Ql,{method:"POST",body:J(e)}),authProviders:e=>{const t=new URLSearchParams;e?.mode!==void 0&&t.set("mode",e.mode),e?.authType!==void 0&&t.set("authType",e.authType);const i=t.toString();return v(`${R(e?.machineId)}/auth/providers${i===""?"":`?${i}`}`,cl)},saveApiKey:(e,t,i="local")=>v(`${R(i)}/auth/api-key`,Jt,{method:"POST",body:JSON.stringify({providerId:e,key:t})}),logoutProvider:(e,t="local")=>v(`${R(t)}/auth/logout`,Jt,{method:"POST",body:JSON.stringify({providerId:e})}),startOAuthLogin:(e,t="local")=>v(`${R(t)}/auth/oauth`,Gt,{method:"POST",body:JSON.stringify({providerId:e})}),oauthFlow:(e,t="local")=>v(`${R(t)}/auth/oauth/${encodeURIComponent(e)}`,Gt),respondOAuthFlow:(e,t,i,s="local")=>v(`${R(s)}/auth/oauth/${encodeURIComponent(e)}/respond`,Gt,{method:"POST",body:JSON.stringify({requestId:t,value:i})}),cancelOAuthFlow:(e,t="local")=>v(`${R(t)}/auth/oauth/${encodeURIComponent(e)}/cancel`,Gt,{method:"POST"})},dt={terminals:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals`,z(Qi)),startTerminal:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals`,Qi,{method:"POST",body:JSON.stringify(i??{})}),closeWorkspaceTerminals:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals`,ks,{method:"DELETE"}),closeTerminal:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals/${encodeURIComponent(i)}`,ks,{method:"DELETE"}),continueTerminal:(e,t,i,s="local")=>v(`${R(s)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals/${encodeURIComponent(i)}/continue`,Qi,{method:"POST"}),runTerminalCommand:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(t.workspace.projectId)}/workspaces/${encodeURIComponent(t.workspace.id)}/terminal-command-runs`,Et,{method:"POST",body:JSON.stringify({origin:e,title:t.title,command:t.command,metadata:t.metadata??{}})}),listCommandRuns:(e,t="local")=>v(`${R(t)}/terminal-command-runs${cd(e)}`,z(Et)),getCommandRun:(e,t="local")=>ad(e,t),cancelCommandRun:(e,t="local")=>v(`${R(t)}/terminal-command-runs/${encodeURIComponent(e)}/cancel`,Et,{method:"POST"})};async function ad(e,t){const i=await fetch(`${R(t)}/terminal-command-runs/${encodeURIComponent(e)}`);if(i.status!==404){if(!i.ok){const s=await i.json().catch(()=>({}));throw new Error(Js(s)??i.statusText)}return Et(await i.json())}}function cd(e){if(e===void 0)return"";const t=new URLSearchParams;e.projectId!==void 0&&t.set("projectId",e.projectId),e.workspaceId!==void 0&&t.set("workspaceId",e.workspaceId),e.terminalId!==void 0&&t.set("terminalId",e.terminalId),e.statuses!==void 0&&e.statuses.length>0&&t.set("statuses",e.statuses.join(",")),e.metadata!==void 0&&Object.keys(e.metadata).length>0&&t.set("metadata",JSON.stringify(e.metadata));const i=t.toString();return i===""?"":`?${i}`}function Js(e){if(!ud(e))return;const t=e.error;return typeof t=="string"?t:void 0}async function ld(e){return dd(await e.arrayBuffer())}function dd(e){const t=new Uint8Array(e);let i="";for(const s of t)i+=String.fromCharCode(s);return btoa(i)}async function pd(e,t,i,s){const o=new FormData;o.set("path",i),o.set("file",s,s.name);const r=await fetch(`${R("local")}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file`,{method:"POST",body:o});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(Js(n)??r.statusText)}return Ss(await r.json())}async function hd(e,t,i,s){const o=await fetch(Cn(e,t,i,{machineId:s}));if(!o.ok){const p=await o.json().catch(()=>({}));throw new Error(Js(p)??o.statusText)}const r=await o.blob(),n=URL.createObjectURL(r),a=document.createElement("a");a.href=n;const l=i.split("/").pop();a.download=l===void 0||l===""?"download":l,document.body.append(a),a.click(),a.remove(),URL.revokeObjectURL(n)}function ud(e){return typeof e=="object"&&e!==null}const fd={files:(e,t,i={})=>{const s=new URLSearchParams({cwd:e,q:t});return i.kind!==void 0&&s.set("kind",i.kind),i.mode!==void 0&&s.set("mode",i.mode),i.scope!==void 0&&s.set("scope",i.scope),v(`${R(i.machineId)}/files?${s.toString()}`,z($n))}},gd={gitStatus:(e,t,i="local")=>v(`${R(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/git/status`,wl),gitDiff:(e,t,i,s="local")=>v(Yl(s,e,t,i),Sl)},N={...En,...od,...gi,...$s,...Dn,...rd,...Ps,...nd,...dt,...fd,...gd};function md(e,t="local"){const i=typeof e=="string"?void 0:e.cwd,s=i===void 0||i===""?"":`?${new URLSearchParams({cwd:i}).toString()}`,o=typeof e=="string"?e:e.id;return new WebSocket(`${Zs()}${Qs(t)}/sessions/${encodeURIComponent(o)}/events${s}`)}function iy(e,t,i,s,o="local"){const r=s===void 0?"":`?cols=${encodeURIComponent(String(s.cols))}&rows=${encodeURIComponent(String(s.rows))}`;return new WebSocket(`${Zs()}${Qs(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/terminals/${encodeURIComponent(i)}/socket${r}`)}function vd(e="local"){return new WebSocket(`${Zs()}${Qs(e)}/events`)}function Qs(e){return`/api/machines/${encodeURIComponent(e)}`}function Zs(){return`${location.protocol==="https:"?"wss:":"ws:"}//${location.host}`}function ni(){return{sessions:[],fileTree:[],expandedDirs:{},selectedFilePath:void 0,selectedFileContent:void 0,fileTreeStale:!1,gitStatus:void 0,selectedDiffPath:void 0,selectedDiff:void 0,selectedStagedDiff:void 0,gitStale:!1,selectedTerminalId:void 0,error:""}}function bd(){return{machines:[],selectedMachine:void 0,isLoadingMachines:!1,machineStatuses:{},machineRuntimes:{},projects:[],workspaces:[],sessions:[],messages:[],messagePageStart:0,messagePageEnd:0,messagePageTotal:0,isLoadingEarlierMessages:!1,isReceivingPartialStream:!1,sendingPrompts:{},isLoadingProjects:!1,isLoadingWorkspaces:!1,selectedProject:void 0,selectedWorkspace:void 0,selectedSession:void 0,status:void 0,activity:void 0,availableThinkingLevels:[],sessionStatuses:{},sessionActivities:{},workspaceActivities:{},machineActivities:{},workspacesByProjectId:{},workspaceDeletionRuns:{},commandDialog:void 0,modelDialog:void 0,thinkingDialog:void 0,themeDialog:void 0,authDialog:void 0,actionPaletteOpen:!1,projectDialogOpen:!1,machineDialogOpen:!1,workspaceTool:"core:workspace.files",mainView:"chat",fileTree:[],expandedDirs:{},selectedFilePath:void 0,selectedFileContent:void 0,fileTreeStale:!1,gitStatus:void 0,selectedDiffPath:void 0,selectedDiff:void 0,selectedStagedDiff:void 0,gitStale:!1,activeTerminalCount:0,selectedTerminalId:void 0,piWebStatus:void 0,error:""}}function Xe(e,t){return t?.phase==="active"||e?.isStreaming===!0||e?.isBashRunning===!0||e?.isCompacting===!0||(e?.pendingMessageCount??0)>0}function Wn(e){return e!==void 0&&(e.hasSessionActivity||e.hasTerminalActivity)}const _n="local";function Zi(e,t){return`${e}:${t}`}function Ln(e,t){return`${e}:${t}`}function f(e){return e.selectedMachine?.id??_n}class wd{constructor(t,i,s={}){this.getState=t,this.setState=i,this.api=s.api??Dn}async refresh(t=f(this.getState())){this.applyMachineActivitySnapshot(t,yd(await this.api.workspaceActivity(t)))}applyWorkspaceActivity(t,i=f(this.getState())){const s=this.getState(),o=f(s)===i,r=s.machineActivities[i]??(o?s.workspaceActivities:{}),n=Sd(r,t);this.setState({machineActivities:{...s.machineActivities,[i]:n},...o?{workspaceActivities:n}:{}})}applyMachineActivitySnapshot(t,i){const s=this.getState();this.setState({machineActivities:{...s.machineActivities,[t]:i},...f(s)===t?{workspaceActivities:i}:{}})}}function yd(e){const t={};for(const i of e.workspaces)Wn(i)&&(t[i.cwd]=i);return t}function Sd(e,t){const i={...e};return Wn(t)?(i[t.cwd]=t,i):Object.fromEntries(Object.entries(i).filter(([s])=>s!==t.cwd))}class xd{constructor(t,i,s,o={}){this.getState=t,this.setState=i,this.applyStatus=s,this.api=o.api??N,this.pollIntervalMs=o.pollIntervalMs??1e3}dispose(){this.stopPolling()}handleSlashCommand(t){const i=kd(t);return i===void 0?!1:(i.command==="login"?this.openLogin(i.providerId):this.openLogout(i.providerId),!0)}async openLogin(t){if(t!==void 0&&t!==""){await this.openLoginProvider(t);return}this.setState({authDialog:{step:"method"}})}async chooseLoginMethod(t){try{const{providers:i}=await this.api.authProviders({mode:"login",authType:t,machineId:f(this.getState())});this.setState({authDialog:{step:"providers",mode:"login",authType:t,providers:i}})}catch(i){this.setState({error:String(i)})}}async selectLoginProvider(t,i){const s=this.getState().authDialog;if(s?.step!=="providers")return;const o=s.providers.find(r=>r.id===t&&(i===void 0||r.authType===i));o!==void 0&&(o.authType==="oauth"?await this.startOAuth(o):this.setState({authDialog:{step:"apiKey",provider:o,value:""}}))}updateApiKey(t){const i=this.getState().authDialog;if(i?.step!=="apiKey")return;const s={...i};delete s.error,this.setState({authDialog:{...s,value:t}})}async saveApiKey(){const t=this.getState().authDialog;if(t?.step!=="apiKey")return;const i=t.value.trim();if(i===""){this.setState({authDialog:{...t,error:"API key is required"}});return}const s={...t};delete s.error,this.setState({authDialog:{...s,saving:!0}});try{await this.api.saveApiKey(t.provider.id,i,f(this.getState())),this.closeDialog(),this.refreshStatus()}catch(o){this.setState({authDialog:{...t,saving:!1,error:String(o)}})}}async openLogout(t){try{const{providers:i}=await this.api.authProviders({mode:"logout",machineId:f(this.getState())});if(t!==void 0&&t!==""){const s=i.find(o=>o.id===t);s!==void 0&&!this.rejectRemoteOAuth("logout",s)?await this.logoutProvider(s.id):s===void 0&&this.setState({error:`No stored credentials for ${t}`});return}this.setState({authDialog:{step:"logout",providers:i}})}catch(i){this.setState({error:String(i)})}}async logoutProvider(t){const i=this.getState().authDialog,s=i?.step==="logout"?i.providers.find(o=>o.id===t):void 0;if(!(s!==void 0&&this.rejectRemoteOAuth("logout",s)))try{await this.api.logoutProvider(t,f(this.getState())),this.closeDialog(),this.refreshStatus()}catch(o){this.setState({error:String(o)})}}updateOAuthInput(t){const i=this.getState().authDialog;if(i?.step!=="oauth")return;const s={...i};delete s.error,this.setState({authDialog:{...s,inputValue:t}})}async respondOAuth(t){const i=this.getState().authDialog;if(i?.step!=="oauth")return;const s=i.flow.prompt??i.flow.select;if(s===void 0)return;const o=t??i.inputValue??"",r={...i};delete r.error,this.setState({authDialog:{...r,responding:!0}});try{const n=await this.api.respondOAuthFlow(i.flow.flowId,s.requestId,o,f(this.getState()));this.updateOAuthFlow(n)}catch(n){this.setState({authDialog:{...i,responding:!1,error:String(n)}})}}async cancelOAuth(){const t=this.getState().authDialog;if(t?.step!=="oauth"){this.closeDialog();return}this.stopPolling();try{await this.api.cancelOAuthFlow(t.flow.flowId,f(this.getState()))}catch{}this.closeDialog()}closeDialog(){this.stopPolling(),this.setState({authDialog:void 0})}async openLoginProvider(t){try{const{providers:i}=await this.api.authProviders({mode:"login",machineId:f(this.getState())}),s=i.filter(r=>r.id===t);if(s.length===0){this.setState({error:`Auth provider not found: ${t}`});return}if(s.length>1){this.setState({authDialog:{step:"providers",mode:"login",providers:s}});return}const o=s[0];if(o===void 0)return;o.authType==="oauth"?await this.startOAuth(o):this.setState({authDialog:{step:"apiKey",provider:o,value:""}})}catch(i){this.setState({error:String(i)})}}async startOAuth(t){if(!this.rejectRemoteOAuth("login",t))try{const i=await this.api.startOAuthLogin(t.id,f(this.getState()));this.updateOAuthFlow(i),this.startPolling(i.flowId)}catch(i){this.setState({error:String(i)})}}rejectRemoteOAuth(t,i){const s=this.getState().selectedMachine;if(i.authType!=="oauth"||s?.kind!=="remote")return!1;const o=s.baseUrl??"that remote PI WEB instance";return this.setState({error:`OAuth ${t} for remote machines must be configured directly on ${o}.`}),!0}updateOAuthFlow(t){if(t.status==="complete"){this.stopPolling(),this.closeDialog(),this.refreshStatus();return}(t.status==="error"||t.status==="cancelled")&&this.stopPolling();const i=this.getState().authDialog,s=i?.step==="oauth"&&i.flow.flowId===t.flowId?i.inputValue??"":"",o=i?.step==="oauth"?i.flow.prompt?.requestId??i.flow.select?.requestId:void 0,r=t.prompt?.requestId??t.select?.requestId,n=o!==void 0&&o===r,a=n?s:"",l=n&&i?.step==="oauth"?i.responding===!0:!1;this.setState({authDialog:{step:"oauth",flow:t,inputValue:a,responding:l}})}startPolling(t){this.stopPolling(),this.pollTimer=window.setInterval(()=>{this.poll(t)},this.pollIntervalMs)}stopPolling(){this.pollTimer!==void 0&&(window.clearInterval(this.pollTimer),this.pollTimer=void 0)}async poll(t){const i=this.getState().authDialog;if(i?.step!=="oauth"||i.flow.flowId!==t){this.stopPolling();return}try{this.updateOAuthFlow(await this.api.oauthFlow(t,f(this.getState())))}catch(s){this.stopPolling(),this.setState({authDialog:{...i,error:String(s)}})}}async refreshStatus(){const t=this.session();if(t!==void 0)try{this.applyStatus(await this.api.status(t,f(this.getState())))}catch{}}session(){const t=this.getState().selectedSession;if(!(t===void 0||t.archived===!0))return t}}function kd(e){const t=e.trim(),i=/^\/(login|logout)(?:\s+(\S+))?\s*$/u.exec(t);if(i===null)return;const s=i[1];if(s!=="login"&&s!=="logout")return;const o=i[2];return o===void 0||o===""?{command:s}:{command:s,providerId:o}}function Ft(e){return e.replaceAll(":",".")}function $d(e){const t=new URLSearchParams(window.location.search),i=`${e}--`,s={};for(const[o,r]of t.entries()){if(!o.startsWith(i))continue;const n=o.slice(i.length),a=s[n];a===void 0?s[n]=r:Array.isArray(a)?a.push(r):s[n]=[a,r]}return s}function Xi(e,t){const i=$d(e)[t];return Array.isArray(i)?i[0]:i===""?void 0:i}function le(e,t,i,s){const o=new URL(window.location.href),r=`${e}--${t}`;if(o.searchParams.delete(r),i!=null&&i!=="")if(Array.isArray(i))for(const n of i)o.searchParams.append(r,String(n));else o.searchParams.set(r,String(i));Pd(o,s)}function Pd(e,t){const i=`${e.pathname}${e.search}${e.hash}`,s=`${window.location.pathname}${window.location.search}${window.location.hash}`;i!==s&&(t?.replace===!0?window.history.replaceState({},"",e):window.history.pushState({},"",e))}const Zt=Ft("core:workspace.files");class Rd{constructor(t,i,s,o={}){this.getState=t,this.setState=i,this.updateUrl=s,this.api=o.api??N}async refreshFiles(){const t=this.getState().selectedProject,i=this.getState().selectedWorkspace;if(!(t===void 0||i===void 0))try{const s=f(this.getState()),o=await this.api.workspaceTree(t.id,i.id,"",s),r=await Promise.all(Object.keys(this.getState().expandedDirs).map(async a=>{try{const l=await this.api.workspaceTree(t.id,i.id,a,s);return[a,l.entries]}catch(l){if(Xo(l))return;throw l}})),n=Object.fromEntries(r.filter(a=>a!==void 0));this.setState({fileTree:o.entries,expandedDirs:n,fileTreeStale:!1,error:""})}catch(s){this.setState({error:String(s)})}}async expandDir(t){const i=this.getState().selectedProject,s=this.getState().selectedWorkspace;if(!(i===void 0||s===void 0)){if(this.getState().expandedDirs[t]!==void 0){this.setState({expandedDirs:Id(this.getState().expandedDirs,t)});return}try{const o=await this.api.workspaceTree(i.id,s.id,t,f(this.getState()));this.setState({expandedDirs:{...this.getState().expandedDirs,[t]:o.entries},error:""})}catch(o){this.setState({error:String(o)})}}}async selectFile(t){this.setState({selectedFilePath:t,selectedFileContent:void 0,workspaceTool:"core:workspace.files",mainView:this.getState().mainView==="chat"?"chat":"core:workspace.files"}),le(Zt,"file",t),this.updateUrl({replace:!0}),await this.restoreFile(t)}selectDirectory(t){this.setState({selectedFilePath:t,selectedFileContent:void 0,workspaceTool:"core:workspace.files",mainView:this.getState().mainView==="chat"?"chat":"core:workspace.files"}),le(Zt,"file",void 0,{replace:!0}),this.updateUrl({replace:!0})}async restoreFile(t){const i=this.getState().selectedProject,s=this.getState().selectedWorkspace;if(!(i===void 0||s===void 0)){this.setState({selectedFilePath:t,selectedFileContent:void 0});try{const o=await this.api.workspaceFile(i.id,s.id,t,f(this.getState()));this.getState().selectedFilePath===t&&this.setState({selectedFileContent:o,error:""})}catch(o){if(this.getState().selectedFilePath!==t)return;if(Xo(o)){this.setState({selectedFilePath:void 0,selectedFileContent:void 0,error:""}),le(Zt,"file",void 0,{replace:!0}),this.updateUrl({replace:!0});return}this.setState({error:String(o)})}}}async uploadFiles(t){const i=this.getState().selectedProject,s=this.getState().selectedWorkspace;if(!(i===void 0||s===void 0||t.length===0))try{const o=f(this.getState()),r=Cd(this.getState()),n=[];for(const l of t){const p=Td(r,Md(l));await this.api.uploadWorkspaceFile(i.id,s.id,p,l,o),n.push(p)}await this.refreshFiles();const a=n.at(-1);a!==void 0&&await this.selectFile(a),this.setState({error:""})}catch(o){this.setState({error:String(o)})}}async createFile(t){const i=this.getState().selectedProject,s=this.getState().selectedWorkspace;if(!(i===void 0||s===void 0||t===""))try{await this.api.createWorkspaceFile(i.id,s.id,t,f(this.getState())),await this.refreshFiles(),await this.selectFile(t),this.setState({error:""})}catch(o){this.setState({error:String(o)})}}async createDirectory(t){const i=this.getState().selectedProject,s=this.getState().selectedWorkspace;if(!(i===void 0||s===void 0||t===""))try{await this.api.createWorkspaceDirectory(i.id,s.id,t,f(this.getState())),await this.refreshFiles(),this.selectDirectory(t),this.setState({error:""})}catch(o){this.setState({error:String(o)})}}async moveSelectedPath(t){const i=this.getState().selectedProject,s=this.getState().selectedWorkspace,o=this.getState().selectedFilePath;if(!(i===void 0||s===void 0||o===void 0||o===""||t===""))try{const r=f(this.getState());Yi(this.getState())==="directory"?(await this.api.moveWorkspaceDirectory(i.id,s.id,o,t,r),await this.refreshFiles(),this.selectDirectory(t)):(await this.api.moveWorkspaceFile(i.id,s.id,o,t,r),await this.refreshFiles(),await this.selectFile(t)),this.setState({error:""})}catch(r){this.setState({error:String(r)})}}async deleteSelectedPath(){const t=this.getState().selectedProject,i=this.getState().selectedWorkspace,s=this.getState().selectedFilePath;if(!(t===void 0||i===void 0||s===void 0||s===""))try{const o=f(this.getState());Yi(this.getState())==="directory"?await this.api.deleteWorkspaceDirectory(t.id,i.id,s,o):await this.api.deleteWorkspaceFile(t.id,i.id,s,o),await this.refreshFiles(),this.clearSelection(),this.setState({error:""})}catch(o){this.setState({error:String(o)})}}async downloadSelectedFile(){const t=this.getState().selectedProject,i=this.getState().selectedWorkspace,s=this.getState().selectedFilePath;if(!(t===void 0||i===void 0||s===void 0||s===""||Yi(this.getState())==="directory"))try{await this.api.downloadWorkspaceFile(t.id,i.id,s,f(this.getState())),this.setState({error:""})}catch(o){this.setState({error:String(o)})}}clearSelection(){this.setState({selectedFilePath:void 0,selectedFileContent:void 0}),le(Zt,"file",void 0,{replace:!0}),this.updateUrl({replace:!0})}}function Xo(e){const t=String(e);return t.includes("Path does not exist")||t.includes("ENOENT")||t.includes("no such file or directory")}function Id(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>i!==t))}function Cd(e){const t=e.selectedFilePath;if(t===void 0||t==="")return"";if(On(e.fileTree,e.expandedDirs,t)?.type==="directory")return t;const s=t.lastIndexOf("/");return s===-1?"":t.slice(0,s)}function Yi(e){const t=e.selectedFilePath;return t===void 0?"file":On(e.fileTree,e.expandedDirs,t)?.type==="directory"?"directory":"file"}function On(e,t,i){const s=e.find(o=>o.path===i);if(s!==void 0)return s;for(const o of Object.values(t)){const r=o.find(n=>n.path===i);if(r!==void 0)return r}}function Md(e){return e.name.split(/[\\/]+/u).filter(t=>t!=="").at(-1)??e.name}function Td(e,t){return e===""?t:`${e}/${t}`}const Yo=Ft("core:workspace.git");class Ad{constructor(t,i,s){this.getState=t,this.setState=i,this.updateUrl=s}dispose(){this.pollTimer!==void 0&&window.clearInterval(this.pollTimer),this.pollTimer=void 0}async refreshGit(){const t=this.getState().selectedProject,i=this.getState().selectedWorkspace;if(!(t===void 0||i===void 0))try{const s=await N.gitStatus(t.id,i.id,f(this.getState()));this.setState({gitStatus:s,gitStale:!1,error:""});const o=this.getState().selectedDiffPath;o!==void 0&&(s.files.some(r=>r.path===o)?await this.refreshDiff(o):(this.setState({selectedDiffPath:void 0,selectedDiff:void 0,selectedStagedDiff:void 0}),le(Yo,"diff",void 0,{replace:!0})))}catch(s){this.setState({error:String(s)})}}async selectDiff(t){this.setState({selectedDiffPath:t,selectedDiff:void 0,selectedStagedDiff:void 0,workspaceTool:"core:workspace.git",mainView:this.getState().mainView==="chat"?"chat":"core:workspace.git"}),le(Yo,"diff",t),this.updateUrl({replace:!0}),await this.refreshDiff(t)}async restoreDiff(t){this.setState({selectedDiffPath:t,selectedDiff:void 0,selectedStagedDiff:void 0}),await this.refreshDiff(t)}async refreshDiff(t){const i=this.getState().selectedProject,s=this.getState().selectedWorkspace;if(!(i===void 0||s===void 0))try{const[o,r]=await Promise.all([N.gitDiff(i.id,s.id,{path:t},f(this.getState())),N.gitDiff(i.id,s.id,{path:t,staged:!0},f(this.getState()))]);this.setState({selectedDiff:o,selectedStagedDiff:r,error:""})}catch(o){this.setState({error:String(o)})}}updatePolling(){this.dispose();const t=this.getState();(t.workspaceTool==="core:workspace.git"||t.mainView==="core:workspace.git")&&(this.pollTimer=window.setInterval(()=>{this.refreshGit()},8e3))}}class Ed{constructor(t,i,s,o){this.getState=t,this.setState=i,this.updateUrl=s,this.projects=o}async loadMachines(t){this.setState({error:"",isLoadingMachines:!0});try{const i=await N.machines(),s=await this.selectInitialMachine(i,t),o=new Set(i.map(r=>r.id));this.setState({machines:i,selectedMachine:s,machineActivities:er(this.getState().machineActivities,o),machineRuntimes:er(this.getState().machineRuntimes,o)}),this.refreshMachineHealthFor(i),this.refreshMachineRuntimeFor(i)}catch(i){this.setState({error:String(i)})}finally{this.setState({isLoadingMachines:!1})}}async selectMachine(t,i={}){this.getState().selectedMachine?.id!==t.id&&(this.setState({selectedMachine:t,projects:[],workspaces:[],isLoadingWorkspaces:!1,selectedProject:void 0,selectedWorkspace:void 0,selectedSession:void 0,messages:[],messagePageStart:0,messagePageTotal:0,status:void 0,activity:void 0,sessionStatuses:{},sessionActivities:{},sendingPrompts:{},workspaceActivities:{},workspacesByProjectId:{},workspaceDeletionRuns:{},activeTerminalCount:0,...ni()}),i.updateUrl!==!1&&this.updateUrl(),await this.projects.loadProjects(),this.refreshMachineHealth(t.id),this.refreshMachineRuntime(t.id))}async addMachine(t){this.setState({error:""});try{const i=await N.addMachine(t);return this.setState({machines:[...this.getState().machines.filter(s=>s.id!==i.id),i]}),await this.selectMachine(i),i}catch(i){this.setState({error:String(i)});return}}async deleteMachine(t=this.getState().selectedMachine,i={}){if(t!==void 0){if(t.kind==="local"){this.setState({error:"The local machine cannot be removed."});return}try{const s=this.getState().selectedMachine?.id===t.id;await N.deleteMachine(t.id);const o=this.getState().machines.filter(n=>n.id!==t.id),r=o.find(n=>n.id==="local")??o[0];return this.setState({machines:o,machineStatuses:es(this.getState().machineStatuses,t.id),machineRuntimes:es(this.getState().machineRuntimes,t.id),machineActivities:es(this.getState().machineActivities,t.id)}),s&&r!==void 0?(i.selectFallback===!1||await this.selectMachine(r),r):void 0}catch(s){this.setState({error:String(s)});return}}}async refreshMachineHealth(t=this.getState().selectedMachine?.id??"local"){try{const i=await N.health(t);return this.setState({machineStatuses:{...this.getState().machineStatuses,[i.machineId]:i}}),i}catch(i){this.setState({error:String(i)});return}}async refreshMachineRuntime(t=this.getState().selectedMachine?.id??"local"){try{const i=await N.runtime(t);this.setState({machineRuntimes:{...this.getState().machineRuntimes,[i.machineId]:i}})}catch(i){this.setState({error:String(i)})}}async selectInitialMachine(t,i){const s=t.find(r=>r.id===(i??"local"));if(s===void 0)return this.localMachine(t);if(s.kind!=="remote")return s;const o=await this.safeRemoteHealth(s);return this.setState({machineStatuses:{...this.getState().machineStatuses,[o.machineId]:o},...o.ok?{}:{error:`${s.name} is unavailable; reconnecting…`}}),s}async safeRemoteHealth(t){try{return await N.health(t.id)}catch(i){return{machineId:t.id,ok:!1,checkedAt:new Date().toISOString(),status:"offline",error:i instanceof Error?i.message:String(i)}}}localMachine(t){return t.find(i=>i.id==="local")??t[0]}async refreshMachineHealthFor(t){const i=await Promise.allSettled(t.map(o=>N.health(o.id))),s=Object.fromEntries(i.flatMap(o=>o.status==="fulfilled"?[[o.value.machineId,o.value]]:[]));Object.keys(s).length>0&&this.setState({machineStatuses:{...this.getState().machineStatuses,...s}})}async refreshMachineRuntimeFor(t){const i=await Promise.allSettled(t.map(o=>N.runtime(o.id))),s=Object.fromEntries(i.flatMap(o=>o.status==="fulfilled"?[[o.value.machineId,o.value]]:[]));Object.keys(s).length>0&&this.setState({machineRuntimes:{...this.getState().machineRuntimes,...s}})}}function es(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>i!==t))}function er(e,t){return Object.fromEntries(Object.entries(e).filter(([i])=>t.has(i)))}class Dd{constructor(t,i,s){this.getState=t,this.setState=i,this.workspaces=s}async loadProjects(){const t=f(this.getState());this.setState({error:"",isLoadingProjects:!0});try{const i=await N.projects(t);if(f(this.getState())!==t)return;const s=new Set(i.map(r=>r.id)),o=Object.fromEntries(Object.entries(this.getState().workspacesByProjectId).filter(([r])=>s.has(r)));this.setState({projects:i,workspacesByProjectId:o})}catch(i){f(this.getState())===t&&this.setState({error:String(i)})}finally{f(this.getState())===t&&this.setState({isLoadingProjects:!1})}}async addProject(t,i){if(t.trim()!=="")try{const s=await N.addProject(t.trim(),void 0,i,f(this.getState())),o=this.getState().projects;this.setState({projects:[...o.filter(r=>r.id!==s.id),s],projectDialogOpen:!1}),await this.workspaces.selectProject(s)}catch(s){this.setState({error:String(s)})}}async closeProject(t){try{await N.closeProject(t,f(this.getState())),this.workspaces.forgetProject(t);const i=this.getState();this.setState({projects:i.projects.filter(s=>s.id!==t)}),i.selectedProject?.id===t&&this.workspaces.clearSelection()}catch(i){this.setState({error:String(i)})}}}const Rs="pi-web:cached-new-sessions:v1",Wd="browserCachedNew",gt="local";function zt(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}function tr(e,t=gt,i=zt()){if(e.messageCount!==0||e.archived===!0)return;const s=Xs(i).filter(o=>o.id!==e.id||o.machineId!==t);Ys([Is(e,t),...s],i)}function Is(e,t=gt){return{...e,browserCachedNew:!0,machineId:t}}function ir(e,t=gt,i=zt()){const s=Xs(i).filter(o=>o.id!==e||o.machineId!==t);Ys(s,i)}function _d(e,t,i=gt,s=zt()){const o=new Set(t.map(l=>l.id)),r=Xs(s),n=r.filter(l=>l.machineId!==i||!o.has(l.id));return n.length!==r.length&&Ys(n,s),[...n.filter(l=>l.machineId===i&&l.cwd===e),...t]}function ee(e){return e===void 0?!1:jd(e)&&e.browserCachedNew===!0}function Ld(e){return{id:e.id,path:e.path,cwd:e.cwd,...e.name===void 0?{}:{name:e.name},created:e.created,modified:e.modified,messageCount:e.messageCount,firstMessage:e.firstMessage,...e.parentSessionPath===void 0?{}:{parentSessionPath:e.parentSessionPath},..."machineId"in e&&typeof e.machineId=="string"?{machineId:e.machineId}:{machineId:gt},...e.archived===!0?{archived:!0}:{},...e.archivedAt===void 0?{}:{archivedAt:e.archivedAt}}}function Xs(e=zt()){try{const t=e?.getItem(Rs);if(t==null||t==="")return[];const i=JSON.parse(t);return Array.isArray(i)?i.flatMap(s=>Od(s)):[]}catch{return[]}}function Ys(e,t=zt()){try{e.length===0?t?.removeItem(Rs):t?.setItem(Rs,JSON.stringify(e))}catch{}}function Od(e){if(!Fd(e))return[];const t=nt(e,"id"),i=nt(e,"path"),s=nt(e,"cwd"),o=nt(e,"created"),r=nt(e,"modified"),n=nt(e,"firstMessage"),a=zd(e,"messageCount");if(t===void 0||i===void 0||s===void 0||o===void 0||r===void 0||n===void 0||a!==0)return[];const l=ts(e,"name"),p=ts(e,"parentSessionPath"),u=ts(e,"machineId")??gt;return[{id:t,path:i,cwd:s,...l===void 0?{}:{name:l},created:o,modified:r,messageCount:a,firstMessage:n,...p===void 0?{}:{parentSessionPath:p},machineId:u,browserCachedNew:!0}]}function jd(e){return Wd in e}function Fd(e){return typeof e=="object"&&e!==null}function nt(e,t){const i=e[t];return typeof i=="string"?i:void 0}function ts(e,t){const i=e[t];return i===void 0||typeof i!="string"?void 0:i}function zd(e,t){const i=e[t];return typeof i=="number"?i:void 0}function Nd(e){return sp(e.flatMap(eo)).filter(t=>t.parts.length>0)}function Ae(e,t){return{role:e,parts:[{type:"text",text:t}]}}function St(e,t){const i=Jd(t);return i===void 0?e:{...e,meta:i}}function Bd(e,t,i){if(i==="")return e;const s=e.at(-1),o=s?.parts.at(-1);return s?.role===t&&o?.type==="text"?[...e.slice(0,-1),{...s,parts:[...s.parts.slice(0,-1),{...o,text:o.text+i}]}]:s?.role===t?[...e.slice(0,-1),{...s,parts:[...s.parts,{type:"text",text:i}]}]:[...e,Ae(t,i)]}function Ud(e,t){if(t==="")return e;const i=e.at(-1),s=i?.parts.at(-1);return i?.role==="assistant"&&s?.type==="thinking"?[...e.slice(0,-1),{...i,parts:[...i.parts.slice(0,-1),{...s,text:s.text+t}]}]:i?.role==="assistant"?[...e.slice(0,-1),{...i,parts:[...i.parts,{type:"thinking",text:t}]}]:[...e,{role:"assistant",parts:[{type:"thinking",text:t}]}]}function eo(e){if(qd(e))return[e];if(W(e,"role")==="bashExecution")return[St(Xd(e),e)];const t=Yd(W(e,"role")),i=ep(ge(e,"content"),e),s=t==="user"?Kd(i):void 0;if(s!==void 0)return s.map(p=>St(p,e));const o=Gd(e);if(t==="tool")return[St({role:t,parts:i,...o===void 0?{}:{source:o}},e)];const r=i.filter(p=>p.type!=="empty"),n=t==="assistant"&&r.length>0&&r.every(p=>p.type==="skillRead")?"skill":t,a=r.length>0?[St({role:n,parts:r,...o===void 0?{}:{source:o}},e)]:[],l=Hd(e);return l===void 0?a:[...a,St(l,e)]}function Hd(e){if(W(e,"role")!=="assistant"||W(e,"stopReason")!=="error")return;const t=W(e,"errorMessage")?.trim();return Ae("system",`Model response failed: ${t===void 0||t===""?"The model returned an error.":t}`)}function qd(e){const t=W(e,"role");return(t==="user"||t==="assistant"||t==="tool"||t==="system"||t==="bash"||t==="skill")&&Array.isArray(ge(e,"parts"))}function Kd(e){if(e.length!==1||e[0]?.type!=="text")return;const t=Vd(e[0].text);if(t!==void 0)return[{role:"user",parts:[{type:"skillInvocation",name:t.name,location:t.location,content:t.content}]},...t.userMessage===void 0?[]:[{role:"user",parts:[{type:"text",text:t.userMessage}]}]]}function Vd(e){const t=/^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/.exec(e);if(t===null)return;const i=t[4]?.trim();return{name:t[1]??"skill",location:t[2]??"",content:t[3]??"",...i===void 0||i===""?{}:{userMessage:i}}}function Gd(e){const t=W(e,"source");if(t==="compaction"||t==="branch_summary")return t}function Jd(e){const t=Qd(ge(e,"timestamp")),i=Zd(e);if(!(t===void 0&&i===void 0))return{...t===void 0?{}:{timestamp:t},...i===void 0?{}:{model:i}}}function Qd(e){if(typeof e=="number"&&Number.isFinite(e))return new Date(e).toISOString();if(typeof e!="string"||e==="")return;const t=Date.parse(e);return Number.isFinite(t)?new Date(t).toISOString():void 0}function Zd(e){if(W(e,"role")!=="assistant")return;const t=W(e,"provider"),i=W(e,"model"),s=W(e,"responseModel");if(!((t===void 0||t==="")&&(i===void 0||i==="")&&(s===void 0||s==="")))return{...t===void 0||t===""?{}:{provider:t},...i===void 0||i===""?{}:{id:i},...s===void 0||s===""?{}:{responseId:s}}}function Xd(e){const t=W(e,"command")??"",i=ai(e,"excludeFromContext")===!0?["excluded from context","",`$ ${t}`]:[`$ ${t}`],s=ge(e,"output");s!=null&&i.push("",vi(s));const o=ge(e,"exitCode");o!=null&&i.push("",`exit ${vi(o)}`),ai(e,"cancelled")===!0&&i.push("","cancelled"),ai(e,"truncated")===!0&&i.push("","output truncated");const r=W(e,"fullOutputPath");return r!==void 0&&r!==""&&i.push("",`full output: ${r}`),{role:"bash",parts:[{type:"text",text:i.join(`
@@ -132,7 +132,7 @@ ${h}`;await this.api.prompt(a,g,i,p)}else await this.api.prompt(a,t,i,p,s);this.
132
132
  <div class="viewer-header"><strong>${e.path??"diff"}</strong><small>${e.staged?"已暂存":"未暂存"}${e.truncated?" · 已截断":""}</small></div>
133
133
  <code-viewer .content=${e.diff} .language=${"diff"}></code-viewer>
134
134
  </section>
135
- `}function la(){na(()=>import("./CodeViewer-rwuQkhmb.js"),__vite__mapDeps([0,1,2,3]))}function Uu(){na(()=>import("./TerminalPanel-BTDv_JgG.js"),__vite__mapDeps([4,5,6,1,2]))}function Hu(e){const t=e.branch??"分离 HEAD",i=e.ahead??0,s=e.behind??0;return i===0&&s===0?t:`${t} · ↑${String(i)} ↓${String(s)}`}function qu(e,t){return(t!=="unmodified"?t:e).slice(0,1).toUpperCase()}function Ds(e){if(!Number.isFinite(e)||e<0)return"0 B";if(e<1024)return`${String(e)} B`;const t=e/1024;if(t<1024)return`${ss(t)} KB`;const i=t/1024;return i<1024?`${ss(i)} MB`:`${ss(i/1024)} GB`}function ss(e){return e>=10?String(Math.round(e)):e.toFixed(1)}const Ku={apiVersion:1,name:"PI WEB 核心",activate:()=>{const e=!du();return{contributions:{actions:e?wr():wr().filter(t=>t.id!=="view.terminal"),workspacePanels:e?xr():xr().filter(t=>t.id!=="workspace.terminal")}}}},Vu={"--pi-bg":"#0d1117","--pi-surface":"#161b22","--pi-surface-hover":"#21262d","--pi-terminal-bg":"#05070a","--pi-terminal-text":"#e6edf3","--pi-border":"#30363d","--pi-border-muted":"#21262d","--pi-text":"#e6edf3","--pi-text-secondary":"#c9d1d9","--pi-text-bright":"#f0f6fc","--pi-muted":"#8b949e","--pi-dim":"#6e7681","--pi-accent":"#58a6ff","--pi-accent-border":"#2f81f7","--pi-selection-bg":"#0d2847","--pi-success":"#3fb950","--pi-success-border":"#238636","--pi-success-bg":"#0f1b12","--pi-success-surface":"#0f2a16","--pi-success-ring":"#3fb95055","--pi-warning":"#d29922","--pi-warning-border":"#6e5200","--pi-warning-surface":"#1f1a10","--pi-danger":"#ff7b72","--pi-purple":"#d2a8ff","--pi-purple-border":"#a371f7","--pi-purple-surface":"#21132f","--pi-overlay":"#0008","--pi-shadow-soft":"#0006","--pi-shadow":"#0008","--pi-shadow-strong":"#000b","--pi-bg-overlay-soft":"#0d1117dd","--pi-bg-overlay":"#0d1117e6","--pi-success-bg-overlay":"#0f1b12ee","--pi-terminal-selection":"#264f78"},Gu={"--pi-bg":"#070912","--pi-surface":"#101527","--pi-surface-hover":"#151b31","--pi-terminal-bg":"#050710","--pi-terminal-text":"#f7f4ff","--pi-border":"#26304f","--pi-border-muted":"#26304f","--pi-text":"#f7f4ff","--pi-text-secondary":"#aaa4bd","--pi-text-bright":"#ffffff","--pi-muted":"#aaa4bd","--pi-dim":"#817a99","--pi-accent":"#7c3cff","--pi-accent-border":"#5a47b0","--pi-selection-bg":"#1d2547","--pi-success":"#00f0d8","--pi-success-border":"#00f0d8","--pi-success-bg":"#071e22","--pi-success-surface":"#092d31","--pi-success-ring":"#00f0d855","--pi-warning":"#ffb000","--pi-warning-border":"#ffb000","--pi-warning-surface":"#16140d","--pi-danger":"#ff4f7b","--pi-purple":"#b7a2ff","--pi-purple-border":"#7c3cff","--pi-purple-surface":"#181026","--pi-overlay":"#0008","--pi-shadow-soft":"#0006","--pi-shadow":"#0008","--pi-shadow-strong":"#000b","--pi-bg-overlay-soft":"#070912dd","--pi-bg-overlay":"#070912e6","--pi-success-bg-overlay":"#071e22ee","--pi-terminal-selection":"#3d4a78"},Ju={"--pi-bg":"#f7f1e6","--pi-surface":"#fff9ee","--pi-surface-hover":"#f0e6d6","--pi-terminal-bg":"#15131b","--pi-terminal-text":"#fff9ee","--pi-border":"#c9bca8","--pi-border-muted":"#d8cdbc","--pi-text":"#15131b","--pi-text-secondary":"#15131b","--pi-text-bright":"#15131b","--pi-muted":"#5f586a","--pi-dim":"#766f7e","--pi-accent":"#6430d8","--pi-accent-border":"#6430d8","--pi-selection-bg":"#eadff8","--pi-success":"#008c82","--pi-success-border":"#008c82","--pi-success-bg":"#e1f4ef","--pi-success-surface":"#d7f0ec","--pi-success-ring":"#008c8255","--pi-warning":"#b05f00","--pi-warning-border":"#b05f00","--pi-warning-surface":"#fff2d2","--pi-danger":"#b51d49","--pi-purple":"#6430d8","--pi-purple-border":"#6430d8","--pi-purple-surface":"#eadff8","--pi-overlay":"#15131b66","--pi-shadow-soft":"#15131b22","--pi-shadow":"#15131b33","--pi-shadow-strong":"#15131b44","--pi-bg-overlay-soft":"#f7f1e6dd","--pi-bg-overlay":"#f7f1e6e6","--pi-success-bg-overlay":"#e1f4efee","--pi-terminal-selection":"#8d7b64"},Qu={apiVersion:1,name:"PI WEB 主题",activate:()=>({contributions:{themes:[{id:"pi-web-dark",name:"PI WEB 深色",description:"PI WEB 深色配色。",order:10,colorScheme:"dark",tokens:Gu},{id:"pi-web-light",name:"PI WEB 浅色",description:"PI WEB 浅色配色。",order:20,colorScheme:"light",tokens:Ju},{id:"classic",name:"PI WEB 经典",description:"原始 PI WEB 深色配色。",order:30,colorScheme:"dark",tokens:Vu}],themePairs:[{id:"pi-web",name:"PI WEB",description:"跟随系统浅色/深色偏好使用 PI WEB 主题。",order:10,light:"pi-web-light",dark:"pi-web-dark"}]}})},Zu=/^[a-z][a-z0-9.-]*$/u;function Xu(e){return Zu.test(e)}const Yu="machine.";function ef(e,t){if(e==="")throw new Error("Machine id is required");if(!Xu(t))throw new Error(`Invalid PI WEB plugin id: ${t}`);return`${Yu}${tf(e)}.${t}`}function tf(e){return[...new TextEncoder().encode(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}async function kr(e="/pi-web-plugins/manifest.json",t={}){const i=await sf(e);if(i===void 0)return[];const s=[];for(const o of i.plugins)if(t.shouldLoadPlugin?.(o)!==!1)try{const r=new URL(o.module,new URL(e,window.location.href)).toString(),n=await import(r),a=nf(n,r);s.push({id:t.machineId===void 0?o.id:ef(t.machineId,o.id),plugin:a,machineSpecific:o.machineSpecific,...t.machineId===void 0?{}:{machineId:t.machineId,sourcePluginId:o.id}})}catch(r){console.warn(`Failed to load PI WEB plugin ${o.module}`,r)}return s}async function sf(e){const t=await fetch(e,{cache:"no-store"});if(t.status!==404){if(!t.ok)throw new Error(`Failed to load plugin manifest: ${t.statusText}`);return of(await t.json())}}function of(e){if(!$i(e)||!Array.isArray(e.plugins))throw new Error("Invalid plugin manifest");return{plugins:e.plugins.map(t=>{if(!$i(t)||typeof t.id!="string"||t.id===""||typeof t.module!="string"||t.module==="")throw new Error("Invalid plugin manifest entry");return{id:t.id,module:t.module,machineSpecific:rf(t.machineSpecific)}})}}function rf(e){if(e===void 0)return!1;if(typeof e!="boolean")throw new Error("Invalid plugin manifest entry");return e}function nf(e,t){if(!$i(e))throw new Error(`Plugin module ${t} did not export an object`);const i=e.default;if(!af(i))throw new Error(`Plugin module ${t} default export is not a PiWebPlugin`);return i}function af(e){return $i(e)&&e.apiVersion===1&&typeof e.name=="string"&&typeof e.activate=="function"}function $i(e){return typeof e=="object"&&e!==null}const cf=/^[a-z][a-z0-9.-]*$/u,lf=/^[a-z][a-z0-9.-]*$/u,da=new WeakMap,pa=new WeakMap;class df{constructor(){this.actions=[],this.workspacePanels=[],this.workspaceLabels=[],this.themes=[],this.themePairs=[],this.pluginIds=new Set,this.gatewayPluginIds=new Set,this.gatewayMachineSpecificPluginIds=new Set,this.remoteMachineSpecificPluginIds=new Map,this.contributionIds=new Set}register(t){const{id:i,plugin:s}=t;this.validatePluginId(i);const o=this.parseMachineSpecific(i,t.machineSpecific);if(this.pluginIds.has(i))throw new Error(`Duplicate plugin id: ${i}`);if(this.isRemoteDuplicateHiddenByGateway(t.sourcePluginId,t.machineId,o))return;this.pluginIds.add(i);const r=s.apiVersion;if(r!==1)throw new Error(`Unsupported plugin API version for ${i}: ${String(r)}`);const a=s.activate({apiVersion:1,pluginId:i,html:c,svg:ue}).contributions;for(const l of a.actions??[])this.actions.push(this.qualifyAction(i,l,t.machineId,t.sourcePluginId));for(const l of a.workspacePanels??[])this.workspacePanels.push(this.qualifyWorkspacePanel(i,l,t.machineId,t.sourcePluginId));for(const l of a.workspaceLabels??[])this.workspaceLabels.push(this.qualifyWorkspaceLabelContribution(i,l,t.machineId,t.sourcePluginId));if(t.machineId===void 0){for(const l of a.themes??[])this.themes.push(this.qualifyTheme(i,l));for(const l of a.themePairs??[])this.themePairs.push(this.qualifyThemePair(i,l));this.gatewayPluginIds.add(i),o&&this.gatewayMachineSpecificPluginIds.add(i)}else t.sourcePluginId!==void 0&&o&&ff(this.remoteMachineSpecificPluginIds,t.sourcePluginId,t.machineId)}shouldLoadRemotePlugin(t,i=!1){return!this.gatewayPluginIds.has(t)||this.gatewayMachineSpecificPluginIds.has(t)||i}getActions(t){const i=mf(t);return this.actions.filter(s=>this.isContributionActive(s.pluginId,s.machineId,i,s.sourcePluginId)).map(s=>{const o=pf(t,s.pluginId),r=s.enabled?.(o),n={id:s.id,pluginId:s.pluginId,localId:s.localId,...s.machineId===void 0?{}:{machineId:s.machineId},title:s.title,run:()=>s.run(o)};return s.description!==void 0&&(n.description=s.description),s.shortcut!==void 0&&(n.shortcut=s.shortcut),s.group!==void 0&&(n.group=s.group),r!==void 0&&(n.enabled=r),n})}getWorkspacePanels(){return[...this.workspacePanels].sort((t,i)=>(t.order??1e3)-(i.order??1e3)||t.title.localeCompare(i.title))}getThemes(){return[...this.themes].sort((t,i)=>(t.order??1e3)-(i.order??1e3)||t.name.localeCompare(i.name))}getThemePairs(){return[...this.themePairs].sort((t,i)=>(t.order??1e3)-(i.order??1e3)||t.name.localeCompare(i.name))}getWorkspaceLabelItems(t){return[...this.workspaceLabels].sort((i,s)=>(i.order??1e3)-(s.order??1e3)||i.id.localeCompare(s.id)).flatMap(i=>i.visible?.(t)===!1?[]:i.items(t))}qualifyAction(t,i,s,o){const r=this.qualify(t,i.id);return{...i,id:r,pluginId:t,localId:i.id,...s===void 0?{}:{machineId:s},...o===void 0?{}:{sourcePluginId:o}}}qualifyWorkspacePanel(t,i,s,o){const r=this.qualify(t,i.id),n=i.badge,a=i.visible;return{...i,id:r,pluginId:t,localId:i.id,...s===void 0?{}:{machineId:s},visible:l=>this.isContributionActive(t,s,l.machine.id,o)&&(a?.(os(l,t))??!0),...n===void 0?{}:{badge:l=>this.isContributionActive(t,s,l.machine.id,o)?n(os(l,t)):void 0},render:l=>i.render(os(l,t))}}qualifyWorkspaceLabelContribution(t,i,s,o){const r=this.qualify(t,i.id),n=i.visible,a=i.items;return{...i,id:r,pluginId:t,localId:i.id,...s===void 0?{}:{machineId:s},visible:l=>this.isContributionActive(t,s,l.machine.id,o)&&(n?.(l)??!0),items:l=>this.isContributionActive(t,s,l.machine.id,o)?a(l):[]}}qualifyTheme(t,i){const s=this.qualify(t,i.id);return{...i,id:s,pluginId:t,localId:i.id}}qualifyThemePair(t,i){const s=this.qualify(t,i.id);return{...i,id:s,pluginId:t,localId:i.id,light:this.qualifyReference(t,i.light),dark:this.qualifyReference(t,i.dark)}}qualify(t,i){this.validateLocalId(i);const s=`${t}:${i}`;if(this.contributionIds.has(s))throw new Error(`Duplicate contribution id: ${s}`);return this.contributionIds.add(s),s}qualifyReference(t,i){return this.validateLocalId(i),`${t}:${i}`}isContributionActive(t,i,s,o){return i===void 0?!this.isGatewayPluginHiddenForMachine(t,s):i===s&&!this.isRemotePluginHiddenByGateway(o,i)}isRemoteDuplicateHiddenByGateway(t,i,s){return t!==void 0&&i!==void 0&&this.gatewayPluginIds.has(t)&&!this.gatewayMachineSpecificPluginIds.has(t)&&!s}isRemotePluginHiddenByGateway(t,i){return t===void 0||this.gatewayMachineSpecificPluginIds.has(t)||this.remoteMachineSpecificPluginIds.get(t)?.has(i)===!0?!1:this.gatewayPluginIds.has(t)}isGatewayPluginHiddenForMachine(t,i){return i!=="local"&&(this.gatewayMachineSpecificPluginIds.has(t)||this.remoteMachineSpecificPluginIds.get(t)?.has(i)===!0)}validatePluginId(t){if(!cf.test(t))throw new Error(`Invalid plugin id: ${t}`)}validateLocalId(t){if(!lf.test(t))throw new Error(`Invalid contribution id: ${t}`)}parseMachineSpecific(t,i){if(i===void 0)return!1;if(typeof i!="boolean")throw new Error(`Invalid plugin machineSpecific value for ${t}: ${gf(i)}`);return i}}function pf(e,t){return da.get(e)?.(t)??e}function os(e,t){return pa.get(e)?.(t)??e}function hf(e,t){return da.set(e,t),e}function uf(e,t){return pa.set(e,t),e}function ff(e,t,i){const s=e.get(t);s===void 0?e.set(t,new Set([i])):s.add(i)}function gf(e){if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"||typeof e=="symbol"||typeof e=="function"||e===null||e===void 0)return String(e);try{return JSON.stringify(e)}catch{return Object.prototype.toString.call(e)}}function mf(e){return e.state.selectedMachine?.id??"local"}const vf=["(display-mode: standalone)","(display-mode: fullscreen)","(display-mode: minimal-ui)"];function bf(){return typeof window>"u"||!("matchMedia"in window)?[]:vf.map(e=>window.matchMedia(e))}function $r(e,t=wf()){return e.some(i=>i.matches)||yf(t)}function wf(){return typeof navigator>"u"?void 0:navigator}function yf(e){return e!==void 0&&"standalone"in e&&e.standalone===!0}const Sf=250;class xf{constructor(t=kf()){this.scheduler=t}repair(t){if(!t){this.clear();return}this.resetViewportScroll(),this.repairFrame!==void 0&&this.scheduler.cancelAnimationFrame(this.repairFrame),this.repairFrame=this.scheduler.requestAnimationFrame(()=>{this.repairFrame=void 0,this.resetViewportScroll(),this.repairFrame=this.scheduler.requestAnimationFrame(()=>{this.repairFrame=void 0,this.resetViewportScroll()})}),this.repairTimer!==void 0&&this.scheduler.clearTimeout(this.repairTimer),this.repairTimer=this.scheduler.setTimeout(()=>{this.repairTimer=void 0,this.resetViewportScroll()},Sf)}clear(){this.repairFrame!==void 0&&(this.scheduler.cancelAnimationFrame(this.repairFrame),this.repairFrame=void 0),this.repairTimer!==void 0&&(this.scheduler.clearTimeout(this.repairTimer),this.repairTimer=void 0)}resetViewportScroll(){this.scheduler.scrollTo(0,0);const t=this.scheduler.documentElement;t!==void 0&&(t.scrollTop=0);const i=this.scheduler.body;i!==void 0&&(i.scrollTop=0)}}function kf(){return{requestAnimationFrame(e){return window.requestAnimationFrame(e)},cancelAnimationFrame(e){window.cancelAnimationFrame(e)},setTimeout(e,t){return window.setTimeout(e,t)},clearTimeout(e){window.clearTimeout(e)},scrollTo(e,t){window.scrollTo(e,t)},get documentElement(){return typeof document>"u"?void 0:document.documentElement},get body(){return typeof document>"u"?void 0:document.body}}}const $f="(max-width: 760px)",Pf="(max-width: 1180px)";class Rf{constructor(t,i={}){this.host=t,this.onMobileNavigationMediaChange=s=>{this.isMobileNavigationLayout!==s.matches&&(this.isMobileNavigationLayout=s.matches,this.host.requestUpdate())},this.onStackedWorkspaceMediaChange=s=>{this.isStackedWorkspaceLayout!==s.matches&&(this.isStackedWorkspaceLayout=s.matches,this.host.requestUpdate())},this.onPwaDisplayModeChange=()=>{const s=$r(this.pwaDisplayModeMedia);this.isPwaDisplayMode!==s&&(this.isPwaDisplayMode=s,this.host.requestUpdate())},t.addController(this),this.mobileNavigationMedia=i.mobileNavigationMedia??If(),this.stackedWorkspaceMedia=i.stackedWorkspaceMedia??Cf(),this.pwaDisplayModeMedia=i.pwaDisplayModeMedia??bf(),this.viewportPositionRepairer=i.viewportPositionRepairer??new xf,this.isMobileNavigationLayout=this.mobileNavigationMedia?.matches??!1,this.isStackedWorkspaceLayout=this.stackedWorkspaceMedia?.matches??!1,this.isPwaDisplayMode=$r(this.pwaDisplayModeMedia)}hostConnected(){this.mobileNavigationMedia?.addEventListener("change",this.onMobileNavigationMediaChange),this.stackedWorkspaceMedia?.addEventListener("change",this.onStackedWorkspaceMediaChange);for(const t of this.pwaDisplayModeMedia)t.addEventListener("change",this.onPwaDisplayModeChange)}hostDisconnected(){this.mobileNavigationMedia?.removeEventListener("change",this.onMobileNavigationMediaChange),this.stackedWorkspaceMedia?.removeEventListener("change",this.onStackedWorkspaceMediaChange);for(const t of this.pwaDisplayModeMedia)t.removeEventListener("change",this.onPwaDisplayModeChange);this.viewportPositionRepairer.clear()}shouldAutoFocusPrompt(){return!this.isMobileNavigationLayout&&!this.isPwaDisplayMode}shouldShowAppRefreshInHeader(){return this.isPwaDisplayMode&&!this.isMobileNavigationLayout}shouldShowAppRefreshInContextBar(){return this.isPwaDisplayMode&&this.isMobileNavigationLayout}defaultRouteView(){return this.normalizedMainView(void 0,!1)}normalizedMainView(t,i){return Mf(t,{isMobileNavigationLayout:this.isMobileNavigationLayout,isStackedWorkspaceLayout:this.isStackedWorkspaceLayout,hasSelectedSession:i})}repairViewportPosition(){this.viewportPositionRepairer.repair(this.shouldRepairViewportPosition())}shouldRepairViewportPosition(){return this.isMobileNavigationLayout||this.isPwaDisplayMode}}function If(){if(!(typeof window>"u"||!("matchMedia"in window)))return window.matchMedia($f)}function Cf(){if(!(typeof window>"u"||!("matchMedia"in window)))return window.matchMedia(Pf)}function Mf(e,t){const i=e??(t.isMobileNavigationLayout?"navigation":"chat");return t.isMobileNavigationLayout||!t.isStackedWorkspaceLayout||!t.hasSelectedSession||i==="navigation"||i==="chat"?i:"chat"}const Pi=["machines","projects","workspaces","sessions"];function Tf(e){return e.selectedProject===void 0?"projects":e.selectedWorkspace===void 0?"workspaces":"sessions"}function lo(e,t){if(e!=="none")return e??Tf(t)}function Af(e,t){return t.isMobileLayout?lo(t.expanded,t.state)!==e:t.collapsedSections?.includes(e)??!1}function Ef(e,t,i){return lo(e,i.state)===t?"none":t}function Df(e,t,i){return i?t:e}function Wf(e,t){const i=new Set(e);return i.has(t)?i.delete(t):i.add(t),Of(i)}function _f(e){return Pi[Pi.indexOf(e)+1]}class Lf{constructor(t,i,s){this.host=t,this.getState=i,this.isMobileLayout=s,this.collapsedSections=[],t.addController(this)}hostConnected(){}expandedSection(){return lo(this.expanded,this.getState())}isCollapsed(t){return Af(t,{isMobileLayout:this.isMobileLayout(),expanded:this.expanded,state:this.getState(),collapsedSections:this.collapsedSections})}toggle(t){if(this.isMobileLayout()){this.setExpanded(Ef(this.expanded,t,{state:this.getState()}));return}this.setCollapsedSections(Wf(this.collapsedSections,t))}expand(t){if(this.isMobileLayout()){this.setExpanded(Df(this.expanded,t,!0));return}this.setCollapsedSections(this.collapsedSections.filter(i=>i!==t))}advanceAfterSelection(t){if(!this.isMobileLayout())return;const i=_f(t);i!==void 0&&this.expand(i)}open(t,i){this.isMobileLayout()&&(this.expand(t),i())}setExpanded(t){this.expanded!==t&&(this.expanded=t,this.host.requestUpdate())}setCollapsedSections(t){jf(this.collapsedSections,t)||(this.collapsedSections=t,this.host.requestUpdate())}}function Of(e){const t=new Set(e);return Pi.filter(i=>t.has(i))}function jf(e,t){return e.length===t.length&&e.every((i,s)=>i===t[s])}class Ff{constructor(t){this.host=t,this.navigationPanelCollapsed=!1,this.workspacePanelCollapsed=!1,t.addController(this)}hostConnected(){}toggleNavigationPanel(){this.navigationPanelCollapsed=!this.navigationPanelCollapsed,this.host.requestUpdate()}toggleWorkspacePanel(){this.workspacePanelCollapsed=!this.workspacePanelCollapsed,this.host.requestUpdate()}expandNavigationPanel(){this.navigationPanelCollapsed&&(this.navigationPanelCollapsed=!1,this.host.requestUpdate())}expandWorkspacePanel(){this.workspacePanelCollapsed&&(this.workspacePanelCollapsed=!1,this.host.requestUpdate())}shellClass(t){return["shell",ha(t),...this.navigationPanelCollapsed?["navigation-panel-collapsed"]:[],...this.workspacePanelCollapsed?["workspace-panel-collapsed"]:[]].join(" ")}}function ha(e){return e==="navigation"?"navigation-view":e==="chat"?"chat-view":"workspace-view"}const Ws="pi-web:panel-sizes:v1",zf={navigation:{minWidth:180,maxWidth:4096,defaultWidth:340,keyboardStep:24,largeKeyboardStep:72},workspace:{minWidth:240,maxWidth:4096,defaultWidth:480,keyboardStep:24,largeKeyboardStep:72}};class Nf{constructor(t,i={}){this.host=t,t.addController(this),this.storage=i.storage??po(),this.panelSizes=qf(this.storage)}hostConnected(){}constraints(t){return Ht(t)}panelWidth(t,i){return fe(t,i??this.storedPanelWidth(t)??this.constraints(t).defaultWidth)}resizePanel(t,i,s={}){const o=fe(t,i);this.storedPanelWidth(t)!==o&&(this.panelSizes=Gf(this.panelSizes,t,o),s.persist!==!1&&this.persistPanelSizes(),this.host.requestUpdate())}resetPanel(t,i={}){this.storedPanelWidth(t)!==void 0&&(this.panelSizes=Jf(this.panelSizes,t),i.persist!==!1&&this.persistPanelSizes(),this.host.requestUpdate())}resetPanels(t={}){this.panelSizes.navigationPanelWidth===void 0&&this.panelSizes.workspacePanelWidth===void 0||(this.panelSizes={},t.persist!==!1&&this.persistPanelSizes(),this.host.requestUpdate())}persistPanelSizes(){Kf(this.panelSizes,this.storage)}shellStyle(t={}){const i=[];return this.panelSizes.navigationPanelWidth!==void 0&&i.push(`--navigation-panel-size: ${Rr(fe("navigation",this.panelSizes.navigationPanelWidth,t.navigation))};`),this.panelSizes.workspacePanelWidth!==void 0&&i.push(`--workspace-panel-size: ${Rr(fe("workspace",this.panelSizes.workspacePanelWidth,t.workspace))};`),i.join(" ")}storedPanelWidth(t){return t==="navigation"?this.panelSizes.navigationPanelWidth:this.panelSizes.workspacePanelWidth}}function Ht(e){return zf[e]}function Bf(e,t,i){return e==="navigation"?i-t:t-i}function Uf(e,t,i,s,o=Ht(e)){return fe(e,t+Bf(e,i,s),o)}function Hf(e,t,i,s={}){const o=s.constraints??Ht(e);if(i==="Home")return o.minWidth;if(i==="End")return o.maxWidth;const r=s.largeStep===!0?o.largeKeyboardStep:o.keyboardStep,n=Qf(e,i,r);if(n!==void 0)return fe(e,t+n,o)}function fe(e,t,i=Ht(e)){return Number.isFinite(t)?Math.round(Math.min(Math.max(t,i.minWidth),i.maxWidth)):i.defaultWidth}function qf(e=po()){try{const t=e?.getItem(Ws);if(t==null||t==="")return{};const i=JSON.parse(t);return Vf(i)}catch{return{}}}function Kf(e,t=po()){if(t!==void 0)try{if(e.navigationPanelWidth===void 0&&e.workspacePanelWidth===void 0){t.removeItem(Ws);return}const i={version:1};e.navigationPanelWidth!==void 0&&(i.navigationPanelWidth=fe("navigation",e.navigationPanelWidth)),e.workspacePanelWidth!==void 0&&(i.workspacePanelWidth=fe("workspace",e.workspacePanelWidth)),t.setItem(Ws,JSON.stringify(i))}catch{}}function Vf(e){if(!Zf(e)||e.version!==1)return{};const t={},i=Pr(e.navigationPanelWidth),s=Pr(e.workspacePanelWidth);return i!==void 0&&(t.navigationPanelWidth=fe("navigation",i)),s!==void 0&&(t.workspacePanelWidth=fe("workspace",s)),t}function Pr(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Gf(e,t,i){return t==="navigation"?{...e,navigationPanelWidth:i}:{...e,workspacePanelWidth:i}}function Jf(e,t){return t==="navigation"?e.workspacePanelWidth===void 0?{}:{workspacePanelWidth:e.workspacePanelWidth}:e.navigationPanelWidth===void 0?{}:{navigationPanelWidth:e.navigationPanelWidth}}function Qf(e,t,i){if(e==="navigation")return t==="ArrowRight"?i:t==="ArrowLeft"?-i:void 0;if(t==="ArrowLeft")return i;if(t==="ArrowRight")return-i}function Rr(e){return`${String(Math.round(e))}px`}function po(){try{return typeof window>"u"?void 0:window.localStorage}catch{return}}function Zf(e){return typeof e=="object"&&e!==null}function Ir(){const e=new URLSearchParams(window.location.search);return{machineId:e.get("machine")??void 0,projectId:e.get("project")??void 0,workspaceId:e.get("workspace")??void 0,sessionId:e.get("session")??void 0,tool:Xf(e.get("tool")),view:Yf(e.get("view"))}}function rs(e,t){const i=new URL(window.location.href);i.searchParams.delete("machine"),i.searchParams.delete("project"),i.searchParams.delete("workspace"),i.searchParams.delete("session"),i.searchParams.delete("tool"),i.searchParams.delete("view"),e.machineId!==void 0&&e.machineId!==""&&e.machineId!=="local"&&i.searchParams.set("machine",e.machineId),e.projectId!==void 0&&e.projectId!==""&&i.searchParams.set("project",e.projectId),e.workspaceId!==void 0&&e.workspaceId!==""&&i.searchParams.set("workspace",e.workspaceId),e.sessionId!==void 0&&e.sessionId!==""&&i.searchParams.set("session",e.sessionId),e.tool!==void 0&&i.searchParams.set("tool",e.tool),e.view!==void 0&&i.searchParams.set("view",e.view);const s=`${i.pathname}${i.search}${i.hash}`,o=`${window.location.pathname}${window.location.search}${window.location.hash}`;s!==o&&(t?.replace===!0?window.history.replaceState({},"",i):window.history.pushState({},"",i))}function Xf(e){return e==="files"?"core:workspace.files":e==="git"?"core:workspace.git":ua(e)?e:void 0}function Yf(e){return e==="chat"?"chat":e==="files"?"core:workspace.files":e==="git"?"core:workspace.git":ua(e)?e:void 0}function ua(e){return e!==null&&/^[a-z][a-z0-9.-]*:[a-z][a-z0-9.-]*$/u.test(e)}function Cr(){return eg(new URLSearchParams(window.location.search).get("settings"))}function ns(e,t){const i=new URL(window.location.href);e===void 0?i.searchParams.delete("settings"):i.searchParams.set("settings",e);const s=`${i.pathname}${i.search}${i.hash}`,o=`${window.location.pathname}${window.location.search}${window.location.hash}`;s!==o&&window.history.pushState({},"",i)}function eg(e){if(e==="general")return"general";if(e==="sessiond"||e==="sessions")return"sessiond";if(e==="plugins")return"plugins";if(e==="shortcuts"||e==="keyboard"||e==="keyboard-shortcuts")return"shortcuts"}function tg(e,t){return t===void 0?e:e.map(i=>sg(i,t))}function ig(e,t){const i=new Set(no(e,t,{enabledOnly:!0}).filter(s=>s.active).map(s=>s.action.id));return tg(e,t).map(s=>s.shortcut!==void 0&&!i.has(s.id)?fa(s):s)}function sg(e,t){if(!Object.hasOwn(t,e.id))return e;const i=t[e.id];return i===void 0?e:i===null?fa(e):{...e,shortcut:i}}function fa(e){const t={...e};return delete t.shortcut,t}function og(e,t){const i=t.api??dt,s=t.pollIntervalMs??1e3,o=t.setTimeout??ng(),r=t.clearTimeout??ag();return{async runCommand(n){const a=await i.runTerminalCommand(e,n);return n.open===!0&&t.openTerminal(n.workspace,{terminalId:a.terminalId}),{run:a,completed:rg(a,i,s,o,r)}},listCommandRuns:n=>i.listCommandRuns(n),getCommandRun:n=>i.getCommandRun(n),open:n=>{t.openTerminal(void 0,n)}}}function rg(e,t,i,s,o){return Mr(e)?Promise.resolve(e):new Promise((r,n)=>{let a,l=!1;const p=g=>{l||(l=!0,a!==void 0&&o(a),r(g))},u=g=>{l||(l=!0,a!==void 0&&o(a),n(g instanceof Error?g:new Error(String(g))))},h=()=>{t.getCommandRun(e.id).then(g=>{if(g!==void 0&&Mr(g)){p(g);return}a=s(h,i)}).catch(u)};a=s(h,i)})}function Mr(e){return e.status==="succeeded"||e.status==="failed"}function ng(){return(e,t)=>globalThis.setTimeout(e,t)}function ag(){return e=>{globalThis.clearTimeout(e)}}function cg(e,t){return t[e.path]}function lg(e){if(e?.hasSessionActivity===!0)return"session";if(e?.hasTerminalActivity===!0)return"terminal"}function dg(e,t,i){return ma(pg(e,t,i))}function ga(e){return ma(Object.values(e??{}))}function ma(e){if(e.some(t=>t.hasSessionActivity))return"session";if(e.some(t=>t.hasTerminalActivity))return"terminal"}function pg(e,t,i){const s=new Set(t.filter(r=>r.projectId===e.id).map(r=>r.path)),o=new Map;for(const r of s){const n=i[r];n!==void 0&&o.set(n.cwd,n)}for(const r of Object.values(i))(r.cwd===e.path||r.cwd.startsWith(`${e.path}/`))&&o.set(r.cwd,r);return[...o.values()]}const Xt=0,hg=120;function qt(e,t={}){if(typeof HTMLElement>"u"||typeof window>"u"||!(e instanceof HTMLElement))return"";const i=e.getBoundingClientRect(),s=t.constrainTo==="viewport"?va():ug(e),o=window.innerWidth,r=window.innerHeight,n=Math.max(0,s.left),a=Math.min(o,s.right),l=Math.max(0,s.top),p=Math.min(r,s.bottom),u=Math.min(i.right,a),h=p-i.bottom-Xt,g=i.top-l-Xt;return[...h<hg&&g>h?[`bottom: ${at(r-i.top+Xt)};`,`max-height: ${at(Math.max(0,g))};`]:[`top: ${at(i.bottom+Xt)};`,`max-height: ${at(Math.max(0,h))};`],`right: ${at(Math.max(0,o-u))};`,`max-width: ${at(Math.max(0,u-n))};`].join(" ")}function ug(e){const t=e.getRootNode();return typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&t.host instanceof HTMLElement?t.host.getBoundingClientRect():va()}function va(){return{top:0,right:window.innerWidth,bottom:window.innerHeight,left:0}}function at(e){return`${String(Math.round(e))}px`}function ba(e,t="活跃"){if(e!==void 0)return c`<span class=${`activity-indicator ${e}`} role="img" aria-label=${t} title=${t}></span>`}function ji(e,t="活跃"){const i=ba(e,t);if(i!==void 0)return c`<span class="action-activity">${i}</span>`}const fg=["a[href]","button","input","select","textarea","summary","[role='button']","[role='link']","[contenteditable='true']"].join(",");function wa(e){return e.composedPath().some(t=>gg(t,fg))}function gg(e,t){if(typeof Element<"u"&&e instanceof Element)return e.matches(t);if(!("matches"in e))return!1;const{matches:i}=e;return typeof i=="function"&&i.call(e,t)===!0}function Fi(e,t){wa(e)||t()}function zi(e,t){return wa(e)?!1:e.key==="Enter"||e.key===" "?(e.preventDefault(),t.activate(),!0):e.key==="ArrowUp"?Ke(e,()=>{Tr(e.currentTarget,-1)}):e.key==="ArrowDown"?Ke(e,()=>{Tr(e.currentTarget,1)}):e.key==="Home"?Ke(e,()=>{Ar(e.currentTarget,0)}):e.key==="End"?Ke(e,()=>{Ar(e.currentTarget,-1)}):e.key==="ArrowLeft"&&t.previousSection!==void 0?Ke(e,t.previousSection):e.key==="ArrowRight"&&t.nextSection!==void 0?Ke(e,t.nextSection):e.key==="Escape"&&t.cancel!==void 0?Ke(e,t.cancel):!1}function Ni(e,t={}){const i=e.querySelector(".action-row.selected")??e.querySelector(".action-row")??(t.fallbackSelector===void 0?void 0:e.querySelector(t.fallbackSelector));return i==null?!1:(i.focus(),i.scrollIntoView({block:"nearest"}),!0)}function Ke(e,t){return e.preventDefault(),e.stopPropagation?.(),t(),!0}function Tr(e,t){const i=Sa(e),s=xa(e);if(s===void 0||i.length===0)return;const o=i.indexOf(s);o<0||ya(i,o+t)}function Ar(e,t){const i=Sa(e);i.length!==0&&ya(i,t<0?i.length-1:t)}function ya(e,t){const i=e[Math.min(Math.max(t,0),e.length-1)];i?.focus(),i?.scrollIntoView({block:"nearest"})}function Sa(e){const t=xa(e)?.getRootNode();return t===void 0||!mg(t)?[]:Array.from(t.querySelectorAll(".action-row"))}function mg(e){return typeof Document<"u"&&e instanceof Document||typeof DocumentFragment<"u"&&e instanceof DocumentFragment}function xa(e){if(!(typeof HTMLElement>"u"||!(e instanceof HTMLElement)))return e.closest(".action-row")??void 0}const vg=_`
135
+ `}function la(){na(()=>import("./CodeViewer-BFn0HY4O.js"),__vite__mapDeps([0,1,2,3]))}function Uu(){na(()=>import("./TerminalPanel-CiYd2dqB.js"),__vite__mapDeps([4,5,6,1,2]))}function Hu(e){const t=e.branch??"分离 HEAD",i=e.ahead??0,s=e.behind??0;return i===0&&s===0?t:`${t} · ↑${String(i)} ↓${String(s)}`}function qu(e,t){return(t!=="unmodified"?t:e).slice(0,1).toUpperCase()}function Ds(e){if(!Number.isFinite(e)||e<0)return"0 B";if(e<1024)return`${String(e)} B`;const t=e/1024;if(t<1024)return`${ss(t)} KB`;const i=t/1024;return i<1024?`${ss(i)} MB`:`${ss(i/1024)} GB`}function ss(e){return e>=10?String(Math.round(e)):e.toFixed(1)}const Ku={apiVersion:1,name:"PI WEB 核心",activate:()=>{const e=!du();return{contributions:{actions:e?wr():wr().filter(t=>t.id!=="view.terminal"),workspacePanels:e?xr():xr().filter(t=>t.id!=="workspace.terminal")}}}},Vu={"--pi-bg":"#0d1117","--pi-surface":"#161b22","--pi-surface-hover":"#21262d","--pi-terminal-bg":"#05070a","--pi-terminal-text":"#e6edf3","--pi-border":"#30363d","--pi-border-muted":"#21262d","--pi-text":"#e6edf3","--pi-text-secondary":"#c9d1d9","--pi-text-bright":"#f0f6fc","--pi-muted":"#8b949e","--pi-dim":"#6e7681","--pi-accent":"#58a6ff","--pi-accent-border":"#2f81f7","--pi-selection-bg":"#0d2847","--pi-success":"#3fb950","--pi-success-border":"#238636","--pi-success-bg":"#0f1b12","--pi-success-surface":"#0f2a16","--pi-success-ring":"#3fb95055","--pi-warning":"#d29922","--pi-warning-border":"#6e5200","--pi-warning-surface":"#1f1a10","--pi-danger":"#ff7b72","--pi-purple":"#d2a8ff","--pi-purple-border":"#a371f7","--pi-purple-surface":"#21132f","--pi-overlay":"#0008","--pi-shadow-soft":"#0006","--pi-shadow":"#0008","--pi-shadow-strong":"#000b","--pi-bg-overlay-soft":"#0d1117dd","--pi-bg-overlay":"#0d1117e6","--pi-success-bg-overlay":"#0f1b12ee","--pi-terminal-selection":"#264f78"},Gu={"--pi-bg":"#070912","--pi-surface":"#101527","--pi-surface-hover":"#151b31","--pi-terminal-bg":"#050710","--pi-terminal-text":"#f7f4ff","--pi-border":"#26304f","--pi-border-muted":"#26304f","--pi-text":"#f7f4ff","--pi-text-secondary":"#aaa4bd","--pi-text-bright":"#ffffff","--pi-muted":"#aaa4bd","--pi-dim":"#817a99","--pi-accent":"#7c3cff","--pi-accent-border":"#5a47b0","--pi-selection-bg":"#1d2547","--pi-success":"#00f0d8","--pi-success-border":"#00f0d8","--pi-success-bg":"#071e22","--pi-success-surface":"#092d31","--pi-success-ring":"#00f0d855","--pi-warning":"#ffb000","--pi-warning-border":"#ffb000","--pi-warning-surface":"#16140d","--pi-danger":"#ff4f7b","--pi-purple":"#b7a2ff","--pi-purple-border":"#7c3cff","--pi-purple-surface":"#181026","--pi-overlay":"#0008","--pi-shadow-soft":"#0006","--pi-shadow":"#0008","--pi-shadow-strong":"#000b","--pi-bg-overlay-soft":"#070912dd","--pi-bg-overlay":"#070912e6","--pi-success-bg-overlay":"#071e22ee","--pi-terminal-selection":"#3d4a78"},Ju={"--pi-bg":"#f7f1e6","--pi-surface":"#fff9ee","--pi-surface-hover":"#f0e6d6","--pi-terminal-bg":"#15131b","--pi-terminal-text":"#fff9ee","--pi-border":"#c9bca8","--pi-border-muted":"#d8cdbc","--pi-text":"#15131b","--pi-text-secondary":"#15131b","--pi-text-bright":"#15131b","--pi-muted":"#5f586a","--pi-dim":"#766f7e","--pi-accent":"#6430d8","--pi-accent-border":"#6430d8","--pi-selection-bg":"#eadff8","--pi-success":"#008c82","--pi-success-border":"#008c82","--pi-success-bg":"#e1f4ef","--pi-success-surface":"#d7f0ec","--pi-success-ring":"#008c8255","--pi-warning":"#b05f00","--pi-warning-border":"#b05f00","--pi-warning-surface":"#fff2d2","--pi-danger":"#b51d49","--pi-purple":"#6430d8","--pi-purple-border":"#6430d8","--pi-purple-surface":"#eadff8","--pi-overlay":"#15131b66","--pi-shadow-soft":"#15131b22","--pi-shadow":"#15131b33","--pi-shadow-strong":"#15131b44","--pi-bg-overlay-soft":"#f7f1e6dd","--pi-bg-overlay":"#f7f1e6e6","--pi-success-bg-overlay":"#e1f4efee","--pi-terminal-selection":"#8d7b64"},Qu={apiVersion:1,name:"PI WEB 主题",activate:()=>({contributions:{themes:[{id:"pi-web-dark",name:"PI WEB 深色",description:"PI WEB 深色配色。",order:10,colorScheme:"dark",tokens:Gu},{id:"pi-web-light",name:"PI WEB 浅色",description:"PI WEB 浅色配色。",order:20,colorScheme:"light",tokens:Ju},{id:"classic",name:"PI WEB 经典",description:"原始 PI WEB 深色配色。",order:30,colorScheme:"dark",tokens:Vu}],themePairs:[{id:"pi-web",name:"PI WEB",description:"跟随系统浅色/深色偏好使用 PI WEB 主题。",order:10,light:"pi-web-light",dark:"pi-web-dark"}]}})},Zu=/^[a-z][a-z0-9.-]*$/u;function Xu(e){return Zu.test(e)}const Yu="machine.";function ef(e,t){if(e==="")throw new Error("Machine id is required");if(!Xu(t))throw new Error(`Invalid PI WEB plugin id: ${t}`);return`${Yu}${tf(e)}.${t}`}function tf(e){return[...new TextEncoder().encode(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}async function kr(e="/pi-web-plugins/manifest.json",t={}){const i=await sf(e);if(i===void 0)return[];const s=[];for(const o of i.plugins)if(t.shouldLoadPlugin?.(o)!==!1)try{const r=new URL(o.module,new URL(e,window.location.href)).toString(),n=await import(r),a=nf(n,r);s.push({id:t.machineId===void 0?o.id:ef(t.machineId,o.id),plugin:a,machineSpecific:o.machineSpecific,...t.machineId===void 0?{}:{machineId:t.machineId,sourcePluginId:o.id}})}catch(r){console.warn(`Failed to load PI WEB plugin ${o.module}`,r)}return s}async function sf(e){const t=await fetch(e,{cache:"no-store"});if(t.status!==404){if(!t.ok)throw new Error(`Failed to load plugin manifest: ${t.statusText}`);return of(await t.json())}}function of(e){if(!$i(e)||!Array.isArray(e.plugins))throw new Error("Invalid plugin manifest");return{plugins:e.plugins.map(t=>{if(!$i(t)||typeof t.id!="string"||t.id===""||typeof t.module!="string"||t.module==="")throw new Error("Invalid plugin manifest entry");return{id:t.id,module:t.module,machineSpecific:rf(t.machineSpecific)}})}}function rf(e){if(e===void 0)return!1;if(typeof e!="boolean")throw new Error("Invalid plugin manifest entry");return e}function nf(e,t){if(!$i(e))throw new Error(`Plugin module ${t} did not export an object`);const i=e.default;if(!af(i))throw new Error(`Plugin module ${t} default export is not a PiWebPlugin`);return i}function af(e){return $i(e)&&e.apiVersion===1&&typeof e.name=="string"&&typeof e.activate=="function"}function $i(e){return typeof e=="object"&&e!==null}const cf=/^[a-z][a-z0-9.-]*$/u,lf=/^[a-z][a-z0-9.-]*$/u,da=new WeakMap,pa=new WeakMap;class df{constructor(){this.actions=[],this.workspacePanels=[],this.workspaceLabels=[],this.themes=[],this.themePairs=[],this.pluginIds=new Set,this.gatewayPluginIds=new Set,this.gatewayMachineSpecificPluginIds=new Set,this.remoteMachineSpecificPluginIds=new Map,this.contributionIds=new Set}register(t){const{id:i,plugin:s}=t;this.validatePluginId(i);const o=this.parseMachineSpecific(i,t.machineSpecific);if(this.pluginIds.has(i))throw new Error(`Duplicate plugin id: ${i}`);if(this.isRemoteDuplicateHiddenByGateway(t.sourcePluginId,t.machineId,o))return;this.pluginIds.add(i);const r=s.apiVersion;if(r!==1)throw new Error(`Unsupported plugin API version for ${i}: ${String(r)}`);const a=s.activate({apiVersion:1,pluginId:i,html:c,svg:ue}).contributions;for(const l of a.actions??[])this.actions.push(this.qualifyAction(i,l,t.machineId,t.sourcePluginId));for(const l of a.workspacePanels??[])this.workspacePanels.push(this.qualifyWorkspacePanel(i,l,t.machineId,t.sourcePluginId));for(const l of a.workspaceLabels??[])this.workspaceLabels.push(this.qualifyWorkspaceLabelContribution(i,l,t.machineId,t.sourcePluginId));if(t.machineId===void 0){for(const l of a.themes??[])this.themes.push(this.qualifyTheme(i,l));for(const l of a.themePairs??[])this.themePairs.push(this.qualifyThemePair(i,l));this.gatewayPluginIds.add(i),o&&this.gatewayMachineSpecificPluginIds.add(i)}else t.sourcePluginId!==void 0&&o&&ff(this.remoteMachineSpecificPluginIds,t.sourcePluginId,t.machineId)}shouldLoadRemotePlugin(t,i=!1){return!this.gatewayPluginIds.has(t)||this.gatewayMachineSpecificPluginIds.has(t)||i}getActions(t){const i=mf(t);return this.actions.filter(s=>this.isContributionActive(s.pluginId,s.machineId,i,s.sourcePluginId)).map(s=>{const o=pf(t,s.pluginId),r=s.enabled?.(o),n={id:s.id,pluginId:s.pluginId,localId:s.localId,...s.machineId===void 0?{}:{machineId:s.machineId},title:s.title,run:()=>s.run(o)};return s.description!==void 0&&(n.description=s.description),s.shortcut!==void 0&&(n.shortcut=s.shortcut),s.group!==void 0&&(n.group=s.group),r!==void 0&&(n.enabled=r),n})}getWorkspacePanels(){return[...this.workspacePanels].sort((t,i)=>(t.order??1e3)-(i.order??1e3)||t.title.localeCompare(i.title))}getThemes(){return[...this.themes].sort((t,i)=>(t.order??1e3)-(i.order??1e3)||t.name.localeCompare(i.name))}getThemePairs(){return[...this.themePairs].sort((t,i)=>(t.order??1e3)-(i.order??1e3)||t.name.localeCompare(i.name))}getWorkspaceLabelItems(t){return[...this.workspaceLabels].sort((i,s)=>(i.order??1e3)-(s.order??1e3)||i.id.localeCompare(s.id)).flatMap(i=>i.visible?.(t)===!1?[]:i.items(t))}qualifyAction(t,i,s,o){const r=this.qualify(t,i.id);return{...i,id:r,pluginId:t,localId:i.id,...s===void 0?{}:{machineId:s},...o===void 0?{}:{sourcePluginId:o}}}qualifyWorkspacePanel(t,i,s,o){const r=this.qualify(t,i.id),n=i.badge,a=i.visible;return{...i,id:r,pluginId:t,localId:i.id,...s===void 0?{}:{machineId:s},visible:l=>this.isContributionActive(t,s,l.machine.id,o)&&(a?.(os(l,t))??!0),...n===void 0?{}:{badge:l=>this.isContributionActive(t,s,l.machine.id,o)?n(os(l,t)):void 0},render:l=>i.render(os(l,t))}}qualifyWorkspaceLabelContribution(t,i,s,o){const r=this.qualify(t,i.id),n=i.visible,a=i.items;return{...i,id:r,pluginId:t,localId:i.id,...s===void 0?{}:{machineId:s},visible:l=>this.isContributionActive(t,s,l.machine.id,o)&&(n?.(l)??!0),items:l=>this.isContributionActive(t,s,l.machine.id,o)?a(l):[]}}qualifyTheme(t,i){const s=this.qualify(t,i.id);return{...i,id:s,pluginId:t,localId:i.id}}qualifyThemePair(t,i){const s=this.qualify(t,i.id);return{...i,id:s,pluginId:t,localId:i.id,light:this.qualifyReference(t,i.light),dark:this.qualifyReference(t,i.dark)}}qualify(t,i){this.validateLocalId(i);const s=`${t}:${i}`;if(this.contributionIds.has(s))throw new Error(`Duplicate contribution id: ${s}`);return this.contributionIds.add(s),s}qualifyReference(t,i){return this.validateLocalId(i),`${t}:${i}`}isContributionActive(t,i,s,o){return i===void 0?!this.isGatewayPluginHiddenForMachine(t,s):i===s&&!this.isRemotePluginHiddenByGateway(o,i)}isRemoteDuplicateHiddenByGateway(t,i,s){return t!==void 0&&i!==void 0&&this.gatewayPluginIds.has(t)&&!this.gatewayMachineSpecificPluginIds.has(t)&&!s}isRemotePluginHiddenByGateway(t,i){return t===void 0||this.gatewayMachineSpecificPluginIds.has(t)||this.remoteMachineSpecificPluginIds.get(t)?.has(i)===!0?!1:this.gatewayPluginIds.has(t)}isGatewayPluginHiddenForMachine(t,i){return i!=="local"&&(this.gatewayMachineSpecificPluginIds.has(t)||this.remoteMachineSpecificPluginIds.get(t)?.has(i)===!0)}validatePluginId(t){if(!cf.test(t))throw new Error(`Invalid plugin id: ${t}`)}validateLocalId(t){if(!lf.test(t))throw new Error(`Invalid contribution id: ${t}`)}parseMachineSpecific(t,i){if(i===void 0)return!1;if(typeof i!="boolean")throw new Error(`Invalid plugin machineSpecific value for ${t}: ${gf(i)}`);return i}}function pf(e,t){return da.get(e)?.(t)??e}function os(e,t){return pa.get(e)?.(t)??e}function hf(e,t){return da.set(e,t),e}function uf(e,t){return pa.set(e,t),e}function ff(e,t,i){const s=e.get(t);s===void 0?e.set(t,new Set([i])):s.add(i)}function gf(e){if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"||typeof e=="symbol"||typeof e=="function"||e===null||e===void 0)return String(e);try{return JSON.stringify(e)}catch{return Object.prototype.toString.call(e)}}function mf(e){return e.state.selectedMachine?.id??"local"}const vf=["(display-mode: standalone)","(display-mode: fullscreen)","(display-mode: minimal-ui)"];function bf(){return typeof window>"u"||!("matchMedia"in window)?[]:vf.map(e=>window.matchMedia(e))}function $r(e,t=wf()){return e.some(i=>i.matches)||yf(t)}function wf(){return typeof navigator>"u"?void 0:navigator}function yf(e){return e!==void 0&&"standalone"in e&&e.standalone===!0}const Sf=250;class xf{constructor(t=kf()){this.scheduler=t}repair(t){if(!t){this.clear();return}this.resetViewportScroll(),this.repairFrame!==void 0&&this.scheduler.cancelAnimationFrame(this.repairFrame),this.repairFrame=this.scheduler.requestAnimationFrame(()=>{this.repairFrame=void 0,this.resetViewportScroll(),this.repairFrame=this.scheduler.requestAnimationFrame(()=>{this.repairFrame=void 0,this.resetViewportScroll()})}),this.repairTimer!==void 0&&this.scheduler.clearTimeout(this.repairTimer),this.repairTimer=this.scheduler.setTimeout(()=>{this.repairTimer=void 0,this.resetViewportScroll()},Sf)}clear(){this.repairFrame!==void 0&&(this.scheduler.cancelAnimationFrame(this.repairFrame),this.repairFrame=void 0),this.repairTimer!==void 0&&(this.scheduler.clearTimeout(this.repairTimer),this.repairTimer=void 0)}resetViewportScroll(){this.scheduler.scrollTo(0,0);const t=this.scheduler.documentElement;t!==void 0&&(t.scrollTop=0);const i=this.scheduler.body;i!==void 0&&(i.scrollTop=0)}}function kf(){return{requestAnimationFrame(e){return window.requestAnimationFrame(e)},cancelAnimationFrame(e){window.cancelAnimationFrame(e)},setTimeout(e,t){return window.setTimeout(e,t)},clearTimeout(e){window.clearTimeout(e)},scrollTo(e,t){window.scrollTo(e,t)},get documentElement(){return typeof document>"u"?void 0:document.documentElement},get body(){return typeof document>"u"?void 0:document.body}}}const $f="(max-width: 760px)",Pf="(max-width: 1180px)";class Rf{constructor(t,i={}){this.host=t,this.onMobileNavigationMediaChange=s=>{this.isMobileNavigationLayout!==s.matches&&(this.isMobileNavigationLayout=s.matches,this.host.requestUpdate())},this.onStackedWorkspaceMediaChange=s=>{this.isStackedWorkspaceLayout!==s.matches&&(this.isStackedWorkspaceLayout=s.matches,this.host.requestUpdate())},this.onPwaDisplayModeChange=()=>{const s=$r(this.pwaDisplayModeMedia);this.isPwaDisplayMode!==s&&(this.isPwaDisplayMode=s,this.host.requestUpdate())},t.addController(this),this.mobileNavigationMedia=i.mobileNavigationMedia??If(),this.stackedWorkspaceMedia=i.stackedWorkspaceMedia??Cf(),this.pwaDisplayModeMedia=i.pwaDisplayModeMedia??bf(),this.viewportPositionRepairer=i.viewportPositionRepairer??new xf,this.isMobileNavigationLayout=this.mobileNavigationMedia?.matches??!1,this.isStackedWorkspaceLayout=this.stackedWorkspaceMedia?.matches??!1,this.isPwaDisplayMode=$r(this.pwaDisplayModeMedia)}hostConnected(){this.mobileNavigationMedia?.addEventListener("change",this.onMobileNavigationMediaChange),this.stackedWorkspaceMedia?.addEventListener("change",this.onStackedWorkspaceMediaChange);for(const t of this.pwaDisplayModeMedia)t.addEventListener("change",this.onPwaDisplayModeChange)}hostDisconnected(){this.mobileNavigationMedia?.removeEventListener("change",this.onMobileNavigationMediaChange),this.stackedWorkspaceMedia?.removeEventListener("change",this.onStackedWorkspaceMediaChange);for(const t of this.pwaDisplayModeMedia)t.removeEventListener("change",this.onPwaDisplayModeChange);this.viewportPositionRepairer.clear()}shouldAutoFocusPrompt(){return!this.isMobileNavigationLayout&&!this.isPwaDisplayMode}shouldShowAppRefreshInHeader(){return this.isPwaDisplayMode&&!this.isMobileNavigationLayout}shouldShowAppRefreshInContextBar(){return this.isPwaDisplayMode&&this.isMobileNavigationLayout}defaultRouteView(){return this.normalizedMainView(void 0,!1)}normalizedMainView(t,i){return Mf(t,{isMobileNavigationLayout:this.isMobileNavigationLayout,isStackedWorkspaceLayout:this.isStackedWorkspaceLayout,hasSelectedSession:i})}repairViewportPosition(){this.viewportPositionRepairer.repair(this.shouldRepairViewportPosition())}shouldRepairViewportPosition(){return this.isMobileNavigationLayout||this.isPwaDisplayMode}}function If(){if(!(typeof window>"u"||!("matchMedia"in window)))return window.matchMedia($f)}function Cf(){if(!(typeof window>"u"||!("matchMedia"in window)))return window.matchMedia(Pf)}function Mf(e,t){const i=e??(t.isMobileNavigationLayout?"navigation":"chat");return t.isMobileNavigationLayout||!t.isStackedWorkspaceLayout||!t.hasSelectedSession||i==="navigation"||i==="chat"?i:"chat"}const Pi=["machines","projects","workspaces","sessions"];function Tf(e){return e.selectedProject===void 0?"projects":e.selectedWorkspace===void 0?"workspaces":"sessions"}function lo(e,t){if(e!=="none")return e??Tf(t)}function Af(e,t){return t.isMobileLayout?lo(t.expanded,t.state)!==e:t.collapsedSections?.includes(e)??!1}function Ef(e,t,i){return lo(e,i.state)===t?"none":t}function Df(e,t,i){return i?t:e}function Wf(e,t){const i=new Set(e);return i.has(t)?i.delete(t):i.add(t),Of(i)}function _f(e){return Pi[Pi.indexOf(e)+1]}class Lf{constructor(t,i,s){this.host=t,this.getState=i,this.isMobileLayout=s,this.collapsedSections=[],t.addController(this)}hostConnected(){}expandedSection(){return lo(this.expanded,this.getState())}isCollapsed(t){return Af(t,{isMobileLayout:this.isMobileLayout(),expanded:this.expanded,state:this.getState(),collapsedSections:this.collapsedSections})}toggle(t){if(this.isMobileLayout()){this.setExpanded(Ef(this.expanded,t,{state:this.getState()}));return}this.setCollapsedSections(Wf(this.collapsedSections,t))}expand(t){if(this.isMobileLayout()){this.setExpanded(Df(this.expanded,t,!0));return}this.setCollapsedSections(this.collapsedSections.filter(i=>i!==t))}advanceAfterSelection(t){if(!this.isMobileLayout())return;const i=_f(t);i!==void 0&&this.expand(i)}open(t,i){this.isMobileLayout()&&(this.expand(t),i())}setExpanded(t){this.expanded!==t&&(this.expanded=t,this.host.requestUpdate())}setCollapsedSections(t){jf(this.collapsedSections,t)||(this.collapsedSections=t,this.host.requestUpdate())}}function Of(e){const t=new Set(e);return Pi.filter(i=>t.has(i))}function jf(e,t){return e.length===t.length&&e.every((i,s)=>i===t[s])}class Ff{constructor(t){this.host=t,this.navigationPanelCollapsed=!1,this.workspacePanelCollapsed=!1,t.addController(this)}hostConnected(){}toggleNavigationPanel(){this.navigationPanelCollapsed=!this.navigationPanelCollapsed,this.host.requestUpdate()}toggleWorkspacePanel(){this.workspacePanelCollapsed=!this.workspacePanelCollapsed,this.host.requestUpdate()}expandNavigationPanel(){this.navigationPanelCollapsed&&(this.navigationPanelCollapsed=!1,this.host.requestUpdate())}expandWorkspacePanel(){this.workspacePanelCollapsed&&(this.workspacePanelCollapsed=!1,this.host.requestUpdate())}shellClass(t){return["shell",ha(t),...this.navigationPanelCollapsed?["navigation-panel-collapsed"]:[],...this.workspacePanelCollapsed?["workspace-panel-collapsed"]:[]].join(" ")}}function ha(e){return e==="navigation"?"navigation-view":e==="chat"?"chat-view":"workspace-view"}const Ws="pi-web:panel-sizes:v1",zf={navigation:{minWidth:180,maxWidth:4096,defaultWidth:340,keyboardStep:24,largeKeyboardStep:72},workspace:{minWidth:240,maxWidth:4096,defaultWidth:480,keyboardStep:24,largeKeyboardStep:72}};class Nf{constructor(t,i={}){this.host=t,t.addController(this),this.storage=i.storage??po(),this.panelSizes=qf(this.storage)}hostConnected(){}constraints(t){return Ht(t)}panelWidth(t,i){return fe(t,i??this.storedPanelWidth(t)??this.constraints(t).defaultWidth)}resizePanel(t,i,s={}){const o=fe(t,i);this.storedPanelWidth(t)!==o&&(this.panelSizes=Gf(this.panelSizes,t,o),s.persist!==!1&&this.persistPanelSizes(),this.host.requestUpdate())}resetPanel(t,i={}){this.storedPanelWidth(t)!==void 0&&(this.panelSizes=Jf(this.panelSizes,t),i.persist!==!1&&this.persistPanelSizes(),this.host.requestUpdate())}resetPanels(t={}){this.panelSizes.navigationPanelWidth===void 0&&this.panelSizes.workspacePanelWidth===void 0||(this.panelSizes={},t.persist!==!1&&this.persistPanelSizes(),this.host.requestUpdate())}persistPanelSizes(){Kf(this.panelSizes,this.storage)}shellStyle(t={}){const i=[];return this.panelSizes.navigationPanelWidth!==void 0&&i.push(`--navigation-panel-size: ${Rr(fe("navigation",this.panelSizes.navigationPanelWidth,t.navigation))};`),this.panelSizes.workspacePanelWidth!==void 0&&i.push(`--workspace-panel-size: ${Rr(fe("workspace",this.panelSizes.workspacePanelWidth,t.workspace))};`),i.join(" ")}storedPanelWidth(t){return t==="navigation"?this.panelSizes.navigationPanelWidth:this.panelSizes.workspacePanelWidth}}function Ht(e){return zf[e]}function Bf(e,t,i){return e==="navigation"?i-t:t-i}function Uf(e,t,i,s,o=Ht(e)){return fe(e,t+Bf(e,i,s),o)}function Hf(e,t,i,s={}){const o=s.constraints??Ht(e);if(i==="Home")return o.minWidth;if(i==="End")return o.maxWidth;const r=s.largeStep===!0?o.largeKeyboardStep:o.keyboardStep,n=Qf(e,i,r);if(n!==void 0)return fe(e,t+n,o)}function fe(e,t,i=Ht(e)){return Number.isFinite(t)?Math.round(Math.min(Math.max(t,i.minWidth),i.maxWidth)):i.defaultWidth}function qf(e=po()){try{const t=e?.getItem(Ws);if(t==null||t==="")return{};const i=JSON.parse(t);return Vf(i)}catch{return{}}}function Kf(e,t=po()){if(t!==void 0)try{if(e.navigationPanelWidth===void 0&&e.workspacePanelWidth===void 0){t.removeItem(Ws);return}const i={version:1};e.navigationPanelWidth!==void 0&&(i.navigationPanelWidth=fe("navigation",e.navigationPanelWidth)),e.workspacePanelWidth!==void 0&&(i.workspacePanelWidth=fe("workspace",e.workspacePanelWidth)),t.setItem(Ws,JSON.stringify(i))}catch{}}function Vf(e){if(!Zf(e)||e.version!==1)return{};const t={},i=Pr(e.navigationPanelWidth),s=Pr(e.workspacePanelWidth);return i!==void 0&&(t.navigationPanelWidth=fe("navigation",i)),s!==void 0&&(t.workspacePanelWidth=fe("workspace",s)),t}function Pr(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Gf(e,t,i){return t==="navigation"?{...e,navigationPanelWidth:i}:{...e,workspacePanelWidth:i}}function Jf(e,t){return t==="navigation"?e.workspacePanelWidth===void 0?{}:{workspacePanelWidth:e.workspacePanelWidth}:e.navigationPanelWidth===void 0?{}:{navigationPanelWidth:e.navigationPanelWidth}}function Qf(e,t,i){if(e==="navigation")return t==="ArrowRight"?i:t==="ArrowLeft"?-i:void 0;if(t==="ArrowLeft")return i;if(t==="ArrowRight")return-i}function Rr(e){return`${String(Math.round(e))}px`}function po(){try{return typeof window>"u"?void 0:window.localStorage}catch{return}}function Zf(e){return typeof e=="object"&&e!==null}function Ir(){const e=new URLSearchParams(window.location.search);return{machineId:e.get("machine")??void 0,projectId:e.get("project")??void 0,workspaceId:e.get("workspace")??void 0,sessionId:e.get("session")??void 0,tool:Xf(e.get("tool")),view:Yf(e.get("view"))}}function rs(e,t){const i=new URL(window.location.href);i.searchParams.delete("machine"),i.searchParams.delete("project"),i.searchParams.delete("workspace"),i.searchParams.delete("session"),i.searchParams.delete("tool"),i.searchParams.delete("view"),e.machineId!==void 0&&e.machineId!==""&&e.machineId!=="local"&&i.searchParams.set("machine",e.machineId),e.projectId!==void 0&&e.projectId!==""&&i.searchParams.set("project",e.projectId),e.workspaceId!==void 0&&e.workspaceId!==""&&i.searchParams.set("workspace",e.workspaceId),e.sessionId!==void 0&&e.sessionId!==""&&i.searchParams.set("session",e.sessionId),e.tool!==void 0&&i.searchParams.set("tool",e.tool),e.view!==void 0&&i.searchParams.set("view",e.view);const s=`${i.pathname}${i.search}${i.hash}`,o=`${window.location.pathname}${window.location.search}${window.location.hash}`;s!==o&&(t?.replace===!0?window.history.replaceState({},"",i):window.history.pushState({},"",i))}function Xf(e){return e==="files"?"core:workspace.files":e==="git"?"core:workspace.git":ua(e)?e:void 0}function Yf(e){return e==="chat"?"chat":e==="files"?"core:workspace.files":e==="git"?"core:workspace.git":ua(e)?e:void 0}function ua(e){return e!==null&&/^[a-z][a-z0-9.-]*:[a-z][a-z0-9.-]*$/u.test(e)}function Cr(){return eg(new URLSearchParams(window.location.search).get("settings"))}function ns(e,t){const i=new URL(window.location.href);e===void 0?i.searchParams.delete("settings"):i.searchParams.set("settings",e);const s=`${i.pathname}${i.search}${i.hash}`,o=`${window.location.pathname}${window.location.search}${window.location.hash}`;s!==o&&window.history.pushState({},"",i)}function eg(e){if(e==="general")return"general";if(e==="sessiond"||e==="sessions")return"sessiond";if(e==="plugins")return"plugins";if(e==="shortcuts"||e==="keyboard"||e==="keyboard-shortcuts")return"shortcuts"}function tg(e,t){return t===void 0?e:e.map(i=>sg(i,t))}function ig(e,t){const i=new Set(no(e,t,{enabledOnly:!0}).filter(s=>s.active).map(s=>s.action.id));return tg(e,t).map(s=>s.shortcut!==void 0&&!i.has(s.id)?fa(s):s)}function sg(e,t){if(!Object.hasOwn(t,e.id))return e;const i=t[e.id];return i===void 0?e:i===null?fa(e):{...e,shortcut:i}}function fa(e){const t={...e};return delete t.shortcut,t}function og(e,t){const i=t.api??dt,s=t.pollIntervalMs??1e3,o=t.setTimeout??ng(),r=t.clearTimeout??ag();return{async runCommand(n){const a=await i.runTerminalCommand(e,n);return n.open===!0&&t.openTerminal(n.workspace,{terminalId:a.terminalId}),{run:a,completed:rg(a,i,s,o,r)}},listCommandRuns:n=>i.listCommandRuns(n),getCommandRun:n=>i.getCommandRun(n),open:n=>{t.openTerminal(void 0,n)}}}function rg(e,t,i,s,o){return Mr(e)?Promise.resolve(e):new Promise((r,n)=>{let a,l=!1;const p=g=>{l||(l=!0,a!==void 0&&o(a),r(g))},u=g=>{l||(l=!0,a!==void 0&&o(a),n(g instanceof Error?g:new Error(String(g))))},h=()=>{t.getCommandRun(e.id).then(g=>{if(g!==void 0&&Mr(g)){p(g);return}a=s(h,i)}).catch(u)};a=s(h,i)})}function Mr(e){return e.status==="succeeded"||e.status==="failed"}function ng(){return(e,t)=>globalThis.setTimeout(e,t)}function ag(){return e=>{globalThis.clearTimeout(e)}}function cg(e,t){return t[e.path]}function lg(e){if(e?.hasSessionActivity===!0)return"session";if(e?.hasTerminalActivity===!0)return"terminal"}function dg(e,t,i){return ma(pg(e,t,i))}function ga(e){return ma(Object.values(e??{}))}function ma(e){if(e.some(t=>t.hasSessionActivity))return"session";if(e.some(t=>t.hasTerminalActivity))return"terminal"}function pg(e,t,i){const s=new Set(t.filter(r=>r.projectId===e.id).map(r=>r.path)),o=new Map;for(const r of s){const n=i[r];n!==void 0&&o.set(n.cwd,n)}for(const r of Object.values(i))(r.cwd===e.path||r.cwd.startsWith(`${e.path}/`))&&o.set(r.cwd,r);return[...o.values()]}const Xt=0,hg=120;function qt(e,t={}){if(typeof HTMLElement>"u"||typeof window>"u"||!(e instanceof HTMLElement))return"";const i=e.getBoundingClientRect(),s=t.constrainTo==="viewport"?va():ug(e),o=window.innerWidth,r=window.innerHeight,n=Math.max(0,s.left),a=Math.min(o,s.right),l=Math.max(0,s.top),p=Math.min(r,s.bottom),u=Math.min(i.right,a),h=p-i.bottom-Xt,g=i.top-l-Xt;return[...h<hg&&g>h?[`bottom: ${at(r-i.top+Xt)};`,`max-height: ${at(Math.max(0,g))};`]:[`top: ${at(i.bottom+Xt)};`,`max-height: ${at(Math.max(0,h))};`],`right: ${at(Math.max(0,o-u))};`,`max-width: ${at(Math.max(0,u-n))};`].join(" ")}function ug(e){const t=e.getRootNode();return typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&t.host instanceof HTMLElement?t.host.getBoundingClientRect():va()}function va(){return{top:0,right:window.innerWidth,bottom:window.innerHeight,left:0}}function at(e){return`${String(Math.round(e))}px`}function ba(e,t="活跃"){if(e!==void 0)return c`<span class=${`activity-indicator ${e}`} role="img" aria-label=${t} title=${t}></span>`}function ji(e,t="活跃"){const i=ba(e,t);if(i!==void 0)return c`<span class="action-activity">${i}</span>`}const fg=["a[href]","button","input","select","textarea","summary","[role='button']","[role='link']","[contenteditable='true']"].join(",");function wa(e){return e.composedPath().some(t=>gg(t,fg))}function gg(e,t){if(typeof Element<"u"&&e instanceof Element)return e.matches(t);if(!("matches"in e))return!1;const{matches:i}=e;return typeof i=="function"&&i.call(e,t)===!0}function Fi(e,t){wa(e)||t()}function zi(e,t){return wa(e)?!1:e.key==="Enter"||e.key===" "?(e.preventDefault(),t.activate(),!0):e.key==="ArrowUp"?Ke(e,()=>{Tr(e.currentTarget,-1)}):e.key==="ArrowDown"?Ke(e,()=>{Tr(e.currentTarget,1)}):e.key==="Home"?Ke(e,()=>{Ar(e.currentTarget,0)}):e.key==="End"?Ke(e,()=>{Ar(e.currentTarget,-1)}):e.key==="ArrowLeft"&&t.previousSection!==void 0?Ke(e,t.previousSection):e.key==="ArrowRight"&&t.nextSection!==void 0?Ke(e,t.nextSection):e.key==="Escape"&&t.cancel!==void 0?Ke(e,t.cancel):!1}function Ni(e,t={}){const i=e.querySelector(".action-row.selected")??e.querySelector(".action-row")??(t.fallbackSelector===void 0?void 0:e.querySelector(t.fallbackSelector));return i==null?!1:(i.focus(),i.scrollIntoView({block:"nearest"}),!0)}function Ke(e,t){return e.preventDefault(),e.stopPropagation?.(),t(),!0}function Tr(e,t){const i=Sa(e),s=xa(e);if(s===void 0||i.length===0)return;const o=i.indexOf(s);o<0||ya(i,o+t)}function Ar(e,t){const i=Sa(e);i.length!==0&&ya(i,t<0?i.length-1:t)}function ya(e,t){const i=e[Math.min(Math.max(t,0),e.length-1)];i?.focus(),i?.scrollIntoView({block:"nearest"})}function Sa(e){const t=xa(e)?.getRootNode();return t===void 0||!mg(t)?[]:Array.from(t.querySelectorAll(".action-row"))}function mg(e){return typeof Document<"u"&&e instanceof Document||typeof DocumentFragment<"u"&&e instanceof DocumentFragment}function xa(e){if(!(typeof HTMLElement>"u"||!(e instanceof HTMLElement)))return e.closest(".action-row")??void 0}const vg=_`
136
136
  /* Mobile browsers already subtract browser controls from 100dvh; reserve bottom safe area only in standalone PWA modes. */
137
137
  :host { --pi-app-safe-area-bottom: 0px; position: fixed; top: 0; right: 0; left: 0; display: block; height: 100dvh; box-sizing: border-box; overflow: hidden; padding: env(safe-area-inset-top) env(safe-area-inset-right) var(--pi-app-safe-area-bottom) env(safe-area-inset-left); color: var(--pi-text); background: var(--pi-bg); font: 14px system-ui, sans-serif; }
138
138
  :host([pwa-display-mode]) { --pi-app-safe-area-bottom: env(safe-area-inset-bottom); }
@@ -146,7 +146,7 @@ ${h}`;await this.api.prompt(a,g,i,p)}else await this.api.prompt(a,t,i,p,s);this.
146
146
  .header-actions { display: flex; align-items: center; gap: 8px; }
147
147
  project-list, workspace-list { flex: 0 0 auto; max-height: 26%; min-height: 0; overflow: hidden; border-bottom: 1px solid var(--pi-border-muted); }
148
148
  session-list { flex: 1 1 auto; min-height: 0; overflow: hidden; }
149
- main { grid-column: 3; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
149
+ main { grid-column: 3; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
150
150
  .context-bar { position: relative; flex: 0 0 auto; min-width: 0; display: none; align-items: center; gap: 0; padding: 6px 0; border-bottom: 1px solid var(--pi-border-muted); background: var(--pi-bg); }
151
151
  .context-bar::before, .context-bar::after { content: ""; position: absolute; top: 0; bottom: 0; z-index: 2; width: 20px; opacity: 0; pointer-events: none; transition: opacity .15s ease; }
152
152
  .context-bar::before { left: 0; background: linear-gradient(90deg, color-mix(in srgb, var(--pi-shadow-strong) 55%, transparent) 0%, transparent 100%); }
@@ -225,7 +225,7 @@ ${h}`;await this.api.prompt(a,g,i,p)}else await this.api.prompt(a,t,i,p,s);this.
225
225
  main.navigation-view .mobile-navigation-panel session-list[collapsed] { flex: 0 0 auto; min-height: auto; overflow: hidden; }
226
226
  }
227
227
  status-bar { flex: 0 0 auto; }
228
- chat-view { flex: 1 1 auto; min-height: 0; overflow: hidden; }
228
+ chat-view { flex: 1 1 0; min-height: 0; overflow: hidden; }
229
229
  prompt-editor { flex: 0 0 auto; }
230
230
  button { border: 1px solid var(--pi-border); border-radius: 8px; background: var(--pi-surface); color: var(--pi-text); padding: 7px 9px; cursor: pointer; }
231
231
  .empty { margin: auto; color: var(--pi-muted); }
@@ -351,8 +351,8 @@ ${h}`;await this.api.prompt(a,g,i,p)}else await this.api.prompt(a,t,i,p,s);this.
351
351
  .workspace-detail-row .workspace-label-base, .workspace-detail-row .workspace-label-item, .workspace-detail-row .workspace-label-render { overflow: visible; text-overflow: clip; overflow-wrap: anywhere; white-space: normal; }
352
352
  @keyframes pulse { 0%, 100% { transform: scale(.75); opacity: .55; } 50% { transform: scale(1.2); opacity: 1; } }
353
353
  `,wg=_`
354
- :host { position: relative; z-index: 0; display: flex; flex-direction: column; min-height: 0; overflow: hidden; color: var(--pi-text); font: 14px system-ui, sans-serif; }
355
- .chat-wrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
354
+ :host { position: relative; z-index: 0; display: flex; flex: 1 1 0; flex-direction: column; min-height: 0; overflow: hidden; color: var(--pi-text); font: 14px system-ui, sans-serif; }
355
+ .chat-wrap { position: relative; flex: 1 1 0; min-height: 0; overflow: hidden; }
356
356
  .chat { height: 100%; min-height: 0; overflow: auto; overflow-anchor: none; padding: 26px 16px 64px; box-sizing: border-box; }
357
357
  .scroll-marker { display: block; height: 0; overflow: hidden; pointer-events: none; }
358
358
  .activity-dock { position: absolute; left: 16px; right: 16px; bottom: 12px; z-index: 20; display: flex; align-items: center; gap: 8px; min-width: 0; box-sizing: border-box; border: 1px solid var(--pi-border); border-radius: 999px; background: var(--pi-bg-overlay); color: var(--pi-muted); padding: 8px 12px; font-size: 13px; pointer-events: none; box-shadow: 0 8px 28px var(--pi-shadow); backdrop-filter: blur(6px); }
@@ -50,7 +50,7 @@
50
50
  html, body { margin: 0; height: 100%; overflow: hidden; background: var(--pi-bg); color: var(--pi-text); }
51
51
  body { min-height: 100dvh; }
52
52
  </style>
53
- <script type="module" crossorigin src="/assets/index-Bv6Wa4z_.js"></script>
53
+ <script type="module" crossorigin src="/assets/index-BdQ-j_1w.js"></script>
54
54
  <link rel="modulepreload" crossorigin href="/assets/vendor-editor-core-Bc1A7SO7.js">
55
55
  <link rel="modulepreload" crossorigin href="/assets/vendor-editor-languages-D0CnB2js.js">
56
56
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainingintention/pi-web-cn",
3
- "version": "1.202606.16",
3
+ "version": "1.202606.17",
4
4
  "description": "Remote web UI and browser control plane for persistent Pi Coding Agent sessions.",
5
5
  "license": "MIT",
6
6
  "author": "Federico Jaramillo Martinez",